]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Introduce and use virDomainDiskEmptySource
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 31 Mar 2017 13:59:54 +0000 (15:59 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 3 Apr 2017 06:35:57 +0000 (08:35 +0200)
Currently, if we want to zero out disk source (e,g, due to
startupPolicy when starting up a domain) we use
virDomainDiskSetSource(disk, NULL). This works well for file
based storage (storage type file, dir, or block). But it doesn't
work at all for other types like volume and network.

So imagine that you have a domain that has a CDROM configured
which source is a volume from an inactive pool. Because it is
startupPolicy='optional', the CDROM is empty when the domain
starts. However, the source element is not cleared out in the
status XML and thus when the daemon restarts and tries to
reconnect to the domain it refreshes the disks (which fails - the
storage pool is still not running) and thus the domain is killed.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
src/conf/domain_conf.c
src/conf/domain_conf.h
src/libvirt_private.syms
src/qemu/qemu_domain.c
src/qemu/qemu_process.c

index 01553b52942de7fb971e8217df13a3affda7c178..80baa090a7f8ddeba72b7387de5a7a5570b1e455 100644 (file)
@@ -1719,6 +1719,16 @@ virDomainDiskSetSource(virDomainDiskDefPtr def, const char *src)
 }
 
 
+void
+virDomainDiskEmptySource(virDomainDiskDefPtr def)
+{
+    virStorageSourcePtr src = def->src;
+
+    virStorageSourceClear(src);
+    src->type = VIR_STORAGE_TYPE_FILE;
+}
+
+
 const char *
 virDomainDiskGetDriver(virDomainDiskDefPtr def)
 {
index 47eaacef3d48e56f2d8579e2e6462f850e9ae5f3..26c0e6b88759108fb5654fbddadd5ae15e874c60 100644 (file)
@@ -2590,6 +2590,7 @@ void virDomainDiskSetType(virDomainDiskDefPtr def, int type);
 const char *virDomainDiskGetSource(virDomainDiskDef const *def);
 int virDomainDiskSetSource(virDomainDiskDefPtr def, const char *src)
     ATTRIBUTE_RETURN_CHECK;
+void virDomainDiskEmptySource(virDomainDiskDefPtr def);
 const char *virDomainDiskGetDriver(virDomainDiskDefPtr def);
 int virDomainDiskSetDriver(virDomainDiskDefPtr def, const char *name)
     ATTRIBUTE_RETURN_CHECK;
index b551cb86a68e65b154d31fd63700fff3cf7bae05..92083e54142dbaa4c61bf5fabbceaa7131f603d1 100644 (file)
@@ -299,6 +299,7 @@ virDomainDiskDetectZeroesTypeFromString;
 virDomainDiskDetectZeroesTypeToString;
 virDomainDiskDeviceTypeToString;
 virDomainDiskDiscardTypeToString;
+virDomainDiskEmptySource;
 virDomainDiskErrorPolicyTypeFromString;
 virDomainDiskErrorPolicyTypeToString;
 virDomainDiskFindByBusAndDst;
index 589eb188993ff0eaa7eac0abc1883106489a17f6..b733505d0bbd552d45f3b660995ed3dafa60c084 100644 (file)
@@ -4908,7 +4908,7 @@ qemuDomainCheckRemoveOptionalDisk(virQEMUDriverPtr driver,
         event = virDomainEventDiskChangeNewFromObj(vm, src, NULL,
                                                    disk->info.alias,
                                                    VIR_DOMAIN_EVENT_DISK_CHANGE_MISSING_ON_START);
-        ignore_value(virDomainDiskSetSource(disk, NULL));
+        virDomainDiskEmptySource(disk);
         /* keeping the old startup policy would be invalid for new images */
         disk->startupPolicy = VIR_DOMAIN_STARTUP_POLICY_DEFAULT;
     } else {
index a20beb13c1f91430464ed830c1440c3dc6d62847..e450d0647e29359bda98703f1281de622c9eaf74 100644 (file)
@@ -6804,7 +6804,7 @@ qemuProcessRefreshDisks(virQEMUDriverPtr driver,
 
         if (info->removable) {
             if (info->empty)
-                ignore_value(virDomainDiskSetSource(disk, NULL));
+                virDomainDiskEmptySource(disk);
 
             if (info->tray) {
                 if (info->tray_open)