Received: by 2002:a05:7412:e79e:b0:f3:1519:9f41 with SMTP id o30csp145406rdd; Wed, 22 Nov 2023 11:38:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IET1gnL7/oAnkODS4L85+GLwjgS6d0S+WKHgofrVkKC2EpvCfFs21AuAOzHEQA8oxt0aClW X-Received: by 2002:a05:6808:120d:b0:3ae:16b6:6338 with SMTP id a13-20020a056808120d00b003ae16b66338mr4177508oil.3.1700681883255; Wed, 22 Nov 2023 11:38:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700681883; cv=none; d=google.com; s=arc-20160816; b=URP+4bfdKGcl+tMLgD/a3Iu8DrAyI9oo52pMU+nSqArRvaieaal73pfz8OdvnUknWn lrd51NuXeSy8yFqg2Hn01eMeJ35LFSV6/UnAW5tYeAHD9FqnT0I9I3N6ySTJ9TVA7aGF fuK40lUveNQBotyNGbTWKjXjES3rOA1rNb4T17+dG8Ffh1aCz8UENOkZIBBnCgTj3cDA LvuAZ3JZ8kKyacMUqvhw08pq2UWdCXdfO7vYfC9jWAa+jGQZbwLp1qQQEb/8ixb357qa YUzLVgLOh+u0nwgG1kJ7MUrY4ZxZ4BAW+zhCqRS8Shxcej/7q1cke9aT/EHMzfQsbQLo HxIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mSKI/kF/ejeHo+EBKx8s+JuNIL0q9sqkXoXpNGVtVqI=; fh=W6BEtqt7iV8phMzKg0C2MCZmXBORzGPTeuIhW3f8iqY=; b=qqNnpEjTvdxKdcObqBPs0tp2B6K+XawiNAWMFuldmogCiCBcLPqRrpw8GSOpK9rDM8 +QGBZzj3c8jZds+Y31GOSnEafqc9pXw8HDXIXRHOzSxPXDe/ogPvfNki976VPIIeLQ5p NtIvJ1yIlM/vGiEB0HaNs4xKOWdTMtJsznUJHL+MTJ7J/szDxtaF0I1/+97zLowWdq2k qdkVkbiaFtojr2N6fKtUF5pBAPRyuHGXq5p6YPF3+SoYl8RLp5ThbYC6fHMtPkyOtn+B Fg5iNrB3prc9vkgex2iBM6zx8gDC0Rv1hdXnJgFq1WC2OU2U/JzUxnIkF8H8atyzBT1v 66nA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=LqkoXTTq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id t1-20020a056a00138100b006bd5d6f7c71si161360pfg.390.2023.11.22.11.37.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 11:38:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=LqkoXTTq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 29DFB8271753; Wed, 22 Nov 2023 11:37:34 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344498AbjKVThC (ORCPT + 99 others); Wed, 22 Nov 2023 14:37:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343942AbjKVTg6 (ORCPT ); Wed, 22 Nov 2023 14:36:58 -0500 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [IPv6:2a03:a000:7:0:5054:ff:fe1c:15ff]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 968FB19D; Wed, 22 Nov 2023 11:36:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=mSKI/kF/ejeHo+EBKx8s+JuNIL0q9sqkXoXpNGVtVqI=; b=LqkoXTTqgqMlCQAJ5QbdD+KUHW uMAKXYkMjo/D4JcVUUvgAq3BRImH56DFBksI9uMj3OT564SbAF5UmKtVQ1mACT5R1dD6tP2QTaKnn A6I82CyhEuVTfnl4RBea9t4e8xEnYF71jNq1nqcAO+HUSmtE+rtRmzgn2uOmQ6po4RJ8iv8fQmkqR hA8xrDjtFs3ygp8R/8MFE7SIuW9CH4rypmFSTy8+Bsawf+FWPXl58ktLohSYbUWkrTmtmlYxokjKW GyYYnemfn0PUD5gJISng8I7Lytq+fuY6YdS6aoEyo2LxFYoK+YRc2WEJMIEwmk3GhentERu2taLFD hihENqsg==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1r5t1p-001l1m-0c; Wed, 22 Nov 2023 19:36:53 +0000 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: Linus Torvalds , Mo Zou , Jan Kara , linux-kernel@vger.kernel.org Subject: [PATCH 5/9] ext4: don't access the source subdirectory content on same-directory rename Date: Wed, 22 Nov 2023 19:36:48 +0000 Message-Id: <20231122193652.419091-5-viro@zeniv.linux.org.uk> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231122193652.419091-1-viro@zeniv.linux.org.uk> References: <20231122193028.GE38156@ZenIV> <20231122193652.419091-1-viro@zeniv.linux.org.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: Al Viro X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, 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 groat.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 (groat.vger.email [0.0.0.0]); Wed, 22 Nov 2023 11:37:34 -0800 (PST) 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 --- 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