Hi all,

Currently when calling commit() on a ped_disk, the following happens:
open /dev/sda
write partition table
close /dev/sda
open /dev/sda
ioctl (BLKRRPART)
close /dev/sda

This is rather inefficient, and causes 2 udev change events to be fired
for /dev/sda (+ the change events from the BLKRRPART), causing all kind
of scanning (blkid & friends) twice.

The attached patch fixes things to only open the device once.

Regards,

Hans
diff -up parted-1.9.0/libparted/disk.c~ parted-1.9.0/libparted/disk.c
--- parted-1.9.0/libparted/disk.c~      2009-08-26 10:36:06.000000000 +0200
+++ parted-1.9.0/libparted/disk.c       2009-08-26 13:55:57.000000000 +0200
@@ -513,9 +513,25 @@ error:
 int
 ped_disk_commit (PedDisk* disk)
 {
+        /* Open the device here, so that the underlying fd is not closed
+           between commit_to_dev and commit_to_os (closing causes unwanted
+           udev events to be send under Linux). */
+       if (!ped_device_open (disk->dev))
+               goto error;
+
        if (!ped_disk_commit_to_dev (disk))
-               return 0;
-       return ped_disk_commit_to_os (disk);
+               goto error_close_dev;
+
+       if (!ped_disk_commit_to_os (disk))
+               goto error_close_dev;
+
+       ped_device_close (disk->dev);
+       return 1;
+
+error_close_dev:
+       ped_device_close (disk->dev);
+error:
+       return 0;
 }
 
 /**
_______________________________________________
bug-parted mailing list
bug-parted@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-parted

Reply via email to