Whamcloud - gitweb
LU-12027 utils: fix "lfs find -amctime" comparison 58/34658/2
authorAndreas Dilger <adilger@whamcloud.com>
Wed, 27 Feb 2019 09:25:23 +0000 (02:25 -0700)
committerOleg Drokin <green@whamcloud.com>
Tue, 30 Apr 2019 03:38:09 +0000 (03:38 +0000)
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 <adilger@whamcloud.com>
Change-Id: Ib1eb4e626b712bb75f13b075849f959f203ebbe5
Reviewed-on: https://review.whamcloud.com/34658
Tested-by: Jenkins
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Jian Yu <yujian@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/doc/lfs-find.1
lustre/include/lustre/lustreapi.h
lustre/utils/lfs.c
lustre/utils/liblustreapi.c

index 29fb105..4486b92 100644 (file)
@@ -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
 \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),
 .TP
 .BR --blocks | -b
 Blocks allocated by the file is \fIn\fR Kibibytes (if no units are given),
index f8466e3..0e51d25 100644 (file)
@@ -320,7 +320,7 @@ struct find_param {
                                 fp_obds_printed:1;
        unsigned int             fp_depth;
        unsigned int             fp_hash_type;
                                 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);
 };
 
 int llapi_ostlist(char *path, struct find_param *param);
index 193eb5d..eaeca58 100644 (file)
@@ -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;
                }
                                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;
                        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;
        }
 
        *set = *time - t;
+
        return res;
 }
 
        return res;
 }
 
index f14d288..c7a8281 100644 (file)
@@ -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,
  * (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) {
 {
        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) {
                if (file + margin <= limit)
                        ret = mds ? 0 : 1;
        } else if (sign == 0) {