Whamcloud - gitweb
LU-279 tests: Ensure lgetxattr is consistent
authorPrakash Surya <surya1@llnl.gov>
Fri, 13 May 2011 15:48:36 +0000 (08:48 -0700)
committerOleg Drokin <green@whamcloud.com>
Thu, 13 Dec 2012 00:29:01 +0000 (19:29 -0500)
* 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 <surya1@llnl.gov>
Change-Id: Id46dbe888d42b058e02ec32b6d1612705d7f6349
Reviewed-on: http://review.whamcloud.com/547
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Fan Yong <fan.yong@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
lustre/tests/Makefile.am
lustre/tests/lgetxattr_size_check.c [new file with mode: 0644]
lustre/tests/sanity.sh

index d3b6a00..e247d42 100644 (file)
@@ -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 (file)
index 0000000..6e83e22
--- /dev/null
@@ -0,0 +1,68 @@
+#include <sys/types.h>
+#include <attr/xattr.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+void usage(char *prog)
+{
+       printf("Usage: %s <pathname> <xattr name>\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;
+}
index caf86b9..5ccf2b1 100644 (file)
@@ -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"