thin: implement get_thin_device_id get_thin_device_id() returns the device_id of a locally activated thin logical volume. This function is used to check if a thin snapshot merge has completed. Signed-off-by: Mike Snitzer --- lib/metadata/thin_manip.c | 55 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) Index: lvm2/lib/metadata/thin_manip.c =================================================================== --- lvm2.orig/lib/metadata/thin_manip.c +++ lvm2/lib/metadata/thin_manip.c @@ -20,6 +20,7 @@ #include "lv_alloc.h" #include "defaults.h" #include "display.h" +#include "commands/toolcontext.h" /* * thin snapshots don't have intermediate snapshot segments, so we @@ -935,7 +936,57 @@ int vg_remove_pool_metadata_spare(struct */ int get_thin_device_id(struct logical_volume *lv, uint32_t *device_id) { - *device_id = find_merging_snapshot(lv)->device_id; + struct dm_task *dmt; + const char *uuid; + void *next = NULL; + uint64_t start, length; + char *target_type, *params; + char pool_dev[80], extra[80]; + int r; - return 1; + if (!lv_is_active_locally(lv)) { + log_error("LV is not active locally"); + return 0; + } + + if (!(dmt = dm_task_create(DM_DEVICE_TABLE))) { + log_error("Failed to create device-mapper task struct"); + return 0; + } + + if (!(uuid = build_dm_uuid(lv->vg->cmd->mem, lv->lvid.s, lv_layer(lv)))) + return_0; + + if (!dm_task_set_uuid(dmt, uuid)) + return_0; + + if (!(r = dm_task_run(dmt))) + goto_out; + + if (dm_get_next_target(dmt, next, &start, &length, + &target_type, ¶ms)) { + /* thin target is only ever in a singleton table */ + r = 0; + goto_out; + } + if (strncmp(target_type, "thin", 4)) { + r = 0; + goto_out; + } + + /* + * Get the device_id from @params: + * [] + */ + if (sscanf(params, "%s %u %s", pool_dev, device_id, extra) < 2) { + log_error("Invalid thin target table params: %s", params); + r = 0; + goto out; + } + + r = 1; +out: + dm_task_destroy(dmt); + + return r; }