~ubuntu-branches/ubuntu/utopic/parted/utopic-proposed

« back to all changes in this revision

Viewing changes to debian/patches/avoid-disturbing-partitions.patch

  • Committer: Package Import Robot
  • Author(s): Phillip Susi
  • Date: 2013-08-12 10:11:10 UTC
  • mfrom: (7.2.25 sid)
  • Revision ID: package-import@ubuntu.com-20130812101110-b6xi9i5tcoq7deo0
Tags: 2.3-14
* Merge fix-head-size-assertion.patch from Ubuntu: change an
  assert so it correctly recovers instead of aborting the program
  (closes: #620273).
* Merge dm_p_separator.patch from Ubuntu: parted would add a
  'p' between the base device name and the partition number for
  all device-mapper devices instead of only if the base name
  ended in a digit.
* Merge remove-dev_t-dep.patch from Ubuntu: parted was making
  bad assumptions about the meaning of the values of dev_t,
  causing it to fail to detect in-use partitions on all dmraid
  disks, and regular disk partitions > #16.
* Merge skip-floppy.patch from Ubuntu: add floppies to the list
  of ignored devices since they can not be partitioned anyhow,
  and often people have no floppy though their bios thinks they do,
  and touching it causes hangs.
* Merge gptsync.patch from Ubuntu: On Intel Mac systems, write a
  synced MBR rather than a protective MBR.
* Merge loop-partitions.patch from Ubuntu: backport some changes
  to allow the use of partitions on loop devices.  This also
  allows more than 16 partitions.
* Merge dmraid.patch from Ubuntu: Don't probe dmraid partition
  devices.  Also set UUID of newly created dmraid partition devices.
* Merge dm-part-sync.patch from Ubuntu: refactor device-mapper
  partition sync code so it does not fail when unmodified partitions
  are mounted.
* Merge udevadm-settle.patch from Ubuntu: Run udevadm settle around
  partition table rereads, to avoid races.
* Merge 16-dos-partitions.patch from Ubuntu: the kernel was not
  being informed of partitions above #16 on dos partition tables
  (closes: #667638).
* Merge hfs-probe-corrupt.patch from Ubuntu: don't let a corrupt
  FS evoke failed assertion.
* Backport online resize patches: 0001-parted-resizepart-command.patch,
  0003-libparted-Add-support-for-BLKPG-ioctl-partition-resi.patch,
  and 0004-parted-make-_partition_warn_busy-actually-a-warning.patch
* Merge fewer-gpt-entries.patch: Backport upstream patches to handle
  GPT labels with fewer than 128 partition entries (LP: #1187560).
* debian/patches/avoid-disturbing-partitions.patch: Don't remove and
  re-add unmodified partitions (LP: #1060484).
* debian/patches/linux-specific-gpt-type.patch: Backport upstream
  changes to use a linux specific partition type code instead of
  Microsoft's, which causes Windows to offer to format the partition.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
6
 partitions.
 
7
 
 
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);
 
12
         if (!errnums)
 
13
                 goto cleanup;
 
14
-
 
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);
 
21
         int i;
 
22
-        for (i = 0; i < n_sleep; i++) {
 
23
-           if (i)
 
24
-               usleep (sleep_microseconds);
 
25
-            bool busy = false;
 
26
-            int j;
 
27
-            for (j = 0; j < lpn; j++) {
 
28
-                if (!ok[j]) {
 
29
-                    ok[j] = remove_partition (disk, j + 1);
 
30
-                    errnums[j] = errno;
 
31
-                    if (!ok[j] && errnums[j] == EBUSY)
 
32
-                        busy = true;
 
33
-                }
 
34
-            }
 
35
-            if (!busy)
 
36
-                break;
 
37
-        }
 
38
-
 
39
         for (i = 1; i <= lpn; i++) {
 
40
                 PedPartition *part = ped_disk_get_partition (disk, i);
 
41
                 if (part) {
 
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,
 
47
-                                                                    &start, &length))
 
48
-                                          goto cleanup;
 
49
-                                if (start == part->geom.start
 
50
-                                   && length == part->geom.length)
 
51
-                                        ok[i - 1] = 1;
 
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,
 
56
+                                                            &start, &length))
 
57
+                                goto remove_partition;
 
58
+                        if (start == part->geom.start
 
59
+                            && length == part->geom.length)
 
60
+                        {
 
61
+                                ok[i - 1] = 1;
 
62
+                                continue;
 
63
+                        }
 
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)
 
69
+                        {
 
70
+                                /* try to resize */
 
71
+                                if (_blkpg_resize_partition (disk, part))
 
72
                                 {
 
73
-                                        /* try to resize */
 
74
-                                        if (_blkpg_resize_partition (disk, part))
 
75
-                                                ok[i - 1] = 1;
 
76
+                                        ok[i - 1] = 1;
 
77
+                                        continue;
 
78
                                 }
 
79
-#endif
 
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.  */
 
84
-                                continue;
 
85
                         }
 
86
-
 
87
+#endif
 
88
+                }
 
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);
 
95
+       remove_partition:
 
96
+                do {
 
97
+                        ok[i-1] = remove_partition (disk, i);
 
98
+                        errnums[i-1] = errno;
 
99
+                        if (ok[i-1] || errnums[i-1] != EBUSY)
 
100
+                                break;
 
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));
 
111
                                 goto cleanup;
 
112
                         }
 
113
+                       ok[i-1] = 1;
 
114
                 }
 
115
         }
 
116