diff --git a/tools/toollib.c b/tools/toollib.c index 807e34c33..0b8823bce 100644 --- a/tools/toollib.c +++ b/tools/toollib.c @@ -3009,6 +3009,7 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg, log_report_t saved_log_report_state = log_get_report_state(); char lv_uuid[64] __attribute__((aligned(8))); char vg_uuid[64] __attribute__((aligned(8))); + struct lvinfo lvinfo; int ret_max = ECMD_PROCESSED; int ret = 0; int whole_selected = 0; @@ -3025,6 +3026,8 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg, struct lv_list *final_lvl; struct dm_list found_arg_lvnames; struct glv_list *glvl, *tglvl; + struct device *dev; + dev_t devt; int do_report_ret_code = 1; log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_LV); @@ -3162,6 +3165,18 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg, } log_set_report_object_name_and_id(NULL, NULL); + /* + * If a PV is stacked on an LV, then the LV is kept open + * in bcache, and needs to be closed so the open fd doesn't + * interfere with processing the LV. + */ + dm_list_iterate_items(lvl, &final_lvs) { + lv_info(cmd, lvl->lv, 0, &lvinfo, 0, 0); + devt = MKDEV(lvinfo.major, lvinfo.minor); + if ((dev = dev_cache_get_by_devt(devt, cmd->filter))) + label_scan_invalidate(dev); + } + dm_list_iterate_items(lvl, &final_lvs) { lv_uuid[0] = '\0'; if (!id_write_format(&lvl->lv->lvid.id[1], lv_uuid, sizeof(lv_uuid)))