GNU logs - #15490, boring messages


Message sent to bug-parted@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#15490: [PATCH] Refactor device canonicalization
Resent-From: Phillip Susi <psusi@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-parted@HIDDEN
Resent-Date: Mon, 30 Sep 2013 02:20:02 +0000
Resent-Message-ID: <handler.15490.B.13805075596311 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: report 15490
X-GNU-PR-Package: parted
X-GNU-PR-Keywords: patch
To: 15490 <at> debbugs.gnu.org
X-Debbugs-Original-To: bug-parted@HIDDEN
Received: via spool by submit <at> debbugs.gnu.org id=B.13805075596311
          (code B ref -1); Mon, 30 Sep 2013 02:20:02 +0000
Received: (at submit) by debbugs.gnu.org; 30 Sep 2013 02:19:19 +0000
Received: from localhost ([127.0.0.1]:45338 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1VQT4v-0001di-N3
	for submit <at> debbugs.gnu.org; Sun, 29 Sep 2013 22:19:18 -0400
Received: from eggs.gnu.org ([208.118.235.92]:49587)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <psusi@HIDDEN>) id 1VQT4s-0001dZ-LB
 for submit <at> debbugs.gnu.org; Sun, 29 Sep 2013 22:19:15 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <psusi@HIDDEN>) id 1VQT4o-0000rB-4j
 for submit <at> debbugs.gnu.org; Sun, 29 Sep 2013 22:19:14 -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.8 required=5.0 tests=BAYES_50 autolearn=disabled
 version=3.3.2
Received: from lists.gnu.org ([2001:4830:134:3::11]:45138)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <psusi@HIDDEN>) id 1VQT4o-0000r6-1O
 for submit <at> debbugs.gnu.org; Sun, 29 Sep 2013 22:19:10 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:51271)
 by lists.gnu.org with esmtp (Exim 4.71)
 (envelope-from <psusi@HIDDEN>) id 1VQT4j-0000j0-Sg
 for bug-parted@HIDDEN; Sun, 29 Sep 2013 22:19:09 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <psusi@HIDDEN>) id 1VQT4b-0000po-Kn
 for bug-parted@HIDDEN; Sun, 29 Sep 2013 22:19:05 -0400
Received: from cdptpa-omtalb.mail.rr.com ([75.180.132.120]:35575)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <psusi@HIDDEN>) id 1VQT4b-0000ol-Fn
 for bug-parted@HIDDEN; 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=S1A5HrydsesA:10 a=fxJcL_dCAAAA:8 a=KGjhK52YXX0A:10
 a=WWPDmsuk3mkA:10 a=mDV3o1hIAAAA:8 a=IEpHJuUJd4AQPiufyWcA:9
 a=LVIKo3jbQPFQ94In:21 a=9e50RpS1IKJK-Hs6: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 <psusi@HIDDEN>)
 (ecelerity 2.2.3.46 r()) with ESMTP
 id F5/3E-06587-F8FD8425; Mon, 30 Sep 2013 02:18:56 +0000
From: Phillip Susi <psusi@HIDDEN>
Date: Sun, 29 Sep 2013 22:18:55 -0400
Message-Id: <1380507535-28030-2-git-send-email-psusi@HIDDEN>
X-Mailer: git-send-email 1.8.1.2
In-Reply-To: <1380507535-28030-1-git-send-email-psusi@HIDDEN>
References: <1380507535-28030-1-git-send-email-psusi@HIDDEN>
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-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <http://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -5.0 (-----)

Previous attempts to use the correct name for device-mapper devices on
linux simply bypassed canonicalizing the given name if it started with
"/dev/mapper".  This gave the correct name ( as opposed to following the
symlink in /dev/mapper to /dev/dm-X ), but only when the given name was
the /dev/mapper name.  The wrong name would still be used when given some
other symlink, such as /dev/disk/by-id.  This was worked around in linux.c
by having linux_partition_get_path generate the full canonical path name
to the partition, while parted still reported the symlink as the name
of the disk.

This patch adds an arch specific get_normal_path method that, if
implemented, is used to find the canonical device path instead of the
canonicalize_file_name function from gnulib.  The linux arch implements
this by generating the correct /dev/mapper name and no longer has to
special case linux_partition_get_path to generate the base name.

The original t3000-symlink test was incorrect because it relied on the
hard coded "/dev/mapper" prefix so it has been replaced with
t6004-dm-symlink.sh instead, which creates a real dm device and a symlink
to it to verify the real name is used when the user gives the symlink.

