From 7e3d403b88049abc81e4e6e01c2d9a1f57c38398 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Thu, 11 Apr 2002 14:10:32 +0000 Subject: [PATCH] Implement a no_locking module that *does* attempt activation. --- lib/Makefile.in | 3 +- lib/locking/locking.c | 22 +------------- lib/locking/locking_types.h | 2 ++ lib/locking/no_locking.c | 60 +++++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 22 deletions(-) create mode 100644 lib/locking/no_locking.c diff --git a/lib/Makefile.in b/lib/Makefile.in index d791f0057..f3842ca57 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -38,9 +38,10 @@ SOURCES=\ format_text/import.c \ label/label.c \ label/uuid-map.c \ - locking/file_locking.c \ locking/external_locking.c \ + locking/file_locking.c \ locking/locking.c \ + locking/no_locking.c \ log/log.c \ metadata/lv_manip.c \ metadata/merge.c \ diff --git a/lib/locking/locking.c b/lib/locking/locking.c index b75a6a472..0073d4893 100644 --- a/lib/locking/locking.c +++ b/lib/locking/locking.c @@ -65,26 +65,6 @@ static inline void _update_lock_count(int flags) _lock_count++; } -/* - * No locking - currently does nothing. - */ -int no_lock_resource(struct cmd_context *cmd, const char *resource, int flags) -{ - return 1; -} - -void no_fin_locking(void) -{ - return; -} - -static void _init_no_locking(struct locking_type *locking, - struct config_file *cf) -{ - locking->lock_resource = no_lock_resource; - locking->fin_locking = no_fin_locking; -} - /* * Select a locking type */ @@ -92,7 +72,7 @@ int init_locking(int type, struct config_file *cf) { switch (type) { case 0: - _init_no_locking(&_locking, cf); + init_no_locking(&_locking, cf); log_print("WARNING: Locking disabled. Be careful! " "This could corrupt your metadata."); break; diff --git a/lib/locking/locking_types.h b/lib/locking/locking_types.h index cefa1db2c..a8a94ad1d 100644 --- a/lib/locking/locking_types.h +++ b/lib/locking/locking_types.h @@ -24,6 +24,8 @@ struct locking_type { /* * Locking types */ +int init_no_locking(struct locking_type *locking, struct config_file *cf); + int init_file_locking(struct locking_type *locking, struct config_file *cf); int init_external_locking(struct locking_type *locking, struct config_file *cf); diff --git a/lib/locking/no_locking.c b/lib/locking/no_locking.c new file mode 100644 index 000000000..b4af79664 --- /dev/null +++ b/lib/locking/no_locking.c @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2001 Sistina Software (UK) Limited. + * + * This file is released under the LGPL. + * + */ + +#include "log.h" +#include "locking.h" +#include "locking_types.h" +#include "lvm-string.h" +#include "activate.h" + +#include + +/* + * No locking + */ + +static void _no_fin_locking(void) +{ + return; +} + +static int _no_lock_resource(struct cmd_context *cmd, const char *resource, + int flags) +{ + switch (flags & LCK_SCOPE_MASK) { + case LCK_VG: + break; + case LCK_LV: + switch (flags & LCK_TYPE_MASK) { + case LCK_UNLOCK: + return lv_resume_if_active(cmd, resource); + case LCK_READ: + return lv_activate(cmd, resource); + case LCK_WRITE: + return lv_suspend_if_active(cmd, resource); + case LCK_EXCL: + return lv_deactivate(cmd, resource); + default: + break; + } + break; + default: + log_error("Unrecognised lock scope: %d", + flags & LCK_SCOPE_MASK); + return 0; + } + + return 1; +} + +int init_no_locking(struct locking_type *locking, struct config_file *cf) +{ + locking->lock_resource = _no_lock_resource; + locking->fin_locking = _no_fin_locking; + + return 1; +} -- 2.43.5