All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] generic/337: add checks for listxattr call fails.
@ 2016-08-24 11:55 Artem Savkov
  2016-08-25  4:09 ` Eryu Guan
  0 siblings, 1 reply; 9+ messages in thread
From: Artem Savkov @ 2016-08-24 11:55 UTC (permalink / raw)
  To: fstests; +Cc: Filipe Manana, Dave Chinner, Artem Savkov

Add simple checks for failed calls to listxattr syscall. So far ERANGE, ENOENT
and EFAULT are checked.

Test is based on llistxattr02 test from LTP.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
---
 .gitignore            |  1 +
 src/Makefile          |  2 +-
 src/listxattr_fails.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/generic/337     |  4 ++++
 tests/generic/337.out |  3 +++
 5 files changed, 60 insertions(+), 1 deletion(-)
 create mode 100644 src/listxattr_fails.c

diff --git a/.gitignore b/.gitignore
index d84f385..613d245 100644
--- a/.gitignore
+++ b/.gitignore
@@ -66,6 +66,7 @@
 /src/holes
 /src/holetest
 /src/itrash
+/src/listxattr_fails
 /src/locktest
 /src/loggen
 /src/looptest
diff --git a/src/Makefile b/src/Makefile
index 57b0df1..0fee55f 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -21,7 +21,7 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \
 	stale_handle pwrite_mmap_blocked t_dir_offset2 seek_sanity_test \
 	seek_copy_test t_readdir_1 t_readdir_2 fsync-tester nsexec cloner \
 	renameat2 t_getcwd e4compact test-nextquota punch-alternating \
-	attr-list-by-handle-cursor-test
+	attr-list-by-handle-cursor-test listxattr_fails
 
 SUBDIRS =
 
diff --git a/src/listxattr_fails.c b/src/listxattr_fails.c
new file mode 100644
index 0000000..ddc4f7e
--- /dev/null
+++ b/src/listxattr_fails.c
@@ -0,0 +1,51 @@
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/xattr.h>
+
+int main(int argc, char **argv)
+{
+  int ret;
+  char buf;
+
+  if (argc < 2) {
+    fprintf(stderr, "usage: %s <testfile>\n", argv[0]);
+    return 1;
+  };
+
+  ret = listxattr(argv[1], &buf, 1);
+  if (ret == -1) {
+    if (errno == ERANGE) {
+      printf("expected error: ERANGE\n");
+    } else {
+      perror("unexpected error");
+    }
+  } else {
+    fprintf(stderr, "unexpected success\n");
+  }
+
+  ret = listxattr("", &buf, 1);
+  if (ret == -1) {
+    if (errno == ENOENT) {
+      printf("expected error: ENOENT\n");
+    } else {
+      perror("unexpected error");
+    }
+  } else {
+    fprintf(stderr, "unexpected success\n");
+  }
+
+  ret = listxattr((char *)-1, &buf, 1);
+  if (ret == -1) {
+    if (errno == EFAULT) {
+      printf("expected error: EFAULT\n");
+    } else {
+      perror("unexpected error");
+    }
+  } else {
+    fprintf(stderr, "unexpected success\n");
+  }
+
+  return 0;
+}
diff --git a/tests/generic/337 b/tests/generic/337
index 1758871..88b1e33 100755
--- a/tests/generic/337
+++ b/tests/generic/337
@@ -68,5 +68,9 @@ $SETFATTR_PROG -n user.ping -v pong $SCRATCH_MNT/testfile
 # It should list all the xattrs we have set before.
 $GETFATTR_PROG --absolute-names --dump $SCRATCH_MNT/testfile | _filter_scratch
 
+# Call listattr_fails to check if we get expected errors on errorneus listxattr
+# calls.
+$here/src/listxattr_fails $SCRATCH_MNT/testfile
+
 status=0
 exit
diff --git a/tests/generic/337.out b/tests/generic/337.out
index 1cd92ff..8ff8374 100644
--- a/tests/generic/337.out
+++ b/tests/generic/337.out
@@ -6,3 +6,6 @@ user.foobar="123"
 user.ping="pong"
 user.something="pizza"
 
+expected error: ERANGE
+expected error: ENOENT
+expected error: EFAULT
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] generic/337: add checks for listxattr call fails.
  2016-08-24 11:55 [PATCH] generic/337: add checks for listxattr call fails Artem Savkov
@ 2016-08-25  4:09 ` Eryu Guan
  2016-08-25  5:57   ` Dave Chinner
  0 siblings, 1 reply; 9+ messages in thread
From: Eryu Guan @ 2016-08-25  4:09 UTC (permalink / raw)
  To: Artem Savkov; +Cc: fstests, Filipe Manana, Dave Chinner

On Wed, Aug 24, 2016 at 01:55:53PM +0200, Artem Savkov wrote:
> Add simple checks for failed calls to listxattr syscall. So far ERANGE, ENOENT
> and EFAULT are checked.
> 
> Test is based on llistxattr02 test from LTP.

Any reason porting this from LTP? I think LTP is the right place for
such syscall level tests, this test should stay there, or extend
llistxattr02 test if you want to test new errnos.

> 
> Signed-off-by: Artem Savkov <asavkov@redhat.com>
> ---
>  .gitignore            |  1 +
>  src/Makefile          |  2 +-
>  src/listxattr_fails.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  tests/generic/337     |  4 ++++
>  tests/generic/337.out |  3 +++
>  5 files changed, 60 insertions(+), 1 deletion(-)
>  create mode 100644 src/listxattr_fails.c
> 
> diff --git a/.gitignore b/.gitignore
> index d84f385..613d245 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -66,6 +66,7 @@
>  /src/holes
>  /src/holetest
>  /src/itrash
> +/src/listxattr_fails
>  /src/locktest
>  /src/loggen
>  /src/looptest
> diff --git a/src/Makefile b/src/Makefile
> index 57b0df1..0fee55f 100644
> --- a/src/Makefile
> +++ b/src/Makefile
> @@ -21,7 +21,7 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \
>  	stale_handle pwrite_mmap_blocked t_dir_offset2 seek_sanity_test \
>  	seek_copy_test t_readdir_1 t_readdir_2 fsync-tester nsexec cloner \
>  	renameat2 t_getcwd e4compact test-nextquota punch-alternating \
> -	attr-list-by-handle-cursor-test
> +	attr-list-by-handle-cursor-test listxattr_fails
>  
>  SUBDIRS =
[snip]
> diff --git a/tests/generic/337 b/tests/generic/337
> index 1758871..88b1e33 100755
> --- a/tests/generic/337
> +++ b/tests/generic/337
> @@ -68,5 +68,9 @@ $SETFATTR_PROG -n user.ping -v pong $SCRATCH_MNT/testfile
>  # It should list all the xattrs we have set before.
>  $GETFATTR_PROG --absolute-names --dump $SCRATCH_MNT/testfile | _filter_scratch
>  
> +# Call listattr_fails to check if we get expected errors on errorneus listxattr
> +# calls.
> +$here/src/listxattr_fails $SCRATCH_MNT/testfile
> +

And usually we don't add new test to existing cases, so if the new test
fails we know it's not a regression.

Thanks,
Eryu

>  status=0
>  exit
> diff --git a/tests/generic/337.out b/tests/generic/337.out
> index 1cd92ff..8ff8374 100644
> --- a/tests/generic/337.out
> +++ b/tests/generic/337.out
> @@ -6,3 +6,6 @@ user.foobar="123"
>  user.ping="pong"
>  user.something="pizza"
>  
> +expected error: ERANGE
> +expected error: ENOENT
> +expected error: EFAULT
> -- 
> 1.8.3.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe fstests" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] generic/337: add checks for listxattr call fails.
  2016-08-25  4:09 ` Eryu Guan
