From a21105c265a330ce852210429820189d90f03d54a7332d91c7a9d8387990336e Mon Sep 17 00:00:00 2001 From: Petr Uzel Date: Fri, 11 Mar 2016 11:49:52 +0000 Subject: [PATCH 1/3] - libparted: Use read only when probing devices on linux (bsc#967375) OBS-URL: https://build.opensuse.org/package/show/Base:System/parted?expand=0&rev=116 --- ...ad-only-when-probing-devices-on-linu.patch | 216 ++++++++++++++++++ parted.changes | 6 + parted.spec | 4 +- 3 files changed, 225 insertions(+), 1 deletion(-) create mode 100644 libparted-Use-read-only-when-probing-devices-on-linu.patch diff --git a/libparted-Use-read-only-when-probing-devices-on-linu.patch b/libparted-Use-read-only-when-probing-devices-on-linu.patch new file mode 100644 index 0000000..74ae46a --- /dev/null +++ b/libparted-Use-read-only-when-probing-devices-on-linu.patch @@ -0,0 +1,216 @@ +From 44d5ae0115c4ecfe3158748309e9912c5aede92d Mon Sep 17 00:00:00 2001 +From: "Brian C. Lane" +Date: Thu, 6 Aug 2015 07:17:14 -0700 +Subject: [PATCH] libparted: Use read only when probing devices on linux + (#1245144) + +When a device is opened for RW closing it can trigger other actions, +like udev scanning it for partition changes. Use read only for the +init_* methods and RW for actual changes to the device. + +This adds _device_open which takes mode flags as an argument and turns +linux_open into a wrapper for it with RW_MODE. + +_device_open_ro is added to open the device with RD_MODE and increment +the open_counter. This is used in the init_* functions. + +_device_close is a wrapper around linux_close that decrements the +open_counter and is used in the init_* functions. + +All of these changes are self-contained with no external API changes. +The only visible change in behavior is that when a new PedDevice is +created the device is opened in RO_MODE instead of RW_MODE. + +Resolves: rhbz#1245144 +--- + libparted/arch/linux.c | 62 ++++++++++++++++++++++++++++++++++--------------- + 1 file changed, 44 insertions(+), 18 deletions(-) + +Index: parted-3.2/libparted/arch/linux.c +=================================================================== +--- parted-3.2.orig/libparted/arch/linux.c ++++ parted-3.2/libparted/arch/linux.c +@@ -292,7 +292,9 @@ struct blkdev_ioctl_param { + static char* _device_get_part_path (PedDevice const *dev, int num); + static int _partition_is_mounted_by_path (const char* path); + static unsigned int _device_get_partition_range(PedDevice const* dev); +- ++static int _device_open (PedDevice* dev, int flags); ++static int _device_open_ro (PedDevice* dev); ++static int _device_close (PedDevice* dev); + + static int + _read_fd (int fd, char **buf) +@@ -911,7 +913,7 @@ init_ide (PedDevice* dev) + if (!_device_stat (dev, &dev_stat)) + goto error; + +- if (!ped_device_open (dev)) ++ if (!_device_open_ro (dev)) + goto error; + + if (ioctl (arch_specific->fd, HDIO_GET_IDENTITY, &hdi)) { +@@ -980,11 +982,11 @@ init_ide (PedDevice* dev) + if (!_device_probe_geometry (dev)) + goto error_close_dev; + +- ped_device_close (dev); ++ _device_close (dev); + return 1; + + error_close_dev: +- ped_device_close (dev); ++ _device_close (dev); + error: + return 0; + } +@@ -1117,7 +1119,7 @@ init_scsi (PedDevice* dev) + char* vendor; + char* product; + +- if (!ped_device_open (dev)) ++ if (!_device_open_ro (dev)) + goto error; + + if (ioctl (arch_specific->fd, SCSI_IOCTL_GET_IDLUN, &idlun) < 0) { +@@ -1131,7 +1133,7 @@ init_scsi (PedDevice* dev) + goto error_close_dev; + if (!_device_probe_geometry (dev)) + goto error_close_dev; +- ped_device_close (dev); ++ _device_close (dev); + return 1; + } + +@@ -1153,11 +1155,11 @@ init_scsi (PedDevice* dev) + if (!_device_probe_geometry (dev)) + goto error_close_dev; + +- ped_device_close (dev); ++ _device_close (dev); + return 1; + + error_close_dev: +- ped_device_close (dev); ++ _device_close (dev); + error: + return 0; + } +@@ -1169,7 +1171,7 @@ init_file (PedDevice* dev) + + if (!_device_stat (dev, &dev_stat)) + goto error; +- if (!ped_device_open (dev)) ++ if (!_device_open_ro (dev)) + goto error; + + dev->sector_size = PED_SECTOR_SIZE_DEFAULT; +@@ -1196,7 +1198,7 @@ init_file (PedDevice* dev) + goto error_close_dev; + } + +- ped_device_close (dev); ++ _device_close (dev); + + dev->bios_geom.cylinders = dev->length / 4 / 32; + dev->bios_geom.heads = 4; +@@ -1207,7 +1209,7 @@ init_file (PedDevice* dev) + return 1; + + error_close_dev: +- ped_device_close (dev); ++ _device_close (dev); + error: + return 0; + } +@@ -1223,7 +1225,7 @@ init_dasd (PedDevice* dev, const char* m + if (!_device_stat (dev, &dev_stat)) + goto error; + +- if (!ped_device_open (dev)) ++ if (!_device_open_ro (dev)) + goto error; + + LinuxSpecific* arch_specific = LINUX_SPECIFIC (dev); +@@ -1263,11 +1265,11 @@ init_dasd (PedDevice* dev, const char* m + + dev->model = strdup (model_name); + +- ped_device_close (dev); ++ _device_close (dev); + return 1; + + error_close_dev: +- ped_device_close (dev); ++ _device_close (dev); + error: + return 0; + } +@@ -1282,7 +1284,7 @@ init_generic (PedDevice* dev, const char + if (!_device_stat (dev, &dev_stat)) + goto error; + +- if (!ped_device_open (dev)) ++ if (!_device_open_ro (dev)) + goto error; + + ped_exception_fetch_all (); +@@ -1330,11 +1332,11 @@ init_generic (PedDevice* dev, const char + + dev->model = strdup (model_name); + +- ped_device_close (dev); ++ _device_close (dev); + return 1; + + error_close_dev: +- ped_device_close (dev); ++ _device_close (dev); + error: + return 0; + } +@@ -1621,12 +1623,27 @@ retry: + } + + static int ++_device_open_ro (PedDevice* dev) ++{ ++ int rc = _device_open (dev, RD_MODE); ++ if (rc) ++ dev->open_count++; ++ return rc; ++} ++ ++static int + linux_open (PedDevice* dev) + { ++ return _device_open (dev, RW_MODE); ++} ++ ++static int ++_device_open (PedDevice* dev, int flags) ++{ + LinuxSpecific* arch_specific = LINUX_SPECIFIC (dev); + + retry: +- arch_specific->fd = open (dev->path, RW_MODE); ++ arch_specific->fd = open (dev->path, flags); + + if (arch_specific->fd == -1) { + char* rw_error_msg = strerror (errno); +@@ -1695,6 +1712,15 @@ linux_refresh_close (PedDevice* dev) + return 1; + } + ++static int ++_device_close (PedDevice* dev) ++{ ++ int rc = linux_close (dev); ++ if (dev->open_count > 0) ++ dev->open_count--; ++ return rc; ++} ++ + #if SIZEOF_OFF_T < 8 + + static _syscall5(int,_llseek, diff --git a/parted.changes b/parted.changes index b125e4a..35fbdf8 100644 --- a/parted.changes +++ b/parted.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Fri Mar 11 11:20:12 UTC 2016 - puzel@suse.com + +- libparted: Use read only when probing devices on linux + (bsc#967375) + ------------------------------------------------------------------- Thu Sep 10 09:18:30 UTC 2015 - fvogt@suse.com diff --git a/parted.spec b/parted.spec index 0a219eb..7992a3e 100644 --- a/parted.spec +++ b/parted.spec @@ -1,7 +1,7 @@ # # spec file for package parted # -# Copyright (c) 2015 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -56,6 +56,7 @@ Patch28: libparted-device-mapper-uses-512b-sectors.patch Patch29: parted-resize-alias-to-resizepart.patch Patch30: libparted-avoid-libdevice-mapper-warnings.patch Patch31: parted-do-not-warn-when-shrinking-in-script-mode.patch +Patch32: libparted-Use-read-only-when-probing-devices-on-linu.patch Patch100: parted-fatresize-autoconf.patch BuildRequires: check-devel BuildRequires: device-mapper-devel >= 1.02.33 @@ -130,6 +131,7 @@ to develop applications that require these. %patch29 -p1 %patch30 -p1 %patch31 -p1 +%patch32 -p1 %patch100 -p1 %build From 038e7d22ce715cb982a9d009ddb1cb094a01d9c373720bca2c3c04b65661d393 Mon Sep 17 00:00:00 2001 From: Petr Uzel Date: Wed, 18 May 2016 07:25:05 +0000 Subject: [PATCH 2/3] - implement --wipesignatures option (bsc#943623, fate#319893) - parted-implement-wipesignatures-option.patch OBS-URL: https://build.opensuse.org/package/show/Base:System/parted?expand=0&rev=117 --- parted-implement-wipesignatures-option.patch | 158 +++++++++++++++++++ parted.changes | 6 + parted.spec | 2 + 3 files changed, 166 insertions(+) create mode 100644 parted-implement-wipesignatures-option.patch diff --git a/parted-implement-wipesignatures-option.patch b/parted-implement-wipesignatures-option.patch new file mode 100644 index 0000000..50d5588 --- /dev/null +++ b/parted-implement-wipesignatures-option.patch @@ -0,0 +1,158 @@ +From 4ff404cc2d7ab74d0b1000c0212318dcbb2dda11 Mon Sep 17 00:00:00 2001 +From: Petr Uzel +Date: Thu, 28 Apr 2016 17:18:44 +0200 +Subject: [PATCH] parted: implement --wipesignatures option + +With this option, parted uses libblkid to wipe superblock signatures +from a disk region where it is about to create a new partition. + +References: bsc#943623 +References: fate#319893 +--- + doc/C/parted.8 | 4 +++ + parted/parted.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 74 insertions(+) + +Index: parted-3.2/doc/C/parted.8 +=================================================================== +--- parted-3.2.orig/doc/C/parted.8 ++++ parted-3.2/doc/C/parted.8 +@@ -30,6 +30,10 @@ never prompts for user intervention + .B -v, --version + displays the version + .TP ++.B --wipesignatures ++mkpart wipes the superblock signatures from the disk region where it is ++about to create the partition ++.TP + .B -a \fIalignment-type\fP, --align \fIalignment-type\fP + Set alignment for newly created partitions, valid alignment types are: + .RS +Index: parted-3.2/parted/parted.c +=================================================================== +--- parted-3.2.orig/parted/parted.c ++++ parted-3.2/parted/parted.c +@@ -57,6 +57,11 @@ + #include "c-strcase.h" + #include "xalloc.h" + ++#include ++#include ++#include ++#include ++ + #ifdef ENABLE_MTRACE + #include + #endif +@@ -76,6 +81,7 @@ static int MEGABYTE_SECTORS (PedDevice* + enum + { + PRETEND_INPUT_TTY = CHAR_MAX + 1, ++ WIPESIGNATURES = CHAR_MAX + 2, + }; + + enum +@@ -117,6 +123,7 @@ static struct option const options[] = { + {"script", 0, NULL, 's'}, + {"version", 0, NULL, 'v'}, + {"align", required_argument, NULL, 'a'}, ++ {"wipesignatures", 0, NULL, WIPESIGNATURES}, + {"-pretend-input-tty", 0, NULL, PRETEND_INPUT_TTY}, + {NULL, 0, NULL, 0} + }; +@@ -128,11 +135,13 @@ static const char *const options_help [] + {"script", N_("never prompts for user intervention")}, + {"version", N_("displays the version")}, + {"align=[none|cyl|min|opt]", N_("alignment for new partitions")}, ++ {"wipesignatures", N_("wipe superblock signatures when creating partition")}, + {NULL, NULL} + }; + + int opt_script_mode = 0; + int pretend_input_tty = 0; ++int wipesignatures = 0; + int opt_machine_mode = 0; + int disk_is_modified = 0; + int is_toggle_mode = 0; +@@ -650,6 +659,56 @@ _adjust_end_if_iec (PedSector* start, Pe + } + } + ++#ifdef USE_BLKID ++static int ++_wipe_signatures (PedDevice *dev, PedSector start, PedSector length) ++{ ++ int fd = open (dev->path, O_RDWR); ++ if (fd == -1) ++ goto error; ++ ++ blkid_loff_t wipe_offset = start * dev->sector_size; ++ blkid_loff_t wipe_size = length * dev->sector_size; ++ ++ blkid_probe pr; ++ pr = blkid_new_probe(); ++ if (!pr) ++ goto error_close_fd; ++ ++ if (blkid_probe_set_device(pr, fd, wipe_offset, wipe_size) == -1) ++ goto error_free_probe; ++ if (blkid_probe_enable_superblocks(pr, 1) == -1) ++ goto error_free_probe; ++ if (blkid_probe_set_superblocks_flags(pr, BLKID_SUBLKS_MAGIC) == -1) ++ goto error_free_probe; ++ ++ while (blkid_do_probe(pr) == 0) { ++ if (blkid_do_wipe(pr, 0) == -1) ++ goto error_free_probe; ++ } ++ ++ blkid_free_probe(pr); ++ close(fd); ++ return 1; ++ ++error_free_probe: ++ blkid_free_probe(pr); ++ ++error_close_fd: ++ close(fd); ++ ++error: ++ return 0; ++ ++} ++#else ++static int ++_wipe_signatures (PedDevice *dev, PedSector start, PedSector length) ++{ ++ return 0; ++} ++#endif ++ + static int + do_mkpart (PedDevice** dev, PedDisk** diskp) + { +@@ -840,6 +899,14 @@ do_mkpart (PedDevice** dev, PedDisk** di + if (ped_partition_is_flag_available (part, PED_PARTITION_LBA)) + ped_partition_set_flag (part, PED_PARTITION_LBA, 1); + ++ if (wipesignatures) { ++ if (!_wipe_signatures(*dev, part->geom.start, part->geom.length)) ++ ped_exception_throw ( ++ PED_EXCEPTION_WARNING, ++ PED_EXCEPTION_OK, ++ _("Wiping the superblock signatures has failed.")); ++ } ++ + if (!ped_disk_commit (disk)) + goto error; + +@@ -2196,6 +2263,9 @@ while (1) + case PRETEND_INPUT_TTY: + pretend_input_tty = 1; + break; ++ case WIPESIGNATURES: ++ wipesignatures = 1; ++ break; + default: + wrong = 1; + break; diff --git a/parted.changes b/parted.changes index 35fbdf8..4271e68 100644 --- a/parted.changes +++ b/parted.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Wed May 18 07:23:08 UTC 2016 - puzel@suse.com + +- implement --wipesignatures option (bsc#943623, fate#319893) + - parted-implement-wipesignatures-option.patch + ------------------------------------------------------------------- Fri Mar 11 11:20:12 UTC 2016 - puzel@suse.com diff --git a/parted.spec b/parted.spec index 7992a3e..4fe4777 100644 --- a/parted.spec +++ b/parted.spec @@ -57,6 +57,7 @@ Patch29: parted-resize-alias-to-resizepart.patch Patch30: libparted-avoid-libdevice-mapper-warnings.patch Patch31: parted-do-not-warn-when-shrinking-in-script-mode.patch Patch32: libparted-Use-read-only-when-probing-devices-on-linu.patch +Patch33: parted-implement-wipesignatures-option.patch Patch100: parted-fatresize-autoconf.patch BuildRequires: check-devel BuildRequires: device-mapper-devel >= 1.02.33 @@ -132,6 +133,7 @@ to develop applications that require these. %patch30 -p1 %patch31 -p1 %patch32 -p1 +%patch33 -p1 %patch100 -p1 %build From c607a856b876ea46b5748d62f672824d9b4d73e448ba9c05e8b00ddd62943261 Mon Sep 17 00:00:00 2001 From: Petr Uzel Date: Thu, 19 May 2016 08:14:31 +0000 Subject: [PATCH 3/3] - libparted-Use-read-only-when-probing-devices-on-linu.patch OBS-URL: https://build.opensuse.org/package/show/Base:System/parted?expand=0&rev=118 --- parted.changes | 1 + 1 file changed, 1 insertion(+) diff --git a/parted.changes b/parted.changes index 4271e68..eb46d1d 100644 --- a/parted.changes +++ b/parted.changes @@ -8,6 +8,7 @@ Wed May 18 07:23:08 UTC 2016 - puzel@suse.com Fri Mar 11 11:20:12 UTC 2016 - puzel@suse.com - libparted: Use read only when probing devices on linux + - libparted-Use-read-only-when-probing-devices-on-linu.patch (bsc#967375) -------------------------------------------------------------------