]> xenbits.xensource.com Git - libvirt.git/commitdiff
nodedev: refactor storage type fixup
authorBoris Fiuczynski <fiuczy@linux.ibm.com>
Wed, 19 Jun 2024 12:29:14 +0000 (14:29 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 20 Jun 2024 07:33:32 +0000 (09:33 +0200)
Refactor the storage type fixup into a reusable method.

Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/node_device/node_device_udev.c

index 3b85db00da0c4a83b30ea7d65927a83270f1b7c6..84848a3d5c9eafaca632a056167f875b66df56dc 100644 (file)
@@ -962,6 +962,23 @@ udevProcessDASD(struct udev_device *device,
 }
 
 
+static int
+udevFixupStorageType(virNodeDeviceDef *def,
+                     const char *prefix,
+                     const char *subst)
+{
+    if (STRPREFIX(def->caps->data.storage.block, prefix)) {
+        def->caps->data.storage.drive_type = g_strdup(subst);
+        VIR_DEBUG("Found storage type '%s' for device with sysfs path '%s'",
+                  def->caps->data.storage.drive_type,
+                  def->sysfs_path);
+        return 1;
+    }
+
+    return 0;
+}
+
+
 /* This function exists to deal with the case in which a driver does
  * not provide a device type in the usual place, but udev told us it's
  * a storage device, and we can make a good guess at what kind of
@@ -994,13 +1011,8 @@ udevKludgeStorageType(virNodeDeviceDef *def)
               def->sysfs_path);
 
     for (i = 0; i < G_N_ELEMENTS(fixups); i++) {
-        if (STRPREFIX(def->caps->data.storage.block, fixups[i].prefix)) {
-            def->caps->data.storage.drive_type = g_strdup(fixups[i].subst);
-            VIR_DEBUG("Found storage type '%s' for device with sysfs path '%s'",
-                      def->caps->data.storage.drive_type,
-                      def->sysfs_path);
+        if (udevFixupStorageType(def, fixups[i].prefix, fixups[i].subst))
             return 0;
-        }
     }
 
     VIR_DEBUG("Could not determine storage type "