From patchwork Fri Nov 8 17:32:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13868586 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 0B01DD64070 for ; Fri, 8 Nov 2024 17:36:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0A732900004; Fri, 8 Nov 2024 12:36:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 030BE8D0001; Fri, 8 Nov 2024 12:36:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD08E900004; Fri, 8 Nov 2024 12:36:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id B38AA8D0001 for ; Fri, 8 Nov 2024 12:36:24 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 78192120E64 for ; Fri, 8 Nov 2024 17:36:24 +0000 (UTC) X-FDA: 82763629326.20.34AC4C9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf28.hostedemail.com (Postfix) with ESMTP id 10709C000D for ; Fri, 8 Nov 2024 17:35:44 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="e/AIslVi"; spf=pass (imf28.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=1731087155; 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=xT95iRI7GFEw7/DsY259MSksQtxbslsuX0w7QNZo9gI=; b=Hl7nPRSX50PM4Pq5KrLsQHohZ092YxiebBqV7tv4vRSwoSoh6py8RhWf8Sy3oAso+RQVze ss1kFu3Z3eymJk/Nqy42JMAEE74lHdlf+d9ZgC5ChZWJwKlfR11P3IcDoDKA+wCtOsn2d5 iecefo8n6Yj7xO69pxV7My75qO4RZt8= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="e/AIslVi"; spf=pass (imf28.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731087155; a=rsa-sha256; cv=none; b=rwVSkeNXI3i0unYhjVAqltA3v1hAkwXWQ5A1PVaAM1LPsr2vdDGQHQzxLhtjheWIFE3SXt FjHiMZjryWMgP9K4hyJx45SSJTQGc+kuPZaYKnNAka0cIXbXybbmOH/ej+DE9WhZID0iwO roeSrrEcEgtj6J7c+/CKGFifQ8yii5c= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731087382; 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=xT95iRI7GFEw7/DsY259MSksQtxbslsuX0w7QNZo9gI=; b=e/AIslVivp+FCaktipzFon0DR42fp02Qk08MjBFWRcStTye/tbVmcybNBzNse2I/vdV7NA XKi4UTO+plwE5PBuqQoMH9+3/1j2NGz+ehH52ZLvYjWrsb6JS9ZPQEiwCS84qmy9sOg0q7 D9oQBOvKAhp5YMEgKYhSpZY6IDTpWTg= 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-292-gbmONp36NJu4Uorphe299A-1; Fri, 08 Nov 2024 12:36:18 -0500 X-MC-Unique: gbmONp36NJu4Uorphe299A-1 X-Mimecast-MFC-AGG-ID: gbmONp36NJu4Uorphe299A 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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9E3C51953942; Fri, 8 Nov 2024 17:36:15 +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 0DF60300019E; Fri, 8 Nov 2024 17:36:09 +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 v4 29/33] afs: Make afs_mkdir() locally initialise a new directory's content Date: Fri, 8 Nov 2024 17:32:30 +0000 Message-ID: <20241108173236.1382366-30-dhowells@redhat.com> In-Reply-To: <20241108173236.1382366-1-dhowells@redhat.com> References: <20241108173236.1382366-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 10709C000D X-Stat-Signature: qo1hp7g4fq3cyrgt8xt7e1jyi5n3w85p X-Rspam-User: X-HE-Tag: 1731087344-373755 X-HE-Meta: U2FsdGVkX1+SIyHNJvyvVZbYaCxFd66D0vnRI9BUISFPm2MbePz08zB510KWY0QMTiVV6GMESgWeE7Y7iEiJ0fX2BWp7qKlLooj8LlREMKVcdeNZ1mamkirdWAKG1DmsbpISCn8j3eviuXvfdHDTPEhwjq58TyhAcZWRi2JcHx/X+1ZFO3bGilNQYRfRZ5/c8pDnIpa8E6myRdrUBN4rGfAIHLYoFq1troHgPFSeSxvm6AnWOOrC6G4jGhPVS2OeRaZ/TDbEW1OBV6mK5Lpztyk5KsYpb/OGkARtHHMecjOcjIk02OFdTIxH/sWsjd2+BUXahP2hjrcD2GYLi3nOW3tLnoceymZPk/bvhxvGkFKXCs8JALfhJp7N7oFii7NDddpZQGmM9AbHyOJsgWNFCNPy/I7HsxlIIj0RRML+qOMhd5ov0zjxc1nU0oP4E36iBD9Tig3k/z/Sm9bQb5nkCj/ijA5Lk1+tSYNVd3BBkxRDkxxNfE7GkCk9jGzkYU18XSEEKVGEDn9uOYr++EvUbnIoMBvugC24MN7/g9R6YDoLrb/WupKTse4LL8yLaDtJm05U+BKFLkKAOQ8QvptrAzs3t9P9imDTbbIDS6l7GT8DsUlZZ6/PB5O5rQ0+CzsiIOkhv9/XdV6DhCoDa9ZoNkuC6TUWaTD0Pm81FMoQB8ofOS0zdzx+D0YYAEmcG6IA506n9po/sCe8ak6ACx2m49cpHxTAXp+TgTOMfxfTm6kRW5B6Ug8CrevlPqzzQmWR2/zR+psQUhdceqnQNdMzRVoj7of1uWNYngnwoiKycaN8ciruHrD6ks7JlNE4GYSn5j8/fZGvZAbccclxwKNzxNtXHoauPD8pD1Izlha2fPx7Y2GfCzp9S+EcMCn1f6MHOXwZjnAtJ+rvEn01LInHzwQ93DRzfwOegE2MIWQ5QAD0kjtyJqXEUXhHBYF8rzbd/aXyv5FeyCa7aNeU33m z8HWYdjm XCGJB9W0sDMgH6FCGXOR11cy/kDNOWgE0eLDpQmZ7vNubWDaXxgb59e09Mth6DGRcAjUIz/a2t52sSqrFY4zfzOd4z1RlJO23nRSzi8EmT0+5dm49F4gPztRo56a56TIQ22DGHHLyfbE+Wi9ltvK0taC0CWI8Ir2CmIK90ryGGK5qvwQTwBpqxfDeTKn5r+of3SUaG/TJAb4+n5NwMGmt+bsNhcdPnY0f80lYvDA2+FRfi/8Y67h1RaPNdlNo6LqjpHm3Gz/ohWqnDjD1g2pv6MjeZS6fiIS0XrL8r8tiz7EZIqAB/prcAgZnaVbeWwFZ98RaAB9RiLvziTTpnSgF2k/h0wR+smplZ3cRR2/Vl7t9bSNXZPkkpnpd8+yunzb5++9q3BSOaYUBcwTW8Q8NgcuOv+F7iK6LxmhA2Zjqz0tfDgzpNP7QNhE4Kmrcu+Ws2cnJklOhcFtjVLPafDrsRKmn6anH2ggDkANJ0bBvllnHXDE= 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 | 49 ++++++++++++++++++++++++++++++++++++++ fs/afs/internal.h | 1 + include/trace/events/afs.h | 2 ++ 4 files changed, 55 insertions(+) diff --git a/fs/afs/dir.c b/fs/afs/dir.c index 36b80449ef0e..8c4c1029ea2f 100644 --- a/fs/afs/dir.c +++ b/fs/afs/dir.c @@ -1259,6 +1259,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; @@ -1278,6 +1279,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..53178bb2d1a6 100644 --- a/fs/afs/dir_edit.c +++ b/fs/afs/dir_edit.c @@ -556,3 +556,52 @@ 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); + set_bit(AFS_VNODE_DIR_READ, &dvnode->flags); +} diff --git a/fs/afs/internal.h b/fs/afs/internal.h index cd2c4f85117d..acae1b5bfc63 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -1078,6 +1078,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") \