@ 2016-08-25  5:57   ` Dave Chinner
  2016-08-25 11:01     ` [PATCH v2] Add a test for listxattr syscall with different buffer sizes Artem Savkov
  0 siblings, 1 reply; 9+ messages in thread
From: Dave Chinner @ 2016-08-25  5:57 UTC (permalink / raw)
  To: Eryu Guan; +Cc: Artem Savkov, fstests, Filipe Manana

On Thu, Aug 25, 2016 at 12:09:44PM +0800, Eryu Guan wrote:
> On Wed, Aug 24, 2016 at 01:55:53PM +0200, Artem Savkov wrote:
> > Add simple checks for failed calls to listxattr syscall. So far ERANGE, ENOENT
> > and EFAULT are checked.
> > 
> > Test is based on llistxattr02 test from LTP.
> 
> Any reason porting this from LTP? I think LTP is the right place for
> such syscall level tests, this test should stay there, or extend
> llistxattr02 test if you want to test new errnos.

It's pretty clear that nobody is actually using LTP in their
day-to-day development work-flow. It's a pain to build and
configure and it wants to write to places it shouldn't.

I asked that this test be added to xfstests, and that's especially
important because I can't reproduce the reported problem with LTP.
Hence we need to work out a reliable reproducer, and really that
belongs in xfstests along with all the other xattr tests we run.

> > Signed-off-by: Artem Savkov <asavkov@redhat.com>
> > ---
> >  .gitignore            |  1 +
> >  src/Makefile          |  2 +-
> >  src/listxattr_fails.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
> >  tests/generic/337     |  4 ++++
> >  tests/generic/337.out |  3 +++
> >  5 files changed, 60 insertions(+), 1 deletion(-)
> >  create mode 100644 src/listxattr_fails.c
> > 
> > diff --git a/.gitignore b/.gitignore
> > index d84f385..613d245 100644
> > --- a/.gitignore
> > +++ b/.gitignore
> > @@ -66,6 +66,7 @@
> >  /src/holes
> >  /src/holetest
> >  /src/itrash
> > +/src/listxattr_fails

