Display status percentage. Display percentage of space usage for shared snapshots. Display 'I' and 'S' for invalidated snapshots. Signed-off-by: Mikulas Patocka --- lib/activate/dev_manager.c | 4 +++- lib/multisnapshot/multisnapshot.c | 25 ++++++++++++++++++++++++- lib/report/report.c | 24 +++++++++++++++++++++--- 3 files changed, 48 insertions(+), 5 deletions(-) Index: LVM2.2.02.53/lib/activate/dev_manager.c =================================================================== --- LVM2.2.02.53.orig/lib/activate/dev_manager.c 2009-10-14 01:58:26.000000000 +0200 +++ LVM2.2.02.53/lib/activate/dev_manager.c 2009-10-14 02:06:25.000000000 +0200 @@ -513,7 +513,9 @@ int dev_manager_snapshot_percent(struct * Try and get some info on this device. */ log_debug("Getting device status percentage for %s", name); - if (!(r = _percent(dm, name, dlid, "snapshot", 0, NULL, percent, NULL))) + if (!(r = _percent(dm, name, dlid, + lv_is_multisnap_origin(lv) ? "multisnapshot" : "snapshot", + 0, NULL, percent, NULL))) return_0; /* FIXME dm_pool_free ? */ Index: LVM2.2.02.53/lib/multisnapshot/multisnapshot.c =================================================================== --- LVM2.2.02.53.orig/lib/multisnapshot/multisnapshot.c 2009-10-14 01:57:28.000000000 +0200 +++ LVM2.2.02.53/lib/multisnapshot/multisnapshot.c 2009-10-14 02:22:38.000000000 +0200 @@ -167,7 +167,30 @@ static int _multisnapshot_target_percent char *params, uint64_t *total_numerator, uint64_t *total_denominator) { - return TARGET_STATUS_INVALIDATED; + int m; + unsigned nargs; + int error; + char *snapid; + uint64_t total, allocated, metadata; + + snapid = dm_pool_alloc(mem, strlen(params) + 1); + if (!snapid) { + log_error("Out of memory."); + return TARGET_STATUS_ERROR; + } + + m = sscanf(params, "%u %d %s %"SCNu64" %"SCNu64" %"SCNu64"", &nargs, &error, snapid, &total, &allocated, &metadata); + if (m != 6) { + log_error("_multisnapshot_target_percent: matched only %d entries of '%s'", m, params); + return TARGET_STATUS_ERROR; + } + if (error < 0) { + return TARGET_STATUS_INVALIDATED; + } + + *total_numerator += allocated; + *total_denominator += total; + return TARGET_STATUS_PROCESSING; } static int _multisnap_target_present(struct cmd_context *cmd, Index: LVM2.2.02.53/lib/report/report.c =================================================================== --- LVM2.2.02.53.orig/lib/report/report.c 2009-10-14 01:52:03.000000000 +0200 +++ LVM2.2.02.53/lib/report/report.c 2009-10-14 02:37:18.000000000 +0200 @@ -363,7 +363,7 @@ static int _lvstatus_disp(struct dm_repo repstr[4] = 'd'; /* Inactive without table */ /* Snapshot dropped? */ - if (info.live_table && lv_is_cow(lv) && + if ((info.live_table) && lv_is_cow(lv) && (lv_snapshot_percent(lv, &snap_percent) <= TARGET_STATUS_INVALIDATED)) { repstr[0] = toupper(repstr[0]); @@ -382,6 +382,18 @@ static int _lvstatus_disp(struct dm_repo repstr[5] = '-'; } + if (lv_is_cow(lv) && lv->snapshot->status & SNAPSHOT_SHARED) + lv = lv->snapshot->origin; + else if (lv_is_multisnap_cow(lv)) + lv = first_seg(lv)->origin; + else + lv = NULL; + + if (lv && lv_snapshot_percent(lv, &snap_percent) <= TARGET_STATUS_INVALIDATED) { + repstr[0] = toupper(repstr[0]); + repstr[4] = 'I'; + } + out: dm_report_field_set_value(field, repstr, NULL); return 1; @@ -1029,13 +1041,19 @@ static int _snpercent_disp(struct dm_rep return 0; } - if (!lv_is_cow(lv) || - (lv_info(lv->vg->cmd, lv, &info, 0, 0) && !info.exists)) { + if (!lv_is_cow(lv)) { +report_empty: *sortval = UINT64_C(0); dm_report_field_set_value(field, "", sortval); return 1; } + if (lv->snapshot->status & SNAPSHOT_SHARED) + lv = lv->snapshot->origin; + + if (lv_info(lv->vg->cmd, lv, &info, 0, 0) && !info.exists) + goto report_empty; + if (lv_snapshot_percent(lv, &snap_percent) < TARGET_STATUS_INVALIDATED) { *sortval = UINT64_C(100);