From: Andreas Dilger Date: Fri, 7 Jun 2019 03:34:49 +0000 (-0600) Subject: LU-11264 llapi: reduce llapi_stripe_limit_check() overhead X-Git-Tag: 2.12.56~93 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=1c8ce141c6b6b621cf0fc89d32e1e7a2db43729d LU-11264 llapi: reduce llapi_stripe_limit_check() overhead 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 Change-Id: Ib377c1cc734c9e683f75eeb509e220c4ea3ebbe5 Reviewed-on: https://review.whamcloud.com/35091 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Olaf Faaland-LLNL Reviewed-by: Jian Yu Reviewed-by: Oleg Drokin --- diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index a81fb92..3d305f0 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -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 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); - 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); - 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); - return rc; + goto out; } 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,