Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp802813rdh; Thu, 23 Nov 2023 20:19:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IG/WFMFHaBwfWez5NXYZg2qs7cz3kIwYDRBbxduRZ6drCDiYlt7P6gJDatl3uhzizkTmaSi X-Received: by 2002:a05:6a00:15d0:b0:6c3:1b7d:dac9 with SMTP id o16-20020a056a0015d000b006c31b7ddac9mr1823519pfu.34.1700799579766; Thu, 23 Nov 2023 20:19:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700799579; cv=none; d=google.com; s=arc-20160816; b=W18/BAQG8aY0avK4uumfd40mFyw/mHTRb0ZD1IR1JXakmCwKQ2lJ30s+08sVyIvR8u C+EVeSVYdnEJp4p25Hub0zYl7nAxIvNMs2FwLgXJ0G4lX2p+UCMstletfL6+c0pNQUi6 GhQLXDasA7/AU0bKTBjlv2knX4lFzjCTU67g48fpIA7eO8O3qiK1QsjKD0ZyxuJN8tQB 5BmULDIW/i98I16HMksqQFghncavSvfzknKJ+oT/npg5McN78IxPLn3C9rGrpduSgdAs j35oDnazF1/yhE+GEVG8jLclCOaUW4LSNCmyesgx9Wy3JkP+jVfX176UARQhB6sPogjy ZQGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-signature; bh=omeWePB3jH6tIgfQoj8aRvHvFRnEFTlgknAY1wCXGoU=; fh=1UvAp7GUQSaqrdARWG8zoUWPhj4hWkACxxyVSa4vxWY=; b=RozeKhTL/g7X8zWgoPCeXL/f/D6awhPtwHpafxu1eQXVKs4sqY8Fuw/CqnaGzpKs/8 aAq/6LQ64tkjOVIfV56yYarPMDNPRk9krcdZ2aSY5wZd/jhdkvJ3/Xul018foSZOxsvM Eom5oHC6vFvmeIXSCiaUiqw3uFgb9ve3Hah2c0bfh3ALZwUwIAPY5eq5r7wxeZiTCZ9Z 4ZC4KmcwdzzUkhOUU78i9nMGnamR0uDo2xVjNgqZXcsFOCKj7sQoR8GQfvW4CJXpLVOO sOW1m0l3mmelkVmzZGm+Ib+8J62J/WO7Be8H287BgBjDc8fD3MxaHANBwnzRSAPey9Cj 6QKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=agUeiy+m; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id 16-20020a631050000000b005bd043751ccsi2676955pgq.748.2023.11.23.20.19.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 20:19:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=agUeiy+m; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 8D21E805DC6B; Thu, 23 Nov 2023 20:19:31 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229940AbjKXETR (ORCPT + 99 others); Thu, 23 Nov 2023 23:19:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230372AbjKXETP (ORCPT ); Thu, 23 Nov 2023 23:19:15 -0500 X-Greylist: delayed 99 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 23 Nov 2023 20:19:21 PST Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62EA5D43; Thu, 23 Nov 2023 20:19:21 -0800 (PST) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id D36D01FD14; Thu, 23 Nov 2023 15:33:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1700753592; h=from:from:reply-to: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=omeWePB3jH6tIgfQoj8aRvHvFRnEFTlgknAY1wCXGoU=; b=agUeiy+mXLYfptxnifo6GkUdb6gDP+S7iYTI+TBDR7orWZWNjulyvAN/A3M68PeLzYATQz LvInQv4emsDYrpxjfdyExBOjL9cfA5bSzJN3yUD8YuU8GTofOumb2Vg9xyXT3rSPPGuDAQ FoOFvOUFG/foLOXpxkXje6OVer6CqSw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1700753592; h=from:from:reply-to: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=omeWePB3jH6tIgfQoj8aRvHvFRnEFTlgknAY1wCXGoU=; b=UUPLwpzXbPgqzNm4TugN2s0bkxoe8qMx5ZRbUvDEQVV1zuSwy6sthWxdlXLRMVpJWhOHSb 8SQ1Is1qz1EL9FAw== Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 059DF13A82; Thu, 23 Nov 2023 11:57:33 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id zMEEAS0+X2WiZgAAn2gu4w (envelope-from ); Thu, 23 Nov 2023 11:57:33 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 5AF64A07DB; Thu, 23 Nov 2023 10:31:12 +0100 (CET) Date: Thu, 23 Nov 2023 10:31:12 +0100 From: Jan Kara To: Al Viro Cc: linux-fsdevel@vger.kernel.org, Linus Torvalds , Mo Zou , Jan Kara , linux-kernel@vger.kernel.org Subject: Re: [PATCH 5/9] ext4: don't access the source subdirectory content on same-directory rename Message-ID: <20231123093112.rkgqmyaocisvyeyh@quack3> References: <20231122193028.GE38156@ZenIV> <20231122193652.419091-1-viro@zeniv.linux.org.uk> <20231122193652.419091-5-viro@zeniv.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231122193652.419091-5-viro@zeniv.linux.org.uk> Authentication-Results: smtp-out2.suse.de; none X-Spam-Score: -6.60 X-Spam-Level: X-Spamd-Result: default: False [-6.60 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; REPLY(-4.00)[]; RCPT_COUNT_FIVE(0.00)[6]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[linux.org.uk:email,suse.cz:email,suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; MID_RHS_NOT_FQDN(0.50)[]; FREEMAIL_CC(0.00)[vger.kernel.org,linux-foundation.org,gmail.com,suse.cz]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,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 morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 23 Nov 2023 20:19:31 -0800 (PST) On Wed 22-11-23 19:36:48, Al Viro wrote: > We can't really afford locking the source on same-directory rename; > currently vfs_rename() tries to do that, but it will have to be changed. > The logics in ext4 is lazy and goes looking for ".." in source even in > same-directory case. It's not hard to get rid of that, leaving that > behaviour only for cross-directory case; that VFS can get locks safely > (and will keep doing that after the coming changes). > > Signed-off-by: Al Viro Looks good to me. Feel free to add: Reviewed-by: Jan Kara Honza > --- > fs/ext4/namei.c | 21 +++++++++++++-------- > 1 file changed, 13 insertions(+), 8 deletions(-) > > diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c > index d252935f9c8a..467ba47a691c 100644 > --- a/fs/ext4/namei.c > +++ b/fs/ext4/namei.c > @@ -3591,10 +3591,14 @@ struct ext4_renament { > int dir_inlined; > }; > > -static int ext4_rename_dir_prepare(handle_t *handle, struct ext4_renament *ent) > +static int ext4_rename_dir_prepare(handle_t *handle, struct ext4_renament *ent, bool is_cross) > { > int retval; > > + ent->is_dir = true; > + if (!is_cross) > + return 0; > + > ent->dir_bh = ext4_get_first_dir_block(handle, ent->inode, > &retval, &ent->parent_de, > &ent->dir_inlined); > @@ -3612,6 +3616,9 @@ static int ext4_rename_dir_finish(handle_t *handle, struct ext4_renament *ent, > { > int retval; > > + if (!ent->dir_bh) > + return 0; > + > ent->parent_de->inode = cpu_to_le32(dir_ino); > BUFFER_TRACE(ent->dir_bh, "call ext4_handle_dirty_metadata"); > if (!ent->dir_inlined) { > @@ -3900,7 +3907,7 @@ static int ext4_rename(struct mnt_idmap *idmap, struct inode *old_dir, > if (new.dir != old.dir && EXT4_DIR_LINK_MAX(new.dir)) > goto end_rename; > } > - retval = ext4_rename_dir_prepare(handle, &old); > + retval = ext4_rename_dir_prepare(handle, &old, new.dir != old.dir); > if (retval) > goto end_rename; > } > @@ -3964,7 +3971,7 @@ static int ext4_rename(struct mnt_idmap *idmap, struct inode *old_dir, > } > inode_set_mtime_to_ts(old.dir, inode_set_ctime_current(old.dir)); > ext4_update_dx_flag(old.dir); > - if (old.dir_bh) { > + if (old.is_dir) { > retval = ext4_rename_dir_finish(handle, &old, new.dir->i_ino); > if (retval) > goto end_rename; > @@ -3987,7 +3994,7 @@ static int ext4_rename(struct mnt_idmap *idmap, struct inode *old_dir, > if (unlikely(retval)) > goto end_rename; > > - if (S_ISDIR(old.inode->i_mode)) { > + if (old.is_dir) { > /* > * We disable fast commits here that's because the > * replay code is not yet capable of changing dot dot > @@ -4114,14 +4121,12 @@ static int ext4_cross_rename(struct inode *old_dir, struct dentry *old_dentry, > ext4_handle_sync(handle); > > if (S_ISDIR(old.inode->i_mode)) { > - old.is_dir = true; > - retval = ext4_rename_dir_prepare(handle, &old); > + retval = ext4_rename_dir_prepare(handle, &old, new.dir != old.dir); > if (retval) > goto end_rename; > } > if (S_ISDIR(new.inode->i_mode)) { > - new.is_dir = true; > - retval = ext4_rename_dir_prepare(handle, &new); > + retval = ext4_rename_dir_prepare(handle, &new, new.dir != old.dir); > if (retval) > goto end_rename; > } > -- > 2.39.2 > -- Jan Kara SUSE Labs, CR