Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1338544pxb; Thu, 28 Oct 2021 01:45:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCy9S5VaXExkUss6iOTUUznZgjlSleuTibDk670IlXarUqw584ovDzL0NwbtpI2GDwMA5O X-Received: by 2002:a17:90b:3511:: with SMTP id ls17mr11340755pjb.145.1635410703554; Thu, 28 Oct 2021 01:45:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635410703; cv=none; d=google.com; s=arc-20160816; b=C5hcHNAplKe2XdP3rwBZFkTLv3Iwm/BG9G5JUisG+eoaixz24Rc1UpDduYczz0E2ao FbJHX3x3YLhOfK9PxXUmeBrGY8qnWXItVMMtEV3MKSCc0zBJbPsV4HtxzNpZO+6BGBhZ YefTxURv5975632cqQmM9BdcTlLF0Ygccf9QdrmP2jhFp0kSyDFB7Jdi72ysHRxsLPlS qN0od8ZOvV2ud7xF8KExkOpco+CnvX8tZJT2FASg7lDNRSPN6i60K/LcVQrO4hzYzol5 qvmmjoQ0IAE5Ia6y2FLnEibsb6t/ojl3tfG1ugFr5UtwbsXfHUFJepxvKP9kVy88aWPU OmhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=KccYG4rSdcXMoVRo53pQg4Ozdzh38yw0Q7oh7hWL/OA=; b=y0lv/+tq+TJfRzQvqI3zECwj1RaxZTO65ZhtGcJC5q2rdCMyaoKN/8M9oMDEgUefaV SF2nQZLtZFHjN5xZdOSZvz83ScZCvkiOsYlRFQw0GJg0cGA8hB3VIkFjRCkQopqDT9nh EqOqelbbv5+js0AsBY0nPHL9LrjMVvTneTgk8+Q5SUhj1HV9LQAAWRklohR6WpeN3ET7 Be+JGKKz7ABVN74CfVzYK9MSYuh2+yI64hoHWqf3LmYim6YigBfEr0PDc0DzwceRsoMw tf5atqXAxmYoHOITHrSjAgk/yaEAlhS+OckyVbOD+UqJxdQd9qrG74JtCWt0h+7AKBww e7JQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=W53oVEaD; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u1si3366779pga.592.2021.10.28.01.44.51; Thu, 28 Oct 2021 01:45:03 -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=@redhat.com header.s=mimecast20190719 header.b=W53oVEaD; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229626AbhJ1IqX (ORCPT + 99 others); Thu, 28 Oct 2021 04:46:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:37494 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229800AbhJ1IqW (ORCPT ); Thu, 28 Oct 2021 04:46:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635410635; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=KccYG4rSdcXMoVRo53pQg4Ozdzh38yw0Q7oh7hWL/OA=; b=W53oVEaDQzM8VF6YoIGich0YcmQU7TxrAmiqolsqmbApNLJD5N0jCCnjEoOjGsd2oNqg2x vIjegVBS5fClyOdzmOHGzoycz8fSkZNNJeLO3f3KXjBC6eJoGv/qXcsDF6b5+9+qTc7Z4K Tn72LK5p6uxxzsfaHbRvF0tZfq88XiU= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-167-j9wFlNvAPLWXvlWpG2AP-g-1; Thu, 28 Oct 2021 04:43:54 -0400 X-MC-Unique: j9wFlNvAPLWXvlWpG2AP-g-1 Received: by mail-qv1-f72.google.com with SMTP id gi5-20020a056214248500b00382f7a7c7e6so4345064qvb.21 for ; Thu, 28 Oct 2021 01:43:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=KccYG4rSdcXMoVRo53pQg4Ozdzh38yw0Q7oh7hWL/OA=; b=Gt1nU+tB7HqmZOxNhcLs67o2Yzejx6a2M8PTWmVL64VQmTbKZwFmhQ8NoX4rjPadLc 2W3Czx+oKrQYLiROGQLy+vhzPE+ppweQ3or5Fs4wIsl7nqbxIPAv2B4pjlYDgRVxfSWD wC/klEVNMwF9oIyWIW6hN6A3ixPtU2DzFrlrdmmHvA4Cob3Mpi1RFMRAmvHOhRH8Y57q /cAEsihieRl3s2d0NS+Hb0e7EL9twK8atr5rlNT+vFlv3hi9jVod3//BkfUtZnItQE+/ Ba+jjCaeA84A9xGA296OLYHb9CnE/ijpuk7X9NWui/8Xf3usYuGZPFEAAYq9+l8HhGCW xDNA== X-Gm-Message-State: AOAM531EY5vrWql1MNmECa1dOPgDAKEVRBIMfpuYtmbdXurc5QL4qjrf 92EjnQffP9GO4eXgtJMenXfZCneTmzC0XBspNXpk3UDKy+EBZHO72VV8HxGzUETjxFTJlGL97Jf Y19G8JKxAfhY9r2s8mja15sBh9+TH6Z7fFv5NEFOK X-Received: by 2002:a05:620a:15f3:: with SMTP id p19mr2422629qkm.337.1635410634134; Thu, 28 Oct 2021 01:43:54 -0700 (PDT) X-Received: by 2002:a05:620a:15f3:: with SMTP id p19mr2422618qkm.337.1635410633974; Thu, 28 Oct 2021 01:43:53 -0700 (PDT) MIME-Version: 1.0 References: <20211021151528.116818-1-lmb@cloudflare.com> <20211021151528.116818-2-lmb@cloudflare.com> In-Reply-To: From: Miklos Szeredi Date: Thu, 28 Oct 2021 10:43:43 +0200 Message-ID: Subject: Re: [PATCH bpf-next v2 1/3] libfs: support RENAME_EXCHANGE in simple_rename() To: Daniel Borkmann Cc: Lorenz Bauer , Alexander Viro , Alexei Starovoitov , Andrii Nakryiko , kernel-team@cloudflare.com, linux-fsdevel , lkml , netdev@vger.kernel.org, bpf@vger.kernel.org, Greg Kroah-Hartman Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 28, 2021 at 1:46 AM Daniel Borkmann wrote: > > [ Adding Miklos & Greg to Cc for review given e0e0be8a8355 ("libfs: support RENAME_NOREPLACE in > simple_rename()"). If you have a chance, would be great if you could take a look, thanks! ] > > On 10/21/21 5:15 PM, Lorenz Bauer wrote: > > Allow atomic exchange via RENAME_EXCHANGE when using simple_rename. > > This affects binderfs, ramfs, hubetlbfs and bpffs. There isn't much > > to do except update the various *time fields. > > > > Signed-off-by: Lorenz Bauer > > --- > > fs/libfs.c | 6 +++++- > > 1 file changed, 5 insertions(+), 1 deletion(-) > > > > diff --git a/fs/libfs.c b/fs/libfs.c > > index 51b4de3b3447..93c03d593749 100644 > > --- a/fs/libfs.c > > +++ b/fs/libfs.c > > @@ -455,9 +455,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) > > + goto done; > > + This is not sufficient. RENAME_EXCHANGE can swap a dir and a non-dir, in which case the parent nlink counters need to be fixed up. See shmem_exchange(). My suggestion is to move that function to libfs.c:simple_rename_exchange(). Thanks, Miklos