From 11670b4c5e7014e2092bfa7ca6ba96ecca5d9d4e Mon Sep 17 00:00:00 2001 From: Emoly Liu Date: Wed, 28 Jun 2017 17:28:34 +0800 Subject: [PATCH] LU-9657 llapi: check if the file layout is composite Add a new API llapi_layout_is_composite() to check if the file layout is composite. Signed-off-by: Emoly Liu Change-Id: Ie7d60f95feb9dfde5fbf52ea65ebd26b925bd33d Reviewed-on: https://review.whamcloud.com/27752 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Niu Yawei Reviewed-by: Andreas Dilger --- lustre/include/lustre/lustreapi.h | 4 ++++ lustre/utils/lfs.c | 16 +++++----------- lustre/utils/liblustreapi_layout.c | 13 +++++++++++++ 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/lustre/include/lustre/lustreapi.h b/lustre/include/lustre/lustreapi.h index 67df286..f2d6db8 100644 --- a/lustre/include/lustre/lustreapi.h +++ b/lustre/include/lustre/lustreapi.h @@ -816,6 +816,10 @@ int llapi_layout_file_comp_del(const char *path, uint32_t id, uint32_t flags); int llapi_layout_file_comp_set(const char *path, const struct llapi_layout *comp, uint32_t valid); +/** + * Check if the file layout is composite. + */ +bool llapi_layout_is_composite(struct llapi_layout *layout); /** @} llapi */ diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 5870cd8..7a48345 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -1171,17 +1171,11 @@ static int adjust_first_extent(char *fname, struct llapi_layout *layout) * into a component-create. */ llapi_layout_free(head); 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; - } + } else if (!llapi_layout_is_composite(head)) { + fprintf(stderr, "'%s' isn't a composite file.\n", + fname); + llapi_layout_free(head); + return -EINVAL; } rc = llapi_layout_comp_extent_get(head, &start, &prev_end); diff --git a/lustre/utils/liblustreapi_layout.c b/lustre/utils/liblustreapi_layout.c index dbf1369..0168de2 100644 --- a/lustre/utils/liblustreapi_layout.c +++ b/lustre/utils/liblustreapi_layout.c @@ -2012,3 +2012,16 @@ int llapi_layout_file_comp_set(const char *path, errno = EOPNOTSUPP; return -1; } + +/** + * Check if the file layout is composite. + * + * \param[in] layout the file layout to check + * + * \retval true composite + * \retval false not composite + */ +bool llapi_layout_is_composite(struct llapi_layout *layout) +{ + return layout->llot_is_composite; +} -- 1.8.3.1