From 679ea1e5ab5c570b461cf3dacfe0fb61a04e9d79 Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Sun, 5 Mar 2017 19:08:06 +0000 Subject: When writing a GPT partition table, merge all actions into a single commit. This avoids unnecessary udev events, which in some cases were causing udevd to trigger a kernel partition table reread, causing the kernel to get out of sync with drakx. In order to do so, the libparted bindings are enhanced so that we manipulate a 'ped_disk' object: - disk_open() returns such an object - set_disk_type() is removed - disk_commit() writes back the partition table and tell the kernel about it if we fails to write the partition table, we let partition_table::write() fire an exceptionc if we only have succeed in writing the partition table, we let partition_table::write() try harder (umounting partitions before trying againt to tell the kernel again) - need_to_tell_kernel() is overrided The last change is needed because we now tell the kernel about the new partition layout in partition_table::gpt::write() when calling disk_commit() while previously we were deferring that to partition_table::write() which after having called the gpt's write() calls tell_kernel() -> c::tell_kernel_to_reread_partition_table() So we must tell partition_table::write() that telling the kernel to reread the partition_table is not needed if we already succeeded in that. --- perl-install/c/stuff.xs.pl | 132 +++++++++++++++++++++------------------------ 1 file changed, 60 insertions(+), 72 deletions(-) (limited to 'perl-install/c') diff --git a/perl-install/c/stuff.xs.pl b/perl-install/c/stuff.xs.pl index e255b570f..1a148b497 100755 --- a/perl-install/c/stuff.xs.pl +++ b/perl-install/c/stuff.xs.pl @@ -610,25 +610,23 @@ get_iso_volume_ids(int fd) print ' +TYPEMAP: <dev, (long long)start, (long long)length); + PedPartition* part = ped_partition_new (disk, PED_PARTITION_NORMAL, ped_file_system_type_get(fs_type), (long long)start, (long long)start+length-1); + PedConstraint* constraint = ped_constraint_new_from_max(geom); + if(!part) { + printf("ped_partition_new failed\n"); + } else { + RETVAL = ped_disk_add_partition (disk, part, constraint); + } + ped_geometry_destroy(geom); + ped_constraint_destroy(constraint); + OUTPUT: + RETVAL + +int +disk_commit(PedDisk *disk) + CODE: + RETVAL = 0; + /* As done in ped_disk_commit(), open the device here, so that the underlying + file descriptor is not closed between the call to ped_disk_commit_to_dev() + and the call to ped_disk_commit_to_os(). This avoids unwanted udev events. */ + if (ped_device_open(disk->dev)) { + if (ped_disk_commit_to_dev(disk)) { + RETVAL = 1; + if (ped_disk_commit_to_os(disk)) { + RETVAL = 2; } - ped_geometry_destroy(geom); - ped_constraint_destroy(constraint); - ped_disk_destroy(disk); } + ped_device_close(disk->dev); } + ped_disk_destroy(disk); OUTPUT: RETVAL -- cgit v1.2.1