You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

283 lines
11 KiB

lib/activate/activate.c | 40 +++++++++++++++++++++++++---------------
lib/activate/activate.h | 2 ++
lib/activate/dev_manager.c | 28 +++++++++++++++++++---------
lib/activate/dev_manager.h | 2 +-
4 files changed, 47 insertions(+), 25 deletions(-)
diff --git a/lib/activate/activate.c b/lib/activate/activate.c
index aba5d14..c395d58 100644
--- a/lib/activate/activate.c
+++ b/lib/activate/activate.c
@@ -671,7 +671,7 @@ static int _lv_info(struct cmd_context *cmd, const struct logical_volume *lv,
int use_layer, struct lvinfo *info,
const struct lv_segment *seg,
struct lv_seg_status *seg_status,
- int with_open_count, int with_read_ahead)
+ int with_open_count, int with_read_ahead, int with_name_check)
{
struct dm_info dminfo;
@@ -691,7 +691,7 @@ static int _lv_info(struct cmd_context *cmd, const struct logical_volume *lv,
/* New thin-pool has no layer, but -tpool suffix needs to be queried */
if (!use_layer && lv_is_new_thin_pool(lv)) {
/* Check if there isn't existing old thin pool mapping in the table */
- if (!dev_manager_info(cmd, lv, NULL, 0, 0, &dminfo, NULL, NULL))
+ if (!dev_manager_info(cmd, lv, NULL, 0, 0, 0, &dminfo, NULL, NULL))
return_0;
if (!dminfo.exists)
use_layer = 1;
@@ -704,8 +704,9 @@ static int _lv_info(struct cmd_context *cmd, const struct logical_volume *lv,
if (!dev_manager_info(cmd, lv,
(use_layer) ? lv_layer(lv) : NULL,
- with_open_count, with_read_ahead,
- &dminfo, (info) ? &info->read_ahead : NULL,
+ with_open_count, with_read_ahead, with_name_check,
+ &dminfo,
+ (info) ? &info->read_ahead : NULL,
seg_status))
return_0;
@@ -734,7 +735,7 @@ int lv_info(struct cmd_context *cmd, const struct logical_volume *lv, int use_la
if (!activation())
return 0;
- return _lv_info(cmd, lv, use_layer, info, NULL, NULL, with_open_count, with_read_ahead);
+ return _lv_info(cmd, lv, use_layer, info, NULL, NULL, with_open_count, with_read_ahead, 0);
}
int lv_info_by_lvid(struct cmd_context *cmd, const char *lvid_s, int use_layer,
@@ -752,6 +753,15 @@ int lv_info_by_lvid(struct cmd_context *cmd, const char *lvid_s, int use_layer,
return r;
}
+int lv_info_with_name_check(struct cmd_context *cmd, const struct logical_volume *lv,
+ int use_layer, struct lvinfo *info)
+{
+ if (!activation())
+ return 0;
+
+ return _lv_info(cmd, lv, use_layer, info, NULL, NULL, 0, 0, 1);
+}
+
/*
* Returns 1 if lv_with_info_and_seg_status info structure populated,
* else 0 on failure or if device not active locally.
@@ -779,16 +789,16 @@ int lv_info_with_seg_status(struct cmd_context *cmd,
* STATUS is collected from cache LV */
if (!(lv_seg = get_only_segment_using_this_lv(lv)))
return_0;
- (void) _lv_info(cmd, lv_seg->lv, 1, NULL, lv_seg, &status->seg_status, 0, 0);
+ (void) _lv_info(cmd, lv_seg->lv, 1, NULL, lv_seg, &status->seg_status, 0, 0, 0);
return 1;
}
if (lv_is_thin_pool(lv)) {
/* Always collect status for '-tpool' */
- if (_lv_info(cmd, lv, 1, &status->info, lv_seg, &status->seg_status, 0, 0) &&
+ if (_lv_info(cmd, lv, 1, &status->info, lv_seg, &status->seg_status, 0, 0, 0) &&
(status->seg_status.type == SEG_STATUS_THIN_POOL)) {
/* There is -tpool device, but query 'active' state of 'fake' thin-pool */
- if (!_lv_info(cmd, lv, 0, NULL, NULL, NULL, 0, 0) &&
+ if (!_lv_info(cmd, lv, 0, NULL, NULL, NULL, 0, 0, 0) &&
!status->seg_status.thin_pool->needs_check)
status->info.exists = 0; /* So pool LV is not active */
}
@@ -797,10 +807,10 @@ int lv_info_with_seg_status(struct cmd_context *cmd,
if (lv_is_external_origin(lv)) {
if (!_lv_info(cmd, lv, 0, &status->info, NULL, NULL,
- with_open_count, with_read_ahead))
+ with_open_count, with_read_ahead, 0))
return_0;
- (void) _lv_info(cmd, lv, 1, NULL, lv_seg, &status->seg_status, 0, 0);
+ (void) _lv_info(cmd, lv, 1, NULL, lv_seg, &status->seg_status, 0, 0, 0);
return 1;
}
@@ -813,13 +823,13 @@ int lv_info_with_seg_status(struct cmd_context *cmd,
/* Show INFO for actual origin and grab status for merging origin */
if (!_lv_info(cmd, lv, 0, &status->info, lv_seg,
lv_is_merging_origin(lv) ? &status->seg_status : NULL,
- with_open_count, with_read_ahead))
+ with_open_count, with_read_ahead, 0))
return_0;
if (status->info.exists &&
(status->seg_status.type != SEG_STATUS_SNAPSHOT)) /* Not merging */
/* Grab STATUS from layered -real */
- (void) _lv_info(cmd, lv, 1, NULL, lv_seg, &status->seg_status, 0, 0);
+ (void) _lv_info(cmd, lv, 1, NULL, lv_seg, &status->seg_status, 0, 0, 0);
return 1;
}
@@ -828,7 +838,7 @@ int lv_info_with_seg_status(struct cmd_context *cmd,
olv = origin_from_cow(lv);
if (!_lv_info(cmd, olv, 0, &status->info, first_seg(olv), &status->seg_status,
- with_open_count, with_read_ahead))
+ with_open_count, with_read_ahead, 0))
return_0;
if (status->seg_status.type == SEG_STATUS_SNAPSHOT ||
@@ -849,7 +859,7 @@ int lv_info_with_seg_status(struct cmd_context *cmd,
}
return _lv_info(cmd, lv, 0, &status->info, lv_seg, &status->seg_status,
- with_open_count, with_read_ahead);
+ with_open_count, with_read_ahead, 0);
}
#define OPEN_COUNT_CHECK_RETRIES 25
@@ -2834,7 +2844,7 @@ static int _lv_activate(struct cmd_context *cmd, const char *lvid_s,
laopts->noscan ? " noscan" : "",
laopts->temporary ? " temporary" : "");
- if (!lv_info(cmd, lv, 0, &info, 0, 0))
+ if (!lv_info_with_name_check(cmd, lv, 0, &info))
goto_out;
/*
diff --git a/lib/activate/activate.h b/lib/activate/activate.h
index 43d26d1..a938cb4 100644
--- a/lib/activate/activate.h
+++ b/lib/activate/activate.h
@@ -135,6 +135,8 @@ int lv_info(struct cmd_context *cmd, const struct logical_volume *lv, int use_la
struct lvinfo *info, int with_open_count, int with_read_ahead);
int lv_info_by_lvid(struct cmd_context *cmd, const char *lvid_s, int use_layer,
struct lvinfo *info, int with_open_count, int with_read_ahead);
+int lv_info_with_name_check(struct cmd_context *cmd, const struct logical_volume *lv,
+ int use_layer, struct lvinfo *info);
/*
* Returns 1 if lv_info_and_seg_status structure has been populated,
diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c
index a5e026c..1ca97c1 100644
--- a/lib/activate/dev_manager.c
+++ b/lib/activate/dev_manager.c
@@ -239,6 +239,7 @@ static uint32_t _seg_len(const struct lv_segment *seg)
static int _info_run(const char *dlid, struct dm_info *dminfo,
uint32_t *read_ahead,
struct lv_seg_status *seg_status,
+ const char *name_check,
int with_open_count, int with_read_ahead,
uint32_t major, uint32_t minor)
{
@@ -249,6 +250,7 @@ static int _info_run(const char *dlid, struct dm_info *dminfo,
void *target = NULL;
uint64_t target_start, target_length, start, length;
char *target_name, *target_params;
+ const char *dev_name;
if (seg_status) {
dmtask = DM_DEVICE_STATUS;
@@ -262,6 +264,11 @@ static int _info_run(const char *dlid, struct dm_info *dminfo,
with_open_count, with_flush, 0)))
return_0;
+ if (name_check && dminfo->exists &&
+ (dev_name = dm_task_get_name(dmt)) &&
+ (strcmp(name_check, dev_name) != 0))
+ dminfo->exists = 0; /* mismatching name -> device does not exist */
+
if (with_read_ahead && dminfo->exists) {
if (!dm_task_get_read_ahead(dmt, read_ahead))
goto_out;
@@ -777,18 +784,19 @@ static int _original_uuid_format_check_required(struct cmd_context *cmd)
static int _info(struct cmd_context *cmd,
const char *name, const char *dlid,
- int with_open_count, int with_read_ahead,
+ int with_open_count, int with_read_ahead, int with_name_check,
struct dm_info *dminfo, uint32_t *read_ahead,
struct lv_seg_status *seg_status)
{
char old_style_dlid[sizeof(UUID_PREFIX) + 2 * ID_LEN];
const char *suffix, *suffix_position;
+ const char *name_check = (with_name_check) ? name : NULL;
unsigned i = 0;
log_debug_activation("Getting device info for %s [%s].", name, dlid);
/* Check for dlid */
- if (!_info_run(dlid, dminfo, read_ahead, seg_status,
+ if (!_info_run(dlid, dminfo, read_ahead, seg_status, name_check,
with_open_count, with_read_ahead, 0, 0))
return_0;
@@ -804,7 +812,8 @@ static int _info(struct cmd_context *cmd,
(void) strncpy(old_style_dlid, dlid, sizeof(old_style_dlid));
old_style_dlid[sizeof(old_style_dlid) - 1] = '\0';
if (!_info_run(old_style_dlid, dminfo, read_ahead, seg_status,
- with_open_count, with_read_ahead, 0, 0))
+ name_check, with_open_count, with_read_ahead,
+ 0, 0))
return_0;
if (dminfo->exists)
return 1;
@@ -817,7 +826,7 @@ static int _info(struct cmd_context *cmd,
/* Check for dlid before UUID_PREFIX was added */
if (!_info_run(dlid + sizeof(UUID_PREFIX) - 1, dminfo, read_ahead, seg_status,
- with_open_count, with_read_ahead, 0, 0))
+ name_check, with_open_count, with_read_ahead, 0, 0))
return_0;
return 1;
@@ -825,12 +834,12 @@ static int _info(struct cmd_context *cmd,
static int _info_by_dev(uint32_t major, uint32_t minor, struct dm_info *info)
{
- return _info_run(NULL, info, NULL, 0, 0, 0, major, minor);
+ return _info_run(NULL, info, NULL, NULL, NULL, 0, 0, major, minor);
}
int dev_manager_info(struct cmd_context *cmd,
const struct logical_volume *lv, const char *layer,
- int with_open_count, int with_read_ahead,
+ int with_open_count, int with_read_ahead, int with_name_check,
struct dm_info *dminfo, uint32_t *read_ahead,
struct lv_seg_status *seg_status)
{
@@ -843,7 +852,8 @@ int dev_manager_info(struct cmd_context *cmd,
if (!(dlid = build_dm_uuid(cmd->mem, lv, layer)))
goto_out;
- if (!(r = _info(cmd, name, dlid, with_open_count, with_read_ahead,
+ if (!(r = _info(cmd, name, dlid,
+ with_open_count, with_read_ahead, with_name_check,
dminfo, read_ahead, seg_status)))
stack;
out:
@@ -1953,7 +1963,7 @@ static int _add_dev_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,
if (!(dlid = build_dm_uuid(dm->track_pending_delete ? dm->cmd->pending_delete_mem : dm->mem, lv, layer)))
return_0;
- if (!_info(dm->cmd, name, dlid, 1, 0, &info, NULL, NULL))
+ if (!_info(dm->cmd, name, dlid, 1, 0, 0, &info, NULL, NULL))
return_0;
/*
@@ -2479,7 +2489,7 @@ static char *_add_error_or_zero_device(struct dev_manager *dm, struct dm_tree *d
seg->lv->name, errid)))
return_NULL;
- if (!_info(dm->cmd, name, dlid, 1, 0, &info, NULL, NULL))
+ if (!_info(dm->cmd, name, dlid, 1, 0, 0, &info, NULL, NULL))
return_NULL;
if (!info.exists) {
diff --git a/lib/activate/dev_manager.h b/lib/activate/dev_manager.h
index 5be417b..20b6a26 100644
--- a/lib/activate/dev_manager.h
+++ b/lib/activate/dev_manager.h
@@ -47,7 +47,7 @@ void dev_manager_exit(void);
*/
int dev_manager_info(struct cmd_context *cmd, const struct logical_volume *lv,
const char *layer,
- int with_open_count, int with_read_ahead,
+ int with_open_count, int with_read_ahead, int with_name_check,
struct dm_info *dminfo, uint32_t *read_ahead,
struct lv_seg_status *seg_status);