t6000-dm.sh was also relying on a private /dev/mapper directory, which
is unworkable.
---
 include/parted/device.in.h       |   1 +
 libparted/arch/linux.c           |  52 +++++++--------
 libparted/device.c               |   6 +-
 libparted/tests/Makefile.am      |   5 +-
 libparted/tests/symlink.c        | 135 ---------------------------------------
 libparted/tests/t3000-symlink.sh |  27 --------
 tests/Makefile.am                |   1 +
 tests/t6000-dm.sh                |   2 +-
 tests/t6004-dm-symlink.sh        |  68 ++++++++++++++++++++
 9 files changed, 103 insertions(+), 194 deletions(-)

diff --git a/include/parted/device.in.h b/include/parted/device.in.h
index 7c06a66..d243fcc 100644
--- a/include/parted/device.in.h
+++ b/include/parted/device.in.h
@@ -119,6 +119,7 @@ struct _PedDeviceArchOps {
         /* These functions are optional */
         PedAlignment *(*get_minimum_alignment)(const PedDevice *dev);
         PedAlignment *(*get_optimum_alignment)(const PedDevice *dev);
+        char *(*get_normal_path)(const char *path);
 };
 
 #include <parted/constraint.h>
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index d3a03d6..c2a6184 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -2286,24 +2286,29 @@ zasprintf (const char *format, ...)
 }
 
 static char *
-dm_canonical_path (PedDevice const *dev)
+linux_get_normal_path (const char *path)
 {
-        LinuxSpecific const *arch_specific = LINUX_SPECIFIC (dev);
-
-        /* Get map name from devicemapper */
-        struct dm_task *task = dm_task_create (DM_DEVICE_INFO);
-        if (!task)
-                goto err;
-        if (!dm_task_set_major_minor (task, arch_specific->major,
-                                      arch_specific->minor, 0))
-                goto err;
-        if (!dm_task_run(task))
-                goto err;
-        char *dev_name = zasprintf ("/dev/mapper/%s", dm_task_get_name (task));
-        if (dev_name == NULL)
+        struct stat st;
+        if (stat(path, &st))
                 goto err;
-        dm_task_destroy (task);
-        return dev_name;
+        if (!S_ISBLK(st.st_mode))
+                return canonicalize_file_name(path);
+        if (_is_dm_major(major(st.st_rdev))) {
+                /* Get map name from devicemapper */
+                struct dm_task *task = dm_task_create (DM_DEVICE_INFO);
+                if (!task)
+                        goto err;
+                if (!dm_task_set_major_minor (task, major(st.st_rdev),
+                                              minor(st.st_rdev), 0))
+                        goto err;
+                if (!dm_task_run(task))
+                        goto err;
+                char *dev_name = zasprintf ("/dev/mapper/%s", dm_task_get_name (task));
+                if (dev_name == NULL)
+                        goto err;
+                dm_task_destroy (task);
+                return dev_name;
+        } else return canonicalize_file_name(path);
 err:
         return NULL;
 }
@@ -2311,27 +2316,23 @@ err:
 static char*
 _device_get_part_path (PedDevice const *dev, int num)
 {
-        char *devpath = (dev->type == PED_DEVICE_DM
-                         ? dm_canonical_path (dev) : dev->path);
-        size_t path_len = strlen (devpath);
+        size_t path_len = strlen (dev->path);
         char *result;
         /* Check for devfs-style /disc => /partN transformation
            unconditionally; the system might be using udev with devfs rules,
            and if not the test is harmless. */
-        if (5 < path_len && !strcmp (devpath + path_len - 5, "/disc")) {
+        if (5 < path_len && !strcmp (dev->path + path_len - 5, "/disc")) {
                 /* replace /disc with /part%d */
                 result = zasprintf ("%.*s/part%d",
-                                    (int) (path_len - 5), devpath, num);
+                                    (int) (path_len - 5), dev->path, num);
         } else {
                 char const *p = (dev->type == PED_DEVICE_DAC960
                                  || dev->type == PED_DEVICE_CPQARRAY
                                  || dev->type == PED_DEVICE_ATARAID
-                                 || isdigit (devpath[path_len - 1])
+                                 || isdigit (dev->path[path_len - 1])
                                  ? "p" : "");
-                result = zasprintf ("%s%s%d", devpath, p, num);
+                result = zasprintf ("%s%s%d", dev->path, p, num);
         }
-        if (dev->type == PED_DEVICE_DM)
-                free (devpath);
         return result;
 }
 
