From: Andreas Dilger Date: Sun, 5 Nov 2023 05:32:19 +0000 (-0600) Subject: LU-17263 utils: 'lfs find -blocks' to use 512-byte units X-Git-Tag: 2.15.60~94 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=refs%2Fchanges%2F93%2F52993%2F3;p=fs%2Flustre-release.git LU-17263 utils: 'lfs find -blocks' to use 512-byte units Change the default units for 'lfs find -blocks' from 1KiB blocks to 512-byte blocks to better match the behavior of find(1). This also matches what "-printf %b" will print. Change llapi_parse_size() to accept a 'c' argument to specify characters, and accept a "B" or "iB" suffix if provided. Fixes: c043f46025 ("LU-10705 utils: add "lfs find --blocks"") Signed-off-by: Andreas Dilger Change-Id: If8345f15bf53912501cadc0fa7f981a9f787b767 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/52993 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Arshad Hussain Reviewed-by: Vitaliy Kuznetsov Reviewed-by: Oleg Drokin --- diff --git a/lustre/doc/lfs-find.1 b/lustre/doc/lfs-find.1 index 4f4a458..d9f8726 100644 --- a/lustre/doc/lfs-find.1 +++ b/lustre/doc/lfs-find.1 @@ -70,8 +70,8 @@ Compressed (c), Immutable (i), Append_Only (a), No_Dump (d), Encrypted (E), Automount (M) .TP .BR --blocks | -b -Blocks allocated by the file is \fIn\fR Kibibytes (if no units are given), -\fIn\fR 512-byte \fBb\fRlocks, or \fBK\fRibi-, \fBM\fRebi-, \fBG\fRibi-, +Blocks allocated by the file is \fIn\fR 512-byte \fBb\fRlocks (if no units +are given), or \fBc\fRhars (bytes), \fBK\fRibi-, \fBM\fRebi-, \fBG\fRibi-, \fBT\fRebi-, \fBP\fRebi-, or \fBE\fRbi-bytes if that suffix is given. .TP .BR --btime | --Btime | -B diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 14832cb..c387aa5 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -5339,7 +5339,7 @@ static int lfs_find(int argc, char **argv) optarg++; } - param.fp_blocks_units = 1024; + param.fp_blocks_units = 512; ret = llapi_parse_size(optarg, ¶m.fp_blocks, ¶m.fp_blocks_units, 0); if (ret) { diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index eca1453..ddad8a0 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -285,41 +285,56 @@ int llapi_parse_size(const char *optarg, unsigned long long *size, } if (*end != '\0') { - if ((*end == 'b') && *(end + 1) == '\0' && - (*size & (~0ULL << (64 - 9))) == 0 && - !bytes_spec) { - *size_units = 1 << 9; - } else if ((*end == 'b') && - *(end + 1) == '\0' && - bytes_spec) { + char next = tolower(*(end + 1)); + + switch (tolower(*end)) { + case 'b': + if (bytes_spec) { + *size_units = 1; + } else { + if (*size & (~0ULL << (64 - 9))) + return -EINVAL; + *size_units = 1 << 9; + } + break; + case 'c': *size_units = 1; - } else if ((*end == 'k' || *end == 'K') && - *(end + 1) == '\0' && - (*size & (~0ULL << (64 - 10))) == 0) { + break; + case 'k': + if (*size & (~0ULL << (64 - 10))) + return -EINVAL; *size_units = 1 << 10; - } else if ((*end == 'm' || *end == 'M') && - *(end + 1) == '\0' && - (*size & (~0ULL << (64 - 20))) == 0) { + break; + case 'm': + if (*size & (~0ULL << (64 - 20))) + return -EINVAL; *size_units = 1 << 20; - } else if ((*end == 'g' || *end == 'G') && - *(end + 1) == '\0' && - (*size & (~0ULL << (64 - 30))) == 0) { + break; + case 'g': + if (*size & (~0ULL << (64 - 30))) + return -EINVAL; *size_units = 1 << 30; - } else if ((*end == 't' || *end == 'T') && - *(end + 1) == '\0' && - (*size & (~0ULL << (64 - 40))) == 0) { + break; + case 't': + if (*size & (~0ULL << (64 - 40))) + return -EINVAL; *size_units = 1ULL << 40; - } else if ((*end == 'p' || *end == 'P') && - *(end + 1) == '\0' && - (*size & (~0ULL << (64 - 50))) == 0) { + break; + case 'p': + if (*size & (~0ULL << (64 - 50))) + return -EINVAL; *size_units = 1ULL << 50; - } else if ((*end == 'e' || *end == 'E') && - *(end + 1) == '\0' && - (*size & (~0ULL << (64 - 60))) == 0) { + break; + case 'e': + if (*size & (~0ULL << (64 - 60))) + return -EINVAL; *size_units = 1ULL << 60; - } else { + break; + default: return -EINVAL; } + if (next != '\0' && next != 'i' && next != 'b') + return -EINVAL; } *size = *size * *size_units + frac * *size_units / frac_d;