[PATCH 3/7] qcow2GetFeatures: Extract population of features bitmap

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Prepare for extraction of features from the 'incompatible features'
group.

This is done by moving the extraction loop into a new function called
qcow2GetFeaturesProcessGroup. The new function also allows to ingore
features we don't care about by passing VIR_STORAGE_FILE_FEATURE_LAST as
the target flag.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/storage_file/storage_file_probe.c | 33 ++++++++++++++++++---------
 1 file changed, 22 insertions(+), 11 deletions(-)

diff --git a/src/storage_file/storage_file_probe.c b/src/storage_file/storage_file_probe.c
index dc438a5e5d..f403e50938 100644
--- a/src/storage_file/storage_file_probe.c
+++ b/src/storage_file/storage_file_probe.c
@@ -344,7 +344,7 @@ enum qcow2CompatibleFeature {
 };

 /* conversion to virStorageFileFeature */
-static const int qcow2CompatibleFeatureArray[] = {
+static const virStorageFileFeature qcow2CompatibleFeatureArray[] = {
     VIR_STORAGE_FILE_FEATURE_LAZY_REFCOUNTS,
 };
 G_STATIC_ASSERT(G_N_ELEMENTS(qcow2CompatibleFeatureArray) ==
@@ -748,6 +748,22 @@ virStorageFileProbeFormatFromBuf(const char *path,
 }


+static void
+qcow2GetFeaturesProcessGroup(uint64_t bits,
+                             const virStorageFileFeature *featuremap,
+                             size_t nfeatures,
+                             virBitmap *features)
+{
+    size_t i;
+
+    for (i = 0; i < nfeatures; i++) {
+        if ((bits & ((uint64_t) 1 << i)) &&
+            featuremap[i] != VIR_STORAGE_FILE_FEATURE_LAST)
+            ignore_value(virBitmapSetBit(features, featuremap[i]));
+    }
+}
+
+
 static int
 qcow2GetFeatures(virBitmap **features,
                  int format,
@@ -755,9 +771,6 @@ qcow2GetFeatures(virBitmap **features,
                  ssize_t len)
 {
     int version = -1;
-    virBitmap *feat = NULL;
-    uint64_t bits;
-    size_t i;

     version = virReadBufInt32BE(buf + fileTypeInfo[format].versionOffset);

@@ -767,16 +780,14 @@ qcow2GetFeatures(virBitmap **features,
     if (len < QCOW2v3_HDR_SIZE)
         return -1;

-    feat = virBitmapNew(VIR_STORAGE_FILE_FEATURE_LAST);
+    *features = virBitmapNew(VIR_STORAGE_FILE_FEATURE_LAST);

     /* todo: check for incompatible or autoclear features? */
-    bits = virReadBufInt64BE(buf + QCOW2v3_HDR_FEATURES_COMPATIBLE);
-    for (i = 0; i < QCOW2_COMPATIBLE_FEATURE_LAST; i++) {
-        if (bits & ((uint64_t) 1 << i))
-            ignore_value(virBitmapSetBit(feat, qcow2CompatibleFeatureArray[i]));
-    }
+    qcow2GetFeaturesProcessGroup(virReadBufInt64BE(buf + QCOW2v3_HDR_FEATURES_COMPATIBLE),
+                                 qcow2CompatibleFeatureArray,
+                                 G_N_ELEMENTS(qcow2CompatibleFeatureArray),
+                                 *features);

-    *features = feat;
     return 0;
 }

-- 
2.31.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux