From: Damien Le Moal <Damien.LeMoal@wdc.com>
To: Naohiro Aota <Naohiro.Aota@wdc.com>, Karel Zak <kzak@redhat.com>
Cc: "util-linux@vger.kernel.org" <util-linux@vger.kernel.org>
Subject: Re: [PATCH v2 1/3] lsblk: factor out function to read sysfs param as bytes
Date: Sun, 29 Aug 2021 23:07:10 +0000 [thread overview]
Message-ID: <DM6PR04MB7081FBA5FEB9A90D022991D6E7CA9@DM6PR04MB7081.namprd04.prod.outlook.com> (raw)
In-Reply-To: 20210827073453.4079636-2-naohiro.aota@wdc.com
On 2021/08/27 16:35, Naohiro Aota wrote:
> Factor out a new function device_read_bytes() to read a sysfs path as bytes
> for a preparation for the next commit and to reduce the code duplication.
>
> Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
> ---
> misc-utils/lsblk.c | 45 ++++++++++++++++++++-------------------------
> 1 file changed, 20 insertions(+), 25 deletions(-)
>
> diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c
> index 100eba0779f8..775a6d832076 100644
> --- a/misc-utils/lsblk.c
> +++ b/misc-utils/lsblk.c
> @@ -708,6 +708,24 @@ static uint64_t device_get_discard_granularity(struct lsblk_device *dev)
> return dev->discard_granularity;
> }
>
> +static void device_read_bytes(struct lsblk_device *dev, char *path, char **str,
> + uint64_t *sortdata)
> +{
> + if (lsblk->bytes) {
> + ul_path_read_string(dev->sysfs, str, path);
> + if (sortdata)
> + str2u64(*str, sortdata);
You could return early here to avoid the else...
> + } else {
> + uint64_t x;
> +
> + if (ul_path_read_u64(dev->sysfs, &x, path) == 0) {
> + *str = size_to_human_string(SIZE_SUFFIX_1LETTER, x);
> + if (sortdata)
> + *sortdata = x;
> + }
> + }
> +}
> +
> /*
> * Generates data (string) for column specified by column ID for specified device. If sortdata
> * is not NULL then returns number usable to sort the column if the data are available for the
> @@ -1033,18 +1051,7 @@ static char *device_get_data(
> }
> break;
> case COL_DMAX:
> - if (lsblk->bytes) {
> - ul_path_read_string(dev->sysfs, &str, "queue/discard_max_bytes");
> - if (sortdata)
> - str2u64(str, sortdata);
> - } else {
> - uint64_t x;
> - if (ul_path_read_u64(dev->sysfs, &x, "queue/discard_max_bytes") == 0) {
> - str = size_to_human_string(SIZE_SUFFIX_1LETTER, x);
> - if (sortdata)
> - *sortdata = x;
> - }
> - }
> + device_read_bytes(dev, "queue/discard_max_bytes", &str, sortdata);
> break;
> case COL_DZERO:
> if (device_get_discard_granularity(dev) > 0)
> @@ -1053,19 +1060,7 @@ static char *device_get_data(
> str = xstrdup("0");
> break;
> case COL_WSAME:
> - if (lsblk->bytes) {
> - ul_path_read_string(dev->sysfs, &str, "queue/write_same_max_bytes");
> - if (sortdata)
> - str2u64(str, sortdata);
> - } else {
> - uint64_t x;
> -
> - if (ul_path_read_u64(dev->sysfs, &x, "queue/write_same_max_bytes") == 0) {
> - str = size_to_human_string(SIZE_SUFFIX_1LETTER, x);
> - if (sortdata)
> - *sortdata = x;
> - }
> - }
> + device_read_bytes(dev, "queue/write_same_max_bytes", &str, sortdata);
> if (!str)
> str = xstrdup("0");
> break;
>
Apart from the optional nit above, looks good to me.
Reviewed-by: Damien Le Moal <damien.lemoal@wdc.com>
--
Damien Le Moal
Western Digital Research
next prev parent reply other threads:[~2021-08-29 23:07 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-27 7:34 [PATCH v2 0/3] add columns for zoned parameters Naohiro Aota
2021-08-27 7:34 ` [PATCH v2 1/3] lsblk: factor out function to read sysfs param as bytes Naohiro Aota
2021-08-29 23:07 ` Damien Le Moal [this message]
2021-08-30 1:21 ` Naohiro Aota
2021-08-27 7:34 ` [PATCH v2 2/3] lsblk: add columns of zoned parameters Naohiro Aota
2021-08-29 23:10 ` Damien Le Moal
2021-08-30 1:08 ` Naohiro Aota
2021-08-30 1:50 ` Damien Le Moal
2021-08-30 5:15 ` Naohiro Aota
2021-08-29 23:15 ` Damien Le Moal
2021-08-27 7:34 ` [PATCH v2 3/3] lsblk: add zoned columns to "lsblk -z" Naohiro Aota
2021-08-29 23:14 ` Damien Le Moal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DM6PR04MB7081FBA5FEB9A90D022991D6E7CA9@DM6PR04MB7081.namprd04.prod.outlook.com \
--to=damien.lemoal@wdc.com \
--cc=Naohiro.Aota@wdc.com \
--cc=kzak@redhat.com \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).