From: Prakash Surya Date: Fri, 13 May 2011 15:48:36 +0000 (-0700) Subject: LU-279 tests: Ensure lgetxattr is consistent X-Git-Tag: 2.3.58~63 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=a21cfa02dff3b9b290bbb8bd7b33f0606d32acde LU-279 tests: Ensure lgetxattr is consistent * Added the lgetxattr_size_check.c program to compare the size returned by lgetxattr() when passed zero size buffers and non zero size buffers * Sanity test 17l was added to make use of this new test program and ensure that the values returned by lgetxattr remain consistent Signed-off-by: Prakash Surya Change-Id: Id46dbe888d42b058e02ec32b6d1612705d7f6349 Reviewed-on: http://review.whamcloud.com/547 Tested-by: Hudson Tested-by: Maloo Reviewed-by: Fan Yong Reviewed-by: Andreas Dilger --- diff --git a/lustre/tests/Makefile.am b/lustre/tests/Makefile.am index d3b6a00..e247d42 100644 --- a/lustre/tests/Makefile.am +++ b/lustre/tests/Makefile.am @@ -63,7 +63,7 @@ noinst_PROGRAMS += small_write multiop ll_sparseness_verify noinst_PROGRAMS += ll_sparseness_write mrename ll_dirstripe_verify mkdirmany noinst_PROGRAMS += openfilleddirunlink rename_many memhog noinst_PROGRAMS += mmap_sanity writemany reads flocks_test -noinst_PROGRAMS += write_time_limit rwv copytool +noinst_PROGRAMS += write_time_limit rwv copytool lgetxattr_size_check # noinst_PROGRAMS += copy_attr mkdirdeep bin_PROGRAMS = mcreate munlink testdir = $(libdir)/lustre/tests diff --git a/lustre/tests/lgetxattr_size_check.c b/lustre/tests/lgetxattr_size_check.c new file mode 100644 index 0000000..6e83e22 --- /dev/null +++ b/lustre/tests/lgetxattr_size_check.c @@ -0,0 +1,68 @@ +#include +#include +#include +#include +#include +#include + +void usage(char *prog) +{ + printf("Usage: %s \n", prog); +} + +/* Simple program to test the lgetxattr return value. */ +int main(int argc, char *argv[]) +{ + char *path, *xattr, *buf; + ssize_t ret_null; + int ret = 0; + + if (argc != 3) { + usage(argv[0]); + exit(1); + } + + path = argv[1]; + xattr = argv[2]; + + ret_null = lgetxattr(path, xattr, NULL, 0); + if (ret_null < 0) { + fprintf(stderr, "lgetxattr(%s, %s, NULL, 0) failed " + "with %i: %s\n", path, xattr, errno, + strerror(errno)); + ret = 1; + goto out; + } + + buf = (char *)malloc(ret_null); + if (buf == NULL) { + fprintf(stderr, "malloc(%zi) failed with %i: %s\n", + ret_null, errno, strerror(errno)); + ret = 1; + goto out; + } + + ssize_t ret_buf = lgetxattr(path, xattr, buf, ret_null); + if (ret_buf < 0) { + fprintf(stderr, "lgetxattr(%s, %s, %p, %zi) failed " + "with %i: %s\n", path, xattr, buf, + ret_null, errno, strerror(errno)); + ret = 1; + goto free; + } + + if (ret_null != ret_buf) { + fprintf(stderr, "lgetxattr returned inconsistent sizes!\n"); + fprintf(stderr, "lgetxattr(%s, %s, NULL, 0) = %zi\n", + path, xattr, ret_null); + fprintf(stderr, "lgetxattr(%s, %s, %p, %zi) = %zi\n", + path, xattr, buf, ret_null, ret_buf); + ret = 1; + goto free; + } + +free: + free(buf); +out: + return ret; +} diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index caf86b9..5ccf2b1 100644 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -510,6 +510,22 @@ test_17k() { #bug 22301 } run_test 17k "symlinks: rsync with xattrs enabled =========================" +test_17l() { # LU-279 + mkdir -p $DIR/$tdir + touch $DIR/$tdir/$tfile + ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk + for path in "$DIR/$tdir" "$DIR/$tdir/$tfile" "$DIR/$tdir/$tfile.lnk"; do + # -h to not follow symlinks. -m '' to list all the xattrs. + # grep to remove first line: '# file: $path'. + for xattr in `getfattr -hm '' $path 2>/dev/null | grep -v '^#'`; + do + lgetxattr_size_check $path $xattr || + error "lgetxattr_size_check $path $xattr failed" + done + done +} +run_test 17l "Ensure lgetxattr's returned xattr size is consistent ========" + # LU-1540 test_17m() { local short_sym="0123456789"