1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-02 01:18:26 +03:00

display: add display_percent function

Add universal function to print dm_percent_t values via single
code path.

TODO: extend with configurale precision of printed values.
This commit is contained in:
Zdenek Kabelac 2017-06-24 16:03:21 +02:00
parent feed61f3fa
commit 07eec06f5d
3 changed files with 29 additions and 2 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.172 -
===============================
Add display_percent helper function for printing percent values.
Lvconvert --repair handles failing raid legs (present but marked 'D'ead).
Do not lvdisplay --maps unset settings of cache pool.
Fix lvdisplay --maps for cache pool without policy settings.

View File

@ -1,6 +1,6 @@
/*
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
* Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
* Copyright (C) 2004-2017 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
@ -152,6 +152,30 @@ const char *display_lvname(const struct logical_volume *lv)
return name;
}
/* Display percentage with (TODO) configurable precision */
const char *display_percent(struct cmd_context *cmd, dm_percent_t percent)
{
char *buf;
int r;
/* Reusing same ring buffer we use for displaying LV names */
if ((cmd->display_lvname_idx + NAME_LEN) >= sizeof((cmd->display_buffer)))
cmd->display_lvname_idx = 0;
buf = cmd->display_buffer + cmd->display_lvname_idx;
/* TODO: Make configurable hardcoded 2 digits */
r = dm_snprintf(buf, NAME_LEN, "%.2f", dm_percent_to_round_float(percent, 2));
if (r < 0) {
log_error("Percentage %d does not fit.", percent);
return NULL;
}
cmd->display_lvname_idx += r + 1;
return buf;
}
/* Size supplied in sectors */
static const char *_display_size(const struct cmd_context *cmd,
uint64_t size, dm_size_suffix_t suffix_type)

View File

@ -1,6 +1,6 @@
/*
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
* Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
* Copyright (C) 2004-2017 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
@ -24,6 +24,8 @@
const char *display_lvname(const struct logical_volume *lv);
const char *display_percent(struct cmd_context *cmd, dm_percent_t percent);
/* Specify size in KB */
const char *display_size(const struct cmd_context *cmd, uint64_t size);
const char *display_size_long(const struct cmd_context *cmd, uint64_t size);