Whamcloud - gitweb
LU-14645 utils: fix API for llapi_sanity_check 51/46151/3
authorVitaly Fertman <c17818@cray.com>
Mon, 17 Jan 2022 18:49:52 +0000 (21:49 +0300)
committerOleg Drokin <green@whamcloud.com>
Mon, 31 Jan 2022 01:09:00 +0000 (01:09 +0000)
fix the previous patch which introduced a change in API.

Fixes: 149934fe28 ("LU-14645 utils: setstripe cleanup")
Signed-off-by: Vitaly Fertman <c17818@cray.com>
Change-Id: I43ae6822768ac70c9348af270c17830b13133f8c
Reviewed-on: https://review.whamcloud.com/46151
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Alexander Boyko <alexander.boyko@hpe.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/include/lustre/lustreapi.h
lustre/tests/llapi_layout_test.c
lustre/utils/lfs.c
lustre/utils/liblustreapi.c
lustre/utils/liblustreapi_layout.c
lustre/utils/lustreapi_internal.h

index 8cb362b..65ed22a 100644 (file)
@@ -995,7 +995,7 @@ int llapi_layout_pool_name_get(const struct llapi_layout *layout,
  * \retval -1  Invalid argument, errno set to EINVAL.
  */
 int llapi_layout_pool_name_set(struct llapi_layout *layout,
-                              char *pool_name);
+                              const char *pool_name);
 
 /******************** File Creation ********************/
 
@@ -1216,8 +1216,11 @@ int llapi_mirror_punch(int fd, unsigned int id, off_t start, size_t length);
 int llapi_heat_get(int fd, struct lu_heat *heat);
 int llapi_heat_set(int fd, __u64 flags);
 
-int llapi_layout_sanity(struct llapi_layout *layout, const char *fname,
-                       bool incomplete, bool flr);
+int llapi_layout_sanity(struct llapi_layout *layout, bool incomplete, bool flr);
+int llapi_layout_sanity_fsname_check(struct llapi_layout *layout,
+                                    const char *pathname,
+                                    bool incomplete,
+                                    bool flr);
 void llapi_layout_sanity_perror(int error);
 int llapi_layout_dom_size(struct llapi_layout *layout, uint64_t *size);
 
index 890dd8d..f67fb9d 100644 (file)
@@ -1366,7 +1366,7 @@ void test30(void)
        /* set non-contiguous extent will fail */
        rc = llapi_layout_comp_extent_set(layout, start[1] * 2, end[1]);
        ASSERTF(rc == 0, "errno %d", errno);
-       rc = llapi_layout_sanity(layout, NULL, false, false);
+       rc = llapi_layout_sanity(layout, false, false);
        ASSERTF(rc == 12 /*LSE_NOT_ADJACENT_PREV*/, "rc %d", rc);
 
        rc = llapi_layout_comp_extent_set(layout, start[1], end[1]);
@@ -1734,7 +1734,7 @@ void test34(void)
        layout = llapi_layout_get_by_path(path, 0);
        ASSERTF(layout != NULL, "errno = %d", errno);
 
-       rc = llapi_layout_sanity(layout, NULL, false, false);
+       rc = llapi_layout_sanity(layout, false, false);
        ASSERTF(rc == 0, "errno %d", errno);
 }
 
index 466f44c..2724832 100644 (file)
@@ -1047,7 +1047,7 @@ int lfs_layout_compid_by_pool(char *fname, const char *pool, int *comp_id)
                rc = -errno;
                goto free_layout;
        }
-       rc = llapi_layout_sanity(layout, fname, false, true);
+       rc = llapi_layout_sanity_fsname_check(layout, fname, false, true);
        if (rc < 0) {
                llapi_layout_sanity_perror(errno);
                goto free_layout;
@@ -1512,7 +1512,8 @@ static int mirror_create_sanity_check(const char *fname,
                        return -ENODATA;
                }
 
-               rc = llapi_layout_sanity(layout, fname, false, true);
+               rc = llapi_layout_sanity_fsname_check(layout, fname,
+                                                     false, true);
 
                llapi_layout_free(layout);
 
@@ -1544,7 +1545,8 @@ static int mirror_create_sanity_check(const char *fname,
                        }
                }
 
