From nobody Thu May 23 06:08:32 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4VlHmK0Tc3z5HDQC; Thu, 23 May 2024 06:08:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VlHmJ6qXbz4T6L; Thu, 23 May 2024 06:08:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716444513; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=t3Hd8gO5XLmQT/kVXQNHYpHU9sWfkahYjeQaX8wj3Ek=; b=BHg3KfhQDelkyjllc6ATcXU1yHfg2K6naFzIB0dAWOxNI6rOIxNpms6XZEUsY4ack3Xt4U 4+xljqMJPysoK7pT3p09AXri+9EjHYRyJ3wTWVvK7/eVgplbM77neuHYbrBsmBQv4z7C9K YGDq8Dl9J6NUIh2TiDz0jWBOex7ioWp96GaqrM4E07a9xZYI5+6AeWll6Ln5H8yqw9tdQ5 16yqqrTAY3QeLIZI+4na4HKBlSL4Oi/TyYj3IjajFTFI2N92QFmaf16wHxmMGWUa1hg2+L S5wzQT293TrEeccM3t6VvlqDMXb0t1zFde+mwEwfee65F+YFycU5G+qqagjvfw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1716444513; a=rsa-sha256; cv=none; b=e8FCZ6R+G/IpmEAwf3RtCD1ImaHLnf6Rp1db0RSzPzZQzOo4YphNMXdFKqZQVlfuf+Oucj VsW6V/0+oPTJvtpIIsqPNlk39B0bQ1QpcM/Ha7d9KsvBMmuGb6rXTJZmATqLsMBRY+MSOq q2rGj5TecUtywEuBjUowJ7BZct3qYQdJZHmtWYxpgJPmuqv4zyvQwu7teNcNPDkANMk3dP LJnUU70CLr4soPxuucCFLcyV/xlW+9CBkwWEp0/M++vicfCbzjE/IdjAsGIosF9KMd/y58 L8FfEUxemzIlg+8NgloE01kyFESvUqwAWtch1SMawfOkmmT7Y1KY4kkrYgVGPQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716444513; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=t3Hd8gO5XLmQT/kVXQNHYpHU9sWfkahYjeQaX8wj3Ek=; b=EvlEboG0fFzlY9rSiCvKNgIzIrPYGvft9AMRDRLGrliag9lGth3Suqe7niKw7k5Kjmfd94 tKqC3AyKbDSYKGI9D0kXj5ITVcBa1FWbbtd9gb7KTbevR1AS4pn6WnBs2P6M7i1Q6C7KqV y0Cds30DoiXmhzGEMbD7JGlPRxVMeZlG8EmAihSbGRsnp3vyOESy4AP/5jdmMH45zMaBLN FYclzndeNbrIl5QywbcUjUOPVB4/eKd3sV8Ujzv4LTqow8I4/Y6px8a+mA7o5WQ5kMOTyA y0lf4jlzj3wbGRZaXluESaJB6ufLUniEn7oEKOJhY8eBxB27sUOkh9Qqg8pe6g== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4VlHmJ6P8pzdGx; Thu, 23 May 2024 06:08:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 44N68WFr000244; Thu, 23 May 2024 06:08:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44N68WUV000241; Thu, 23 May 2024 06:08:32 GMT (envelope-from git) Date: Thu, 23 May 2024 06:08:32 GMT Message-Id: <202405230608.44N68WUV000241@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Pawel Jakub Dawidek Subject: git: 56a8aca83ab5 - main - Stop treating size 0 as unknown size in vnode_create_vobject(). List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: pjd X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 56a8aca83ab5a93af05f4c8c3a358b71a8392af8 Auto-Submitted: auto-generated The branch main has been updated by pjd: URL: https://cgit.FreeBSD.org/src/commit/?id=56a8aca83ab5a93af05f4c8c3a358b71a8392af8 commit 56a8aca83ab5a93af05f4c8c3a358b71a8392af8 Author: Pawel Jakub Dawidek AuthorDate: 2024-05-19 01:08:41 +0000 Commit: Pawel Jakub Dawidek CommitDate: 2024-05-23 06:08:14 +0000 Stop treating size 0 as unknown size in vnode_create_vobject(). Whenever file is created, the vnode_create_vobject() function will try to determine its size by calling vn_getsize_locked() as size 0 is ambigious: it means either the file size is 0 or the file size is unknown. Introduce special value for the size argument: VNODE_NO_SIZE. Only when it is given, the vnode_create_vobject() will try to obtain file's size on its own. Introduce dedicated vnode_disk_create_vobject() for use by g_vfs_open(), so we don't have to call vn_isdisk() in the common case (for regular files). Handle the case of mediasize==0 in g_vfs_open(). Reviewed by: alc, kib, markj, olce Approved by: oshogbo (mentor), allanjude (mentor) Differential Revision: https://reviews.freebsd.org/D45244 --- sys/fs/ext2fs/ext2_vfsops.c | 2 +- sys/fs/fuse/fuse_node.c | 2 +- sys/fs/fuse/fuse_vfsops.c | 2 +- sys/geom/geom_vfs.c | 11 ++++++++++- sys/sys/vnode.h | 7 +++++++ sys/vm/vnode_pager.c | 45 +++++++++++++++++++++++++++++++-------------- 6 files changed, 51 insertions(+), 18 deletions(-) diff --git a/sys/fs/ext2fs/ext2_vfsops.c b/sys/fs/ext2fs/ext2_vfsops.c index bffbf4546f37..9e7a03fffd71 100644 --- a/sys/fs/ext2fs/ext2_vfsops.c +++ b/sys/fs/ext2fs/ext2_vfsops.c @@ -1345,7 +1345,7 @@ ext2_fhtovp(struct mount *mp, struct fid *fhp, int flags, struct vnode **vpp) return (ESTALE); } *vpp = nvp; - vnode_create_vobject(*vpp, 0, curthread); + vnode_create_vobject(*vpp, ip->i_size, curthread); return (0); } diff --git a/sys/fs/fuse/fuse_node.c b/sys/fs/fuse/fuse_node.c index 777519450954..0a24d0da4fac 100644 --- a/sys/fs/fuse/fuse_node.c +++ b/sys/fs/fuse/fuse_node.c @@ -354,7 +354,7 @@ void fuse_vnode_open(struct vnode *vp, int32_t fuse_open_flags, struct thread *td) { if (vnode_vtype(vp) == VREG) - vnode_create_vobject(vp, 0, td); + vnode_create_vobject(vp, VNODE_NO_SIZE, td); } int diff --git a/sys/fs/fuse/fuse_vfsops.c b/sys/fs/fuse/fuse_vfsops.c index e088f92bf5bf..e60c9aa80cfa 100644 --- a/sys/fs/fuse/fuse_vfsops.c +++ b/sys/fs/fuse/fuse_vfsops.c @@ -286,7 +286,7 @@ fuse_vfsop_fhtovp(struct mount *mp, struct fid *fhp, int flags, return (ESTALE); } *vpp = nvp; - vnode_create_vobject(*vpp, 0, curthread); + vnode_create_vobject(*vpp, VNODE_NO_SIZE, curthread); return (0); } diff --git a/sys/geom/geom_vfs.c b/sys/geom/geom_vfs.c index 87b2fea21baa..d9e9a6c82da1 100644 --- a/sys/geom/geom_vfs.c +++ b/sys/geom/geom_vfs.c @@ -292,7 +292,16 @@ g_vfs_open(struct vnode *vp, struct g_consumer **cpp, const char *fsname, int wr g_wither_geom(gp, ENXIO); return (error); } - vnode_create_vobject(vp, pp->mediasize, curthread); + /* + * Mediasize might not be set until first access (see g_disk_access()), + * That's why we check it here and not earlier. + */ + if (pp->mediasize == 0) { + (void)g_access(cp, -1, -wr, -wr); + g_wither_geom(gp, ENXIO); + return (ENXIO); + } + vnode_create_disk_vobject(vp, pp->mediasize, curthread); *cpp = cp; cp->private = vp; cp->flags |= G_CF_DIRECT_SEND | G_CF_DIRECT_RECEIVE; diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h index 987cf995f606..dc926d7a9c9e 100644 --- a/sys/sys/vnode.h +++ b/sys/sys/vnode.h @@ -1081,7 +1081,14 @@ vrefcnt(struct vnode *vp) vref(vp); \ } while (0) +/* + * The caller doesn't know the file size and vnode_create_vobject() should + * determine the size on its own. + */ +#define VNODE_NO_SIZE ((off_t)-1) + int vnode_create_vobject(struct vnode *vp, off_t size, struct thread *td); +int vnode_create_disk_vobject(struct vnode *vp, off_t size, struct thread *td); void vnode_destroy_vobject(struct vnode *vp); extern struct vop_vector fifo_specops; diff --git a/sys/vm/vnode_pager.c b/sys/vm/vnode_pager.c index d32fec845043..98b905f27c4a 100644 --- a/sys/vm/vnode_pager.c +++ b/sys/vm/vnode_pager.c @@ -146,27 +146,22 @@ vnode_pager_init(void *dummy) SYSINIT(vnode_pager, SI_SUB_CPU, SI_ORDER_ANY, vnode_pager_init, NULL); /* Create the VM system backing object for this vnode */ -int -vnode_create_vobject(struct vnode *vp, off_t isize, struct thread *td) +static int +vnode_create_vobject_any(struct vnode *vp, off_t isize, struct thread *td) { vm_object_t object; - vm_ooffset_t size = isize; + vm_ooffset_t size; bool last; - if (!vn_isdisk(vp) && vn_canvmio(vp) == FALSE) - return (0); - object = vp->v_object; if (object != NULL) return (0); - if (size == 0) { - if (vn_isdisk(vp)) { - size = IDX_TO_OFF(INT_MAX); - } else { - if (vn_getsize_locked(vp, &size, td->td_ucred) != 0) - return (0); - } + if (isize == VNODE_NO_SIZE) { + if (vn_getsize_locked(vp, &size, td->td_ucred) != 0) + return (0); + } else { + size = isize; } object = vnode_pager_alloc(vp, size, 0, 0, td->td_ucred); @@ -182,11 +177,33 @@ vnode_create_vobject(struct vnode *vp, off_t isize, struct thread *td) if (last) vrele(vp); - KASSERT(vp->v_object != NULL, ("vnode_create_vobject: NULL object")); + VNASSERT(vp->v_object != NULL, vp, ("%s: NULL object", __func__)); return (0); } +int +vnode_create_vobject(struct vnode *vp, off_t isize, struct thread *td) +{ + VNASSERT(!vn_isdisk(vp), vp, ("%s: disk vnode", __func__)); + VNASSERT(isize == VNODE_NO_SIZE || isize >= 0, vp, + ("%s: invalid size (%jd)", __func__, (intmax_t)isize)); + + if (!vn_canvmio(vp)) + return (0); + + return (vnode_create_vobject_any(vp, isize, td)); +} + +int +vnode_create_disk_vobject(struct vnode *vp, off_t isize, struct thread *td) +{ + VNASSERT(isize > 0, vp, ("%s: invalid size (%jd)", __func__, + (intmax_t)isize)); + + return (vnode_create_vobject_any(vp, isize, td)); +} + void vnode_destroy_vobject(struct vnode *vp) {