Whamcloud - gitweb
LU-11872 utils: don't follow link files in default 11/34111/5
authorWang Shilong <wshilong@ddn.com>
Fri, 25 Jan 2019 08:54:50 +0000 (16:54 +0800)
committerOleg Drokin <green@whamcloud.com>
Sat, 1 Jun 2019 03:55:13 +0000 (03:55 +0000)
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 <wshilong@ddn.com>
Change-Id: Ib0069ed1982e26984c6cf093f0803bf4a2208fe1
Reviewed-on: https://review.whamcloud.com/34111
Tested-by: Jenkins
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Gu Zheng <gzheng@ddn.com>
lustre/tests/sanity-quota.sh
lustre/utils/lfs_project.c

index 14a20cd..3336688 100755 (executable)
@@ -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"
index d61b038..8d3ee2f 100644 (file)
@@ -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;