From 004b80da5c4b2a7cf4f4885b43c9edec76cd2493 Mon Sep 17 00:00:00 2001 From: Wang Shilong Date: Fri, 25 Jan 2019 16:54:50 +0800 Subject: [PATCH] LU-11872 utils: don't follow link files in default We actually don't support operation on link files itself for now. As a first step, let's skip link files for now in default, otherwise, it cause unexpected behavior. Test-Parameters: trivial testlist=sanity-quota Signed-off-by: Wang Shilong Change-Id: Ib0069ed1982e26984c6cf093f0803bf4a2208fe1 Reviewed-on: https://review.whamcloud.com/34111 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Gu Zheng --- lustre/tests/sanity-quota.sh | 21 ++++++++++++++++++++- lustre/utils/lfs_project.c | 40 ++++++++++++++++++++++++++++++++-------- 2 files changed, 52 insertions(+), 9 deletions(-) diff --git a/lustre/tests/sanity-quota.sh b/lustre/tests/sanity-quota.sh index 14a20cd..3336688 100755 --- a/lustre/tests/sanity-quota.sh +++ b/lustre/tests/sanity-quota.sh @@ -3064,7 +3064,7 @@ test_57() { #try to change pipe file should not hang and return failure wait_update_facet client "$LFS project -sp 1 $dir/pipe 2>&1 | awk -F ':' '{ print \\\$2 }'" \ - " failed to get xattr for '$dir/pipe'" || return 1 + " unable to get xattr for fifo '$dir/pipe'" || return 1 #command can process further if it hit some errors touch $dir/aaa $dir/bbb mkdir $dir/subdir -p @@ -3432,6 +3432,25 @@ test_63() { } run_test 63 "quota on DoM tests" +test_64() { + ! is_project_quota_supported && + skip "Project quota is not supported" + setup_quota_test || error "setup quota failed with $?" + local dir1="$DIR/$tdir/" + + touch $dir1/file + ln -s $dir1/file $dir1/file_link + + $LFS project -sp $TSTPRJID $dir1/file_link >&/dev/null && + error "set symlink file's project should fail" + + $LFS project $TSTPRJID $dir1/file_link >&/dev/null && + error "get symlink file's project should fail" + + cleanup_quota_test +} +run_test 64 "lfs project on symlink files should fail" + quota_fini() { do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota" diff --git a/lustre/utils/lfs_project.c b/lustre/utils/lfs_project.c index d61b038..8d3ee2f 100644 --- a/lustre/utils/lfs_project.c +++ b/lustre/utils/lfs_project.c @@ -75,9 +75,41 @@ lfs_project_item_alloc(struct list_head *head, const char *pathname) return 0; } +static const char *mode_to_type(mode_t mode) +{ + switch (mode & S_IFMT) { + case S_IFDIR: return "dir"; + case S_IFREG: return "regular"; + case S_IFLNK: return "symlink"; + case S_IFCHR: return "char device"; + case S_IFBLK: return "block device"; + case S_IFIFO: return "fifo"; + case S_IFSOCK: return "sock"; + } + + return "unknown"; +} + static int project_get_xattr(const char *pathname, struct fsxattr *fsx) { int ret, fd; + struct stat st; + + ret = lstat(pathname, &st); + if (ret) { + fprintf(stderr, "%s: failed to stat '%s': %s\n", + progname, pathname, strerror(errno)); + return -errno; + } + + /* currently, only file and dir supported */ + if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode)) { + errno = ENOTSUP; + fprintf(stderr, "%s: unable to get xattr for %s '%s': %s\n", + progname, mode_to_type(st.st_mode), pathname, + strerror(errno)); + return -errno; + } fd = open(pathname, O_RDONLY | O_NOCTTY | O_NDELAY); if (fd < 0) { @@ -100,16 +132,8 @@ static int project_check_one(const char *pathname, struct project_handle_control *phc) { struct fsxattr fsx; - struct stat st; int ret; - ret = stat(pathname, &st); - if (ret) { - fprintf(stderr, "%s: failed to stat '%s': %s\n", - progname, pathname, strerror(errno)); - return -errno; - } - ret = project_get_xattr(pathname, &fsx); if (ret < 0) return ret; -- 1.8.3.1