1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

locking: avoid dropping locks

When lvm2 command forks, it calls reset_locking(),
which as an unwanted side effect unlinked lock file from filesystem.

Patch changes the behavior to just close locked file descriptor
in children - so the lock is being still properly hold in the parent.
This commit is contained in:
Zdenek Kabelac 2014-01-27 12:11:09 +01:00
parent f18ee04fab
commit 6b73d21ba9
3 changed files with 53 additions and 4 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.106 - Version 2.02.106 -
==================================== ====================================
Fix unwanted drop of hold flocks on forked children.
Respect LVM_LVMETAD_PIDFILE env var for lvm command. Respect LVM_LVMETAD_PIDFILE env var for lvm command.
Avoid exposing temporary devices when initializing thin pool volume. Avoid exposing temporary devices when initializing thin pool volume.
Fix test when checking target version for available thin features. Fix test when checking target version for available thin features.

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
* Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved. * Copyright (C) 2004-2014 Red Hat, Inc. All rights reserved.
* *
* This file is part of LVM2. * This file is part of LVM2.
* *
@ -44,6 +44,15 @@ static sig_t _oldhandler;
static sigset_t _fullsigset, _intsigset; static sigset_t _fullsigset, _intsigset;
static volatile sig_atomic_t _handler_installed; static volatile sig_atomic_t _handler_installed;
/* Drop lock known to be shared with another file descriptor. */
static void _drop_shared_flock(const char *file, int fd)
{
log_debug_locking("_drop_shared_flock %s.", file);
if (close(fd) < 0)
log_sys_debug("close", file);
}
static void _undo_flock(const char *file, int fd) static void _undo_flock(const char *file, int fd)
{ {
struct stat buf1, buf2; struct stat buf1, buf2;
@ -74,9 +83,9 @@ static int _release_lock(const char *file, int unlock)
log_very_verbose("Unlocking %s", ll->res); log_very_verbose("Unlocking %s", ll->res);
if (flock(ll->lf, LOCK_NB | LOCK_UN)) if (flock(ll->lf, LOCK_NB | LOCK_UN))
log_sys_debug("flock", ll->res); log_sys_debug("flock", ll->res);
}
_undo_flock(ll->res, ll->lf); _undo_flock(ll->res, ll->lf);
} else
_drop_shared_flock(ll->res, ll->lf);
dm_free(ll->res); dm_free(ll->res);
dm_free(llh); dm_free(llh);

View File

@ -0,0 +1,39 @@
#!/bin/sh
# Copyright (C) 2014 Red Hat, Inc. All rights reserved.
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions
# of the GNU General Public License v.2.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# Test parallel use of lvm commands and check locks aren't dropped
# RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1049296
. lib/test
aux prepare_vg
test -e LOCAL_CLVMD && skip
lvcreate -L10 -n $lv1 $vg
lvcreate -l1 -n $lv2 $vg
mkfs.ext4 "$DM_DEV_DIR/$vg/$lv1"
# Slowdown PV for resized LV
aux delay_dev "$dev1" 40 40
lvresize -L-5 -r $vg/$lv1 &
# Let's wait till resize start
sleep 2
lvremove -f $vg/$lv2
wait
aux enable_dev "$dev1"
# Check removed $lv2 does not reappear
not check lv_exists $vg $lv2