From 7dc14743db5ff5e01ea877194182d11418f57cee Mon Sep 17 00:00:00 2001 From: Dmitry Zogin Date: Tue, 15 Jun 2010 08:50:18 -0400 Subject: [PATCH] b=22938 lfs find -s doesn't seem to work correctly Fixing find_value_cmp(). o=yuriy.umanets i=johann i=andreas.dilger --- lustre/include/lustre/liblustreapi.h | 6 ++++- lustre/tests/sanity.sh | 33 ++++++++++++++++++++++++ lustre/utils/lfs.c | 29 +++------------------ lustre/utils/liblustreapi.c | 50 +++++++++++++++++++----------------- 4 files changed, 68 insertions(+), 50 deletions(-) diff --git a/lustre/include/lustre/liblustreapi.h b/lustre/include/lustre/liblustreapi.h index 0db8846..394253b 100644 --- a/lustre/include/lustre/liblustreapi.h +++ b/lustre/include/lustre/liblustreapi.h @@ -124,7 +124,11 @@ struct find_param { check_gid:1, check_uid:1, check_pool:1, - exclude_pool:1; + exclude_pool:1, + exclude_size:1, + exclude_atime:1, + exclude_mtime:1, + exclude_ctime:1; int verbose; int quiet; diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 52b3959..034cee5 100644 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -2841,6 +2841,39 @@ test_56q() { } run_test 56q "check lfs find -gid and ! -gid ===============================" +test_56r() { + setup_56 $NUMFILES $NUMDIRS + TDIR=$DIR/${tdir}g + + EXPECTED=12 + NUMS=`$LFIND -size 0 -t f $TDIR | wc -l` + [ $NUMS -eq $EXPECTED ] || \ + error "lfs find $TDIR -size 0 wrong: found $NUMS, expected $EXPECTED" + EXPECTED=0 + NUMS=`$LFIND ! -size 0 -t f $TDIR | wc -l` + [ $NUMS -eq $EXPECTED ] || \ + error "lfs find $TDIR ! -size 0 wrong: found $NUMS, expected $EXPECTED" + echo "test" > $TDIR/5chars + EXPECTED=1 + NUMS=`$LFIND -size 5 -t f $TDIR | wc -l` + [ $NUMS -eq $EXPECTED ] || \ + error "lfs find $TDIR -size 5 wrong: found $NUMS, expected $EXPECTED" + EXPECTED=1 + NUMS=`$LFIND -size +5 -t f $TDIR | wc -l` + [ $NUMS -eq $EXPECTED ] || \ + error "lfs find $TDIR -size +5 wrong: found $NUMS, expected $EXPECTED" + EXPECTED=13 + NUMS=`$LFIND -size +0 -t f $TDIR | wc -l` + [ $NUMS -eq $EXPECTED ] || \ + error "lfs find $TDIR -size +0 wrong: found $NUMS, expected $EXPECTED" + EXPECTED=0 + NUMS=`$LFIND ! -size -5 -t f $TDIR | wc -l` + [ $NUMS -eq $EXPECTED ] || \ + error "lfs find $TDIR ! -size -5 wrong: found $NUMS, expected $EXPECTED" +} + +run_test 56r "check lfs find -size works ==========================" + test_57a() { remote_mds_nodsh && skip "remote MDS with nodsh" && return diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index e695a54..29a3bdf 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -454,7 +454,6 @@ static int lfs_find(int argc, char **argv) int c, ret; time_t t; struct find_param param = { .maxdepth = -1 }; - char str[1024]; struct option long_opts[] = { /* New find options. */ {"atime", required_argument, 0, 'A'}, @@ -536,29 +535,20 @@ static int lfs_find(int argc, char **argv) case 'A': xtime = ¶m.atime; xsign = ¶m.asign; + param.exclude_atime = !!neg_opt; case 'C': if (c == 'C') { xtime = ¶m.ctime; xsign = ¶m.csign; + param.exclude_ctime = !!neg_opt; } case 'M': if (c == 'M') { xtime = ¶m.mtime; xsign = ¶m.msign; + param.exclude_mtime = !!neg_opt; } new_fashion = 1; - if (neg_opt) { - if (optarg[0] == '-') - optarg[0] = '+'; - else if (optarg[0] == '+') - optarg[0] = '-'; - else { - str[0] = '-'; - str[1] = '\0'; - strcat(str, optarg); - optarg = str; - } - } ret = set_time(&t, xtime, optarg); if (ret == INT_MAX) return -1; @@ -689,18 +679,6 @@ static int lfs_find(int argc, char **argv) }; break; case 's': - if (neg_opt) { - if (optarg[0] == '-') - optarg[0] = '+'; - else if (optarg[0] == '+') - optarg[0] = '-'; - else { - str[0] = '-'; - str[1] = '\0'; - strcat(str, optarg); - optarg = str; - } - } if (optarg[0] == '+') param.size_sign = -1; else if (optarg[0] == '-') @@ -715,6 +693,7 @@ static int lfs_find(int argc, char **argv) optarg); return ret; } + param.exclude_size = !!neg_opt; param.size_check = 1; break; case 'v': diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index eb27739..e466d49 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -1654,28 +1654,26 @@ int llapi_file_lookup(int dirfd, const char *name) * Note: 5th actually means that the value is within the interval * (limit - margin, limit]. */ static int find_value_cmp(unsigned int file, unsigned int limit, int sign, - unsigned long long margin, int mds) + int negopt, unsigned long long margin, int mds) { - if (sign > 0) { - if (file < limit) - return mds ? 0 : 1; - } - - if (sign == 0) { - if (file <= limit && file + margin > limit) - return mds ? 0 : 1; - if (file + margin <= limit) - return mds ? 0 : -1; - } + int ret = -1; - if (sign < 0) { - if (file > limit) - return 1; - if (mds) - return 0; + if (sign > 0) { + if (file <= limit) + ret = mds ? 0 : 1; + } else if (sign == 0) { + if (file <= limit && file + margin >= limit) + ret = mds ? 0 : 1; + else if (file + margin <= limit) + ret = mds ? 0 : -1; + } else if (sign < 0) { + if (file >= limit) + ret = 1; + else if (mds) + ret = 0; } - return -1; + return negopt ? ~ret + 1 : ret; } /* Check if the file time matches all the given criteria (e.g. --atime +/-N). @@ -1693,7 +1691,8 @@ static int find_time_check(lstat_t *st, struct find_param *param, int mds) /* Check if file is accepted. */ if (param->atime) { ret = find_value_cmp(st->st_atime, param->atime, - param->asign, 24 * 60 * 60, mds); + param->asign, param->exclude_atime, + 24 * 60 * 60, mds); if (ret < 0) return ret; rc = ret; @@ -1701,7 +1700,8 @@ static int find_time_check(lstat_t *st, struct find_param *param, int mds) if (param->mtime) { ret = find_value_cmp(st->st_mtime, param->mtime, - param->msign, 24 * 60 * 60, mds); + param->msign, param->exclude_mtime, + 24 * 60 * 60, mds); if (ret < 0) return ret; @@ -1713,7 +1713,8 @@ static int find_time_check(lstat_t *st, struct find_param *param, int mds) if (param->ctime) { ret = find_value_cmp(st->st_ctime, param->ctime, - param->csign, 24 * 60 * 60, mds); + param->csign, param->exclude_ctime, + 24 * 60 * 60, mds); if (ret < 0) return ret; @@ -1972,10 +1973,11 @@ obd_matches: goto decided; } - if (param->size_check) + if (param->size_check) { decision = find_value_cmp(st->st_size, param->size, - param->size_sign, param->size_units, - 0); + param->size_sign, param->exclude_size, + param->size_units, 0); + } if (decision != -1) { llapi_printf(LLAPI_MSG_NORMAL, "%s", path); -- 1.8.3.1