From: Milan Broz Date: Wed, 20 May 2009 12:58:03 +0000 (+0000) Subject: Fix locking query compatibility with old external locking libraries. X-Git-Tag: old-v2_02_46~3 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=03d4efc5c06e6ca4a03d2c63b72f37bdf5be1919;p=lvm2.git Fix locking query compatibility with old external locking libraries. --- diff --git a/lib/activate/activate.c b/lib/activate/activate.c index 9619f7adc..efc3b61bc 100644 --- a/lib/activate/activate.c +++ b/lib/activate/activate.c @@ -694,13 +694,30 @@ int lvs_in_vg_opened(const struct volume_group *vg) */ int lv_is_active(struct logical_volume *lv) { + int ret; + if (_lv_active(lv->vg->cmd, lv, 0)) return 1; if (!vg_is_clustered(lv->vg)) return 0; - return remote_lock_held(lv->lvid.s); + if ((ret = remote_lock_held(lv->lvid.s)) >= 0) + return ret; + + /* + * Old compatibility code if locking doesn't support lock query + * FIXME: check status to not deactivate already activate device + */ + if (activate_lv_excl(lv->vg->cmd, lv)) { + deactivate_lv(lv->vg->cmd, lv); + return 0; + } + + /* + * Exclusive local activation failed so assume it is active elsewhere. + */ + return 1; } /* diff --git a/lib/locking/.exported_symbols b/lib/locking/.exported_symbols index 757a082ed..ec92d131f 100644 --- a/lib/locking/.exported_symbols +++ b/lib/locking/.exported_symbols @@ -1,4 +1,5 @@ locking_init locking_end lock_resource +lock_resource_query reset_locking diff --git a/lib/locking/external_locking.c b/lib/locking/external_locking.c index 1bff650d6..73cb15269 100644 --- a/lib/locking/external_locking.c +++ b/lib/locking/external_locking.c @@ -26,6 +26,7 @@ static int (*_lock_fn) (struct cmd_context * cmd, const char *resource, uint32_t flags) = NULL; static int (*_init_fn) (int type, struct config_tree * cft, uint32_t *flags) = NULL; +static int (*_lock_query_fn) (const char *resource, int *mode) = NULL; static int _lock_resource(struct cmd_context *cmd, const char *resource, uint32_t flags) @@ -88,6 +89,10 @@ int init_external_locking(struct locking_type *locking, struct cmd_context *cmd) return 0; } + if (!(_lock_query_fn = dlsym(_locking_lib, "lock_resource_query"))) + log_warn("WARNING: %s: _lock_resource_query() missing: " + "Using inferior activation method.", libname); + log_verbose("Loaded external locking library %s", libname); return _init_fn(2, cmd->cft, &locking->flags); } diff --git a/lib/locking/locking.c b/lib/locking/locking.c index d57726dab..d711a767b 100644 --- a/lib/locking/locking.c +++ b/lib/locking/locking.c @@ -489,11 +489,13 @@ int remote_lock_held(const char *vol) if (!locking_is_clustered()) return 0; + if (!_locking.lock_resource_query) + return -1; + /* * If an error occured, expect that volume is active */ - if (!_locking.lock_resource_query || - !_locking.lock_resource_query(vol, &mode)) { + if (!_locking.lock_resource_query(vol, &mode)) { stack; return 1; }