conf: use disk source accessors in libxl/

Part of a series of cleanups to use new accessor methods.

* src/libxl/libxl_conf.c (libxlMakeDisk): Use accessors.
* src/libxl/libxl_driver.c (libxlDomainChangeEjectableMedia)
(libxlDomainAttachDeviceDiskLive): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Eric Blake 2014-03-17 14:14:11 -06:00
parent 3c9751187f
commit f7c81d8458
2 changed files with 37 additions and 39 deletions

View File

@ -1,7 +1,7 @@
/* /*
* libxl_conf.c: libxl configuration management * libxl_conf.c: libxl configuration management
* *
* Copyright (C) 2012 Red Hat, Inc. * Copyright (C) 2012-2014 Red Hat, Inc.
* Copyright (c) 2011-2013 SUSE LINUX Products GmbH, Nuernberg, Germany. * Copyright (c) 2011-2013 SUSE LINUX Products GmbH, Nuernberg, Germany.
* Copyright (C) 2011 Univention GmbH. * Copyright (C) 2011 Univention GmbH.
* *
@ -716,18 +716,22 @@ error:
int int
libxlMakeDisk(virDomainDiskDefPtr l_disk, libxl_device_disk *x_disk) libxlMakeDisk(virDomainDiskDefPtr l_disk, libxl_device_disk *x_disk)
{ {
const char *driver;
int format;
libxl_device_disk_init(x_disk); libxl_device_disk_init(x_disk);
if (VIR_STRDUP(x_disk->pdev_path, l_disk->src) < 0) if (VIR_STRDUP(x_disk->pdev_path, virDomainDiskGetSource(l_disk)) < 0)
return -1; return -1;
if (VIR_STRDUP(x_disk->vdev, l_disk->dst) < 0) if (VIR_STRDUP(x_disk->vdev, l_disk->dst) < 0)
return -1; return -1;
if (l_disk->driverName) { driver = virDomainDiskGetDriver(l_disk);
if (STREQ(l_disk->driverName, "tap") || format = virDomainDiskGetFormat(l_disk);
STREQ(l_disk->driverName, "tap2")) { if (driver) {
switch (l_disk->format) { if (STREQ(driver, "tap") || STREQ(driver, "tap2")) {
switch (format) {
case VIR_STORAGE_FILE_QCOW: case VIR_STORAGE_FILE_QCOW:
x_disk->format = LIBXL_DISK_FORMAT_QCOW; x_disk->format = LIBXL_DISK_FORMAT_QCOW;
x_disk->backend = LIBXL_DISK_BACKEND_QDISK; x_disk->backend = LIBXL_DISK_BACKEND_QDISK;
@ -750,13 +754,13 @@ libxlMakeDisk(virDomainDiskDefPtr l_disk, libxl_device_disk *x_disk)
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("libxenlight does not support disk format %s " _("libxenlight does not support disk format %s "
"with disk driver %s"), "with disk driver %s"),
virStorageFileFormatTypeToString(l_disk->format), virStorageFileFormatTypeToString(format),
l_disk->driverName); driver);
return -1; return -1;
} }
} else if (STREQ(l_disk->driverName, "qemu")) { } else if (STREQ(driver, "qemu")) {
x_disk->backend = LIBXL_DISK_BACKEND_QDISK; x_disk->backend = LIBXL_DISK_BACKEND_QDISK;
switch (l_disk->format) { switch (format) {
case VIR_STORAGE_FILE_QCOW: case VIR_STORAGE_FILE_QCOW:
x_disk->format = LIBXL_DISK_FORMAT_QCOW; x_disk->format = LIBXL_DISK_FORMAT_QCOW;
break; break;
@ -775,30 +779,30 @@ libxlMakeDisk(virDomainDiskDefPtr l_disk, libxl_device_disk *x_disk)
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("libxenlight does not support disk format %s " _("libxenlight does not support disk format %s "
"with disk driver %s"), "with disk driver %s"),
virStorageFileFormatTypeToString(l_disk->format), virStorageFileFormatTypeToString(format),
l_disk->driverName); driver);
return -1; return -1;
} }
} else if (STREQ(l_disk->driverName, "file")) { } else if (STREQ(driver, "file")) {
if (l_disk->format != VIR_STORAGE_FILE_NONE && if (format != VIR_STORAGE_FILE_NONE &&
l_disk->format != VIR_STORAGE_FILE_RAW) { format != VIR_STORAGE_FILE_RAW) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("libxenlight does not support disk format %s " _("libxenlight does not support disk format %s "
"with disk driver %s"), "with disk driver %s"),
virStorageFileFormatTypeToString(l_disk->format), virStorageFileFormatTypeToString(format),
l_disk->driverName); driver);
return -1; return -1;
} }
x_disk->format = LIBXL_DISK_FORMAT_RAW; x_disk->format = LIBXL_DISK_FORMAT_RAW;
x_disk->backend = LIBXL_DISK_BACKEND_TAP; x_disk->backend = LIBXL_DISK_BACKEND_TAP;
} else if (STREQ(l_disk->driverName, "phy")) { } else if (STREQ(driver, "phy")) {
if (l_disk->format != VIR_STORAGE_FILE_NONE && if (format != VIR_STORAGE_FILE_NONE &&
l_disk->format != VIR_STORAGE_FILE_RAW) { format != VIR_STORAGE_FILE_RAW) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("libxenlight does not support disk format %s " _("libxenlight does not support disk format %s "
"with disk driver %s"), "with disk driver %s"),
virStorageFileFormatTypeToString(l_disk->format), virStorageFileFormatTypeToString(format),
l_disk->driverName); driver);
return -1; return -1;
} }
x_disk->format = LIBXL_DISK_FORMAT_RAW; x_disk->format = LIBXL_DISK_FORMAT_RAW;
@ -806,7 +810,7 @@ libxlMakeDisk(virDomainDiskDefPtr l_disk, libxl_device_disk *x_disk)
} else { } else {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("libxenlight does not support disk driver %s"), _("libxenlight does not support disk driver %s"),
l_disk->driverName); driver);
return -1; return -1;
} }
} else { } else {

View File

@ -2514,11 +2514,9 @@ libxlDomainChangeEjectableMedia(libxlDomainObjPrivatePtr priv,
goto cleanup; goto cleanup;
} }
VIR_FREE(origdisk->src); if (virDomainDiskSetSource(origdisk, virDomainDiskGetSource(disk)) < 0)
origdisk->src = disk->src; goto cleanup;
disk->src = NULL; virDomainDiskSetType(origdisk, virDomainDiskGetType(disk));
origdisk->type = disk->type;
virDomainDiskDefFree(disk); virDomainDiskDefFree(disk);
@ -2548,7 +2546,7 @@ libxlDomainAttachDeviceDiskLive(libxlDomainObjPrivatePtr priv,
goto cleanup; goto cleanup;
} }
if (!l_disk->src) { if (!virDomainDiskGetSource(l_disk)) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("disk source path is missing")); "%s", _("disk source path is missing"));
goto cleanup; goto cleanup;
@ -3033,16 +3031,12 @@ libxlDomainUpdateDeviceConfig(virDomainDefPtr vmdef, virDomainDeviceDefPtr dev)
goto cleanup; goto cleanup;
} }
VIR_FREE(orig->src); if (virDomainDiskSetSource(orig, virDomainDiskGetSource(disk)) < 0)
orig->src = disk->src; goto cleanup;
orig->type = disk->type; virDomainDiskSetType(orig, virDomainDiskGetType(disk));
if (disk->driverName) { virDomainDiskSetFormat(orig, virDomainDiskGetFormat(disk));
VIR_FREE(orig->driverName); if (virDomainDiskSetDriver(orig, virDomainDiskGetDriver(disk)) < 0)
orig->driverName = disk->driverName; goto cleanup;
disk->driverName = NULL;
}
orig->format = disk->format;
disk->src = NULL;
break; break;
default: default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",