From patchwork Thu Oct 28 09:47:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenz Bauer X-Patchwork-Id: 12589677 X-Patchwork-Delegate: bpf@iogearbox.net 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E39EC433F5 for ; Thu, 28 Oct 2021 09:48:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 749D260F9B for ; Thu, 28 Oct 2021 09:48:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230115AbhJ1Juv (ORCPT ); Thu, 28 Oct 2021 05:50:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229626AbhJ1Jut (ORCPT ); Thu, 28 Oct 2021 05:50:49 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63B80C0613B9 for ; Thu, 28 Oct 2021 02:48:22 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id o14so9024479wra.12 for ; Thu, 28 Oct 2021 02:48:22 -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=TDEJin9Wub/pTmZCaG0ahvo3TESho8nP0MZ/DG5F4bU=; b=Fq7FjlAbZV5zR/iWtDoqRfxsQKOz3/NHuIDK/MgY5Uz+X8Bzve19JOmFMCKZtHnc6C 3JxZxqr5idu9by/1C9tNk29r5SoxWsPFNh4ZvUOyQuzMqlwxlTBnfcpI7COiVFzwU5i7 Kh46iOm6VO6gPmtmj2vn2dabUejlwv7uesL9o= 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=TDEJin9Wub/pTmZCaG0ahvo3TESho8nP0MZ/DG5F4bU=; b=ITR+Nvy+L/ioXmqMupStkWTOCQw01AE1MyGnUyHnpIAr5gSEbZNrilBRjcJU58tQAq nAC/mxgG0aHs3Qt9DhRCy34Vbk0eIOenBpu7EoxcWRo8D2+FlTTDe/nZakEKcaS1R/yx fat68ch0VBevNJ/nnsX8wgb9ai1pm5e0dMLqb1p+RyJi481UwRj0gabktufaxIH8j1P9 kPsFTSbPTEzQ2ivikwOjdR5gJ5wuVFWRkjZD9EKHW2RaWvl7vV9NvEBXcwKGJeNzW9Le WsJb3P3CA/MhOGux48DqeqWRsjDsaLH4T8tbesMq82UmOIhiOh445NHLPD5q3Nny8rD2 LHZQ== X-Gm-Message-State: AOAM533Tq+zpcd02isVw6s6N7cug7ve4QZLLOasXTuaqjcZ1PvsPrdRo YGCu/OCuqQBKtCJrcoKMMZIFxw== X-Google-Smtp-Source: ABdhPJzuPEadJHFC6DHS+OKXKCrBNBoHbYtFLfXrapFarUbsAE/PiuGk7n5gPew0+g/APt+J5HIwJA== X-Received: by 2002:a5d:4d52:: with SMTP id a18mr4233102wru.406.1635414500859; Thu, 28 Oct 2021 02:48:20 -0700 (PDT) Received: from altair.lan (2.f.6.6.b.3.3.0.3.a.d.b.6.0.6.0.f.f.6.2.a.5.a.7.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:7a5a:26ff:606:bda3:33b:66f2]) by smtp.googlemail.com with ESMTPSA id i6sm3378029wry.71.2021.10.28.02.48.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Oct 2021 02:48:20 -0700 (PDT) From: Lorenz Bauer To: viro@zeniv.linux.org.uk, Hugh Dickins , Andrew Morton , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: mszeredi@redhat.com, gregkh@linuxfoundation.org, Lorenz Bauer , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH bpf-next v3 1/4] libfs: move shmem_exchange to simple_rename_exchange Date: Thu, 28 Oct 2021 10:47:21 +0100 Message-Id: <20211028094724.59043-2-lmb@cloudflare.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211028094724.59043-1-lmb@cloudflare.com> References: <20211028094724.59043-1-lmb@cloudflare.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Move shmem_exchange and make it available to other callers. Suggested-by: Signed-off-by: Lorenz Bauer Acked-by: Miklos Szeredi --- fs/libfs.c | 24 ++++++++++++++++++++++++ include/linux/fs.h | 2 ++ mm/shmem.c | 24 +----------------------- 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index 51b4de3b3447..1cf144dc9ed2 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -448,6 +448,30 @@ int simple_rmdir(struct inode *dir, struct dentry *dentry) } EXPORT_SYMBOL(simple_rmdir); +int simple_rename_exchange(struct inode *old_dir, struct dentry *old_dentry, + struct inode *new_dir, struct dentry *new_dentry) +{ + bool old_is_dir = d_is_dir(old_dentry); + bool new_is_dir = d_is_dir(new_dentry); + + if (old_dir != new_dir && old_is_dir != new_is_dir) { + if (old_is_dir) { + drop_nlink(old_dir); + inc_nlink(new_dir); + } else { + drop_nlink(new_dir); + inc_nlink(old_dir); + } + } + old_dir->i_ctime = old_dir->i_mtime = + new_dir->i_ctime = new_dir->i_mtime = + d_inode(old_dentry)->i_ctime = + d_inode(new_dentry)->i_ctime = current_time(old_dir); + + return 0; +} +EXPORT_SYMBOL_GPL(simple_rename_exchange); + int simple_rename(struct user_namespace *mnt_userns, struct inode *old_dir, struct dentry *old_dentry, struct inode *new_dir, struct dentry *new_dentry, unsigned int flags) diff --git a/include/linux/fs.h b/include/linux/fs.h index e7a633353fd2..333b8af405ce 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3383,6 +3383,8 @@ extern int simple_open(struct inode *inode, struct file *file); extern int simple_link(struct dentry *, struct inode *, struct dentry *); extern int simple_unlink(struct inode *, struct dentry *); extern int simple_rmdir(struct inode *, struct dentry *); +extern int simple_rename_exchange(struct inode *old_dir, struct dentry *old_dentry, + struct inode *new_dir, struct dentry *new_dentry); extern int simple_rename(struct user_namespace *, struct inode *, struct dentry *, struct inode *, struct dentry *, unsigned int); diff --git a/mm/shmem.c b/mm/shmem.c index b5860f4a2738..a18dde3d3092 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2945,28 +2945,6 @@ static int shmem_rmdir(struct inode *dir, struct dentry *dentry) return shmem_unlink(dir, dentry); } -static int shmem_exchange(struct inode *old_dir, struct dentry *old_dentry, struct inode *new_dir, struct dentry *new_dentry) -{ - bool old_is_dir = d_is_dir(old_dentry); - bool new_is_dir = d_is_dir(new_dentry); - - if (old_dir != new_dir && old_is_dir != new_is_dir) { - if (old_is_dir) { - drop_nlink(old_dir); - inc_nlink(new_dir); - } else { - drop_nlink(new_dir); - inc_nlink(old_dir); - } - } - old_dir->i_ctime = old_dir->i_mtime = - new_dir->i_ctime = new_dir->i_mtime = - d_inode(old_dentry)->i_ctime = - d_inode(new_dentry)->i_ctime = current_time(old_dir); - - return 0; -} - static int shmem_whiteout(struct user_namespace *mnt_userns, struct inode *old_dir, struct dentry *old_dentry) { @@ -3012,7 +2990,7 @@ static int shmem_rename2(struct user_namespace *mnt_userns, return -EINVAL; if (flags & RENAME_EXCHANGE) - return shmem_exchange(old_dir, old_dentry, new_dir, new_dentry); + return simple_rename_exchange(old_dir, old_dentry, new_dir, new_dentry); if (!simple_empty(new_dentry)) return -ENOTEMPTY; From patchwork Thu Oct 28 09:47:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenz Bauer X-Patchwork-Id: 12589679 X-Patchwork-Delegate: bpf@iogearbox.net 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5D2AC43219 for ; Thu, 28 Oct 2021 09:48:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7B21B610D2 for ; Thu, 28 Oct 2021 09:48:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230111AbhJ1Juw (ORCPT ); Thu, 28 Oct 2021 05:50:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230119AbhJ1Juu (ORCPT ); Thu, 28 Oct 2021 05:50:50 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 447CBC061243 for ; Thu, 28 Oct 2021 02:48:23 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id d13so9052833wrf.11 for ; Thu, 28 Oct 2021 02:48:23 -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=Yiz7MiIC+w5wxi7ovhqP5wkmEdrKSKSQKMo0rSjvbko=; b=JTF2MCL5w0PpoQtF94DGwsa3VstO6Faq3yeusALoRsVLeuyTY044h/nYCZyewX8A8U cuiaM0GLTss4nOzwJOrpPfli1mxpQmBUtu80yJDHR5FZJvA+ua9/iVIeuVeM7By/QYbM 9FQxfRPwyDhdvuvHLcS2ZW1LnvCLIR6WqZtkI= 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=Yiz7MiIC+w5wxi7ovhqP5wkmEdrKSKSQKMo0rSjvbko=; b=WcJvK/C5Zrjl4Bn2YIGqEBPBLfiVBFv6biCb00JXPWM5ct/2lDO/oGNVtoMpRroKxR tcyYNUa0/MRcuSDX+L3w+mS7FN28bY74O9iU+hRS0B/aunv6St8Grxd0iimNBGuakl6b sSlRDalXNKAav6/WgzEEZFTwoN1TPvyNDWbxSb/6I7X0D9KU3W03Qk/YGHnePifKYYVU zAI4o9J448k+sIXF+zXlwEMB8Yt8JoNYiaeYqU211ek6TNaySyFgxDHkI1DA1/kjoBkp W0bYDiHEhl0Tp96PoMnPPgX5YpbmrT2hCYLonwDTSSubABO04ZEh/h1RX9TiiK5of15O 35mw== X-Gm-Message-State: AOAM5339lypQJd+i3t8AdhuMdR6u2Kn2DBPmXxPTOJZgcwcsDv6GJP88 U+aYrmeARViRkK/mZzmacOQ6SA== X-Google-Smtp-Source: ABdhPJzHZI6Qzejpe7gF+o+e2+cssreAhde5t4LpII5b7rhQbXbt4OeISNb7STE/0Jv9wfcQoGsYuw== X-Received: by 2002:adf:e483:: with SMTP id i3mr4231238wrm.175.1635414501867; Thu, 28 Oct 2021 02:48:21 -0700 (PDT) Received: from altair.lan (2.f.6.6.b.3.3.0.3.a.d.b.6.0.6.0.f.f.6.2.a.5.a.7.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:7a5a:26ff:606:bda3:33b:66f2]) by smtp.googlemail.com with ESMTPSA id i6sm3378029wry.71.2021.10.28.02.48.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Oct 2021 02:48:21 -0700 (PDT) From: Lorenz Bauer To: viro@zeniv.linux.org.uk, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: mszeredi@redhat.com, gregkh@linuxfoundation.org, Lorenz Bauer , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH bpf-next v3 2/4] libfs: support RENAME_EXCHANGE in simple_rename() Date: Thu, 28 Oct 2021 10:47:22 +0100 Message-Id: <20211028094724.59043-3-lmb@cloudflare.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211028094724.59043-1-lmb@cloudflare.com> References: <20211028094724.59043-1-lmb@cloudflare.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Allow atomic exchange via RENAME_EXCHANGE when using simple_rename. This affects binderfs, ramfs, hubetlbfs and bpffs. Signed-off-by: Lorenz Bauer Acked-by: Christian Brauner --- fs/libfs.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/libfs.c b/fs/libfs.c index 1cf144dc9ed2..ba7438ab9371 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -479,9 +479,12 @@ int simple_rename(struct user_namespace *mnt_userns, struct inode *old_dir, struct inode *inode = d_inode(old_dentry); int they_are_dirs = d_is_dir(old_dentry); - if (flags & ~RENAME_NOREPLACE) + if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE)) return -EINVAL; + if (flags & RENAME_EXCHANGE) + return simple_rename_exchange(old_dir, old_dentry, new_dir, new_dentry); + if (!simple_empty(new_dentry)) return -ENOTEMPTY; From patchwork Thu Oct 28 09:47:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenz Bauer X-Patchwork-Id: 12589681 X-Patchwork-Delegate: bpf@iogearbox.net 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 322F5C433FE for ; Thu, 28 Oct 2021 09:48:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1A22060F9B for ; Thu, 28 Oct 2021 09:48:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230185AbhJ1Jux (ORCPT ); Thu, 28 Oct 2021 05:50:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230093AbhJ1Juv (ORCPT ); Thu, 28 Oct 2021 05:50:51 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38FB1C061225 for ; Thu, 28 Oct 2021 02:48:24 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id v17so9055234wrv.9 for ; Thu, 28 Oct 2021 02:48:24 -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=r3QcDl+qrCs7DfRcj3nDkgEldBtCcz4guF3zRxr4yw0=; b=V1tUt0C+yOFlv1l6b4PrP7zPJM4iHTVUGYIiH5UnTUEaG0AniQhwCxz1BJDgWfiTOr UWi1hgVhvCQQv+5lrpnBpaoMDmriNh1Q342XoCjlM/oJg/9lolw1gbl7XDwAeJrHzO2K ujDlfcvNKS6rSwtYQGaw7+zuEOlPJGPxpyYPo= 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=r3QcDl+qrCs7DfRcj3nDkgEldBtCcz4guF3zRxr4yw0=; b=Ov7LrayTUChZhU+dG8c7XWOUGcUidaMxazfAmTXX7qArlMUcFURVJ3ac8X2EeO0H9a vfAac9M1VHadLa8GLRbBvwOrqbT/Ja/n9FGx7Y3zTYTfN9uhNg1g8xllhLqzYz0c/sjo L+wpOmtJuMQUTU2oX3WjVi06ATvVze5zEipEzMZTPqhe3Hkd6m1jm6PEi5Fi9WyCs3qv DjlXAg6V7sKbiSE2bW2nuJmr0PpzeDvCb2XdGDTHd4hifeqANqqWeeUlCVyXkQzRT7co jbO4M5oHW62pKYfKHU0hSJJ0FMVUk1guYNIlEpxLysumlTwkK0n6hfJyvVSWwH0GWT0Z k+SQ== X-Gm-Message-State: AOAM532wZBTR7K4IOzCECM65ASC2sQfUQ0jW/RHxo/8MXYtI/wtsp4Vr pXNm6X44RdQPVVQjkkfkxBBmwQ== X-Google-Smtp-Source: ABdhPJzIo8pks7n2t0RUJFJiDKpZeJEfJSYFuhEHfnaygEuP2ulaLXtrXHHK1wlBmnYNMksso8MRXg== X-Received: by 2002:adf:ee43:: with SMTP id w3mr4157256wro.198.1635414502859; Thu, 28 Oct 2021 02:48:22 -0700 (PDT) Received: from altair.lan (2.f.6.6.b.3.3.0.3.a.d.b.6.0.6.0.f.f.6.2.a.5.a.7.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:7a5a:26ff:606:bda3:33b:66f2]) by smtp.googlemail.com with ESMTPSA id i6sm3378029wry.71.2021.10.28.02.48.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Oct 2021 02:48:22 -0700 (PDT) From: Lorenz Bauer To: viro@zeniv.linux.org.uk, Shuah Khan , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: mszeredi@redhat.com, gregkh@linuxfoundation.org, Lorenz Bauer , linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next v3 3/4] selftests: bpf: convert test_bpffs to ASSERT macros Date: Thu, 28 Oct 2021 10:47:23 +0100 Message-Id: <20211028094724.59043-4-lmb@cloudflare.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211028094724.59043-1-lmb@cloudflare.com> References: <20211028094724.59043-1-lmb@cloudflare.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Remove usage of deprecated CHECK macros. Signed-off-by: Lorenz Bauer --- .../selftests/bpf/prog_tests/test_bpffs.c | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/test_bpffs.c b/tools/testing/selftests/bpf/prog_tests/test_bpffs.c index 172c999e523c..533e3f3a459a 100644 --- a/tools/testing/selftests/bpf/prog_tests/test_bpffs.c +++ b/tools/testing/selftests/bpf/prog_tests/test_bpffs.c @@ -29,43 +29,43 @@ static int read_iter(char *file) static int fn(void) { - int err, duration = 0; + int err; err = unshare(CLONE_NEWNS); - if (CHECK(err, "unshare", "failed: %d\n", errno)) + if (!ASSERT_OK(err, "unshare")) goto out; err = mount("", "/", "", MS_REC | MS_PRIVATE, NULL); - if (CHECK(err, "mount /", "failed: %d\n", errno)) + if (!ASSERT_OK(err, "mount /")) goto out; err = umount(TDIR); - if (CHECK(err, "umount " TDIR, "failed: %d\n", errno)) + if (!ASSERT_OK(err, "umount " TDIR)) goto out; err = mount("none", TDIR, "tmpfs", 0, NULL); - if (CHECK(err, "mount", "mount root failed: %d\n", errno)) + if (!ASSERT_OK(err, "mount tmpfs")) goto out; err = mkdir(TDIR "/fs1", 0777); - if (CHECK(err, "mkdir "TDIR"/fs1", "failed: %d\n", errno)) + if (!ASSERT_OK(err, "mkdir " TDIR "/fs1")) goto out; err = mkdir(TDIR "/fs2", 0777); - if (CHECK(err, "mkdir "TDIR"/fs2", "failed: %d\n", errno)) + if (!ASSERT_OK(err, "mkdir " TDIR "/fs2")) goto out; err = mount("bpf", TDIR "/fs1", "bpf", 0, NULL); - if (CHECK(err, "mount bpffs "TDIR"/fs1", "failed: %d\n", errno)) + if (!ASSERT_OK(err, "mount bpffs " TDIR "/fs1")) goto out; err = mount("bpf", TDIR "/fs2", "bpf", 0, NULL); - if (CHECK(err, "mount bpffs " TDIR "/fs2", "failed: %d\n", errno)) + if (!ASSERT_OK(err, "mount bpffs " TDIR "/fs2")) goto out; err = read_iter(TDIR "/fs1/maps.debug"); - if (CHECK(err, "reading " TDIR "/fs1/maps.debug", "failed\n")) + if (!ASSERT_OK(err, "reading " TDIR "/fs1/maps.debug")) goto out; err = read_iter(TDIR "/fs2/progs.debug"); - if (CHECK(err, "reading " TDIR "/fs2/progs.debug", "failed\n")) + if (!ASSERT_OK(err, "reading " TDIR "/fs2/progs.debug")) goto out; out: umount(TDIR "/fs1"); From patchwork Thu Oct 28 09:47:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenz Bauer X-Patchwork-Id: 12589683 X-Patchwork-Delegate: bpf@iogearbox.net 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFA36C4332F for ; Thu, 28 Oct 2021 09:48:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AC8B96112F for ; Thu, 28 Oct 2021 09:48:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230204AbhJ1Ju4 (ORCPT ); Thu, 28 Oct 2021 05:50:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229626AbhJ1Juw (ORCPT ); Thu, 28 Oct 2021 05:50:52 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 420F6C061570 for ; Thu, 28 Oct 2021 02:48:25 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id b2-20020a1c8002000000b0032fb900951eso654032wmd.4 for ; Thu, 28 Oct 2021 02:48:25 -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=ZaAreBeSojAVPrdAUspWmFMN01Pw9vpD9iNJLz69uRDTgfjNojHGm4jITuhKRBxEeZ jCEFnusSdYFQG1mz7NV801OW+4Xau5zhrUxj4gPK0kVknJrsg+mxY/eDuE3T6VLLKhby SO8kKacYT8u+LlES/iknuTHDgSWkt4ogyHPDE= 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=BcTymunzvCKkWeVTI+eY3vZFSEnezpMINPEQW3EeC5bB2m3hGKi5jDA3TgQslcKref O670m7u4dNwBxnQpym6WwjFXQyoFz0VR8OE4JYmliLQPNrZR7gameNgKVCM0+dK5J6sp /hoWYaMEmF3kDiIeuHwEma3UDgjmpa4hMyNyUMY7OQ2OljNow79Diwa/W2b8mvpdYoIu iCBNwSHF2K36IL9iV9LRIyTT/2pHM2DRbALhQ0hN+HirPLwAPAfyeQIAkwxm7EHDCN4x hlU/q4G78vaIdPzJl5uUNwD4v5m1Q2EyY4Den9+B/VrtVs9Js4WLJVPIVc6tEw4q5Y6p 7bDA== X-Gm-Message-State: AOAM532T7x2N09e+nTX+fql2f0A7m1t+sGn855GEdOiYyHXLHgoSaEb3 wMKOUuTwbosq5coubyvx++vxGA== X-Google-Smtp-Source: ABdhPJx6yn8XpE55PL/NDDyWj0wiSNcnZKApHrqoLEGCBiHaSDslHVx/ymfDR2GLyqJZ/7SX0JBR4A== X-Received: by 2002:a1c:f319:: with SMTP id q25mr3310603wmq.33.1635414503789; Thu, 28 Oct 2021 02:48:23 -0700 (PDT) Received: from altair.lan (2.f.6.6.b.3.3.0.3.a.d.b.6.0.6.0.f.f.6.2.a.5.a.7.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:7a5a:26ff:606:bda3:33b:66f2]) by smtp.googlemail.com with ESMTPSA id i6sm3378029wry.71.2021.10.28.02.48.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Oct 2021 02:48:23 -0700 (PDT) From: Lorenz Bauer To: viro@zeniv.linux.org.uk, Shuah Khan , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: mszeredi@redhat.com, gregkh@linuxfoundation.org, Lorenz Bauer , linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next v3 4/4] selftests: bpf: test RENAME_EXCHANGE and RENAME_NOREPLACE on bpffs Date: Thu, 28 Oct 2021 10:47:24 +0100 Message-Id: <20211028094724.59043-5-lmb@cloudflare.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211028094724.59043-1-lmb@cloudflare.com> References: <20211028094724.59043-1-lmb@cloudflare.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net 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");