/*
- * Copyright (C) 2010-2013 Red Hat, Inc.
+ * Copyright (C) 2010-2014 Red Hat, Inc.
* Copyright IBM Corp. 2008
*
* lxc_controller.c: linux container process controller
{
int lofd;
char *loname = NULL;
+ const char *src = virDomainDiskGetSource(disk);
- if ((lofd = virFileLoopDeviceAssociate(disk->src, &loname)) < 0)
+ if ((lofd = virFileLoopDeviceAssociate(src, &loname)) < 0)
return -1;
VIR_DEBUG("Changing disk %s to use type=block for dev %s",
- disk->src, loname);
+ src, loname);
/*
* We now change it into a block device type, so that
* the rest of container setup 'just works'
*/
- disk->type = VIR_DOMAIN_DISK_TYPE_BLOCK;
- VIR_FREE(disk->src);
- disk->src = loname;
- loname = NULL;
+ virDomainDiskSetType(disk, VIR_DOMAIN_DISK_TYPE_BLOCK);
+ if (virDomainDiskSetSource(disk, loname) < 0) {
+ VIR_FREE(loname);
+ return -1;
+ }
+ VIR_FREE(loname);
return lofd;
}
static int virLXCControllerSetupNBDDeviceDisk(virDomainDiskDefPtr disk)
{
char *dev;
+ const char *src = virDomainDiskGetSource(disk);
+ int format = virDomainDiskGetFormat(disk);
- if (disk->format <= VIR_STORAGE_FILE_NONE) {
+ if (format <= VIR_STORAGE_FILE_NONE) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("An explicit disk format must be specified"));
return -1;
}
- if (virFileNBDDeviceAssociate(disk->src,
- disk->format,
+ if (virFileNBDDeviceAssociate(src,
+ format,
disk->readonly,
&dev) < 0)
return -1;
VIR_DEBUG("Changing disk %s to use type=block for dev %s",
- disk->src, dev);
+ src, dev);
/*
* We now change it into a block device type, so that
* the rest of container setup 'just works'
*/
- disk->type = VIR_DOMAIN_DISK_TYPE_BLOCK;
- VIR_FREE(disk->src);
- disk->src = dev;
+ virDomainDiskSetType(disk, VIR_DOMAIN_DISK_TYPE_BLOCK);
+ if (virDomainDiskSetSource(disk, dev) < 0) {
+ VIR_FREE(dev);
+ return -1;
+ }
+ VIR_FREE(dev);
return 0;
}
for (i = 0; i < ctrl->def->ndisks; i++) {
virDomainDiskDefPtr disk = ctrl->def->disks[i];
int fd;
+ const char *driver = virDomainDiskGetDriver(disk);
+ int format = virDomainDiskGetFormat(disk);
- if (disk->type != VIR_DOMAIN_DISK_TYPE_FILE)
+ if (virDomainDiskGetType(disk) != VIR_DOMAIN_DISK_TYPE_FILE)
continue;
/* If no driverName is set, we prefer 'loop' for
* dealing with raw or undefined formats, otherwise
* we use 'nbd'.
*/
- if (STREQ_NULLABLE(disk->driverName, "loop") ||
- (!disk->driverName &&
- (disk->format == VIR_STORAGE_FILE_RAW ||
- disk->format == VIR_STORAGE_FILE_NONE))) {
- if (disk->format != VIR_STORAGE_FILE_RAW &&
- disk->format != VIR_STORAGE_FILE_NONE) {
+ if (STREQ_NULLABLE(driver, "loop") ||
+ (!driver &&
+ (format == VIR_STORAGE_FILE_RAW ||
+ format == VIR_STORAGE_FILE_NONE))) {
+ if (format != VIR_STORAGE_FILE_RAW &&
+ format != VIR_STORAGE_FILE_NONE) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("disk format %s is not supported"),
- virStorageFileFormatTypeToString(disk->format));
+ virStorageFileFormatTypeToString(format));
goto cleanup;
}
goto cleanup;
}
ctrl->loopDevFds[ctrl->nloopDevs - 1] = fd;
- } else if (STREQ_NULLABLE(disk->driverName, "nbd") ||
- !disk->driverName) {
+ } else if (!driver || STREQ(driver, "nbd")) {
if (disk->cachemode != VIR_DOMAIN_DISK_CACHE_DEFAULT &&
disk->cachemode != VIR_DOMAIN_DISK_CACHE_DISABLE) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
} else {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("disk driver %s is not supported"),
- disk->driverName);
+ driver);
goto cleanup;
}
}
mode_t mode;
char *tmpsrc = def->src;
- if (def->type != VIR_DOMAIN_DISK_TYPE_BLOCK) {
+ if (virDomainDiskGetType(def) != VIR_DOMAIN_DISK_TYPE_BLOCK) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Can't setup disk for non-block device"));
goto cleanup;
}
- if (def->src == NULL) {
+ if (!tmpsrc) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Can't setup disk without media"));
goto cleanup;
if (stat(def->src, &sb) < 0) {
virReportSystemError(errno,
- _("Unable to access %s"), def->src);
+ _("Unable to access %s"), tmpsrc);
goto cleanup;
}
if (!S_ISCHR(sb.st_mode) && !S_ISBLK(sb.st_mode)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Disk source %s must be a character/block device"),
- def->src);
+ tmpsrc);
goto cleanup;
}
* to that normally implied by the device name
*/
VIR_DEBUG("Creating dev %s (%d,%d) from %s",
- dst, major(sb.st_rdev), minor(sb.st_rdev), def->src);
+ dst, major(sb.st_rdev), minor(sb.st_rdev), tmpsrc);
if (mknod(dst, mode, sb.st_rdev) < 0) {
virReportSystemError(errno,
_("Unable to create device %s"),
struct stat sb;
char *file = NULL;
int perms;
+ const char *src = NULL;
if (!priv->initpid) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
goto cleanup;
}
- if (def->type != VIR_DOMAIN_DISK_TYPE_BLOCK) {
+ if (!virDomainDiskSourceIsBlockType(def)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Can't setup disk for non-block device"));
goto cleanup;
}
- if (def->src == NULL) {
+ src = virDomainDiskGetSource(def);
+ if (src == NULL) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Can't setup disk without media"));
goto cleanup;
goto cleanup;
}
- if (stat(def->src, &sb) < 0) {
+ if (stat(src, &sb) < 0) {
virReportSystemError(errno,
- _("Unable to access %s"), def->src);
+ _("Unable to access %s"), src);
goto cleanup;
}
if (!S_ISBLK(sb.st_mode)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Disk source %s must be a block device"),
- def->src);
+ src);
goto cleanup;
}
minor(sb.st_rdev),
perms) < 0)
VIR_WARN("cannot deny device %s for domain %s",
- def->src, vm->def->name);
+ src, vm->def->name);
goto cleanup;
}
ret = 0;
cleanup:
- virDomainAuditDisk(vm, NULL, def->src, "attach", ret == 0);
+ if (src)
+ virDomainAuditDisk(vm, NULL, src, "attach", ret == 0);
VIR_FREE(file);
return ret;
}
virDomainDiskDefPtr def = NULL;
int idx, ret = -1;
char *dst = NULL;
+ const char *src;
if (!priv->initpid) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
}
def = vm->def->disks[idx];
+ src = virDomainDiskGetSource(def);
if (virAsprintf(&dst, "/dev/%s", def->dst) < 0)
goto cleanup;
}
if (lxcDomainAttachDeviceUnlink(vm, dst) < 0) {
- virDomainAuditDisk(vm, def->src, NULL, "detach", false);
+ virDomainAuditDisk(vm, src, NULL, "detach", false);
goto cleanup;
}
- virDomainAuditDisk(vm, def->src, NULL, "detach", true);
+ virDomainAuditDisk(vm, src, NULL, "detach", true);
- if (virCgroupDenyDevicePath(priv->cgroup, def->src, VIR_CGROUP_DEVICE_RWM) != 0)
+ if (virCgroupDenyDevicePath(priv->cgroup, src, VIR_CGROUP_DEVICE_RWM) != 0)
VIR_WARN("cannot deny device %s for domain %s",
- def->src, vm->def->name);
+ src, vm->def->name);
virDomainDiskRemove(vm->def, idx);
virDomainDiskDefFree(def);