Whamcloud - gitweb
LU-11264 llapi: reduce llapi_stripe_limit_check() overhead 91/35091/2
authorAndreas Dilger <adilger@whamcloud.com>
Fri, 7 Jun 2019 03:34:49 +0000 (21:34 -0600)
committerOleg Drokin <green@whamcloud.com>
Thu, 20 Jun 2019 03:52:53 +0000 (03:52 +0000)
There is no need to check PAGE_SIZE in llapi_stripe_limit_check()
every time, since this cannot change between calls.

Always set errno if an error is returned.

Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Change-Id: Ib377c1cc734c9e683f75eeb509e220c4ea3ebbe5
Reviewed-on: https://review.whamcloud.com/35091
Tested-by: Jenkins
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Olaf Faaland-LLNL <faaland1@llnl.gov>
Reviewed-by: Jian Yu <yujian@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/utils/liblustreapi.c

index a81fb92..3d305f0 100644 (file)
@@ -386,45 +386,52 @@ int llapi_ioctl_unpack(struct obd_ioctl_data *data, char *pbuf, int max_len)
 int llapi_stripe_limit_check(unsigned long long stripe_size, int stripe_offset,
                                int stripe_count, int stripe_pattern)
 {
 int llapi_stripe_limit_check(unsigned long long stripe_size, int stripe_offset,
                                int stripe_count, int stripe_pattern)
 {
-       int page_size, rc;
-
-       /* 64 KB is the largest common page size I'm aware of (on ia64), but
-        * check the local page size just in case. */
-       page_size = LOV_MIN_STRIPE_SIZE;
-       if (getpagesize() > page_size) {
-               page_size = getpagesize();
-               llapi_err_noerrno(LLAPI_MSG_WARN,
-                               "warning: your page size (%u) is "
-                               "larger than expected (%u)", page_size,
-                               LOV_MIN_STRIPE_SIZE);
+       static int page_size;
+       int rc = 0;
+
+       if (page_size == 0) {
+               /* 64 KB is the largest common page size (on ia64/PPC/ARM),
+                * but check the local page size just in case. The page_size
+                * will not change for the lifetime of this process at least.
+                */
+               page_size = LOV_MIN_STRIPE_SIZE;
+               if (getpagesize() > page_size) {
+                       page_size = getpagesize();
+                       llapi_err_noerrno(LLAPI_MSG_WARN,
+                                         "warning: page size (%u) larger than expected (%u)",
+                                         page_size, LOV_MIN_STRIPE_SIZE);
+               }
        }
        if (!llapi_stripe_size_is_aligned(stripe_size)) {
                rc = -EINVAL;
                llapi_error(LLAPI_MSG_ERROR, rc, "error: bad stripe_size %llu, "
                                "must be an even multiple of %d bytes",
                                stripe_size, page_size);
        }
        if (!llapi_stripe_size_is_aligned(stripe_size)) {
                rc = -EINVAL;
                llapi_error(LLAPI_MSG_ERROR, rc, "error: bad stripe_size %llu, "
                                "must be an even multiple of %d bytes",
                                stripe_size, page_size);
-               return rc;
+               goto out;
        }
        if (!llapi_stripe_index_is_valid(stripe_offset)) {
                rc = -EINVAL;
                llapi_error(LLAPI_MSG_ERROR, rc, "error: bad stripe offset %d",
                                stripe_offset);
        }
        if (!llapi_stripe_index_is_valid(stripe_offset)) {
                rc = -EINVAL;
                llapi_error(LLAPI_MSG_ERROR, rc, "error: bad stripe offset %d",
                                stripe_offset);
-               return rc;
+               goto out;
        }
        if (!llapi_stripe_count_is_valid(stripe_count)) {
                rc = -EINVAL;
                llapi_error(LLAPI_MSG_ERROR, rc, "error: bad stripe count %d",
                                stripe_count);
        }
        if (!llapi_stripe_count_is_valid(stripe_count)) {
                rc = -EINVAL;
                llapi_error(LLAPI_MSG_ERROR, rc, "error: bad stripe count %d",
                                stripe_count);
-               return rc;
+               goto out;
        }
        if (llapi_stripe_size_is_too_big(stripe_size)) {
                rc = -EINVAL;
                llapi_error(LLAPI_MSG_ERROR, rc,
        }
        if (llapi_stripe_size_is_too_big(stripe_size)) {
                rc = -EINVAL;
                llapi_error(LLAPI_MSG_ERROR, rc,
-                               "warning: stripe size 4G or larger "
-                               "is not currently supported and would wrap");
-               return rc;
+                           "error: stripe size '%llu' over 4GB limit",
+                           stripe_size);
+               goto out;
        }
        }
-       return 0;
+
+out:
+       errno = -rc;
+       return rc;
 }
 
 int llapi_dir_stripe_limit_check(int stripe_offset, int stripe_count,
 }
 
 int llapi_dir_stripe_limit_check(int stripe_offset, int stripe_count,