From patchwork Thu Aug 25 11:01:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artem Savkov X-Patchwork-Id: 9299221 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6CA2360757 for ; Thu, 25 Aug 2016 11:01:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 54C7A29272 for ; Thu, 25 Aug 2016 11:01:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 48B7D29274; Thu, 25 Aug 2016 11:01:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 970B529272 for ; Thu, 25 Aug 2016 11:01:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758040AbcHYLBp (ORCPT ); Thu, 25 Aug 2016 07:01:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38086 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758044AbcHYLBo (ORCPT ); Thu, 25 Aug 2016 07:01:44 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A188919CF94; Thu, 25 Aug 2016 11:01:39 +0000 (UTC) Received: from shodan.usersys.redhat.com (dhcp-1-150.brq.redhat.com [10.34.1.150]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u7PB1c8g013259; Thu, 25 Aug 2016 07:01:39 -0400 Received: by shodan.usersys.redhat.com (Postfix, from userid 1000) id 36FFD2C1A4A; Thu, 25 Aug 2016 13:01:38 +0200 (CEST) From: Artem Savkov To: fstests@vger.kernel.org Cc: Dave Chinner , Eryu Guan , Filipe Manana , Artem Savkov Subject: [PATCH v2] Add a test for listxattr syscall with different buffer sizes. Date: Thu, 25 Aug 2016 13:01:33 +0200 Message-Id: <1472122893-22158-1-git-send-email-asavkov@redhat.com> In-Reply-To: <20160825055713.GN22388@dastard> References: <20160825055713.GN22388@dastard> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 25 Aug 2016 11:01:39 +0000 (UTC) Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add generic/375 test that calls listxattr syscall with different buffer size arguments checking if it fails properly. Signed-off-by: Artem Savkov --- .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 +#include +#include +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + int ret; + size_t bufsize = 0; + char *buf = NULL; + + if (argc < 2) { + fprintf(stderr, "usage: %s [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