File more-reliable-informing-the-kernel.patch of Package parted.30108

From: Petr Uzel <petr.uzel@suse.cz>
Subject: parted: Make informing the kernel more reliable
References: bnc#657360
Patch-mainline: no

This patch should make parted's process of informing the kernel
about changes of partition table sligtly more reliable.
It consists of 2 quite unrelated parts:

* increase the max sleep time if partition is busy from 1 to 2 seconds
* do not inform the kernel when only partition flags change - kernel
  does not care about the flags
---
 libparted/arch/linux.c |    2 +-
 parted/parted.c        |   28 +++++++++++++++++++++++++++-
 2 files changed, 28 insertions(+), 2 deletions(-)

--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -2858,7 +2858,7 @@ _disk_sync_part_table (PedDisk* disk)
                 /* Attempt to remove the partition, retrying for
                    up to max_sleep_seconds upon any failure due to EBUSY. */
                 unsigned int sleep_microseconds = 10000;
-                unsigned int max_sleep_seconds = 1;
+                unsigned int max_sleep_seconds = 2;
                 unsigned int n_sleep = (max_sleep_seconds
                                         * 1000000 / sleep_microseconds);
                 do {
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -258,6 +258,32 @@ _disk_warn_loss (PedDisk* disk)
                 disk->dev->path) == PED_EXCEPTION_YES;
 }
 
+/*
+ * Copied from ped_disk_commit() but removed the ped_disk_commit_to_os. We use
+ * this function in do_set - BLKPG* ioctls() does not care about the partition
+ * flags anyway.
+ */
+static int
+ped_disk_commit_just_to_disk (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 sent under Linux). */
+	if (!ped_device_open (disk->dev))
+		goto error;
+
+	if (!ped_disk_commit_to_dev (disk))
+		goto error_close_dev;
+
+	ped_device_close (disk->dev);
+	return 1;
+
+error_close_dev:
+	ped_device_close (disk->dev);
+error:
+	return 0;
+}
+
 /* This function changes "sector" to "new_sector" if the new value lies
  * within the required range.
  */
@@ -1643,7 +1669,7 @@ do_set (PedDevice** dev)
 
         if (!ped_partition_set_flag (part, flag, state))
 	        	goto error_destroy_disk;
-    	if (!ped_disk_commit (disk))
+    	if (!ped_disk_commit_just_to_disk (disk))
 	        	goto error_destroy_disk;
     	ped_disk_destroy (disk);
 
openSUSE Build Service is sponsored by