diff options
author | David Teigland <teigland@redhat.com> | 2015-06-03 15:50:24 -0500 |
---|---|---|
committer | David Teigland <teigland@redhat.com> | 2015-06-08 11:50:40 -0500 |
commit | 25eb5ff4aa7cdde76c0655971221645618e4132b (patch) | |
tree | 9d22479765c90bce3f009fff443e1fdb504c4314 | |
parent | 0dde547e669239a7e034caaf519b7bd0236fd93a (diff) | |
download | lvm2-25eb5ff4aa7cdde76c0655971221645618e4132b.tar.gz |
lvmlockd: make sanlock lv like metadata spare lv
handle them similarly
-rw-r--r-- | lib/format_text/flags.c | 1 | ||||
-rw-r--r-- | lib/format_text/import_vsn1.c | 7 | ||||
-rw-r--r-- | lib/locking/lvmlockd.c | 96 | ||||
-rw-r--r-- | lib/locking/lvmlockd.h | 2 | ||||
-rw-r--r-- | lib/metadata/metadata-exported.h | 2 | ||||
-rw-r--r-- | lib/metadata/vg.h | 1 |
6 files changed, 31 insertions, 78 deletions
diff --git a/lib/format_text/flags.c b/lib/format_text/flags.c index bbd47c307..717ef65ab 100644 --- a/lib/format_text/flags.c +++ b/lib/format_text/flags.c @@ -67,6 +67,7 @@ static const struct flag _lv_flags[] = { {LV_NOSCAN, NULL, 0}, {LV_TEMPORARY, NULL, 0}, {POOL_METADATA_SPARE, NULL, 0}, + {LOCKD_SANLOCK_LV, NULL, 0}, {RAID, NULL, 0}, {RAID_META, NULL, 0}, {RAID_IMAGE, NULL, 0}, diff --git a/lib/format_text/import_vsn1.c b/lib/format_text/import_vsn1.c index 0483c8030..1946aedcb 100644 --- a/lib/format_text/import_vsn1.c +++ b/lib/format_text/import_vsn1.c @@ -20,6 +20,7 @@ #include "toolcontext.h" #include "lvmcache.h" #include "lvmetad.h" +#include "lvmlockd.h" #include "lv_alloc.h" #include "pv_alloc.h" #include "segtype.h" @@ -653,6 +654,12 @@ static int _read_lvnames(struct format_instance *fid __attribute__((unused)), vg->pool_metadata_spare_lv = lv; } + if (!lv_is_visible(lv) && !strcmp(lv->name, LOCKD_SANLOCK_LV_NAME)) { + log_debug_metadata("Logical volume %s is sanlock lv.", lv->name); + lv->status |= LOCKD_SANLOCK_LV; + vg->sanlock_lv = lv; + } + return 1; } diff --git a/lib/locking/lvmlockd.c b/lib/locking/lvmlockd.c index d40f1576b..85e002db5 100644 --- a/lib/locking/lvmlockd.c +++ b/lib/locking/lvmlockd.c @@ -319,28 +319,6 @@ static int _lockd_request(struct cmd_context *cmd, } /* - * The name of the internal lv created to hold sanlock locks. - */ -#define LVMLOCKD_SANLOCK_LV_NAME "lvmlock" - -/* - * The internal sanlock lv starts at 512MB and is increased by that amount - * whenever it runs out of space. - */ - -static struct logical_volume *_find_sanlock_lv(struct volume_group *vg, - const char *lock_lv_name) -{ - struct lv_list *lvl; - - dm_list_iterate_items(lvl, &vg->lvs) { - if (!strcmp(lvl->lv->name, lock_lv_name)) - return lvl->lv; - } - return NULL; -} - -/* * Eventually add an option to specify which pv the lvmlock lv should be placed on. */ @@ -375,22 +353,16 @@ static int _create_sanlock_lv(struct cmd_context *cmd, struct volume_group *vg, } lv_set_hidden(lv); + lv->status |= LOCKD_SANLOCK_LV; + vg->sanlock_lv = lv; return 1; } -static int _remove_sanlock_lv(struct cmd_context *cmd, struct volume_group *vg, - const char *lock_lv_name) +static int _remove_sanlock_lv(struct cmd_context *cmd, struct volume_group *vg) { - struct logical_volume *lv; - - if (!(lv = _find_sanlock_lv(vg, lock_lv_name))) { - log_error("Failed to find sanlock LV %s in VG %s", lock_lv_name, vg->name); - return 0; - } - - if (!lv_remove(lv)) { - log_error("Failed to remove sanlock LV %s/%s", vg->name, lock_lv_name); + if (!lv_remove(vg->sanlock_lv)) { + log_error("Failed to remove sanlock LV %s/%s", vg->name, vg->sanlock_lv->name); return 0; } @@ -399,10 +371,9 @@ static int _remove_sanlock_lv(struct cmd_context *cmd, struct volume_group *vg, static int _extend_sanlock_lv(struct cmd_context *cmd, struct volume_group *vg, int extend_mb) { - const char *lock_lv_name = LVMLOCKD_SANLOCK_LV_NAME; - struct logical_volume *lv; + struct logical_volume *lv = vg->sanlock_lv; struct lvresize_params lp = { - .lv_name = lock_lv_name, + .lv_name = vg->sanlock_lv->name, .sign = SIGN_NONE, .percent = PERCENT_NONE, .resize = LV_EXTEND, @@ -410,11 +381,6 @@ static int _extend_sanlock_lv(struct cmd_context *cmd, struct volume_group *vg, .sizeargs = 1, }; - if (!(lv = _find_sanlock_lv(vg, lock_lv_name))) { - log_error("Extend failed to find sanlock LV %s in VG %s", lock_lv_name, vg->name); - return 0; - } - lp.size = lv->size + ((extend_mb * 1024 * 1024) / SECTOR_SIZE); if (!lv_resize_prepare(cmd, lv, &lp, &vg->pvs) || @@ -431,16 +397,8 @@ static int _extend_sanlock_lv(struct cmd_context *cmd, struct volume_group *vg, static int _refresh_sanlock_lv(struct cmd_context *cmd, struct volume_group *vg) { - struct logical_volume *lv; - const char *lock_lv_name = LVMLOCKD_SANLOCK_LV_NAME; - - if (!(lv = _find_sanlock_lv(vg, lock_lv_name))) { - log_error("Refresh failed to find sanlock lv %s in vg %s", lock_lv_name, vg->name); - return 0; - } - - if (!lv_refresh_suspend_resume(cmd, lv)) { - log_error("Failed to refresh %s.", lv->name); + if (!lv_refresh_suspend_resume(cmd, vg->sanlock_lv)) { + log_error("Failed to refresh %s.", vg->sanlock_lv->name); return 0; } @@ -507,16 +465,8 @@ int handle_sanlock_lv(struct cmd_context *cmd, struct volume_group *vg) static int _activate_sanlock_lv(struct cmd_context *cmd, struct volume_group *vg) { - struct logical_volume *lv; - const char *lock_lv_name = LVMLOCKD_SANLOCK_LV_NAME; - - if (!(lv = _find_sanlock_lv(vg, lock_lv_name))) { - log_error("Failed to find sanlock lv %s in vg %s", lock_lv_name, vg->name); - return 0; - } - - if (!activate_lv(cmd, lv)) { - log_error("Failed to activate sanlock lv %s/%s", vg->name, lock_lv_name); + if (!activate_lv(cmd, vg->sanlock_lv)) { + log_error("Failed to activate sanlock lv %s/%s", vg->name, vg->sanlock_lv->name); return 0; } @@ -525,16 +475,8 @@ static int _activate_sanlock_lv(struct cmd_context *cmd, struct volume_group *vg static int _deactivate_sanlock_lv(struct cmd_context *cmd, struct volume_group *vg) { - struct logical_volume *lv; - const char *lock_lv_name = LVMLOCKD_SANLOCK_LV_NAME; - - if (!(lv = _find_sanlock_lv(vg, lock_lv_name))) { - log_error("Failed to find sanlock lv %s in vg %s", lock_lv_name, vg->name); - return 0; - } - - if (!deactivate_lv(cmd, lv)) { - log_error("Failed to deactivate sanlock lv %s/%s", vg->name, lock_lv_name); + if (!deactivate_lv(cmd, vg->sanlock_lv)) { + log_error("Failed to deactivate sanlock lv %s/%s", vg->name, vg->sanlock_lv->name); return 0; } @@ -618,7 +560,6 @@ static int _init_vg_sanlock(struct cmd_context *cmd, struct volume_group *vg) daemon_reply reply; const char *reply_str; const char *vg_lock_args = NULL; - const char *lock_lv_name = LVMLOCKD_SANLOCK_LV_NAME; const char *opts = NULL; int extend_mb; int result; @@ -638,13 +579,13 @@ static int _init_vg_sanlock(struct cmd_context *cmd, struct volume_group *vg) if (!(extend_mb = find_config_tree_int(cmd, global_sanlock_lv_extend_CFG, NULL))) extend_mb = DEFAULT_SANLOCK_LV_EXTEND_MB; - if (!_create_sanlock_lv(cmd, vg, lock_lv_name, extend_mb)) { + if (!_create_sanlock_lv(cmd, vg, LOCKD_SANLOCK_LV_NAME, extend_mb)) { log_error("Failed to create internal lv."); return 0; } /* - * N.B. this passes the lock_lv_name as vg_lock_args + * N.B. this passes the sanlock lv name as vg_lock_args * even though it is only part of the final args string * which will be returned from lvmlockd. */ @@ -653,7 +594,7 @@ static int _init_vg_sanlock(struct cmd_context *cmd, struct volume_group *vg) "pid = %d", getpid(), "vg_name = %s", vg->name, "vg_lock_type = %s", "sanlock", - "vg_lock_args = %s", lock_lv_name, + "vg_lock_args = %s", vg->sanlock_lv->name, "opts = %s", opts ?: "none", NULL); @@ -716,7 +657,7 @@ out: */ usleep(1000000); _deactivate_sanlock_lv(cmd, vg); - _remove_sanlock_lv(cmd, vg, lock_lv_name); + _remove_sanlock_lv(cmd, vg); if (!vg_write(vg) || !vg_commit(vg)) stack; } @@ -760,7 +701,6 @@ static int _free_vg_dlm(struct cmd_context *cmd, struct volume_group *vg) static int _free_vg_sanlock(struct cmd_context *cmd, struct volume_group *vg) { daemon_reply reply; - const char *lock_lv_name = LVMLOCKD_SANLOCK_LV_NAME; int result; int ret; @@ -810,7 +750,7 @@ static int _free_vg_sanlock(struct cmd_context *cmd, struct volume_group *vg) usleep(1000000); _deactivate_sanlock_lv(cmd, vg); - _remove_sanlock_lv(cmd, vg, lock_lv_name); + _remove_sanlock_lv(cmd, vg); out: daemon_reply_destroy(reply); diff --git a/lib/locking/lvmlockd.h b/lib/locking/lvmlockd.h index 88d4d49dd..bfd9cbe34 100644 --- a/lib/locking/lvmlockd.h +++ b/lib/locking/lvmlockd.h @@ -14,6 +14,8 @@ #include "config-util.h" #include "daemon-client.h" +#define LOCKD_SANLOCK_LV_NAME "lvmlock" + #define LOCK_TYPE_NONE 0 #define LOCK_TYPE_CLVM 1 #define LOCK_TYPE_DLM 2 diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h index 1fc46662c..a4df33c0e 100644 --- a/lib/metadata/metadata-exported.h +++ b/lib/metadata/metadata-exported.h @@ -101,6 +101,7 @@ #define THIN_POOL_DATA UINT64_C(0x0000004000000000) /* LV - Internal use only */ #define THIN_POOL_METADATA UINT64_C(0x0000008000000000) /* LV - Internal use only */ #define POOL_METADATA_SPARE UINT64_C(0x0000010000000000) /* LV - Internal use only */ +#define LOCKD_SANLOCK_LV UINT64_C(0x0000020000000000) /* LV - Internal use only */ #define LV_WRITEMOSTLY UINT64_C(0x0000020000000000) /* LV (RAID1) */ @@ -228,6 +229,7 @@ #define lv_is_pool_data(lv) (((lv)->status & (CACHE_POOL_DATA | THIN_POOL_DATA)) ? 1 : 0) #define lv_is_pool_metadata(lv) (((lv)->status & (CACHE_POOL_METADATA | THIN_POOL_METADATA)) ? 1 : 0) #define lv_is_pool_metadata_spare(lv) (((lv)->status & POOL_METADATA_SPARE) ? 1 : 0) +#define lv_is_lockd_sanlock_lv(lv) (((lv)->status & LOCKD_SANLOCK_LV) ? 1 : 0) #define lv_is_rlog(lv) (((lv)->status & REPLICATOR_LOG) ? 1 : 0) diff --git a/lib/metadata/vg.h b/lib/metadata/vg.h index 27b50110d..85f449932 100644 --- a/lib/metadata/vg.h +++ b/lib/metadata/vg.h @@ -141,6 +141,7 @@ struct volume_group { struct dm_hash_table *hostnames; /* map of creation hostnames */ struct logical_volume *pool_metadata_spare_lv; /* one per VG */ + struct logical_volume *sanlock_lv; /* one per VG */ }; struct volume_group *alloc_vg(const char *pool_name, struct cmd_context *cmd, |