Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp723461pxb; Thu, 21 Oct 2021 08:17:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSK0Cgk9H7JzNZAiXlgttynqO7NnhBnUQWXxFOHqC5ECu2iABFf8gj8odJ6jdHVtq97v40 X-Received: by 2002:a62:d11e:0:b0:446:d705:7175 with SMTP id z30-20020a62d11e000000b00446d7057175mr6227139pfg.74.1634829457442; Thu, 21 Oct 2021 08:17:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634829457; cv=none; d=google.com; s=arc-20160816; b=wbIlZ+JN25YLRI1B70C6gt3QRhhwLpffSCXE+Wi4OlKBRqglIDsqylZ4x7YMrdSlL7 qAS+ypmvKeUKEEVcT0RCrydl2ZeQ2shH163QV5Cv7AwKWAb7eSHgJczqhAMR2Ij8Ipcv L0TU1QvDng63DLSywg8rC6GcAWCyqsfG9e0YCcctC3/gAKZgVb2gn4rJ3s50CdvIURfm adWS+pPoALmQsZ3TWto4ASkgaxEan9/MwRJPkEmRPKHuhR+tdWAW0R3VcewYMYX3WRzd VxPTpAY6RyWQuerPzUvjRZ+ULzPMlkWRYiUln9rncHNb+Xr76RlsowAyGKHBlC6gAIJY lZJA== 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=wPEEI/42En9uKSJ0rR6svxJibQPpLgl3/xd+Q1CAzs4=; b=p7AX4+CToaab7GNI+YAfMIEtYOZL/UBtzboxxzu1aQe8Pm68byQlYKwpXsbsfaxOdZ s/MpyxyGHlTeQeqnmbCu7OVaIZEtlOKfB6bEOAnrthQzvEk6empg0aMefqHgeto4E6RZ 0v4LvsstcqoqFFfnvLiPoWIRN1BoGgNL/JAXCvPbr9svskAZVnADciC9q7TnjVqtnIVG KALU8BX4DlYCzkcvBMT43jK+Don6E2hXfc0s869qYaA4M8IygkVIfcFzlpNCctOvxOp0 oJf6u9iFJB7ZGDTYfVH/IojMDRzTMsq09eoBntI90vNbCV74lQuov3XX8CVE1TfG6uXX cpYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=ArwVTh3E; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m22si11139611pgu.68.2021.10.21.08.17.17; Thu, 21 Oct 2021 08:17:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=ArwVTh3E; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232103AbhJUPSd (ORCPT + 99 others); Thu, 21 Oct 2021 11:18:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231857AbhJUPST (ORCPT ); Thu, 21 Oct 2021 11:18:19 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8B81C061229 for ; Thu, 21 Oct 2021 08:16:03 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id o24-20020a05600c511800b0030d9da600aeso15127wms.4 for ; Thu, 21 Oct 2021 08:16:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wPEEI/42En9uKSJ0rR6svxJibQPpLgl3/xd+Q1CAzs4=; b=ArwVTh3EaIjsFaD/Zbzk2v9QkwA3pWqH34r8L0lMMOpk5RFI4xI5zowgC5WNu3NqO5 1kyrUBKSFJi7H2zK6/4d5xiODpuHqkWpcmN4WOp0LS6RRGmtvOpZ9JCaxt8m2Cz714ai QDV0et2cSifjt23YweKmZ8SMST9HKxMXkJCDk= 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=wPEEI/42En9uKSJ0rR6svxJibQPpLgl3/xd+Q1CAzs4=; b=XpETePFtQ4xytn/+AaoBGzHXKu1BQHRXZOyHfK7rLgmn4RG21FeTLGKfEOFJ8ImGf/ DePx7/M8+hK0HWbG5eYdfPE3CAmOPMqaxtbsL00rk5MTNcf9OjXAaVC2RIS7dwYXssBE cztrYnnCS3msMIF8P5QsuNRAkmvgzaBvmQGVUE0w+Zy0vhy29Jp0RVKTjdt/t/27EPBX cT79TAEh8NjDUrzkEKun5IOWdesaASZ/mWGcMf1Tlas97C1I9EbECs5cGdAPkAopG9D7 pvwl9fwbx22loD8fZo/NNMU8b7ZsfR0p5UE2Uq5WzAcyPNoRUapWKTmQ3jND+PZlQGKD RPYg== X-Gm-Message-State: AOAM533u/DFILxVyLqQiQMnZFAqSfkpKyOWrbvQUkpp2wP63vB4BLgE2 J9b7gsmd60MFSsBsJ9MfTgMV4w== X-Received: by 2002:a7b:c30c:: with SMTP id k12mr22015678wmj.38.1634829362115; Thu, 21 Oct 2021 08:16:02 -0700 (PDT) Received: from altair.lan (7.2.6.0.8.8.2.4.4.c.c.f.b.1.5.4.f.f.6.2.a.5.a.7.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:7a5a:26ff:451b:fcc4:4288:627]) by smtp.googlemail.com with ESMTPSA id z1sm5098562wrt.94.2021.10.21.08.16.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Oct 2021 08:16:01 -0700 (PDT) From: Lorenz Bauer To: Shuah Khan , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: kernel-team@cloudflare.com, Lorenz Bauer , linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next v2 3/3] selftests: bpf: test RENAME_EXCHANGE and RENAME_NOREPLACE on bpffs Date: Thu, 21 Oct 2021 16:15:28 +0100 Message-Id: <20211021151528.116818-4-lmb@cloudflare.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211021151528.116818-1-lmb@cloudflare.com> References: <20211021151528.116818-1-lmb@cloudflare.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add tests to exercise the behaviour of RENAME_EXCHANGE and RENAME_NOREPLACE on bpffs. The former checks that after an exchange the inode of two directories has changed. The latter checks that the source still exists after a failed rename. Signed-off-by: Lorenz Bauer --- .../selftests/bpf/prog_tests/test_bpffs.c | 65 ++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/prog_tests/test_bpffs.c b/tools/testing/selftests/bpf/prog_tests/test_bpffs.c index 533e3f3a459a..d29ebfeef9c5 100644 --- a/tools/testing/selftests/bpf/prog_tests/test_bpffs.c +++ b/tools/testing/selftests/bpf/prog_tests/test_bpffs.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 /* Copyright (c) 2020 Facebook */ #define _GNU_SOURCE +#include #include #include #include @@ -29,7 +30,8 @@ static int read_iter(char *file) static int fn(void) { - int err; + struct stat a, b, c; + int err, map; err = unshare(CLONE_NEWNS); if (!ASSERT_OK(err, "unshare")) @@ -67,6 +69,67 @@ static int fn(void) err = read_iter(TDIR "/fs2/progs.debug"); if (!ASSERT_OK(err, "reading " TDIR "/fs2/progs.debug")) goto out; + + err = mkdir(TDIR "/fs1/a", 0777); + if (!ASSERT_OK(err, "creating " TDIR "/fs1/a")) + goto out; + err = mkdir(TDIR "/fs1/a/1", 0777); + if (!ASSERT_OK(err, "creating " TDIR "/fs1/a/1")) + goto out; + err = mkdir(TDIR "/fs1/b", 0777); + if (!ASSERT_OK(err, "creating " TDIR "/fs1/b")) + goto out; + + map = bpf_create_map(BPF_MAP_TYPE_ARRAY, 4, 4, 1, 0); + if (!ASSERT_GT(map, 0, "create_map(ARRAY)")) + goto out; + err = bpf_obj_pin(map, TDIR "/fs1/c"); + if (!ASSERT_OK(err, "pin map")) + goto out; + close(map); + + /* Check that RENAME_EXCHANGE works for directories. */ + err = stat(TDIR "/fs1/a", &a); + if (!ASSERT_OK(err, "stat(" TDIR "/fs1/a)")) + goto out; + err = renameat2(0, TDIR "/fs1/a", 0, TDIR "/fs1/b", RENAME_EXCHANGE); + if (!ASSERT_OK(err, "renameat2(/fs1/a, /fs1/b, RENAME_EXCHANGE)")) + goto out; + err = stat(TDIR "/fs1/b", &b); + if (!ASSERT_OK(err, "stat(" TDIR "/fs1/b)")) + goto out; + if (!ASSERT_EQ(a.st_ino, b.st_ino, "b should have a's inode")) + goto out; + err = access(TDIR "/fs1/b/1", F_OK); + if (!ASSERT_OK(err, "access(" TDIR "/fs1/b/1)")) + goto out; + + /* Check that RENAME_EXCHANGE works for mixed file types. */ + err = stat(TDIR "/fs1/c", &c); + if (!ASSERT_OK(err, "stat(" TDIR "/fs1/map)")) + goto out; + err = renameat2(0, TDIR "/fs1/c", 0, TDIR "/fs1/b", RENAME_EXCHANGE); + if (!ASSERT_OK(err, "renameat2(/fs1/c, /fs1/b, RENAME_EXCHANGE)")) + goto out; + err = stat(TDIR "/fs1/b", &b); + if (!ASSERT_OK(err, "stat(" TDIR "/fs1/b)")) + goto out; + if (!ASSERT_EQ(c.st_ino, b.st_ino, "b should have c's inode")) + goto out; + err = access(TDIR "/fs1/c/1", F_OK); + if (!ASSERT_OK(err, "access(" TDIR "/fs1/c/1)")) + goto out; + + /* Check that RENAME_NOREPLACE works. */ + err = renameat2(0, TDIR "/fs1/b", 0, TDIR "/fs1/a", RENAME_NOREPLACE); + if (!ASSERT_ERR(err, "renameat2(RENAME_NOREPLACE)")) { + err = -EINVAL; + goto out; + } + err = access(TDIR "/fs1/b", F_OK); + if (!ASSERT_OK(err, "access(" TDIR "/fs1/b)")) + goto out; + out: umount(TDIR "/fs1"); umount(TDIR "/fs2"); -- 2.32.0