Merge lp:~psusi/ubuntu/raring/parted/resize into lp:ubuntu/raring/parted

Proposed by Phillip Susi on 2013-03-03
Status: Needs review
Proposed branch: lp:~psusi/ubuntu/raring/parted/resize
Merge into: lp:ubuntu/raring/parted
Diff against target: 308 lines (+278/-0)
5 files modified
debian/changelog (+8/-0)
debian/patches/0001-parted-resizepart-command.patch (+134/-0)
debian/patches/0003-libparted-Add-support-for-BLKPG-ioctl-partition-resi.patch (+88/-0)
debian/patches/0004-parted-make-_partition_warn_busy-actually-a-warning-.patch (+45/-0)
debian/patches/series (+3/-0)
To merge this branch: bzr merge lp:~psusi/ubuntu/raring/parted/resize
Reviewer Review Type Date Requested Status
Scott Moser 2013-03-03 Pending
Review via email: mp+151401@code.launchpad.net
To post a comment you must log in.

Unmerged revisions

118. By Phillip Susi on 2013-02-24

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/changelog'
--- debian/changelog 2012-10-23 11:50:25 +0000
+++ debian/changelog 2013-03-03 23:38:21 +0000
@@ -1,3 +1,11 @@
1parted (2.3-11ubuntu2) raring; urgency=low
2
3 * Backport online resize patches: 0001-parted-resizepart-command.patch,
4 0003-libparted-Add-support-for-BLKPG-ioctl-partition-resi.patch,
5 and 0004-parted-make-_partition_warn_busy-actually-a-warning.patch
6
7 -- Phillip Susi <psusi@ubuntu.com> Sun, 24 Feb 2013 12:25:51 -0500
8
1parted (2.3-11ubuntu1) raring; urgency=low9parted (2.3-11ubuntu1) raring; urgency=low
210
3 * Resynchronise with Debian. Remaining changes:11 * Resynchronise with Debian. Remaining changes:
412
=== added file 'debian/patches/0001-parted-resizepart-command.patch'
--- debian/patches/0001-parted-resizepart-command.patch 1970-01-01 00:00:00 +0000
+++ debian/patches/0001-parted-resizepart-command.patch 2013-03-03 23:38:21 +0000
@@ -0,0 +1,134 @@
1From be7c4b8da40aca5296f96d09ae73fbb7f5250b99 Mon Sep 17 00:00:00 2001
2From: Petr Uzel <petr.uzel@suse.cz>
3Date: Mon, 26 Sep 2011 17:21:01 +0200
4Subject: [PATCH 1/6] parted: resizepart command
5
6TODO
7---
8 parted/parted.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
9 1 file changed, 89 insertions(+)
10
11Index: b/parted/parted.c
12===================================================================
13--- a/parted/parted.c
14+++ b/parted/parted.c
15@@ -150,6 +150,9 @@
16 static const char* start_end_msg = N_("START and END are disk locations, such as "
17 "4GB or 10%. Negative values count from the end of the disk. "
18 "For example, -1s specifies exactly the last sector.\n");
19+static const char* end_msg = N_("END is disk location, such as "
20+ "4GB or 10%. Negative value counts from the end of the disk. "
21+ "For example, -1s specifies exactly the last sector.\n");
22 static const char* state_msg = N_("STATE is one of: on, off\n");
23 static const char* device_msg = N_("DEVICE is usually /dev/hda or /dev/sda\n");
24 static const char* name_msg = N_("NAME is any word you want\n");
25@@ -466,6 +469,21 @@
26 return result;
27 }
28
29+
30+static PedConstraint*
31+constraint_from_start_end_fixed_start (PedDevice* dev, PedSector start_sector,
32+ PedGeometry* range_end)
33+{
34+ PedGeometry range_start;
35+ range_start.dev = dev;
36+ range_start.start = start_sector;
37+ range_start.end = start_sector;
38+ range_start.length = 1;
39+
40+ return ped_constraint_new (ped_alignment_any, ped_alignment_any,
41+ &range_start, range_end, 1, dev->length);
42+}
43+
44 void
45 help_on (char* topic)
46 {
47@@ -2004,11 +2022,69 @@
48 }
49
50 static int
51+do_resizepart (PedDevice** dev)
52+{
53+ PedDisk *disk;
54+ PedPartition *part = NULL;
55+ PedSector start, end, oldend;
56+ PedGeometry *range_end = NULL;
57+ PedConstraint* constraint;
58+
59+ disk = ped_disk_new (*dev);
60+ if (!disk)
61+ goto error;
62+
63+ if (ped_disk_is_flag_available(disk, PED_DISK_CYLINDER_ALIGNMENT))
64+ if (!ped_disk_set_flag(disk, PED_DISK_CYLINDER_ALIGNMENT,
65+ alignment == ALIGNMENT_CYLINDER))
66+ goto error;
67+
68+ if (!command_line_get_partition (_("Partition number?"), disk, &part))
69+ goto error;
70+ if (!_partition_warn_busy (part))
71+ goto error;
72+
73+ start = part->geom.start;
74+ end = oldend = part->geom.end;
75+ if (!command_line_get_sector (_("End?"), *dev, &end, &range_end))
76+ goto error;
77+ /* Do not move start of the partition */
78+ constraint = constraint_from_start_end_fixed_start (*dev, start, range_end);
79+ if (!ped_disk_set_partition_geom (disk, part, constraint,
80+ start, end))
81+ goto error_destroy_constraint;
82+ /* warn when shrinking partition - might lose data */
83+ if (part->geom.end < oldend)
84+ if (ped_exception_throw (
85+ PED_EXCEPTION_WARNING,
86+ PED_EXCEPTION_YES_NO,
87+ _("Shrinking a partition can cause data loss, " \
88+ "are you sure you want to continue?")) != PED_EXCEPTION_YES)
89+ goto error_destroy_constraint;
90+ ped_disk_commit (disk);
91+ ped_constraint_destroy (constraint);
92+ if (range_end != NULL)
93+ ped_geometry_destroy (range_end);
94+
95+ if ((*dev)->type != PED_DEVICE_FILE)
96+ disk_is_modified = 1;
97+
98+ return 1;
99+
100+error_destroy_constraint:
101+ ped_constraint_destroy (constraint);
102+error:
103+ if (range_end != NULL)
104+ ped_geometry_destroy (range_end);
105+ return 0;
106+}
107+
108+
109+static int
110 do_rm (PedDevice** dev)
111 {
112- PedDisk* disk;
113+ PedDisk* disk;
114 PedPartition* part = NULL;
115-
116 disk = ped_disk_new (*dev);
117 if (!disk)
118 goto error;
119@@ -2423,6 +2499,15 @@
120 NULL),
121 str_list_create (_(part_type_msg), _(start_end_msg), NULL), 1));
122
123+//XXX: mention that this command does never move start of the partition
124+command_register (commands, command_create (
125+ str_list_create_unique ("resizepart", _("resizepart"), NULL),
126+ do_resizepart,
127+ str_list_create (
128+_("resizepart NUMBER END resize partition NUMBER"),
129+NULL),
130+ str_list_create (_(number_msg), _(end_msg), NULL), 1));
131+
132 command_register (commands, command_create (
133 str_list_create_unique ("move", _("move"), NULL),
134 do_move,
0135
=== added file 'debian/patches/0003-libparted-Add-support-for-BLKPG-ioctl-partition-resi.patch'
--- debian/patches/0003-libparted-Add-support-for-BLKPG-ioctl-partition-resi.patch 1970-01-01 00:00:00 +0000
+++ debian/patches/0003-libparted-Add-support-for-BLKPG-ioctl-partition-resi.patch 2013-03-03 23:38:21 +0000
@@ -0,0 +1,88 @@
1From 6ca0769fcc25f1e4fc7b40769eabd05804670b30 Mon Sep 17 00:00:00 2001
2From: Phillip Susi <psusi@ubuntu.com>
3Date: Tue, 29 Nov 2011 14:05:48 -0500
4Subject: [PATCH 3/6] libparted: Add support for BLKPG ioctl partition resize
5
6When resizing a partition ( same partition number, same
7start sector, different end sector ), if removing the old
8partition fails because it is in use, try to use the
9new BLKPG_RES_PARTITION request to update the kernel
10partition table with the new size.
11---
12 libparted/arch/linux.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++
13 1 file changed, 56 insertions(+)
14
15Index: b/libparted/arch/linux.c
16===================================================================
17--- a/libparted/arch/linux.c
18+++ b/libparted/arch/linux.c
19@@ -2481,6 +2481,53 @@
20 BLKPG_DEL_PARTITION);
21 }
22
23+#ifdef BLKPG_RESIZE_PARTITION
24+static int _blkpg_resize_partition (PedDisk* disk, const PedPartition *part)
25+{
26+ struct blkpg_partition linux_part;
27+ const char* vol_name;
28+ char* dev_name;
29+
30+ PED_ASSERT(disk != NULL, return 0);
31+ PED_ASSERT(disk->dev->sector_size % PED_SECTOR_SIZE_DEFAULT == 0, return 0);
32+
33+ dev_name = _device_get_part_path (disk->dev, part->num);
34+ if (!dev_name)
35+ return 0;
36+ memset (&linux_part, 0, sizeof (linux_part));
37+ linux_part.start = part->geom.start * disk->dev->sector_size;
38+ /* see fs/partitions/msdos.c:msdos_partition(): "leave room for LILO" */
39+ if (part->type & PED_PARTITION_EXTENDED)
40+ linux_part.length = part->geom.length == 1 ? 512 : 1024;
41+ else
42+ linux_part.length = part->geom.length * disk->dev->sector_size;
43+ linux_part.pno = part->num;
44+ strncpy (linux_part.devname, dev_name, BLKPG_DEVNAMELTH);
45+ if (vol_name)
46+ strncpy (linux_part.volname, vol_name, BLKPG_VOLNAMELTH);
47+
48+ free (dev_name);
49+
50+ if (!_blkpg_part_command (disk->dev, &linux_part,
51+ BLKPG_RESIZE_PARTITION)) {
52+ return ped_exception_throw (
53+ PED_EXCEPTION_ERROR,
54+ PED_EXCEPTION_IGNORE_CANCEL,
55+ _("Error informing the kernel about modifications to "
56+ "partition %s -- %s. This means Linux won't know "
57+ "about any changes you made to %s until you reboot "
58+ "-- so you shouldn't mount it or use it in any way "
59+ "before rebooting."),
60+ linux_part.devname,
61+ strerror (errno),
62+ linux_part.devname)
63+ == PED_EXCEPTION_IGNORE;
64+ }
65+
66+ return 1;
67+}
68+#endif
69+
70 /* Read the unsigned long long from /sys/block/DEV_BASE/PART_BASE/ENTRY
71 and set *VAL to that value, where DEV_BASE is the last component of path to
72 block device corresponding to PART and PART_BASE is the sysfs name of PART.
73@@ -2695,6 +2742,15 @@
74 if (start == part->geom.start
75 && length == part->geom.length)
76 ok[i - 1] = 1;
77+#ifdef BLKPG_RESIZE_PARTITION
78+ if (start == part->geom.start
79+ && length != part->geom.length)
80+ {
81+ /* try to resize */
82+ if (_blkpg_resize_partition (disk, part))
83+ ok[i - 1] = 1;
84+ }
85+#endif
86 /* If the new partition is unchanged and the
87 existing one was not removed because it was
88 in use, then reset the error flag and do not
089
=== added file 'debian/patches/0004-parted-make-_partition_warn_busy-actually-a-warning-.patch'
--- debian/patches/0004-parted-make-_partition_warn_busy-actually-a-warning-.patch 1970-01-01 00:00:00 +0000
+++ debian/patches/0004-parted-make-_partition_warn_busy-actually-a-warning-.patch 2013-03-03 23:38:21 +0000
@@ -0,0 +1,45 @@
1From 7ef73999b35294a8fd30f5af4eb6221a0ce62802 Mon Sep 17 00:00:00 2001
2From: Phillip Susi <psusi@ubuntu.com>
3Date: Wed, 30 Nov 2011 13:13:58 -0500
4Subject: [PATCH 4/6] parted: make _partition_warn_busy actually a warning
5 instead of an error
6
7This function was throwing a PED_EXCEPTION_ERROR with only the
8PED_EXCEPTION_CANCEL option. Converted to a PED_EXCEPTION_WARNING
9with the option to continue anyhow.
10---
11 parted/parted.c | 19 +++++++++++--------
12 tests/t1101-busy-partition.sh | 2 +-
13 tests/t9041-undetected-in-use-16th-partition.sh | 4 ++--
14 3 files changed, 14 insertions(+), 11 deletions(-)
15
16Index: b/parted/parted.c
17===================================================================
18--- a/parted/parted.c
19+++ b/parted/parted.c
20@@ -224,14 +224,17 @@
21
22 if (ped_partition_is_busy (part)) {
23 path = ped_partition_get_path (part);
24- ped_exception_throw (
25- PED_EXCEPTION_ERROR,
26- PED_EXCEPTION_CANCEL,
27- _("Partition %s is being used. You must unmount it "
28- "before you modify it with Parted."),
29- path);
30- free (path);
31- return 0;
32+ if (ped_exception_throw (
33+ PED_EXCEPTION_WARNING,
34+ PED_EXCEPTION_YES_NO,
35+ _("Partition %s is being used. Are you sure you " \
36+ "want to continue?"),
37+ path) != PED_EXCEPTION_YES)
38+ {
39+ free (path);
40+ return 0;
41+ }
42+ free (path);
43 }
44 return 1;
45 }
046
=== modified file 'debian/patches/series'
--- debian/patches/series 2012-10-23 11:50:25 +0000
+++ debian/patches/series 2013-03-03 23:38:21 +0000
@@ -44,3 +44,6 @@
4444
45# Ubuntu FTBFS eglibc-2.1645# Ubuntu FTBFS eglibc-2.16
46gnulib-gets.patch46gnulib-gets.patch
470001-parted-resizepart-command.patch
480003-libparted-Add-support-for-BLKPG-ioctl-partition-resi.patch
490004-parted-make-_partition_warn_busy-actually-a-warning-.patch

Subscribers

People subscribed via source and target branches

to all changes: