1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-03-10 16:58:47 +03:00

cache: report stats for cache volumes usage

Show some stats with 'lvs'
Display same info for active cache volume and cache-pool.

data% - #used cache blocks/#total cache blocks
meta% - #used metadata blocks/#total metadata blocks
copy% - #dirty/#used cache blocks

TODO: maybe there is a better mapping
 - should be seen as first-try-and-see.
This commit is contained in:
Zdenek Kabelac 2014-11-03 12:38:29 +01:00
parent b7bc28b7b7
commit ca9482b276
3 changed files with 48 additions and 3 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.112 - Version 2.02.112 -
===================================== =====================================
Report some basic percentage info for cache pools.
Introduce size_mb_arg_with_percent() for advanced size arg reading. Introduce size_mb_arg_with_percent() for advanced size arg reading.
Add extra support for '.' as decimal point in size args. Add extra support for '.' as decimal point in size args.
Configurable support for creation of sparse volumes with thin-pools. Configurable support for creation of sparse volumes with thin-pools.

View File

@ -104,10 +104,21 @@ static dm_percent_t _snap_percent(const struct logical_volume *lv)
static dm_percent_t _data_percent(const struct logical_volume *lv) static dm_percent_t _data_percent(const struct logical_volume *lv)
{ {
dm_percent_t percent; dm_percent_t percent;
struct lv_status_cache *status;
if (lv_is_cow(lv)) if (lv_is_cow(lv))
return _snap_percent(lv); return _snap_percent(lv);
if (lv_is_cache(lv) || lv_is_cache_pool(lv)) {
if (!lv_cache_status(lv, &status)) {
stack;
return DM_PERCENT_INVALID;
}
percent = status->dirty_usage;
dm_pool_destroy(status->mem);
return percent;
}
if (lv_is_thin_volume(lv)) if (lv_is_thin_volume(lv))
return lv_thin_percent(lv, 0, &percent) ? percent : DM_PERCENT_INVALID; return lv_thin_percent(lv, 0, &percent) ? percent : DM_PERCENT_INVALID;
@ -117,8 +128,22 @@ static dm_percent_t _data_percent(const struct logical_volume *lv)
static dm_percent_t _metadata_percent(const struct logical_volume *lv) static dm_percent_t _metadata_percent(const struct logical_volume *lv)
{ {
dm_percent_t percent; dm_percent_t percent;
struct lv_status_cache *status;
return lv_thin_pool_percent(lv, 1, &percent) ? percent : DM_PERCENT_INVALID; if (lv_is_cache(lv) || lv_is_cache_pool(lv)) {
if (!lv_cache_status(lv, &status)) {
stack;
return DM_PERCENT_INVALID;
}
percent = status->dirty_usage;
dm_pool_destroy(status->mem);
return percent;
}
if (lv_is_thin_pool(lv))
return lv_thin_pool_percent(lv, 1, &percent) ? percent : DM_PERCENT_INVALID;
return DM_PERCENT_INVALID;
} }
/* PV */ /* PV */

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2002-2004 Sistina Software, Inc. All rights reserved. * Copyright (C) 2002-2004 Sistina Software, Inc. All rights reserved.
* Copyright (C) 2004-2013 Red Hat, Inc. All rights reserved. * Copyright (C) 2004-2014 Red Hat, Inc. All rights reserved.
* *
* This file is part of LVM2. * This file is part of LVM2.
* *
@ -1057,13 +1057,18 @@ static int _copypercent_disp(struct dm_report *rh,
const void *data, void *private __attribute__((unused))) const void *data, void *private __attribute__((unused)))
{ {
const struct logical_volume *lv = (const struct logical_volume *) data; const struct logical_volume *lv = (const struct logical_volume *) data;
struct lv_status_cache *status;
dm_percent_t percent = DM_PERCENT_INVALID; dm_percent_t percent = DM_PERCENT_INVALID;
if (((lv_is_raid(lv) && lv_raid_percent(lv, &percent)) || if (((lv_is_raid(lv) && lv_raid_percent(lv, &percent)) ||
(lv_is_mirror(lv) && lv_mirror_percent(lv->vg->cmd, lv, 0, &percent, NULL))) && (lv_is_mirror(lv) && lv_mirror_percent(lv->vg->cmd, lv, 0, &percent, NULL))) &&
(percent != DM_PERCENT_INVALID)) { (percent != DM_PERCENT_INVALID)) {
percent = copy_percent(lv); percent = copy_percent(lv);
return dm_report_field_percent(rh, field, &percent); } else if (lv_is_cache(lv) || lv_is_cache_pool(lv)) {
if (lv_cache_status(lv, &status)) {
percent = status->dirty_usage;
dm_pool_destroy(status->mem);
}
} }
return dm_report_field_percent(rh, field, &percent); return dm_report_field_percent(rh, field, &percent);
@ -1149,6 +1154,7 @@ static int _datapercent_disp(struct dm_report *rh, struct dm_pool *mem,
{ {
const struct logical_volume *lv = (const struct logical_volume *) data; const struct logical_volume *lv = (const struct logical_volume *) data;
dm_percent_t percent = DM_PERCENT_INVALID; dm_percent_t percent = DM_PERCENT_INVALID;
struct lv_status_cache *status;
if (lv_is_cow(lv)) if (lv_is_cow(lv))
return _snpercent_disp(rh, mem, field, data, private); return _snpercent_disp(rh, mem, field, data, private);
@ -1156,6 +1162,12 @@ static int _datapercent_disp(struct dm_report *rh, struct dm_pool *mem,
(void) lv_thin_pool_percent(lv, 0, &percent); (void) lv_thin_pool_percent(lv, 0, &percent);
else if (lv_is_thin_volume(lv)) else if (lv_is_thin_volume(lv))
(void) lv_thin_percent(lv, 0, &percent); (void) lv_thin_percent(lv, 0, &percent);
else if (lv_is_cache(lv) || lv_is_cache_pool(lv)) {
if (lv_cache_status(lv, &status)) {
percent = status->data_usage;
dm_pool_destroy(status->mem);
}
}
return dm_report_field_percent(rh, field, &percent); return dm_report_field_percent(rh, field, &percent);
} }
@ -1167,11 +1179,18 @@ static int _metadatapercent_disp(struct dm_report *rh,
{ {
const struct logical_volume *lv = (const struct logical_volume *) data; const struct logical_volume *lv = (const struct logical_volume *) data;
dm_percent_t percent = DM_PERCENT_INVALID; dm_percent_t percent = DM_PERCENT_INVALID;
struct lv_status_cache *status;
if (lv_is_thin_pool(lv)) if (lv_is_thin_pool(lv))
(void) lv_thin_pool_percent(lv, 1, &percent); (void) lv_thin_pool_percent(lv, 1, &percent);
else if (lv_is_thin_volume(lv)) else if (lv_is_thin_volume(lv))
(void) lv_thin_percent(lv, 1, &percent); (void) lv_thin_percent(lv, 1, &percent);
else if (lv_is_cache(lv) || lv_is_cache_pool(lv)) {
if (lv_cache_status(lv, &status)) {
percent = status->metadata_usage;
dm_pool_destroy(status->mem);
}
}
return dm_report_field_percent(rh, field, &percent); return dm_report_field_percent(rh, field, &percent);
} }