@@ -2997,6 +2998,7 @@ static PedDeviceArchOps linux_dev_ops = {
         get_minimum_alignment:	linux_get_minimum_alignment,
         get_optimum_alignment:	linux_get_optimum_alignment,
 #endif
+        get_normal_path: linux_get_normal_path,
 };
 
 PedDiskArchOps linux_disk_ops =  {
diff --git a/libparted/device.c b/libparted/device.c
index 738b320..9b67454 100644
--- a/libparted/device.c
+++ b/libparted/device.c
@@ -152,9 +152,9 @@ ped_device_get (const char* path)
 	char*		normal_path = NULL;
 
 	PED_ASSERT (path != NULL);
-	/* Don't canonicalize /dev/mapper paths, see tests/symlink.c */
-	if (strncmp (path, "/dev/mapper/", 12))
-		normal_path = canonicalize_file_name (path);
+	if (ped_architecture->dev_ops->get_normal_path)
+		normal_path = ped_architecture->dev_ops->get_normal_path(path);
+	else normal_path = canonicalize_file_name (path);
 	if (!normal_path)
 		/* Well, maybe it is just that the file does not exist.
 		 * Try it anyway.  */
diff --git a/libparted/tests/Makefile.am b/libparted/tests/Makefile.am
index bfa5790..4e99ed1 100644
--- a/libparted/tests/Makefile.am
+++ b/libparted/tests/Makefile.am
@@ -3,9 +3,9 @@
 #
 # This file may be modified and/or distributed without restriction.
 
-TESTS = t1000-label.sh t2000-disk.sh t2100-zerolen.sh t3000-symlink.sh
+TESTS = t1000-label.sh t2000-disk.sh t2100-zerolen.sh
 EXTRA_DIST = $(TESTS)
-check_PROGRAMS = label disk zerolen symlink
+check_PROGRAMS = label disk zerolen
 AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS)
 
 LDADD = \
@@ -21,7 +21,6 @@ AM_CPPFLAGS = \
 label_SOURCES = common.h common.c label.c
 disk_SOURCES  = common.h common.c disk.c
 zerolen_SOURCES = common.h common.c zerolen.c
-symlink_SOURCES = common.h common.c symlink.c
 
 # Arrange to symlink to tests/init.sh.
 CLEANFILES = init.sh
