- libparted: Tell libdevmapper to retry remove when BUSY (bcl)

-   Resolves: rhbz#1980697
- parted: Escape colons and backslashes in machine output (bcl)
- tests: check for vfat kernel support and tools (ross.burton)
- tests: add a helper to check the kernel knows about a file system (ross.burton)
- tests: add aarch64 and mips64 as a valid 64-bit machines (ross.burton)
- libparted: Add swap flag to msdos disklabel (bcl)
- Move Exception Option values into enum (bcl)
This commit is contained in:
Brian C. Lane 2021-08-10 16:24:56 -07:00
parent ce8126ec00
commit e7b34705b0
8 changed files with 472 additions and 1 deletions

View File

@ -0,0 +1,77 @@
From fabd4e35427ab156d1e0b28745c926d0253a72cd Mon Sep 17 00:00:00 2001
From: "Brian C. Lane" <bcl@redhat.com>
Date: Tue, 10 Aug 2021 09:40:28 -0700
Subject: [PATCH 25/30] Move Exception Option values into enum
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Adding enums together doesn't create a new enum value, so when compiling
with warnings you will get warnings like:
warning: case value 96 not in enumerated type
for PED_EXCEPTION_IGNORE_CANCEL
This moved the defines into the enum as new values so that they are
recognized as valid members of the enum with the values staying the
same.
NOTE: PED_EXCEPTION_OPTION_LAST *MUST* be the last of the individual
options, not the combined options.
Thanks to D. Hugh Redelmeier for this patch.
---
include/parted/exception.in.h | 27 ++++++++++++++++-----------
1 file changed, 16 insertions(+), 11 deletions(-)
diff --git a/include/parted/exception.in.h b/include/parted/exception.in.h
index 20abb08..3b131fe 100644
--- a/include/parted/exception.in.h
+++ b/include/parted/exception.in.h
@@ -46,6 +46,7 @@ typedef enum _PedExceptionType PedExceptionType;
* Option for resolving the exception
*/
enum _PedExceptionOption {
+ /* individual options */
PED_EXCEPTION_UNHANDLED=0,
PED_EXCEPTION_FIX=1,
PED_EXCEPTION_YES=2,
@@ -54,19 +55,23 @@ enum _PedExceptionOption {
PED_EXCEPTION_RETRY=16,
PED_EXCEPTION_IGNORE=32,
PED_EXCEPTION_CANCEL=64,
+
+ /* combinations of individual options */
+ PED_EXCEPTION_OK_CANCEL = PED_EXCEPTION_OK + PED_EXCEPTION_CANCEL,
+ PED_EXCEPTION_YES_NO = PED_EXCEPTION_YES + PED_EXCEPTION_NO,
+ PED_EXCEPTION_YES_NO_CANCEL =
+ PED_EXCEPTION_YES_NO + PED_EXCEPTION_CANCEL,
+ PED_EXCEPTION_IGNORE_CANCEL =
+ PED_EXCEPTION_IGNORE + PED_EXCEPTION_CANCEL,
+ PED_EXCEPTION_RETRY_CANCEL = PED_EXCEPTION_RETRY + PED_EXCEPTION_CANCEL,
+ PED_EXCEPTION_RETRY_IGNORE_CANCEL =
+ PED_EXCEPTION_RETRY + PED_EXCEPTION_IGNORE_CANCEL,
};
-typedef enum _PedExceptionOption PedExceptionOption;
-#define PED_EXCEPTION_OK_CANCEL (PED_EXCEPTION_OK + PED_EXCEPTION_CANCEL)
-#define PED_EXCEPTION_YES_NO (PED_EXCEPTION_YES + PED_EXCEPTION_NO)
-#define PED_EXCEPTION_YES_NO_CANCEL (PED_EXCEPTION_YES_NO \
- + PED_EXCEPTION_CANCEL)
-#define PED_EXCEPTION_IGNORE_CANCEL (PED_EXCEPTION_IGNORE \
- + PED_EXCEPTION_CANCEL)
-#define PED_EXCEPTION_RETRY_CANCEL (PED_EXCEPTION_RETRY + PED_EXCEPTION_CANCEL)
-#define PED_EXCEPTION_RETRY_IGNORE_CANCEL (PED_EXCEPTION_RETRY \
- + PED_EXCEPTION_IGNORE_CANCEL)
+
#define PED_EXCEPTION_OPTION_FIRST PED_EXCEPTION_FIX
-#define PED_EXCEPTION_OPTION_LAST PED_EXCEPTION_CANCEL
+#define PED_EXCEPTION_OPTION_LAST PED_EXCEPTION_CANCEL /* last individual option */
+
+typedef enum _PedExceptionOption PedExceptionOption;
/**
* Structure with information about exception
--
2.31.1

View File

@ -0,0 +1,133 @@
From f8dd8c2c255a3c5c398a62ffdc1bcf5468becccd Mon Sep 17 00:00:00 2001
From: "Brian C. Lane" <bcl@redhat.com>
Date: Tue, 10 Aug 2021 13:14:26 -0700
Subject: [PATCH 26/30] libparted: Add swap flag to msdos disklabel
Previously you had to set the filesystem type to one of the linux-swap
options at creation time. With this change you can now toggle the
partition swap type using the 'swap' partition flag in the same way that
you can on gpt disklabels.
Thanks to Arvin Schnell for this patch.
---
doc/parted.texi | 4 ++--
libparted/labels/dos.c | 24 ++++++++++++++++++++++--
2 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/doc/parted.texi b/doc/parted.texi
index 33212f0..0da68e9 100644
--- a/doc/parted.texi
+++ b/doc/parted.texi
@@ -897,8 +897,8 @@ MS Windows ME based operating systems to use Linear (LBA) mode.
to be used by Linux.
@item swap
-(Mac) - this flag should be enabled if the partition is the swap
-device to be used by Linux.
+(MS-DOS, GPT, Mac) - this flag should be enabled if the partition is the
+swap device to be used by Linux.
@item hidden
(MS-DOS, PC98) - this flag can be enabled to hide partitions from
diff --git a/libparted/labels/dos.c b/libparted/labels/dos.c
index e2aa5e0..b44ccaf 100644
--- a/libparted/labels/dos.c
+++ b/libparted/labels/dos.c
@@ -160,6 +160,7 @@ typedef struct {
int msftres;
int raid;
int lvm;
+ int swap;
int lba;
int palo;
int prep;
@@ -958,6 +959,7 @@ raw_part_parse (const PedDisk* disk, const DosRawPartition* raw_part,
dos_data->raid = raw_part->type == PARTITION_LINUX_RAID;
dos_data->lvm = raw_part->type == PARTITION_LINUX_LVM_OLD
|| raw_part->type == PARTITION_LINUX_LVM;
+ dos_data->swap = raw_part->type == PARTITION_LINUX_SWAP;
dos_data->lba = raw_part_is_lba (raw_part);
dos_data->palo = raw_part->type == PARTITION_PALO;
dos_data->prep = raw_part->type == PARTITION_PREP;
@@ -1380,6 +1382,7 @@ msdos_partition_duplicate (const PedPartition* part)
new_dos_data->msftres = old_dos_data->msftres;
new_dos_data->raid = old_dos_data->raid;
new_dos_data->lvm = old_dos_data->lvm;
+ new_dos_data->swap = old_dos_data->swap;
new_dos_data->lba = old_dos_data->lba;
new_dos_data->palo = old_dos_data->palo;
new_dos_data->prep = old_dos_data->prep;
@@ -1437,6 +1440,7 @@ msdos_partition_set_system (PedPartition* part,
dos_data->diag = 0;
dos_data->raid = 0;
dos_data->lvm = 0;
+ dos_data->swap = 0;
dos_data->palo = 0;
dos_data->prep = 0;
dos_data->irst = 0;
@@ -1464,6 +1468,10 @@ msdos_partition_set_system (PedPartition* part,
dos_data->system = PARTITION_LINUX_LVM;
return 1;
}
+ if (dos_data->swap) {
+ dos_data->system = PARTITION_LINUX_SWAP;
+ return 1;
+ }
if (dos_data->raid) {
dos_data->system = PARTITION_LINUX_RAID;
return 1;
@@ -1510,9 +1518,10 @@ msdos_partition_set_system (PedPartition* part,
dos_data->system = PARTITION_UDF;
else if (!strcmp (fs_type->name, "sun-ufs"))
dos_data->system = PARTITION_SUN_UFS;
- else if (is_linux_swap (fs_type->name))
+ else if (is_linux_swap (fs_type->name)) {
dos_data->system = PARTITION_LINUX_SWAP;
- else
+ dos_data->swap = 1;
+ } else
dos_data->system = PARTITION_LINUX;
return 1;
@@ -1525,6 +1534,7 @@ clear_flags (DosPartitionData *dos_data)
dos_data->hidden = 0;
dos_data->msftres = 0;
dos_data->lvm = 0;
+ dos_data->swap = 0;
dos_data->palo = 0;
dos_data->prep = 0;
dos_data->irst = 0;
@@ -1604,6 +1614,12 @@ msdos_partition_set_flag (PedPartition* part,
dos_data->lvm = state;
return ped_partition_set_system (part, part->fs_type);
+ case PED_PARTITION_SWAP:
+ if (state)
+ clear_flags (dos_data);
+ dos_data->swap = state;
+ return ped_partition_set_system (part, part->fs_type);
+
case PED_PARTITION_LBA:
dos_data->lba = state;
return ped_partition_set_system (part, part->fs_type);
@@ -1677,6 +1693,9 @@ msdos_partition_get_flag (const PedPartition* part, PedPartitionFlag flag)
case PED_PARTITION_LVM:
return dos_data->lvm;
+ case PED_PARTITION_SWAP:
+ return dos_data->swap;
+
case PED_PARTITION_LBA:
return dos_data->lba;
@@ -1720,6 +1739,7 @@ msdos_partition_is_flag_available (const PedPartition* part,
case PED_PARTITION_BOOT:
case PED_PARTITION_RAID:
case PED_PARTITION_LVM:
+ case PED_PARTITION_SWAP:
case PED_PARTITION_LBA:
case PED_PARTITION_PALO:
case PED_PARTITION_PREP:
--
2.31.1

View File

@ -0,0 +1,31 @@
From b5e17a613d2ea9894fcc090499dcc73e3ea07f61 Mon Sep 17 00:00:00 2001
From: Ross Burton <ross.burton@arm.com>
Date: Mon, 9 Aug 2021 15:25:50 +0100
Subject: [PATCH 27/30] tests: add aarch64 and mips64 as a valid 64-bit
machines
require_64_bit_ in t-lib-helpers.sh has a hard-coded list of uname
machines that are 64-bit, so add aarch64 and mips64 to cover the major
architectures.
Signed-off-by: Brian C. Lane <bcl@redhat.com>
---
tests/t-lib-helpers.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/t-lib-helpers.sh b/tests/t-lib-helpers.sh
index 9312343..dddb44e 100644
--- a/tests/t-lib-helpers.sh
+++ b/tests/t-lib-helpers.sh
@@ -411,7 +411,7 @@ device_mapper_required_()
require_64bit_()
{
case $(uname -m) in
- x86_64|ppc64)
+ aarch64|mips64|ppc64|x86_64)
return 0;;
*)
skip_ "This test requires a 64 bit system"
--
2.31.1

View File

@ -0,0 +1,43 @@
From 8e97e5f7ad7cc8a1e6233306a45fcdbf08c959bd Mon Sep 17 00:00:00 2001
From: Ross Burton <ross.burton@arm.com>
Date: Mon, 9 Aug 2021 15:25:51 +0100
Subject: [PATCH 28/30] tests: add a helper to check the kernel knows about a
file system
Some tests need both the file system tools (eg mkfs.vfat) and kernel
support (eg vfat kernel module) to pass.
There are already helpers such as require_fat_ which check for mkfs.vfat,
but if the kernel doesn't support the filesystem then mounting the disk
image will fail.
Add require_filesystem_, which checks for either the filesystem name in
/proc/filesystems (so it's built-in, or already loaded) or if the name
is a valid module (so can be loaded on demand).
Signed-off-by: Brian C. Lane <bcl@redhat.com>
---
tests/t-lib-helpers.sh | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/tests/t-lib-helpers.sh b/tests/t-lib-helpers.sh
index dddb44e..33151bb 100644
--- a/tests/t-lib-helpers.sh
+++ b/tests/t-lib-helpers.sh
@@ -418,3 +418,13 @@ require_64bit_()
;;
esac
}
+
+# Check if the specified filesystem is either built into the kernel, or can be loaded
+# as a module
+# Usage: has_filesystem vfat
+# Ruturns 0 if the filesystem is available, otherwise skips the test
+require_filesystem_()
+{
+ grep -q $1 /proc/filesystems && return 0
+ modprobe --quiet --dry-run $1 || skip_ "this test requires kernel support for $1"
+}
--
2.31.1

View File

@ -0,0 +1,46 @@
From 231a1e1d3ab525272b44bd20f703f9253fd1ed5c Mon Sep 17 00:00:00 2001
From: Ross Burton <ross.burton@arm.com>
Date: Mon, 9 Aug 2021 15:25:52 +0100
Subject: [PATCH 29/30] tests: check for vfat kernel support and tools
t1100-busy-label.sh and t1101-busy-partition.sh create and mount VFAT
partitions, so check for both the tools and the kernel support.
Fixes bug#49594.
Signed-off-by: Brian C. Lane <bcl@redhat.com>
---
tests/t1100-busy-label.sh | 3 +++
tests/t1101-busy-partition.sh | 2 ++
2 files changed, 5 insertions(+)
diff --git a/tests/t1100-busy-label.sh b/tests/t1100-busy-label.sh
index 71b847c..a77a70f 100755
--- a/tests/t1100-busy-label.sh
+++ b/tests/t1100-busy-label.sh
@@ -19,6 +19,9 @@
. "${srcdir=.}/init.sh"; path_prepend_ ../parted
require_root_
require_scsi_debug_module_
+require_fat_
+require_filesystem_ vfat
+
ss=$sector_size_
scsi_debug_setup_ sector_size=$ss dev_size_mb=10 > dev-name ||
diff --git a/tests/t1101-busy-partition.sh b/tests/t1101-busy-partition.sh
index 5e37814..c936718 100755
--- a/tests/t1101-busy-partition.sh
+++ b/tests/t1101-busy-partition.sh
@@ -22,6 +22,8 @@ test "$VERBOSE" = yes && parted --version
require_root_
require_scsi_debug_module_
+require_fat_
+require_filesystem_ vfat
# create memory-backed device
scsi_debug_setup_ dev_size_mb=10 > dev-name ||
--
2.31.1

View File

@ -0,0 +1,91 @@
From 33f7bb2f9967856afac2411831ef16dcf95746ab Mon Sep 17 00:00:00 2001
From: "Brian C. Lane" <bcl@redhat.com>
Date: Tue, 10 Aug 2021 15:49:48 -0700
Subject: [PATCH 30/30] parted: Escape colons and backslashes in machine output
The device path, device model, and partition name could all contain
colons or backslashes. This escapes all of these with a backslash.
Thanks to Arvin Schnell for the patch.
---
parted/parted.c | 42 ++++++++++++++++++++++++++++++++++++++----
1 file changed, 38 insertions(+), 4 deletions(-)
diff --git a/parted/parted.c b/parted/parted.c
index 22b5818..65b5ab2 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -985,6 +985,32 @@ _print_disk_geometry (const PedDevice *dev)
free (cyl_size);
}
+static char *
+_escape_machine_string (const char *str)
+{
+ size_t i, j;
+ char *dest;
+
+ dest = ped_malloc (2 * strlen(str) + 1);
+ if (!dest)
+ return NULL;
+
+ for (i = 0, j = 0; str[i] != '\0'; i++, j++) {
+ switch (str[i]) {
+ case ':':
+ case '\\':
+ dest[j++] = '\\';
+ /* fallthrough */
+ default:
+ dest[j] = str[i];
+ break;
+ }
+ }
+ dest[j] = '\0';
+
+ return dest;
+}
+
static void
_print_disk_info (const PedDevice *dev, const PedDisk *diskp)
{
@@ -1005,6 +1031,9 @@ _print_disk_info (const PedDevice *dev, const PedDisk *diskp)
char *disk_flags = disk_print_flags (diskp);
if (opt_machine_mode) {
+ char *escaped_path = _escape_machine_string (dev->path);
+ char *escaped_model = _escape_machine_string (dev->model);
+
switch (default_unit) {
case PED_UNIT_CHS: puts ("CHS;");
break;
@@ -1015,9 +1044,11 @@ _print_disk_info (const PedDevice *dev, const PedDisk *diskp)
}
printf ("%s:%s:%s:%lld:%lld:%s:%s:%s;\n",
- dev->path, end, transport[dev->type],
+ escaped_path, end, transport[dev->type],
dev->sector_size, dev->phys_sector_size,
- pt_name, dev->model, disk_flags);
+ pt_name, escaped_model, disk_flags);
+ free (escaped_path);
+ free (escaped_model);
} else {
printf (_("Model: %s (%s)\n"),
dev->model, transport[dev->type]);
@@ -1289,8 +1320,11 @@ do_print (PedDevice** dev, PedDisk** diskp)
putchar (':');
if (has_name)
- printf ("%s:", ped_partition_get_name (part));
- else
+ {
+ char *escaped_name = _escape_machine_string (ped_partition_get_name (part));
+ printf ("%s:", escaped_name);
+ free (escaped_name);
+ } else
putchar (':');
char *flags = partition_print_flags (part);
--
2.31.1

View File

@ -0,0 +1,32 @@
From 9e194581edf31ddd2474e7be5393578542b4ef8d Mon Sep 17 00:00:00 2001
From: "Brian C. Lane" <bcl@redhat.com>
Date: Fri, 9 Jul 2021 10:54:51 -0700
Subject: [PATCH] libparted: Tell libdevmapper to retry remove when BUSY
This sets the libdevmapper retry remove flag, which will retry a remove
command if it is BUSY.
parted already has it's own BUSY retry code, but when run with
device-mapper an error can be printed by libdevmapper which can be
confusing to the user.
Resolves: rhbz#1980697
---
libparted/arch/linux.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index aacc94f..758d36a 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -2855,6 +2855,7 @@ _dm_remove_partition(PedDisk* disk, int partno)
if (!task)
goto err;
dm_task_set_name (task, part_name);
+ dm_task_retry_remove(task);
if (!dm_task_set_cookie (task, &cookie, 0))
goto err;
rc = _dm_task_run_wait (task, cookie);
--
2.31.1

View File

@ -1,7 +1,7 @@
Summary: The GNU disk partition manipulation program Summary: The GNU disk partition manipulation program
Name: parted Name: parted
Version: 3.4 Version: 3.4
Release: 6%{?dist} Release: 7%{?dist}
License: GPLv3+ License: GPLv3+
URL: http://www.gnu.org/software/parted URL: http://www.gnu.org/software/parted
@ -35,6 +35,14 @@ Patch0021: 0021-tests-t3200-Change-dev_size_mb-to-10.patch
Patch0022: 0022-tests-t6006-Change-dev_size_mb-to-10.patch Patch0022: 0022-tests-t6006-Change-dev_size_mb-to-10.patch
Patch0023: 0023-tests-t3000-Check-for-hfs-and-vfat-support-separatel.patch Patch0023: 0023-tests-t3000-Check-for-hfs-and-vfat-support-separatel.patch
Patch0024: 0024-tests-t3000-Use-mkfs.hfsplus-and-fsck.hfsplus-for-re.patch Patch0024: 0024-tests-t3000-Use-mkfs.hfsplus-and-fsck.hfsplus-for-re.patch
Patch0025: 0025-Move-Exception-Option-values-into-enum.patch
Patch0026: 0026-libparted-Add-swap-flag-to-msdos-disklabel.patch
Patch0027: 0027-tests-add-aarch64-and-mips64-as-a-valid-64-bit-machi.patch
Patch0028: 0028-tests-add-a-helper-to-check-the-kernel-knows-about-a.patch
Patch0029: 0029-tests-check-for-vfat-kernel-support-and-tools.patch
Patch0030: 0030-parted-Escape-colons-and-backslashes-in-machine-outp.patch
# Fixes rhbz#1980697 but not yet upstream
Patch0031: 0031-libparted-Tell-libdevmapper-to-retry-remove-when-BUS.patch
BuildRequires: gcc BuildRequires: gcc
BuildRequires: e2fsprogs-devel BuildRequires: e2fsprogs-devel
@ -138,6 +146,16 @@ make check
%changelog %changelog
* Tue Aug 10 2021 Brian C. Lane <bcl@redhat.com> - 3.4-7
- libparted: Tell libdevmapper to retry remove when BUSY (bcl)
Resolves: rhbz#1980697
- parted: Escape colons and backslashes in machine output (bcl)
- tests: check for vfat kernel support and tools (ross.burton)
- tests: add a helper to check the kernel knows about a file system (ross.burton)
- tests: add aarch64 and mips64 as a valid 64-bit machines (ross.burton)
- libparted: Add swap flag to msdos disklabel (bcl)
- Move Exception Option values into enum (bcl)
* Tue Aug 03 2021 Brian C. Lane <bcl@redhat.com> - 3.4-6 * Tue Aug 03 2021 Brian C. Lane <bcl@redhat.com> - 3.4-6
- spec: Use the %%gpgverify macro for the signature check - spec: Use the %%gpgverify macro for the signature check
- tests/t3000: Use mkfs.hfsplus and fsck.hfsplus for resize tests (bcl) - tests/t3000: Use mkfs.hfsplus and fsck.hfsplus for resize tests (bcl)