From 1d700aaf9ff785e062d8e4c6a8920f37265dd969 Mon Sep 17 00:00:00 2001 From: Ned Bass Date: Tue, 12 May 2015 11:07:59 -0700 Subject: [PATCH] LU-6589 llapi: ..._layout_pattern_set() rejects valid patterns A typo in the input validation code causes llapi_layout_pattern_set() to reject valid pattern values. Correct the typo and add related test coverage in llapi_layout_test.c. Signed-off-by: Ned Bass Change-Id: I676a98b63d61fca114eacd882a19abce6f2cc857 Reviewed-on: http://review.whamcloud.com/14784 Reviewed-by: frank zago Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Oleg Drokin --- lustre/tests/llapi_layout_test.c | 26 ++++++++++++++++++-------- lustre/utils/liblustreapi_layout.c | 2 +- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/lustre/tests/llapi_layout_test.c b/lustre/tests/llapi_layout_test.c index 53b20b7..60d3ab8 100644 --- a/lustre/tests/llapi_layout_test.c +++ b/lustre/tests/llapi_layout_test.c @@ -173,7 +173,6 @@ void test1(void) llapi_layout_free(layout); } - #define T2_DESC "Read test0 file by FD and verify attributes" void test2(void) { @@ -219,7 +218,6 @@ void test3(void) llapi_layout_free(layout); } - #define T4FILE "t4" #define T4_STRIPE_COUNT 2 #define T4_STRIPE_SIZE 2097152 @@ -302,7 +300,6 @@ void test6(void) ASSERTF(layout == NULL && errno == EBADF, "errno = %d", errno); } - #define T7FILE "t7" #define T7_DESC "llapi_layout_get_by_path EACCES handling" void test7(void) @@ -345,7 +342,6 @@ void test7(void) ASSERTF(rc == 0, "errno = %d", errno); } - /* llapi_layout_get_by_path() returns default layout for file with no * striping attributes. */ #define T8FILE "t8" @@ -388,8 +384,8 @@ void test8(void) llapi_layout_free(layout); } -/* Setting pattern > 0 returns EOPNOTSUPP in errno. */ -#define T9_DESC "llapi_layout_pattern_set() EOPNOTSUPP handling" +/* Verify llapi_layout_patter_set() return values for various inputs. */ +#define T9_DESC "verify llapi_layout_pattern_set() return values" void test9(void) { struct llapi_layout *layout; @@ -397,14 +393,28 @@ void test9(void) layout = llapi_layout_alloc(); ASSERTF(layout != NULL, "errno = %d\n", errno); + errno = 0; - rc = llapi_layout_pattern_set(layout, 1); + rc = llapi_layout_pattern_set(layout, LLAPI_LAYOUT_INVALID); ASSERTF(rc == -1 && errno == EOPNOTSUPP, "rc = %d, errno = %d", rc, errno); + + errno = 0; + rc = llapi_layout_pattern_set(NULL, LLAPI_LAYOUT_DEFAULT); + ASSERTF(rc == -1 && errno == EINVAL, "rc = %d, errno = %d", rc, + errno); + + errno = 0; + rc = llapi_layout_pattern_set(layout, LLAPI_LAYOUT_DEFAULT); + ASSERTF(rc == 0, "rc = %d, errno = %d", rc, errno); + + errno = 0; + rc = llapi_layout_pattern_set(layout, LLAPI_LAYOUT_RAID0); + ASSERTF(rc == 0, "rc = %d, errno = %d", rc, errno); + llapi_layout_free(layout); } - /* Verify stripe_count interfaces return errors as expected */ #define T10_DESC "stripe_count error handling" void test10(void) diff --git a/lustre/utils/liblustreapi_layout.c b/lustre/utils/liblustreapi_layout.c index 937d5cc..4cd584e 100644 --- a/lustre/utils/liblustreapi_layout.c +++ b/lustre/utils/liblustreapi_layout.c @@ -786,7 +786,7 @@ int llapi_layout_pattern_set(struct llapi_layout *layout, uint64_t pattern) return -1; } - if (pattern != LLAPI_LAYOUT_DEFAULT || + if (pattern != LLAPI_LAYOUT_DEFAULT && pattern != LLAPI_LAYOUT_RAID0) { errno = EOPNOTSUPP; return -1; -- 1.8.3.1