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

[libvirt] [PATCH] Do a correct format mapping of partitions 2



I make a new try from a different mail client now.

/Henrik
--- libvirt-0.6.4.org/src/parthelper.c	2008-09-02 11:24:21.000000000 +0200
+++ libvirt-0.6.4/src/parthelper.c	2009-06-22 16:29:49.108681000 +0200
@@ -67,6 +67,7 @@ int main(int argc, char **argv)
     while (part) {
         const char *type;
         const char *content;
+        int partType = 0;
         if (part->type & PED_PARTITION_LOGICAL) {
             type = "logical";
             if (part->type & PED_PARTITION_FREESPACE)
@@ -92,26 +93,35 @@ int main(int argc, char **argv)
                 content = "data";
         }
 
+        /* Get partition type */
+        if(ped_partition_is_active(part)) {
+            if(ped_partition_is_flag_available(part, PED_PARTITION_TYPE)) {
+                partType = ped_partition_get_flag(part,PED_PARTITION_TYPE);
+            }
+        }
+
         /* We do +1 on geom.end, because we want end of the last sector
          * in bytes, not the last sector number
          */
         if (part->num != -1) {
-            printf("%s%d%c%s%c%s%c%llu%c%llu%c%llu%c",
+            printf("%s%d%c%s%c%s%c%llu%c%llu%c%llu%c%d%c",
                    part->geom.dev->path,
                    part->num, '\0',
                    type, '\0',
                    content, '\0',
                    part->geom.start * 512llu, '\0',
                    (part->geom.end + 1 ) * 512llu, '\0',
-                   part->geom.length * 512llu, '\0');
+                   part->geom.length * 512llu, '\0',
+                   partType, '\0');
         } else {
-            printf("%s%c%s%c%s%c%llu%c%llu%c%llu%c",
+            printf("%s%c%s%c%s%c%llu%c%llu%c%llu%c%d%c",
                    "-", '\0',
                    type, '\0',
                    content, '\0',
                    part->geom.start * 512llu, '\0',
                    (part->geom.end + 1 ) * 512llu, '\0',
-                   part->geom.length * 512llu, '\0');
+                   part->geom.length * 512llu, '\0',
+                   partType, '\0');
         }
         part = ped_disk_next_partition(disk, part);
     }
--- libvirt-0.6.4.org/src/storage_backend_disk.c	2009-04-02 11:50:10.000000000 +0200
+++ libvirt-0.6.4/src/storage_backend_disk.c	2009-06-23 11:27:25.966487000 +0200
@@ -36,6 +36,33 @@
 
 #define PARTHELPER BINDIR "/libvirt_parthelper"
 
+/* Map partition types to internal enum */
+static int 
+virStorageBackendDiskMapPartitionType(const char* partType)
+{
+    switch(atoi(partType)) {
+       case 0x05:
+       case 0x0f:
+            return VIR_STORAGE_VOL_DISK_EXTENDED;
+       case 0x06:
+       case 0x0e:
+            return VIR_STORAGE_VOL_DISK_FAT16;
+       case 0x0b:
+       case 0x0c:
+            return VIR_STORAGE_VOL_DISK_FAT32;
+       case 0x82:
+            return VIR_STORAGE_VOL_DISK_LINUX_SWAP;
+       case 0x83:
+            return VIR_STORAGE_VOL_DISK_LINUX;
+       case 0x8e:
+            return VIR_STORAGE_VOL_DISK_LINUX_LVM;
+       case 0xfd:
+            return VIR_STORAGE_VOL_DISK_LINUX_RAID;
+       default:
+            return VIR_STORAGE_VOL_DISK_NONE;
+   }
+}
+
 static int
 virStorageBackendDiskMakeDataVol(virConnectPtr conn,
                                  virStoragePoolObjPtr pool,
@@ -128,6 +155,9 @@ virStorageBackendDiskMakeDataVol(virConn
     if (virStorageBackendUpdateVolInfo(conn, vol, 1) < 0)
         return -1;
 
+    /* virStorageBackendUpdateVolInfo sets format incorrect for partitions */
+    vol->target.format = virStorageBackendDiskMapPartitionType(groups[6]);
+
     vol->type = VIR_STORAGE_VOL_BLOCK;
 
     /* The above gets allocation wrong for
@@ -250,7 +280,7 @@ virStorageBackendDiskReadPartitions(virC
     return virStorageBackendRunProgNul(conn,
                                        pool,
                                        prog,
-                                       6,
+                                       7,
                                        virStorageBackendDiskMakeVol,
                                        vol);
 }

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