Not the best name for a test program. Better is to write a simple
tool that runs listxattr with a buffer size specified on the command
line. That way it canbe used for more than just the specific test
case. e.g. we can test corner cases rather than jsut "is the buffer
too small?" by creating specific combinations of extended attributes
and then calling the listxattr tool with different buffer sizes...

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2] Add a test for listxattr syscall with different buffer sizes.
  2016-08-25  5:57   ` Dave Chinner
@ 2016-08-25 11:01     ` Artem Savkov
  2016-08-26  5:18       ` Dave Chinner
  0 siblings, 1 reply; 9+ messages in thread
From: Artem Savkov @ 2016-08-25 11:01 UTC (permalink / raw)
  To: fstests; +Cc: Dave Chinner, Eryu Guan, Filipe Manana, Artem Savkov

Add generic/375 test that calls listxattr syscall with different buffer size
arguments checking if it fails properly.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
---
 .gitignore            |  1 +
 src/Makefile          |  2 +-
 src/listxattr.c       | 55 +++++++++++++++++++++++++++++++++++++++++++++
 tests/generic/375     | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/generic/375.out | 10 +++++++++
 tests/generic/group   |  1 +
 6 files changed, 130 insertions(+), 1 deletion(-)
 create mode 100644 src/listxattr.c
 create mode 100755 tests/generic/375
 create mode 100644 tests/generic/375.out

diff --git a/.gitignore b/.gitignore
index d84f385..915d2d8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -66,6 +66,7 @@
 /src/holes
 /src/holetest
 /src/itrash
+/src/listxattr
 /src/locktest
 /src/loggen
 /src/looptest
diff --git a/src/Makefile b/src/Makefile
index 57b0df1..dd51216 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -21,7 +21,7 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \
 	stale_handle pwrite_mmap_blocked t_dir_offset2 seek_sanity_test \
 	seek_copy_test t_readdir_1 t_readdir_2 fsync-tester nsexec cloner \
 	renameat2 t_getcwd e4compact test-nextquota punch-alternating \
-	attr-list-by-handle-cursor-test
+	attr-list-by-handle-cursor-test listxattr
 
 SUBDIRS =
 
diff --git a/src/listxattr.c b/src/listxattr.c
new file mode 100644
index 0000000..7fdccb5
--- /dev/null
+++ b/src/listxattr.c
@@ -0,0 +1,55 @@
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/xattr.h>
+
+int main(int argc, char **argv)
+{
+  int ret;
+  size_t bufsize = 0;
+  char *buf = NULL;
+
+  if (argc < 2) {
+    fprintf(stderr, "usage: %s <testfile> [bufsize]\n", argv[0]);
+    return 1;
+  };
+
+  if (argc == 3) {
+    bufsize = strtoul(argv[2], NULL, 10);
+    if (bufsize == -1) {
+      perror("buffsize");
+      return 1;
+    }
+  }
+
+  if (bufsize == 0) {
+    bufsize = listxattr(argv[1], buf, 0);
+    if (bufsize == -1) {
+      fprintf(stderr, "listxattr failed with %d\n", -errno);
+      return 1;
+    }
+  }
+
+  buf = malloc(bufsize + 1);
+  if (buf == NULL) {
+    perror("buf alloc");
+    return 1;
+  }
+
+  ret = listxattr(argv[1], buf, bufsize);
+  if (ret < 0) {
+    fprintf(stderr, "listxattr failed with %d\n", -errno);
+  } else {
+    char *l;
+    for (l = buf; l != (buf + bufsize) && *l != '\0'; l = strchr(l, '\0') + 1) {
+      printf("xattr: %s\n", l);
+    }
+  }
+
+  free(buf);
+
+  return 0;
+}
diff --git a/tests/generic/375 b/tests/generic/375
new file mode 100755
index 0000000..ad7b168
--- /dev/null
+++ b/tests/generic/375
@@ -0,0 +1,62 @@
+#! /bin/bash
+# FSQA Test No. 375
+#
+# Test listxattr syscall behaviour with different buffer sizes.
+#
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+tmp=/tmp/$$
+status=1	# failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+	cd /
+	rm -f $tmp.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+. ./common/attr
+
+# real QA test starts here
+_supported_fs generic
+_supported_os Linux
+_require_scratch
+_require_attrs
+
+rm -f $seqres.full
+
+_scratch_mkfs >>$seqres.full 2>&1
+_scratch_mount
+
+# Create a testfile with multiple xattrs.
+TESTFILE=${SCRATCH_MNT}/testfile
+touch $TESTFILE
+$SETFATTR_PROG -n user.foo -v bar $TESTFILE
+$SETFATTR_PROG -n user.ping -v pong $TESTFILE
+$SETFATTR_PROG -n user.xxxx -v yyyy $TESTFILE
+
+# Call listxattr without buffer length argument. This should succeed.
+$here/src/listxattr $TESTFILE
+
+# Calling listxattr on nonexistant file should fail with -ENOENT.
+$here/src/listxattr ""
+
+# Calling listxattr with buffersize not suffecient for even one xattr should
+# fail with -ERANGE.
+$here/src/listxattr $TESTFILE 1
+
+# Calling listxattr with buffersize suffecient for one xattr, but not
+# sufficient for the whole list should still fail with -ERANGE.
+$here/src/listxattr $TESTFILE 9
+
+# Calling listxattr with buffersize not suffecient for even one xattr should
+# fail with -ERANGE.
+$here/src/listxattr $TESTFILE 500
+
+status=0
+exit
diff --git a/tests/generic/375.out b/tests/generic/375.out
new file mode 100644
index 0000000..0c02a83
--- /dev/null
+++ b/tests/generic/375.out
@@ -0,0 +1,10 @@
+QA output created by 375
+xattr: user.foo
+xattr: user.ping
+xattr: user.xxxx
+listxattr failed with -2
+listxattr failed with -34
+listxattr failed with -34
+xattr: user.foo
+xattr: user.ping
+xattr: user.xxxx
diff --git a/tests/generic/group b/tests/generic/group
index ef38c35..3068510 100644
--- a/tests/generic/group
+++ b/tests/generic/group
@@ -377,3 +377,4 @@
 372 auto quick clone
 373 auto quick clone
 374 auto quick clone dedupe
+375 auto quick metadata
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] Add a test for listxattr syscall with different buffer sizes.
  2016-08-25 11:01     ` [PATCH v2] Add a test for listxattr syscall with different buffer sizes Artem Savkov
@ 2016-08-26  5:18       ` Dave Chinner
  2016-08-26 11:31         ` [PATCH v3] " Artem Savkov
  0 siblings, 1 reply; 9+ messages in thread
From: Dave Chinner @ 2016-08-26  5:18 UTC (permalink / raw)
  To: Artem Savkov; +Cc: fstests, Eryu Guan, Filipe Manana

On Thu, Aug 25, 2016 at 01:01:33PM +0200, Artem Savkov wrote:
> Add generic/375 test that calls listxattr syscall with different buffer size
> arguments checking if it fails properly.
> 
> Signed-off-by: Artem Savkov <asavkov@redhat.com>
> ---
>  .gitignore            |  1 +
>  src/Makefile          |  2 +-
>  src/listxattr.c       | 55 +++++++++++++++++++++++++++++++++++++++++++++
>  tests/generic/375     | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  tests/generic/375.out | 10 +++++++++
>  tests/generic/group   |  1 +
>  6 files changed, 130 insertions(+), 1 deletion(-)
>  create mode 100644 src/listxattr.c
>  create mode 100755 tests/generic/375
>  create mode 100644 tests/generic/375.out
> 
> diff --git a/.gitignore b/.gitignore
> index d84f385..915d2d8 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -66,6 +66,7 @@
>  /src/holes
>  /src/holetest
>  /src/itrash
> +/src/listxattr
>  /src/locktest
>  /src/loggen
>  /src/looptest
> diff --git a/src/Makefile b/src/Makefile
> index 57b0df1..dd51216 100644
> --- a/src/Makefile
> +++ b/src/Makefile
> @@ -21,7 +21,7 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \
>  	stale_handle pwrite_mmap_blocked t_dir_offset2 seek_sanity_test \
>  	seek_copy_test t_readdir_1 t_readdir_2 fsync-tester nsexec cloner \
>  	renameat2 t_getcwd e4compact test-nextquota punch-alternating \
> -	attr-list-by-handle-cursor-test
> +	attr-list-by-handle-cursor-test listxattr
>  
>  SUBDIRS =
>  
> diff --git a/src/listxattr.c b/src/listxattr.c
> new file mode 100644
> index 0000000..7fdccb5
> --- /dev/null
> +++ b/src/listxattr.c
> @@ -0,0 +1,55 @@