diff --git a/libparted/tests/symlink.c b/libparted/tests/symlink.c
deleted file mode 100644
index 52e99ca..0000000
--- a/libparted/tests/symlink.c
+++ /dev/null
@@ -1,135 +0,0 @@
-/* Sometimes libparted operates on device mapper files, with a path of
-   /dev/mapper/foo. With newer lvm versions /dev/mapper/foo is a symlink to
-   /dev/dm-#. However some storage administration programs (anaconda for
-   example) may do the following:
-   1) Create a ped_device for /dev/mapper/foo
-   2) ped_get_device resolves the symlink to /dev/dm-#, and the path
-      in the PedDevice struct points to /dev/dm-#
-   3) The program does some things to lvm, causing the symlink to
-      point to a different /dev/dm-# node
-   4) The program does something with the PedDevice, which results
-      in an operation on the wrong device
-
-   Newer libparted versions do not suffer from this problem, as they
-   do not canonicalize device names under /dev/mapper. This test checks
-   for this bug. */
-
-#include <config.h>
-#include <unistd.h>
-
-#include <check.h>
-
-#include <parted/parted.h>
-
-#include "common.h"
-#include "progname.h"
-
-static char *temporary_disk;
-
-static void
-create_disk (void)
-{
-        temporary_disk = _create_disk (4096 * 1024);
-        fail_if (temporary_disk == NULL, "Failed to create temporary disk");
-}
-
-static void
-destroy_disk (void)
-{
-        unlink (temporary_disk);
-        free (temporary_disk);
-}
-
-START_TEST (test_symlink)
-{
-        char cwd[256], ln[256] = "/dev/mapper/parted-test-XXXXXX";
-
-        if (!getcwd (cwd, sizeof cwd)) {
-                fail ("Could not get cwd");
-                return;
-        }
-
-        /* Create a symlink under /dev/mapper to our
-           temporary disk */
-        int tmp_fd = mkstemp (ln);
-        if (tmp_fd == -1) {
-                fail ("Could not create tempfile");
-                return;
-        }
-
-        /* There is a temp file vulnerability symlink attack possibility
-           here, but as /dev/mapper is root owned this is a non issue */
-        close (tmp_fd);
-        unlink (ln);
-        char temp_disk_path[256];
-        snprintf (temp_disk_path, sizeof temp_disk_path, "%s/%s", cwd,
-                  temporary_disk);
-        int res = symlink (temp_disk_path, ln);
-        if (res) {
-                fail ("could not create symlink");
-                return;
-        }
-
-        PedDevice *dev = ped_device_get (ln);
-        if (dev == NULL)
-                goto exit_unlink_ln;
-
-        /* Create a second temporary_disk */
-        char *temporary_disk2 = _create_disk (4096 * 1024);
-        if (temporary_disk2 == NULL) {
-                fail ("Failed to create 2nd temporary disk");
-                goto exit_destroy_dev;
-        }
-
-        /* Remove first temporary disk, and make temporary_disk point to
-           temporary_disk2 (for destroy_disk()). */
-        unlink (temporary_disk);
-        free (temporary_disk);
-        temporary_disk = temporary_disk2;
-
-        /* Update symlink to point to our new / second temporary disk */
-        unlink (ln);
-        snprintf (temp_disk_path, sizeof temp_disk_path, "%s/%s", cwd,
-                  temporary_disk);
-        res = symlink (temp_disk_path, ln);
-        if (res) {
-                fail ("could not create 2nd symlink");
-                goto exit_destroy_dev;
-        }
-
-        /* Do something to our PedDevice, if the symlink was resolved,
-           instead of remembering the /dev/mapper/foo name, this will fail */
-        ped_disk_clobber (dev);
-
-exit_destroy_dev:
-        ped_device_destroy (dev);
-exit_unlink_ln:
-        unlink (ln);
-}
-END_TEST
-
-int
-main (int argc, char **argv)
-{
-        set_program_name (argv[0]);
-        int number_failed;
-        Suite* suite = suite_create ("Symlink");
-        TCase* tcase_symlink = tcase_create ("/dev/mapper symlink");
-
-        /* Fail when an exception is raised */
-        ped_exception_set_handler (_test_exception_handler);
-
-        tcase_add_checked_fixture (tcase_symlink, create_disk, destroy_disk);
-        tcase_add_test (tcase_symlink, test_symlink);
-        /* Disable timeout for this test */
-        tcase_set_timeout (tcase_symlink, 0);
-        suite_add_tcase (suite, tcase_symlink);
-
-        SRunner* srunner = srunner_create (suite);
-        srunner_run_all (srunner, CK_VERBOSE);
-
-        number_failed = srunner_ntests_failed (srunner);
-        srunner_free (srunner);
-
-        return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
-}
diff --git a/libparted/tests/t3000-symlink.sh b/libparted/tests/t3000-symlink.sh
deleted file mode 100755
index 338e44a..0000000
--- a/libparted/tests/t3000-symlink.sh
+++ /dev/null
@@ -1,27 +0,0 @@
-#!/bin/sh
-# run the /dev/mapper symlink test
-
-# Copyright (C) 2007-2013 Free Software Foundation, Inc.
-
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3 of the License, or
-# (at your option) any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-. "${abs_top_srcdir=../..}/tests/init.sh"; path_prepend_ .
-
-. $abs_top_srcdir/tests/t-lib-helpers.sh
-# Need root privileges to create a symlink under /dev/mapper.
-require_root_
-
-symlink || fail=1
-
-Exit $fail
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 16ec5d2..c5472d2 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -63,6 +63,7 @@ TESTS = \
   t6001-psep.sh \
   t6002-dm-busy.sh \
   t6003-dm-hide.sh \
+  t6004-dm-symlink.sh \
   t6100-mdraid-partitions.sh \
   t7000-scripting.sh \
   t8000-loop.sh \
diff --git a/tests/t6000-dm.sh b/tests/t6000-dm.sh
index c301dee..241f34b 100755
--- a/tests/t6000-dm.sh
+++ b/tests/t6000-dm.sh
@@ -65,7 +65,7 @@ for type in linear ; do
 
   # setup: create a mapping
   echo "$dmsetup_cmd" | dmsetup create "$type_kwd" || fail=1
