1
Author: Phillip Susi <psusi@ubuntu.com>
2
Description: The partition sync logic was first removing all
3
partitions, then trying to re-add them. This resulted in many
4
udev events triggering annoying behavior like auto mounting.
5
Refactor the code to avoid removing and re-adding unmodified
8
--- a/libparted/arch/linux.c
9
+++ b/libparted/arch/linux.c
10
@@ -2705,60 +2705,52 @@
11
int *errnums = ped_malloc(sizeof(int) * lpn);
15
- /* Attempt to remove each and every partition, retrying for
16
- up to max_sleep_seconds upon any failure due to EBUSY. */
17
- unsigned int sleep_microseconds = 10000;
18
- unsigned int max_sleep_seconds = 1;
19
- unsigned int n_sleep = (max_sleep_seconds
20
- * 1000000 / sleep_microseconds);
22
- for (i = 0; i < n_sleep; i++) {
24
- usleep (sleep_microseconds);
27
- for (j = 0; j < lpn; j++) {
29
- ok[j] = remove_partition (disk, j + 1);
31
- if (!ok[j] && errnums[j] == EBUSY)
39
for (i = 1; i <= lpn; i++) {
40
PedPartition *part = ped_disk_get_partition (disk, i);
42
- if (!ok[i - 1] && errnums[i - 1] == EBUSY) {
43
- unsigned long long length;
44
- unsigned long long start;
45
- /* get start and length of existing partition */
46
- if (!get_partition_start_and_length(part,
49
- if (start == part->geom.start
50
- && length == part->geom.length)
52
+ unsigned long long length;
53
+ unsigned long long start;
54
+ /* get start and length of existing partition */
55
+ if (!get_partition_start_and_length(part,
57
+ goto remove_partition;
58
+ if (start == part->geom.start
59
+ && length == part->geom.length)
64
#ifdef BLKPG_RESIZE_PARTITION
65
- if (start == part->geom.start
66
- && length != part->geom.length)
67
+ if (start == part->geom.start
68
+ && length != part->geom.length)
71
+ if (_blkpg_resize_partition (disk, part))
74
- if (_blkpg_resize_partition (disk, part))
80
- /* If the new partition is unchanged and the
81
- existing one was not removed because it was
82
- in use, then reset the error flag and do not
83
- try to add it since it is already there. */
89
+ /* Attempt to remove the partition, retrying for
90
+ up to max_sleep_seconds upon any failure due to EBUSY. */
91
+ unsigned int sleep_microseconds = 10000;
92
+ unsigned int max_sleep_seconds = 1;
93
+ unsigned int n_sleep = (max_sleep_seconds
94
+ * 1000000 / sleep_microseconds);
97
+ ok[i-1] = remove_partition (disk, i);
98
+ errnums[i-1] = errno;
99
+ if (ok[i-1] || errnums[i-1] != EBUSY)
101
+ usleep (sleep_microseconds);
102
+ } while (n_sleep--);
103
+ if (!ok[i-1] && errnums[i-1] == ENXIO)
104
+ ok[i-1] = 1; /* it already doesn't exist */
105
+ if (part && ok[i-1]) {
106
/* add the (possibly modified or new) partition */
107
if (!add_partition (disk, part)) {
108
ped_exception_throw (
109
@@ -2768,6 +2760,7 @@
110
i, strerror (errno));