From: Keith Mannthey Date: Fri, 9 Aug 2013 06:17:27 +0000 (-0700) Subject: LU-3403 test: error of listxattr when buffer is small X-Git-Tag: 2.4.93~50 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=e86619c7d593c2a96b0ba6654e696219294b51ed LU-3403 test: error of listxattr when buffer is small Add a new test for LU-3403. Check that when a buffer that is too small is passed into listxattr the system call fails correctly. Signed-off-by: Keith Mannthey Change-Id: Idf45a3155284a20afadbd2c331a3d85710f740cb Reviewed-on: http://review.whamcloud.com/6594 Tested-by: Maloo Reviewed-by: Dmitry Eremin Reviewed-by: Li Xi Tested-by: Hudson Reviewed-by: Oleg Drokin --- diff --git a/lustre/tests/Makefile.am b/lustre/tests/Makefile.am index e1ea3f9..57ff236 100644 --- a/lustre/tests/Makefile.am +++ b/lustre/tests/Makefile.am @@ -68,6 +68,8 @@ noinst_PROGRAMS += ll_sparseness_write mrename ll_dirstripe_verify mkdirmany noinst_PROGRAMS += openfilleddirunlink rename_many memhog noinst_PROGRAMS += mmap_sanity writemany reads flocks_test flock_deadlock noinst_PROGRAMS += write_time_limit rwv lgetxattr_size_check checkfiemap +noinst_PROGRAMS += listxattr_size_check + bin_PROGRAMS = mcreate munlink testdir = $(libdir)/lustre/tests diff --git a/lustre/tests/listxattr_size_check.c b/lustre/tests/listxattr_size_check.c new file mode 100644 index 0000000..5adf144 --- /dev/null +++ b/lustre/tests/listxattr_size_check.c @@ -0,0 +1,94 @@ +/* + * GPL HEADER START + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 only, + * as published by the Free Software Foundation. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License version 2 for more details. A copy is + * included in the COPYING file that accompanied this code. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * GPL HEADER END + * + * Copyright (c) 2013, Intel Corporation. + * + * lustre/tests/listxattr_size_check.c + * + * Author: Keith Mannthey + */ + +#include +#include +#include +#include +#include +#include + +void usage(char *prog) +{ + printf("Usage: %s \n", prog); +} + +/* Test the listxattr return value when the buffer is small. */ +int main(int argc, char *argv[]) +{ + char *path, *buf; + ssize_t ret_buf, ret_null, error_s; + int ret = 0; + + if (argc != 2) { + usage(argv[0]); + exit(1); + } + + path = argv[1]; + + ret_null = listxattr(path, NULL, 0); + if (ret_null < 0) { + fprintf(stderr, "listxattr(%s, NULL, 0) failed " + "with %i: %s\n", path, errno, + strerror(errno)); + ret = errno; + goto out; + } + + /* LU-3403 llite: error of listxattr when buffer is small */ + if (ret_null < 2) { + fprintf(stderr, "listxattr(%s, NULL, 0) returned" + "a sizes less than 2", path); + ret = EINVAL; + goto out; + } + + error_s = ret_null - 1; + buf = (char *)malloc(error_s); + if (buf == NULL) { + fprintf(stderr, "malloc(%zi) failed with %i: %s\n", + error_s, errno, strerror(errno)); + ret = errno; + goto out; + } + + ret_buf = llistxattr(path, buf, error_s); + if (ret_buf != -1) { + fprintf(stderr, "llistxattr(%s, %p, %zi) passed with %zi but " + "should have failed with -1\n", path, buf, + error_s, ret_buf); + ret = EINVAL; + goto free; + } + +free: + free(buf); +out: + return ret; +} diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index c740e59..72d2d87 100644 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -6338,7 +6338,15 @@ test_102l() { return 0; } -run_test 102l "listxattr filter test ==================================" +run_test 102l "listxattr size test ==================================" + +test_102m() { # LU-3403 llite: error of listxattr when buffer is small + local path=$DIR/$tfile + touch $path + + listxattr_size_check $path || error "listattr_size_check $path failed" +} +run_test 102m "Ensure listxattr fails on small bufffer ========" cleanup_test102