License, copyright.

> +#include <errno.h>
> +#include <fcntl.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <sys/types.h>
> +#include <sys/xattr.h>
> +
> +int main(int argc, char **argv)
> +{
> +  int ret;
> +  size_t bufsize = 0;
> +  char *buf = NULL;
> +
> +  if (argc < 2) {
> +    fprintf(stderr, "usage: %s <testfile> [bufsize]\n", argv[0]);
> +    return 1;
> +  };

Please use 8 space tabs for all new code in xfstests.

> +
> +  if (argc == 3) {
> +    bufsize = strtoul(argv[2], NULL, 10);
> +    if (bufsize == -1) {
> +      perror("buffsize");
> +      return 1;
> +    }
> +  }
> +
> +  if (bufsize == 0) {
> +    bufsize = listxattr(argv[1], buf, 0);
> +    if (bufsize == -1) {
> +      fprintf(stderr, "listxattr failed with %d\n", -errno);

	perror("listxattr:");

> +      return 1;
> +    }
> +  }
> +
> +  buf = malloc(bufsize + 1);
> +  if (buf == NULL) {
> +    perror("buf alloc");
> +    return 1;
> +  }
> +
> +  ret = listxattr(argv[1], buf, bufsize);
> +  if (ret < 0) {
> +    fprintf(stderr, "listxattr failed with %d\n", -errno);

	perror("listxattr:");

> +  } else {
> +    char *l;
> +    for (l = buf; l != (buf + bufsize) && *l != '\0'; l = strchr(l, '\0') + 1) {
> +      printf("xattr: %s\n", l);
> +    }
> +  }
> +
> +  free(buf);
> +
> +  return 0;
> +}
> diff --git a/tests/generic/375 b/tests/generic/375
> new file mode 100755
> index 0000000..ad7b168
> --- /dev/null
> +++ b/tests/generic/375
> @@ -0,0 +1,62 @@
> +#! /bin/bash
> +# FSQA Test No. 375
> +#
> +# Test listxattr syscall behaviour with different buffer sizes.
> +#

Why did you remove the license and copyright statement from the
template? Please add them back in when you resend.

> +
> +seq=`basename $0`
> +seqres=$RESULT_DIR/$seq
> +echo "QA output created by $seq"
> +tmp=/tmp/$$
> +status=1	# failure is the default!
> +trap "_cleanup; exit \$status" 0 1 2 3 15
> +
> +_cleanup()
> +{
> +	cd /
> +	rm -f $tmp.*
> +}
> +
> +# get standard environment, filters and checks
> +. ./common/rc
> +. ./common/filter
> +. ./common/attr
> +
> +# real QA test starts here
> +_supported_fs generic
> +_supported_os Linux
> +_require_scratch
> +_require_attrs

_require_test_program "listxattr"

listxattr="$here/src/listxattr"

> +
> +rm -f $seqres.full
> +
> +_scratch_mkfs >>$seqres.full 2>&1
> +_scratch_mount
> +
> +# Create a testfile with multiple xattrs.
> +TESTFILE=${SCRATCH_MNT}/testfile
> +touch $TESTFILE

testfile, not TESTFILE.

i.e. local variables use lower case, harness provided/global
variables use upper case.

> +$SETFATTR_PROG -n user.foo -v bar $TESTFILE
> +$SETFATTR_PROG -n user.ping -v pong $TESTFILE
> +$SETFATTR_PROG -n user.xxxx -v yyyy $TESTFILE

Why only 3 attributes? A small comment explaining the reason for the
initial conditions helps a lot here.

> +
> +# Call listxattr without buffer length argument. This should succeed.
> +$here/src/listxattr $TESTFILE

$listxattr $testfile

> +
> +# Calling listxattr on nonexistant file should fail with -ENOENT.
> +$here/src/listxattr ""
> +
> +# Calling listxattr with buffersize not suffecient for even one xattr should
> +# fail with -ERANGE.
> +$here/src/listxattr $TESTFILE 1
> +
> +# Calling listxattr with buffersize sufficient for one xattr, but not
> +# sufficient for the whole list should still fail with -ERANGE.
> +$here/src/listxattr $TESTFILE 9
> +
> +# Calling listxattr with buffersize not suffecient for even one xattr should
> +# fail with -ERANGE.
> +$here/src/listxattr $TESTFILE 500

Comment above this case is wrong.

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v3] Add a test for listxattr syscall with different buffer sizes.
  2016-08-26  5:18       ` Dave Chinner
@ 2016-08-26 11:31         ` Artem Savkov
  2016-08-30  4:35           ` Eryu Guan
  2016-08-30  6:06           ` [PATCH v3] " Dave Chinner
  0 siblings, 2 replies; 9+ messages in thread
From: Artem Savkov @ 2016-08-26 11:31 UTC (permalink / raw)
  To: fstests; +Cc: Dave Chinner, Eryu Guan, Filipe Manana, Artem Savkov

Add generic/375 test that calls listxattr syscall with different buffer size
arguments checking if it fails properly.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
---
 .gitignore            |  1 +
 src/Makefile          |  2 +-
 src/listxattr.c       | 73 ++++++++++++++++++++++++++++++++++++++++++
 tests/generic/375     | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/generic/375.out | 11 +++++++
 tests/generic/group   |  1 +
 6 files changed, 174 insertions(+), 1 deletion(-)
 create mode 100644 src/listxattr.c
 create mode 100755 tests/generic/375
 create mode 100644 tests/generic/375.out

diff --git a/.gitignore b/.gitignore
index d84f385..915d2d8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -66,6 +66,7 @@
 /src/holes
 /src/holetest
 /src/itrash
+/src/listxattr
 /src/locktest
 /src/loggen
 /src/looptest
