From 53969ac9958877a239694ed09707f30bea3d02cc Mon Sep 17 00:00:00 2001 From: Niu Yawei Date: Thu, 4 May 2017 08:35:18 -0400 Subject: [PATCH] LU-9449 tools: component add to no stripe info file 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 Change-Id: I4ead7fae5ba2d0c4427b820e0506b507ef17a43b Reviewed-on: https://review.whamcloud.com/26944 Reviewed-by: Andreas Dilger Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Bobi Jam --- lustre/utils/lfs.c | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 7ba9003..3eb8cec 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -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; } -- 1.8.3.1