-               rc = llapi_layout_sanity(list->m_layout, fname, false, true);
+               rc = llapi_layout_sanity_fsname_check(list->m_layout, fname,
+                                                     false, true);
                if (rc) {
                        llapi_layout_sanity_perror(rc);
                        return rc;
@@ -2114,7 +2116,7 @@ static int mirror_split(const char *fname, __u32 id, const char *pool,
                return -EINVAL;
        }
 
-       rc = llapi_layout_sanity(layout, fname, false, true);
+       rc = llapi_layout_sanity_fsname_check(layout, fname, false, true);
        if (rc) {
                llapi_layout_sanity_perror(rc);
                goto free_layout;
index 99f8b1b..27725be 100644 (file)
@@ -402,10 +402,10 @@ int llapi_ioctl_unpack(struct obd_ioctl_data *data, char *pbuf, int max_len)
 
 /* XXX: llapi_xxx() functions return negative values upon failure */
 
-int llapi_layout_search_ost(__u32 ost, char *pname, char *fsname)
+int llapi_layout_search_ost(__u32 ost, const char *pname, char *fsname)
 {
        char ostname[MAX_OBD_NAME + 64];
-       char *pool_name = pname;
+       const char *pool_name = pname;
        int rc = 0;
 
        /**
@@ -446,7 +446,7 @@ int llapi_layout_search_ost(__u32 ost, char *pname, char *fsname)
  *                             < 0, error code on failre
  */
 static int llapi_stripe_param_verify(const struct llapi_stripe_param *param,
-                                    char **pool_name,
+                                    const char **pool_name,
                                     char *fsname)
 {
        int count;
@@ -492,8 +492,8 @@ static int llapi_stripe_param_verify(const struct llapi_stripe_param *param,
        if (param->lsp_stripe_pattern == LOV_PATTERN_MDT) {
                rc = -EINVAL;
                llapi_error(LLAPI_MSG_ERROR, rc,
-                           "Invalid pattern: %d, must be specified with -E\n",
-                           param->lsp_stripe_pattern);
+                           "Invalid pattern: '-L mdt', must be specified "
+                           "with -E\n");
                goto out;
        } else {
                if (!llapi_stripe_count_is_valid(count)) {
@@ -679,7 +679,7 @@ int llapi_file_open_param(const char *name, int flags, mode_t mode,
 {
        char fsname[MAX_OBD_NAME + 1] = { 0 };
        struct lov_user_md *lum = NULL;
-       char *pool_name = param->lsp_pool;
+       const char *pool_name = param->lsp_pool;
        size_t lum_size;
        int fd, rc;
 
index c90972b..8fdc15f 100644 (file)
@@ -1538,7 +1538,7 @@ int llapi_layout_pool_name_get(const struct llapi_layout *layout, char *dest,
  * \retval     -1 if arguments are invalid or pool name is too long
  */
 int llapi_layout_pool_name_set(struct llapi_layout *layout,
-                              char *pool_name)
+                              const char *pool_name)
 {
        struct llapi_layout_comp *comp;
 
@@ -1586,9 +1586,9 @@ int llapi_layout_file_open(const char *path, int open_flags, mode_t mode,
        }
 
        if (layout) {
-               rc = llapi_layout_sanity((struct llapi_layout *)layout,
-                                        path, false,
-                                        !!(layout->llot_mirror_count > 1));
+               rc = llapi_layout_sanity_fsname_check(
+                               (struct llapi_layout *)layout, path, false,
+                               !!(layout->llot_mirror_count > 1));
                if (rc) {
                        llapi_layout_sanity_perror(rc);
                        return -1;
@@ -2218,7 +2218,8 @@ int llapi_layout_file_comp_add(const char *path,
                goto out;
        }
 
-       rc = llapi_layout_sanity(existing_layout, path, false, false);
+       rc = llapi_layout_sanity_fsname_check(existing_layout, path,
+                                             false, false);
        if (rc) {
                tmp_errno = errno;
                llapi_layout_sanity_perror(rc);
@@ -2353,7 +2354,8 @@ int llapi_layout_file_comp_del(const char *path, uint32_t id, uint32_t flags)
                goto out;
        }
 
-       rc = llapi_layout_sanity(existing_layout, path, false, false);
+       rc = llapi_layout_sanity_fsname_check(existing_layout, path,
+                                             false, false);
        if (rc) {
                tmp_errno = errno;
                llapi_layout_sanity_perror(rc);
@@ -2513,7 +2515,8 @@ int llapi_layout_file_comp_set(const char *path, uint32_t *ids, uint32_t *flags,
                goto out;
        }
 
-       rc = llapi_layout_sanity(existing_layout, path, false, false);
+       rc = llapi_layout_sanity_fsname_check(existing_layout, path,
+                                             false, false);
        if (rc) {
                tmp_errno = errno;
                llapi_layout_sanity_perror(rc);
@@ -3447,10 +3450,10 @@ void llapi_layout_sanity_perror(int error)
  * \retval                      0, success, positive: various errors, see
  *                              llapi_layout_sanity_perror, -1, failure
  */
-int llapi_layout_sanity(struct llapi_layout *layout,
-                       const char *fname,
-                       bool incomplete,
-                       bool flr)
+static int __llapi_layout_sanity(struct llapi_layout *layout,
+                                const char *fname,
+                                bool incomplete,
+                                bool flr)
 {
        struct llapi_layout_sanity_args args = { { 0 } };
        struct llapi_layout_comp *curr;
@@ -3498,6 +3501,21 @@ int llapi_layout_sanity(struct llapi_layout *layout,
        return rc;
 }
 
+int llapi_layout_sanity(struct llapi_layout *layout,
+                       bool incomplete,
+                       bool flr)
+{
+       return __llapi_layout_sanity(layout, NULL, incomplete, flr);
+}
+
+int llapi_layout_sanity_fsname_check(struct llapi_layout *layout,
+                                    const char *pathname,
+                                    bool incomplete,
+                                    bool flr)
+{
+       return __llapi_layout_sanity(layout, pathname, incomplete, flr);
+}
+
 int llapi_layout_dom_size(struct llapi_layout *layout, uint64_t *size)
 {
        uint64_t pattern, start;
index 3d291dc..95c57ff 100644 (file)
@@ -131,10 +131,10 @@ static inline bool llapi_stripe_index_is_valid(int64_t index)
        return index >= -1 && index <= LOV_V1_INSANE_STRIPE_COUNT;
 }
 
-static inline bool llapi_pool_name_is_valid(char **pool_name,
+static inline bool llapi_pool_name_is_valid(const char **pool_name,
                                            const char *fsname)
 {
-       char *ptr;
+       const char *ptr;
 
        if (*pool_name == NULL)
                return false;
@@ -145,10 +145,12 @@ static inline bool llapi_pool_name_is_valid(char **pool_name,
         */
        ptr = strchr(*pool_name, '.');
        if (ptr != NULL) {
-               *ptr = '\0';
-               if (fsname != NULL && strcmp(*pool_name, fsname) != 0) {
-                       *ptr = '.';
-                       return false;
+               if (fsname != NULL) {
+                       int fslen = strlen(fsname);
+
+                       if (fslen != ptr - *pool_name ||
+                           strncmp(*pool_name, fsname, fslen) != 0)
+                               return false;
                }
                *pool_name = ptr + 1;
        }
@@ -160,7 +162,7 @@ static inline bool llapi_pool_name_is_valid(char **pool_name,
 }
 
 
-int llapi_layout_search_ost(__u32 ost, char *pname, char *fsname);
+int llapi_layout_search_ost(__u32 ost, const char *pname, char *fsname);
 
 /* Compatibility macro for legacy llapi functions that use "offset"
  * terminology instead of the preferred "index". */