diff --git a/src/Makefile b/src/Makefile
index 57b0df1..dd51216 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -21,7 +21,7 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \
 	stale_handle pwrite_mmap_blocked t_dir_offset2 seek_sanity_test \
 	seek_copy_test t_readdir_1 t_readdir_2 fsync-tester nsexec cloner \
 	renameat2 t_getcwd e4compact test-nextquota punch-alternating \
-	attr-list-by-handle-cursor-test
+	attr-list-by-handle-cursor-test listxattr
 
 SUBDIRS =
 
diff --git a/src/listxattr.c b/src/listxattr.c
new file mode 100644
index 0000000..da9d163
--- /dev/null
+++ b/src/listxattr.c
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2016 Artem Savkov <asavkov@redhat.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it would 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 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/xattr.h>
+
+int main(int argc, char **argv)
+{
+        int ret;
+        size_t bufsize = 0;
+        char *buf = NULL;
+
+        if (argc < 2) {
+                fprintf(stderr, "usage: %s <testfile> [bufsize]\n", argv[0]);
+                return 1;
+        };
+
+        if (argc > 2) {
+                bufsize = strtoul(argv[2], NULL, 10);
+                if (bufsize == -1) {
+                        perror("buffsize");
+                        return 1;
+                }
+        }
+
+        if (bufsize == 0) {
+                bufsize = listxattr(argv[1], NULL, 0);
+                if (bufsize == -1) {
+                        perror("listxattr");
+                        return 1;
+                }
+        }
+
+        buf = malloc(bufsize);
+        if (buf == NULL) {
+                perror("buf alloc");
+                return 1;
+        }
+
+        ret = listxattr(argv[1], buf, bufsize);
+        if (ret < 0) {
+                perror("listxattr");
+        } else {
+                char *l;
+                for (l = buf; l != (buf + bufsize) && *l != '\0';
+                                l = strchr(l, '\0') + 1) {
+                        printf("xattr: %s\n", l);
+                }
+        }
+
+        free(buf);
+
+        return 0;
+}
diff --git a/tests/generic/375 b/tests/generic/375
new file mode 100755
index 0000000..8651c7d
--- /dev/null
+++ b/tests/generic/375
@@ -0,0 +1,87 @@
+#! /bin/bash
+# FSQA Test No. 375
+#
+# Test listxattr syscall behaviour with different buffer sizes.
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2016 Artem Savkov <asavkov@redhat.com>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation, either version 2 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it would 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 for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, see <http://www.gnu.org/licenses/>.
+#-----------------------------------------------------------------------
+#
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+tmp=/tmp/$$
+status=1	# failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+	cd /
+	rm -f $tmp.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+. ./common/attr
+
+# real QA test starts here
+_supported_fs generic
+_supported_os Linux
+_require_scratch
+_require_attrs
+_require_test_program "listxattr"
+
+listxattr="$here/src/listxattr"
+
+rm -f $seqres.full
+
+_scratch_mkfs >>$seqres.full 2>&1
+_scratch_mount
+
+# Create a testfile with three xattrs such that the sum of namelengths of the
+# first two is bigger than the namelength of the third. This is needed for
+# the 5th testcase that tests one of the cornercases.
+testfile=${SCRATCH_MNT}/testfile
+touch $testfile
+$SETFATTR_PROG -n user.foo -v bar $testfile
+$SETFATTR_PROG -n user.ping -v pong $testfile
+$SETFATTR_PROG -n user.hello -v there $testfile
+
+# 1. Call listxattr without buffer length argument. This should succeed.
+$listxattr $testfile
+
+# 2. Calling listxattr on nonexistant file should fail with -ENOENT.
+$listxattr ""
+
+# 3. Calling listxattr with buffersize not suffecient for even one xattr
+# should fail with -ERANGE.
+$listxattr $testfile 1
+
+# 4. Calling listxattr with buffersize suffecient for one xattr, but not
+# sufficient for the whole list should still fail with -ERANGE.
+$listxattr $testfile 9
+
+# 5. Calling listxattr with buffersize suffecient for the last xattr, but not
+# sufficient for the sum of first two. Should fail with -ERANGE.
+$listxattr $testfile 11
+
+# 6. Calling listxattr with buffersize bigger than needed should succeed.
+$listxattr $testfile 500
+
+status=0
+exit
diff --git a/tests/generic/375.out b/tests/generic/375.out
new file mode 100644
index 0000000..0d45622
--- /dev/null
+++ b/tests/generic/375.out
@@ -0,0 +1,11 @@
+QA output created by 375
+xattr: user.foo
+xattr: user.ping
+xattr: user.hello
+listxattr: No such file or directory
+listxattr: Numerical result out of range
+listxattr: Numerical result out of range
+listxattr: Numerical result out of range
+xattr: user.foo
+xattr: user.ping
+xattr: user.hello
diff --git a/tests/generic/group b/tests/generic/group
index ef38c35..3068510 100644
--- a/tests/generic/group
+++ b/tests/generic/group
@@ -377,3 +377,4 @@
 372 auto quick clone
 373 auto quick clone
 374 auto quick clone dedupe
+375 auto quick metadata
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v3] Add a test for listxattr syscall with different buffer sizes.
  2016-08-26 11:31         ` [PATCH v3] " Artem Savkov
@ 2016-08-30  4:35           ` Eryu Guan
  2016-08-30  7:39             ` [PATCH v4] " Artem Savkov
  2016-08-30  6:06           ` [PATCH v3] " Dave Chinner
  1 sibling, 1 reply; 9+ messages in thread
From: Eryu Guan @ 2016-08-30  4:35 UTC (permalink / raw)
  To: Artem Savkov; +Cc: fstests, Dave Chinner, Filipe Manana

