From unknown Fri Jun 20 07:15:47 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#15491 <15491@debbugs.gnu.org> To: bug#15491 <15491@debbugs.gnu.org> Subject: Status: [PATCH] libparted: avoid disturbing partitions Reply-To: bug#15491 <15491@debbugs.gnu.org> Date: Fri, 20 Jun 2025 14:15:47 +0000 retitle 15491 [PATCH] libparted: avoid disturbing partitions reassign 15491 parted submitter 15491 Phillip Susi severity 15491 normal tag 15491 patch thanks From debbugs-submit-bounces@debbugs.gnu.org Sun Sep 29 22:19:28 2013 Received: (at submit) by debbugs.gnu.org; 30 Sep 2013 02:19:28 +0000 Received: from localhost ([127.0.0.1]:45341 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VQT55-0001e7-UW for submit@debbugs.gnu.org; Sun, 29 Sep 2013 22:19:28 -0400 Received: from eggs.gnu.org ([208.118.235.92]:49622) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VQT53-0001dz-L9 for submit@debbugs.gnu.org; Sun, 29 Sep 2013 22:19:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VQT4u-0000s4-7D for submit@debbugs.gnu.org; Sun, 29 Sep 2013 22:19:25 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=BAYES_40 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:36592) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VQT4u-0000s0-4A for submit@debbugs.gnu.org; Sun, 29 Sep 2013 22:19:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51283) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VQT4m-0000j3-P5 for bug-parted@gnu.org; Sun, 29 Sep 2013 22:19:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VQT4b-0000pi-F6 for bug-parted@gnu.org; Sun, 29 Sep 2013 22:19:08 -0400 Received: from cdptpa-omtalb.mail.rr.com ([75.180.132.120]:35575) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VQT4b-0000ol-AS for bug-parted@gnu.org; Sun, 29 Sep 2013 22:18:57 -0400 X-Authority-Analysis: v=2.0 cv=aItyWMBm c=1 sm=0 a=3SewDSjaRW4vdJyuxQ33ZQ==:17 a=DeBnktw0k-IA:10 a=I0QiU5h8WSQA:10 a=S1A5HrydsesA:10 a=fxJcL_dCAAAA:8 a=KGjhK52YXX0A:10 a=wNgh-K-fkMYA:10 a=lEEuysEHwMbBY8NwMy4A:9 a=x2EwGivjjUOjJvye:21 a=BC9GMrilcduq6lgg:21 a=3SewDSjaRW4vdJyuxQ33ZQ==:117 X-Cloudmark-Score: 0 X-Authenticated-User: X-Originating-IP: 72.238.73.171 Received: from [72.238.73.171] ([72.238.73.171:39904] helo=localhost.localdomain) by cdptpa-oedge01.mail.rr.com (envelope-from ) (ecelerity 2.2.3.46 r()) with ESMTP id E4/3E-06587-F8FD8425; Mon, 30 Sep 2013 02:18:55 +0000 From: Phillip Susi To: bug-parted@gnu.org Subject: [PATCH] libparted: avoid disturbing partitions Date: Sun, 29 Sep 2013 22:18:54 -0400 Message-Id: <1380507535-28030-1-git-send-email-psusi@ubuntu.com> X-Mailer: git-send-email 1.8.1.2 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) The partition sync logic was first removing all partitions, then trying to re-add them. This resulted in many udev events triggering annoying behavior like auto mounting. Refactor the code to avoid removing and re-adding unmodified partitions. --- libparted/arch/linux.c | 69 +++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 38 deletions(-) diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c index 4b1b438..d3a03d6 100644 --- a/libparted/arch/linux.c +++ b/libparted/arch/linux.c @@ -2670,6 +2670,11 @@ _dm_get_partition_start_and_length(PedPartition const *part, return 0; char *path = _device_get_part_path (part->disk->dev, part->num); PED_ASSERT(path); + /* libdevmapper likes to complain on stderr instead of quietly + returning ENOENT or ENXIO, so try to stat first */ + struct stat st; + if (stat(path, &st)) + goto err; dm_task_set_name(task, path); if (!dm_task_run(task)) goto err; @@ -2806,50 +2811,38 @@ _disk_sync_part_table (PedDisk* disk) if (!errnums) goto cleanup; - /* Attempt to remove each and every 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 n_sleep = (max_sleep_seconds - * 1000000 / sleep_microseconds); int i; - for (i = 0; i < n_sleep; i++) { - if (i) - usleep (sleep_microseconds); - bool busy = false; - int j; - for (j = 0; j < lpn; j++) { - if (!ok[j]) { - ok[j] = remove_partition (disk, j + 1); - errnums[j] = errno; - if (!ok[j] && errnums[j] == EBUSY) - busy = true; - } - } - if (!busy) - break; - } - for (i = 1; i <= lpn; i++) { PedPartition *part = ped_disk_get_partition (disk, i); if (part) { - if (!ok[i - 1] && errnums[i - 1] == EBUSY) { - unsigned long long length; - unsigned long long start; - /* get start and length of existing partition */ - if (!get_partition_start_and_length(part, - &start, &length)) - goto cleanup; - if (start == part->geom.start - && length == part->geom.length) - ok[i - 1] = 1; - /* If the new partition is unchanged and the - existing one was not removed because it was - in use, then reset the error flag and do not - try to add it since it is already there. */ + unsigned long long length; + unsigned long long start; + /* get start and length of existing partition */ + if (get_partition_start_and_length(part, + &start, &length) + && start == part->geom.start + && length == part->geom.length) { + ok[i - 1] = 1; + /* partition is unchanged, so nothing to do */ continue; } - + } + /* 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 n_sleep = (max_sleep_seconds + * 1000000 / sleep_microseconds); + do { + ok[i - 1] = remove_partition (disk, i); + errnums[i - 1] = errno; + if (ok[i - 1] || errnums[i - 1] != EBUSY) + break; + usleep (sleep_microseconds); + } while (n_sleep--); + if (!ok[i - 1] && errnums[i - 1] == ENXIO) + ok[i - 1] = 1; /* it already doesn't exist */ + if (part && ok[i - 1]) { /* add the (possibly modified or new) partition */ if (!add_partition (disk, part)) { ok[i - 1] = 0; -- 1.8.1.2 From debbugs-submit-bounces@debbugs.gnu.org Sun Nov 17 23:20:18 2013 Received: (at 15491) by debbugs.gnu.org; 18 Nov 2013 04:20:18 +0000 Received: from localhost ([127.0.0.1]:59314 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ViGJt-0001YM-2m for submit@debbugs.gnu.org; Sun, 17 Nov 2013 23:20:17 -0500 Received: from cdptpa-omtalb.mail.rr.com ([75.180.132.120]:43150) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ViGJs-0001Y8-1h for 15491@debbugs.gnu.org; Sun, 17 Nov 2013 23:20:16 -0500 X-Authority-Analysis: v=2.0 cv=UpLhxpMB c=1 sm=0 a=3SewDSjaRW4vdJyuxQ33ZQ==:17 a=DeBnktw0k-IA:10 a=AizhB-pfR1kA:10 a=4RM3G5GzZfQA:10 a=S1A5HrydsesA:10 a=8nJEP1OIZ-IA:10 a=fxJcL_dCAAAA:8 a=KGjhK52YXX0A:10 a=XBKX86WKqV0A:10 a=QfKxxUxMAAAA:8 a=Sz6FQ2mQPZTZpd3SRlUA:9 a=wPNLvfGTeEIA:10 a=3SewDSjaRW4vdJyuxQ33ZQ==:117 X-Cloudmark-Score: 0 X-Authenticated-User: X-Originating-IP: 72.238.73.171 Received: from [72.238.73.171] ([72.238.73.171:45054] helo=[192.168.1.6]) by cdptpa-oedge04.mail.rr.com (envelope-from ) (ecelerity 2.2.3.46 r()) with ESMTP id 27/41-07922-A7599825; Mon, 18 Nov 2013 04:20:10 +0000 Message-ID: <5289957A.2010909@ubuntu.com> Date: Sun, 17 Nov 2013 23:20:10 -0500 From: Phillip Susi User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 MIME-Version: 1.0 To: 15491@debbugs.gnu.org Subject: Re: bug#15491: [PATCH] libparted: avoid disturbing partitions References: <1380507535-28030-1-git-send-email-psusi@ubuntu.com> In-Reply-To: <1380507535-28030-1-git-send-email-psusi@ubuntu.com> X-Enigmail-Version: 1.6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 15491 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 I had to revise this patch because it caused failures to update the partition table when lower numbered partitions that had been added or removed overlapped with higher numbered partitions that had been removed or changed ( and not yet removed/changed at the time the lower partition is processed ). So I fixed it to try to remove all partitions that are not unchanged first, then add/resize. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.14 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCgAGBQJSiZV6AAoJEJrBOlT6nu756mIH/1J7un4cXEkJVIq8g65CLTZa BpbxnZkwLMHUagz644vmHxBY+erVLtouN8f5/pki80murF6z7u27wGUfjRcgjf3B wWPqg+2VKFc6iM6VlPIy6IP8ATXe8ym62RHak6xgpq9TGBDK0yIjB7vAi/2KCFLE x2LWbI94pR90WlpZfgtrsJxCfCjINlrXbJuBAPIiL958KyllwOFD4DPxv6L89ZLU a+oD0ANpF544OJJmYtpZ/NCefZrIDc9inHpgcLivlzTdQKhODKK3ROT9Q5VtWRP8 NAe8m3kXxcyCXgms32NXiWnKio38owHuOBy04dlliHVBHURTgwfLtFAz5IV9BSo= =SBMT -----END PGP SIGNATURE----- From debbugs-submit-bounces@debbugs.gnu.org Sun Nov 17 23:22:01 2013 Received: (at 15491) by debbugs.gnu.org; 18 Nov 2013 04:22:01 +0000 Received: from localhost ([127.0.0.1]:59318 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ViGLZ-0001b1-8p for submit@debbugs.gnu.org; Sun, 17 Nov 2013 23:22:01 -0500 Received: from cdptpa-omtalb.mail.rr.com ([75.180.132.120]:43261) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ViGLW-0001an-HZ for 15491@debbugs.gnu.org; Sun, 17 Nov 2013 23:21:58 -0500 X-Authority-Analysis: v=2.0 cv=FKiZNpUs c=1 sm=0 a=3SewDSjaRW4vdJyuxQ33ZQ==:17 a=DeBnktw0k-IA:10 a=I0QiU5h8WSQA:10 a=S1A5HrydsesA:10 a=fxJcL_dCAAAA:8 a=KGjhK52YXX0A:10 a=wNgh-K-fkMYA:10 a=LsaQ4rqtewAJi6Cl9k0A:9 a=zpI43annioIhtbOV:21 a=-GfkUTbE6eVOp9EN:21 a=3SewDSjaRW4vdJyuxQ33ZQ==:117 X-Cloudmark-Score: 0 X-Authenticated-User: X-Originating-IP: 72.238.73.171 Received: from [72.238.73.171] ([72.238.73.171:45056] helo=localhost.localdomain) by cdptpa-oedge03.mail.rr.com (envelope-from ) (ecelerity 2.2.3.46 r()) with ESMTP id 8E/35-01931-1E599825; Mon, 18 Nov 2013 04:21:53 +0000 From: Phillip Susi To: 15491@debbugs.gnu.org Subject: [PATCH] libparted: avoid disturbing partitions Date: Sun, 17 Nov 2013 23:21:52 -0500 Message-Id: <1384748512-32694-1-git-send-email-psusi@ubuntu.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <5289957A.2010909@ubuntu.com> References: <5289957A.2010909@ubuntu.com> X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 15491 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) The partition sync logic was first removing all partitions, then trying to re-add them. This resulted in many udev events triggering annoying behavior like auto mounting. Refactor the code to avoid removing and re-adding unmodified partitions. --- libparted/arch/linux.c | 84 ++++++++++++++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 37 deletions(-) diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c index 4b1b438..f43eae1 100644 --- a/libparted/arch/linux.c +++ b/libparted/arch/linux.c @@ -2670,6 +2670,11 @@ _dm_get_partition_start_and_length(PedPartition const *part, return 0; char *path = _device_get_part_path (part->disk->dev, part->num); PED_ASSERT(path); + /* libdevmapper likes to complain on stderr instead of quietly + returning ENOENT or ENXIO, so try to stat first */ + struct stat st; + if (stat(path, &st)) + goto err; dm_task_set_name(task, path); if (!dm_task_run(task)) goto err; @@ -2806,50 +2811,55 @@ _disk_sync_part_table (PedDisk* disk) if (!errnums) goto cleanup; - /* Attempt to remove each and every 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 n_sleep = (max_sleep_seconds - * 1000000 / sleep_microseconds); int i; - for (i = 0; i < n_sleep; i++) { - if (i) - usleep (sleep_microseconds); - bool busy = false; - int j; - for (j = 0; j < lpn; j++) { - if (!ok[j]) { - ok[j] = remove_partition (disk, j + 1); - errnums[j] = errno; - if (!ok[j] && errnums[j] == EBUSY) - busy = true; + /* remove old partitions first */ + for (i = 1; i <= lpn; i++) { + PedPartition *part = ped_disk_get_partition (disk, i); + if (part) { + unsigned long long length; + unsigned long long start; + /* get start and length of existing partition */ + if (get_partition_start_and_length(part, + &start, &length) + && start == part->geom.start + && length == part->geom.length) + { + ok[i - 1] = 1; + continue; + } } - } - if (!busy) - break; - } - + } for (i = 1; i <= lpn; i++) { PedPartition *part = ped_disk_get_partition (disk, i); if (part) { - if (!ok[i - 1] && errnums[i - 1] == EBUSY) { - unsigned long long length; - unsigned long long start; - /* get start and length of existing partition */ - if (!get_partition_start_and_length(part, - &start, &length)) - goto cleanup; - if (start == part->geom.start - && length == part->geom.length) - ok[i - 1] = 1; - /* If the new partition is unchanged and the - existing one was not removed because it was - in use, then reset the error flag and do not - try to add it since it is already there. */ + unsigned long long length; + unsigned long long start; + /* get start and length of existing partition */ + if (get_partition_start_and_length(part, + &start, &length) + && start == part->geom.start + && length == part->geom.length) { + ok[i - 1] = 1; + /* partition is unchanged, so nothing to do */ continue; } - + } + /* 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 n_sleep = (max_sleep_seconds + * 1000000 / sleep_microseconds); + do { + ok[i - 1] = remove_partition (disk, i); + errnums[i - 1] = errno; + if (ok[i - 1] || errnums[i - 1] != EBUSY) + break; + usleep (sleep_microseconds); + } while (n_sleep--); + if (!ok[i - 1] && errnums[i - 1] == ENXIO) + ok[i - 1] = 1; /* it already doesn't exist */ + if (part && ok[i - 1]) { /* add the (possibly modified or new) partition */ if (!add_partition (disk, part)) { ok[i - 1] = 0; -- 1.8.3.2 From debbugs-submit-bounces@debbugs.gnu.org Sat Nov 23 22:00:16 2013 Received: (at 15491-done) by debbugs.gnu.org; 24 Nov 2013 03:00:16 +0000 Received: from localhost ([127.0.0.1]:41069 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VkPvj-0000OM-B9 for submit@debbugs.gnu.org; Sat, 23 Nov 2013 22:00:15 -0500 Received: from cdptpa-omtalb.mail.rr.com ([75.180.132.120]:46299) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VkPve-0000NB-Jo; Sat, 23 Nov 2013 22:00:11 -0500 X-Authority-Analysis: v=2.0 cv=CLiorGXD c=1 sm=0 a=3SewDSjaRW4vdJyuxQ33ZQ==:17 a=DeBnktw0k-IA:10 a=JlIHnqCoHBcA:10 a=qHGamGaSwooA:10 a=S1A5HrydsesA:10 a=8nJEP1OIZ-IA:10 a=fxJcL_dCAAAA:8 a=KGjhK52YXX0A:10 a=GqfOtW4sZfIA:10 a=QfKxxUxMAAAA:8 a=zDTgnsAXjy1L-NlmqZAA:9 a=wPNLvfGTeEIA:10 a=3SewDSjaRW4vdJyuxQ33ZQ==:117 X-Cloudmark-Score: 0 X-Authenticated-User: X-Originating-IP: 72.238.73.171 Received: from [72.238.73.171] ([72.238.73.171:42965] helo=[192.168.1.6]) by cdptpa-oedge03.mail.rr.com (envelope-from ) (ecelerity 2.2.3.46 r()) with ESMTP id 31/75-07327-4BB61925; Sun, 24 Nov 2013 03:00:05 +0000 Message-ID: <52916BB4.8070306@ubuntu.com> Date: Sat, 23 Nov 2013 22:00:04 -0500 From: Phillip Susi User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.1 MIME-Version: 1.0 To: 15299-done@debbugs.gnu.org, 15579-done@debbugs.gnu.org, 15491-done@debbugs.gnu.org Subject: Re: bug#15299: [PATCH 1/9] parted: fix EOF and ctrl-c handling References: <1372648321-1631-1-git-send-email-psusi@ubuntu.com> <20130809004517.GQ3094@lister.brianlane.com> <520AFDA4.7060602@ubuntu.com> <522B5483.1000503@ubuntu.com> In-Reply-To: <522B5483.1000503@ubuntu.com> X-Enigmail-Version: 1.6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 15491-done X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 Patches pushed. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.14 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCgAGBQJSkWu0AAoJEJrBOlT6nu75jvEH/0YAeaOBrU/ANr8yIqNyb51t YYwS16WiiIi9MQ5dBL4pxamSWYVZWo56SwxL3VE0U3JgjuYFcQ/frc3DvLGE6Zbq 4UszohWAsBftn4N4bQJlq6sWewN3R4bbauVUfwEHv9B4KgFnyDkomELseFyNgYL9 y33ZMLEQpIKkD5JM8jL/xb48V71J8kkVU/4vLGVUT4xF5ZswCXixKDqCpjlbvhzE e+r172v0hIkIE9VE5ZtsvyRdebjZuNRYYuQSCkh+9Vr4Xbk+erB9Uz0paApwyVV9 iNfVS0s8K0oDBpOdpYpWgRkn7+SA6SQoPR5oCSTkkE9lmUXAUfu3/f5L+J1crv0= =gQOi -----END PGP SIGNATURE----- From unknown Fri Jun 20 07:15:47 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sun, 22 Dec 2013 12:24:05 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator