From patchwork Wed Nov 6 12:35:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13864797 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 29BA5D44D57 for ; Wed, 6 Nov 2024 12:39:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 954FB8D000B; Wed, 6 Nov 2024 07:39:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8DF328D0001; Wed, 6 Nov 2024 07:39:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7095C8D000B; Wed, 6 Nov 2024 07:39:56 -0500 (EST) 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 4811A8D0001 for ; Wed, 6 Nov 2024 07:39:56 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 07DF680200 for ; Wed, 6 Nov 2024 12:39:56 +0000 (UTC) X-FDA: 82755626814.02.08A38C5 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf24.hostedemail.com (Postfix) with ESMTP id A4976180006 for ; Wed, 6 Nov 2024 12:39:49 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cIkLUYeh; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf24.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730896735; a=rsa-sha256; cv=none; b=s0wvK2nkprKoiUyXYJqhgRy+DkpF8L6xRv/Sn3UXOO8rY2cAgu3P6ZMJvyeo4WP/TwNoy8 DDRvDKNRJPnqSS3Dhu3gOL6XEyZqaoF5KKlEejZFWW5doj/3+kBTEGfpAdnq77AizmNXbK c8MUPBIUxI6yf+3vz2m6JFLwzpIahkg= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cIkLUYeh; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf24.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730896735; 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=xzpKBUK2tltbM1JTinkFiBtaf3Y2PKq5iqCKH2QUCE0=; b=FUEeypURV3Z4O0wH2OldIX9+Ypzml4K7/1S7mxmkgQMG8trIU78Gusv4R5R8LsL55t991V CydhH56DmqB4kZip953j4ZDdONODk2I9CR0DEJeG3x7g1g0CNUdOTgyAeDJL2wrzvje5Qv uE/otUkTzZeMMUTaQEZYjt3uYNiXQy0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730896793; 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=xzpKBUK2tltbM1JTinkFiBtaf3Y2PKq5iqCKH2QUCE0=; b=cIkLUYehEpLHSR3E5ed36E5E9L1yPSiZxEzazzHeQxzN0rM2pnJ2ItC/l0fjW9zFXAHbcx SzYJcaBzy5kjeoj8Iy0F7a+BjWrCZIIuMSU9HvzPzT6bvwnlS0opzImLB8bdg3SDtRwW/W 2mXwoFDn9tmbvZ4+klpf05BMd/S51jg= Received: from mx-prod-mc-04.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-137-cyG4cguPO0qRL60CsEtGOg-1; Wed, 06 Nov 2024 07:39:48 -0500 X-MC-Unique: cyG4cguPO0qRL60CsEtGOg-1 X-Mimecast-MFC-AGG-ID: cyG4cguPO0qRL60CsEtGOg Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id F2E521955E7A; Wed, 6 Nov 2024 12:39:45 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.42.28.231]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 752541956054; Wed, 6 Nov 2024 12:39:40 +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 v3 29/33] afs: Make afs_mkdir() locally initialise a new directory's content Date: Wed, 6 Nov 2024 12:35:53 +0000 Message-ID: <20241106123559.724888-30-dhowells@redhat.com> In-Reply-To: <20241106123559.724888-1-dhowells@redhat.com> References: <20241106123559.724888-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Rspam-User: X-Rspamd-Queue-Id: A4976180006 X-Rspamd-Server: rspam11 X-Stat-Signature: rue1kzzz9kpqjpc1139mspohae8u1oau X-HE-Tag: 1730896789-585145 X-HE-Meta: U2FsdGVkX1+G2b1k+kGFosFYhK/37AnZGM6LQ8oFkLb5Y/gj6KOMJZjtTo3LMi7OEQFIgrocLxT4NA+gnvDRN/np7ubHc33B/b4W3lDyQIs4bUe7Uw/0oOrHopoyRSp2IcYiAAK22dAE9Dn5Fm5N6K70Pl9JV2dkMgUqhfVRUnB3JwIIBRNi0qSI5a89XXKgrxksvg1CKgnnr879KJ8oX/DKlHld41fL+5JDKf/fArqZu9y5LCHQWEh0rn+7l44WVFvlesemEgUTLEUKE+W/hXAX31Jrs4cN3XKZgdG3TiQTz4Ibirk9GRMgbr0faJs1RMFfdIe3mlb1SH617WobgWH1EDidxQHFf4vby87qmk3clgNL0h/7/b/EdXPDC2zsqUja94CP02Lu55KfZqluRN/6VaxeJ5bqZwM42SbpXMI5gJxoPPGC39OJpuZMJikYMo2wmYc7BozHQ1Tar3eTXvpu4NIr7gFYwlub/4Q7OhvyaMsav2idv4dQwLP3lK8N1P9boLsNlQBZcMktFT4NEqa2OXmraRDme8iWkmwwh/FhboscsxgdDT3gYUBdonp8K3NoVpVvDDpmn9JUV0/YaYsXjcmwjrHYgV6tuCGYh/cqJ2hwtwQ3s5ECOEMURaJ9WC/c2CIKhFDo/plumukULdOZAq2e+zlAvn2vK+ZiCpn66XYFUp8YAXAzI9lIUEDGPte9E1ya/VzWTLN6I/UyCDkK7KGJnlDxbs947Oi7AdBnyFNv2kSkV5DzmGDI6zSniroYGZxKWBeNp1FRxgFzjCZH6yXVXuwloNXhpjN5LXiFQiujLY0lBQKOkfGdbN9EM3IEqKKMBJd2M7YRNzbmdEPCj9IyQKmzZqTKbq+ZeVKdWyOfBheQh0oKSZngstAE0E4xCucXJTOEu+MxMtvyEG9CjPtMZHIgMVAHPidE13fUrazuocFP00XNqKVSq/gF+nhU6HwP7yveNv/YmTv qkwCd4pO nciikseKnNsKvltdzTfIEDYaohw47dc2yDXIlSiwoTcXIjwD+zDgkbKWN6aUZfsfyhzm9vMcJGI9NxqFTiHTiVtrVTpMfRfXLLmbO1oF1jBAJKd1oWy4aYKxK1MgPNNm8pQJ3YQVEphphpQB26h7pWm2eHV51fr5Q6Tue/F+BY4gQ1F7bpLY9YDCITV/OZSXcjtZv/iFkNc1bk7H3Z21HV5K0Tx4iKZx8GjXaRywSEzB81AvGhPGg5EStChr01kjk3ZE4Nk6Bujr8td+I8FQ4gd1LQjoxaCrsw8VHrOssIG+q39p/BrTz5MqHIx65Nt+Lqec1C96zj0XR2vb7StB8FuEbIAL19ejBnDro4wSZ4JqD0dn6PDgeZOD9RHALF/NVr+p6KMEOYYwfSoUbudrh0ore0QCExfyjM0t3yGOB4DY/cPhBd+mZG+6g9AuvYHEcreuWAwCIG0YUCC+rB375AGtCq8VMZBLDGhXA/r7cG0bz9dU= 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 466d3b5ef7df..dd0e5278204e 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -1077,6 +1077,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 cdb5f2af7799..c52fd83ca9b7 100644 --- a/include/trace/events/afs.h +++ b/include/trace/events/afs.h @@ -350,6 +350,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") \ @@ -371,6 +372,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") \