-  dev="$DM_DEV_DIR/mapper/$type_kwd"
+  dev="/dev/mapper/$type_kwd"
 
   # Create msdos partition table
   parted -s $dev mklabel msdos > out 2>&1 || fail=1
diff --git a/tests/t6004-dm-symlink.sh b/tests/t6004-dm-symlink.sh
new file mode 100644
index 0000000..0cb967b
--- /dev/null
+++ b/tests/t6004-dm-symlink.sh
@@ -0,0 +1,68 @@
+#!/bin/sh
+# ensure that parted canonicalizes symlinks to dm devices correctly
+
+# Copyright (C) 2008-2013 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../parted
+
+require_root_
+lvm_init_root_dir_
+
+test "x$ENABLE_DEVICE_MAPPER" = xyes \
+  || skip_ "no device-mapper support"
+
+# Device maps names - should be random to not conflict with existing ones on
+# the system
+linear_=plinear-$$
+
+d1=
+f1=
+ln1=
+cleanup_fn_() {
+    dmsetup remove $linear_
+    test -n "$d1" && losetup -d "$d1"
+    rm -f "$f1" "$ln1";
+}
+
+f1=$(pwd)/1; d1=$(loop_setup_ "$f1") \
+  || skip_ "is this partition mounted with 'nodev'?"
+
+dmsetup_cmd="0 1024 linear $d1 0"
+
+  # setup: create a mapping
+  echo "$dmsetup_cmd" | dmsetup create $linear_ || fail=1
+  dev="/dev/mapper/$linear_"
+  ln1=symlink
+  ln -s "$dev" symlink || fail=1
+
+  # Create msdos partition table
+  parted -s $dev mklabel msdos
+  parted -s symlink print > out 2>&1 || fail=1
+  # Create expected output file.
+  cat <<EOF >> exp || fail=1
+Model: Linux device-mapper (linear) (dm)
+Disk $dev: 524kB
+Sector size (logical/physical): 512B/512B
+Partition Table: msdos
+Disk Flags: 
+
+Number  Start  End  Size  Type  File system  Flags
+
+EOF
+
+  compare exp out || fail=1
+
+Exit $fail
-- 
1.8.1.2





Message sent:


Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
X-Mailer: MIME-tools 5.503 (Entity 5.503)
Content-Type: text/plain; charset=utf-8
X-Loop: help-debbugs@HIDDEN
From: help-debbugs@HIDDEN (GNU bug Tracking System)
To: Phillip Susi <psusi@HIDDEN>
Subject: bug#15490: Acknowledgement ([PATCH] Refactor device canonicalization)
Message-ID: <handler.15490.B.13805075596311.ack <at> debbugs.gnu.org>
References: <1380507535-28030-2-git-send-email-psusi@HIDDEN>
X-Gnu-PR-Message: ack 15490
X-Gnu-PR-Package: parted
X-Gnu-PR-Keywords: patch
Reply-To: 15490 <at> debbugs.gnu.org
Date: Mon, 30 Sep 2013 02:20:03 +0000

Thank you for filing a new bug report with debbugs.gnu.org.

This is an automatically generated reply to let you know your message
has been received.

Your message is being forwarded to the package maintainers and other
interested parties for their attention; they will reply in due course.

Your message has been sent to the package maintainer(s):
 bug-parted@HIDDEN

If you wish to submit further information on this problem, please
send it to 15490 <at> debbugs.gnu.org.

Please do not send mail to help-debbugs@HIDDEN unless you wish
to report a problem with the Bug-tracking system.

--=20
15490: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D15490
GNU Bug Tracking System
Contact help-debbugs@HIDDEN with problems


Message sent to bug-parted@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#15490: [PATCH] Refactor device canonicalization
Resent-From: Phillip Susi <psusi@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-parted@HIDDEN
Resent-Date: Mon, 18 Nov 2013 02:52:01 +0000
Resent-Message-ID: <handler.15490.B15490.138474307729744 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 15490
X-GNU-PR-Package: parted
X-GNU-PR-Keywords: patch
To: 15490 <at> debbugs.gnu.org
Received: via spool by 15490-submit <at> debbugs.gnu.org id=B15490.138474307729744
          (code B ref 15490); Mon, 18 Nov 2013 02:52:01 +0000
