From nobody Mon Jun 24 16:12:45 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 4W7Cfk1N7Gz5P9sv; Mon, 24 Jun 2024 16:12:46 +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 4W7Cfj6d7Nz4M5l; Mon, 24 Jun 2024 16:12:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1719245565; 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=eY4L00bnbZHs+h4xAcOYbtJqSNzMLqBMIQra2Eu2QAI=; b=p9nHjjgCd10kKtcGql9EIBgP+1Tx56URnilYRM7LmF3tVdMk1ftTmC6IY4/nEEaR/P0FFP DotYSwElzzZcbjJvuuVVPM+X8vI5lVZ8kNPXo8m9RVeCoMVMaz81zdl7AkVaSxGyqi8Rgj FAgU2g9/SEjIcscdwL884FDoXTAbOXFmn2JCGpnJ0lgUQgCkpJKVvJI0/HMFg5Gj1HYKwY EE6sMpP0uzjv64f3r0j+tj/wF69R3+B+wWjPoxdsX5kJYjq0EF2BLR8CJEJlcjYZ/RpXDC iz2YdPChEFG+/n2EJlUQWU6/4bMOLBWb+sXeSCsW1fnlgwV7grm4Y5Elwa/yxg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1719245565; a=rsa-sha256; cv=none; b=ilTdiHYrArtsqWkwg0TlogZi35RwFtgEg60uOuesE0plKsMw8eCJuNylNlVKIO+qMuW/3G N39tKNK/r7WTxQKjwXg8v3yC5C+I9t7Q57CEfOxa2i1o9AmkZpi2fQzG1cvCKamHAsEC0C 5F+9g8rw6cvU67eF4+zvnvELNj8IELD8a4eySNE9Fe/taeGpMlLAdz/dUaqrmKUeTpKMC5 mXgM8c/QCVO13NwTs8hsydBxQyKFy60CjkK5L0Ka8I/L/WpNF7x8Mo9M9Is8Hi2MMaRNfj IsvByd0jfAQHmoK1uvoLcfvWWqE/UlHB+w6v4zNa96p2q1PASSksf4n3vZ8ThA== 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=1719245565; 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=eY4L00bnbZHs+h4xAcOYbtJqSNzMLqBMIQra2Eu2QAI=; b=ryRxGyGtExFps572xMfIynQp0l59iSMEfOUWVwlV8KeC6/BntNTIL5nDH3WDS682XXUKbR Q1Q/uCgv/rQGFcS3+w+pveK2i1MIkJfa8Ty3xJRq8pRNt8nX9cAwuRAQiwQLz5n1UrXFDE 37sDXFLysHFavfiEnseb1oDdJCqccELpQECJXrBry4A5o2c+oVe4S1RMkeu9WQpoe0n3Gz BFVc/cKGt9tulR7DDhIkYYjtK4L1mcu0MRry5nTFZIC7btP93oI7Leo0Lwnl5pw9gw2/OC m5XiuD+ZT/I4XZz4Kg78QSj+MTeL6d5vdDdMhm8dPGJ5Z2PPdpf/LqACMtwnwQ== 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 4W7Cfj4tmQzQGc; Mon, 24 Jun 2024 16:12:45 +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 45OGCjdB040865; Mon, 24 Jun 2024 16:12:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 45OGCjTK040862; Mon, 24 Jun 2024 16:12:45 GMT (envelope-from git) Date: Mon, 24 Jun 2024 16:12:45 GMT Message-Id: <202406241612.45OGCjTK040862@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Doug Rabson Subject: git: daa2c99c89f2 - main - p9fs: implement working putpages (fix mmap write) 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: dfr X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: daa2c99c89f224200911aa6c8cdee07bc354947a Auto-Submitted: auto-generated The branch main has been updated by dfr: URL: https://cgit.FreeBSD.org/src/commit/?id=daa2c99c89f224200911aa6c8cdee07bc354947a commit daa2c99c89f224200911aa6c8cdee07bc354947a Author: Val Packett AuthorDate: 2024-06-24 13:37:58 +0000 Commit: Doug Rabson CommitDate: 2024-06-24 16:11:47 +0000 p9fs: implement working putpages (fix mmap write) Mostly copied from smbfs. This driver in its current state has the exact same issue that prevents the generic putpages implementation from working. Sponsored by: https://www.patreon.com/valpackett Reviewed by: dfr Differential Revision: https://reviews.freebsd.org/D45639 MFC after: 3 months --- sys/fs/p9fs/p9fs_vfsops.c | 6 ++++ sys/fs/p9fs/p9fs_vnops.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/sys/fs/p9fs/p9fs_vfsops.c b/sys/fs/p9fs/p9fs_vfsops.c index 6cc65aca35d3..f674c866ce9d 100644 --- a/sys/fs/p9fs/p9fs_vfsops.c +++ b/sys/fs/p9fs/p9fs_vfsops.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -53,6 +54,7 @@ static uma_zone_t p9fs_node_zone; uma_zone_t p9fs_io_buffer_zone; uma_zone_t p9fs_getattr_zone; uma_zone_t p9fs_setattr_zone; +uma_zone_t p9fs_pbuf_zone; extern struct vop_vector p9fs_vnops; /* option parsing */ @@ -106,6 +108,9 @@ p9fs_init(struct vfsconf *vfsp) p9fs_setattr_zone = uma_zcreate("p9fs setattr zone", sizeof(struct p9_iattr_dotl), NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0); + /* Create the putpages zone */ + p9fs_pbuf_zone = pbuf_zsecond_create("p9fs pbuf zone", nswbuf / 2); + /* * Create the io_buffer zone pool to keep things simpler in case of * multiple threads. Each thread works with its own so there is no @@ -126,6 +131,7 @@ p9fs_uninit(struct vfsconf *vfsp) uma_zdestroy(p9fs_io_buffer_zone); uma_zdestroy(p9fs_getattr_zone); uma_zdestroy(p9fs_setattr_zone); + uma_zdestroy(p9fs_pbuf_zone); return (0); } diff --git a/sys/fs/p9fs/p9fs_vnops.c b/sys/fs/p9fs/p9fs_vnops.c index 77162c0a4aff..5556e60f4bae 100644 --- a/sys/fs/p9fs/p9fs_vnops.c +++ b/sys/fs/p9fs/p9fs_vnops.c @@ -39,10 +39,14 @@ #include #include #include +#include +#include #include #include #include +#include +#include #include #include @@ -62,6 +66,7 @@ static MALLOC_DEFINE(M_P9UIOV, "uio", "UIOV structures for strategy in p9fs"); extern uma_zone_t p9fs_io_buffer_zone; extern uma_zone_t p9fs_getattr_zone; extern uma_zone_t p9fs_setattr_zone; +extern uma_zone_t p9fs_pbuf_zone; /* For the root vnode's vnops. */ struct vop_vector p9fs_vnops; @@ -2126,6 +2131,79 @@ out: return (error); } +/* + * Put VM pages, synchronously. + * XXX: like smbfs, cannot use vop_stdputpages due to mapping requirement + */ +static int +p9fs_putpages(struct vop_putpages_args *ap) +{ + struct uio uio; + struct iovec iov; + int i, error, npages, count; + off_t offset; + int *rtvals; + struct vnode *vp; + struct thread *td; + struct ucred *cred; + struct p9fs_node *np; + vm_page_t *pages; + vm_offset_t kva; + struct buf *bp; + + vp = ap->a_vp; + np = P9FS_VTON(vp); + td = curthread; + cred = curthread->td_ucred; + pages = ap->a_m; + count = ap->a_count; + rtvals = ap->a_rtvals; + npages = btoc(count); + offset = IDX_TO_OFF(pages[0]->pindex); + + /* + * When putting pages, do not extend file past EOF. + */ + if (offset + count > np->inode.i_size) { + count = np->inode.i_size - offset; + if (count < 0) + count = 0; + } + + for (i = 0; i < npages; i++) + rtvals[i] = VM_PAGER_ERROR; + + bp = uma_zalloc(p9fs_pbuf_zone, M_WAITOK); + kva = (vm_offset_t) bp->b_data; + pmap_qenter(kva, pages, npages); + + VM_CNT_INC(v_vnodeout); + VM_CNT_ADD(v_vnodepgsout, count); + + iov.iov_base = (caddr_t) kva; + iov.iov_len = count; + uio.uio_iov = &iov; + uio.uio_iovcnt = 1; + uio.uio_offset = offset; + uio.uio_resid = count; + uio.uio_segflg = UIO_SYSSPACE; + uio.uio_rw = UIO_WRITE; + uio.uio_td = td; + + P9_DEBUG(VOPS, "of=%jd,resid=%zd\n", (intmax_t)uio.uio_offset, uio.uio_resid); + + error = VOP_WRITE(vp, &uio, vnode_pager_putpages_ioflags(ap->a_sync), + cred); + + pmap_qremove(kva, npages); + uma_zfree(p9fs_pbuf_zone, bp); + + if (error == 0) + vnode_pager_undirty_pages(pages, rtvals, count - uio.uio_resid, + np->inode.i_size - offset, npages * PAGE_SIZE); + + return (rtvals[0]); +} struct vop_vector p9fs_vnops = { .vop_default = &default_vnodeops, @@ -2150,5 +2228,6 @@ struct vop_vector p9fs_vnops = { .vop_rename = p9fs_rename, .vop_link = p9fs_link, .vop_readlink = p9fs_readlink, + .vop_putpages = p9fs_putpages, }; VFS_VOP_VECTOR_REGISTER(p9fs_vnops);