]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage: Implement 'checkPool' method for 'disk' type pools
authorPeter Krempa <pkrempa@redhat.com>
Thu, 20 Jan 2022 10:46:51 +0000 (11:46 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 20 Jan 2022 13:23:56 +0000 (14:23 +0100)
If 'checkPool' is not implemented, the pool will be made inactive when
restarting libvirtd and subsequently re-loading the state from the pool
state XML.

Base the 'checkPool' implementation on logic similar to 'startPool'.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1910856
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/storage/storage_backend_disk.c

index be8a53557084776e453cd30e2d2bd7a32524f419..bf867491d0982868d17d97e527d229a3e9388609 100644 (file)
@@ -476,6 +476,32 @@ virStorageBackendDiskStartPool(virStoragePoolObj *pool)
 }
 
 
+static int
+virStorageBackendDiskCheckPool(virStoragePoolObj *pool,
+                               bool *isActive)
+{
+    virStoragePoolDef *def = virStoragePoolObjGetDef(pool);
+    const char *path = def->source.devices[0].path;
+
+    *isActive = false;
+
+    if (!virFileExists(path))
+        return 0;
+
+    if (def->source.format == VIR_STORAGE_POOL_DISK_UNKNOWN)
+        def->source.format = VIR_STORAGE_POOL_DISK_DOS;
+
+    if (!virStorageBackendDeviceIsEmpty(path,
+                                        virStoragePoolFormatDiskTypeToString(def->source.format),
+                                        false))
+        return -1;
+
+    *isActive = true;
+
+    return 0;
+}
+
+
 /**
  * Write a new partition table header
  */
@@ -973,6 +999,7 @@ virStorageBackend virStorageBackendDisk = {
     .buildPool = virStorageBackendDiskBuildPool,
     .refreshPool = virStorageBackendDiskRefreshPool,
     .deletePool = virStorageBackendDiskDeletePool,
+    .checkPool = virStorageBackendDiskCheckPool,
 
     .createVol = virStorageBackendDiskCreateVol,
     .deleteVol = virStorageBackendDiskDeleteVol,