Received: (at 15490) by debbugs.gnu.org; 18 Nov 2013 02:51:17 +0000
Received: from localhost ([127.0.0.1]:59245 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1ViEvk-0007jf-F0
	for submit <at> debbugs.gnu.org; Sun, 17 Nov 2013 21:51:16 -0500
Received: from cdptpa-omtalb.mail.rr.com ([75.180.132.120]:41218)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <psusi@HIDDEN>) id 1ViEvh-0007jN-Mj
 for 15490 <at> debbugs.gnu.org; Sun, 17 Nov 2013 21:51:14 -0500
X-Authority-Analysis: v=2.0 cv=LKjkseq9 c=1 sm=0 a=3SewDSjaRW4vdJyuxQ33ZQ==:17
 a=DeBnktw0k-IA:10 a=AizhB-pfR1kA:10 a=-Wg-csLjjI0A:10 a=S1A5HrydsesA:10
 a=8nJEP1OIZ-IA:10 a=fxJcL_dCAAAA:8 a=KGjhK52YXX0A:10 a=lUrIvlZhNr0A: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:52295] helo=[192.168.1.6])
 by cdptpa-oedge02.mail.rr.com (envelope-from <psusi@HIDDEN>)
 (ecelerity 2.2.3.46 r()) with ESMTP
 id 87/CD-09301-B9089825; Mon, 18 Nov 2013 02:51:07 +0000
Message-ID: <5289809B.4030604@HIDDEN>
Date: Sun, 17 Nov 2013 21:51:07 -0500
From: Phillip Susi <psusi@HIDDEN>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
 rv:24.0) Gecko/20100101 Thunderbird/24.1.0
MIME-Version: 1.0
References: <1380507535-28030-1-git-send-email-psusi@HIDDEN>
 <1380507535-28030-2-git-send-email-psusi@HIDDEN>
In-Reply-To: <1380507535-28030-2-git-send-email-psusi@HIDDEN>
X-Enigmail-Version: 1.6
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Spam-Score: 0.0 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <http://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
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/

iQEcBAEBCgAGBQJSiYCbAAoJEJrBOlT6nu75p/AIAJJR4fT7IWxgXtgkfG6vCfoZ
2e1Bv0hZzt6a8UGGel9AaGfyZyL4bq/Kibl5HCPEYcKiomYJuzJ4c+EngP4M3oyi
2sHlyNAqWIMAnyNfqaE7O5MnMMXXtQuxSqv3JjVTLKIa1knRJ65Xul3jOSPlwWMU
/V/DVJqmcQh5r6t4dY0ubKrIUNKk9np+XNkHUTbrFiNchSnTS/KDPNGFESZNxsAN
gW/GRnXKBx1lI9WucNLOo3SuHiF34vhuhCkvUUHEv8KgyGpBFh63StQpheu3nyaX
e/JQ9q88/X02Y2b4TSWFFCSl+sBFUqaWxyPY08nQNLg6Jie0l8p1xCMZs2W6VOs=
=ur6D
-----END PGP SIGNATURE-----




Message sent to bug-parted@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#15490: [PATCH] libparted: avoid disturbing partitions
Resent-From: Phillip Susi <psusi@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-parted@HIDDEN
Resent-Date: Mon, 18 Nov 2013 02:52:02 +0000
Resent-Message-ID: <handler.15490.B15490.138474311829805 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 15490
X-GNU-PR-Package: parted
X-GNU-PR-Keywords: patch
To: 15490 <at> debbugs.gnu.org
Received: via spool by 15490-submit <at> debbugs.gnu.org id=B15490.138474311829805
          (code B ref 15490); Mon, 18 Nov 2013 02:52:02 +0000
Received: (at 15490) by debbugs.gnu.org; 18 Nov 2013 02:51:58 +0000
Received: from localhost ([127.0.0.1]:59248 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1ViEwQ-0007kf-0g
	for submit <at> debbugs.gnu.org; Sun, 17 Nov 2013 21:51:58 -0500
Received: from cdptpa-omtalb.mail.rr.com ([75.180.132.120]:58232)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <psusi@HIDDEN>) id 1ViEwO-0007kS-8r
 for 15490 <at> debbugs.gnu.org; Sun, 17 Nov 2013 21:51:56 -0500
X-Authority-Analysis: v=2.0 cv=LKjkseq9 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=02e47F8qemUa3nEc:21 a=XRMYLcmfI1XKCVq_: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:52297]
 helo=localhost.localdomain)
 by cdptpa-oedge02.mail.rr.com (envelope-from <psusi@HIDDEN>)
 (ecelerity 2.2.3.46 r()) with ESMTP
 id 1F/3E-09301-6C089825; Mon, 18 Nov 2013 02:51:50 +0000
