master - Remove locking infrastructure from activation paths
by Joe Thornber
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=da30b4a7865b82c05cd...
Commit: da30b4a7865b82c05cd2be1a8eb3bca42c39abb3
Parent: 616eeba6f2b33640534e26dea43661724edf3a14
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Tue Jun 5 16:47:24 2018 -0500
Committer: Joe Thornber <ejt(a)redhat.com>
CommitterDate: Thu Jun 7 16:17:04 2018 +0100
Remove locking infrastructure from activation paths
Basic LV functions:
activate_lv(), deactivate_lv(),
suspend_lv(), resume_lv()
were routed through the locking infrastruture on the way to:
lv_activate_with_filter(), lv_deactivate(),
lv_suspend_if_active(), lv_resume_if_active()
This commit removes the locking infrastructure from the
middle and calls the later functions directly from the former.
There were a couple of ancillary steps that the locking
infrastructure added along the way which are still included:
- critical section inc/dec during suspend/resume
- checking for active component LVs during activate
The "activation" file lock (serializing activation) has not
been kept because activation commands have been changed to
take the VG file lock exclusively which makes the activation
lock unused and unnecessary.
---
lib/activate/activate.c | 103 ++++++++++++++++++++++++++++++++++++++++----
lib/activate/activate.h | 8 +++
lib/locking/file_locking.c | 48 --------------------
lib/locking/locking.c | 65 ++-------------------------
lib/locking/locking.h | 76 --------------------------------
5 files changed, 107 insertions(+), 193 deletions(-)
diff --git a/lib/activate/activate.c b/lib/activate/activate.c
index c9ead42..a7e5fe3 100644
--- a/lib/activate/activate.c
+++ b/lib/activate/activate.c
@@ -2424,15 +2424,6 @@ static int _lv_activate(struct cmd_context *cmd, const char *lvid_s,
if (!activation())
return 1;
- if (!laopts->exclusive &&
- (lv_is_origin(lv) ||
- seg_only_exclusive(first_seg(lv)))) {
- log_error(INTERNAL_ERROR "Trying non-exlusive activation of %s with "
- "a volume type %s requiring exclusive activation.",
- display_lvname(lv), lvseg_name(first_seg(lv)));
- return 0;
- }
-
if (filter && !_passes_activation_filter(cmd, lv)) {
log_verbose("Not activating %s since it does not pass "
"activation filter.", display_lvname(lv));
@@ -2765,3 +2756,97 @@ int deactivate_lv_with_sub_lv(const struct logical_volume *lv)
return 1;
}
+
+int activate_lv(struct cmd_context *cmd, const struct logical_volume *lv)
+{
+ const struct logical_volume *active_lv;
+ int ret;
+
+ /*
+ * When trying activating component LV, make sure none of sub component
+ * LV or LVs that are using it are active.
+ */
+ if (!lv_is_visible(lv))
+ active_lv = lv_holder_is_active(lv);
+ else
+ active_lv = lv_component_is_active(lv);
+
+ if (active_lv) {
+ log_error("Activation of logical volume %s is prohibited while logical volume %s is active.",
+ display_lvname(lv), display_lvname(active_lv));
+ ret = 0;
+ goto out;
+ }
+
+ ret = lv_activate_with_filter(cmd, NULL, 0,
+ (lv->status & LV_NOSCAN) ? 1 : 0,
+ (lv->status & LV_TEMPORARY) ? 1 : 0,
+ lv_committed(lv));
+out:
+ return ret;
+}
+
+int deactivate_lv(struct cmd_context *cmd, const struct logical_volume *lv)
+{
+ int ret;
+
+ ret = lv_deactivate(cmd, NULL, lv_committed(lv));
+
+ return ret;
+}
+
+int suspend_lv(struct cmd_context *cmd, const struct logical_volume *lv)
+{
+ int ret;
+
+ critical_section_inc(cmd, "locking for suspend");
+
+ ret = lv_suspend_if_active(cmd, NULL, 0, 0, lv_committed(lv), lv);
+
+ return ret;
+}
+
+int suspend_lv_origin(struct cmd_context *cmd, const struct logical_volume *lv)
+{
+ int ret;
+
+ critical_section_inc(cmd, "locking for suspend");
+
+ ret = lv_suspend_if_active(cmd, NULL, 1, 0, lv_committed(lv), lv);
+
+ return ret;
+}
+
+int resume_lv(struct cmd_context *cmd, const struct logical_volume *lv)
+{
+ int ret;
+
+ ret = lv_resume_if_active(cmd, NULL, 0, 0, 0, lv_committed(lv));
+
+ critical_section_dec(cmd, "unlocking on resume");
+
+ return ret;
+}
+
+int resume_lv_origin(struct cmd_context *cmd, const struct logical_volume *lv)
+{
+ int ret;
+
+ ret = lv_resume_if_active(cmd, NULL, 1, 0, 0, lv_committed(lv));
+
+ critical_section_dec(cmd, "unlocking on resume");
+
+ return ret;
+}
+
+int revert_lv(struct cmd_context *cmd, const struct logical_volume *lv)
+{
+ int ret;
+
+ ret = lv_resume_if_active(cmd, NULL, 0, 0, 1, lv_committed(lv));
+
+ critical_section_dec(cmd, "unlocking on resume");
+
+ return ret;
+}
+
diff --git a/lib/activate/activate.h b/lib/activate/activate.h
index 8b6c4ad..2f0b0a0 100644
--- a/lib/activate/activate.h
+++ b/lib/activate/activate.h
@@ -126,6 +126,14 @@ int lv_mknodes(struct cmd_context *cmd, const struct logical_volume *lv);
int lv_deactivate_any_missing_subdevs(const struct logical_volume *lv);
+int activate_lv(struct cmd_context *cmd, const struct logical_volume *lv);
+int deactivate_lv(struct cmd_context *cmd, const struct logical_volume *lv);
+int suspend_lv(struct cmd_context *cmd, const struct logical_volume *lv);
+int suspend_lv_origin(struct cmd_context *cmd, const struct logical_volume *lv);
+int resume_lv(struct cmd_context *cmd, const struct logical_volume *lv);
+int resume_lv_origin(struct cmd_context *cmd, const struct logical_volume *lv);
+int revert_lv(struct cmd_context *cmd, const struct logical_volume *lv);
+
/*
* Returns 1 if info structure has been populated, else 0 on failure.
* When lvinfo* is NULL, it returns 1 if the device is locally active, 0 otherwise.
diff --git a/lib/locking/file_locking.c b/lib/locking/file_locking.c
index d4f47c6..a60a3e5 100644
--- a/lib/locking/file_locking.c
+++ b/lib/locking/file_locking.c
@@ -44,20 +44,8 @@ static int _file_lock_resource(struct cmd_context *cmd, const char *resource,
uint32_t flags, const struct logical_volume *lv)
{
char lockfile[PATH_MAX];
- unsigned origin_only = (flags & LCK_ORIGIN_ONLY) ? 1 : 0;
- unsigned revert = (flags & LCK_REVERT) ? 1 : 0;
switch (flags & LCK_SCOPE_MASK) {
- case LCK_ACTIVATION:
- if (dm_snprintf(lockfile, sizeof(lockfile),
- "%s/A_%s", _lock_dir, resource) < 0) {
- log_error("Too long locking filename %s/A_%s.", _lock_dir, resource);
- return 0;
- }
-
- if (!lock_file(lockfile, flags))
- return_0;
- break;
case LCK_VG:
if (!strcmp(resource, VG_SYNC_NAMES))
fs_unlock();
@@ -84,42 +72,6 @@ static int _file_lock_resource(struct cmd_context *cmd, const char *resource,
if (!lock_file(lockfile, flags))
return_0;
break;
- case LCK_LV:
- switch (flags & LCK_TYPE_MASK) {
- case LCK_UNLOCK:
- log_very_verbose("Unlocking LV %s%s%s", resource, origin_only ? " without snapshots" : "", revert ? " (reverting)" : "");
- if (!lv_resume_if_active(cmd, resource, origin_only, 0, revert, lv_committed(lv)))
- return 0;
- break;
- case LCK_NULL:
- log_very_verbose("Locking LV %s (NL)", resource);
- if (!lv_deactivate(cmd, resource, lv_committed(lv)))
- return 0;
- break;
- case LCK_READ:
- log_very_verbose("Locking LV %s (R)", resource);
- if (!lv_activate_with_filter(cmd, resource, 0, (lv->status & LV_NOSCAN) ? 1 : 0,
- (lv->status & LV_TEMPORARY) ? 1 : 0, lv_committed(lv)))
- return 0;
- break;
- case LCK_PREAD:
- log_very_verbose("Locking LV %s (PR) - ignored", resource);
- break;
- case LCK_WRITE:
- log_very_verbose("Locking LV %s (W)%s", resource, origin_only ? " without snapshots" : "");
- if (!lv_suspend_if_active(cmd, resource, origin_only, 0, lv_committed(lv), lv))
- return 0;
- break;
- case LCK_EXCL:
- log_very_verbose("Locking LV %s (EX)", resource);
- if (!lv_activate_with_filter(cmd, resource, 1, (lv->status & LV_NOSCAN) ? 1 : 0,
- (lv->status & LV_TEMPORARY) ? 1 : 0, lv_committed(lv)))
- return 0;
- break;
- default:
- break;
- }
- break;
default:
log_error("Unrecognised lock scope: %d",
flags & LCK_SCOPE_MASK);
diff --git a/lib/locking/locking.c b/lib/locking/locking.c
index 5e28452..4b7d7eb 100644
--- a/lib/locking/locking.c
+++ b/lib/locking/locking.c
@@ -35,30 +35,6 @@ static int _vg_lock_count = 0; /* Number of locks held */
static int _vg_write_lock_held = 0; /* VG write lock held? */
static int _blocking_supported = 0;
-typedef enum {
- LV_NOOP,
- LV_SUSPEND,
- LV_RESUME
-} lv_operation_t;
-
-static void _lock_memory(struct cmd_context *cmd, lv_operation_t lv_op)
-{
- if (!(_locking.flags & LCK_PRE_MEMLOCK))
- return;
-
- if (lv_op == LV_SUSPEND)
- critical_section_inc(cmd, "locking for suspend");
-}
-
-static void _unlock_memory(struct cmd_context *cmd, lv_operation_t lv_op)
-{
- if (!(_locking.flags & LCK_PRE_MEMLOCK))
- return;
-
- if (lv_op == LV_RESUME)
- critical_section_dec(cmd, "unlocking on resume");
-}
-
static void _unblock_signals(void)
{
/* Don't unblock signals while any locks are held */
@@ -139,16 +115,13 @@ void fin_locking(void)
* VG locking is by VG name.
* FIXME This should become VG uuid.
*/
-static int _lock_vol(struct cmd_context *cmd, const char *resource,
- uint32_t flags, lv_operation_t lv_op, const struct logical_volume *lv)
+static int _lock_vol(struct cmd_context *cmd, const char *resource, uint32_t flags)
{
uint32_t lck_type = flags & LCK_TYPE_MASK;
uint32_t lck_scope = flags & LCK_SCOPE_MASK;
int ret = 0;
- const struct logical_volume *active_lv;
block_signals(flags);
- _lock_memory(cmd, lv_op);
assert(resource);
@@ -162,23 +135,13 @@ static int _lock_vol(struct cmd_context *cmd, const char *resource,
goto out;
}
- /* When trying activating component LV, make sure none of
- * sub component LV or LVs that are using it are active */
- if (lv && ((lck_type == LCK_READ) || (lck_type == LCK_EXCL)) &&
- ((!lv_is_visible(lv) && (active_lv = lv_holder_is_active(lv))) ||
- (active_lv = lv_component_is_active(lv)))) {
- log_error("Activation of logical volume %s is prohibited while logical volume %s is active.",
- display_lvname(lv), display_lvname(active_lv));
- goto out;
- }
-
if (cmd->metadata_read_only && lck_type == LCK_WRITE &&
strcmp(resource, VG_GLOBAL)) {
log_error("Operation prohibited while global/metadata_read_only is set.");
goto out;
}
- if ((ret = _locking.lock_resource(cmd, resource, flags, lv))) {
+ if ((ret = _locking.lock_resource(cmd, resource, flags, NULL))) {
if (lck_scope == LCK_VG && !(flags & LCK_CACHE)) {
if (lck_type != LCK_UNLOCK)
lvmcache_lock_vgname(resource, lck_type == LCK_READ);
@@ -196,7 +159,6 @@ static int _lock_vol(struct cmd_context *cmd, const char *resource,
_update_vg_lock_count(resource, flags);
}
out:
- _unlock_memory(cmd, lv_op);
_unblock_signals();
return ret;
@@ -205,28 +167,14 @@ out:
int lock_vol(struct cmd_context *cmd, const char *vol, uint32_t flags, const struct logical_volume *lv)
{
char resource[258] __attribute__((aligned(8)));
- lv_operation_t lv_op;
int lck_type = flags & LCK_TYPE_MASK;
- switch (flags & (LCK_SCOPE_MASK | LCK_TYPE_MASK)) {
- case LCK_LV_SUSPEND:
- lv_op = LV_SUSPEND;
- break;
- case LCK_LV_RESUME:
- lv_op = LV_RESUME;
- break;
- default: lv_op = LV_NOOP;
- }
-
-
if (flags == LCK_NONE) {
log_debug_locking(INTERNAL_ERROR "%s: LCK_NONE lock requested", vol);
return 1;
}
switch (flags & LCK_SCOPE_MASK) {
- case LCK_ACTIVATION:
- break;
case LCK_VG:
if (!_blocking_supported)
flags |= LCK_NONBLOCK;
@@ -235,10 +183,6 @@ int lock_vol(struct cmd_context *cmd, const char *vol, uint32_t flags, const str
if (is_orphan_vg(vol))
vol = VG_ORPHANS;
break;
- case LCK_LV:
- /* All LV locks are non-blocking. */
- flags |= LCK_NONBLOCK;
- break;
default:
log_error("Unrecognised lock scope: %d",
flags & LCK_SCOPE_MASK);
@@ -250,7 +194,7 @@ int lock_vol(struct cmd_context *cmd, const char *vol, uint32_t flags, const str
return 0;
}
- if (!_lock_vol(cmd, resource, flags, lv_op, lv))
+ if (!_lock_vol(cmd, resource, flags))
return_0;
/*
@@ -261,7 +205,7 @@ int lock_vol(struct cmd_context *cmd, const char *vol, uint32_t flags, const str
(flags & (LCK_CACHE | LCK_HOLD)))
return 1;
- if (!_lock_vol(cmd, resource, (flags & ~LCK_TYPE_MASK) | LCK_UNLOCK, lv_op, lv))
+ if (!_lock_vol(cmd, resource, (flags & ~LCK_TYPE_MASK) | LCK_UNLOCK))
return_0;
return 1;
@@ -312,3 +256,4 @@ int sync_dev_names(struct cmd_context* cmd)
return lock_vol(cmd, VG_SYNC_NAMES, LCK_VG_SYNC, NULL);
}
+
diff --git a/lib/locking/locking.h b/lib/locking/locking.h
index f3956c2..6d7d8e8 100644
--- a/lib/locking/locking.h
+++ b/lib/locking/locking.h
@@ -94,8 +94,6 @@ int check_lvm1_vg_inactive(struct cmd_context *cmd, const char *vgname);
*/
#define LCK_SCOPE_MASK 0x00001008U
#define LCK_VG 0x00000000U /* Volume Group */
-#define LCK_LV 0x00000008U /* Logical Volume */
-#define LCK_ACTIVATION 0x00001000U /* Activation */
/*
* Lock bits.
@@ -138,9 +136,6 @@ int check_lvm1_vg_inactive(struct cmd_context *cmd, const char *vgname);
*/
#define LCK_NONE (LCK_VG | LCK_NULL)
-#define LCK_ACTIVATE_LOCK (LCK_ACTIVATION | LCK_WRITE | LCK_HOLD)
-#define LCK_ACTIVATE_UNLOCK (LCK_ACTIVATION | LCK_UNLOCK)
-
#define LCK_VG_READ (LCK_VG | LCK_READ | LCK_HOLD)
#define LCK_VG_WRITE (LCK_VG | LCK_WRITE | LCK_HOLD)
#define LCK_VG_UNLOCK (LCK_VG | LCK_UNLOCK)
@@ -155,51 +150,8 @@ int check_lvm1_vg_inactive(struct cmd_context *cmd, const char *vgname);
#define LCK_VG_SYNC (LCK_NONE | LCK_CACHE)
#define LCK_VG_SYNC_LOCAL (LCK_NONE | LCK_CACHE | LCK_LOCAL)
-#define LCK_LV_EXCLUSIVE (LCK_LV | LCK_EXCL)
-#define LCK_LV_SUSPEND (LCK_LV | LCK_WRITE)
-#define LCK_LV_RESUME (LCK_LV | LCK_UNLOCK)
-#define LCK_LV_ACTIVATE (LCK_LV | LCK_READ)
-#define LCK_LV_DEACTIVATE (LCK_LV | LCK_NULL)
-
#define LCK_MASK (LCK_TYPE_MASK | LCK_SCOPE_MASK)
-#define lock_lv_vol(cmd, lv, flags) lock_vol(cmd, (lv)->lvid.s, flags, lv)
-
-/*
- * Activation locks are wrapped around activation commands that have to
- * be processed atomically one-at-a-time.
- * If a VG WRITE lock is held or clustered activation activates simple LV
- * an activation lock is redundant.
- *
- * Some LV types do require taking a lock common for whole group of LVs.
- * TODO: For simplicity reasons ATM take a VG activation global lock and
- * later more fine-grained component detection algorithm can be added
- */
-
-#define lv_type_requires_activation_lock(lv) ((lv_is_thin_type(lv) || lv_is_cache_type(lv) || lv_is_mirror_type(lv) || lv_is_raid_type(lv) || lv_is_origin(lv) || lv_is_snapshot(lv)) ? 1 : 0)
-
-#define lv_activation_lock_name(lv) (lv_type_requires_activation_lock(lv) ? (lv)->vg->name : (lv)->lvid.s)
-
-#define lv_requires_activation_lock_now(lv) ((!vg_write_lock_held() && (!vg_is_clustered((lv)->vg) || !lv_type_requires_activation_lock(lv))) ? 1 : 0)
-
-#define lock_activation(cmd, lv) (lv_requires_activation_lock_now(lv) ? lock_vol(cmd, lv_activation_lock_name(lv), LCK_ACTIVATE_LOCK, lv) : 1)
-#define unlock_activation(cmd, lv) (lv_requires_activation_lock_now(lv) ? lock_vol(cmd, lv_activation_lock_name(lv), LCK_ACTIVATE_UNLOCK, lv) : 1)
-
-/*
- * Place temporary exclusive 'activation' lock around an LV locking operation
- * to serialise it.
- */
-#define lock_lv_vol_serially(cmd, lv, flags) \
-({ \
- int rr = 0; \
-\
- if (lock_activation((cmd), (lv))) { \
- rr = lock_lv_vol((cmd), (lv), (flags)); \
- unlock_activation((cmd), (lv)); \
- } \
- rr; \
-})
-
#define unlock_vg(cmd, vg, vol) \
do { \
if (vg && !lvmetad_vg_update_finish(vg)) \
@@ -215,34 +167,6 @@ int check_lvm1_vg_inactive(struct cmd_context *cmd, const char *vgname);
release_vg(vg); \
} while (0)
-#define resume_lv(cmd, lv) \
-({ \
- int rr = lock_lv_vol((cmd), (lv), LCK_LV_RESUME); \
- unlock_activation((cmd), (lv)); \
- rr; \
-})
-#define resume_lv_origin(cmd, lv) lock_lv_vol(cmd, lv, LCK_LV_RESUME | LCK_ORIGIN_ONLY)
-#define revert_lv(cmd, lv) \
-({ \
- int rr = lock_lv_vol((cmd), (lv), LCK_LV_RESUME | LCK_REVERT); \
-\
- unlock_activation((cmd), (lv)); \
- rr; \
-})
-#define suspend_lv(cmd, lv) \
- (lock_activation((cmd), (lv)) ? lock_lv_vol((cmd), (lv), LCK_LV_SUSPEND | LCK_HOLD) : 0)
-
-#define suspend_lv_origin(cmd, lv) lock_lv_vol(cmd, lv, LCK_LV_SUSPEND | LCK_HOLD | LCK_ORIGIN_ONLY)
-
-#define deactivate_lv(cmd, lv) lock_lv_vol_serially(cmd, lv, LCK_LV_DEACTIVATE)
-
-#define activate_lv(cmd, lv) lock_lv_vol_serially(cmd, lv, LCK_LV_ACTIVATE | LCK_HOLD)
-
-struct logical_volume;
-
-#define deactivate_lv_local(cmd, lv) \
- lock_lv_vol_serially(cmd, lv, LCK_LV_DEACTIVATE | LCK_LOCAL)
-
#define drop_cached_metadata(vg) \
lock_vol((vg)->cmd, (vg)->name, LCK_VG_DROP_CACHE, NULL)
5 years, 10 months
master - use exclusive file lock on VG for activation
by Joe Thornber
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=616eeba6f2b33640534...
Commit: 616eeba6f2b33640534e26dea43661724edf3a14
Parent: e7aa51c70f17af10df906a7e123a497c1cf3c1ba
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Wed Jun 6 11:14:39 2018 -0500
Committer: Joe Thornber <ejt(a)redhat.com>
CommitterDate: Thu Jun 7 16:17:04 2018 +0100
use exclusive file lock on VG for activation
Make activation commands:
vgchange -ay, lvchange -ay, pvscan -aay
take an exclusive file lock on the VG to serialize
multiple concurrent activation commands which could
otherwise interfere with each other.
---
tools/lvchange.c | 2 +-
tools/pvscan.c | 2 +-
tools/vgchange.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/tools/lvchange.c b/tools/lvchange.c
index a90174e..3ed6b06 100644
--- a/tools/lvchange.c
+++ b/tools/lvchange.c
@@ -1386,7 +1386,7 @@ int lvchange_activate_cmd(struct cmd_context *cmd, int argc, char **argv)
} else /* Component LVs might be active, support easy deactivation */
cmd->process_component_lvs = 1;
- ret = process_each_lv(cmd, argc, argv, NULL, NULL, 0,
+ ret = process_each_lv(cmd, argc, argv, NULL, NULL, READ_FOR_UPDATE,
NULL, &_lvchange_activate_check, &_lvchange_activate_single);
if (ret != ECMD_PROCESSED)
diff --git a/tools/pvscan.c b/tools/pvscan.c
index 7cba0f4..61626e6 100644
--- a/tools/pvscan.c
+++ b/tools/pvscan.c
@@ -288,7 +288,7 @@ static int _pvscan_autoactivate(struct cmd_context *cmd, struct pvscan_aa_params
pp->refresh_all = 1;
}
- ret = process_each_vg(cmd, 0, NULL, NULL, vgnames, 0, 0, handle, _pvscan_autoactivate_single);
+ ret = process_each_vg(cmd, 0, NULL, NULL, vgnames, READ_FOR_UPDATE, 0, handle, _pvscan_autoactivate_single);
destroy_processing_handle(cmd, handle);
diff --git a/tools/vgchange.c b/tools/vgchange.c
index a67c3be..b07057f 100644
--- a/tools/vgchange.c
+++ b/tools/vgchange.c
@@ -791,7 +791,7 @@ int vgchange(struct cmd_context *cmd, int argc, char **argv)
cmd->lockd_vg_enforce_sh = 1;
}
- if (update)
+ if (update || arg_is_set(cmd, activate_ARG))
flags |= READ_FOR_UPDATE;
if (!(handle = init_processing_handle(cmd, NULL))) {
5 years, 10 months
master - Remove VG lock ordering check
by Joe Thornber
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=e7aa51c70f17af10df9...
Commit: e7aa51c70f17af10df906a7e123a497c1cf3c1ba
Parent: 18259d5559307f2708e12b9923988319e46572df
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Tue Jun 5 15:16:58 2018 -0500
Committer: Joe Thornber <ejt(a)redhat.com>
CommitterDate: Thu Jun 7 16:17:04 2018 +0100
Remove VG lock ordering check
Four commands lock two VGs at a time:
- vgsplit and vgmerge already have their own logic to
acquire the locks in the correct order.
- vgimportclone and vgrename disable this ordering check.
---
lib/cache/lvmcache.c | 66 -------------------------------------------------
lib/cache/lvmcache.h | 1 -
lib/locking/locking.c | 6 ----
tools/toollib.c | 8 ------
tools/vgimportclone.c | 4 ---
tools/vgrename.c | 5 ---
6 files changed, 0 insertions(+), 90 deletions(-)
diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c
index b9aa8a0..774d687 100644
--- a/lib/cache/lvmcache.c
+++ b/lib/cache/lvmcache.c
@@ -77,7 +77,6 @@ static int _has_scanned = 0;
static int _vgs_locked = 0;
static int _vg_global_lock_held = 0; /* Global lock held when cache wiped? */
static int _found_duplicate_pvs = 0; /* If we never see a duplicate PV we can skip checking for them later. */
-static int _suppress_lock_ordering = 0;
int lvmcache_init(struct cmd_context *cmd)
{
@@ -158,71 +157,6 @@ static void _update_cache_lock_state(const char *vgname, int locked)
_update_cache_vginfo_lock_state(vginfo, locked);
}
-/*
- * Ensure vgname2 comes after vgname1 alphabetically.
- * Orphan locks come last.
- * VG_GLOBAL comes first.
- */
-static int _vgname_order_correct(const char *vgname1, const char *vgname2)
-{
- if (is_global_vg(vgname1))
- return 1;
-
- if (is_global_vg(vgname2))
- return 0;
-
- if (is_orphan_vg(vgname1))
- return 0;
-
- if (is_orphan_vg(vgname2))
- return 1;
-
- if (strcmp(vgname1, vgname2) < 0)
- return 1;
-
- return 0;
-}
-
-void lvmcache_lock_ordering(int enable)
-{
- _suppress_lock_ordering = !enable;
-}
-
-/*
- * Ensure VG locks are acquired in alphabetical order.
- */
-int lvmcache_verify_lock_order(const char *vgname)
-{
- struct dm_hash_node *n;
- const char *vgname2;
-
- if (_suppress_lock_ordering)
- return 1;
-
- if (!_lock_hash)
- return 1;
-
- dm_hash_iterate(n, _lock_hash) {
- if (!dm_hash_get_data(_lock_hash, n))
- return_0;
-
- if (!(vgname2 = dm_hash_get_key(_lock_hash, n))) {
- log_error(INTERNAL_ERROR "VG lock %s hits NULL.",
- vgname);
- return 0;
- }
-
- if (!_vgname_order_correct(vgname2, vgname)) {
- log_errno(EDEADLK, INTERNAL_ERROR "VG lock %s must "
- "be requested before %s, not after.",
- vgname, vgname2);
- return 0;
- }
- }
-
- return 1;
-}
-
void lvmcache_lock_vgname(const char *vgname, int read_only __attribute__((unused)))
{
if (dm_hash_lookup(_lock_hash, vgname))
diff --git a/lib/cache/lvmcache.h b/lib/cache/lvmcache.h
index 5891757..4808a0d 100644
--- a/lib/cache/lvmcache.h
+++ b/lib/cache/lvmcache.h
@@ -87,7 +87,6 @@ int lvmcache_update_vg(struct volume_group *vg, unsigned precommitted);
void lvmcache_lock_vgname(const char *vgname, int read_only);
void lvmcache_unlock_vgname(const char *vgname);
-int lvmcache_verify_lock_order(const char *vgname);
/* Queries */
const struct format_type *lvmcache_fmt_from_vgname(struct cmd_context *cmd, const char *vgname, const char *vgid, unsigned revalidate_labels);
diff --git a/lib/locking/locking.c b/lib/locking/locking.c
index a4fcaf7..5e28452 100644
--- a/lib/locking/locking.c
+++ b/lib/locking/locking.c
@@ -234,12 +234,6 @@ int lock_vol(struct cmd_context *cmd, const char *vol, uint32_t flags, const str
/* Global VG_ORPHANS lock covers all orphan formats. */
if (is_orphan_vg(vol))
vol = VG_ORPHANS;
- /* VG locks alphabetical, ORPHAN lock last */
- if ((lck_type != LCK_UNLOCK) &&
- !(flags & LCK_CACHE) &&
- !lvmcache_verify_lock_order(vol))
- return_0;
-
break;
case LCK_LV:
/* All LV locks are non-blocking. */
diff --git a/tools/toollib.c b/tools/toollib.c
index 236e2b1..a4dddd3 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -5414,14 +5414,6 @@ int pvcreate_each_device(struct cmd_context *cmd,
}
/*
- * This function holds the orphans lock while reading VGs to look for
- * devices. This means the orphans lock is held while VG locks are
- * acquired, which is against lvmcache lock ordering rules, so disable
- * the lvmcache lock ordering checks.
- */
- lvmcache_lock_ordering(0);
-
- /*
* Clear the cache before acquiring the orphan lock. (Clearing the
* cache with locks held is an error.) We want the orphan lock
* acquired before process_each_pv. If the orphan lock is not held
diff --git a/tools/vgimportclone.c b/tools/vgimportclone.c
index 7421912..e37b897 100644
--- a/tools/vgimportclone.c
+++ b/tools/vgimportclone.c
@@ -342,9 +342,6 @@ retry_name:
log_debug("Changing VG %s to %s.", vp.old_vgname, vp.new_vgname);
- /* We don't care if the new name comes before the old in lock order. */
- lvmcache_lock_ordering(0);
-
if (!lock_vol(cmd, vp.new_vgname, LCK_VG_WRITE, NULL)) {
log_error("Can't get lock for new VG name %s", vp.new_vgname);
goto out;
@@ -363,7 +360,6 @@ out:
unlock_vg(cmd, NULL, VG_GLOBAL);
internal_filter_clear();
init_internal_filtering(0);
- lvmcache_lock_ordering(1);
destroy_processing_handle(cmd, handle);
/* Enable lvmetad again if no duplicates are left. */
diff --git a/tools/vgrename.c b/tools/vgrename.c
index 4f2a08b..bbc3087 100644
--- a/tools/vgrename.c
+++ b/tools/vgrename.c
@@ -99,13 +99,8 @@ static int _vgrename_single(struct cmd_context *cmd, const char *vg_name,
* this uuid-for-name case.
*/
if (vp->lock_vg_old_first || vp->old_name_is_uuid) {
- if (vp->old_name_is_uuid)
- lvmcache_lock_ordering(0);
-
if (!_lock_new_vg_for_rename(cmd, vp->vg_name_new))
return ECMD_FAILED;
-
- lvmcache_lock_ordering(1);
}
dev_dir = cmd->dev_dir;
5 years, 10 months
master - Remove unused clvm variations for active LVs
by Joe Thornber
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=18259d5559307f2708e...
Commit: 18259d5559307f2708e12b9923988319e46572df
Parent: e4d9099e19591a7f3ad546c180b59a601e0d03da
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Tue Jun 5 13:21:28 2018 -0500
Committer: Joe Thornber <ejt(a)redhat.com>
CommitterDate: Thu Jun 7 16:17:04 2018 +0100
Remove unused clvm variations for active LVs
Different flavors of activate_lv() and lv_is_active()
which are meaningful in a clustered VG can be eliminated
and replaced with whatever that flavor already falls back
to in a local VG.
e.g. lv_is_active_exclusive_locally() is distinct from
lv_is_active() in a clustered VG, but in a local VG they
are equivalent. So, all instances of the variant are
replaced with the basic local equivalent.
For local VGs, the same behavior remains as before.
For shared VGs, lvmlockd was written with the explicit
requirement of local behavior from these functions
(lvmlockd requires locking_type 1), so the behavior
in shared VGs also remains the same.
---
lib/activate/activate.c | 131 ++--------------------------------------
lib/activate/activate.h | 6 --
lib/locking/locking.c | 18 +-----
lib/locking/locking.h | 10 +---
lib/metadata/cache_manip.c | 6 +-
lib/metadata/lv.c | 64 ++------------------
lib/metadata/lv.h | 2 +-
lib/metadata/lv_manip.c | 36 +++++-------
lib/metadata/mirror.c | 65 ++------------------
lib/metadata/pool_manip.c | 2 +-
lib/metadata/raid_manip.c | 46 ++++----------
lib/metadata/snapshot_manip.c | 6 --
lib/metadata/thin_manip.c | 4 +-
lib/report/report.c | 40 +------------
tools/lvchange.c | 11 +--
tools/lvconvert.c | 27 ++++-----
tools/lvcreate.c | 4 +-
tools/polldaemon.c | 4 +-
tools/pvmove.c | 8 +--
tools/toollib.c | 4 +-
tools/vgchange.c | 16 +-----
21 files changed, 88 insertions(+), 422 deletions(-)
diff --git a/lib/activate/activate.c b/lib/activate/activate.c
index 4c70443..c9ead42 100644
--- a/lib/activate/activate.c
+++ b/lib/activate/activate.c
@@ -374,31 +374,6 @@ int lv_is_active(const struct logical_volume *lv)
{
return 0;
}
-int lv_is_active_locally(const struct logical_volume *lv)
-{
- return 0;
-}
-int lv_is_active_remotely(const struct logical_volume *lv)
-{
- return 0;
-}
-int lv_is_active_but_not_locally(const struct logical_volume *lv)
-{
- return 0;
-}
-int lv_is_active_exclusive(const struct logical_volume *lv)
-{
- return 0;
-}
-int lv_is_active_exclusive_locally(const struct logical_volume *lv)
-{
- return 0;
-}
-int lv_is_active_exclusive_remotely(const struct logical_volume *lv)
-{
- return 0;
-}
-
int lv_check_transient(struct logical_volume *lv)
{
return 1;
@@ -1471,61 +1446,6 @@ int lvs_in_vg_opened(const struct volume_group *vg)
}
/*
- * _lv_is_active
- * @lv: logical volume being queried
- * @locally: set if active locally (when provided)
- * @remotely: set if active remotely (when provided)
- * @exclusive: set if active exclusively (when provided)
- *
- * Determine whether an LV is active locally or in a cluster.
- * In addition to the return code which indicates whether or
- * not the LV is active somewhere, two other values are set
- * to yield more information about the status of the activation:
- *
- * return locally exclusively status
- * ====== ======= =========== ======
- * 0 0 0 not active
- * 1 0 0 active remotely
- * 1 0 1 exclusive remotely
- * 1 1 0 active locally and possibly remotely
- * 1 1 1 exclusive locally (or local && !cluster)
- * The VG lock must be held to call this function.
- *
- * Returns: 0 or 1
- */
-static int _lv_is_active(const struct logical_volume *lv,
- int *locally, int *remotely, int *exclusive)
-{
- int r, l, e; /* remote, local, and exclusive */
- int skip_cluster_query = 0;
-
- r = l = e = 0;
-
- if (_lv_active(lv->vg->cmd, lv))
- l = 1;
-
- if (l)
- e = 1; /* exclusive by definition */
-
- if (locally)
- *locally = l;
- if (exclusive)
- *exclusive = e;
- if (remotely)
- *remotely = r;
-
- log_very_verbose("%s is %sactive%s%s%s%s",
- display_lvname(lv),
- (r || l) ? "" : "not ",
- (exclusive && e) ? " exclusive" : "",
- l ? " locally" : "",
- (!skip_cluster_query && l && r) ? " and" : "",
- (!skip_cluster_query && r) ? " remotely" : "");
-
- return r || l;
-}
-
-/*
* Check if "raid4" @segtype is supported by kernel.
*
* if segment type is not raid4, return 1.
@@ -1545,51 +1465,14 @@ int raid4_is_supported(struct cmd_context *cmd, const struct segment_type *segty
return 1;
}
+/*
+ * The VG lock must be held to call this function.
+ *
+ * Returns: 0 or 1
+ */
int lv_is_active(const struct logical_volume *lv)
{
- return _lv_is_active(lv, NULL, NULL, NULL);
-}
-
-int lv_is_active_locally(const struct logical_volume *lv)
-{
- int l;
-
- return _lv_is_active(lv, &l, NULL, NULL) && l;
-}
-
-int lv_is_active_remotely(const struct logical_volume *lv)
-{
- int r;
-
- return _lv_is_active(lv, NULL, &r, NULL) && r;
-}
-
-int lv_is_active_but_not_locally(const struct logical_volume *lv)
-{
- int l;
-
- return _lv_is_active(lv, &l, NULL, NULL) && !l;
-}
-
-int lv_is_active_exclusive(const struct logical_volume *lv)
-{
- int e;
-
- return _lv_is_active(lv, NULL, NULL, &e) && e;
-}
-
-int lv_is_active_exclusive_locally(const struct logical_volume *lv)
-{
- int l, e;
-
- return _lv_is_active(lv, &l, NULL, &e) && l && e;
-}
-
-int lv_is_active_exclusive_remotely(const struct logical_volume *lv)
-{
- int l, e;
-
- return _lv_is_active(lv, &l, NULL, &e) && !l && e;
+ return _lv_active(lv->vg->cmd, lv);
}
#ifdef DMEVENTD
@@ -1991,7 +1874,7 @@ int monitor_dev_for_events(struct cmd_context *cmd, const struct logical_volume
continue;
if (!vg_write_lock_held() && lv_is_mirror(lv)) {
- mirr_laopts.exclusive = lv_is_active_exclusive_locally(lv) ? 1 : 0;
+ mirr_laopts.exclusive = lv_is_active(lv) ? 1 : 0;
/*
* Commands vgchange and lvchange do use read-only lock when changing
* monitoring (--monitor y|n). All other use cases hold 'write-lock'
diff --git a/lib/activate/activate.h b/lib/activate/activate.h
index 8175f68..8b6c4ad 100644
--- a/lib/activate/activate.h
+++ b/lib/activate/activate.h
@@ -191,12 +191,6 @@ int lvs_in_vg_activated(const struct volume_group *vg);
int lvs_in_vg_opened(const struct volume_group *vg);
int lv_is_active(const struct logical_volume *lv);
-int lv_is_active_locally(const struct logical_volume *lv);
-int lv_is_active_remotely(const struct logical_volume *lv);
-int lv_is_active_but_not_locally(const struct logical_volume *lv);
-int lv_is_active_exclusive(const struct logical_volume *lv);
-int lv_is_active_exclusive_locally(const struct logical_volume *lv);
-int lv_is_active_exclusive_remotely(const struct logical_volume *lv);
/* Check is any component LV is active */
const struct logical_volume *lv_component_is_active(const struct logical_volume *lv);
diff --git a/lib/locking/locking.c b/lib/locking/locking.c
index 0e5658f..a4fcaf7 100644
--- a/lib/locking/locking.c
+++ b/lib/locking/locking.c
@@ -273,16 +273,6 @@ int lock_vol(struct cmd_context *cmd, const char *vol, uint32_t flags, const str
return 1;
}
-/*
- * First try to activate exclusively locally.
- * Then if the VG is clustered and the LV is not yet active (e.g. due to
- * an activation filter) try activating on remote nodes.
- */
-int activate_lv_excl(struct cmd_context *cmd, const struct logical_volume *lv)
-{
- return activate_lv_excl_local(cmd, lv);
-}
-
/* Lock a list of LVs */
int activate_lvs(struct cmd_context *cmd, struct dm_list *lvs, unsigned exclusive)
{
@@ -290,13 +280,9 @@ int activate_lvs(struct cmd_context *cmd, struct dm_list *lvs, unsigned exclusiv
struct lv_list *lvl;
dm_list_iterate_items(lvl, lvs) {
- if (!exclusive && !lv_is_active_exclusive(lvl->lv)) {
- if (!activate_lv(cmd, lvl->lv)) {
- log_error("Failed to activate %s", display_lvname(lvl->lv));
- return 0;
- }
- } else if (!activate_lv_excl(cmd, lvl->lv)) {
+ if (!activate_lv(cmd, lvl->lv)) {
log_error("Failed to activate %s", display_lvname(lvl->lv));
+
dm_list_uniterate(lvh, lvs, &lvl->list) {
lvl = dm_list_item(lvh, struct lv_list);
if (!deactivate_lv(cmd, lvl->lv))
diff --git a/lib/locking/locking.h b/lib/locking/locking.h
index 8b2bced..f3956c2 100644
--- a/lib/locking/locking.h
+++ b/lib/locking/locking.h
@@ -231,20 +231,14 @@ int check_lvm1_vg_inactive(struct cmd_context *cmd, const char *vgname);
})
#define suspend_lv(cmd, lv) \
(lock_activation((cmd), (lv)) ? lock_lv_vol((cmd), (lv), LCK_LV_SUSPEND | LCK_HOLD) : 0)
+
#define suspend_lv_origin(cmd, lv) lock_lv_vol(cmd, lv, LCK_LV_SUSPEND | LCK_HOLD | LCK_ORIGIN_ONLY)
+
#define deactivate_lv(cmd, lv) lock_lv_vol_serially(cmd, lv, LCK_LV_DEACTIVATE)
#define activate_lv(cmd, lv) lock_lv_vol_serially(cmd, lv, LCK_LV_ACTIVATE | LCK_HOLD)
-#define activate_lv_excl_local(cmd, lv) \
- lock_lv_vol_serially(cmd, lv, LCK_LV_EXCLUSIVE | LCK_HOLD | LCK_LOCAL)
-#define activate_lv_excl_remote(cmd, lv) \
- lock_lv_vol(cmd, lv, LCK_LV_EXCLUSIVE | LCK_HOLD | LCK_REMOTE)
struct logical_volume;
-int activate_lv_excl(struct cmd_context *cmd, const struct logical_volume *lv);
-
-#define activate_lv_local(cmd, lv) \
- lock_lv_vol_serially(cmd, lv, LCK_LV_ACTIVATE | LCK_HOLD | LCK_LOCAL)
#define deactivate_lv_local(cmd, lv) \
lock_lv_vol_serially(cmd, lv, LCK_LV_DEACTIVATE | LCK_LOCAL)
diff --git a/lib/metadata/cache_manip.c b/lib/metadata/cache_manip.c
index 0768e6f..fe91fee 100644
--- a/lib/metadata/cache_manip.c
+++ b/lib/metadata/cache_manip.c
@@ -566,8 +566,8 @@ int lv_cache_remove(struct logical_volume *cache_lv)
default:
/* Otherwise localy activate volume to sync dirty blocks */
cache_lv->status |= LV_TEMPORARY;
- if (!activate_lv_excl_local(cache_lv->vg->cmd, cache_lv) ||
- !lv_is_active_locally(cache_lv)) {
+ if (!activate_lv(cache_lv->vg->cmd, cache_lv) ||
+ !lv_is_active(cache_lv)) {
log_error("Failed to active cache locally %s.",
display_lvname(cache_lv));
return 0;
@@ -969,7 +969,7 @@ int wipe_cache_pool(struct logical_volume *cache_pool_lv)
}
cache_pool_lv->status |= LV_TEMPORARY;
- if (!activate_lv_excl_local(cache_pool_lv->vg->cmd, cache_pool_lv)) {
+ if (!activate_lv(cache_pool_lv->vg->cmd, cache_pool_lv)) {
log_error("Aborting. Failed to activate cache pool %s.",
display_lvname(cache_pool_lv));
return 0;
diff --git a/lib/metadata/lv.c b/lib/metadata/lv.c
index f930633..14d7312 100644
--- a/lib/metadata/lv.c
+++ b/lib/metadata/lv.c
@@ -1023,7 +1023,7 @@ int lv_raid_image_in_sync(const struct logical_volume *lv)
* If the LV is not active locally,
* it doesn't make sense to check status
*/
- if (!lv_is_active_locally(lv))
+ if (!lv_is_active(lv))
return 0; /* Assume not in-sync */
if (!lv_is_raid_image(lv)) {
@@ -1081,7 +1081,7 @@ int lv_raid_healthy(const struct logical_volume *lv)
* If the LV is not active locally,
* it doesn't make sense to check status
*/
- if (!lv_is_active_locally(lv))
+ if (!lv_is_active(lv))
return 1; /* assume healthy */
if (!lv_is_raid_type(lv)) {
@@ -1446,22 +1446,8 @@ char *lv_host_dup(struct dm_pool *mem, const struct logical_volume *lv)
return dm_pool_strdup(mem, lv->hostname ? : "");
}
-static int _lv_is_exclusive(struct logical_volume *lv)
-{
- struct lv_segment *seg;
-
- /* Some seg types require exclusive activation */
- /* FIXME Scan recursively */
- dm_list_iterate_items(seg, &lv->segments)
- if (seg_only_exclusive(seg))
- return 1;
-
- /* Origin has no seg type require exlusiveness */
- return lv_is_origin(lv);
-}
-
int lv_active_change(struct cmd_context *cmd, struct logical_volume *lv,
- enum activation_change activate, int needs_exclusive)
+ enum activation_change activate)
{
const char *ay_with_mode = NULL;
@@ -1478,45 +1464,22 @@ int lv_active_change(struct cmd_context *cmd, struct logical_volume *lv,
switch (activate) {
case CHANGE_AN:
+ case CHANGE_ALN:
log_verbose("Deactivating logical volume %s.", display_lvname(lv));
if (!deactivate_lv(cmd, lv))
return_0;
break;
- case CHANGE_ALN:
- log_verbose("Deactivating logical volume %s locally.",
- display_lvname(lv));
- if (!deactivate_lv_local(cmd, lv))
- return_0;
- break;
+
case CHANGE_ALY:
case CHANGE_AAY:
- if (needs_exclusive || _lv_is_exclusive(lv)) {
- log_verbose("Activating logical volume %s exclusively locally.",
- display_lvname(lv));
- if (!activate_lv_excl_local(cmd, lv))
- return_0;
- } else {
- log_verbose("Activating logical volume %s locally.",
- display_lvname(lv));
- if (!activate_lv_local(cmd, lv))
- return_0;
- }
- break;
case CHANGE_AEY:
-exclusive:
- log_verbose("Activating logical volume %s exclusively.",
- display_lvname(lv));
- if (!activate_lv_excl(cmd, lv))
- return_0;
- break;
case CHANGE_ASY:
case CHANGE_AY:
default:
- if (needs_exclusive || _lv_is_exclusive(lv))
- goto exclusive;
log_verbose("Activating logical volume %s.", display_lvname(lv));
if (!activate_lv(cmd, lv))
return_0;
+ break;
}
if (!is_change_activating(activate) &&
@@ -1535,23 +1498,10 @@ char *lv_active_dup(struct dm_pool *mem, const struct logical_volume *lv)
goto out;
}
- if (vg_is_clustered(lv->vg)) {
- //const struct logical_volume *lvo = lv;
- lv = lv_lock_holder(lv);
- //log_debug("Holder for %s => %s.", lvo->name, lv->name);
- }
-
if (!lv_is_active(lv))
s = ""; /* not active */
- else if (!vg_is_clustered(lv->vg))
+ else
s = "active";
- else if (lv_is_active_exclusive(lv))
- /* exclusive cluster activation */
- s = lv_is_active_exclusive_locally(lv) ?
- "local exclusive" : "remote exclusive";
- else /* locally active */
- s = lv_is_active_but_not_locally(lv) ?
- "remotely" : "locally";
out:
return dm_pool_strdup(mem, s);
}
diff --git a/lib/metadata/lv.h b/lib/metadata/lv.h
index 920bcb5..e2e640f 100644
--- a/lib/metadata/lv.h
+++ b/lib/metadata/lv.h
@@ -153,7 +153,7 @@ char *lvseg_kernel_discards_dup(struct dm_pool *mem, const struct lv_segment *se
int lv_set_creation(struct logical_volume *lv,
const char *hostname, uint64_t timestamp);
int lv_active_change(struct cmd_context *cmd, struct logical_volume *lv,
- enum activation_change activate, int needs_exclusive);
+ enum activation_change activate);
/* LV dup functions */
char *lv_attr_dup_with_info_and_seg_status(struct dm_pool *mem, const struct lv_with_info_and_seg_status *lvdm);
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index e023132..dad5953 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -4058,7 +4058,7 @@ static int _lv_extend_layered_lv(struct alloc_handle *ah,
for (s = 0; !fail && s < seg->area_count; s++) {
meta_lv = seg_metalv(seg, s);
- if (!activate_lv_local(meta_lv->vg->cmd, meta_lv)) {
+ if (!activate_lv(meta_lv->vg->cmd, meta_lv)) {
log_error("Failed to activate %s for clearing.",
display_lvname(meta_lv));
fail = 1;
@@ -4228,7 +4228,7 @@ int lv_extend(struct logical_volume *lv,
(lv_is_not_synced(lv))) {
dm_percent_t sync_percent = DM_PERCENT_INVALID;
- if (!lv_is_active_locally(lv)) {
+ if (!lv_is_active(lv)) {
log_error("Unable to read sync percent while LV %s "
"is not locally active.", display_lvname(lv));
/* FIXME Support --force */
@@ -4711,7 +4711,7 @@ static int _lvresize_adjust_policy(const struct logical_volume *lv,
return 0;
}
- if (!lv_is_active_locally(lv)) {
+ if (!lv_is_active(lv)) {
log_error("Can't read state of locally inactive LV %s.",
display_lvname(lv));
return 0;
@@ -5571,7 +5571,7 @@ int lv_resize(struct logical_volume *lv,
* then use suspend and resume and deactivate pool LV,
* instead of searching for an active thin volume.
*/
- if (!activate_lv_excl(cmd, lock_lv)) {
+ if (!activate_lv(cmd, lock_lv)) {
log_error("Failed to activate %s.", display_lvname(lock_lv));
return 0;
}
@@ -6788,7 +6788,7 @@ struct logical_volume *insert_layer_for_lv(struct cmd_context *cmd,
struct segment_type *segtype;
struct lv_segment *mapseg;
struct lv_names lv_names;
- unsigned exclusive = 0, i;
+ unsigned i;
/* create an empty layer LV */
if (dm_snprintf(name, sizeof(name), "%s%s", lv_where->name, layer_suffix) < 0) {
@@ -6804,9 +6804,6 @@ struct logical_volume *insert_layer_for_lv(struct cmd_context *cmd,
return NULL;
}
- if (lv_is_active_exclusive_locally(lv_where))
- exclusive = 1;
-
if (lv_is_active(lv_where) && strstr(name, MIRROR_SYNC_LAYER)) {
log_very_verbose("Creating transient LV %s for mirror conversion in VG %s.", name, lv_where->vg->name);
@@ -6835,10 +6832,7 @@ struct logical_volume *insert_layer_for_lv(struct cmd_context *cmd,
return NULL;
}
- if (exclusive)
- r = activate_lv_excl(cmd, layer_lv);
- else
- r = activate_lv(cmd, layer_lv);
+ r = activate_lv(cmd, layer_lv);
if (!r) {
log_error("Failed to resume transient LV"
@@ -7125,7 +7119,7 @@ int wipe_lv(struct logical_volume *lv, struct wipe_params wp)
/* nothing to do */
return 1;
- if (!lv_is_active_locally(lv)) {
+ if (!lv_is_active(lv)) {
log_error("Volume \"%s/%s\" is not active locally (volume_list activation filter?).",
lv->vg->name, lv->name);
return 0;
@@ -7491,7 +7485,7 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg,
return_NULL;
/* New pool is now inactive */
} else {
- if (!activate_lv_excl_local(cmd, pool_lv)) {
+ if (!activate_lv(cmd, pool_lv)) {
log_error("Aborting. Failed to locally activate thin pool %s.",
display_lvname(pool_lv));
return NULL;
@@ -7783,7 +7777,7 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg,
if (seg_is_cache(lp)) {
if (vg_is_shared(vg)) {
if (is_change_activating(lp->activate)) {
- if (!lv_active_change(cmd, lv, CHANGE_AEY, 0)) {
+ if (!lv_active_change(cmd, lv, CHANGE_AEY)) {
log_error("Aborting. Failed to activate LV %s.",
display_lvname(lv));
goto revert_new_lv;
@@ -7794,7 +7788,7 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg,
/* FIXME Support remote exclusive activation? */
/* Not yet 'cache' LV, it is stripe volume for wiping */
- else if (is_change_activating(lp->activate) && !activate_lv_excl_local(cmd, lv)) {
+ else if (is_change_activating(lp->activate) && !activate_lv(cmd, lv)) {
log_error("Aborting. Failed to activate LV %s locally exclusively.",
display_lvname(lv));
goto revert_new_lv;
@@ -7827,7 +7821,7 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg,
/* Avoid multiple thin-pool activations in this case */
if (thin_pool_was_active < 0)
thin_pool_was_active = 0;
- if (!activate_lv_excl(cmd, pool_lv)) {
+ if (!activate_lv(cmd, pool_lv)) {
log_error("Failed to activate thin pool %s.",
display_lvname(pool_lv));
goto revert_new_lv;
@@ -7846,7 +7840,7 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg,
}
backup(vg);
- if (!lv_active_change(cmd, lv, lp->activate, 0)) {
+ if (!lv_active_change(cmd, lv, lp->activate)) {
log_error("Failed to activate thin %s.", lv->name);
goto deactivate_and_revert_new_lv;
}
@@ -7860,13 +7854,13 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg,
}
} else if (lp->snapshot) {
lv->status |= LV_TEMPORARY;
- if (!activate_lv_local(cmd, lv)) {
+ if (!activate_lv(cmd, lv)) {
log_error("Aborting. Failed to activate snapshot "
"exception store.");
goto revert_new_lv;
}
lv->status &= ~LV_TEMPORARY;
- } else if (!lv_active_change(cmd, lv, lp->activate, 0)) {
+ } else if (!lv_active_change(cmd, lv, lp->activate)) {
log_error("Failed to activate new LV.");
goto deactivate_and_revert_new_lv;
}
@@ -7968,7 +7962,7 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg,
*/
/* Activate spare snapshot once it is a complete LV */
- if (!lv_active_change(cmd, origin_lv, lp->activate, 1)) {
+ if (!lv_active_change(cmd, origin_lv, lp->activate)) {
log_error("Failed to activate sparce volume %s.",
display_lvname(origin_lv));
return NULL;
diff --git a/lib/metadata/mirror.c b/lib/metadata/mirror.c
index 9c775c4..8de1440 100644
--- a/lib/metadata/mirror.c
+++ b/lib/metadata/mirror.c
@@ -354,7 +354,7 @@ static int _init_mirror_log(struct cmd_context *cmd,
} else if (!lv_update_and_reload((struct logical_volume*) lock_holder))
return_0;
- if (!activate_lv_excl_local(cmd, log_lv)) {
+ if (!activate_lv(cmd, log_lv)) {
log_error("Aborting. Failed to activate mirror log.");
goto revert_new_lv;
}
@@ -427,15 +427,10 @@ static int _activate_lv_like_model(struct logical_volume *model,
/* FIXME: run all cases through lv_active_change when clvm variants are gone. */
if (vg_is_shared(lv->vg))
- return lv_active_change(lv->vg->cmd, lv, CHANGE_AEY, 0);
+ return lv_active_change(lv->vg->cmd, lv, CHANGE_AEY);
- if (lv_is_active_exclusive(model)) {
- if (!activate_lv_excl(lv->vg->cmd, lv))
- return_0;
- } else {
- if (!activate_lv(lv->vg->cmd, lv))
- return_0;
- }
+ if (!activate_lv(lv->vg->cmd, lv))
+ return_0;
return 1;
}
@@ -610,14 +605,7 @@ static int _mirrored_lv_in_sync(struct logical_volume *lv)
if (!lv_mirror_percent(lv->vg->cmd, lv, 0, &sync_percent,
NULL)) {
- if (lv_is_active_but_not_locally(lv))
- log_error("Unable to determine mirror sync status of"
- " remotely active LV, %s",
- display_lvname(lv));
- else
- log_error("Unable to determine mirror "
- "sync status of %s.",
- display_lvname(lv));
+ log_error("Unable to determine mirror sync status of %s.", display_lvname(lv));
return 0;
}
@@ -1668,7 +1656,6 @@ int remove_mirror_log(struct cmd_context *cmd,
int force)
{
dm_percent_t sync_percent;
- struct volume_group *vg = lv->vg;
/* Unimplemented features */
if (dm_list_size(&lv->segments) != 1) {
@@ -1677,20 +1664,12 @@ int remove_mirror_log(struct cmd_context *cmd,
}
/* Had disk log, switch to core. */
- if (lv_is_active_locally(lv)) {
+ if (lv_is_active(lv)) {
if (!lv_mirror_percent(cmd, lv, 0, &sync_percent,
NULL)) {
log_error("Unable to determine mirror sync status.");
return 0;
}
- } else if (lv_is_active(lv)) {
- log_error("Unable to determine sync status of "
- "remotely active mirror volume %s.", display_lvname(lv));
- return 0;
- } else if (vg_is_clustered(vg)) {
- log_error("Unable to convert the log of an inactive "
- "cluster mirror volume %s.", display_lvname(lv));
- return 0;
} else if (force || yes_no_prompt("Full resync required to convert inactive "
"mirror volume %s to core log. "
"Proceed? [y/n]: ", display_lvname(lv)) == 'y')
@@ -1910,22 +1889,11 @@ int add_mirror_log(struct cmd_context *cmd, struct logical_volume *lv,
unsigned old_log_count;
int r = 0;
- if (vg_is_clustered(lv->vg) && (log_count > 1)) {
- log_error("Log type, \"mirrored\", is unavailable to cluster mirrors.");
- return 0;
- }
-
if (dm_list_size(&lv->segments) != 1) {
log_error("Multiple-segment mirror is not supported.");
return 0;
}
- if (lv_is_active_but_not_locally(lv)) {
- log_error("Unable to convert the log of a mirror, %s, that is "
- "active remotely but not locally.", display_lvname(lv));
- return 0;
- }
-
log_lv = first_seg(lv)->log_lv;
old_log_count = (log_lv) ? lv_mirror_count(log_lv) : 0;
if (old_log_count == log_count) {
@@ -2079,27 +2047,6 @@ int lv_add_mirrors(struct cmd_context *cmd, struct logical_volume *lv,
return 0;
}
- if (vg_is_clustered(lv->vg)) {
- /* FIXME: move this test out of this function */
- /* Skip test for pvmove mirrors, it can use local mirror */
- if (!lv_is_pvmove(lv) && !lv_is_locked(lv) &&
- lv_is_active(lv) &&
- !lv_is_active_exclusive_locally(lv) && /* lv_is_active_remotely */
- !cluster_mirror_is_available(lv->vg->cmd)) {
- log_error("Shared cluster mirrors are not available.");
- return 0;
- }
-
- /*
- * No mirrored logs for cluster mirrors until
- * log daemon is multi-threaded.
- */
- if (log_count > 1) {
- log_error("Log type, \"mirrored\", is unavailable to cluster mirrors.");
- return 0;
- }
- }
-
if (lv->vg->lock_type && !strcmp(lv->vg->lock_type, "dlm") && cmd->lockd_lv_sh) {
if (!cluster_mirror_is_available(cmd)) {
log_error("Shared cluster mirrors are not available.");
diff --git a/lib/metadata/pool_manip.c b/lib/metadata/pool_manip.c
index 20224d1..80d2e07 100644
--- a/lib/metadata/pool_manip.c
+++ b/lib/metadata/pool_manip.c
@@ -526,7 +526,7 @@ int create_pool(struct logical_volume *pool_lv,
* or directly converted to invisible device via suspend/resume
*/
pool_lv->status |= LV_TEMPORARY;
- if (!activate_lv_excl_local(pool_lv->vg->cmd, pool_lv)) {
+ if (!activate_lv(pool_lv->vg->cmd, pool_lv)) {
log_error("Aborting. Failed to activate pool metadata %s.",
display_lvname(pool_lv));
goto bad;
diff --git a/lib/metadata/raid_manip.c b/lib/metadata/raid_manip.c
index 53aa4f1..92e01a2 100644
--- a/lib/metadata/raid_manip.c
+++ b/lib/metadata/raid_manip.c
@@ -319,7 +319,7 @@ static int _deactivate_and_remove_lvs(struct volume_group *vg, struct dm_list *r
return 0;
}
/* Must get a cluster lock on SubLVs that will be removed. */
- if (!activate_lv_excl_local(vg->cmd, lvl->lv))
+ if (!activate_lv(vg->cmd, lvl->lv))
return_0;
}
@@ -669,7 +669,7 @@ static int _lv_update_and_reload_list(struct logical_volume *lv, int origin_only
dm_list_iterate_items(lvl, lv_list) {
log_very_verbose("Activating logical volume %s before %s in kernel.",
display_lvname(lvl->lv), display_lvname(lock_lv));
- if (!activate_lv_excl_local(vg->cmd, lvl->lv)) {
+ if (!activate_lv(vg->cmd, lvl->lv)) {
log_error("Failed to activate %s before resuming %s.",
display_lvname(lvl->lv), display_lvname(lock_lv));
r = 0; /* But lets try with the rest */
@@ -732,9 +732,9 @@ static int _clear_lvs(struct dm_list *lv_list)
was_active = alloca(sz);
dm_list_iterate_items(lvl, lv_list)
- if (!(was_active[i++] = lv_is_active_locally(lvl->lv))) {
+ if (!(was_active[i++] = lv_is_active(lvl->lv))) {
lvl->lv->status |= LV_TEMPORARY;
- if (!activate_lv_excl_local(vg->cmd, lvl->lv)) {
+ if (!activate_lv(vg->cmd, lvl->lv)) {
log_error("Failed to activate localy %s for clearing.",
display_lvname(lvl->lv));
r = 0;
@@ -2276,7 +2276,7 @@ static int _vg_write_lv_suspend_vg_commit(struct logical_volume *lv, int origin_
/* Helper: function to activate @lv exclusively local */
static int _activate_sub_lv_excl_local(struct logical_volume *lv)
{
- if (lv && !activate_lv_excl_local(lv->vg->cmd, lv)) {
+ if (lv && !activate_lv(lv->vg->cmd, lv)) {
log_error("Failed to activate %s.", display_lvname(lv));
return 0;
}
@@ -3258,16 +3258,6 @@ static int _lv_raid_change_image_count(struct logical_volume *lv, int yes, uint3
return r;
}
- /*
- * LV must be either in-active or exclusively active
- */
- if (lv_is_active(lv_lock_holder(lv)) && vg_is_clustered(lv->vg) &&
- !lv_is_active_exclusive_locally(lv_lock_holder(lv))) {
- log_error("%s must be active exclusive locally to "
- "perform this operation.", display_lvname(lv));
- return 0;
- }
-
if (old_count > new_count)
return _raid_remove_images(lv, yes, new_count, allocate_pvs, removal_lvs, commit);
@@ -3427,13 +3417,13 @@ int lv_raid_split(struct logical_volume *lv, int yes, const char *split_name,
/* FIXME: run all cases through lv_active_change when clvm variants are gone. */
if (vg_is_shared(lvl->lv->vg)) {
- if (!lv_active_change(lv->vg->cmd, lvl->lv, CHANGE_AEY, 0))
+ if (!lv_active_change(lv->vg->cmd, lvl->lv, CHANGE_AEY))
return_0;
- } else if (!activate_lv_excl_local(cmd, lvl->lv))
+ } else if (!activate_lv(cmd, lvl->lv))
return_0;
dm_list_iterate_items(lvl, &removal_lvs)
- if (!activate_lv_excl_local(cmd, lvl->lv))
+ if (!activate_lv(cmd, lvl->lv))
return_0;
if (!resume_lv(cmd, lv_lock_holder(lv))) {
@@ -3539,7 +3529,7 @@ int lv_raid_split_and_track(struct logical_volume *lv,
/* Activate the split (and tracking) LV */
/* Preserving exclusive local activation also for tracked LV */
- if (!activate_lv_excl_local(lv->vg->cmd, seg_lv(seg, s)))
+ if (!activate_lv(lv->vg->cmd, seg_lv(seg, s)))
return_0;
if (seg->area_count == 2)
@@ -5001,7 +4991,7 @@ static int _clear_meta_lvs(struct logical_volume *lv)
/* Grab locks first in case of clustered VG */
if (vg_is_clustered(lv->vg))
dm_list_iterate_items(lvl, &meta_lvs)
- if (!activate_lv_excl_local(lv->vg->cmd, lvl->lv))
+ if (!activate_lv(lv->vg->cmd, lvl->lv))
return_0;
/*
* Now deactivate the MetaLVs before clearing, so
@@ -6520,14 +6510,6 @@ int lv_raid_convert(struct logical_volume *lv,
return 0;
}
- if (vg_is_clustered(lv->vg) &&
- !lv_is_active_exclusive_locally(lv_lock_holder(lv))) {
- /* In clustered VGs, the LV must be active on this node exclusively. */
- log_error("%s must be active exclusive locally to "
- "perform this operation.", display_lvname(lv));
- return 0;
- }
-
new_segtype = new_segtype ? : seg->segtype;
if (!new_segtype) {
log_error(INTERNAL_ERROR "New segtype not specified.");
@@ -6810,10 +6792,8 @@ static int _lv_raid_rebuild_or_replace(struct logical_volume *lv,
if (lv_is_partial(lv))
lv->vg->cmd->partial_activation = 1;
- if (!lv_is_active_exclusive_locally(lv_lock_holder(lv))) {
- log_error("%s must be active %sto perform this operation.",
- display_lvname(lv),
- vg_is_clustered(lv->vg) ? "exclusive locally " : "");
+ if (!lv_is_active(lv_lock_holder(lv))) {
+ log_error("%s must be active to perform this operation.", display_lvname(lv));
return 0;
}
@@ -7013,7 +6993,7 @@ try_again:
* of their new names.
*/
dm_list_iterate_items(lvl, &old_lvs)
- if (!activate_lv_excl_local(lv->vg->cmd, lvl->lv))
+ if (!activate_lv(lv->vg->cmd, lvl->lv))
return_0;
/*
diff --git a/lib/metadata/snapshot_manip.c b/lib/metadata/snapshot_manip.c
index e3669ef..5ccf251 100644
--- a/lib/metadata/snapshot_manip.c
+++ b/lib/metadata/snapshot_manip.c
@@ -411,11 +411,5 @@ int validate_snapshot_origin(const struct logical_volume *origin_lv)
return 0;
}
- if (vg_is_clustered(origin_lv->vg) && lv_is_active(origin_lv) &&
- !lv_is_active_exclusive_locally(origin_lv)) {
- log_error("Snapshot origin must be active exclusively.");
- return 0;
- }
-
return 1;
}
diff --git a/lib/metadata/thin_manip.c b/lib/metadata/thin_manip.c
index e1522d3..6b2b1e7 100644
--- a/lib/metadata/thin_manip.c
+++ b/lib/metadata/thin_manip.c
@@ -504,7 +504,7 @@ int update_pool_lv(struct logical_volume *lv, int activate)
* as this version has major problem when it does not know
* which Node has pool active.
*/
- if (!activate_lv_excl(lv->vg->cmd, lv)) {
+ if (!activate_lv(lv->vg->cmd, lv)) {
init_dmeventd_monitor(monitored);
return_0;
}
@@ -857,7 +857,7 @@ int check_new_thin_pool(const struct logical_volume *pool_lv)
uint64_t transaction_id;
/* For transaction_id check LOCAL activation is required */
- if (!activate_lv_excl_local(cmd, pool_lv)) {
+ if (!activate_lv(cmd, pool_lv)) {
log_error("Aborting. Failed to locally activate thin pool %s.",
display_lvname(pool_lv));
return 0;
diff --git a/lib/report/report.c b/lib/report/report.c
index 4a957a7..8039820 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -3559,11 +3559,7 @@ static int _lvactivelocally_disp(struct dm_report *rh, struct dm_pool *mem,
if (!activation())
return _binary_undef_disp(rh, mem, field, private);
- if (vg_is_clustered(lv->vg)) {
- lv = lv_lock_holder(lv);
- active_locally = lv_is_active_locally(lv);
- } else
- active_locally = lv_is_active(lv);
+ active_locally = lv_is_active(lv);
return _binary_disp(rh, mem, field, active_locally, GET_FIRST_RESERVED_NAME(lv_active_locally_y), private);
}
@@ -3572,38 +3568,12 @@ static int _lvactiveremotely_disp(struct dm_report *rh, struct dm_pool *mem,
struct dm_report_field *field,
const void *data, void *private)
{
- const struct logical_volume *lv = (const struct logical_volume *) data;
int active_remotely;
if (!activation())
return _binary_undef_disp(rh, mem, field, private);
- if (vg_is_clustered(lv->vg)) {
- lv = lv_lock_holder(lv);
- /* FIXME: It seems we have no way to get this info correctly
- * with current interface - we'd need to check number
- * of responses from the cluster:
- * - if number of nodes that responded == 1
- * - and LV is active on local node
- * ..then we may say that LV is *not* active remotely.
- *
- * Otherwise ((responses > 1 && LV active locally) ||
- * (responses == 1 && LV not active locally)), it's
- * active remotely.
- *
- * We have this info, but hidden underneath the
- * locking interface (locking_type.query_resource fn).
- *
- * For now, let's use 'unknown' for remote status if
- * the LV is found active locally until we find a way to
- * smuggle the proper information out of the interface.
- */
- if (lv_is_active_locally(lv))
- return _binary_undef_disp(rh, mem, field, private);
-
- active_remotely = lv_is_active_but_not_locally(lv);
- } else
- active_remotely = 0;
+ active_remotely = 0;
return _binary_disp(rh, mem, field, active_remotely, GET_FIRST_RESERVED_NAME(lv_active_remotely_y), private);
}
@@ -3618,11 +3588,7 @@ static int _lvactiveexclusively_disp(struct dm_report *rh, struct dm_pool *mem,
if (!activation())
return _binary_undef_disp(rh, mem, field, private);
- if (vg_is_clustered(lv->vg)) {
- lv = lv_lock_holder(lv);
- active_exclusively = lv_is_active_exclusive(lv);
- } else
- active_exclusively = lv_is_active(lv);
+ active_exclusively = lv_is_active(lv);
return _binary_disp(rh, mem, field, active_exclusively, GET_FIRST_RESERVED_NAME(lv_active_exclusively_y), private);
}
diff --git a/tools/lvchange.c b/tools/lvchange.c
index 481cb4c..a90174e 100644
--- a/tools/lvchange.c
+++ b/tools/lvchange.c
@@ -294,9 +294,6 @@ static int _reactivate_lv(struct logical_volume *lv,
if (!active)
return 1;
- if (exclusive)
- return activate_lv_excl_local(cmd, lv);
-
return activate_lv(cmd, lv);
}
@@ -318,7 +315,7 @@ static int _lvchange_resync(struct cmd_context *cmd, struct logical_volume *lv)
dm_list_init(&device_list);
- if (lv_is_active_locally(lv)) {
+ if (lv_is_active(lv)) {
if (!lv_check_not_in_use(lv, 1)) {
log_error("Can't resync open logical volume %s.",
display_lvname(lv));
@@ -335,7 +332,7 @@ static int _lvchange_resync(struct cmd_context *cmd, struct logical_volume *lv)
}
active = 1;
- if (lv_is_active_exclusive_locally(lv))
+ if (lv_is_active(lv))
exclusive = 1;
}
@@ -411,7 +408,7 @@ static int _lvchange_resync(struct cmd_context *cmd, struct logical_volume *lv)
memlock_unlock(lv->vg->cmd);
dm_list_iterate_items(lvl, &device_list) {
- if (!activate_lv_excl_local(cmd, lvl->lv)) {
+ if (!activate_lv(cmd, lvl->lv)) {
log_error("Unable to activate %s for %s clearing.",
display_lvname(lvl->lv), (seg_is_raid(seg)) ?
"metadata area" : "mirror log");
@@ -621,7 +618,7 @@ static int _lvchange_persistent(struct cmd_context *cmd,
if (activate != CHANGE_AN) {
log_verbose("Re-activating logical volume %s.", display_lvname(lv));
- if (!lv_active_change(cmd, lv, activate, 0)) {
+ if (!lv_active_change(cmd, lv, activate)) {
log_error("%s: reactivation failed.", display_lvname(lv));
backup(lv->vg);
return 0;
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index aebf3e9..11f7cee 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -1767,7 +1767,7 @@ static int _lvconvert_splitsnapshot(struct cmd_context *cmd, struct logical_volu
return 0;
}
- if (lv_is_active_locally(cow)) {
+ if (lv_is_active(cow)) {
if (!lv_check_not_in_use(cow, 1))
return_0;
@@ -1950,7 +1950,7 @@ static int _lvconvert_snapshot(struct cmd_context *cmd,
log_warn("WARNING: %s not zeroed.", snap_name);
else {
lv->status |= LV_TEMPORARY;
- if (!activate_lv_excl_local(cmd, lv) ||
+ if (!activate_lv(cmd, lv) ||
!wipe_lv(lv, (struct wipe_params) { .do_zero = 1 })) {
log_error("Aborting. Failed to wipe snapshot exception store.");
return 0;
@@ -2037,7 +2037,7 @@ static int _lvconvert_merge_old_snapshot(struct cmd_context *cmd,
* constructor and DM should prevent appropriate devices from
* being open.
*/
- if (lv_is_active_locally(origin)) {
+ if (lv_is_active(origin)) {
if (!lv_check_not_in_use(origin, 0)) {
log_print_unless_silent("Delaying merge since origin is open.");
merge_on_activate = 1;
@@ -2146,7 +2146,7 @@ static int _lvconvert_merge_thin_snapshot(struct cmd_context *cmd,
log_print_unless_silent("Volume %s replaced origin %s.",
display_lvname(origin), display_lvname(lv));
- if (origin_is_active && !activate_lv_excl_local(cmd, lv)) {
+ if (origin_is_active && !activate_lv(cmd, lv)) {
log_error("Failed to reactivate origin %s.",
display_lvname(lv));
return 0;
@@ -2254,13 +2254,13 @@ static int _lvconvert_thin_pool_repair(struct cmd_context *cmd,
return 0;
}
- if (!activate_lv_excl_local(cmd, pmslv)) {
+ if (!activate_lv(cmd, pmslv)) {
log_error("Cannot activate pool metadata spare volume %s.",
pmslv->name);
return 0;
}
- if (!activate_lv_excl_local(cmd, mlv)) {
+ if (!activate_lv(cmd, mlv)) {
log_error("Cannot activate thin pool metadata volume %s.",
mlv->name);
goto deactivate_pmslv;
@@ -2452,13 +2452,13 @@ static int _lvconvert_cache_repair(struct cmd_context *cmd,
return 0;
}
- if (!activate_lv_excl_local(cmd, pmslv)) {
+ if (!activate_lv(cmd, pmslv)) {
log_error("Cannot activate pool metadata spare volume %s.",
pmslv->name);
return 0;
}
- if (!activate_lv_excl_local(cmd, mlv)) {
+ if (!activate_lv(cmd, mlv)) {
log_error("Cannot activate cache pool metadata volume %s.",
mlv->name);
goto deactivate_pmslv;
@@ -3106,7 +3106,7 @@ static int _lvconvert_to_pool(struct cmd_context *cmd,
if (zero_metadata) {
metadata_lv->status |= LV_TEMPORARY;
- if (!activate_lv_excl_local(cmd, metadata_lv)) {
+ if (!activate_lv(cmd, metadata_lv)) {
log_error("Aborting. Failed to activate metadata lv.");
goto bad;
}
@@ -3248,7 +3248,7 @@ static int _lvconvert_to_pool(struct cmd_context *cmd,
}
if (activate_pool &&
- !activate_lv_excl(cmd, pool_lv)) {
+ !activate_lv(cmd, pool_lv)) {
log_error("Failed to activate pool logical volume %s.",
display_lvname(pool_lv));
/* Deactivate subvolumes */
@@ -3461,11 +3461,8 @@ static int _lvconvert_repair_pvs_raid(struct cmd_context *cmd, struct logical_vo
struct dm_list *failed_pvs;
int do_it;
- if (!lv_is_active_exclusive_locally(lv_lock_holder(lv))) {
- log_error("%s must be active %sto perform this operation.",
- display_lvname(lv),
- vg_is_clustered(lv->vg) ?
- "exclusive locally " : "");
+ if (!lv_is_active(lv_lock_holder(lv))) {
+ log_error("%s must be active to perform this operation.", display_lvname(lv));
return 0;
}
diff --git a/tools/lvcreate.c b/tools/lvcreate.c
index 5c9d448..4009ea5 100644
--- a/tools/lvcreate.c
+++ b/tools/lvcreate.c
@@ -1232,13 +1232,13 @@ static int _determine_cache_argument(struct volume_group *vg,
return 1;
} else if (vg_is_shared(vg)) {
- if (!lv_active_change(cmd, lv, CHANGE_AEY, 0)) {
+ if (!lv_active_change(cmd, lv, CHANGE_AEY)) {
log_error("Cannot activate cache origin %s.",
display_lvname(lv));
return 0;
}
- } else if (!activate_lv_excl_local(cmd, lv)) {
+ } else if (!activate_lv(cmd, lv)) {
log_error("Cannot activate cache origin %s.",
display_lvname(lv));
return 0;
diff --git a/tools/polldaemon.c b/tools/polldaemon.c
index bd99c7b..7ad45ca 100644
--- a/tools/polldaemon.c
+++ b/tools/polldaemon.c
@@ -200,7 +200,7 @@ int wait_for_single_lv(struct cmd_context *cmd, struct poll_operation_id *id,
* If the LV is not active locally, the kernel cannot be
* queried for its status. We must exit in this case.
*/
- if (!lv_is_active_locally(lv)) {
+ if (!lv_is_active(lv)) {
log_print_unless_silent("%s: Interrupted: No longer active.", id->display_name);
ret = 1;
goto out;
@@ -440,7 +440,7 @@ static int _report_progress(struct cmd_context *cmd, struct poll_operation_id *i
goto out;
}
- if (!lv_is_active_locally(lv)) {
+ if (!lv_is_active(lv)) {
log_verbose("%s: Interrupted: No longer active.", id->display_name);
ret = 1;
goto out;
diff --git a/tools/pvmove.c b/tools/pvmove.c
index 0fcabb3..c5e3929 100644
--- a/tools/pvmove.c
+++ b/tools/pvmove.c
@@ -466,8 +466,7 @@ static struct logical_volume *_set_up_pvmove_lv(struct cmd_context *cmd,
* in the case it's NOT active anywhere else, since LOCKED LVs cannot be
* later activated by user.
*/
- if (lv_is_active_remotely(holder) ||
- (!lv_is_active_locally(holder) && !activate_lv_excl_local(cmd, holder))) {
+ if ((!lv_is_active(holder) && !activate_lv(cmd, holder))) {
lv_skipped = 1;
log_print_unless_silent("Skipping LV %s which is not locally exclusive%s.",
display_lvname(lv),
@@ -532,10 +531,7 @@ static int _activate_lv(struct cmd_context *cmd, struct logical_volume *lv_mirr,
{
int r = 0;
- if (exclusive || lv_is_active_exclusive(lv_mirr))
- r = activate_lv_excl(cmd, lv_mirr);
- else
- r = activate_lv(cmd, lv_mirr);
+ r = activate_lv(cmd, lv_mirr);
if (!r)
stack;
diff --git a/tools/toollib.c b/tools/toollib.c
index baf84ad..236e2b1 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1034,7 +1034,7 @@ int lv_change_activate(struct cmd_context *cmd, struct logical_volume *lv,
return 0;
}
- if (!lv_active_change(cmd, lv, activate, 0))
+ if (!lv_active_change(cmd, lv, activate))
return_0;
set_lv_notify(lv->vg->cmd);
@@ -1066,7 +1066,7 @@ int lv_refresh(struct cmd_context *cmd, struct logical_volume *lv)
* - fortunately: polldaemon will immediately shutdown if the
* origin doesn't have a status with a snapshot percentage
*/
- if (background_polling() && lv_is_merging_origin(lv) && lv_is_active_locally(lv))
+ if (background_polling() && lv_is_merging_origin(lv) && lv_is_active(lv))
lv_spawn_background_polling(cmd, lv);
return 1;
diff --git a/tools/vgchange.c b/tools/vgchange.c
index e87277f..a67c3be 100644
--- a/tools/vgchange.c
+++ b/tools/vgchange.c
@@ -63,7 +63,7 @@ static int _poll_lvs_in_vg(struct cmd_context *cmd,
dm_list_iterate_items(lvl, &vg->lvs) {
lv = lvl->lv;
- if (lv_is_active_locally(lv) &&
+ if (lv_is_active(lv) &&
(lv_is_pvmove(lv) || lv_is_converting(lv) || lv_is_merging(lv))) {
lv_spawn_background_polling(cmd, lv);
count++;
@@ -116,20 +116,8 @@ static int _activate_lvs_in_vg(struct cmd_context *cmd, struct volume_group *vg,
expected_count++;
- if (!lv_change_activate(cmd, lv, activate)) {
- if (!lv_is_active_exclusive_remotely(lv))
- stack;
- else {
- /*
- * If the LV is active exclusive remotely,
- * then ignore it here
- */
- log_verbose("%s is exclusively active on a remote node.",
- display_lvname(lv));
- expected_count--; /* not accounted */
- }
+ if (!lv_change_activate(cmd, lv, activate))
continue;
- }
count++;
}
5 years, 10 months
master - Remove more clvm code
by Joe Thornber
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=e4d9099e19591a7f3ad...
Commit: e4d9099e19591a7f3ad546c180b59a601e0d03da
Parent: d154dd66382d1bab4c227f6b3aaa12b6ccbb491f
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Tue Jun 5 11:39:07 2018 -0500
Committer: Joe Thornber <ejt(a)redhat.com>
CommitterDate: Thu Jun 7 16:17:04 2018 +0100
Remove more clvm code
---
lib/format_text/archiver.c | 4 ----
lib/locking/locking.h | 15 +++++----------
lib/metadata/metadata.c | 7 -------
3 files changed, 5 insertions(+), 21 deletions(-)
diff --git a/lib/format_text/archiver.c b/lib/format_text/archiver.c
index 9d7be95..ab80117 100644
--- a/lib/format_text/archiver.c
+++ b/lib/format_text/archiver.c
@@ -275,10 +275,6 @@ int backup(struct volume_group *vg)
if (is_orphan_vg(vg->name))
return 1;
- if (vg_is_clustered(vg))
- if (!remote_backup_metadata(vg))
- stack;
-
return backup_locally(vg);
}
diff --git a/lib/locking/locking.h b/lib/locking/locking.h
index 8322bae..8b2bced 100644
--- a/lib/locking/locking.h
+++ b/lib/locking/locking.h
@@ -163,10 +163,7 @@ int check_lvm1_vg_inactive(struct cmd_context *cmd, const char *vgname);
#define LCK_MASK (LCK_TYPE_MASK | LCK_SCOPE_MASK)
-#define LCK_LV_CLUSTERED(lv) \
- (vg_is_clustered((lv)->vg) ? LCK_CLUSTER_VG : 0)
-
-#define lock_lv_vol(cmd, lv, flags) lock_vol(cmd, (lv)->lvid.s, flags | LCK_LV_CLUSTERED(lv), lv)
+#define lock_lv_vol(cmd, lv, flags) lock_vol(cmd, (lv)->lvid.s, flags, lv)
/*
* Activation locks are wrapped around activation commands that have to
@@ -180,7 +177,9 @@ int check_lvm1_vg_inactive(struct cmd_context *cmd, const char *vgname);
*/
#define lv_type_requires_activation_lock(lv) ((lv_is_thin_type(lv) || lv_is_cache_type(lv) || lv_is_mirror_type(lv) || lv_is_raid_type(lv) || lv_is_origin(lv) || lv_is_snapshot(lv)) ? 1 : 0)
+
#define lv_activation_lock_name(lv) (lv_type_requires_activation_lock(lv) ? (lv)->vg->name : (lv)->lvid.s)
+
#define lv_requires_activation_lock_now(lv) ((!vg_write_lock_held() && (!vg_is_clustered((lv)->vg) || !lv_type_requires_activation_lock(lv))) ? 1 : 0)
#define lock_activation(cmd, lv) (lv_requires_activation_lock_now(lv) ? lock_vol(cmd, lv_activation_lock_name(lv), LCK_ACTIVATE_LOCK, lv) : 1)
@@ -246,16 +245,12 @@ int activate_lv_excl(struct cmd_context *cmd, const struct logical_volume *lv);
#define activate_lv_local(cmd, lv) \
lock_lv_vol_serially(cmd, lv, LCK_LV_ACTIVATE | LCK_HOLD | LCK_LOCAL)
+
#define deactivate_lv_local(cmd, lv) \
lock_lv_vol_serially(cmd, lv, LCK_LV_DEACTIVATE | LCK_LOCAL)
+
#define drop_cached_metadata(vg) \
lock_vol((vg)->cmd, (vg)->name, LCK_VG_DROP_CACHE, NULL)
-#define remote_commit_cached_metadata(vg) \
- lock_vol((vg)->cmd, (vg)->name, LCK_VG_COMMIT, NULL)
-#define remote_revert_cached_metadata(vg) \
- lock_vol((vg)->cmd, (vg)->name, LCK_VG_REVERT, NULL)
-#define remote_backup_metadata(vg) \
- lock_vol((vg)->cmd, (vg)->name, LCK_VG_BACKUP, NULL)
int sync_local_dev_names(struct cmd_context* cmd);
int sync_dev_names(struct cmd_context* cmd);
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index 3f177b0..7c41d78 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -3130,10 +3130,6 @@ int vg_commit(struct volume_group *vg)
set_vg_notify(vg->cmd);
if (cache_updated) {
- /* Instruct remote nodes to upgrade cached metadata. */
- if (!remote_commit_cached_metadata(vg))
- stack; // FIXME: What should we do?
-
/*
* We need to clear old_name after a successful commit.
* The volume_group structure could be reused later.
@@ -3188,9 +3184,6 @@ void vg_revert(struct volume_group *vg)
if (!drop_cached_metadata(vg))
log_error("Attempt to drop cached metadata failed "
"after reverted update for VG %s.", vg->name);
-
- if (!remote_revert_cached_metadata(vg))
- stack; // FIXME: What should we do?
}
static int _check_mda_in_use(struct metadata_area *mda, void *_in_use)
5 years, 10 months
master - lvmlockd: fix missing lock_type null check
by Joe Thornber
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=d154dd66382d1bab4c2...
Commit: d154dd66382d1bab4c227f6b3aaa12b6ccbb491f
Parent: 1539e51721418768eae894c0179a82cf5ab8e040
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Wed Jun 6 13:56:02 2018 -0500
Committer: Joe Thornber <ejt(a)redhat.com>
CommitterDate: Thu Jun 7 16:17:04 2018 +0100
lvmlockd: fix missing lock_type null check
Missed checking if vg->lock_type is NULL in commit db8d3bdfa:
lvmlockd: enable mirror split and merge with dlm lock_type
---
lib/metadata/raid_manip.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/metadata/raid_manip.c b/lib/metadata/raid_manip.c
index 4d58d74..53aa4f1 100644
--- a/lib/metadata/raid_manip.c
+++ b/lib/metadata/raid_manip.c
@@ -3395,7 +3395,7 @@ int lv_raid_split(struct logical_volume *lv, int yes, const char *split_name,
lvl->lv->name = split_name;
- if (!strcmp(lv->vg->lock_type, "dlm"))
+ if (lv->vg->lock_type && !strcmp(lv->vg->lock_type, "dlm"))
lvl->lv->lock_args = lv->lock_args;
if (!vg_write(lv->vg)) {
5 years, 10 months
master - devices: clean up io error messages
by Joe Thornber
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=1539e51721418768eae...
Commit: 1539e51721418768eae894c0179a82cf5ab8e040
Parent: bd8c6cf8628e5898ea89ebbcccfe423dba83a840
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Wed Jun 6 10:05:08 2018 -0500
Committer: Joe Thornber <ejt(a)redhat.com>
CommitterDate: Thu Jun 7 16:17:04 2018 +0100
devices: clean up io error messages
Remove the io error message from bcache.c since it is not
very useful without the device path.
Make the io error messages from dev_read_bytes/dev_write_bytes
more user friendly.
---
lib/device/bcache.c | 1 -
lib/label/label.c | 40 ++++++++++++++++++++++------------------
2 files changed, 22 insertions(+), 19 deletions(-)
diff --git a/lib/device/bcache.c b/lib/device/bcache.c
index 8fda0bd..561f68e 100644
--- a/lib/device/bcache.c
+++ b/lib/device/bcache.c
@@ -623,7 +623,6 @@ static void _complete_io(void *context, int err)
dm_list_del(&b->list);
if (b->error) {
- log_warn("bcache io error %d fd %d", b->error, b->fd);
dm_list_add(&cache->errored, &b->list);
} else {
diff --git a/lib/label/label.c b/lib/label/label.c
index f36c706..ce995d6 100644
--- a/lib/label/label.c
+++ b/lib/label/label.c
@@ -1122,14 +1122,15 @@ bool dev_read_bytes(struct device *dev, uint64_t start, size_t len, void *data)
if (dev->bcache_fd <= 0) {
/* This is not often needed, perhaps only with lvmetad. */
if (!label_scan_open(dev)) {
- log_error("dev_read_bytes %s cannot open dev", dev_name(dev));
+ log_error("Error opening device %s for reading at %llu length %u.",
+ dev_name(dev), (unsigned long long)start, (uint32_t)len);
return false;
}
}
if (!bcache_read_bytes(scan_bcache, dev->bcache_fd, start, len, data)) {
- log_error("dev_read_bytes %s at %u failed invalidate fd %d",
- dev_name(dev), (uint32_t)start, dev->bcache_fd);
+ log_error("Error reading device %s at %llu length %u.",
+ dev_name(dev), (unsigned long long)start, (uint32_t)len);
label_scan_invalidate(dev);
return false;
}
@@ -1151,21 +1152,22 @@ bool dev_write_bytes(struct device *dev, uint64_t start, size_t len, void *data)
if (dev->bcache_fd <= 0) {
/* This is not often needed, perhaps only with lvmetad. */
if (!label_scan_open(dev)) {
- log_error("dev_write_bytes %s cannot open dev", dev_name(dev));
+ log_error("Error opening device %s for writing at %llu length %u.",
+ dev_name(dev), (unsigned long long)start, (uint32_t)len);
return false;
}
}
if (!bcache_write_bytes(scan_bcache, dev->bcache_fd, start, len, data)) {
- log_error("dev_write_bytes %s at %u bcache write failed invalidate fd %d",
- dev_name(dev), (uint32_t)start, dev->bcache_fd);
+ log_error("Error writing device %s at %llu length %u.",
+ dev_name(dev), (unsigned long long)start, (uint32_t)len);
label_scan_invalidate(dev);
return false;
}
if (!bcache_flush(scan_bcache)) {
- log_error("dev_write_bytes %s at %u bcache flush failed invalidate fd %d",
- dev_name(dev), (uint32_t)start, dev->bcache_fd);
+ log_error("Error writing device %s at %llu length %u.",
+ dev_name(dev), (unsigned long long)start, (uint32_t)len);
label_scan_invalidate(dev);
return false;
}
@@ -1185,21 +1187,22 @@ bool dev_write_zeros(struct device *dev, uint64_t start, size_t len)
if (dev->bcache_fd <= 0) {
/* This is not often needed, perhaps only with lvmetad. */
if (!label_scan_open(dev)) {
- log_error("dev_write_zeros %s cannot open dev", dev_name(dev));
+ log_error("Error opening device %s for writing at %llu length %u.",
+ dev_name(dev), (unsigned long long)start, (uint32_t)len);
return false;
}
}
if (!bcache_zero_bytes(scan_bcache, dev->bcache_fd, start, len)) {
- log_error("dev_write_zeros %s at %u bcache write failed invalidate fd %d",
- dev_name(dev), (uint32_t)start, dev->bcache_fd);
+ log_error("Error writing device %s at %llu length %u.",
+ dev_name(dev), (unsigned long long)start, (uint32_t)len);
label_scan_invalidate(dev);
return false;
}
if (!bcache_flush(scan_bcache)) {
- log_error("dev_write_zeros %s at %u bcache flush failed invalidate fd %d",
- dev_name(dev), (uint32_t)start, dev->bcache_fd);
+ log_error("Error writing device %s at %llu length %u.",
+ dev_name(dev), (unsigned long long)start, (uint32_t)len);
label_scan_invalidate(dev);
return false;
}
@@ -1219,21 +1222,22 @@ bool dev_set_bytes(struct device *dev, uint64_t start, size_t len, uint8_t val)
if (dev->bcache_fd <= 0) {
/* This is not often needed, perhaps only with lvmetad. */
if (!label_scan_open(dev)) {
- log_error("dev_set_bytes %s cannot open dev", dev_name(dev));
+ log_error("Error opening device %s for writing at %llu length %u.",
+ dev_name(dev), (unsigned long long)start, (uint32_t)len);
return false;
}
}
if (!bcache_set_bytes(scan_bcache, dev->bcache_fd, start, len, val)) {
- log_error("dev_set_bytes %s at %u bcache write failed invalidate fd %d",
- dev_name(dev), (uint32_t)start, dev->bcache_fd);
+ log_error("Error writing device %s at %llu length %u.",
+ dev_name(dev), (unsigned long long)start, (uint32_t)len);
label_scan_invalidate(dev);
return false;
}
if (!bcache_flush(scan_bcache)) {
- log_error("dev_set_bytes %s at %u bcache flush failed invalidate fd %d",
- dev_name(dev), (uint32_t)start, dev->bcache_fd);
+ log_error("Error writing device %s at %llu length %u.",
+ dev_name(dev), (unsigned long long)start, (uint32_t)len);
label_scan_invalidate(dev);
return false;
}
5 years, 10 months
master - scripts/lvm2_activation_generator_systemd_red_hat: rewrite to use lvmconfig
by Joe Thornber
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=bd8c6cf8628e5898ea8...
Commit: bd8c6cf8628e5898ea89ebbcccfe423dba83a840
Parent: 74460cd009267564be032a373e78ec5eba67b4ce
Author: Joe Thornber <ejt(a)redhat.com>
AuthorDate: Thu Jun 7 16:15:04 2018 +0100
Committer: Joe Thornber <ejt(a)redhat.com>
CommitterDate: Thu Jun 7 16:15:04 2018 +0100
scripts/lvm2_activation_generator_systemd_red_hat: rewrite to use lvmconfig
Unit tested the new code, but not run functional tests (assuming they exist).
---
configure.ac | 3 +
scripts/Makefile.in | 16 +--
scripts/generator-internals.c | 200 +++++++++++++++++
.../lvm2_activation_generator_systemd_red_hat.c | 232 ++++++++++++--------
test/unit/Makefile.in | 6 +-
test/unit/units.h | 2 +
6 files changed, 348 insertions(+), 111 deletions(-)
diff --git a/configure.ac b/configure.ac
index 67f2462..365df25 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1533,6 +1533,9 @@ SBINDIR="$(eval echo $(eval echo $sbindir))"
LVM_PATH="$SBINDIR/lvm"
AC_DEFINE_UNQUOTED(LVM_PATH, ["$LVM_PATH"], [Path to lvm binary.])
+LVMCONFIG_PATH="$$BINDIR/lvmconfig"
+AC_DEFINE_UNQUOTED(LVMCONFIG_PATH, ["$LVMCONFIG_PATH"], [Path to lvmconfig binary.])
+
USRSBINDIR="$(eval echo $(eval echo $usrsbindir))"
FSADM_PATH="$SBINDIR/fsadm"
diff --git a/scripts/Makefile.in b/scripts/Makefile.in
index ee39306..208aebf 100644
--- a/scripts/Makefile.in
+++ b/scripts/Makefile.in
@@ -15,21 +15,14 @@ srcdir = @srcdir@
top_srcdir = @top_srcdir@
top_builddir = @top_builddir@
-ifeq ("@APPLIB@", "yes")
- SOURCES = lvm2_activation_generator_systemd_red_hat.c
- TARGETS = lvm2_activation_generator_systemd_red_hat
-endif
+SOURCES = lvm2_activation_generator_systemd_red_hat.c
+TARGETS = lvm2_activation_generator_systemd_red_hat
include $(top_builddir)/make.tmpl
-ifeq ("@APPLIB@", "yes")
- DEPLIBS += $(top_builddir)/liblvm/liblvm2app.so
- LDFLAGS += -L$(top_builddir)/liblvm
ifeq ("@BUILD_DMEVENTD@", "yes")
LDFLAGS += -Wl,-rpath-link,$(top_builddir)/daemons/dmeventd
endif
- LVMLIBS = @LVM2APP_LIB@ -laio
-endif
LVM_SCRIPTS = lvmdump.sh lvmconf.sh
DM_SCRIPTS =
@@ -93,12 +86,7 @@ lvm2_activation_generator_systemd_red_hat: $(OBJECTS) $(DEPLIBS) $(INTERNAL_LIBS
install_systemd_generators:
$(INSTALL_DIR) $(systemd_generator_dir)
-ifeq ("@APPLIB@", "yes")
$(INSTALL_PROGRAM) lvm2_activation_generator_systemd_red_hat $(systemd_generator_dir)/lvm2-activation-generator
-else
- @echo "WARNING: LVM2 activation systemd generator not installed." \
- "It requires the LVM2 application library to be built as well."
-endif
install_systemd_units: install_dbus_service
$(INSTALL_DIR) $(systemd_unit_dir)
diff --git a/scripts/generator-internals.c b/scripts/generator-internals.c
new file mode 100644
index 0000000..c38323b
--- /dev/null
+++ b/scripts/generator-internals.c
@@ -0,0 +1,200 @@
+// This file contains the unit testable parts of
+// lvm2_activation_generator_systemd_red_hat
+
+#include <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h> /* For PATH_MAX for musl libc */
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <syslog.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+//----------------------------------------------------------------
+
+static void _error(const char *format, ...) __attribute__ ((format(printf, 1, 2)));
+
+//----------------------------------------------------------------
+
+// I'm rolling my own version of popen() here because I do not want to
+// go through the shell.
+
+struct child_process {
+ pid_t pid;
+ FILE *fp;
+};
+
+static bool _open_child(struct child_process *child, const char *cmd, const char *argv[])
+{
+ int r, pipe_fd[2];
+
+ r = pipe(pipe_fd);
+ if (r < 0) {
+ _error("call to pipe() failed: %d\n", r);
+ return false;
+ }
+
+ child->pid = fork();
+ if (child->pid < 0) {
+ close(pipe_fd[0]);
+ close(pipe_fd[1]);
+ _error("call to fork() failed: %d\n", r);
+ return false;
+ }
+
+ if (child->pid == 0) {
+ // child
+ close(pipe_fd[0]);
+ if (pipe_fd[1] != STDOUT_FILENO) {
+ dup2(pipe_fd[1], STDOUT_FILENO);
+ close(pipe_fd[1]);
+ }
+
+ execv(cmd, (char *const *) argv);
+ // Shouldn't get here unless exec failed.
+ exit(1);
+ } else {
+ // parent
+ close(pipe_fd[1]);
+ child->fp = fdopen(pipe_fd[0], "r");
+ if (!child->fp) {
+ _error("call to fdopen() failed\n");
+ return false;
+ }
+ }
+
+ return true;
+}
+
+// Returns the child's exit status
+static bool _close_child(struct child_process *child)
+{
+ int status;
+
+ fclose(child->fp);
+
+ while (waitpid(child->pid, &status, 0) < 0)
+ if (errno != EINTR)
+ return -1;
+
+ if (WIFEXITED(status) && !WEXITSTATUS(status))
+ return true;
+
+ return false;
+}
+
+//----------------------------------------------------------------
+// Aquiring config from the lvmconfig process
+
+#define LVM_CONF_USE_LVMETAD "global/use_lvmetad"
+#define LVM_CONF_USE_LVMPOLLD "global/use_lvmpolld"
+
+struct config {
+ bool use_lvmetad;
+ bool sysinit_needed;
+};
+
+static bool _begins_with(const char *line, const char *prefix, const char **rest)
+{
+ size_t len = strlen(prefix);
+
+ if (strlen(line) < len)
+ return false;
+
+ if (strncmp(line, prefix, len))
+ return false;
+
+ *rest = line + len;
+
+ return true;
+}
+
+static bool _parse_bool(const char *val, bool * result)
+{
+ const char *b = val, *e;
+
+ while (*b && isspace(*b))
+ b++;
+
+ if (!*b)
+ goto parse_error;
+
+ e = b;
+ while (*e && !isspace(*e))
+ e++;
+
+ if ((e - b) != 1)
+ goto parse_error;
+
+ // We only handle '1', or '0'
+ if (*b == '1') {
+ *result = true;
+ return true;
+
+ } else if (*b == '0') {
+ *result = false;
+ return true;
+ }
+ // Fallthrough
+
+ parse_error:
+ _error("couldn't parse bool value '%s'\n", val);
+ return false;
+}
+
+static bool _parse_line(const char *line, struct config *cfg)
+{
+ const char *val;
+
+ if (_begins_with(line, "use_lvmetad=", &val)) {
+ return _parse_bool(val, &cfg->use_lvmetad);
+
+ } else if (_begins_with(line, "use_lvmpolld=", &val)) {
+ bool r;
+ if (!_parse_bool(val, &r))
+ return false;
+ cfg->sysinit_needed = !r;
+ return true;
+ }
+
+ return false;
+}
+
+static bool _get_config(struct config *cfg, const char *lvmconfig_path)
+{
+ static const char *_argv[] = {
+ "lvmconfig", LVM_CONF_USE_LVMETAD, LVM_CONF_USE_LVMPOLLD, NULL
+ };
+
+ bool r = true;
+ char buffer[256];
+ struct child_process child;
+
+ cfg->use_lvmetad = false;
+ cfg->sysinit_needed = true;
+
+ if (!_open_child(&child, lvmconfig_path, _argv)) {
+ _error("couldn't open lvmconfig process\n");
+ return false;
+ }
+
+ while (fgets(buffer, sizeof(buffer), child.fp)) {
+ if (!_parse_line(buffer, cfg)) {
+ _error("_parse_line() failed\n");
+ r = false;
+ }
+ }
+
+ if (!_close_child(&child)) {
+ _error("lvmconfig failed\n");
+ r = false;
+ }
+
+ return r;
+}
diff --git a/scripts/lvm2_activation_generator_systemd_red_hat.c b/scripts/lvm2_activation_generator_systemd_red_hat.c
index 551b29a..9ba1996 100644
--- a/scripts/lvm2_activation_generator_systemd_red_hat.c
+++ b/scripts/lvm2_activation_generator_systemd_red_hat.c
@@ -12,106 +12,139 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <stdio.h>
-#include <unistd.h>
+#include <ctype.h>
#include <errno.h>
+#include <fcntl.h>
+#include <limits.h> /* For PATH_MAX for musl libc */
#include <stdarg.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
#include <syslog.h>
-#include <sys/types.h>
#include <sys/stat.h>
-#include <fcntl.h>
-#include <limits.h> /* For PATH_MAX for musl libc */
-#include "liblvm/lvm2app.h"
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
#include "configure.h"
+#include "device_mapper/libdevmapper.h"
-#define KMSG_DEV_PATH "/dev/kmsg"
-#define LVM_CONF_USE_LVMETAD "global/use_lvmetad"
-#define LVM_CONF_USE_LVMPOLLD "global/use_lvmpolld"
+//----------------------------------------------------------------
-#define UNIT_TARGET_LOCAL_FS "local-fs-pre.target"
-#define UNIT_TARGET_REMOTE_FS "remote-fs-pre.target"
+// Code in this file gets included in the unit tests.
+#include "generator-internals.c"
-static char unit_path[PATH_MAX];
-static char target_path[PATH_MAX];
-static char message[PATH_MAX + 3]; /* +3 for '<n>' where n is the log level */
-static int kmsg_fd = -1;
+//----------------------------------------------------------------
+// Logging
-enum {
- UNIT_EARLY,
- UNIT_MAIN,
- UNIT_NET
-};
+#define KMSG_DEV_PATH "/dev/kmsg"
+static int _kmsg_fd;
-static const char *unit_names[] = {
- [UNIT_EARLY] = "lvm2-activation-early.service",
- [UNIT_MAIN] = "lvm2-activation.service",
- [UNIT_NET] = "lvm2-activation-net.service"
-};
+static void _log_init(void)
+{
+ // failing is harmless
+ _kmsg_fd = open(KMSG_DEV_PATH, O_WRONLY | O_NOCTTY);
+}
-__attribute__ ((format(printf, 2, 3)))
-static void kmsg(int log_level, const char *format, ...)
+static void _log_exit(void)
+{
+ if (_kmsg_fd != -1)
+ (void) close(_kmsg_fd);
+}
+
+__attribute__ ((format(printf, 1, 2)))
+static void _error(const char *format, ...)
{
- va_list ap;
int n;
+ va_list ap;
+ char message[PATH_MAX + 3]; /* +3 for '<n>' where n is the log level */
- snprintf(message, 4, "<%d>", log_level);
+ snprintf(message, 4, "<%d>", LOG_ERR);
va_start(ap, format);
n = vsnprintf(message + 3, PATH_MAX, format, ap);
va_end(ap);
- if (kmsg_fd < 0 || (n < 0 || ((unsigned) n + 1 > PATH_MAX)))
+ if (_kmsg_fd < 0 || (n < 0 || ((unsigned) n + 1 > PATH_MAX)))
return;
/* The n+4: +3 for "<n>" prefix and +1 for '\0' suffix */
- if (write(kmsg_fd, message, n + 4)) { /* Ignore result code */; }
+ (void) write(_kmsg_fd, message, n + 4);
}
-static void lvm_get_use_lvmetad_and_lvmpolld(int *use_lvmetad, int *use_lvmpolld)
-{
- *use_lvmetad = *use_lvmpolld = 0;
+//----------------------------------------------------------------
- *use_lvmetad = lvm_config_find_bool(NULL, LVM_CONF_USE_LVMETAD, 0);
- *use_lvmpolld = lvm_config_find_bool(NULL, LVM_CONF_USE_LVMPOLLD, 0);
-}
+#define UNIT_TARGET_LOCAL_FS "local-fs-pre.target"
+#define UNIT_TARGET_REMOTE_FS "remote-fs-pre.target"
+
+struct generator {
+ const char *dir;
+ struct config cfg;
-static int register_unit_with_target(const char *dir, const char *unit, const char *target)
+ int kmsg_fd;
+ char unit_path[PATH_MAX];
+ char target_path[PATH_MAX];
+};
+
+enum {
+ UNIT_EARLY,
+ UNIT_MAIN,
+ UNIT_NET
+};
+
+static const char *_unit_names[] = {
+ [UNIT_EARLY] = "lvm2-activation-early.service",
+ [UNIT_MAIN] = "lvm2-activation.service",
+ [UNIT_NET] = "lvm2-activation-net.service"
+};
+
+//----------------------------------------------------------------
+
+static int register_unit_with_target(struct generator *gen, const char *unit,
+ const char *target)
{
int r = 1;
- if (dm_snprintf(target_path, PATH_MAX, "%s/%s.wants", dir, target) < 0) {
- r = 0; goto out;
+ if (dm_snprintf(gen->target_path, PATH_MAX, "%s/%s.wants", gen->dir, target) < 0) {
+ r = 0;
+ goto out;
}
- (void) dm_prepare_selinux_context(target_path, S_IFDIR);
- if (mkdir(target_path, 0755) < 0 && errno != EEXIST) {
- kmsg(LOG_ERR, "LVM: Failed to create target directory %s: %m.\n", target_path);
- r = 0; goto out;
+
+ (void) dm_prepare_selinux_context(gen->target_path, S_IFDIR);
+ if (mkdir(gen->target_path, 0755) < 0 && errno != EEXIST) {
+ _error("LVM: Failed to create target directory %s: %m.\n", gen->target_path);
+ r = 0;
+ goto out;
}
- if (dm_snprintf(target_path, PATH_MAX, "%s/%s.wants/%s", dir, target, unit) < 0) {
- r = 0; goto out;
+ if (dm_snprintf
+ (gen->target_path, PATH_MAX, "%s/%s.wants/%s", gen->dir, target, unit) < 0) {
+ r = 0;
+ goto out;
}
- (void) dm_prepare_selinux_context(target_path, S_IFLNK);
- if (symlink(unit_path, target_path) < 0) {
- kmsg(LOG_ERR, "LVM: Failed to create symlink for unit %s: %m.\n", unit);
+ (void) dm_prepare_selinux_context(gen->target_path, S_IFLNK);
+ if (symlink(gen->unit_path, gen->target_path) < 0) {
+ _error("LVM: Failed to create symlink for unit %s: %m.\n", unit);
r = 0;
}
-out:
+ out:
dm_prepare_selinux_context(NULL, 0);
return r;
}
-static int generate_unit(const char *dir, int unit, int sysinit_needed)
+static int generate_unit(struct generator *gen, int unit)
{
FILE *f;
- const char *unit_name = unit_names[unit];
- const char *target_name = unit == UNIT_NET ? UNIT_TARGET_REMOTE_FS : UNIT_TARGET_LOCAL_FS;
+ const char *unit_name = _unit_names[unit];
+ const char *target_name =
+ unit == UNIT_NET ? UNIT_TARGET_REMOTE_FS : UNIT_TARGET_LOCAL_FS;
- if (dm_snprintf(unit_path, PATH_MAX, "%s/%s", dir, unit_name) < 0)
+ if (dm_snprintf(gen->unit_path, PATH_MAX, "%s/%s", gen->dir, unit_name)
+ < 0)
return 0;
- if (!(f = fopen(unit_path, "wxe"))) {
- kmsg(LOG_ERR, "LVM: Failed to create unit file %s: %m.\n", unit_name);
+ if (!(f = fopen(gen->unit_path, "wxe"))) {
+ _error("LVM: Failed to create unit file %s: %m.\n", unit_name);
return 0;
}
@@ -124,79 +157,90 @@ static int generate_unit(const char *dir, int unit, int sysinit_needed)
"[Unit]\n"
"Description=Activation of LVM2 logical volumes\n"
"Documentation=man:lvm2-activation-generator(8)\n"
- "SourcePath=/etc/lvm/lvm.conf\n"
- "DefaultDependencies=no\n", f);
+ "SourcePath=/etc/lvm/lvm.conf\n" "DefaultDependencies=no\n", f);
if (unit == UNIT_NET) {
fprintf(f, "After=%s iscsi.service fcoe.service\n"
"Before=remote-fs-pre.target shutdown.target\n\n"
"[Service]\n"
- "ExecStartPre=/usr/bin/udevadm settle\n", unit_names[UNIT_MAIN]);
+ "ExecStartPre=/usr/bin/udevadm settle\n", _unit_names[UNIT_MAIN]);
} else {
- if (unit == UNIT_EARLY) {
+ if (unit == UNIT_EARLY)
fputs("After=systemd-udev-settle.service\n"
"Before=cryptsetup.target\n", f);
- } else
- fprintf(f, "After=%s cryptsetup.target\n", unit_names[UNIT_EARLY]);
+ else
+ fprintf(f, "After=%s cryptsetup.target\n", _unit_names[UNIT_EARLY]);
fputs("Before=local-fs-pre.target shutdown.target\n"
- "Wants=systemd-udev-settle.service\n\n"
- "[Service]\n", f);
+ "Wants=systemd-udev-settle.service\n\n" "[Service]\n", f);
}
fputs("ExecStart=" LVM_PATH " vgchange -aay --ignoreskippedcluster", f);
- if (sysinit_needed)
- fputs (" --sysinit", f);
+ if (gen->cfg.sysinit_needed)
+ fputs(" --sysinit", f);
fputs("\nType=oneshot\n", f);
if (fclose(f) < 0) {
- kmsg(LOG_ERR, "LVM: Failed to write unit file %s: %m.\n", unit_name);
+ _error("LVM: Failed to write unit file %s: %m.\n", unit_name);
return 0;
}
- if (!register_unit_with_target(dir, unit_name, target_name)) {
- kmsg(LOG_ERR, "LVM: Failed to register unit %s with target %s.\n", unit_name, target_name);
+ if (!register_unit_with_target(gen, unit_name, target_name)) {
+ _error("LVM: Failed to register unit %s with target %s.\n",
+ unit_name, target_name);
return 0;
}
return 1;
}
-int main(int argc, char *argv[])
+static bool _parse_command_line(struct generator *gen, int argc, const char **argv)
{
- int use_lvmetad, use_lvmpolld, sysinit_needed;
- const char *dir;
- int r = EXIT_SUCCESS;
- mode_t old_mask;
-
- kmsg_fd = open(KMSG_DEV_PATH, O_WRONLY|O_NOCTTY);
-
if (argc != 4) {
- kmsg(LOG_ERR, "LVM: Incorrect number of arguments for activation generator.\n");
- r = EXIT_FAILURE; goto out;
+ _error("LVM: Incorrect number of arguments for activation generator.\n");
+ return false;
}
- /* If lvmetad used, rely on autoactivation instead of direct activation. */
- lvm_get_use_lvmetad_and_lvmpolld(&use_lvmetad, &use_lvmpolld);
- if (use_lvmetad)
- goto out;
+ gen->dir = argv[1];
+ return true;
+}
+
+static bool _run(int argc, const char **argv)
+{
+ bool r;
+ mode_t old_mask;
+ struct generator gen;
+
+ if (!_parse_command_line(&gen, argc, argv))
+ return false;
+
+ if (!_get_config(&gen.cfg, LVMCONFIG_PATH))
+ return false;
- dir = argv[1];
+ if (gen.cfg.use_lvmetad)
+ // If lvmetad used, rely on autoactivation instead of direct activation.
+ return true;
/* mark lvm2-activation.*.service as world-accessible */
old_mask = umask(0022);
- sysinit_needed = !use_lvmpolld;
+ r = generate_unit(&gen, UNIT_EARLY) &&
+ generate_unit(&gen, UNIT_MAIN) && generate_unit(&gen, UNIT_NET);
- if (!generate_unit(dir, UNIT_EARLY, sysinit_needed) ||
- !generate_unit(dir, UNIT_MAIN, sysinit_needed) ||
- !generate_unit(dir, UNIT_NET, sysinit_needed))
- r = EXIT_FAILURE;
umask(old_mask);
-out:
- if (r)
- kmsg(LOG_ERR, "LVM: Activation generator failed.\n");
- if (kmsg_fd != -1)
- (void) close(kmsg_fd);
+
return r;
}
+
+int main(int argc, const char **argv)
+{
+ bool r;
+
+ _log_init();
+ r = _run(argc, argv);
+ if (!r)
+ _error("LVM: Activation generator failed.\n");
+ _log_exit();
+
+ return r ? EXIT_SUCCESS : EXIT_FAILURE;
+}
diff --git a/test/unit/Makefile.in b/test/unit/Makefile.in
index 994968c..e7cc852 100644
--- a/test/unit/Makefile.in
+++ b/test/unit/Makefile.in
@@ -14,6 +14,7 @@ UNIT_SOURCE=\
base/data-struct/radix-tree.c \
device_mapper/vdo/status.c \
\
+ test/unit/activation-generator_t.c \
test/unit/bcache_t.c \
test/unit/bcache_utils_t.c \
test/unit/bitset_t.c \
@@ -32,12 +33,11 @@ UNIT_SOURCE=\
UNIT_DEPENDS=$(subst .c,.d,$(UNIT_SOURCE))
UNIT_OBJECTS=$(UNIT_SOURCE:%.c=%.o)
CLEAN_TARGETS+=$(UNIT_DEPENDS) $(UNIT_OBJECTS)
-UNIT_LDLIBS += $(LVMINTERNAL_LIBS) -laio
-test/unit/unit-test: $(UNIT_OBJECTS) lib/liblvm-internal.a $(INTERNAL_LIBS)
+test/unit/unit-test: $(UNIT_OBJECTS) lib/liblvm-internal.a libdaemon/client/libdaemonclient.a $(INTERNAL_LIBS)
@echo " [LD] $@"
$(Q) $(CC) $(CFLAGS) $(LDFLAGS) $(EXTRA_EXEC_LDFLAGS) \
- -o $@ $+ $(UNIT_LDLIBS) -lm
+ -o $@ $+ $(LIBS) -lm -ldl -laio
.PHONEY: run-unit-test
run-unit-test: test/unit/unit-test
diff --git a/test/unit/units.h b/test/unit/units.h
index d7ac6ad..bc0db8d 100644
--- a/test/unit/units.h
+++ b/test/unit/units.h
@@ -20,6 +20,7 @@
//-----------------------------------------------------------------
// Declare the function that adds tests suites here ...
+void activation_generator_tests(struct dm_list *suites);
void bcache_tests(struct dm_list *suites);
void bcache_utils_tests(struct dm_list *suites);
void bitset_tests(struct dm_list *suites);
@@ -36,6 +37,7 @@ void vdo_tests(struct dm_list *suites);
// ... and call it in here.
static inline void register_all_tests(struct dm_list *suites)
{
+ activation_generator_tests(suites);
bcache_tests(suites);
bcache_utils_tests(suites);
bitset_tests(suites);
5 years, 10 months
master - device_mapper: fixup a couple of includes
by Joe Thornber
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=74460cd009267564be0...
Commit: 74460cd009267564be032a373e78ec5eba67b4ce
Parent: 3e781ea446bb7ddc9a494cbba6b6104dd51c3910
Author: Joe Thornber <ejt(a)redhat.com>
AuthorDate: Wed Jun 6 14:45:16 2018 +0100
Committer: Joe Thornber <ejt(a)redhat.com>
CommitterDate: Wed Jun 6 14:45:16 2018 +0100
device_mapper: fixup a couple of includes
"libdevmapper.h" -> "device_mapper/libdevmapper.h"
---
device_mapper/misc/dm-logging.h | 2 +-
device_mapper/misc/dmlib.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/device_mapper/misc/dm-logging.h b/device_mapper/misc/dm-logging.h
index a35480e..e355bc5 100644
--- a/device_mapper/misc/dm-logging.h
+++ b/device_mapper/misc/dm-logging.h
@@ -16,7 +16,7 @@
#ifndef _DM_LOGGING_H
#define _DM_LOGGING_H
-#include "libdevmapper.h"
+#include "device_mapper/libdevmapper.h"
extern dm_log_with_errno_fn dm_log_with_errno;
diff --git a/device_mapper/misc/dmlib.h b/device_mapper/misc/dmlib.h
index ba376bc..88b6ac3 100644
--- a/device_mapper/misc/dmlib.h
+++ b/device_mapper/misc/dmlib.h
@@ -26,7 +26,7 @@
#define _REENTRANT
#define _GNU_SOURCE
-#include "libdevmapper.h"
+#include "device_mapper/libdevmapper.h"
#include "lib/misc/util.h"
#include "dm-logging.h"
5 years, 10 months
master - Implement lock-override options without locking type
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=f2ff06d6756bb31779d...
Commit: f2ff06d6756bb31779d16915c64361393054cfe7
Parent: 55521be2cbe28b0580fafafff6151cf4b6a219ea
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Wed Jun 6 16:31:59 2018 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Wed Jun 6 16:31:59 2018 -0500
Implement lock-override options without locking type
The options: --nolocking, --readonly, --sysinit
override, or make exceptions to, the normal file locking
behavior. Implement these by just checking for the
options in the file locking path instead of using
special locking types.
---
lib/locking/file_locking.c | 2 +-
lib/locking/locking.c | 58 +++++++++++++++++++++++++++++++++---------
lib/locking/locking.h | 2 +-
lib/locking/locking_types.h | 18 +------------
tools/lvmcmdline.c | 52 +++++++++++++++++++-------------------
5 files changed, 75 insertions(+), 57 deletions(-)
diff --git a/lib/locking/file_locking.c b/lib/locking/file_locking.c
index a60a3e5..0bded0e 100644
--- a/lib/locking/file_locking.c
+++ b/lib/locking/file_locking.c
@@ -92,7 +92,7 @@ int init_file_locking(struct locking_type *locking, struct cmd_context *cmd,
locking->lock_resource = _file_lock_resource;
locking->reset_locking = _reset_file_locking;
locking->fin_locking = _fin_file_locking;
- locking->flags = 0;
+ locking->flags = LCK_FLOCK;
/* Get lockfile directory from config file */
locking_dir = find_config_tree_str(cmd, global_locking_dir_CFG, NULL);
diff --git a/lib/locking/locking.c b/lib/locking/locking.c
index 4b7d7eb..4c27a81 100644
--- a/lib/locking/locking.c
+++ b/lib/locking/locking.c
@@ -34,6 +34,8 @@ static struct locking_type _locking;
static int _vg_lock_count = 0; /* Number of locks held */
static int _vg_write_lock_held = 0; /* VG write lock held? */
static int _blocking_supported = 0;
+static int _file_locking_readonly = 0;
+static int _file_locking_sysinit = 0;
static void _unblock_signals(void)
{
@@ -46,6 +48,10 @@ void reset_locking(void)
{
int was_locked = _vg_lock_count;
+ /* file locking disabled */
+ if (!_locking.flags)
+ return;
+
_vg_lock_count = 0;
_vg_write_lock_held = 0;
@@ -82,21 +88,19 @@ static void _update_vg_lock_count(const char *resource, uint32_t flags)
* Select a locking type
* type: locking type; if < 0, then read config tree value
*/
-int init_locking(int type, struct cmd_context *cmd, int suppress_messages)
+int init_locking(struct cmd_context *cmd, int file_locking_sysinit, int file_locking_readonly)
{
+ int suppress_messages = 0;
+
if (getenv("LVM_SUPPRESS_LOCKING_FAILURE_MESSAGES"))
suppress_messages = 1;
- if (type < 0)
- type = find_config_tree_int(cmd, global_locking_type_CFG, NULL);
+ if (file_locking_sysinit)
+ suppress_messages = 1;
_blocking_supported = find_config_tree_bool(cmd, global_wait_for_locks_CFG, NULL);
-
- if (type != 1)
- log_warn("WARNING: locking_type deprecated, using file locking.");
-
- if (type == 3)
- log_warn("WARNING: See lvmlockd(8) for information on using cluster/clvm VGs.");
+ _file_locking_readonly = file_locking_readonly;
+ _file_locking_sysinit = file_locking_sysinit;
log_very_verbose("%sFile-based locking selected.", _blocking_supported ? "" : "Non-blocking ");
@@ -108,6 +112,10 @@ int init_locking(int type, struct cmd_context *cmd, int suppress_messages)
void fin_locking(void)
{
+ /* file locking disabled */
+ if (!_locking.flags)
+ return;
+
_locking.fin_locking();
}
@@ -135,10 +143,30 @@ static int _lock_vol(struct cmd_context *cmd, const char *resource, uint32_t fla
goto out;
}
- if (cmd->metadata_read_only && lck_type == LCK_WRITE &&
+ if ((lck_type == LCK_WRITE) && (lck_scope == LCK_VG) && !(flags & LCK_CACHE) &&
strcmp(resource, VG_GLOBAL)) {
- log_error("Operation prohibited while global/metadata_read_only is set.");
- goto out;
+
+ /* read only locking set in lvm.conf metadata_read_only */
+
+ if (cmd->metadata_read_only) {
+ log_error("Operation prohibited while global/metadata_read_only is set.");
+ goto out;
+ }
+
+ /* read only locking set with option --readonly */
+
+ if (_file_locking_readonly) {
+ log_error("Read-only locking specified. Write locks are prohibited.");
+ goto out;
+ }
+
+ /* read only locking (except activation) set with option --sysinit */
+ /* FIXME: sysinit is intended to allow activation, add that exception here */
+
+ if (_file_locking_sysinit) {
+ log_error("Read-only sysinit locking specified. Write locks are prohibited.");
+ goto out;
+ }
}
if ((ret = _locking.lock_resource(cmd, resource, flags, NULL))) {
@@ -169,6 +197,10 @@ int lock_vol(struct cmd_context *cmd, const char *vol, uint32_t flags, const str
char resource[258] __attribute__((aligned(8)));
int lck_type = flags & LCK_TYPE_MASK;
+ /* file locking disabled */
+ if (!_locking.flags)
+ return 1;
+
if (flags == LCK_NONE) {
log_debug_locking(INTERNAL_ERROR "%s: LCK_NONE lock requested", vol);
return 1;
@@ -240,7 +272,7 @@ int vg_write_lock_held(void)
int locking_is_clustered(void)
{
- return (_locking.flags & LCK_CLUSTERED) ? 1 : 0;
+ return 0;
}
int sync_local_dev_names(struct cmd_context* cmd)
diff --git a/lib/locking/locking.h b/lib/locking/locking.h
index 6d7d8e8..422f1d8 100644
--- a/lib/locking/locking.h
+++ b/lib/locking/locking.h
@@ -21,7 +21,7 @@
struct logical_volume;
-int init_locking(int type, struct cmd_context *cmd, int suppress_messages);
+int init_locking(struct cmd_context *cmd, int suppress_messages, int only_read_locks);
void fin_locking(void);
void reset_locking(void);
int vg_write_lock_held(void);
diff --git a/lib/locking/locking_types.h b/lib/locking/locking_types.h
index 99aa964..5bb4fe4 100644
--- a/lib/locking/locking_types.h
+++ b/lib/locking/locking_types.h
@@ -23,12 +23,10 @@ typedef int (*query_resource_fn) (const char *resource, const char *node, int *m
typedef void (*fin_lock_fn) (void);
typedef void (*reset_lock_fn) (void);
-#define LCK_PRE_MEMLOCK 0x00000001 /* Is memlock() needed before calls? */
-#define LCK_CLUSTERED 0x00000002
-#define LCK_SUPPORTS_REMOTE_QUERIES 0x00000004
+#define LCK_FLOCK 0x00000001
struct locking_type {
- uint32_t flags;
+ uint32_t flags; /* 0 means file locking is disabled */
lock_resource_fn lock_resource;
query_resource_fn query_resource;
@@ -36,17 +34,5 @@ struct locking_type {
fin_lock_fn fin_locking;
};
-/*
- * Locking types
- */
-void init_no_locking(struct locking_type *locking, struct cmd_context *cmd,
- int suppress_messages);
-
-void init_dummy_locking(struct locking_type *locking, struct cmd_context *cmd,
- int suppress_messages);
-
-int init_readonly_locking(struct locking_type *locking, struct cmd_context *cmd,
- int suppress_messages);
-
int init_file_locking(struct locking_type *locking, struct cmd_context *cmd,
int suppress_messages);
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index 4f4e917..788f007 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -2734,6 +2734,9 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
const char *reason = NULL;
int ret = 0;
int locking_type;
+ int file_locking_disable = 0;
+ int file_locking_sysinit = 0;
+ int file_locking_readonly = 0;
int monitoring;
char *arg_new, *arg;
int i;
@@ -2908,34 +2911,31 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
goto out;
}
- if (_cmd_no_meta_proc(cmd))
- locking_type = 0;
- else if (arg_is_set(cmd, readonly_ARG)) {
- if (find_config_tree_bool(cmd, global_use_lvmlockd_CFG, NULL)) {
- /*
- * FIXME: we could use locking_type 5 here if that didn't
- * cause CLUSTERED to be set, which conflicts with using lvmlockd.
- */
- locking_type = 1;
- cmd->lockd_gl_disable = 1;
- cmd->lockd_vg_disable = 1;
- cmd->lockd_lv_disable = 1;
- } else {
- locking_type = 5;
- }
+ if (arg_is_set(cmd, nolocking_ARG) || _cmd_no_meta_proc(cmd))
+ file_locking_disable = 1;
- if (lvmetad_used()) {
- lvmetad_make_unused(cmd);
- log_verbose("Not using lvmetad because read-only is set.");
- }
- } else if (arg_is_set(cmd, nolocking_ARG))
- locking_type = 0;
- else
- locking_type = -1;
+ else if (arg_is_set(cmd, sysinit_ARG))
+ file_locking_sysinit = 1;
- if (!init_locking(locking_type, cmd, _cmd_no_meta_proc(cmd) || arg_is_set(cmd, sysinit_ARG))) {
- ret = ECMD_FAILED;
- goto_out;
+ else if (arg_is_set(cmd, readonly_ARG))
+ file_locking_readonly = 1;
+
+ locking_type = find_config_tree_int(cmd, global_locking_type_CFG, NULL);
+
+ if (locking_type == 3)
+ log_warn("WARNING: See lvmlockd(8) for information on using cluster/clvm VGs.");
+
+ if (locking_type != 1) {
+ log_warn("WARNING: locking_type deprecated, using file locking.");
+ locking_type = 1;
+ }
+
+ if (!file_locking_disable) {
+ /* Set up file locking */
+ if (!init_locking(cmd, file_locking_sysinit, file_locking_readonly)) {
+ ret = ECMD_FAILED;
+ goto_out;
+ }
}
if (!_cmd_no_meta_proc(cmd) && !_init_lvmlockd(cmd)) {
5 years, 10 months