From patchwork Sun Sep 16 21:50:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Weinberger X-Patchwork-Id: 10601899 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B761113AD for ; Sun, 16 Sep 2018 21:50:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 98A5E29344 for ; Sun, 16 Sep 2018 21:50:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8CA60293E8; Sun, 16 Sep 2018 21:50:35 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 A0E4F29344 for ; Sun, 16 Sep 2018 21:50:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728281AbeIQDOy (ORCPT ); Sun, 16 Sep 2018 23:14:54 -0400 Received: from lilium.sigma-star.at ([109.75.188.150]:37452 "EHLO lilium.sigma-star.at" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728218AbeIQDOy (ORCPT ); Sun, 16 Sep 2018 23:14:54 -0400 Received: from localhost (localhost [127.0.0.1]) by lilium.sigma-star.at (Postfix) with ESMTP id 9A7DA18023C41; Sun, 16 Sep 2018 23:50:30 +0200 (CEST) From: Richard Weinberger To: fstests@vger.kernel.org Cc: koen.vandeputte@ncentric.com, Richard Weinberger Subject: [PATCH] generic: Test whether xattrs work on unlinked files Date: Sun, 16 Sep 2018 23:50:11 +0200 Message-Id: <20180916215011.31029-1-richard@nod.at> X-Mailer: git-send-email 2.19.0 MIME-Version: 1.0 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On UBIFS we had an embarrassing bug where xattr operations worked only for files with nlink > 0. Make sure this will never happen again. Signed-off-by: Richard Weinberger --- Hi! I'm not sure whether this is worth a new test, maybe we can add it to an existing test? What about generic/020? Since xfs_io does not support xattrs, we need a new C test helper. Thanks, //richard --- src/Makefile | 2 +- src/attr_unlinked_test.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/generic/505 | 46 +++++++++++++++++++++++++++++++++++++++++ tests/generic/505.out | 2 ++ tests/generic/group | 1 + 5 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 src/attr_unlinked_test.c create mode 100755 tests/generic/505 create mode 100644 tests/generic/505.out diff --git a/src/Makefile b/src/Makefile index 41826585..433fa517 100644 --- a/src/Makefile +++ b/src/Makefile @@ -27,7 +27,7 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \ renameat2 t_getcwd e4compact test-nextquota punch-alternating \ attr-list-by-handle-cursor-test listxattr dio-interleaved t_dir_type \ dio-invalidate-cache stat_test t_encrypted_d_revalidate \ - attr_replace_test swapon mkswap + attr_replace_test swapon mkswap attr_unlinked_test SUBDIRS = log-writes perf diff --git a/src/attr_unlinked_test.c b/src/attr_unlinked_test.c new file mode 100644 index 00000000..f3ce6d84 --- /dev/null +++ b/src/attr_unlinked_test.c @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Test whether xattr operations work on unlinked files. + * based on attr_replace_test.c + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define die() do { perror(""); \ +fprintf(stderr, "error at line %d\n", __LINE__); \ +exit(1); } while (0) + +#define fail(...) do { \ +fprintf(stderr, __VA_ARGS__); exit (1); \ +} while (0) + +int main(int argc, char *argv[]) +{ + int ret; + int fd; + char *name = "user.world"; + char value[] = "hello"; + + if (argc != 2) + fail("Usage: %s \n", argv[0]); + + fd = open(argv[1], O_RDWR | O_DIRECTORY | O_TMPFILE, S_IRUSR | S_IWUSR); + if (fd < 0) + die(); + + ret = fsetxattr(fd, name, value, sizeof(value), XATTR_CREATE); + if (ret < 0) + die(); + + ret = fsetxattr(fd, name, value, sizeof(value), XATTR_REPLACE); + if (ret < 0) + die(); + + ret = fsetxattr(fd, name, NULL, 0, 0); + if (ret < 0) + die(); + + close(fd); + + return 0; +} diff --git a/tests/generic/505 b/tests/generic/505 new file mode 100755 index 00000000..6e8bb512 --- /dev/null +++ b/tests/generic/505 @@ -0,0 +1,46 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# +# FS QA Test No. 505 +# +# Ensure that xattr operations work also on unlinked files. +# UBIFS wrongly assumed that xattr operations are only valid for nlink > 0. +# +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f $testfile +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter +. ./common/attr + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here +_supported_fs generic +_supported_os Linux +_require_test_program "attr_unlinked_test" +_require_attrs +_require_scratch + +rm -f $seqres.full +_scratch_mkfs >>$seqres.full 2>&1 +_scratch_mount >>$seqres.full 2>&1 + +./src/attr_unlinked_test $SCRATCH_MNT/ + +echo "Silence is golden" + +status=0 +exit diff --git a/tests/generic/505.out b/tests/generic/505.out new file mode 100644 index 00000000..80e3bd1d --- /dev/null +++ b/tests/generic/505.out @@ -0,0 +1,2 @@ +QA output created by 505 +Silence is golden diff --git a/tests/generic/group b/tests/generic/group index 55155de8..75770f7a 100644 --- a/tests/generic/group +++ b/tests/generic/group @@ -507,3 +507,4 @@ 502 auto quick log 503 auto quick dax punch collapse zero 504 auto quick locks +505 auto quick attr