From patchwork Wed Jan 29 08:58:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 11355723 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 437CD159A for ; Wed, 29 Jan 2020 08:58:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0E0C4207FD for ; Wed, 29 Jan 2020 08:58:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=osandov-com.20150623.gappssmtp.com header.i=@osandov-com.20150623.gappssmtp.com header.b="J85FbUDc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726184AbgA2I6p (ORCPT ); Wed, 29 Jan 2020 03:58:45 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:41442 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726116AbgA2I6p (ORCPT ); Wed, 29 Jan 2020 03:58:45 -0500 Received: by mail-pf1-f195.google.com with SMTP id w62so8095030pfw.8 for ; Wed, 29 Jan 2020 00:58:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HZ1fUgHkKafGnPPxbaIK69OWQ8cHhuK6+MSpL+KfJsw=; b=J85FbUDc/TdNx7uRrkMJNtNzm2tqgFgyIb1YAEQNDhJhCaQW9aEQ0U13SPHkR3c7Xf ofZic2Y+3nWH/J7UGGzlO7mQZd86FiaQEi4OCgLA9bQTctvxgpLSsAe+11+uRNU1GyAV KZdm1wZ6X9EcS8cCwII1zgVTM131xJAvNr8SOANepdLfayhZ8nbn52mhdllFuvp7Vu6E 7lfVHsWE3jIP/WPd0h6ByqtX1TmfUwK+cglVz+SfuLSevlBVPysT51ArHJwbzEizS1Pd C6SXxcBfG3hyJzp6w7CGrU3GaUwviIZ1c1Nm8OzcgzZNg805s5M0uAvuD4efBCm2qLFj SYcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HZ1fUgHkKafGnPPxbaIK69OWQ8cHhuK6+MSpL+KfJsw=; b=hk3Xqt4QpXbQNwbZN0h+Nr/O9cGDmEuXqYtTWcpQF54uYo4qnoNlZn8f6FkqiE+3t8 1V7BFkXi6UjA4YBjZ1OK8hR5AVx+ZLNgvUR0kJsGua7L5IUl5dmwdRwreX2Dglm8LZyG Q7CiyCfpyPOViA18qms/BvKT1a5Jj7poRgBzdNPXfGSCWCeICgeQFueCaxc1XWwhmJAZ S2HrqqTiWxdfqXkpX1CMYh1s89Gu6HxzLP3BdGjdlEv63weqyS/hzEuY3W33upXHEq+k nLpSxLE0RviBnR6yxWeddblSmt7QlSONMUVHPeK1F2V+A54X1Ot7T9JNEZufRvpiNXiz JxWA== X-Gm-Message-State: APjAAAW0NDyHRm1PpiOT9l3pebKVyhNOuq7VAVBawGkJ7IyLW/ac3sA7 qRBnRf7SC7z87vAzMZeksWuaqQ== X-Google-Smtp-Source: APXvYqzCaxjzL1BCmtE9Gr4XiyfN2SK3rP/+TSRXQgOwqWHDazZahMLQ22ojJ77gTeOc+H6hpGaz5A== X-Received: by 2002:a62:1a16:: with SMTP id a22mr8261295pfa.34.1580288324210; Wed, 29 Jan 2020 00:58:44 -0800 (PST) Received: from vader.hsd1.wa.comcast.net ([2601:602:8b80:8e0:e6a7:a0ff:fe0b:c9a8]) by smtp.gmail.com with ESMTPSA id s131sm1935932pfs.135.2020.01.29.00.58.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2020 00:58:43 -0800 (PST) From: Omar Sandoval To: linux-fsdevel@vger.kernel.org, Al Viro Cc: kernel-team@fb.com, linux-api@vger.kernel.org, David Howells , Amir Goldstein , Xi Wang , fstests@vger.kernel.org Subject: [RFC PATCH xfstests] generic: add smoke test for AT_LINK_REPLACE Date: Wed, 29 Jan 2020 00:58:27 -0800 Message-Id: X-Mailer: git-send-email 2.25.0 In-Reply-To: References: MIME-Version: 1.0 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org From: Omar Sandoval Cc: fstests@vger.kernel.org Signed-off-by: Omar Sandoval --- common/rc | 2 +- tests/generic/593 | 97 +++++++++++++++++++++++++++++++++++++++++++ tests/generic/593.out | 6 +++ tests/generic/group | 1 + 4 files changed, 105 insertions(+), 1 deletion(-) create mode 100755 tests/generic/593 create mode 100644 tests/generic/593.out diff --git a/common/rc b/common/rc index eeac1355..257f65a1 100644 --- a/common/rc +++ b/common/rc @@ -2172,7 +2172,7 @@ _require_xfs_io_command() ;; "flink") local testlink=$TEST_DIR/$$.link.xfs_io - testio=`$XFS_IO_PROG -F -f -c "flink $testlink" $testfile 2>&1` + testio=`$XFS_IO_PROG -F -f -c "flink $param $testlink" $testfile 2>&1` rm -f $testlink > /dev/null 2>&1 ;; "-T") diff --git a/tests/generic/593 b/tests/generic/593 new file mode 100755 index 00000000..8a9fee02 --- /dev/null +++ b/tests/generic/593 @@ -0,0 +1,97 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2020 Facebook. All Rights Reserved. +# +# FS QA Test 593 +# +# Smoke test linkat() with AT_LINK_REPLACE. +# +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +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 + +# remove previous $seqres.full before test +rm -f $seqres.full + +_supported_fs generic +_supported_os Linux +_require_test +_require_xfs_io_command "-T" +_require_xfs_io_command "flink" "-f" + +same_file() { + [[ "$(stat -c '%d %i' "$1")" = "$(stat -c '%d %i' "$2")" ]] +} + +touch "$TEST_DIR/$seq.src" +touch "$TEST_DIR/$seq.tgt" +$XFS_IO_PROG -c "flink -f $TEST_DIR/$seq.tgt" "$TEST_DIR/$seq.src" +same_file "$TEST_DIR/$seq.src" "$TEST_DIR/$seq.tgt" || + echo "Target was not replaced" + +# Linking to the same file should be a noop. +$XFS_IO_PROG -c "flink -f $TEST_DIR/$seq.src" "$TEST_DIR/$seq.src" +$XFS_IO_PROG -c "flink -f $TEST_DIR/$seq.tgt" "$TEST_DIR/$seq.src" +same_file "$TEST_DIR/$seq.src" "$TEST_DIR/$seq.tgt" || echo "Target changed?" + +# Should work with O_TMPFILE. +$XFS_IO_PROG -c "flink -f $TEST_DIR/$seq.tgt" -T "$TEST_DIR" +stat -c '%h' "$TEST_DIR/$seq.tgt" +same_file "$TEST_DIR/$seq.src" "$TEST_DIR/$seq.tgt" && + echo "Target was not replaced" + +# It's okay if the target doesn't exist. +$XFS_IO_PROG -c "flink -f $TEST_DIR/$seq.tgt2" "$TEST_DIR/$seq.src" +same_file "$TEST_DIR/$seq.src" "$TEST_DIR/$seq.tgt2" || + echo "Target was not created" + +# Can't replace directories. +mkdir "$TEST_DIR/$seq.dir" +$XFS_IO_PROG -c "flink -f $TEST_DIR/$seq.dir" "$TEST_DIR/$seq.src" +cd "$TEST_DIR/$seq.dir" +$XFS_IO_PROG -c "flink -f ." "$TEST_DIR/$seq.src" +$XFS_IO_PROG -c "flink -f .." "$TEST_DIR/$seq.src" +cd - &> /dev/null + +# Can't replace local mount points. +touch "$TEST_DIR/$seq.mnt" +$MOUNT_PROG --bind "$TEST_DIR/$seq.mnt" "$TEST_DIR/$seq.mnt" +$XFS_IO_PROG -c "flink -f $TEST_DIR/$seq.mnt" "$TEST_DIR/$seq.src" + +# Can replace mount points in other namespaces, though. +unshare -m \ + bash -c "$UMOUNT_PROG $TEST_DIR/$seq.mnt; $XFS_IO_PROG -c \"flink -f $TEST_DIR/$seq.mnt\" $TEST_DIR/$seq.src" +if $UMOUNT_PROG "$TEST_DIR/$seq.mnt" &> /dev/null; then + echo "Mount point was not detached" +fi +same_file "$TEST_DIR/$seq.src" "$TEST_DIR/$seq.mnt" || + echo "Mount point was not replaced" + +# Should replace symlinks, not follow them. +touch "$TEST_DIR/$seq.symtgt" +ln -s "$TEST_DIR/$seq.symtgt" "$TEST_DIR/$seq.sym" +$XFS_IO_PROG -c "flink -f $TEST_DIR/$seq.sym" "$TEST_DIR/$seq.src" +same_file "$TEST_DIR/$seq.src" "$TEST_DIR/$seq.sym" || + echo "Symlink was not replaced" +same_file "$TEST_DIR/$seq.src" "$TEST_DIR/$seq.symtgt" && + echo "Symlink target was replaced" + +rm -rf "$TEST_DIR/$seq."* + +status=0 +exit diff --git a/tests/generic/593.out b/tests/generic/593.out new file mode 100644 index 00000000..834c34bf --- /dev/null +++ b/tests/generic/593.out @@ -0,0 +1,6 @@ +QA output created by 593 +1 +flink: Is a directory +flink: Is a directory +flink: Is a directory +flink: Device or resource busy diff --git a/tests/generic/group b/tests/generic/group index 6fe62505..0a87efca 100644 --- a/tests/generic/group +++ b/tests/generic/group @@ -595,3 +595,4 @@ 590 auto prealloc preallocrw 591 auto quick rw pipe splice 592 auto quick encrypt +593 auto quick hardlink