Whamcloud - gitweb
LU-9449 tools: component add to no stripe info file 44/26944/6
authorNiu Yawei <yawei.niu@intel.com>
Thu, 4 May 2017 12:35:18 +0000 (08:35 -0400)
committerOleg Drokin <oleg.drokin@intel.com>
Sat, 3 Jun 2017 03:56:02 +0000 (03:56 +0000)
When add component by 'lfs setstripe --component-add' to a
file without LOVEA, it'll be turned into a 'lfs setstripe' operation
internally.

Signed-off-by: Niu Yawei <yawei.niu@intel.com>
Change-Id: I4ead7fae5ba2d0c4427b820e0506b507ef17a43b
Reviewed-on: https://review.whamcloud.com/26944
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Bobi Jam <bobijam@hotmail.com>
lustre/utils/lfs.c

index 7ba9003..3eb8cec 100644 (file)
@@ -1160,21 +1160,28 @@ static int adjust_first_extent(char *fname, struct llapi_layout *layout)
        if (layout == NULL)
                return -EINVAL;
 
+       errno = 0;
        head = llapi_layout_get_by_path(fname, 0);
        if (head == NULL) {
                fprintf(stderr, "Read layout from %s failed. %s\n",
                        fname, strerror(errno));
                return -EINVAL;
-       }
-
-       /* Current component of 'head' should be tail of component list by
-        * default, but we do an extra move cursor operation here to test
-        * if the layout is non-composite. */
-       rc = llapi_layout_comp_use(head, LLAPI_LAYOUT_COMP_USE_LAST);
-       if (rc < 0) {
-               fprintf(stderr, "'%s' isn't a composite file?\n", fname);
+       } else if (errno == ENODATA) {
+               /* file without LOVEA, this component-add will be turned
+                * into a component-create. */
                llapi_layout_free(head);
-               return rc;
+               return -ENODATA;
+       } else {
+               /* Current component of 'head' should be tail of component
+                * list by default, but we do an extra move cursor operation
+                * here to test if the layout is non-composite. */
+               rc = llapi_layout_comp_use(head, LLAPI_LAYOUT_COMP_USE_LAST);
+               if (rc < 0) {
+                       fprintf(stderr, "'%s' isn't a composite file?\n",
+                               fname);
+                       llapi_layout_free(head);
+                       return rc;
+               }
        }
 
        rc = llapi_layout_comp_extent_get(head, &start, &prev_end);
@@ -1598,6 +1605,18 @@ static int lfs_setstripe(int argc, char **argv)
                goto error;
        }
 
+       if (comp_add || comp_del) {
+               struct stat st;
+
+               result = lstat(fname, &st);
+               if (result == 0 && S_ISDIR(st.st_mode)) {
+                       fprintf(stderr, "error: %s: can't use --component-add "
+                               "or --component-del for directory.\n",
+                               argv[0]);
+                       goto error;
+               }
+       }
+
        if (comp_add) {
                if (layout == NULL) {
                        fprintf(stderr, "error: %s: -E option must be present"
@@ -1605,7 +1624,9 @@ static int lfs_setstripe(int argc, char **argv)
                        goto error;
                }
                result = adjust_first_extent(fname, layout);
-               if (result != 0)
+               if (result == -ENODATA)
+                       comp_add = 0;
+               else if (result != 0)
                        goto error;
        }