On Wed, Jun 24, 2009 at 11:17:49AM +0200, Henrik Persson wrote: > 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); > } > Was rather hoping parted did this kind of alignment for us, but it seems not. ACK to this, since it is internal only and we can change it if a better way turns up in the future. Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :| -- Libvir-list mailing list Libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list