On Mon, 2014-02-17 at 14:32 +0800, Chunyan Liu wrote:
For extracting hostdev codes from qemu_hostdev.c to common library,
move
add/remove a shareable csi hostdev to/from shared device table outside hostdev
functions.
Typo csi -> scsi
Signed-off-by: Chunyan Liu <cyliu(a)suse.com>
---
src/qemu/qemu_hostdev.c | 9 ---------
src/qemu/qemu_hotplug.c | 14 ++++++++++++++
src/qemu/qemu_process.c | 28 ++++++++++++++++++++++++++++
3 files changed, 42 insertions(+), 9 deletions(-)
diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
index 80552cd..cfdfb03 100644
--- a/src/qemu/qemu_hostdev.c
+++ b/src/qemu/qemu_hostdev.c
@@ -1061,9 +1061,6 @@ qemuPrepareHostdevSCSIDevices(virQEMUDriverPtr driver,
dev.type = VIR_DOMAIN_DEVICE_HOSTDEV;
dev.data.hostdev = hostdevs[i];
- if (qemuAddSharedDevice(driver, &dev, name) < 0)
- return -1;
-
if (qemuSetUnprivSGIO(&dev) < 0)
return -1;
}
@@ -1389,12 +1386,6 @@ qemuDomainReAttachHostScsiDevices(virQEMUDriverPtr driver,
virDomainHostdevDefPtr hostdev = hostdevs[i];
virSCSIDevicePtr scsi;
virSCSIDevicePtr tmp;
- virDomainDeviceDef dev;
-
- dev.type = VIR_DOMAIN_DEVICE_HOSTDEV;
- dev.data.hostdev = hostdev;
-
- ignore_value(qemuRemoveSharedDevice(driver, &dev, name));
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI)
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 8486f25..afa92da 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1548,6 +1548,7 @@ qemuDomainAttachHostScsiDevice(virQEMUDriverPtr driver,
char *drvstr = NULL;
bool teardowncgroup = false;
bool teardownlabel = false;
+ virDomainDeviceDef dev;
if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DRIVE) ||
!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE) ||
@@ -1561,6 +1562,12 @@ qemuDomainAttachHostScsiDevice(virQEMUDriverPtr driver,
if (!cont)
return -1;
+ /* check sharable scsi device */
+ dev.type = VIR_DOMAIN_DEVICE_HOSTDEV;
+ dev.data.hostdev = hostdev;
+ if (qemuAddSharedDevice(driver, &dev, vm->def->name) < 0)
+ return -1;
+
if (qemuPrepareHostdevSCSIDevices(driver, vm->def->name,
&hostdev, 1)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -1619,6 +1626,7 @@ qemuDomainAttachHostScsiDevice(virQEMUDriverPtr driver,
ret = 0;
cleanup:
if (ret < 0) {
+ ignore_value(qemuRemoveSharedDevice(driver, &dev, vm->def->name));
qemuDomainReAttachHostScsiDevices(driver, vm->def->name, &hostdev,
1);
if (teardowncgroup && qemuTeardownHostdevCgroup(vm, hostdev) < 0)
VIR_WARN("Unable to remove host device cgroup ACL on hotplug
fail");
@@ -2587,6 +2595,12 @@ qemuDomainRemoveSCSIHostDevice(virQEMUDriverPtr driver,
virDomainObjPtr vm,
virDomainHostdevDefPtr hostdev)
{
+ virDomainDeviceDef dev;
+
+ dev.type = VIR_DOMAIN_DEVICE_HOSTDEV;
+ dev.data.hostdev = hostdev;
+
+ ignore_value(qemuRemoveSharedDevice(driver, &dev, vm->def->name));
qemuDomainReAttachHostScsiDevices(driver, vm->def->name, &hostdev, 1);
}
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index e938649..5ea42c7 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -3158,6 +3158,16 @@ qemuProcessReconnect(void *opaque)
priv->agentError = true;
}
+ /* update hostdevs */
+ for (i = 0; i < obj->def->nhostdevs; i++) {
+ virDomainDeviceDef dev;
+ dev.type = VIR_DOMAIN_DEVICE_HOSTDEV;
+ dev.data.hostdev = obj->def->hostdevs[i];
+ /* handle sharable scsi hostdev */
+ if (qemuAddSharedDevice(driver, &dev, obj->def->name) < 0)
+ goto error;
+ }
+
if (qemuUpdateActivePciHostdevs(driver, obj->def) < 0) {
goto error;
}
@@ -3686,6 +3696,15 @@ int qemuProcessStart(virConnectPtr conn,
/* Must be run before security labelling */
VIR_DEBUG("Preparing host devices");
+ for (i = 0; i < vm->def->nhostdevs; i++) {
+ virDomainDeviceDef dev;
+ dev.type = VIR_DOMAIN_DEVICE_HOSTDEV;
+ dev.data.hostdev = vm->def->hostdevs[i];
+ /* handle sharable scsi hostdev */
+ if (qemuAddSharedDevice(driver, &dev, vm->def->name) < 0)
+ goto cleanup;
+ }
+
if (!cfg->relaxedACS)
hostdev_flags |= VIR_STRICT_ACS_CHECK;
if (!migrateFrom)
@@ -4372,6 +4391,15 @@ void qemuProcessStop(virQEMUDriverPtr driver,
priv->ccwaddrs = NULL;
}
+ /* handle shared scsi hostdev */
+ for (i = 0; i < vm->def->nhostdevs; i++) {
+ virDomainDeviceDef dev;
+
+ dev.type = VIR_DOMAIN_DEVICE_HOSTDEV;
+ dev.data.hostdev = vm->def->hostdevs[i];
+ ignore_value(qemuRemoveSharedDevice(driver, &dev, vm->def->name));
+ }
+
qemuDomainReAttachHostDevices(driver, vm->def);
def = vm->def;
ACK
--
Cedric