Sign In
Sign Up
Search is temporarily disabled. See
ticket
for more info.
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
List overview
Download
lvm2-commits
May 2014
----- 2024 -----
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
lvm2-commits@lists.fedorahosted.org
5 participants
116 discussions
Start a n
N
ew thread
master - make: fix commit 1756bf6
by Peter Rajnoha
07 May '14
07 May '14
Gitweb:
http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=9d64573da135b489…
Commit: 9d64573da135b489e1b3079612e77363526ca44d Parent: 1899783aa646cfc7f4851de7231f4f2db65b6986 Author: Peter Rajnoha <prajnoha(a)redhat.com> AuthorDate: Wed May 7 12:13:36 2014 +0200 Committer: Peter Rajnoha <prajnoha(a)redhat.com> CommitterDate: Wed May 7 12:13:36 2014 +0200 make: fix commit 1756bf6 "DIST_TARGET" should be "DISTCLEAN_TARGET" --- scripts/Makefile.in | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/scripts/Makefile.in b/scripts/Makefile.in index c2842a4..2c92033 100644 --- a/scripts/Makefile.in +++ b/scripts/Makefile.in @@ -125,7 +125,7 @@ install_tmpfiles_configuration: $(INSTALL_DIR) $(tmpfiles_dir) $(INSTALL_DATA) lvm2_tmpfiles_red_hat.conf $(tmpfiles_dir)/lvm2.conf -DIST_TARGETS += \ +DISTCLEAN_TARGETS += \ blkdeactivate.sh \ blk_availability_init_red_hat \ blk_availability_systemd_red_hat.service \
1
0
0
0
master - cleanup: fix compiler warning
by Peter Rajnoha
06 May '14
06 May '14
Gitweb:
http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=1899783aa646cfc7…
Commit: 1899783aa646cfc7f4851de7231f4f2db65b6986 Parent: 8b49d61d8337cedddf65c35fb4de83cb01b1cdf4 Author: Peter Rajnoha <prajnoha(a)redhat.com> AuthorDate: Tue May 6 14:38:38 2014 +0200 Committer: Peter Rajnoha <prajnoha(a)redhat.com> CommitterDate: Tue May 6 14:38:38 2014 +0200 cleanup: fix compiler warning locking/file_locking.c:162:2: warning: implicit declaration of function ‘init_signals’ --- lib/locking/file_locking.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/lib/locking/file_locking.c b/lib/locking/file_locking.c index 37fa0eb..d3794db 100644 --- a/lib/locking/file_locking.c +++ b/lib/locking/file_locking.c @@ -23,6 +23,7 @@ #include "lvm-string.h" #include "lvm-flock.h" #include "lvmcache.h" +#include "lvm-signal.h" #include <limits.h> #include <unistd.h>
1
0
0
0
master - logging: Add LCK_REVERT_MODE to flags printed by decode_flags()
by Jonathan Brassow
05 May '14
05 May '14
Gitweb:
http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=8b49d61d8337cedd…
Commit: 8b49d61d8337cedddf65c35fb4de83cb01b1cdf4 Parent: 09064cc2db00a5da593aa9be61572aa643e4b035 Author: Jonathan Brassow <jbrassow(a)redhat.com> AuthorDate: Mon May 5 14:27:10 2014 -0500 Committer: Jonathan Brassow <jbrassow(a)redhat.com> CommitterDate: Mon May 5 14:30:09 2014 -0500 logging: Add LCK_REVERT_MODE to flags printed by decode_flags() The decode_flags() function does not yet know about the LCK_REVERT_MODE flag. --- daemons/clvmd/lvm-functions.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/daemons/clvmd/lvm-functions.c b/daemons/clvmd/lvm-functions.c index 2ecf7d7..e36e206 100644 --- a/daemons/clvmd/lvm-functions.c +++ b/daemons/clvmd/lvm-functions.c @@ -131,14 +131,15 @@ static const char *decode_flags(unsigned char flags) static char buf[128]; int len; - len = sprintf(buf, "0x%x ( %s%s%s%s%s%s%s)", flags, + len = sprintf(buf, "0x%x ( %s%s%s%s%s%s%s%s)", flags, flags & LCK_PARTIAL_MODE ? "PARTIAL_MODE|" : "", flags & LCK_MIRROR_NOSYNC_MODE ? "MIRROR_NOSYNC|" : "", flags & LCK_DMEVENTD_MONITOR_MODE ? "DMEVENTD_MONITOR|" : "", flags & LCK_ORIGIN_ONLY_MODE ? "ORIGIN_ONLY|" : "", flags & LCK_TEST_MODE ? "TEST|" : "", flags & LCK_CONVERT ? "CONVERT|" : "", - flags & LCK_DMEVENTD_MONITOR_IGNORE ? "DMEVENTD_MONITOR_IGNORE|" : ""); + flags & LCK_DMEVENTD_MONITOR_IGNORE ? "DMEVENTD_MONITOR_IGNORE|" : "", + flags & LCK_REVERT_MODE ? "REVERT|" : ""); if (len > 1) buf[len - 2] = ' ';
1
0
0
0
master - signals: Add init_signals.
by Alasdair Kergon
01 May '14
01 May '14
Gitweb:
http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=09064cc2db00a5da…
Commit: 09064cc2db00a5da593aa9be61572aa643e4b035 Parent: 2eed136f0f5d9eaa65d421b2b93b6405fd7c6f08 Author: Alasdair G Kergon <agk(a)redhat.com> AuthorDate: Thu May 1 20:31:19 2014 +0100 Committer: Alasdair G Kergon <agk(a)redhat.com> CommitterDate: Thu May 1 20:31:19 2014 +0100 signals: Add init_signals. --- lib/locking/file_locking.c | 17 ++--------------- lib/misc/lvm-signal.c | 17 +++++++++++++++++ lib/misc/lvm-signal.h | 1 + 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/lib/locking/file_locking.c b/lib/locking/file_locking.c index 2f6716d..37fa0eb 100644 --- a/lib/locking/file_locking.c +++ b/lib/locking/file_locking.c @@ -33,10 +33,6 @@ static char _lock_dir[PATH_MAX]; -static sig_t _oldhandler; -static sigset_t _fullsigset, _intsigset; -static volatile sig_atomic_t _handler_installed; - static void _fin_file_locking(void) { release_flocks(1); @@ -163,17 +159,8 @@ int init_file_locking(struct locking_type *locking, struct cmd_context *cmd, if ((access(_lock_dir, R_OK | W_OK | X_OK) == -1) && (errno == EROFS)) return 0; - if (sigfillset(&_intsigset) || sigfillset(&_fullsigset)) { - log_sys_error_suppress(suppress_messages, "sigfillset", - "init_file_locking"); - return 0; - } - - if (sigdelset(&_intsigset, SIGINT)) { - log_sys_error_suppress(suppress_messages, "sigdelset", - "init_file_locking"); - return 0; - } + if (!init_signals(suppress_messages)) + return_0; return 1; } diff --git a/lib/misc/lvm-signal.c b/lib/misc/lvm-signal.c index f2d6d3b..690733b 100644 --- a/lib/misc/lvm-signal.c +++ b/lib/misc/lvm-signal.c @@ -62,6 +62,23 @@ void install_ctrl_c_handler(void) siginterrupt(SIGINT, 1); } +int init_signals(int suppress_messages) +{ + if (sigfillset(&_intsigset) || sigfillset(&_fullsigset)) { + log_sys_error_suppress(suppress_messages, "sigfillset", + "init_signals"); + return 0; + } + + if (sigdelset(&_intsigset, SIGINT)) { + log_sys_error_suppress(suppress_messages, "sigdelset", + "init_signals"); + return 0; + } + + return 1; +} + static void _catch_sigint(int unused __attribute__((unused))) { _sigint_caught = 1; diff --git a/lib/misc/lvm-signal.h b/lib/misc/lvm-signal.h index f2e6141..3fb55f3 100644 --- a/lib/misc/lvm-signal.h +++ b/lib/misc/lvm-signal.h @@ -18,6 +18,7 @@ void remove_ctrl_c_handler(void); void install_ctrl_c_handler(void); +int init_signals(int suppress_messages); void sigint_allow(void); int sigint_caught(void);
1
0
0
0
master - signals: Move sigint handling out to lvm-signal.
by Alasdair Kergon
01 May '14
01 May '14
Gitweb:
http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=2eed136f0f5d9eaa…
Commit: 2eed136f0f5d9eaa65d421b2b93b6405fd7c6f08 Parent: 29a3fbf067e1685ae7e202959a414e4b13f547c7 Author: Alasdair G Kergon <agk(a)redhat.com> AuthorDate: Thu May 1 20:07:17 2014 +0100 Committer: Alasdair G Kergon <agk(a)redhat.com> CommitterDate: Thu May 1 20:07:17 2014 +0100 signals: Move sigint handling out to lvm-signal. --- WHATS_NEW | 1 + lib/cache/lvmetad.c | 1 + lib/display/display.c | 2 + lib/locking/locking.c | 134 +++------------------------------------------- lib/locking/locking.h | 6 -- lib/metadata/lv_manip.c | 1 + lib/metadata/metadata.c | 1 + lib/misc/lvm-flock.h | 6 +- lib/misc/lvm-signal.c | 123 +++++++++++++++++++++++++++++++++++++++++++ lib/misc/lvm-signal.h | 12 ++++- tools/tools.h | 1 + 11 files changed, 153 insertions(+), 135 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index 456f132..37225fe 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.107 - ================================== + Separate signal handling and flock code out into lib/misc. Don't start dmeventd checking seg_monitor and monitoring is disabled. Catch CTRL-c during pvremove prompts. Show correct availability status for snapshot origin in lvscan. diff --git a/lib/cache/lvmetad.c b/lib/cache/lvmetad.c index d0c4a4d..3470c66 100644 --- a/lib/cache/lvmetad.c +++ b/lib/cache/lvmetad.c @@ -21,6 +21,7 @@ #include "lvmetad-client.h" #include "format-text.h" // TODO for disk_locn, used as a DA representation #include "crc.h" +#include "lvm-signal.h" #define SCAN_TIMEOUT_SECONDS 80 #define MAX_RESCANS 10 /* Maximum number of times to scan all PVs and retry if the daemon returns a token mismatch error */ diff --git a/lib/display/display.c b/lib/display/display.c index b83bb59..b808f25 100644 --- a/lib/display/display.c +++ b/lib/display/display.c @@ -20,6 +20,8 @@ #include "toolcontext.h" #include "segtype.h" #include "defaults.h" +#include "lvm-signal.h" + #include <stdarg.h> #define SIZE_BUF 128 diff --git a/lib/locking/locking.c b/lib/locking/locking.c index b5250c1..673713a 100644 --- a/lib/locking/locking.c +++ b/lib/locking/locking.c @@ -22,148 +22,25 @@ #include "memlock.h" #include "defaults.h" #include "lvmcache.h" +#include "lvm-signal.h" #include <assert.h> -#include <signal.h> #include <sys/stat.h> #include <limits.h> #include <unistd.h> static struct locking_type _locking; -static sigset_t _oldset; static int _vg_lock_count = 0; /* Number of locks held */ static int _vg_write_lock_held = 0; /* VG write lock held? */ -static int _signals_blocked = 0; static int _blocking_supported = 0; -static volatile sig_atomic_t _sigint_caught = 0; -static volatile sig_atomic_t _handler_installed; -static struct sigaction _oldhandler; -static int _oldmasked; - typedef enum { LV_NOOP, LV_SUSPEND, LV_RESUME } lv_operation_t; -static void _catch_sigint(int unused __attribute__((unused))) -{ - _sigint_caught = 1; -} - -int sigint_caught(void) { - if (_sigint_caught) - log_error("Interrupted..."); - - return _sigint_caught; -} - -void sigint_clear(void) -{ - _sigint_caught = 0; -} - -/* - * Temporarily allow keyboard interrupts to be intercepted and noted; - * saves interrupt handler state for sigint_restore(). Users should - * use the sigint_caught() predicate to check whether interrupt was - * requested and act appropriately. Interrupt flags are never - * cleared automatically by this code, but the tools clear the flag - * before running each command in lvm_run_command(). All other places - * where the flag needs to be cleared need to call sigint_clear(). - */ - -void sigint_allow(void) -{ - struct sigaction handler; - sigset_t sigs; - - /* - * Do not overwrite the backed-up handler data - - * just increase nesting count. - */ - if (_handler_installed) { - _handler_installed++; - return; - } - - /* Grab old sigaction for SIGINT: shall not fail. */ - sigaction(SIGINT, NULL, &handler); - handler.sa_flags &= ~SA_RESTART; /* Clear restart flag */ - handler.sa_handler = _catch_sigint; - - _handler_installed = 1; - - /* Override the signal handler: shall not fail. */ - sigaction(SIGINT, &handler, &_oldhandler); - - /* Unmask SIGINT. Remember to mask it again on restore. */ - sigprocmask(0, NULL, &sigs); - if ((_oldmasked = sigismember(&sigs, SIGINT))) { - sigdelset(&sigs, SIGINT); - sigprocmask(SIG_SETMASK, &sigs, NULL); - } -} - -void sigint_restore(void) -{ - if (!_handler_installed) - return; - - if (_handler_installed > 1) { - _handler_installed--; - return; - } - - /* Nesting count went down to 0. */ - _handler_installed = 0; - - if (_oldmasked) { - sigset_t sigs; - sigprocmask(0, NULL, &sigs); - sigaddset(&sigs, SIGINT); - sigprocmask(SIG_SETMASK, &sigs, NULL); - } - - sigaction(SIGINT, &_oldhandler, NULL); -} - -static void _block_signals(uint32_t flags __attribute__((unused))) -{ - sigset_t set; - - if (_signals_blocked) - return; - - if (sigfillset(&set)) { - log_sys_error("sigfillset", "_block_signals"); - return; - } - - if (sigprocmask(SIG_SETMASK, &set, &_oldset)) { - log_sys_error("sigprocmask", "_block_signals"); - return; - } - - _signals_blocked = 1; -} - -static void _unblock_signals(void) -{ - /* Don't unblock signals while any locks are held */ - if (!_signals_blocked || _vg_lock_count) - return; - - if (sigprocmask(SIG_SETMASK, &_oldset, NULL)) { - log_sys_error("sigprocmask", "_block_signals"); - return; - } - - _signals_blocked = 0; -} - static void _lock_memory(struct cmd_context *cmd, lv_operation_t lv_op) { if (!(_locking.flags & LCK_PRE_MEMLOCK)) @@ -182,6 +59,13 @@ static void _unlock_memory(struct cmd_context *cmd, lv_operation_t lv_op) critical_section_dec(cmd, "unlocking on resume"); } +static void _unblock_signals(void) +{ + /* Don't unblock signals while any locks are held */ + if (!_vg_lock_count) + unblock_signals(); +} + void reset_locking(void) { int was_locked = _vg_lock_count; @@ -366,7 +250,7 @@ static int _lock_vol(struct cmd_context *cmd, const char *resource, uint32_t lck_scope = flags & LCK_SCOPE_MASK; int ret = 0; - _block_signals(flags); + block_signals(flags); _lock_memory(cmd, lv_op); assert(resource); diff --git a/lib/locking/locking.h b/lib/locking/locking.h index aa42138..0945aa0 100644 --- a/lib/locking/locking.h +++ b/lib/locking/locking.h @@ -213,10 +213,4 @@ int resume_lvs(struct cmd_context *cmd, struct dm_list *lvs); int revert_lvs(struct cmd_context *cmd, struct dm_list *lvs); int activate_lvs(struct cmd_context *cmd, struct dm_list *lvs, unsigned exclusive); -/* Interrupt handling */ -void sigint_clear(void); -void sigint_allow(void); -void sigint_restore(void); -int sigint_caught(void); - #endif diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c index 85f7a39..6817831 100644 --- a/lib/metadata/lv_manip.c +++ b/lib/metadata/lv_manip.c @@ -28,6 +28,7 @@ #include "str_list.h" #include "defaults.h" #include "lvm-exec.h" +#include "lvm-signal.h" typedef enum { PREFERRED, diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c index e2abba7..4791c10 100644 --- a/lib/metadata/metadata.c +++ b/lib/metadata/metadata.c @@ -19,6 +19,7 @@ #include "toolcontext.h" #include "lvm-string.h" #include "lvm-file.h" +#include "lvm-signal.h" #include "lvmcache.h" #include "lvmetad.h" #include "memlock.h" diff --git a/lib/misc/lvm-flock.h b/lib/misc/lvm-flock.h index 5e8aefd..3fed73e 100644 --- a/lib/misc/lvm-flock.h +++ b/lib/misc/lvm-flock.h @@ -12,11 +12,11 @@ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef _LVM_SIGNAL_H -# define _LVM_SIGNAL_H +#ifndef _LVM_FLOCK_H +#define _LVM_FLOCK_H void init_flock(struct cmd_context *cmd); int lock_file(const char *file, uint32_t flags); void release_flocks(int unlock); -#endif /* _LVM_SIGNAL_H */ +#endif /* _LVM_FLOCK_H */ diff --git a/lib/misc/lvm-signal.c b/lib/misc/lvm-signal.c index 927e839..f2d6d3b 100644 --- a/lib/misc/lvm-signal.c +++ b/lib/misc/lvm-signal.c @@ -22,6 +22,13 @@ static sig_t _oldhandler; static sigset_t _fullsigset, _intsigset; static volatile sig_atomic_t _handler_installed; +static sigset_t _oldset; +static int _signals_blocked = 0; +static volatile sig_atomic_t _sigint_caught = 0; +static volatile sig_atomic_t _handler_installed2; +static struct sigaction _oldhandler2; +static int _oldmasked; + void remove_ctrl_c_handler(void) { siginterrupt(SIGINT, 0); @@ -54,3 +61,119 @@ void install_ctrl_c_handler(void) sigprocmask(SIG_SETMASK, &_intsigset, NULL); siginterrupt(SIGINT, 1); } + +static void _catch_sigint(int unused __attribute__((unused))) +{ + _sigint_caught = 1; +} + +int sigint_caught(void) { + if (_sigint_caught) + log_error("Interrupted..."); + + return _sigint_caught; +} + +void sigint_clear(void) +{ + _sigint_caught = 0; +} + +/* + * Temporarily allow keyboard interrupts to be intercepted and noted; + * saves interrupt handler state for sigint_restore(). Users should + * use the sigint_caught() predicate to check whether interrupt was + * requested and act appropriately. Interrupt flags are never + * cleared automatically by this code, but the tools clear the flag + * before running each command in lvm_run_command(). All other places + * where the flag needs to be cleared need to call sigint_clear(). + */ + +void sigint_allow(void) +{ + struct sigaction handler; + sigset_t sigs; + + /* + * Do not overwrite the backed-up handler data - + * just increase nesting count. + */ + if (_handler_installed2) { + _handler_installed2++; + return; + } + + /* Grab old sigaction for SIGINT: shall not fail. */ + sigaction(SIGINT, NULL, &handler); + handler.sa_flags &= ~SA_RESTART; /* Clear restart flag */ + handler.sa_handler = _catch_sigint; + + _handler_installed2 = 1; + + /* Override the signal handler: shall not fail. */ + sigaction(SIGINT, &handler, &_oldhandler2); + + /* Unmask SIGINT. Remember to mask it again on restore. */ + sigprocmask(0, NULL, &sigs); + if ((_oldmasked = sigismember(&sigs, SIGINT))) { + sigdelset(&sigs, SIGINT); + sigprocmask(SIG_SETMASK, &sigs, NULL); + } +} + +void sigint_restore(void) +{ + if (!_handler_installed2) + return; + + if (_handler_installed2 > 1) { + _handler_installed2--; + return; + } + + /* Nesting count went down to 0. */ + _handler_installed2 = 0; + + if (_oldmasked) { + sigset_t sigs; + sigprocmask(0, NULL, &sigs); + sigaddset(&sigs, SIGINT); + sigprocmask(SIG_SETMASK, &sigs, NULL); + } + + sigaction(SIGINT, &_oldhandler2, NULL); +} + +void block_signals(uint32_t flags __attribute__((unused))) +{ + sigset_t set; + + if (_signals_blocked) + return; + + if (sigfillset(&set)) { + log_sys_error("sigfillset", "_block_signals"); + return; + } + + if (sigprocmask(SIG_SETMASK, &set, &_oldset)) { + log_sys_error("sigprocmask", "_block_signals"); + return; + } + + _signals_blocked = 1; +} + +void unblock_signals(void) +{ + /* Don't unblock signals while any locks are held */ + if (!_signals_blocked) + return; + + if (sigprocmask(SIG_SETMASK, &_oldset, NULL)) { + log_sys_error("sigprocmask", "_block_signals"); + return; + } + + _signals_blocked = 0; +} diff --git a/lib/misc/lvm-signal.h b/lib/misc/lvm-signal.h index ce9d2e9..f2e6141 100644 --- a/lib/misc/lvm-signal.h +++ b/lib/misc/lvm-signal.h @@ -14,7 +14,17 @@ */ #ifndef _LVM_SIGNAL_H -# define _LVM_SIGNAL_H +#define _LVM_SIGNAL_H + void remove_ctrl_c_handler(void); void install_ctrl_c_handler(void); + +void sigint_allow(void); +int sigint_caught(void); +void sigint_restore(void); +void sigint_clear(void); + +void block_signals(uint32_t flags); +void unblock_signals(void); + #endif diff --git a/tools/tools.h b/tools/tools.h index a2bfe0d..11111cb 100644 --- a/tools/tools.h +++ b/tools/tools.h @@ -40,6 +40,7 @@ #include "locking.h" #include "lvm-exec.h" #include "lvm-file.h" +#include "lvm-signal.h" #include "lvm-string.h" #include "segtype.h" #include "str_list.h"
1
0
0
0
master - locking: Separate out flock and signal code.
by Alasdair Kergon
01 May '14
01 May '14
Gitweb:
http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=29a3fbf067e1685a…
Commit: 29a3fbf067e1685ae7e202959a414e4b13f547c7 Parent: 239ba5bb04deccee83aa603efee11a9670f6f3fe Author: Alasdair G Kergon <agk(a)redhat.com> AuthorDate: Thu May 1 17:37:14 2014 +0100 Committer: Alasdair G Kergon <agk(a)redhat.com> CommitterDate: Thu May 1 17:37:14 2014 +0100 locking: Separate out flock and signal code. --- include/.symlinks.in | 6 +- lib/Makefile.in | 2 + lib/locking/file_locking.c | 231 +------------------------------------------ lib/misc/lvm-flock.c | 223 ++++++++++++++++++++++++++++++++++++++++++ lib/misc/lvm-flock.h | 22 ++++ lib/misc/lvm-signal.c | 56 +++++++++++ lib/misc/lvm-signal.h | 20 ++++ 7 files changed, 333 insertions(+), 227 deletions(-) diff --git a/include/.symlinks.in b/include/.symlinks.in index 44076c8..ced2cb3 100644 --- a/include/.symlinks.in +++ b/include/.symlinks.in @@ -42,17 +42,19 @@ @top_builddir@/lib/misc/configure.h @top_srcdir@/lib/misc/crc.h @top_srcdir@/lib/misc/intl.h -@top_srcdir@/lib/misc/util.h @top_srcdir@/lib/misc/last-path-component.h @top_srcdir@/lib/misc/lib.h @top_srcdir@/lib/misc/lvm-exec.h @top_srcdir@/lib/misc/lvm-file.h +@top_srcdir@/lib/misc/lvm-flock.h @top_srcdir@/lib/misc/lvm-globals.h +@top_srcdir@/lib/misc/lvm-signal.h @top_srcdir@/lib/misc/lvm-string.h @top_builddir@/lib/misc/lvm-version.h -@top_srcdir@/lib/misc/lvm-wrappers.h @top_srcdir@/lib/misc/lvm-percent.h +@top_srcdir@/lib/misc/lvm-wrappers.h @top_srcdir@/lib/misc/sharedlib.h +@top_srcdir@/lib/misc/util.h @top_srcdir@/lib/properties/prop_common.h @top_srcdir@/lib/report/properties.h @top_srcdir@/lib/report/report.h diff --git a/lib/Makefile.in b/lib/Makefile.in index c3d4598..9f101f3 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -106,7 +106,9 @@ SOURCES =\ misc/crc.c \ misc/lvm-exec.c \ misc/lvm-file.c \ + misc/lvm-flock.c \ misc/lvm-globals.c \ + misc/lvm-signal.c \ misc/lvm-string.c \ misc/lvm-wrappers.c \ misc/lvm-percent.c \ diff --git a/lib/locking/file_locking.c b/lib/locking/file_locking.c index 734e0b4..2f6716d 100644 --- a/lib/locking/file_locking.c +++ b/lib/locking/file_locking.c @@ -21,6 +21,7 @@ #include "defaults.h" #include "lvm-file.h" #include "lvm-string.h" +#include "lvm-flock.h" #include "lvmcache.h" #include <limits.h> @@ -30,237 +31,20 @@ #include <fcntl.h> #include <signal.h> -struct lock_list { - struct dm_list list; - int lf; - char *res; -}; - -static struct dm_list _lock_list; static char _lock_dir[PATH_MAX]; -static int _prioritise_write_locks; static sig_t _oldhandler; static sigset_t _fullsigset, _intsigset; 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) -{ - struct stat buf1, buf2; - - log_debug_locking("_undo_flock %s", file); - if (!flock(fd, LOCK_NB | LOCK_EX) && - !stat(file, &buf1) && - !fstat(fd, &buf2) && - is_same_inode(buf1, buf2)) - if (unlink(file)) - log_sys_debug("unlink", file); - - if (close(fd) < 0) - log_sys_debug("close", file); -} - -static int _release_lock(const char *file, int unlock) -{ - struct lock_list *ll; - struct dm_list *llh, *llt; - - dm_list_iterate_safe(llh, llt, &_lock_list) { - ll = dm_list_item(llh, struct lock_list); - - if (!file || !strcmp(ll->res, file)) { - dm_list_del(llh); - if (unlock) { - log_very_verbose("Unlocking %s", ll->res); - if (flock(ll->lf, LOCK_NB | LOCK_UN)) - log_sys_debug("flock", ll->res); - _undo_flock(ll->res, ll->lf); - } else - _drop_shared_flock(ll->res, ll->lf); - - dm_free(ll->res); - dm_free(llh); - - if (file) - return 1; - } - } - - return 0; -} - static void _fin_file_locking(void) { - _release_lock(NULL, 1); + release_flocks(1); } static void _reset_file_locking(void) { - _release_lock(NULL, 0); -} - -static void _remove_ctrl_c_handler(void) -{ - siginterrupt(SIGINT, 0); - if (!_handler_installed) - return; - - _handler_installed = 0; - - sigprocmask(SIG_SETMASK, &_fullsigset, NULL); - if (signal(SIGINT, _oldhandler) == SIG_ERR) - log_sys_error("signal", "_remove_ctrl_c_handler"); -} - -static void _trap_ctrl_c(int sig __attribute__((unused))) -{ - _remove_ctrl_c_handler(); - log_error("CTRL-c detected: giving up waiting for lock"); -} - -static void _install_ctrl_c_handler(void) -{ - _handler_installed = 1; - - if ((_oldhandler = signal(SIGINT, _trap_ctrl_c)) == SIG_ERR) { - _handler_installed = 0; - return; - } - - sigprocmask(SIG_SETMASK, &_intsigset, NULL); - siginterrupt(SIGINT, 1); -} - -static int _do_flock(const char *file, int *fd, int operation, uint32_t nonblock) -{ - int r = 1; - int old_errno; - struct stat buf1, buf2; - - log_debug_locking("_do_flock %s %c%c", file, - operation == LOCK_EX ? 'W' : 'R', nonblock ? ' ' : 'B'); - do { - if ((*fd > -1) && close(*fd)) - log_sys_debug("close", file); - - if ((*fd = open(file, O_CREAT | O_APPEND | O_RDWR, 0777)) < 0) { - log_sys_error("open", file); - return 0; - } - - if (nonblock) - operation |= LOCK_NB; - else - _install_ctrl_c_handler(); - - r = flock(*fd, operation); - old_errno = errno; - if (!nonblock) - _remove_ctrl_c_handler(); - - if (r) { - errno = old_errno; - log_sys_error("flock", file); - if (close(*fd)) - log_sys_debug("close", file); - *fd = -1; - return 0; - } - - if (!stat(file, &buf1) && !fstat(*fd, &buf2) && - is_same_inode(buf1, buf2)) - return 1; - } while (!nonblock); - - return_0; -} - -#define AUX_LOCK_SUFFIX ":aux" - -static int _do_write_priority_flock(const char *file, int *fd, int operation, uint32_t nonblock) -{ - int r, fd_aux = -1; - char *file_aux = alloca(strlen(file) + sizeof(AUX_LOCK_SUFFIX)); - - strcpy(file_aux, file); - strcat(file_aux, AUX_LOCK_SUFFIX); - - if ((r = _do_flock(file_aux, &fd_aux, LOCK_EX, 0))) { - if (operation == LOCK_EX) { - r = _do_flock(file, fd, operation, nonblock); - _undo_flock(file_aux, fd_aux); - } else { - _undo_flock(file_aux, fd_aux); - r = _do_flock(file, fd, operation, nonblock); - } - } - - return r; -} - -static int _lock_file(const char *file, uint32_t flags) -{ - int operation; - uint32_t nonblock = flags & LCK_NONBLOCK; - int r; - - struct lock_list *ll; - char state; - - switch (flags & LCK_TYPE_MASK) { - case LCK_READ: - operation = LOCK_SH; - state = 'R'; - break; - case LCK_WRITE: - operation = LOCK_EX; - state = 'W'; - break; - case LCK_UNLOCK: - return _release_lock(file, 1); - default: - log_error("Unrecognised lock type: %d", flags & LCK_TYPE_MASK); - return 0; - } - - if (!(ll = dm_malloc(sizeof(struct lock_list)))) - return_0; - - if (!(ll->res = dm_strdup(file))) { - dm_free(ll); - return_0; - } - - ll->lf = -1; - - log_very_verbose("Locking %s %c%c", ll->res, state, - nonblock ? ' ' : 'B'); - - (void) dm_prepare_selinux_context(file, S_IFREG); - if (_prioritise_write_locks) - r = _do_write_priority_flock(file, &ll->lf, operation, nonblock); - else - r = _do_flock(file, &ll->lf, operation, nonblock); - (void) dm_prepare_selinux_context(NULL, 0); - - if (r) - dm_list_add(&_lock_list, &ll->list); - else { - dm_free(ll->res); - dm_free(ll); - stack; - } - - return r; + release_flocks(0); } static int _file_lock_resource(struct cmd_context *cmd, const char *resource, @@ -298,7 +82,7 @@ static int _file_lock_resource(struct cmd_context *cmd, const char *resource, return 0; } - if (!_lock_file(lockfile, flags)) + if (!lock_file(lockfile, flags)) return_0; break; case LCK_LV: @@ -352,6 +136,8 @@ int init_file_locking(struct locking_type *locking, struct cmd_context *cmd, int r; const char *locking_dir; + init_flock(cmd); + locking->lock_resource = _file_lock_resource; locking->reset_locking = _reset_file_locking; locking->fin_locking = _fin_file_locking; @@ -366,9 +152,6 @@ int init_file_locking(struct locking_type *locking, struct cmd_context *cmd, strcpy(_lock_dir, locking_dir); - _prioritise_write_locks = - find_config_tree_bool(cmd, global_prioritise_write_locks_CFG, NULL); - (void) dm_prepare_selinux_context(_lock_dir, S_IFDIR); r = dm_create_dir(_lock_dir); (void) dm_prepare_selinux_context(NULL, 0); @@ -380,8 +163,6 @@ int init_file_locking(struct locking_type *locking, struct cmd_context *cmd, if ((access(_lock_dir, R_OK | W_OK | X_OK) == -1) && (errno == EROFS)) return 0; - dm_list_init(&_lock_list); - if (sigfillset(&_intsigset) || sigfillset(&_fullsigset)) { log_sys_error_suppress(suppress_messages, "sigfillset", "init_file_locking"); diff --git a/lib/misc/lvm-flock.c b/lib/misc/lvm-flock.c new file mode 100644 index 0000000..ca05e1c --- /dev/null +++ b/lib/misc/lvm-flock.c @@ -0,0 +1,223 @@ +/* + * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. + * Copyright (C) 2004-2014 Red Hat, Inc. All rights reserved. + * + * This file is part of LVM2. + * + * 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 Lesser General Public License v.2.1. + * + * You should have received a copy of the GNU Lesser 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 + */ + +#include "lib.h" +#include "config.h" +#include "lvm-file.h" +#include "lvm-flock.h" +#include "lvm-signal.h" +#include "locking.h" + +#include <sys/file.h> +#include <fcntl.h> + +struct lock_list { + struct dm_list list; + int lf; + char *res; +}; + +static struct dm_list _lock_list; +static int _prioritise_write_locks; + +/* 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) +{ + struct stat buf1, buf2; + + log_debug_locking("_undo_flock %s", file); + if (!flock(fd, LOCK_NB | LOCK_EX) && + !stat(file, &buf1) && + !fstat(fd, &buf2) && + is_same_inode(buf1, buf2)) + if (unlink(file)) + log_sys_debug("unlink", file); + + if (close(fd) < 0) + log_sys_debug("close", file); +} + +static int _release_lock(const char *file, int unlock) +{ + struct lock_list *ll; + struct dm_list *llh, *llt; + + dm_list_iterate_safe(llh, llt, &_lock_list) { + ll = dm_list_item(llh, struct lock_list); + + if (!file || !strcmp(ll->res, file)) { + dm_list_del(llh); + if (unlock) { + log_very_verbose("Unlocking %s", ll->res); + if (flock(ll->lf, LOCK_NB | LOCK_UN)) + log_sys_debug("flock", ll->res); + _undo_flock(ll->res, ll->lf); + } else + _drop_shared_flock(ll->res, ll->lf); + + dm_free(ll->res); + dm_free(llh); + + if (file) + return 1; + } + } + + return 0; +} + +void release_flocks(int unlock) +{ + _release_lock(NULL, unlock); +} + +static int _do_flock(const char *file, int *fd, int operation, uint32_t nonblock) +{ + int r = 1; + int old_errno; + struct stat buf1, buf2; + + log_debug_locking("_do_flock %s %c%c", file, + operation == LOCK_EX ? 'W' : 'R', nonblock ? ' ' : 'B'); + do { + if ((*fd > -1) && close(*fd)) + log_sys_debug("close", file); + + if ((*fd = open(file, O_CREAT | O_APPEND | O_RDWR, 0777)) < 0) { + log_sys_error("open", file); + return 0; + } + + if (nonblock) + operation |= LOCK_NB; + else + install_ctrl_c_handler(); + + r = flock(*fd, operation); + old_errno = errno; + if (!nonblock) + remove_ctrl_c_handler(); + + if (r) { + errno = old_errno; + log_sys_error("flock", file); + if (close(*fd)) + log_sys_debug("close", file); + *fd = -1; + return 0; + } + + if (!stat(file, &buf1) && !fstat(*fd, &buf2) && + is_same_inode(buf1, buf2)) + return 1; + } while (!nonblock); + + return_0; +} + +#define AUX_LOCK_SUFFIX ":aux" + +static int _do_write_priority_flock(const char *file, int *fd, int operation, uint32_t nonblock) +{ + int r, fd_aux = -1; + char *file_aux = alloca(strlen(file) + sizeof(AUX_LOCK_SUFFIX)); + + strcpy(file_aux, file); + strcat(file_aux, AUX_LOCK_SUFFIX); + + if ((r = _do_flock(file_aux, &fd_aux, LOCK_EX, 0))) { + if (operation == LOCK_EX) { + r = _do_flock(file, fd, operation, nonblock); + _undo_flock(file_aux, fd_aux); + } else { + _undo_flock(file_aux, fd_aux); + r = _do_flock(file, fd, operation, nonblock); + } + } + + return r; +} + +int lock_file(const char *file, uint32_t flags) +{ + int operation; + uint32_t nonblock = flags & LCK_NONBLOCK; + int r; + + struct lock_list *ll; + char state; + + switch (flags & LCK_TYPE_MASK) { + case LCK_READ: + operation = LOCK_SH; + state = 'R'; + break; + case LCK_WRITE: + operation = LOCK_EX; + state = 'W'; + break; + case LCK_UNLOCK: + return _release_lock(file, 1); + default: + log_error("Unrecognised lock type: %d", flags & LCK_TYPE_MASK); + return 0; + } + + if (!(ll = dm_malloc(sizeof(struct lock_list)))) + return_0; + + if (!(ll->res = dm_strdup(file))) { + dm_free(ll); + return_0; + } + + ll->lf = -1; + + log_very_verbose("Locking %s %c%c", ll->res, state, + nonblock ? ' ' : 'B'); + + (void) dm_prepare_selinux_context(file, S_IFREG); + if (_prioritise_write_locks) + r = _do_write_priority_flock(file, &ll->lf, operation, nonblock); + else + r = _do_flock(file, &ll->lf, operation, nonblock); + (void) dm_prepare_selinux_context(NULL, 0); + + if (r) + dm_list_add(&_lock_list, &ll->list); + else { + dm_free(ll->res); + dm_free(ll); + stack; + } + + return r; +} + +void init_flock(struct cmd_context *cmd) +{ + dm_list_init(&_lock_list); + + _prioritise_write_locks = + find_config_tree_bool(cmd, global_prioritise_write_locks_CFG, NULL); +} diff --git a/lib/misc/lvm-flock.h b/lib/misc/lvm-flock.h new file mode 100644 index 0000000..5e8aefd --- /dev/null +++ b/lib/misc/lvm-flock.h @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2014 Red Hat, Inc. All rights reserved. + * + * This file is part of LVM2. + * + * 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 Lesser General Public License v.2.1. + * + * You should have received a copy of the GNU Lesser 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 + */ + +#ifndef _LVM_SIGNAL_H +# define _LVM_SIGNAL_H + +void init_flock(struct cmd_context *cmd); +int lock_file(const char *file, uint32_t flags); +void release_flocks(int unlock); + +#endif /* _LVM_SIGNAL_H */ diff --git a/lib/misc/lvm-signal.c b/lib/misc/lvm-signal.c new file mode 100644 index 0000000..927e839 --- /dev/null +++ b/lib/misc/lvm-signal.c @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. + * Copyright (C) 2004-2014 Red Hat, Inc. All rights reserved. + * + * This file is part of LVM2. + * + * 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 Lesser General Public License v.2.1. + * + * You should have received a copy of the GNU Lesser 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 + */ + +#include "lib.h" +#include "lvm-signal.h" + +#include <signal.h> + +static sig_t _oldhandler; +static sigset_t _fullsigset, _intsigset; +static volatile sig_atomic_t _handler_installed; + +void remove_ctrl_c_handler(void) +{ + siginterrupt(SIGINT, 0); + if (!_handler_installed) + return; + + _handler_installed = 0; + + sigprocmask(SIG_SETMASK, &_fullsigset, NULL); + if (signal(SIGINT, _oldhandler) == SIG_ERR) + log_sys_error("signal", "_remove_ctrl_c_handler"); +} + +static void _trap_ctrl_c(int sig __attribute__((unused))) +{ + remove_ctrl_c_handler(); + + log_error("CTRL-c detected: giving up waiting for lock"); +} + +void install_ctrl_c_handler(void) +{ + _handler_installed = 1; + + if ((_oldhandler = signal(SIGINT, _trap_ctrl_c)) == SIG_ERR) { + _handler_installed = 0; + return; + } + + sigprocmask(SIG_SETMASK, &_intsigset, NULL); + siginterrupt(SIGINT, 1); +} diff --git a/lib/misc/lvm-signal.h b/lib/misc/lvm-signal.h new file mode 100644 index 0000000..ce9d2e9 --- /dev/null +++ b/lib/misc/lvm-signal.h @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. + * Copyright (C) 2004-2014 Red Hat, Inc. All rights reserved. + * + * This file is part of LVM2. + * + * 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 Lesser General Public License v.2.1. + * + * You should have received a copy of the GNU Lesser 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 + */ + +#ifndef _LVM_SIGNAL_H +# define _LVM_SIGNAL_H +void remove_ctrl_c_handler(void); +void install_ctrl_c_handler(void); +#endif
1
0
0
0
← Newer
1
...
26
27
28
29
12
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
Results per page:
10
25
50
100
200