On Fri, Aug 26, 2016 at 01:31:14PM +0200, Artem Savkov wrote:
> Add generic/375 test that calls listxattr syscall with different buffer size
> arguments checking if it fails properly.
> 
> Signed-off-by: Artem Savkov <asavkov@redhat.com>
> ---
>  .gitignore            |  1 +
>  src/Makefile          |  2 +-
>  src/listxattr.c       | 73 ++++++++++++++++++++++++++++++++++++++++++
>  tests/generic/375     | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  tests/generic/375.out | 11 +++++++
>  tests/generic/group   |  1 +
>  6 files changed, 174 insertions(+), 1 deletion(-)
>  create mode 100644 src/listxattr.c
>  create mode 100755 tests/generic/375
>  create mode 100644 tests/generic/375.out
> 
> diff --git a/.gitignore b/.gitignore
> index d84f385..915d2d8 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -66,6 +66,7 @@
>  /src/holes
>  /src/holetest
>  /src/itrash
> +/src/listxattr
>  /src/locktest
>  /src/loggen
>  /src/looptest
> diff --git a/src/Makefile b/src/Makefile
> index 57b0df1..dd51216 100644
> --- a/src/Makefile
> +++ b/src/Makefile
> @@ -21,7 +21,7 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \
>  	stale_handle pwrite_mmap_blocked t_dir_offset2 seek_sanity_test \
>  	seek_copy_test t_readdir_1 t_readdir_2 fsync-tester nsexec cloner \
>  	renameat2 t_getcwd e4compact test-nextquota punch-alternating \
> -	attr-list-by-handle-cursor-test
> +	attr-list-by-handle-cursor-test listxattr
>  
>  SUBDIRS =
>  
> diff --git a/src/listxattr.c b/src/listxattr.c
> new file mode 100644
> index 0000000..da9d163
> --- /dev/null
> +++ b/src/listxattr.c
> @@ -0,0 +1,73 @@
> +/*
> + * Copyright (c) 2016 Artem Savkov <asavkov@redhat.com>
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation, either version 2 of
> + * the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it would 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 for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <errno.h>
> +#include <fcntl.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <sys/types.h>
> +#include <sys/xattr.h>
> +
> +int main(int argc, char **argv)
> +{
> +        int ret;
> +        size_t bufsize = 0;
> +        char *buf = NULL;
> +
> +        if (argc < 2) {
> +                fprintf(stderr, "usage: %s <testfile> [bufsize]\n", argv[0]);
> +                return 1;
> +        };
> +
> +        if (argc > 2) {
> +                bufsize = strtoul(argv[2], NULL, 10);
> +                if (bufsize == -1) {
> +                        perror("buffsize");
> +                        return 1;
> +                }
> +        }
> +
> +        if (bufsize == 0) {
> +                bufsize = listxattr(argv[1], NULL, 0);
> +                if (bufsize == -1) {
> +                        perror("listxattr");
> +                        return 1;
> +                }
> +        }
> +
> +        buf = malloc(bufsize);
> +        if (buf == NULL) {
> +                perror("buf alloc");
> +                return 1;
> +        }
> +
> +        ret = listxattr(argv[1], buf, bufsize);
> +        if (ret < 0) {
> +                perror("listxattr");
> +        } else {
> +                char *l;
> +                for (l = buf; l != (buf + bufsize) && *l != '\0';
> +                                l = strchr(l, '\0') + 1) {
> +                        printf("xattr: %s\n", l);
> +                }
> +        }
> +
> +        free(buf);
> +
> +        return 0;
> +}
> diff --git a/tests/generic/375 b/tests/generic/375
> new file mode 100755
> index 0000000..8651c7d
> --- /dev/null
> +++ b/tests/generic/375
> @@ -0,0 +1,87 @@
> +#! /bin/bash
> +# FSQA Test No. 375
> +#
> +# Test listxattr syscall behaviour with different buffer sizes.
> +#
> +#-----------------------------------------------------------------------
> +# Copyright (c) 2016 Artem Savkov <asavkov@redhat.com>
> +#
> +# This program is free software; you can redistribute it and/or
> +# modify it under the terms of the GNU General Public License as
> +# published by the Free Software Foundation, either version 2 of
> +# the License, or (at your option) any later version.
> +#
> +# This program is distributed in the hope that it would 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 for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program; if not, see <http://www.gnu.org/licenses/>.
> +#-----------------------------------------------------------------------
> +#
> +
> +seq=`basename $0`
> +seqres=$RESULT_DIR/$seq
> +echo "QA output created by $seq"
> +tmp=/tmp/$$
> +status=1	# failure is the default!
> +trap "_cleanup; exit \$status" 0 1 2 3 15
> +
> +_cleanup()
> +{
> +	cd /
> +	rm -f $tmp.*
> +}
> +
> +# get standard environment, filters and checks
> +. ./common/rc
> +. ./common/filter
> +. ./common/attr
> +
> +# real QA test starts here
> +_supported_fs generic
> +_supported_os Linux
> +_require_scratch
> +_require_attrs
> +_require_test_program "listxattr"
> +
> +listxattr="$here/src/listxattr"
> +
> +rm -f $seqres.full
> +
> +_scratch_mkfs >>$seqres.full 2>&1
> +_scratch_mount
> +
> +# Create a testfile with three xattrs such that the sum of namelengths of the
> +# first two is bigger than the namelength of the third. This is needed for
> +# the 5th testcase that tests one of the cornercases.
> +testfile=${SCRATCH_MNT}/testfile
> +touch $testfile
> +$SETFATTR_PROG -n user.foo -v bar $testfile
> +$SETFATTR_PROG -n user.ping -v pong $testfile
> +$SETFATTR_PROG -n user.hello -v there $testfile
> +
> +# 1. Call listxattr without buffer length argument. This should succeed.
> +$listxattr $testfile

This fails for me on btrfs as:
[root@dhcp-66-86-11 xfstests]# diff -u tests/generic/375.out /root/workspace/xfstests/results//btrfs/generic/375.out.bad
--- tests/generic/375.out       2016-08-30 12:23:06.827000000 +0800
+++ /root/workspace/xfstests/results//btrfs/generic/375.out.bad 2016-08-30 12:28:48.392000000 +0800
@@ -1,11 +1,11 @@
 QA output created by 375
-xattr: user.foo
 xattr: user.ping
 xattr: user.hello
+xattr: user.foo
 listxattr: No such file or directory
 listxattr: Numerical result out of range
 listxattr: Numerical result out of range
 listxattr: Numerical result out of range
-xattr: user.foo
 xattr: user.ping
 xattr: user.hello
+xattr: user.foo

Seems btrfs returns xattrs in a different order, perhaps you need to
sort the results in the test?

> +
> +# 2. Calling listxattr on nonexistant file should fail with -ENOENT.
> +$listxattr ""
> +
> +# 3. Calling listxattr with buffersize not suffecient for even one xattr
> +# should fail with -ERANGE.
> +$listxattr $testfile 1
> +
> +# 4. Calling listxattr with buffersize suffecient for one xattr, but not
> +# sufficient for the whole list should still fail with -ERANGE.
> +$listxattr $testfile 9
> +
> +# 5. Calling listxattr with buffersize suffecient for the last xattr, but not
> +# sufficient for the sum of first two. Should fail with -ERANGE.
> +$listxattr $testfile 11
> +
> +# 6. Calling listxattr with buffersize bigger than needed should succeed.
> +$listxattr $testfile 500
> +
> +status=0
> +exit
> diff --git a/tests/generic/375.out b/tests/generic/375.out
> new file mode 100644
> index 0000000..0d45622
> --- /dev/null
> +++ b/tests/generic/375.out
> @@ -0,0 +1,11 @@
> +QA output created by 375
> +xattr: user.foo
> +xattr: user.ping
> +xattr: user.hello
> +listxattr: No such file or directory
> +listxattr: Numerical result out of range
> +listxattr: Numerical result out of range
> +listxattr: Numerical result out of range
> +xattr: user.foo
> +xattr: user.ping
> +xattr: user.hello
> diff --git a/tests/generic/group b/tests/generic/group
> index ef38c35..3068510 100644
> --- a/tests/generic/group
> +++ b/tests/generic/group
> @@ -377,3 +377,4 @@
>  372 auto quick clone
>  373 auto quick clone
>  374 auto quick clone dedupe
> +375 auto quick metadata

Add 'attr' group too?

Thanks,
Eryu

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3] Add a test for listxattr syscall with different buffer sizes.
  2016-08-26 11:31         ` [PATCH v3] " Artem Savkov
  2016-08-30  4:35           ` Eryu Guan
@ 2016-08-30  6:06           ` Dave Chinner
  1 sibling, 0 replies; 9+ messages in thread
From: Dave Chinner @ 2016-08-30  6:06 UTC (permalink / raw)
  To: Artem Savkov; +Cc: fstests, Eryu Guan, Filipe Manana

On Fri, Aug 26, 2016 at 01:31:14PM +0200, Artem Savkov wrote:
> Add generic/375 test that calls listxattr syscall with different buffer size
> arguments checking if it fails properly.
> 
> Signed-off-by: Artem Savkov <asavkov@redhat.com>
> ---
>  .gitignore            |  1 +
>  src/Makefile          |  2 +-
>  src/listxattr.c       | 73 ++++++++++++++++++++++++++++++++++++++++++
>  tests/generic/375     | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  tests/generic/375.out | 11 +++++++
>  tests/generic/group   |  1 +
>  6 files changed, 174 insertions(+), 1 deletion(-)
>  create mode 100644 src/listxattr.c
>  create mode 100755 tests/generic/375
>  create mode 100644 tests/generic/375.out
> 
> diff --git a/.gitignore b/.gitignore
> index d84f385..915d2d8 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -66,6 +66,7 @@
>  /src/holes
>  /src/holetest
>  /src/itrash
> +/src/listxattr
>  /src/locktest
>  /src/loggen
>  /src/looptest
> diff --git a/src/Makefile b/src/Makefile
> index 57b0df1..dd51216 100644
> --- a/src/Makefile
> +++ b/src/Makefile
> @@ -21,7 +21,7 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \
>  	stale_handle pwrite_mmap_blocked t_dir_offset2 seek_sanity_test \
>  	seek_copy_test t_readdir_1 t_readdir_2 fsync-tester nsexec cloner \
>  	renameat2 t_getcwd e4compact test-nextquota punch-alternating \
> -	attr-list-by-handle-cursor-test
> +	attr-list-by-handle-cursor-test listxattr
>  
>  SUBDIRS =
>  
> diff --git a/src/listxattr.c b/src/listxattr.c
> new file mode 100644
> index 0000000..da9d163
> --- /dev/null
> +++ b/src/listxattr.c
> @@ -0,0 +1,73 @@
> +/*
> + * Copyright (c) 2016 Artem Savkov <asavkov@redhat.com>

This is somewhat contradictory  and quite ambiguous - a personal
copyright assertion from with your employer's email contact and a
s-o-b from the same address. If it's your own personal copyright,
then please use a private email address. i.e

Copyright (c) 2016 Artem Savkov <personal email address>

And the patch needs to have a S-o-B that matches the copyright
statement.

However, you're doing all this work under a @redhat.com email
address, it tends to mean the work is not owned directly by you
but your employer, and hence the copywrite statement needs to be:

Copyright (c) 2016 Red Hat, Inc. All rights reserved.

I know, I'm being a pendant, but copyright is a legal construct and
we need to be certain that it is correct and unambigious. If you
have any doubt about whether you or your company owns the copyright
for work you do on their behalf, please refer to your company legal
counsel for advice...

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v4] Add a test for listxattr syscall with different buffer sizes.
  2016-08-30  4:35           ` Eryu Guan
@ 2016-08-30  7:39             ` Artem Savkov
  0 siblings, 0 replies; 9+ messages in thread
From: Artem Savkov @ 2016-08-30  7:39 UTC (permalink / raw)
  To: Eryu Guan; +Cc: fstests, Dave Chinner, Artem Savkov

Add generic/375 test that calls listxattr syscall with different buffer size
arguments checking if it fails properly.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
---
 .gitignore            |  1 +
 src/Makefile          |  2 +-
 src/listxattr.c       | 73 ++++++++++++++++++++++++++++++++++++++++++
 tests/generic/375     | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/generic/375.out | 11 +++++++
 tests/generic/group   |  1 +
 6 files changed, 174 insertions(+), 1 deletion(-)
 create mode 100644 src/listxattr.c
 create mode 100755 tests/generic/375
 create mode 100644 tests/generic/375.out

diff --git a/.gitignore b/.gitignore
index d84f385..915d2d8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -66,6 +66,7 @@
 /src/holes
 /src/holetest
 /src/itrash
+/src/listxattr
 /src/locktest
 /src/loggen
 /src/looptest
diff --git a/src/Makefile b/src/Makefile
index 57b0df1..dd51216 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -21,7 +21,7 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \
 	stale_handle pwrite_mmap_blocked t_dir_offset2 seek_sanity_test \
 	seek_copy_test t_readdir_1 t_readdir_2 fsync-tester nsexec cloner \
 	renameat2 t_getcwd e4compact test-nextquota punch-alternating \
-	attr-list-by-handle-cursor-test
+	attr-list-by-handle-cursor-test listxattr
 
 SUBDIRS =
 
diff --git a/src/listxattr.c b/src/listxattr.c
new file mode 100644
index 0000000..cd46637
--- /dev/null
+++ b/src/listxattr.c
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2016 Red Hat, Inc.  All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it would 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 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/xattr.h>
+
+int main(int argc, char **argv)
+{
+        int ret;
+        size_t bufsize = 0;
+        char *buf = NULL;
+
+        if (argc < 2) {
+                fprintf(stderr, "usage: %s <testfile> [bufsize]\n", argv[0]);
+                return 1;
+        };
+
+        if (argc > 2) {
+                bufsize = strtoul(argv[2], NULL, 10);
+                if (bufsize == -1) {
+                        perror("buffsize");
+                        return 1;
+                }
+        }
+
+        if (bufsize == 0) {
+                bufsize = listxattr(argv[1], NULL, 0);
+                if (bufsize == -1) {
+                        perror("listxattr");
+                        return 1;
+                }
+        }
+
+        buf = malloc(bufsize);
+        if (buf == NULL) {
+                perror("buf alloc");
+                return 1;
+        }
+
+        ret = listxattr(argv[1], buf, bufsize);
+        if (ret < 0) {
+                perror("listxattr");
+        } else {
+                char *l;
+                for (l = buf; l != (buf + bufsize) && *l != '\0';
+                                l = strchr(l, '\0') + 1) {
+                        printf("xattr: %s\n", l);
+                }
+        }
+
+        free(buf);
+
+        return 0;
+}
diff --git a/tests/generic/375 b/tests/generic/375
new file mode 100755
index 0000000..6e85f46
--- /dev/null
+++ b/tests/generic/375
@@ -0,0 +1,87 @@
+#! /bin/bash
+# FSQA Test No. 375
+#
+# Test listxattr syscall behaviour with different buffer sizes.
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2016 Red Hat, Inc.  All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation, either version 2 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it would 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 for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, see <http://www.gnu.org/licenses/>.
+#-----------------------------------------------------------------------
+#
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+tmp=/tmp/$$
+status=1	# failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+	cd /
+	rm -f $tmp.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+. ./common/attr
+
+# real QA test starts here
+_supported_fs generic
+_supported_os Linux
+_require_scratch
+_require_attrs
+_require_test_program "listxattr"
+
+listxattr="$here/src/listxattr"
+
+rm -f $seqres.full
+
+_scratch_mkfs >>$seqres.full 2>&1
+_scratch_mount
+
+# Create a testfile with three xattrs such that the sum of namelengths of the
+# first two is bigger than the namelength of the third. This is needed for
+# the 5th testcase that tests one of the cornercases.
+testfile=${SCRATCH_MNT}/testfile
+touch $testfile
+$SETFATTR_PROG -n user.foo -v bar $testfile
+$SETFATTR_PROG -n user.ping -v pong $testfile
+$SETFATTR_PROG -n user.hello -v there $testfile
+
+# 1. Call listxattr without buffer length argument. This should succeed.
+$listxattr $testfile | sort
+
+# 2. Calling listxattr on nonexistant file should fail with -ENOENT.
+$listxattr ""
+
+# 3. Calling listxattr with buffersize not suffecient for even one xattr
+# should fail with -ERANGE.
+$listxattr $testfile 1
+
+# 4. Calling listxattr with buffersize suffecient for one xattr, but not
+# sufficient for the whole list should still fail with -ERANGE.
+$listxattr $testfile 9
+
+# 5. Calling listxattr with buffersize suffecient for the last xattr, but not
+# sufficient for the sum of first two. Should fail with -ERANGE.
+$listxattr $testfile 11
+
+# 6. Calling listxattr with buffersize bigger than needed should succeed.
+$listxattr $testfile 500 | sort
+
+status=0
+exit
diff --git a/tests/generic/375.out b/tests/generic/375.out
new file mode 100644
index 0000000..820f40c
--- /dev/null
+++ b/tests/generic/375.out
@@ -0,0 +1,11 @@
+QA output created by 375
+xattr: user.foo
+xattr: user.hello
+xattr: user.ping
+listxattr: No such file or directory
+listxattr: Numerical result out of range
+listxattr: Numerical result out of range
+listxattr: Numerical result out of range
+xattr: user.foo
+xattr: user.hello
+xattr: user.ping
diff --git a/tests/generic/group b/tests/generic/group
index ef38c35..f5aea8d 100644
--- a/tests/generic/group
+++ b/tests/generic/group
@@ -377,3 +377,4 @@
 372 auto quick clone
 373 auto quick clone
 374 auto quick clone dedupe
+375 attr auto quick metadata
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2016-08-30  7:39 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-24 11:55 [PATCH] generic/337: add checks for listxattr call fails Artem Savkov
2016-08-25  4:09 ` Eryu Guan
2016-08-25  5:57   ` Dave Chinner
2016-08-25 11:01     ` [PATCH v2] Add a test for listxattr syscall with different buffer sizes Artem Savkov
2016-08-26  5:18       ` Dave Chinner
2016-08-26 11:31         ` [PATCH v3] " Artem Savkov
2016-08-30  4:35           ` Eryu Guan
2016-08-30  7:39             ` [PATCH v4] " Artem Savkov
2016-08-30  6:06           ` [PATCH v3] " Dave Chinner

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.