Accepting request 398311 from Base:System
- Update parted-implement-wipesignatures-option.patch: - Move functionality to libparted (bsc#980834) - libparted: open the device RO and lazily switch to RW only if necessary (bsc#979275) - libparted-open-the-device-RO-and-lazily-switch-to-RW.patch OBS-URL: https://build.opensuse.org/request/show/398311 OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/parted?expand=0&rev=110
This commit is contained in:
commit
951bb120b5
126
libparted-open-the-device-RO-and-lazily-switch-to-RW.patch
Normal file
126
libparted-open-the-device-RO-and-lazily-switch-to-RW.patch
Normal file
@ -0,0 +1,126 @@
|
||||
From b9420b8e618c8ad988c410e4289273ac962ec918 Mon Sep 17 00:00:00 2001
|
||||
From: Petr Uzel <petr.uzel@suse.cz>
|
||||
Date: Thu, 26 May 2016 09:28:21 +0200
|
||||
Subject: [PATCH] libparted: open the device RO and lazily switch to RW only if
|
||||
necessary
|
||||
|
||||
Avoid useless udev events triggered by opening the device RW
|
||||
for purely read-only operations.
|
||||
|
||||
References: https://bugzilla.novell.com/show_bug.cgi?id=979275
|
||||
Author: Michael Matz <matz@suse.de>
|
||||
---
|
||||
libparted/arch/linux.c | 33 ++++++++++++++++++++++++++++++---
|
||||
libparted/arch/linux.h | 1 +
|
||||
2 files changed, 31 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
|
||||
index 326b956..0a50452 100644
|
||||
--- a/libparted/arch/linux.c
|
||||
+++ b/libparted/arch/linux.c
|
||||
@@ -294,6 +294,9 @@ 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 linux_close (PedDevice* dev);
|
||||
+static void _flush_cache (PedDevice* dev);
|
||||
+
|
||||
|
||||
static int
|
||||
_read_fd (int fd, char **buf)
|
||||
@@ -441,6 +444,24 @@ _is_virtblk_major (int major)
|
||||
return _major_type_in_devices (major, "virtblk");
|
||||
}
|
||||
|
||||
+static void
|
||||
+_ensure_read_write (PedDevice *dev)
|
||||
+{
|
||||
+ PED_ASSERT (dev != NULL);
|
||||
+ LinuxSpecific* arch_specific = LINUX_SPECIFIC (dev);
|
||||
+
|
||||
+ if (arch_specific->rw)
|
||||
+ return;
|
||||
+
|
||||
+ if (!linux_close(dev))
|
||||
+ return;
|
||||
+
|
||||
+ if (!_device_open (dev, RW_MODE))
|
||||
+ return;
|
||||
+
|
||||
+ _flush_cache (dev);
|
||||
+}
|
||||
+
|
||||
#ifdef ENABLE_DEVICE_MAPPER
|
||||
static int
|
||||
_dm_task_run_wait (struct dm_task *task, uint32_t cookie)
|
||||
@@ -1604,6 +1625,7 @@ _flush_cache (PedDevice* dev)
|
||||
|
||||
if (dev->read_only)
|
||||
return;
|
||||
+ _ensure_read_write (dev);
|
||||
dev->dirty = 0;
|
||||
|
||||
ioctl (arch_specific->fd, BLKFLSBUF);
|
||||
@@ -1647,7 +1669,7 @@ _device_open_ro (PedDevice* dev)
|
||||
static int
|
||||
linux_open (PedDevice* dev)
|
||||
{
|
||||
- return _device_open (dev, RW_MODE);
|
||||
+ return _device_open (dev, RD_MODE);
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -1685,10 +1707,12 @@ retry:
|
||||
}
|
||||
} else {
|
||||
dev->read_only = 0;
|
||||
+ if (flags == WR_MODE || flags == RW_MODE)
|
||||
+ arch_specific->rw = 1;
|
||||
+ else
|
||||
+ arch_specific->rw = 0;
|
||||
}
|
||||
|
||||
- _flush_cache (dev);
|
||||
-
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1920,6 +1944,7 @@ _write_lastoddsector (PedDevice* dev, const void* buffer)
|
||||
|
||||
PED_ASSERT(dev != NULL);
|
||||
PED_ASSERT(buffer != NULL);
|
||||
+ _ensure_read_write (dev);
|
||||
|
||||
arch_specific = LINUX_SPECIFIC (dev);
|
||||
|
||||
@@ -1968,6 +1993,7 @@ linux_write (PedDevice* dev, const void* buffer, PedSector start,
|
||||
return 1;
|
||||
}
|
||||
|
||||
+ _ensure_read_write (dev);
|
||||
if (_get_linux_version() < KERNEL_VERSION (2,6,0)) {
|
||||
/* Kludge. This is necessary to read/write the last
|
||||
block of an odd-sized disk, until Linux 2.5.x kernel fixes.
|
||||
@@ -2497,6 +2523,7 @@ _blkpg_part_command (PedDevice* dev, struct blkpg_partition* part, int op)
|
||||
LinuxSpecific* arch_specific = LINUX_SPECIFIC (dev);
|
||||
struct blkpg_ioctl_arg ioctl_arg;
|
||||
|
||||
+ _ensure_read_write (dev);
|
||||
ioctl_arg.op = op;
|
||||
ioctl_arg.flags = 0;
|
||||
ioctl_arg.datalen = sizeof (struct blkpg_partition);
|
||||
diff --git a/libparted/arch/linux.h b/libparted/arch/linux.h
|
||||
index 95def1f..926f7e2 100644
|
||||
--- a/libparted/arch/linux.h
|
||||
+++ b/libparted/arch/linux.h
|
||||
@@ -30,6 +30,7 @@ struct _LinuxSpecific {
|
||||
int fd;
|
||||
int major;
|
||||
int minor;
|
||||
+ int rw;
|
||||
char* dmtype; /**< device map target type */
|
||||
#if defined __s390__ || defined __s390x__
|
||||
unsigned int real_sector_size;
|
||||
--
|
||||
1.8.4.5
|
||||
|
@ -1,4 +1,4 @@
|
||||
From 4ff404cc2d7ab74d0b1000c0212318dcbb2dda11 Mon Sep 17 00:00:00 2001
|
||||
From f5216170b98e0c28dfee717fb03b6a06bcc2a3ee Mon Sep 17 00:00:00 2001
|
||||
From: Petr Uzel <petr.uzel@suse.cz>
|
||||
Date: Thu, 28 Apr 2016 17:18:44 +0200
|
||||
Subject: [PATCH] parted: implement --wipesignatures option
|
||||
@ -9,9 +9,12 @@ 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(+)
|
||||
doc/C/parted.8 | 4 ++++
|
||||
include/parted/device.in.h | 2 ++
|
||||
libparted/arch/linux.c | 39 +++++++++++++++++++++++++++++++++++++++
|
||||
libparted/device.c | 17 +++++++++++++++++
|
||||
parted/parted.c | 16 ++++++++++++++++
|
||||
5 files changed, 78 insertions(+)
|
||||
|
||||
Index: parted-3.2/doc/C/parted.8
|
||||
===================================================================
|
||||
@ -28,23 +31,114 @@ Index: parted-3.2/doc/C/parted.8
|
||||
.B -a \fIalignment-type\fP, --align \fIalignment-type\fP
|
||||
Set alignment for newly created partitions, valid alignment types are:
|
||||
.RS
|
||||
Index: parted-3.2/include/parted/device.in.h
|
||||
===================================================================
|
||||
--- parted-3.2.orig/include/parted/device.in.h
|
||||
+++ parted-3.2/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);
|
||||
+ int (*wipe_signatures)(const PedDevice *dev, PedSector start, PedSector length);
|
||||
};
|
||||
|
||||
#include <parted/constraint.h>
|
||||
@@ -155,6 +156,7 @@ extern PedConstraint *ped_device_get_opt
|
||||
|
||||
extern PedAlignment *ped_device_get_minimum_alignment(const PedDevice *dev);
|
||||
extern PedAlignment *ped_device_get_optimum_alignment(const PedDevice *dev);
|
||||
+extern int ped_device_wipe_signatures(const PedDevice *dev, PedSector start, PedSector length);
|
||||
|
||||
/* private stuff ;-) */
|
||||
|
||||
Index: parted-3.2/libparted/arch/linux.c
|
||||
===================================================================
|
||||
--- parted-3.2.orig/libparted/arch/linux.c
|
||||
+++ parted-3.2/libparted/arch/linux.c
|
||||
@@ -3297,6 +3297,44 @@ linux_get_optimum_alignment(const PedDev
|
||||
blkid_topology_get_alignment_offset(tp) / dev->sector_size,
|
||||
blkid_topology_get_optimal_io_size(tp) / dev->sector_size);
|
||||
}
|
||||
+
|
||||
+static int
|
||||
+linux_wipe_signatures(const PedDevice *dev, PedSector start, PedSector length)
|
||||
+{
|
||||
+ PED_ASSERT (dev != NULL);
|
||||
+ LinuxSpecific* arch_specific = LINUX_SPECIFIC (dev);
|
||||
+
|
||||
+ blkid_loff_t wipe_offset = start * dev->sector_size;
|
||||
+ blkid_loff_t wipe_size = length * dev->sector_size;
|
||||
+
|
||||
+ _ensure_read_write (dev);
|
||||
+
|
||||
+ blkid_probe pr;
|
||||
+ pr = blkid_new_probe();
|
||||
+ if (!pr)
|
||||
+ goto error;
|
||||
+
|
||||
+ if (blkid_probe_set_device(pr, arch_specific->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);
|
||||
+ return 1;
|
||||
+
|
||||
+error_free_probe:
|
||||
+ blkid_free_probe(pr);
|
||||
+
|
||||
+error:
|
||||
+ return 0;
|
||||
+}
|
||||
#endif
|
||||
|
||||
static PedDeviceArchOps linux_dev_ops = {
|
||||
@@ -3316,6 +3354,7 @@ static PedDeviceArchOps linux_dev_ops =
|
||||
#if USE_BLKID
|
||||
get_minimum_alignment: linux_get_minimum_alignment,
|
||||
get_optimum_alignment: linux_get_optimum_alignment,
|
||||
+ wipe_signatures: linux_wipe_signatures,
|
||||
#endif
|
||||
};
|
||||
|
||||
Index: parted-3.2/libparted/device.c
|
||||
===================================================================
|
||||
--- parted-3.2.orig/libparted/device.c
|
||||
+++ parted-3.2/libparted/device.c
|
||||
@@ -565,4 +565,21 @@ ped_device_get_optimum_alignment(const P
|
||||
return align;
|
||||
}
|
||||
|
||||
+
|
||||
+/**
|
||||
+ * Wipe superblock signatures from the specified region on the device.
|
||||
+ *
|
||||
+ * \return zero on failure
|
||||
+ */
|
||||
+int
|
||||
+ped_device_wipe_signatures(const PedDevice *dev, PedSector start, PedSector length)
|
||||
+{
|
||||
+ int ret = 0;
|
||||
+
|
||||
+ if (ped_architecture->dev_ops->wipe_signatures)
|
||||
+ ret = ped_architecture->dev_ops->wipe_signatures(dev, start, length);
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
/** @} */
|
||||
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 <sys/types.h>
|
||||
+#include <sys/stat.h>
|
||||
+#include <fcntl.h>
|
||||
+#include <blkid/blkid.h>
|
||||
+
|
||||
#ifdef ENABLE_MTRACE
|
||||
#include <mcheck.h>
|
||||
#endif
|
||||
@@ -76,6 +81,7 @@ static int MEGABYTE_SECTORS (PedDevice*
|
||||
@@ -76,6 +76,7 @@ static int MEGABYTE_SECTORS (PedDevice*
|
||||
enum
|
||||
{
|
||||
PRETEND_INPUT_TTY = CHAR_MAX + 1,
|
||||
@ -52,7 +146,7 @@ Index: parted-3.2/parted/parted.c
|
||||
};
|
||||
|
||||
enum
|
||||
@@ -117,6 +123,7 @@ static struct option const options[] = {
|
||||
@@ -117,6 +118,7 @@ static struct option const options[] = {
|
||||
{"script", 0, NULL, 's'},
|
||||
{"version", 0, NULL, 'v'},
|
||||
{"align", required_argument, NULL, 'a'},
|
||||
@ -60,7 +154,7 @@ Index: parted-3.2/parted/parted.c
|
||||
{"-pretend-input-tty", 0, NULL, PRETEND_INPUT_TTY},
|
||||
{NULL, 0, NULL, 0}
|
||||
};
|
||||
@@ -128,11 +135,13 @@ static const char *const options_help []
|
||||
@@ -128,11 +130,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")},
|
||||
@ -74,69 +168,20 @@ Index: parted-3.2/parted/parted.c
|
||||
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
|
||||
@@ -650,6 +654,7 @@ _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
|
||||
@@ -840,6 +845,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))
|
||||
+ if (!ped_device_wipe_signatures(*dev, part->geom.start, part->geom.length))
|
||||
+ ped_exception_throw (
|
||||
+ PED_EXCEPTION_WARNING,
|
||||
+ PED_EXCEPTION_OK,
|
||||
@ -146,7 +191,7 @@ Index: parted-3.2/parted/parted.c
|
||||
if (!ped_disk_commit (disk))
|
||||
goto error;
|
||||
|
||||
@@ -2196,6 +2263,9 @@ while (1)
|
||||
@@ -2196,6 +2209,9 @@ while (1)
|
||||
case PRETEND_INPUT_TTY:
|
||||
pretend_input_tty = 1;
|
||||
break;
|
||||
|
@ -1,3 +1,12 @@
|
||||
-------------------------------------------------------------------
|
||||
Thu May 26 10:46:38 UTC 2016 - puzel@suse.com
|
||||
|
||||
- Update parted-implement-wipesignatures-option.patch:
|
||||
- Move functionality to libparted (bsc#980834)
|
||||
- libparted: open the device RO and lazily switch to RW only if
|
||||
necessary (bsc#979275)
|
||||
- libparted-open-the-device-RO-and-lazily-switch-to-RW.patch
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Wed May 18 07:23:08 UTC 2016 - puzel@suse.com
|
||||
|
||||
|
@ -57,7 +57,8 @@ 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
|
||||
Patch33: libparted-open-the-device-RO-and-lazily-switch-to-RW.patch
|
||||
Patch34: parted-implement-wipesignatures-option.patch
|
||||
Patch100: parted-fatresize-autoconf.patch
|
||||
BuildRequires: check-devel
|
||||
BuildRequires: device-mapper-devel >= 1.02.33
|
||||
@ -134,6 +135,7 @@ to develop applications that require these.
|
||||
%patch31 -p1
|
||||
%patch32 -p1
|
||||
%patch33 -p1
|
||||
%patch34 -p1
|
||||
%patch100 -p1
|
||||
|
||||
%build
|
||||
|
Loading…
Reference in New Issue
Block a user