Whamcloud - gitweb
LU-3403 test: error of listxattr when buffer is small 94/6594/8
authorKeith Mannthey <keith.mannthey@intel.com>
Fri, 9 Aug 2013 06:17:27 +0000 (23:17 -0700)
committerOleg Drokin <oleg.drokin@intel.com>
Wed, 11 Sep 2013 03:56:23 +0000 (03:56 +0000)
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 <keith.mannthey@intel.com>
Change-Id: Idf45a3155284a20afadbd2c331a3d85710f740cb
Reviewed-on: http://review.whamcloud.com/6594
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Dmitry Eremin <dmitry.eremin@intel.com>
Reviewed-by: Li Xi <pkuelelixi@gmail.com>
Tested-by: Hudson
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/tests/Makefile.am
lustre/tests/listxattr_size_check.c [new file with mode: 0644]
lustre/tests/sanity.sh

index e1ea3f9..57ff236 100644 (file)
@@ -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 += 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
 
 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 (file)
index 0000000..5adf144
--- /dev/null
@@ -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 <keith.mannthey@intel.com>
+ */
+
+#include <sys/types.h>
+#include <sys/xattr.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+void usage(char *prog)
+{
+       printf("Usage: %s <pathname>\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;
+}
index c740e59..72d2d87 100644 (file)
@@ -6338,7 +6338,15 @@ test_102l() {
 
        return 0;
 }
 
        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
 
 
 cleanup_test102