From patchwork Fri Oct 25 20:39:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13851754 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0602D149F0 for ; Fri, 25 Oct 2024 20:43:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2E3396B00AD; Fri, 25 Oct 2024 16:43:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 26ADB6B00C1; Fri, 25 Oct 2024 16:43:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0BB416B00C2; Fri, 25 Oct 2024 16:43:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id DEB736B00AD for ; Fri, 25 Oct 2024 16:43:27 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id A132E120918 for ; Fri, 25 Oct 2024 20:43:09 +0000 (UTC) X-FDA: 82713299466.22.42B4D4D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 75FC44001A for ; Fri, 25 Oct 2024 20:43:01 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=S8BflTGZ; spf=pass (imf11.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729888852; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=DNBmYsisi11F4a9GdaB4+2hzkwarlQJLH0bImPjM4eE=; b=O65Cu9+zUsOLvAlknzND1yxXaz6qsgIxI0NozF6g3d0sVIwuzmUs5KVW/ZT7qvFr18hHRz qAIPxx+eFLLy+n+g20HBVqs8BgL3zWHuCbreOn4607+QEfLXCbvwdV+fiSPBfL/Ycw9DOn AznspYm8czZdBJii2jgVSwQejcUTQ0g= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729888852; a=rsa-sha256; cv=none; b=ribsKmmRNJAtrkhX02YuTdpY+Nb72JEp24hxHtzrw0WCHj8+lXTKSLw1kUooQA3qxtl9+c JYhPtObsKzRoWLId/D4RaQoP5CNwgZWDf28YzSSh9/JUq2MgMOb0jvyliBU//uzKqnQ8Cu RTibPJJ1TT8oj2az9D5Dbx5BmFep+Bo= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=S8BflTGZ; spf=pass (imf11.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729889005; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DNBmYsisi11F4a9GdaB4+2hzkwarlQJLH0bImPjM4eE=; b=S8BflTGZ+4/wIlugVWMRVH2XkdBDH0rR7nOm4Us14+QcCzWlIBdZqBq33XGZL1NRM6jQ85 GHCEx8IPZZn14/YXrr/vOr/pwpQJUsPtDW4/fcQrKpKEDylyho3jMepA2tWThl50zJaFp+ JfvK1zlKXtYEfNmXSht8faYDXCKExA8= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-580-LBc8O0OjOoyLZPAMboBZnQ-1; Fri, 25 Oct 2024 16:43:21 -0400 X-MC-Unique: LBc8O0OjOoyLZPAMboBZnQ-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id F3FE11955F3E; Fri, 25 Oct 2024 20:43:16 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.42.28.231]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 206F6300018D; Fri, 25 Oct 2024 20:43:11 +0000 (UTC) From: David Howells To: Christian Brauner , Steve French , Matthew Wilcox Cc: David Howells , Jeff Layton , Gao Xiang , Dominique Martinet , Marc Dionne , Paulo Alcantara , Shyam Prasad N , Tom Talpey , Eric Van Hensbergen , Ilya Dryomov , netfs@lists.linux.dev, linux-afs@lists.infradead.org, linux-cifs@vger.kernel.org, linux-nfs@vger.kernel.org, ceph-devel@vger.kernel.org, v9fs@lists.linux.dev, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 27/31] afs: Make afs_mkdir() locally initialise a new directory's content Date: Fri, 25 Oct 2024 21:39:54 +0100 Message-ID: <20241025204008.4076565-28-dhowells@redhat.com> In-Reply-To: <20241025204008.4076565-1-dhowells@redhat.com> References: <20241025204008.4076565-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Rspamd-Queue-Id: 75FC44001A X-Stat-Signature: nmddu5unyzf16kumrzsghcu6w4a7kmae X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1729888981-306933 X-HE-Meta: U2FsdGVkX1/ooa4Q5ANZ1B286i8WHS6gYFCGbUo8vjNkPEs7BHu3clL0txo3LcuoyD+guWwB1WEx31OFwXtSZbNQk50LEJA8DMPjPKsw+riN8jl5PQGvF7ooaoZT6w2Dudeqty1zo+ZTA58bu6LLGV2CpYjE7FgMvkLLWFX8/6qgfU3i5OkjBPm+sBcOPfBZhLauQGtwroQ5p2+/pcVwSRqxPMquGR9Ocy0qgAGEjtU8iRXVZ51YR0G0xpq+HAGfCMKBXN7jAdO1rICjJNviGGSGBnxU0SxmueqtQCFaGUV4cvB9eHyPpWiJjv4ANxd1uk7102efyIK3KDNNKDeEHdud8OYNbkJmzX1vTY6AHqStGkh2ZcLfR9+3v8H83UUlltwqZJJ/JZdTHikzETAPNJ6eyB2kg/MctDei8r1OCR+WJehUf4tAt8GzjHgGdbPgq8SYW5vWnkBti994dx/o4ErEh/7TIQ96HXpAPzGbqIYXxCW5u/aMwuxngXhc44Nx84fM8R2pDNSI1Ew8g1EdhUVYXk/x+RyiujUZIIhs2Rigaf9+ovbjw/EK/ZwkqfkGc68p7EfUbZgM/K3mc/seIsAuMQJgr+/pFu4Bxg8TpFHR/oY9jnfSrYyD56Pk63WlgnvKSw+/TiTD0EOtAbxqMyx4kba6QAz+TIluADzykYz2rAzs48/H536UJ4+XerGyuKQ3YuWP54A/2MTr0/QTo2TXhDXcdeJPsayi7pFCbgxbvrRpfDK+19rdhOeoGw3cdxrQPOQXE78drU7o91mfn1fkcjwDS7ueftobh9BRmMXsuyE5zWsvTB8tfMtHNfU9voLkpVoZ1ZItMGeixv9TYMkHU4JPoFPRvQUkVW9KpxIX7ebzcN3omDyL1HdQi39VdnBGDwq+75Oe8AjVtCKZcLqkYq51Fl0YPU6+HvbVaRweP+FFX519RmCWcAf8pEhi2L8iLtCQqENkexJ63Kt RD3E0zrZ 4XWl+UPyeCEIxGnL+leZfWi3IqCtjcl9ADhK8+4IQbmPZbe4eP8S+Lg/yGZ/WLfBoTc/QioCkCZXvFGvEnbCW9IdxoB/kCbIYEoCG8qfKH+M7bbg5qlMkoH3ovghOkkBW8Ew4ou+0bet6plmGUHIYJTD900UTKZQAQehOxDPWQeyruh6asFjDmnSN8xvK1CH0Ri07kXDC9roX1lrK/K2IRoGHmXRIrHBCvQYN22y+niIJEO5QHZ8uGvvrJz2SMvJL7rrm9K9NvpkDWllCnktKhPOzw+WnGn/8BnPbClzBX6Daq1iYhQUaT50ORySfMYR5mCKLYfMO+7TINGXt6iZ8OH1OtNpks6IgD+dw6tIyMDYw4xPXNmqSWrv3+MqUyIgNS4iZpXiUHQJoaXuu9T0cOCXCarez5dX6N31f/Xm5PO5Sf+obBgNq4AUYHoEwEsRTPkykLI/ylJ5o/DMJ1lzZJNLovRmi3yVw6wBpFuPYDoD68lM= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Initialise a new directory's content when it is created by mkdir locally rather than downloading the content from the server as we can predict what it's going to look like. Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- fs/afs/dir.c | 3 +++ fs/afs/dir_edit.c | 48 ++++++++++++++++++++++++++++++++++++++ fs/afs/internal.h | 1 + include/trace/events/afs.h | 2 ++ 4 files changed, 54 insertions(+) diff --git a/fs/afs/dir.c b/fs/afs/dir.c index 4b1b25015573..aa589f0d55bf 100644 --- a/fs/afs/dir.c +++ b/fs/afs/dir.c @@ -1258,6 +1258,7 @@ void afs_check_for_remote_deletion(struct afs_operation *op) */ static void afs_vnode_new_inode(struct afs_operation *op) { + struct afs_vnode_param *dvp = &op->file[0]; struct afs_vnode_param *vp = &op->file[1]; struct afs_vnode *vnode; struct inode *inode; @@ -1277,6 +1278,8 @@ static void afs_vnode_new_inode(struct afs_operation *op) vnode = AFS_FS_I(inode); set_bit(AFS_VNODE_NEW_CONTENT, &vnode->flags); + if (S_ISDIR(inode->i_mode)) + afs_mkdir_init_dir(vnode, dvp->vnode); if (!afs_op_error(op)) afs_cache_permit(vnode, op->key, vnode->cb_break, &vp->scb); d_instantiate(op->dentry, inode); diff --git a/fs/afs/dir_edit.c b/fs/afs/dir_edit.c index 71cce884e434..f4037973416e 100644 --- a/fs/afs/dir_edit.c +++ b/fs/afs/dir_edit.c @@ -556,3 +556,51 @@ void afs_edit_dir_update_dotdot(struct afs_vnode *vnode, struct afs_vnode *new_d 0, 0, 0, 0, ".."); goto out; } + +/* + * Initialise a new directory. We need to fill in the "." and ".." entries. + */ +void afs_mkdir_init_dir(struct afs_vnode *dvnode, struct afs_vnode *parent_dvnode) +{ + union afs_xdr_dir_block *meta; + struct afs_dir_iter iter = { .dvnode = dvnode }; + union afs_xdr_dirent *de; + unsigned int slot = AFS_DIR_RESV_BLOCKS0; + loff_t i_size; + + i_size = i_size_read(&dvnode->netfs.inode); + if (i_size != AFS_DIR_BLOCK_SIZE) { + afs_invalidate_dir(dvnode, afs_dir_invalid_edit_add_bad_size); + return; + } + + meta = afs_dir_get_block(&iter, 0); + if (!meta) + return; + + afs_edit_init_block(meta, meta, 0); + + de = &meta->dirents[slot]; + de->u.valid = 1; + de->u.vnode = htonl(dvnode->fid.vnode); + de->u.unique = htonl(dvnode->fid.unique); + memcpy(de->u.name, ".", 2); + trace_afs_edit_dir(dvnode, afs_edit_dir_for_mkdir, afs_edit_dir_mkdir, 0, slot, + dvnode->fid.vnode, dvnode->fid.unique, "."); + slot++; + + de = &meta->dirents[slot]; + de->u.valid = 1; + de->u.vnode = htonl(parent_dvnode->fid.vnode); + de->u.unique = htonl(parent_dvnode->fid.unique); + memcpy(de->u.name, "..", 3); + trace_afs_edit_dir(dvnode, afs_edit_dir_for_mkdir, afs_edit_dir_mkdir, 0, slot, + parent_dvnode->fid.vnode, parent_dvnode->fid.unique, ".."); + + afs_set_contig_bits(meta, AFS_DIR_RESV_BLOCKS0, 2); + meta->meta.alloc_ctrs[0] -= 2; + kunmap_local(meta); + + netfs_single_mark_inode_dirty(&dvnode->netfs.inode); + set_bit(AFS_VNODE_DIR_VALID, &dvnode->flags); +} diff --git a/fs/afs/internal.h b/fs/afs/internal.h index c7f0d75eab7f..3acf1445e444 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -1074,6 +1074,7 @@ extern void afs_edit_dir_add(struct afs_vnode *, struct qstr *, struct afs_fid * extern void afs_edit_dir_remove(struct afs_vnode *, struct qstr *, enum afs_edit_dir_reason); void afs_edit_dir_update_dotdot(struct afs_vnode *vnode, struct afs_vnode *new_dvnode, enum afs_edit_dir_reason why); +void afs_mkdir_init_dir(struct afs_vnode *dvnode, struct afs_vnode *parent_vnode); /* * dir_silly.c diff --git a/include/trace/events/afs.h b/include/trace/events/afs.h index 49a749672e38..020ab7302a6b 100644 --- a/include/trace/events/afs.h +++ b/include/trace/events/afs.h @@ -348,6 +348,7 @@ enum yfs_cm_operation { EM(afs_dir_invalid_edit_add_no_slots, "edit-add-no-slots") \ EM(afs_dir_invalid_edit_add_too_many_blocks, "edit-add-too-many-blocks") \ EM(afs_dir_invalid_edit_get_block, "edit-get-block") \ + EM(afs_dir_invalid_edit_mkdir, "edit-mkdir") \ EM(afs_dir_invalid_edit_rem_bad_size, "edit-rem-bad-size") \ EM(afs_dir_invalid_edit_rem_wrong_name, "edit-rem-wrong_name") \ EM(afs_dir_invalid_edit_upd_bad_size, "edit-upd-bad-size") \ @@ -369,6 +370,7 @@ enum yfs_cm_operation { EM(afs_edit_dir_delete_error, "d_err ") \ EM(afs_edit_dir_delete_inval, "d_invl") \ EM(afs_edit_dir_delete_noent, "d_nent") \ + EM(afs_edit_dir_mkdir, "mk_ent") \ EM(afs_edit_dir_update_dd, "u_ddot") \ EM(afs_edit_dir_update_error, "u_fail") \ EM(afs_edit_dir_update_inval, "u_invl") \