提交 0db7ff59 编写于 作者: O Osier Yang

qemu: Move the shared disk adding and sgio setting prior to attaching

The disk def could be free'ed by qemuDomainChangeEjectableMedia,
which can thus cause crash if we reference the disk pointer. On
the other hand, we have to remove the added shared disk entry from
the table on error codepath.
上级 d0e4b762
...@@ -5714,6 +5714,12 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn, ...@@ -5714,6 +5714,12 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
goto end; goto end;
} }
if (qemuAddSharedDisk(driver, disk, vm->def->name) < 0)
goto end;
if (qemuSetUnprivSGIO(disk) < 0)
goto end;
if (qemuDomainDetermineDiskChain(driver, disk, false) < 0) if (qemuDomainDetermineDiskChain(driver, disk, false) < 0)
goto end; goto end;
...@@ -5727,6 +5733,7 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn, ...@@ -5727,6 +5733,7 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
if (qemuSetupDiskCgroup(vm, cgroup, disk) < 0) if (qemuSetupDiskCgroup(vm, cgroup, disk) < 0)
goto end; goto end;
} }
switch (disk->device) { switch (disk->device) {
case VIR_DOMAIN_DISK_DEVICE_CDROM: case VIR_DOMAIN_DISK_DEVICE_CDROM:
case VIR_DOMAIN_DISK_DEVICE_FLOPPY: case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
...@@ -5765,16 +5772,9 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn, ...@@ -5765,16 +5772,9 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
NULLSTR(disk->src)); NULLSTR(disk->src));
} }
if (ret == 0) {
if (qemuAddSharedDisk(driver, disk, vm->def->name) < 0)
VIR_WARN("Failed to add disk '%s' to shared disk table",
disk->src);
if (qemuSetUnprivSGIO(disk) < 0)
VIR_WARN("Failed to set unpriv_sgio of disk '%s'", disk->src);
}
end: end:
if (ret != 0)
ignore_value(qemuRemoveSharedDisk(driver, disk, vm->def->name));
if (cgroup) if (cgroup)
virCgroupFree(&cgroup); virCgroupFree(&cgroup);
return ret; return ret;
...@@ -5889,11 +5889,8 @@ qemuDomainDetachDeviceDiskLive(virQEMUDriverPtr driver, ...@@ -5889,11 +5889,8 @@ qemuDomainDetachDeviceDiskLive(virQEMUDriverPtr driver,
break; break;
} }
if (ret == 0) { if (ret == 0)
if (qemuRemoveSharedDisk(driver, disk, vm->def->name) < 0) ignore_value(qemuRemoveSharedDisk(driver, disk, vm->def->name));
VIR_WARN("Failed to remove disk '%s' from shared disk table",
disk->src);
}
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册