1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

vdo: read VDO stats via dm message

As the sysfs interface is seen somewhat obsolete, swith code
to prefer using DM 'stats' message to get our currently needed
info for VDO pool target.
This commit is contained in:
Zdenek Kabelac 2024-02-19 14:13:20 +01:00
parent 4f9215e70f
commit 55937f9c8e
3 changed files with 66 additions and 6 deletions

View File

@ -1905,6 +1905,60 @@ out:
return r;
}
/* Read info from DM VDO 'stats' message */
static int _dev_manager_vdo_pool_message_stats(struct dev_manager *dm,
const struct logical_volume *lv,
struct lv_status_vdo *status)
{
const char *response;
const char *dlid;
struct dm_task *dmt = NULL;
int r = 0;
unsigned i;
const char *p;
struct vdo_msg_elem {
const char *name;
uint64_t *val;
} const vme[] = {
{ "dataBlocksUsed", &status->data_blocks_used },
{ "logicalBlocksUsed", &status->logical_blocks_used }
};
if (!(dlid = build_dm_uuid(dm->mem, lv, lv_layer(lv))))
return_0;
if (!(dmt = _setup_task_run(DM_DEVICE_TARGET_MSG, NULL, NULL, dlid, 0, 0, 0, 0, 0, 0)))
return_0;
if (!dm_task_set_message(dmt, "stats"))
goto_out;
if (!dm_task_run(dmt))
goto_out;
log_debug_activation("Checking VDO pool stats message for LV %s.",
display_lvname(lv));
if ((response = dm_task_get_message_response(dmt))) {
for (i = 0; i < DM_ARRAY_SIZE(vme); ++i) {
errno = 0;
if (!(p = strstr(response, vme[i].name)) ||
!(p = strchr(p, ':')) ||
((*vme[i].val = strtoul(p + 1, NULL, 10)) == ULLONG_MAX) || errno) {
log_debug("Cannot parse %s in VDO DM stats message.", vme[i].name);
*vme[i].val = 0;
goto out;
}
}
}
r = 1;
out:
dm_task_destroy(dmt);
return r;
}
int dev_manager_vdo_pool_status(struct dev_manager *dm,
const struct logical_volume *lv, int flush,
struct lv_status_vdo **status, int *exists)
@ -1945,6 +1999,9 @@ int dev_manager_vdo_pool_status(struct dev_manager *dm,
goto out;
}
if (!_dev_manager_vdo_pool_message_stats(dm, lv, *status))
stack;
if (!parse_vdo_pool_status(dm->mem, lv, params, &info, *status))
goto_out;

View File

@ -1380,8 +1380,9 @@ int wipe_cache_pool(struct logical_volume *cache_pool_lv);
struct lv_status_vdo {
struct dm_pool *mem;
struct dm_vdo_status *vdo;
uint64_t data_blocks_used; /* grabbed from /sys/kvdo */
uint64_t logical_blocks_used; /* grabbed from /sys/kvdo */
/* grabbed from DM stats message, /sys/block/dm-/vdo or /sys/kvdo */
uint64_t data_blocks_used;
uint64_t logical_blocks_used;
dm_percent_t usage;
dm_percent_t saving;
dm_percent_t data_usage;

View File

@ -217,10 +217,12 @@ int parse_vdo_pool_status(struct dm_pool *mem, const struct logical_volume *vdo_
status->vdo = result.status;
if ((result.status->operating_mode == DM_VDO_MODE_NORMAL) &&
_sysfs_get_kvdo_value(dm_name, dminfo, "statistics/data_blocks_used",
&status->data_blocks_used) &&
_sysfs_get_kvdo_value(dm_name, dminfo, "statistics/logical_blocks_used",
&status->logical_blocks_used)) {
(status->data_blocks_used ||
_sysfs_get_kvdo_value(dm_name, dminfo, "statistics/data_blocks_used",
&status->data_blocks_used)) &&
(status->logical_blocks_used ||
_sysfs_get_kvdo_value(dm_name, dminfo, "statistics/logical_blocks_used",
&status->logical_blocks_used))) {
status->usage = dm_make_percent(result.status->used_blocks,
result.status->total_blocks);
status->saving = dm_make_percent(status->logical_blocks_used - status->data_blocks_used,