parted/libparted-fix-udev-cookie-leak.patch
Sebastian Parschauer 3546816d4d Accepting request 541560 from home:sparschauer:branches:Base:System
- Escape printed device path in machine mode (bsc#1066467)
- Add support for NVDIMM devices (bsc#1064446)
- Prepare to fix the resizepart command (bsc#1058667)

OBS-URL: https://build.opensuse.org/request/show/541560
OBS-URL: https://build.opensuse.org/package/show/Base:System/parted?expand=0&rev=134
2017-11-13 17:52:10 +00:00

68 lines
2.5 KiB
Diff

From: "Brian C. Lane" <bcl@redhat.com>
Date: Thu, 25 May 2017 09:42:23 -0700
Subject: libparted: Fix udev cookie leak in _dm_resize_partition
References: bsc#1058667
Patch-mainline: v3.3
Git-commit: e7870afe3c13dcc77845d48409daa35e3e42b5fb
The function is setting udev cookies, but not using them when waiting
for the task. This results in leaked cookies, which can eventually
exhaust the available number of semaphores.
'dmsetup udevcookies' will show a cookie remaining afterwards, and 'ipcs -s'
will show the semaphores in use.
Also simplified the exit so that the task is always destroyed and memory
is all freed in the same path.
Resolves: rhbz#1455564
Acked-by: Sebastian Parschauer <sparschauer@suse.de>
---
libparted/arch/linux.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -2964,6 +2964,7 @@ _dm_resize_partition (PedDisk* disk, con
char* vol_name = NULL;
const char* dev_name = NULL;
uint32_t cookie = 0;
+ int rc = 0;
/* Get map name from devicemapper */
struct dm_task *task = dm_task_create (DM_DEVICE_INFO);
@@ -3004,8 +3005,9 @@ _dm_resize_partition (PedDisk* disk, con
/* device-mapper uses 512b units, not the device's sector size */
dm_task_add_target (task, 0, part->geom.length * (disk->dev->sector_size / PED_SECTOR_SIZE_DEFAULT),
"linear", params);
- if (!dm_task_set_cookie (task, &cookie, 0))
- goto err;
+ /* NOTE: DM_DEVICE_RELOAD doesn't generate udev events, so no cookie is needed (it will freeze).
+ * DM_DEVICE_RESUME does, so get a cookie and synchronize with udev.
+ */
if (dm_task_run (task)) {
dm_task_destroy (task);
task = dm_task_create (DM_DEVICE_RESUME);
@@ -3014,10 +3016,8 @@ _dm_resize_partition (PedDisk* disk, con
dm_task_set_name (task, vol_name);
if (!dm_task_set_cookie (task, &cookie, 0))
goto err;
- if (dm_task_run (task)) {
- free (params);
- free (vol_name);
- return 1;
+ if (_dm_task_run_wait (task, cookie)) {
+ rc = 1;
}
}
err:
@@ -3026,7 +3026,7 @@ err:
dm_task_destroy (task);
free (params);
free (vol_name);
- return 0;
+ return rc;
}
#endif