From 76ee08995eb8271a34c77352ffd499983d6c5752 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Thu, 19 Jan 2012 15:27:54 +0000 Subject: [PATCH] Thin add function to read thin volume percent This value returns percentage of 'mapped' size compared with total LV size. (Without passed seg pointer it return highest mapped size - but it's not used yet.) --- lib/activate/activate.c | 26 ++++++++++++++++++++++++++ lib/activate/activate.h | 2 ++ lib/activate/dev_manager.c | 22 ++++++++++++++++++++++ lib/activate/dev_manager.h | 3 +++ lib/thin/thin.c | 31 +++++++++++++++++++++++++++++++ 5 files changed, 84 insertions(+) diff --git a/lib/activate/activate.c b/lib/activate/activate.c index 56dc37c2a..be235b175 100644 --- a/lib/activate/activate.c +++ b/lib/activate/activate.c @@ -736,6 +736,32 @@ int lv_thin_pool_percent(const struct logical_volume *lv, int metadata, return r; } +/* + * Returns 1 if percent set, else 0 on failure. + */ +int lv_thin_percent(const struct logical_volume *lv, + int mapped, percent_t *percent) +{ + int r; + struct dev_manager *dm; + + if (!activation()) + return 0; + + log_debug("Checking thin percent for LV %s/%s", + lv->vg->name, lv->name); + + if (!(dm = dev_manager_create(lv->vg->cmd, lv->vg->name, 1))) + return_0; + + if (!(r = dev_manager_thin_percent(dm, lv, mapped, percent))) + stack; + + dev_manager_destroy(dm); + + return r; +} + static int _lv_active(struct cmd_context *cmd, struct logical_volume *lv) { struct lvinfo info; diff --git a/lib/activate/activate.h b/lib/activate/activate.h index 64f2ecbee..925876202 100644 --- a/lib/activate/activate.h +++ b/lib/activate/activate.h @@ -103,6 +103,8 @@ int lv_mirror_percent(struct cmd_context *cmd, const struct logical_volume *lv, int lv_raid_percent(const struct logical_volume *lv, percent_t *percent); int lv_thin_pool_percent(const struct logical_volume *lv, int metadata, percent_t *percent); +int lv_thin_percent(const struct logical_volume *lv, int mapped, + percent_t *percent); /* * Return number of LVs in the VG that are active. diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c index c04da5e31..c0adbd7cf 100644 --- a/lib/activate/dev_manager.c +++ b/lib/activate/dev_manager.c @@ -895,6 +895,28 @@ int dev_manager_thin_pool_percent(struct dev_manager *dm, return 1; } +int dev_manager_thin_percent(struct dev_manager *dm, + const struct logical_volume *lv, + int mapped, percent_t *percent) +{ + char *name; + const char *dlid; + + /* Build a name for the top layer */ + if (!(name = dm_build_dm_name(dm->mem, lv->vg->name, lv->name, NULL))) + return_0; + + if (!(dlid = build_dm_uuid(dm->mem, lv->lvid.s, NULL))) + return_0; + + log_debug("Getting device status percentage for %s", name); + if (!(_percent(dm, name, dlid, "thin", 0, + (mapped) ? NULL : lv, percent, NULL, 1))) + return_0; + + return 1; +} + /*************************/ /* NEW CODE STARTS HERE */ /*************************/ diff --git a/lib/activate/dev_manager.h b/lib/activate/dev_manager.h index 417981bd9..e3c73493e 100644 --- a/lib/activate/dev_manager.h +++ b/lib/activate/dev_manager.h @@ -57,6 +57,9 @@ int dev_manager_mirror_percent(struct dev_manager *dm, int dev_manager_thin_pool_percent(struct dev_manager *dm, const struct logical_volume *lv, int metadata, percent_t *percent); +int dev_manager_thin_percent(struct dev_manager *dm, + const struct logical_volume *lv, + int mapped, percent_t *percent); int dev_manager_suspend(struct dev_manager *dm, struct logical_volume *lv, struct lv_activate_opts *laopts, int lockfs, int flush_required); int dev_manager_activate(struct dev_manager *dm, struct logical_volume *lv, diff --git a/lib/thin/thin.c b/lib/thin/thin.c index 7f5bfc7f2..8f4976c24 100644 --- a/lib/thin/thin.c +++ b/lib/thin/thin.c @@ -409,6 +409,36 @@ static int _thin_add_target_line(struct dev_manager *dm, return 1; } +static int _thin_target_percent(void **target_state __attribute__((unused)), + percent_t *percent, + struct dm_pool *mem, + struct cmd_context *cmd __attribute__((unused)), + struct lv_segment *seg, + char *params, + uint64_t *total_numerator, + uint64_t *total_denominator) +{ + struct dm_status_thin *s; + + /* Status for thin device is in sectors */ + if (!dm_get_status_thin(mem, params, &s)) + return_0; + + if (seg) { + *percent = make_percent(s->mapped_sectors, seg->lv->size); + *total_denominator += seg->lv->size; + } else { + /* No lv_segment info here */ + *percent = PERCENT_INVALID; + /* FIXME: Using denominator to pass the mapped info upward? */ + *total_denominator += s->highest_mapped_sector; + } + + *total_numerator += s->mapped_sectors; + + return 1; +} + static int _thin_target_present(struct cmd_context *cmd, const struct lv_segment *seg, unsigned *attributes __attribute__((unused))) @@ -499,6 +529,7 @@ static struct segtype_handler _thin_ops = { .text_export = _thin_text_export, #ifdef DEVMAPPER_SUPPORT .add_target_line = _thin_add_target_line, + .target_percent = _thin_target_percent, .target_present = _thin_target_present, # ifdef DMEVENTD .target_monitored = _target_registered, -- 2.43.5