Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp5857957ioo; Wed, 1 Jun 2022 14:15:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy926NoXAzZ21Sn9xwLXxCsipZ0oRmi4xRAsP/uPBthzTpAU+UTtz0iDMICghiu/3hDmbtW X-Received: by 2002:a17:902:b193:b0:158:c040:5cf8 with SMTP id s19-20020a170902b19300b00158c0405cf8mr1375124plr.146.1654118128720; Wed, 01 Jun 2022 14:15:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654118128; cv=none; d=google.com; s=arc-20160816; b=AZ+1pdBqVJm/xBB36+bsYTiGC0GZGaN42NuVFjih8VEE+riEpIpxlcdhhjWhWV+mUI 8V9dJU62PIzm7pwoDfRharJmL5eBRT4V+XmXHhVDkuXufsFTiJ79jqcWF3rj/LokrXiH 6OfUW1Ozy4Dwv+vSg1N/ZzTUGW+LQJp9odmUf8SwxZjr0OMVTRv/UjMMZaD7TzMX32wz qLasoR/VgX6O29aJi29O2WGzyv3SSembp+Bu+jCrwqwjDzSY2nKzoVoAkdEzf7vvcTdZ UjQEm2L/xgemgsdF9OJVre0L7UAgtQctI4+l1nFFQnA71tsjBiWToGAUm+NHayJJ6gc4 tS0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=hugwPpklhru4dTxd3ocCNrmQ6SYV0EWcsILpPv9gcg0=; b=xcBniZtwuzcFwCS8zSWAFiOJLA7448joCOKuTAmeASopj+MawFfMA5LgQ+V6q2iEFe O3aV2lytI5lx5ZSWUj1A6P0jVYtbvou41QynuYl8LIqLC6MRbibzmts+eXIDST4x3GJe hTs4MZBhzubKtwxKB5iXHX9y0diH4BVLoqjZgd9ZYurT0tIy+Zns7kfl2i7i0n2atUoT EXEUvQnIWSSIHhssoxP6DrAJt9q9ToFefeWxWLvvUZjh9J8DBZTYnntE1JuV0HRI4hD7 6+9AHQz0wnImGNXeyJBBzIpDgfBYzYtmQULatNNhVr978SgtsYUtkBapgKoTF9BjRBrl ZrJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="hHPE7/1O"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id q16-20020a17090311d000b00158bfb59d03si4064554plh.382.2022.06.01.14.15.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 14:15:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="hHPE7/1O"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B39022DCB22; Wed, 1 Jun 2022 13:06:39 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356374AbiFARcj (ORCPT + 99 others); Wed, 1 Jun 2022 13:32:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356354AbiFARcc (ORCPT ); Wed, 1 Jun 2022 13:32:32 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A712249F81 for ; Wed, 1 Jun 2022 10:32:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654104743; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hugwPpklhru4dTxd3ocCNrmQ6SYV0EWcsILpPv9gcg0=; b=hHPE7/1OLlNg05yEh+BoRtY8l+AYRbnmWAqfNmvm22qNx2kM+XJO0GSlAVVNxUUD6VyDLa P/I9jgcII3Us12p9JT3XjGBrfZUFPJQ4aFGtObMsz85XoxfE0SZMamM+n8Nu0SG0NMUbmb /H6rBMl5fB7wpN+um6wNO/Qhk/8NJXM= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-637-ux8i_AxmMy-7n33ICd6bXA-1; Wed, 01 Jun 2022 13:32:22 -0400 X-MC-Unique: ux8i_AxmMy-7n33ICd6bXA-1 Received: by mail-wr1-f69.google.com with SMTP id v4-20020adfebc4000000b002102c69be5eso423211wrn.13 for ; Wed, 01 Jun 2022 10:32:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hugwPpklhru4dTxd3ocCNrmQ6SYV0EWcsILpPv9gcg0=; b=hE5xpZh8YqxHYcKyStQnSoIse66h+QnOoMTJVB0v2tpt16odMadu4UYnbZ8Fxfz215 gTvG5UelXpIQ/sesqD4LMMXKoZKZeEiTB0uTkEenZEaIjbGUrEE1hk3dXZTaSZbL0E6w zewGRjBUoVLKttdKJ9YDm8jKCo4Rnua4FS2VJoCPfaEwyNbYNqs7CCAKD+2WiLJlc0MR P3455ye8J2oypGxqlbajm1O01LdxdPbyMMETjMhTAabnyG52U0ClGm2qz9NKl7NfpQ2b zsMPxYqL0SX5qCDfcy5ajU2AduFTHNcihyjdeebRfxRZo8MSwDCQUowyQStO/Gm99Zer pPoA== X-Gm-Message-State: AOAM531O7JbCcPm5Rs8ubT3isSV9cbCnxR9BeJVUzjtGjovA7GgN+JUk OXnagw6yYtQoL+ViAmTiGpKCZwSTzdxlqW1HrzS+GoG6oijSjbF6PHnpwoOXUSF0xs5w3akafyz k881qWYD1ZKAD0AHH+qFkRBHQ72XRW76ahQbmkCfIe8miD9JyXzNBGh0vFwA1WxOesftPD9x/BO U= X-Received: by 2002:a05:6000:1151:b0:210:155b:1e19 with SMTP id d17-20020a056000115100b00210155b1e19mr456700wrx.162.1654104740486; Wed, 01 Jun 2022 10:32:20 -0700 (PDT) X-Received: by 2002:a05:6000:1151:b0:210:155b:1e19 with SMTP id d17-20020a056000115100b00210155b1e19mr456667wrx.162.1654104740202; Wed, 01 Jun 2022 10:32:20 -0700 (PDT) Received: from minerva.home (205.pool92-176-231.dynamic.orange.es. [92.176.231.205]) by smtp.gmail.com with ESMTPSA id l14-20020a05600c2cce00b0039751bb8c62sm6525625wmc.24.2022.06.01.10.32.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 10:32:19 -0700 (PDT) From: Javier Martinez Canillas To: linux-kernel@vger.kernel.org Cc: Lennart Poettering , OGAWA Hirofumi , Colin Walters , Peter Jones , Alberto Ruiz , Christian Kellner , Chung-Chiang Cheng , Muhammad Usama Anjum , Alexander Larsson , Javier Martinez Canillas , Shuah Khan , linux-kselftest@vger.kernel.org Subject: [PATCH v4 4/4] selftests/filesystems: add a vfat RENAME_EXCHANGE test Date: Wed, 1 Jun 2022 19:32:04 +0200 Message-Id: <20220601173204.1372569-5-javierm@redhat.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220601173204.1372569-1-javierm@redhat.com> References: <20220601173204.1372569-1-javierm@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a test for the renameat2 RENAME_EXCHANGE support in vfat, but split it in a tool that just does the rename exchange and a script that is run by the kselftests framework on `make TARGETS="filesystems/fat" kselftest`. That way the script can be easily extended to test other file operations. The script creates a 1 MiB disk image, that is then formated with a vfat filesystem and mounted using a loop device. That way all file operations are done on an ephemeral filesystem. Signed-off-by: Javier Martinez Canillas Acked-by: Muhammad Usama Anjum --- Changes in v4: - Add Muhammad Usama Anjum Acked-by tag. Changes in v3: - Add a .gitignore for the rename_exchange binary (Muhammad Usama Anjum). - Include $(KHDR_INCLUDES) instead of hardcoding a relative path in Makefile (Muhammad Usama Anjum). Changes in v2: - Call sync to flush the page cache before checking the file contents (Alex Larsson). MAINTAINERS | 1 + tools/testing/selftests/Makefile | 1 + .../selftests/filesystems/fat/.gitignore | 2 + .../selftests/filesystems/fat/Makefile | 7 ++ .../testing/selftests/filesystems/fat/config | 2 + .../filesystems/fat/rename_exchange.c | 37 +++++++++ .../filesystems/fat/run_fat_tests.sh | 82 +++++++++++++++++++ 7 files changed, 132 insertions(+) create mode 100644 tools/testing/selftests/filesystems/fat/.gitignore create mode 100644 tools/testing/selftests/filesystems/fat/Makefile create mode 100644 tools/testing/selftests/filesystems/fat/config create mode 100644 tools/testing/selftests/filesystems/fat/rename_exchange.c create mode 100755 tools/testing/selftests/filesystems/fat/run_fat_tests.sh diff --git a/MAINTAINERS b/MAINTAINERS index 4fdbbd6c1984..158771bb7755 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -20841,6 +20841,7 @@ M: OGAWA Hirofumi S: Maintained F: Documentation/filesystems/vfat.rst F: fs/fat/ +F: tools/testing/selftests/filesystems/fat/ VFIO DRIVER M: Alex Williamson diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index 0aedcd76cf0f..fc59ad849a90 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -16,6 +16,7 @@ TARGETS += exec TARGETS += filesystems TARGETS += filesystems/binderfs TARGETS += filesystems/epoll +TARGETS += filesystems/fat TARGETS += firmware TARGETS += fpu TARGETS += ftrace diff --git a/tools/testing/selftests/filesystems/fat/.gitignore b/tools/testing/selftests/filesystems/fat/.gitignore new file mode 100644 index 000000000000..b89920ed841c --- /dev/null +++ b/tools/testing/selftests/filesystems/fat/.gitignore @@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +rename_exchange diff --git a/tools/testing/selftests/filesystems/fat/Makefile b/tools/testing/selftests/filesystems/fat/Makefile new file mode 100644 index 000000000000..902033f6ef09 --- /dev/null +++ b/tools/testing/selftests/filesystems/fat/Makefile @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0 + +TEST_PROGS := run_fat_tests.sh +TEST_GEN_PROGS_EXTENDED := rename_exchange +CFLAGS += -O2 -g -Wall $(KHDR_INCLUDES) + +include ../../lib.mk diff --git a/tools/testing/selftests/filesystems/fat/config b/tools/testing/selftests/filesystems/fat/config new file mode 100644 index 000000000000..6cf95e787a17 --- /dev/null +++ b/tools/testing/selftests/filesystems/fat/config @@ -0,0 +1,2 @@ +CONFIG_BLK_DEV_LOOP=y +CONFIG_VFAT_FS=y diff --git a/tools/testing/selftests/filesystems/fat/rename_exchange.c b/tools/testing/selftests/filesystems/fat/rename_exchange.c new file mode 100644 index 000000000000..e488ad354fce --- /dev/null +++ b/tools/testing/selftests/filesystems/fat/rename_exchange.c @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Program that atomically exchanges two paths using + * the renameat2() system call RENAME_EXCHANGE flag. + * + * Copyright 2022 Red Hat Inc. + * Author: Javier Martinez Canillas + */ + +#define _GNU_SOURCE +#include +#include +#include + +void print_usage(const char *program) +{ + printf("Usage: %s [oldpath] [newpath]\n", program); + printf("Atomically exchange oldpath and newpath\n"); +} + +int main(int argc, char *argv[]) +{ + int ret; + + if (argc != 3) { + print_usage(argv[0]); + exit(EXIT_FAILURE); + } + + ret = renameat2(AT_FDCWD, argv[1], AT_FDCWD, argv[2], RENAME_EXCHANGE); + if (ret) { + perror("rename exchange failed"); + exit(EXIT_FAILURE); + } + + exit(EXIT_SUCCESS); +} diff --git a/tools/testing/selftests/filesystems/fat/run_fat_tests.sh b/tools/testing/selftests/filesystems/fat/run_fat_tests.sh new file mode 100755 index 000000000000..7f35dc3d15df --- /dev/null +++ b/tools/testing/selftests/filesystems/fat/run_fat_tests.sh @@ -0,0 +1,82 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# +# Run filesystem operations tests on an 1 MiB disk image that is formatted with +# a vfat filesystem and mounted in a temporary directory using a loop device. +# +# Copyright 2022 Red Hat Inc. +# Author: Javier Martinez Canillas + +set -e +set -u +set -o pipefail + +BASE_DIR="$(dirname $0)" +TMP_DIR="$(mktemp -d /tmp/fat_tests_tmp.XXXX)" +IMG_PATH="${TMP_DIR}/fat.img" +MNT_PATH="${TMP_DIR}/mnt" + +cleanup() +{ + mountpoint -q "${MNT_PATH}" && unmount_image + rm -rf "${TMP_DIR}" +} +trap cleanup SIGINT SIGTERM EXIT + +create_loopback() +{ + touch "${IMG_PATH}" + chattr +C "${IMG_PATH}" >/dev/null 2>&1 || true + + truncate -s 1M "${IMG_PATH}" + mkfs.vfat "${IMG_PATH}" >/dev/null 2>&1 +} + +mount_image() +{ + mkdir -p "${MNT_PATH}" + sudo mount -o loop "${IMG_PATH}" "${MNT_PATH}" +} + +rename_exchange_test() +{ + local rename_exchange="${BASE_DIR}/rename_exchange" + local old_path="${MNT_PATH}/old_file" + local new_path="${MNT_PATH}/new_file" + + echo old | sudo tee "${old_path}" >/dev/null 2>&1 + echo new | sudo tee "${new_path}" >/dev/null 2>&1 + sudo "${rename_exchange}" "${old_path}" "${new_path}" >/dev/null 2>&1 + sudo sync -f "${MNT_PATH}" + grep new "${old_path}" >/dev/null 2>&1 + grep old "${new_path}" >/dev/null 2>&1 +} + +rename_exchange_subdir_test() +{ + local rename_exchange="${BASE_DIR}/rename_exchange" + local dir_path="${MNT_PATH}/subdir" + local old_path="${MNT_PATH}/old_file" + local new_path="${dir_path}/new_file" + + sudo mkdir -p "${dir_path}" + echo old | sudo tee "${old_path}" >/dev/null 2>&1 + echo new | sudo tee "${new_path}" >/dev/null 2>&1 + sudo "${rename_exchange}" "${old_path}" "${new_path}" >/dev/null 2>&1 + sudo sync -f "${MNT_PATH}" + grep new "${old_path}" >/dev/null 2>&1 + grep old "${new_path}" >/dev/null 2>&1 +} + +unmount_image() +{ + sudo umount "${MNT_PATH}" &> /dev/null +} + +create_loopback +mount_image +rename_exchange_test +rename_exchange_subdir_test +unmount_image + +exit 0 -- 2.36.1