]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
storage: disk: Properly handle partition numbers separated by 'p'
authorPeter Krempa <pkrempa@redhat.com>
Tue, 17 Jun 2025 08:42:52 +0000 (10:42 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 18 Jun 2025 10:14:32 +0000 (12:14 +0200)
The 'p' separator for partitions is now common also for NVMe devices.
Fix the algorithm to extract the partition number to always consider it.

The fix is based on suggestion in the issue mentioned below.

Closes: https://gitlab.com/libvirt/libvirt/-/issues/239
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/storage/storage_backend_disk.c

index 996395de4a92da5b372910adc0ea9ccc9c266879..871226ee22d9f8f5fbe4951e7d263c6dcc488e92 100644 (file)
@@ -805,7 +805,6 @@ virStorageBackendDiskDeleteVol(virStoragePoolObj *pool,
     virStoragePoolDef *def = virStoragePoolObjGetDef(pool);
     char *src_path = def->source.devices[0].path;
     g_autofree char *srcname = g_path_get_basename(src_path);
-    bool isDevMapperDevice;
     g_autofree char *devpath = NULL;
     g_autoptr(virCommand) cmd = NULL;
 
@@ -822,8 +821,7 @@ virStorageBackendDiskDeleteVol(virStoragePoolObj *pool,
      *     (parthelper.c) that is used to generate the target.path name
      *     for use by libvirt. Changes to either, need to be reflected
      *     in both places */
-    isDevMapperDevice = virIsDevMapperDevice(vol->target.path);
-    if (isDevMapperDevice) {
+    if (virIsDevMapperDevice(vol->target.path)) {
         dev_name = g_path_get_basename(vol->target.path);
     } else {
         if (virFileResolveLink(vol->target.path, &devpath) < 0) {
@@ -846,9 +844,8 @@ virStorageBackendDiskDeleteVol(virStoragePoolObj *pool,
 
     part_num = dev_name + strlen(srcname);
 
-    /* For device mapper and we have a partition character 'p' as the
-     * current character, let's move beyond that before checking part_num */
-    if (isDevMapperDevice && *part_num == 'p')
+    /* Check if partition character 'p' is present and move beyond it */
+    if (*part_num == 'p' &&  g_ascii_isdigit(*(part_num + 1)))
         part_num++;
 
     if (*part_num == 0) {