From: Phillip Susi <psusi@HIDDEN>
Date: Sun, 17 Nov 2013 21:51:50 -0500
Message-Id: <1384743110-9714-1-git-send-email-psusi@HIDDEN>
X-Mailer: git-send-email 1.8.3.2
In-Reply-To: <5289809B.4030604@HIDDEN>
References: <5289809B.4030604@HIDDEN>
X-Spam-Score: 0.0 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <http://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
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





Message sent to bug-parted@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#15490: [PATCH] Refactor device canonicalization
Resent-From: Phillip Susi <psusi@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-parted@HIDDEN
Resent-Date: Mon, 18 Nov 2013 04:20:01 +0000
Resent-Message-ID: <handler.15490.B15490.13847483805893 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 15490
X-GNU-PR-Package: parted
X-GNU-PR-Keywords: patch
To: 15490 <at> debbugs.gnu.org
Received: via spool by 15490-submit <at> debbugs.gnu.org id=B15490.13847483805893
          (code B ref 15490); Mon, 18 Nov 2013 04:20:01 +0000
Received: (at 15490) by debbugs.gnu.org; 18 Nov 2013 04:19:40 +0000
Received: from localhost ([127.0.0.1]:59310 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1ViGJH-0001Wy-GR
	for submit <at> debbugs.gnu.org; Sun, 17 Nov 2013 23:19:39 -0500
Received: from cdptpa-omtalb.mail.rr.com ([75.180.132.120]:43487)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <psusi@HIDDEN>) id 1ViGJF-0001Wl-1l
 for 15490 <at> debbugs.gnu.org; Sun, 17 Nov 2013 23:19:37 -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=-Wg-csLjjI0A:10 a=S1A5HrydsesA:10
 a=8nJEP1OIZ-IA:10 a=fxJcL_dCAAAA:8 a=KGjhK52YXX0A:10 a=lUrIvlZhNr0A:10
 a=QfKxxUxMAAAA:8 a=rADuBjpeAAAA:8 a=1MIbA-bFwXXJnPNuEIcA: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:45052] helo=[192.168.1.6])
 by cdptpa-oedge04.mail.rr.com (envelope-from <psusi@HIDDEN>)
 (ecelerity 2.2.3.46 r()) with ESMTP
 id 24/E0-07922-35599825; Mon, 18 Nov 2013 04:19:31 +0000
Message-ID: <52899553.1030308@HIDDEN>
Date: Sun, 17 Nov 2013 23:19:31 -0500
From: Phillip Susi <psusi@HIDDEN>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
 rv:24.0) Gecko/20100101 Thunderbird/24.1.0
MIME-Version: 1.0
References: <1380507535-28030-1-git-send-email-psusi@HIDDEN>	<1380507535-28030-2-git-send-email-psusi@HIDDEN>
 <5289809B.4030604@HIDDEN>
In-Reply-To: <5289809B.4030604@HIDDEN>
X-Enigmail-Version: 1.6
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Spam-Score: 0.0 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <http://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: 0.0 (/)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

On 11/17/2013 09:51 PM, Phillip Susi wrote:
> I had to revise this patch because it caused failures to update
> the

Gah, that was meant for the other bug.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.14 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBCgAGBQJSiZVPAAoJEJrBOlT6nu75MIwIAK/FR5QGC89Ii4kHFYJsr1cH
itw35mT/43iR0iftfk1jt76VtBxfdxZXk6prkEqd3tswtMdQL9wiGYU/KYEcWgvF
OL3JykyQDDcSrYDthVvHmATTM0lyX7RVJCtHlxWv6iS7EXRju+H4Z4QOMajbDqLB
TqZp4xlSwrS5+pcih9o55CUctxY6lJw/A4FUzgf/3VCEpe8ki4oKn3rTr2DFX6qn
aio4p2mOsWXBe2hrxWwg4OdYIoFW84fki6iFMcTHWfSk3S4HIa38wLuphoOtdgRG
ICm/xc43h+iGtAiEVghIHA26KtJ2tnWTtPUbUgoB6OZ9WU3DOXrfWv6ZKZvkmOo=
=b5ZX
-----END PGP SIGNATURE-----





Last modified: Mon, 25 Nov 2019 12:00:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.