]> xenbits.xensource.com Git - libvirt.git/commitdiff
rbd: do not attempt to use fast-diff if it's marked invalid
authorJason Dillaman <dillaman@redhat.com>
Tue, 19 Mar 2019 13:42:16 +0000 (09:42 -0400)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 19 Mar 2019 14:37:52 +0000 (15:37 +0100)
The librbd API will transparently revert to a slow disk usage
calculation method if the fast-diff map is marked as invalid.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
src/storage/storage_backend_rbd.c

index a0cae1a9e0f88f9965293019abc2eef0104c8502..4744b7bfd8aa46de544e8b0f906ca70532da61bf 100644 (file)
@@ -437,10 +437,28 @@ volStorageBackendRBDGetFeatures(rbd_image_t image,
 }
 
 #if LIBRBD_VERSION_CODE > 265
+static int
+volStorageBackendRBDGetFlags(rbd_image_t image,
+                             const char *volname,
+                             uint64_t *flags)
+{
+    int rc;
+
+    if ((rc = rbd_get_flags(image, flags)) < 0) {
+        virReportSystemError(-rc,
+                             _("failed to get the flags of RBD image %s"),
+                             volname);
+        return -1;
+    }
+
+    return 0;
+}
+
 static bool
-volStorageBackendRBDUseFastDiff(uint64_t features)
+volStorageBackendRBDUseFastDiff(uint64_t features, uint64_t flags)
 {
-    return features & RBD_FEATURE_FAST_DIFF;
+    return (((features & RBD_FEATURE_FAST_DIFF) != 0ULL) &&
+            ((flags & RBD_FLAG_FAST_DIFF_INVALID) == 0ULL));
 }
 
 static int
@@ -484,7 +502,17 @@ virStorageBackendRBDSetAllocation(virStorageVolDefPtr vol,
 
 #else
 static int
-volStorageBackendRBDUseFastDiff(uint64_t features ATTRIBUTE_UNUSED)
+volStorageBackendRBDGetFlags(rbd_image_t image,
+                             const char *volname,
+                             uint64_t *flags)
+{
+    *flags = 0;
+    return 0;
+}
+
+static int
+volStorageBackendRBDUseFastDiff(uint64_t features ATTRIBUTE_UNUSED,
+                                uint64_t feature_flags ATTRIBUTE_UNUSED)
 {
     return false;
 }
@@ -509,6 +537,7 @@ volStorageBackendRBDRefreshVolInfo(virStorageVolDefPtr vol,
     rbd_image_t image = NULL;
     rbd_image_info_t info;
     uint64_t features;
+    uint64_t flags;
 
     if ((r = rbd_open_read_only(ptr->ioctx, vol->name, &image, NULL)) < 0) {
         ret = -r;
@@ -527,11 +556,14 @@ volStorageBackendRBDRefreshVolInfo(virStorageVolDefPtr vol,
     if (volStorageBackendRBDGetFeatures(image, vol->name, &features) < 0)
         goto cleanup;
 
+    if (volStorageBackendRBDGetFlags(image, vol->name, &flags) < 0)
+        goto cleanup;
+
     vol->target.capacity = info.size;
     vol->type = VIR_STORAGE_VOL_NETWORK;
     vol->target.format = VIR_STORAGE_FILE_RAW;
 
-    if (volStorageBackendRBDUseFastDiff(features)) {
+    if (volStorageBackendRBDUseFastDiff(features, flags)) {
         VIR_DEBUG("RBD image %s/%s has fast-diff feature enabled. "
                   "Querying for actual allocation",
                   def->source.name, vol->name);