From patchwork Wed Sep 27 23:14:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 13401812 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F0A5E80ABE for ; Wed, 27 Sep 2023 23:13:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229908AbjI0XNn (ORCPT ); Wed, 27 Sep 2023 19:13:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229464AbjI0XNm (ORCPT ); Wed, 27 Sep 2023 19:13:42 -0400 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 577C8F4; Wed, 27 Sep 2023 16:13:41 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id C735A5C290F; Wed, 27 Sep 2023 19:13:40 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Wed, 27 Sep 2023 19:13:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bur.io; h=cc :content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1695856420; x= 1695942820; bh=j+KD/sriX+e/wWHTpgo0NBnggBDG5I8dvFVim9K0Vrc=; b=V YxG2yI/3XOa0Ind2FBUSR3z0FIOzhH2p1lC9G2aFBOiUd0rxUIcspGdW960NutVH rA+jLuzhOSaeII0LTcm9tfoGHiSlbxY4r4Jlfz0BETZWsPr8SqS9MzksQt+Kdemx hi+PEDqEpKqOMo606unxWAvG8bOI7NIBQPIrVltaMRYecOpexxsEvqksAxQ152V7 GdOZHtt+szHLZoI4UC2ZclD7hrwzhdzc0iqHGzrInYsG0EIVP3Rb2jHBikXfJY84 jp1YhxdCEPvEWkSMfmAzkvpKEug6mRudw388pEr8yMP5fnbdjNvDNKJ6TEsNowRm aALuBD5Umc6h4PfIXvZ/Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:date:feedback-id:feedback-id:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1695856420; x=1695942820; bh=j +KD/sriX+e/wWHTpgo0NBnggBDG5I8dvFVim9K0Vrc=; b=FCM/PSDxPpaonLtLx D1AhmvuAxQxdLo2neJNBZv2Uqy9OskTHdV72/jPxLCS8wJE5ubHh0Nw0TH1bnBFM fazjbcvRQD1Jo5sOFj1VBhVz+U2JO3YUCCPq67pjPwyL7NL+pn4sgiSh6E8NaH82 1nfg+Vk+dRbFetLT2g8zFeqklKsSMgeQhiqaOG2DrpD4HfGho6fPjHC3Q4nozoo6 /ymu4HklEkaxNeLvt18IRwkau2jfA+4dywRRS4dvz0THcjLT/E2n5cqFr5OIPROb DcEXks/kQ7RVvTcYjyXXci8VjnVUFpdqxHimEjThuVoZZlNEoTQpInMKgG0ESQEs /INaA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvjedrtdehgddulecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkffojghfggfgsedtkeertd ertddtnecuhfhrohhmpeeuohhrihhsuceuuhhrkhhovhcuoegsohhrihhssegsuhhrrdhi oheqnecuggftrfgrthhtvghrnhepieeuffeuvdeiueejhfehiefgkeevudejjeejffevvd ehtddufeeihfekgeeuheelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehm rghilhhfrhhomhepsghorhhishessghurhdrihho X-ME-Proxy: Feedback-ID: i083147f8:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 27 Sep 2023 19:13:40 -0400 (EDT) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com, fstests@vger.kernel.org Subject: [PATCH v3 1/6] common: refactor sysfs_attr functions Date: Wed, 27 Sep 2023 16:14:33 -0700 Message-ID: <0714f6b21000181ab43d3085903859b8ae1e1a32.1695856385.git.boris@bur.io> X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Expand the has/get/require functions to allow passing a dev by parameter, and implement the test_dev specific one in terms of the new generic one. Signed-off-by: Boris Burkov --- common/rc | 127 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 82 insertions(+), 45 deletions(-) diff --git a/common/rc b/common/rc index 1618ded54..c3cd53546 100644 --- a/common/rc +++ b/common/rc @@ -4689,47 +4689,33 @@ run_fsx() rm -f $tmp.fsx } -# Test for the existence of a sysfs entry at /sys/fs/$FSTYP/DEV/$ATTR +_require_statx() +{ + $here/src/stat_test --check-statx || + _notrun "This test requires the statx system call" +} + +# Get the path to the sysfs directory for the fs on a device # # Only one argument is needed: -# - attr: path name under /sys/fs/$FSTYP/DEV +# - dev: mounted block device for the fs # # Usage example: -# _require_fs_sysfs error/fail_at_unmount -_has_fs_sysfs() +# _fs_sysfs_dname /dev/mapper/scratch-dev +_fs_sysfs_dname() { - local attr=$1 - local dname + local dev=$1 + + if [ ! -b "$dev" ]; then + _fail "Usage: _fs_sysfs_dname " + fi case "$FSTYP" in btrfs) - dname=$(findmnt -n -o UUID $TEST_DEV) ;; + findmnt -n -o UUID ${dev} ;; *) - dname=$(_short_dev $TEST_DEV) ;; + _short_dev $dev ;; esac - - if [ -z "$attr" -o -z "$dname" ];then - _fail "Usage: _require_fs_sysfs " - fi - - test -e /sys/fs/${FSTYP}/${dname}/${attr} -} - -# Require the existence of a sysfs entry at /sys/fs/$FSTYP/DEV/$ATTR -_require_fs_sysfs() -{ - _has_fs_sysfs "$@" && return - - local attr=$1 - local dname=$(_short_dev $TEST_DEV) - - _notrun "This test requires /sys/fs/${FSTYP}/${dname}/${attr}" -} - -_require_statx() -{ - $here/src/stat_test --check-statx || - _notrun "This test requires the statx system call" } # Write "content" into /sys/fs/$FSTYP/$DEV/$ATTR @@ -4753,13 +4739,7 @@ _set_fs_sysfs_attr() _fail "Usage: _set_fs_sysfs_attr " fi - local dname - case "$FSTYP" in - btrfs) - dname=$(findmnt -n -o UUID ${dev}) ;; - *) - dname=$(_short_dev $dev) ;; - esac + local dname=$(_fs_sysfs_dname $dev) echo "$content" > /sys/fs/${FSTYP}/${dname}/${attr} } @@ -4781,17 +4761,74 @@ _get_fs_sysfs_attr() _fail "Usage: _get_fs_sysfs_attr " fi - local dname - case "$FSTYP" in - btrfs) - dname=$(findmnt -n -o UUID ${dev}) ;; - *) - dname=$(_short_dev $dev) ;; - esac + local dname=$(_fs_sysfs_dname $dev) cat /sys/fs/${FSTYP}/${dname}/${attr} } +# Test for the existence of a sysfs entry at /sys/fs/$FSTYP/$DEV/$ATTR +# +# All arguments are necessary, and in this order: +# - dev: device name, e.g. $SCRATCH_DEV +# - attr: path name under /sys/fs/$FSTYP/$dev +# +# Usage example: +# _has_fs_sysfs_attr /dev/mapper/scratch-dev error/fail_at_unmount +_has_fs_sysfs_attr() +{ + local dev=$1 + local attr=$2 + + if [ ! -b "$dev" -o -z "$attr" ];then + _fail "Usage: _get_fs_sysfs_attr " + fi + + local dname=$(_fs_sysfs_dname $dev) + + test -e /sys/fs/${FSTYP}/${dname}/${attr} +} + +# Require the existence of a sysfs entry at /sys/fs/$FSTYP/$DEV/$ATTR +# All arguments are necessary, and in this order: +# - dev: device name, e.g. $SCRATCH_DEV +# - attr: path name under /sys/fs/$FSTYP/$dev +# +# Usage example: +# _require_fs_sysfs_attr /dev/mapper/scratch-dev error/fail_at_unmount +_require_fs_sysfs_attr() +{ + _has_fs_sysfs_attr "$@" && return + + local dev=$1 + local attr=$2 + local dname=$(_fs_sysfs_dname $dev) + + _notrun "This test requires /sys/fs/${FSTYP}/${dname}/${attr}" +} + +# Test for the existence of a sysfs entry at /sys/fs/$FSTYP/DEV/$ATTR +# +# Only one argument is needed: +# - attr: path name under /sys/fs/$FSTYP/DEV +# +# Usage example: +# _has_fs_sysfs error/fail_at_unmount +_has_fs_sysfs() +{ + _has_fs_sysfs_attr $TEST_DEV "$@" +} + +# Require the existence of a sysfs entry at /sys/fs/$FSTYP/DEV/$ATTR +_require_fs_sysfs() +{ + _has_fs_sysfs "$@" && return + + local attr=$1 + local dname=$(_short_dev $TEST_DEV) + + _notrun "This test requires /sys/fs/${FSTYP}/${dname}/${attr}" +} + # Generic test for specific filesystem feature. # Currently only implemented to test overlayfs features. _require_scratch_feature()