From 3b9d1acfc73a30162cc1eb4c6e2878004af19d19 Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Wed, 27 Feb 2019 02:25:23 -0700 Subject: [PATCH] LU-12027 utils: fix "lfs find -amctime" comparison For matches that are "equal" to the specified time, they must match within the smallest unit specified. For example, "-mtime 24h" would match anything within 1h of 24h ago, similar to how "-size 100M" will match anything within 1MB of 100MB. Test-Parameters: trivial fstype=zfs Fixes: 355c8a529a3a ("LU-12027 utils: add units to 'lfs find -amctime'") Signed-off-by: Andreas Dilger Change-Id: Ib1eb4e626b712bb75f13b075849f959f203ebbe5 Reviewed-on: https://review.whamcloud.com/34658 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Wang Shilong Reviewed-by: Jian Yu Reviewed-by: Oleg Drokin --- lustre/doc/lfs-find.1 | 6 +++++- lustre/include/lustre/lustreapi.h | 2 +- lustre/utils/lfs.c | 5 ++++- lustre/utils/liblustreapi.c | 4 ++-- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lustre/doc/lfs-find.1 b/lustre/doc/lfs-find.1 index 29fb105..4486b92 100644 --- a/lustre/doc/lfs-find.1 +++ b/lustre/doc/lfs-find.1 @@ -50,7 +50,11 @@ or \fIn\fR*\fBs\fReconds, \fBm\fRinutes, \fBh\fRours, \fBd\fRays, \fBw\fReeks, or \fBy\fRears ago within a margin of error of 24h, or smaller if a unit is specified. Multiple units can be specified, for example \fB8h20m\fR is equivalent to \fB500m\fR. If multipe units -are specified, the margin of error is based on the smallest unit used. +are specified, the margin of error is based on the smallest unit used, so +.B -atime 3d +has a margin of error of one day, while +.B -atime 72h +has a margin of error of one hour. .TP .BR --blocks | -b Blocks allocated by the file is \fIn\fR Kibibytes (if no units are given), diff --git a/lustre/include/lustre/lustreapi.h b/lustre/include/lustre/lustreapi.h index f8466e3..0e51d25 100644 --- a/lustre/include/lustre/lustreapi.h +++ b/lustre/include/lustre/lustreapi.h @@ -320,7 +320,7 @@ struct find_param { fp_obds_printed:1; unsigned int fp_depth; unsigned int fp_hash_type; - unsigned int fp_time_margin; + unsigned int fp_time_margin; /* time margin in seconds */ }; int llapi_ostlist(char *path, struct find_param *param); diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 193eb5d..eaeca58 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -3448,7 +3448,9 @@ static time_t set_time(struct find_param *param, time_t *time, time_t *set, progname, timebuf, strerror(EINVAL)); return LONG_MAX; } - if (*endptr && unit < 24 * 60 * 60) + + if (param->fp_time_margin == 0 || + (*endptr && unit < param->fp_time_margin)) param->fp_time_margin = unit; t += val * unit; @@ -3462,6 +3464,7 @@ static time_t set_time(struct find_param *param, time_t *time, time_t *set, } *set = *time - t; + return res; } diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index f14d288..c7a8281 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -3110,12 +3110,12 @@ static void lov_dump_comp_v1_entry(struct find_param *param, * (limit - margin, limit]. */ static int find_value_cmp(unsigned long long file, unsigned long long limit, int sign, int negopt, unsigned long long margin, - int mds) + bool mds) { int ret = -1; if (sign > 0) { - /* Drop the fraction of margin (of days). */ + /* Drop the fraction of margin (of days or size). */ if (file + margin <= limit) ret = mds ? 0 : 1; } else if (sign == 0) { -- 1.8.3.1