parted/libparted-open-the-device-RO-and-lazily-switch-to-RW.patch
Marcus Meissner 5631eac2bb Accepting request 760713 from home:anicka:branches:Base:System
- fix crash in do_resizepart
  + parted-fix-end_input-usage.patch: Fix end_input usage in
    do_resizepart 

- update to version 3.3, noteworthy changes:
 - s390: Re-enabled virtio-attached DASD heuristics by using
   HDIO_GETGEO when probing device geometry. Fixes a bug with
   KVM virtio-blk backed by a DASD.
   Parted now recognizes NVMe devices, NVDIMM, and RAM drives.
 - Fix atari disklabel false positives by probing other labels first.
 - Fix resizepart to adjust the end to be -1 sector when using iec
   power of 2 units so that the next partition can start immediately
   following the new end, just like mkpart does.
 - Fix set and disk_set to not crash when there are no flags to set.
 - Fix a udev cookie leak when using resizepart on device-mapper devices.
 - Fix a gettext crash/error sometimes when using localized languages.
 - Fix fat resize to preverve boot code, and thus not render the
   filesystem unreconized by Windows.
 - Fix rescue command: the rescue command often failed to find
   filesystems due to leaving on cylinder alignment.
 - libparted-fs-resize: Prevent crash resizing FAT file systems with very
   deep directories with path names over 512 bytes long.
 - Use 512b sector size when communicating with device-mapper. Fixes
   problems with partitions being created too small on dm devices
   with sector sizes > 5121b
 - Don't crash in the disk_set command when a disk label is not found
 - libparted-fs-resize: Prevent crash resizing FAT16 file systems.
 - libparted-fs-resize: Prevent crash resizing FAT16 file systems.
 - If the user specifies start/end of the partition as cylinders
   and a cylinder has a size which is power of 2, then such address

OBS-URL: https://build.opensuse.org/request/show/760713
OBS-URL: https://build.opensuse.org/package/show/Base:System/parted?expand=0&rev=144
2020-01-12 13:40:37 +00:00

140 lines
4.5 KiB
Diff

From: Petr Uzel <petr.uzel@suse.cz>
Date: Thu, 26 May 2016 09:28:21 +0200
Subject: libparted: open the device RO and lazily switch to RW only if
necessary
References: bsc#979275
Patch-mainline: not yet
Avoid useless udev events triggered by opening the device RW
for purely read-only operations.
Author: Michael Matz <matz@suse.de>
[sparschauer: Use _flush_cache() also for reads, don't switch to RW
in _flush_cache() to avoid a possible recursion (bnc#989751), open
partitions in _flush_cache() O_RDONLY instead of O_WRONLY]
Signed-off-by: Sebastian Parschauer <sparschauer@suse.de>
---
libparted/arch/linux.c | 33 ++++++++++++++++++++++++++++++---
libparted/arch/linux.h | 1 +
2 files changed, 31 insertions(+), 3 deletions(-)
Index: parted-3.3/libparted/arch/linux.c
===================================================================
--- parted-3.3.orig/libparted/arch/linux.c
+++ parted-3.3/libparted/arch/linux.c
@@ -298,6 +298,9 @@ static unsigned int _device_get_partitio
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)
@@ -451,6 +454,22 @@ _is_blkext_major (int major)
return _major_type_in_devices (major, "blkext");
}
+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;
+}
+
#ifdef ENABLE_DEVICE_MAPPER
static int
_dm_task_run_wait (struct dm_task *task, uint32_t cookie)
@@ -1678,7 +1697,7 @@ _flush_cache (PedDevice* dev)
if (!name)
break;
if (!_partition_is_mounted_by_path (name)) {
- fd = open (name, WR_MODE, 0);
+ fd = open (name, RD_MODE, 0);
if (fd > 0) {
ioctl (fd, BLKFLSBUF);
retry:
@@ -1709,7 +1728,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
@@ -1747,6 +1766,10 @@ 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);
@@ -1984,6 +2007,7 @@ _write_lastoddsector (PedDevice* dev, co
PED_ASSERT(dev != NULL);
PED_ASSERT(buffer != NULL);
+ _ensure_read_write (dev);
arch_specific = LINUX_SPECIFIC (dev);
@@ -2032,6 +2056,9 @@ linux_write (PedDevice* dev, const void*
return 1;
}
+ _ensure_read_write (dev);
+ if (count == 0)
+ return 1; /* We just ensured the device is open RW (see call from dasd_write()) */
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.
@@ -2570,6 +2597,7 @@ _blkpg_part_command (PedDevice* dev, str
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);
Index: parted-3.3/libparted/arch/linux.h
===================================================================
--- parted-3.3.orig/libparted/arch/linux.h
+++ parted-3.3/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;
Index: parted-3.3/libparted/labels/dasd.c
===================================================================
--- parted-3.3.orig/libparted/labels/dasd.c
+++ parted-3.3/libparted/labels/dasd.c
@@ -637,6 +637,10 @@ dasd_write (const PedDisk* disk)
return 1;
}
+ /* Ensure the device is open RW */
+ char dummy[10]; /* to avoid assertion in ped_device_write */
+ ped_device_write(disk->dev, &dummy, 0, 0);
+
/* initialize the anchor */
fdasd_initialize_anchor(&anchor);
if (fdasd_get_geometry(disk->dev, &anchor, arch_specific->fd) == 0)