From 98fd1ce3327acde7f49c0e39426c6eeb40249f33 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Fri, 9 May 2008 18:45:15 +0000 Subject: [PATCH] More P_ and V_ lock cleanup. --- WHATS_NEW | 1 + daemons/clvmd/clvmd-command.c | 12 ++++++------ daemons/clvmd/lvm-functions.c | 3 ++- lib/cache/lvmcache.c | 3 +++ lib/locking/cluster_locking.c | 9 ++++----- lib/locking/file_locking.c | 5 +---- lib/locking/locking.c | 10 ++++++++++ 7 files changed, 27 insertions(+), 16 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index 14864bc4d..5ea507855 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -6,6 +6,7 @@ Version 2.02.38 - Version 2.02.37 - ================================= + Add assertions to trap deprecated P_ and V_ lock usage. Add missing mutex around clvmd lvmcache_drop_metadata library call. Fix uninitialised mutex in clvmd if all daemons are not running at startup. Avoid using DLM locks with LCK_CACHE type P_ lock requests. diff --git a/daemons/clvmd/clvmd-command.c b/daemons/clvmd/clvmd-command.c index 8e544e901..3b1379fee 100644 --- a/daemons/clvmd/clvmd-command.c +++ b/daemons/clvmd/clvmd-command.c @@ -118,10 +118,10 @@ int do_command(struct local_client *client, struct clvm_header *msg, int msglen, lockname = &args[2]; /* Check to see if the VG is in use by LVM1 */ status = do_check_lvm1(lockname); - /* P_#global causes a cache refresh */ - if (strcmp(lockname, "P_#global") == 0) - do_refresh_cache(); - else if (strncmp(lockname, "P_", 2) == 0) + /* P_#global causes a full cache refresh */ + if (!strcmp(lockname, "P_#global")) + do_refresh_cache(); + else drop_metadata(lockname + 2); break; @@ -254,9 +254,9 @@ int do_pre_command(struct local_client *client) case CLVMD_CMD_LOCK_VG: lockname = &args[2]; - /* Do not use lock for cache related commands */ + /* We take out a real lock unless LCK_CACHE was set */ if (!strncmp(lockname, "V_", 2) || - !strcmp(lockname, "P_#global")) + !strncmp(lockname, "P_#", 3)) status = lock_vg(client); break; diff --git a/daemons/clvmd/lvm-functions.c b/daemons/clvmd/lvm-functions.c index 08c370bea..84e0aa5df 100644 --- a/daemons/clvmd/lvm-functions.c +++ b/daemons/clvmd/lvm-functions.c @@ -472,7 +472,8 @@ static void drop_vg_locks() popen ("lvm pvs --config 'log{command_names=0 prefix=\"\"}' --nolocking --noheadings -o vg_name", "r"); - sync_unlock("P_orphans", LCK_EXCL); + sync_unlock("P_#orphans", LCK_EXCL); + sync_unlock("P_#global", LCK_EXCL); if (!vgs) return; diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c index bc0b3d32f..62aaf79f8 100644 --- a/lib/cache/lvmcache.c +++ b/lib/cache/lvmcache.c @@ -162,6 +162,9 @@ void lvmcache_drop_metadata(const char *vgname) _drop_metadata(FMT_TEXT_ORPHAN_VG_NAME); _drop_metadata(FMT_LVM1_ORPHAN_VG_NAME); _drop_metadata(FMT_POOL_ORPHAN_VG_NAME); + + /* Indicate that PVs could now be missing from the cache */ + init_full_scan_done(0); } else _drop_metadata(vgname); } diff --git a/lib/locking/cluster_locking.c b/lib/locking/cluster_locking.c index 20ba6ad9e..3cbc9de9e 100644 --- a/lib/locking/cluster_locking.c +++ b/lib/locking/cluster_locking.c @@ -387,13 +387,12 @@ int lock_resource(struct cmd_context *cmd, const char *resource, uint32_t flags) switch (flags & LCK_SCOPE_MASK) { case LCK_VG: /* If the VG name is empty then lock the unused PVs */ - if (!*resource) /* FIXME Deprecated */ - dm_snprintf(lockname, sizeof(lockname), "P_orphans"); - else if (*resource == '#' || (flags & LCK_CACHE)) - dm_snprintf(lockname, sizeof(lockname), "P_%s", resource); + if (*resource == '#' || (flags & LCK_CACHE)) + dm_snprintf(lockname, sizeof(lockname), "P_%s", + resource); else dm_snprintf(lockname, sizeof(lockname), "V_%s", - resource); + resource); lock_scope = "VG"; cluster_cmd = CLVMD_CMD_LOCK_VG; diff --git a/lib/locking/file_locking.c b/lib/locking/file_locking.c index b162a58c3..ec7417ac7 100644 --- a/lib/locking/file_locking.c +++ b/lib/locking/file_locking.c @@ -214,10 +214,7 @@ static int _file_lock_resource(struct cmd_context *cmd, const char *resource, lvmcache_drop_metadata(resource); break; } - if (!*resource) /* FIXME Deprecated */ - dm_snprintf(lockfile, sizeof(lockfile), - "%s/P_orphans", _lock_dir); - else if (*resource == '#') + if (*resource == '#') dm_snprintf(lockfile, sizeof(lockfile), "%s/P_%s", _lock_dir, resource + 1); else diff --git a/lib/locking/locking.c b/lib/locking/locking.c index 6a1f92d0a..411b4a380 100644 --- a/lib/locking/locking.c +++ b/lib/locking/locking.c @@ -323,6 +323,16 @@ static int _lock_vol(struct cmd_context *cmd, const char *resource, uint32_t fla assert(resource); + if (!*resource) { + log_error("Internal error: Use of P_orphans is deprecated."); + return 0; + } + + if (*resource == '#' && (flags & LCK_CACHE)) { + log_error("Internal error: P_%s referenced", resource); + return 0; + } + if ((ret = _locking.lock_resource(cmd, resource, flags))) { if ((flags & LCK_SCOPE_MASK) == LCK_VG && !(flags & LCK_CACHE)) {