This patch reads the partition type and sets the correct target format
of the storage volume when based on physical disk.
I think the general idea you're trying to implement looks reasonable,
but this patch you posted has been white-space damaged by your email
client. Can you re-post it.
Also, its useful when generating diff's to use the '-p' flag so that
the patch includs the function name, eg
diff -rupN libvirt-0.6.4.orig libvirt-0.6.4.new
Regards,
Daniel
---
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 @@
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 @@
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-22
18:25:14.095095000 +0200
@@ -36,6 +36,35 @@
#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 +157,9 @@
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 +282,7 @@
return virStorageBackendRunProgNul(conn,
pool,
prog,
- 6,
+ 7,
virStorageBackendDiskMakeVol,
vol);
}
--
Libvir-list mailing list
Libvir-list(a)redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|