[libvirt] [PATCH 3/5] disk geometry

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

 



Reads the disk geometry to be able to align disk partitions on cylinder boundries.
Msdos partition tables really like this stuff.
--- libvirt-0.6.4.org/src/parthelper.c	2009-06-23 13:07:38.167048000 +0200
+++ libvirt-0.6.4/src/parthelper.c	2009-06-23 17:13:27.636892000 +0200
@@ -41,14 +41,22 @@
 # define PED_PARTITION_PROTECTED 0
 #endif
 
+enum diskCommand {
+    DISK_LAYOUT = 0,
+    DISK_GEOMETRY
+};
+
 int main(int argc, char **argv)
 {
     PedDevice *dev;
     PedDisk *disk;
     PedPartition *part;
+    int cmd = DISK_LAYOUT;
 
-    if (argc !=  2) {
-        fprintf(stderr, "syntax: %s DEVICE\n", argv[0]);
+    if (argc ==  3 && !strcmp(argv[2], "-g")) {
+        cmd = DISK_GEOMETRY;
+    } else if (argc != 2) {
+        fprintf(stderr, "syntax: %s DEVICE [-g]\n", argv[0]);
         return 1;
     }
 
@@ -57,6 +65,15 @@ int main(int argc, char **argv)
         return 2;
     }
 
+    /* return the geometry of the disk and then exit */
+    if(cmd == DISK_GEOMETRY) {
+        printf("%d%c%d%c%d%c%",
+               dev->hw_geom.cylinders, '\0',
+               dev->hw_geom.heads, '\0',
+               dev->hw_geom.sectors, '\0');
+        return 0;
+    }
+
     if ((disk = ped_disk_new(dev)) == NULL) {
         fprintf(stderr, "unable to access disk %s\n", argv[1]);
         return 2;
--- libvirt-0.6.4.org/src/storage_conf.h	2009-06-23 16:46:47.946019000 +0200
+++ libvirt-0.6.4/src/storage_conf.h	2009-06-23 17:38:23.705006000 +0200
@@ -188,6 +188,13 @@ struct _virStoragePoolSourceDevice {
     virStoragePoolSourceDeviceExtentPtr freeExtents;
     char *path;
     int format;     /* Pool specific source format */
+    /* When the source device is a physical disk,
+       the geometry data is needed */
+    struct _geometry {
+        int cyliders;
+        int heads;
+        int sectors;
+    } geometry;
 };
 
 
--- libvirt-0.6.4.org/src/storage_backend_disk.c	2009-06-23 16:46:47.957024000 +0200
+++ libvirt-0.6.4/src/storage_backend_disk.c	2009-06-23 17:47:35.118203000 +0200
@@ -303,6 +303,35 @@ virStorageBackendDiskReadPartitions(virC
                                        vol);
 }
 
+static int
+virStorageBackendDiskMakePoolGeometry(virConnectPtr conn ATTRIBUTE_UNUSED,
+                                     virStoragePoolObjPtr pool,
+                                     size_t ntok ATTRIBUTE_UNUSED,
+                                     char **const groups,
+                                     void *data ATTRIBUTE_UNUSED)
+{
+
+       pool->def->source.devices[0].geometry.cyliders = atoi(groups[0]);
+       pool->def->source.devices[0].geometry.heads = atoi(groups[1]);
+       pool->def->source.devices[0].geometry.sectors = atoi(groups[2]);
+
+       return 0;
+}
+
+static int
+virStorageBackendDiskReadGeometry(virConnectPtr conn, virStoragePoolObjPtr pool)
+{
+    const char *prog[] = {
+        PARTHELPER, pool->def->source.devices[0].path, "-g", NULL,
+    };
+
+    return virStorageBackendRunProgNul(conn,
+                                       pool,
+                                       prog,
+                                       3,
+                                       virStorageBackendDiskMakePoolGeometry,
+                                       NULL);
+}
 
 static int
 virStorageBackendDiskRefreshPool(virConnectPtr conn,
@@ -313,6 +342,10 @@ virStorageBackendDiskRefreshPool(virConn
 
     virStorageBackendWaitForDevices(conn);
 
+    if (virStorageBackendDiskReadGeometry(conn, pool) != 0) {
+	return -1;
+    }
+
     return virStorageBackendDiskReadPartitions(conn, pool, NULL);
 }
 
--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[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]