diff --git a/sys/conf/files b/sys/conf/files index 98c3863521c..3b2c24aad08 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1,4 +1,4 @@ -# $OpenBSD: files,v 1.740 2024/09/14 11:06:48 jsg Exp $ +# $OpenBSD: files,v 1.741 2024/10/31 13:55:21 claudio Exp $ # $NetBSD: files,v 1.87 1996/05/19 17:17:50 jonathan Exp $ # @(#)files.newconf 7.5 (Berkeley) 5/10/93 @@ -610,6 +610,7 @@ file dev/kstat.c kstat needs-flag pseudo-device fuse file miscfs/fuse/fuse_device.c fuse needs-flag file miscfs/fuse/fuse_file.c fuse +file miscfs/fuse/fuse_ihash.c fuse file miscfs/fuse/fuse_lookup.c fuse file miscfs/fuse/fuse_vfsops.c fuse file miscfs/fuse/fuse_vnops.c fuse diff --git a/sys/miscfs/fuse/fuse_file.c b/sys/miscfs/fuse/fuse_file.c index b944b756315..c056cd9ecac 100644 --- a/sys/miscfs/fuse/fuse_file.c +++ b/sys/miscfs/fuse/fuse_file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fuse_file.c,v 1.9 2016/08/30 16:45:54 natano Exp $ */ +/* $OpenBSD: fuse_file.c,v 1.10 2024/10/31 13:55:21 claudio Exp $ */ /* * Copyright (c) 2012-2013 Sylvestre Gallon * @@ -35,7 +35,7 @@ fusefs_file_open(struct fusefs_mnt *fmp, struct fusefs_node *ip, if (!fmp->sess_init) return (0); - fbuf = fb_setup(0, ip->ufs_ino.i_number, + fbuf = fb_setup(0, ip->i_number, ((isdir) ? FBT_OPENDIR : FBT_OPEN), p); fbuf->fb_io_flags = flags; @@ -60,7 +60,7 @@ fusefs_file_close(struct fusefs_mnt *fmp, struct fusefs_node * ip, int error = 0; if (fmp->sess_init) { - fbuf = fb_setup(0, ip->ufs_ino.i_number, + fbuf = fb_setup(0, ip->i_number, ((isdir) ? FBT_RELEASEDIR : FBT_RELEASE), p); fbuf->fb_io_fd = ip->fufh[fufh_type].fh_id; fbuf->fb_io_flags = flags; diff --git a/sys/miscfs/fuse/fuse_ihash.c b/sys/miscfs/fuse/fuse_ihash.c new file mode 100644 index 00000000000..9a9ff776b33 --- /dev/null +++ b/sys/miscfs/fuse/fuse_ihash.c @@ -0,0 +1,152 @@ +/* $OpenBSD: fuse_ihash.c,v 1.1 2024/10/31 13:55:21 claudio Exp $ */ +/* $NetBSD: ufs_ihash.c,v 1.3 1996/02/09 22:36:04 christos Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1989, 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)ufs_ihash.c 8.4 (Berkeley) 12/30/93 + */ + +#include +#include +#include +#include +#include +#include + +#include "fusefs_node.h" + +#include + +/* + * Structures associated with inode caching. + */ +LIST_HEAD(fuse_ihashhead, fusefs_node) *fuse_ihashtbl; +u_long fuse_ihashsz; /* size of hash table - 1 */ +SIPHASH_KEY fuse_ihashkey; + +struct fuse_ihashhead *fuse_ihash(dev_t, ino_t); + +struct fuse_ihashhead * +fuse_ihash(dev_t dev, ino_t inum) +{ + SIPHASH_CTX ctx; + + SipHash24_Init(&ctx, &fuse_ihashkey); + SipHash24_Update(&ctx, &dev, sizeof(dev)); + SipHash24_Update(&ctx, &inum, sizeof(inum)); + + return (&fuse_ihashtbl[SipHash24_End(&ctx) & fuse_ihashsz]); +} + +/* + * Initialize inode hash table. + */ +void +fuse_ihashinit(void) +{ + fuse_ihashtbl = hashinit(initialvnodes, M_FUSEFS, M_WAITOK, + &fuse_ihashsz); + arc4random_buf(&fuse_ihashkey, sizeof(fuse_ihashkey)); +} + +/* + * Use the device/inum pair to find the incore inode, and return a pointer + * to it. If it is in core, but locked, wait for it. + */ +struct vnode * +fuse_ihashget(dev_t dev, ino_t inum) +{ + struct fuse_ihashhead *ipp; + struct fusefs_node *ip; + struct vnode *vp; +loop: + /* XXXLOCKING lock hash list */ + ipp = fuse_ihash(dev, inum); + LIST_FOREACH(ip, ipp, i_hash) { + if (inum == ip->i_number && dev == ip->i_dev) { + vp = ITOV(ip); + /* XXXLOCKING unlock hash list? */ + if (vget(vp, LK_EXCLUSIVE)) + goto loop; + + return (vp); + } + } + /* XXXLOCKING unlock hash list? */ + return (NULL); +} + +/* + * Insert the inode into the hash table, and return it locked. + */ +int +fuse_ihashins(struct fusefs_node *ip) +{ + struct fusefs_node *curip; + struct fuse_ihashhead *ipp; + dev_t dev = ip->i_dev; + ino_t inum = ip->i_number; + + /* lock the inode, then put it on the appropriate hash list */ + VOP_LOCK(ITOV(ip), LK_EXCLUSIVE); + + /* XXXLOCKING lock hash list */ + + ipp = fuse_ihash(dev, inum); + LIST_FOREACH(curip, ipp, i_hash) { + if (inum == curip->i_number && dev == curip->i_dev) { + /* XXXLOCKING unlock hash list? */ + VOP_UNLOCK(ITOV(ip)); + return (EEXIST); + } + } + + LIST_INSERT_HEAD(ipp, ip, i_hash); + /* XXXLOCKING unlock hash list? */ + + return (0); +} + +/* + * Remove the inode from the hash table. + */ +void +fuse_ihashrem(struct fusefs_node *ip) +{ + /* XXXLOCKING lock hash list */ + + if (ip->i_hash.le_prev == NULL) + return; + LIST_REMOVE(ip, i_hash); +#ifdef DIAGNOSTIC + ip->i_hash.le_next = NULL; + ip->i_hash.le_prev = NULL; +#endif + /* XXXLOCKING unlock hash list? */ +} diff --git a/sys/miscfs/fuse/fuse_lookup.c b/sys/miscfs/fuse/fuse_lookup.c index 7e19d2449ee..e44f7f366d2 100644 --- a/sys/miscfs/fuse/fuse_lookup.c +++ b/sys/miscfs/fuse/fuse_lookup.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fuse_lookup.c,v 1.21 2018/06/21 14:53:36 helg Exp $ */ +/* $OpenBSD: fuse_lookup.c,v 1.22 2024/10/31 13:55:21 claudio Exp $ */ /* * Copyright (c) 2012-2013 Sylvestre Gallon * @@ -55,7 +55,7 @@ fusefs_lookup(void *v) *vpp = NULL; vdp = ap->a_dvp; dp = VTOI(vdp); - fmp = (struct fusefs_mnt *)dp->ufs_ino.i_ump; + fmp = (struct fusefs_mnt *)dp->i_ump; lockparent = flags & LOCKPARENT; wantparent = flags & (LOCKPARENT | WANTPARENT); @@ -67,13 +67,13 @@ fusefs_lookup(void *v) return (EROFS); if (cnp->cn_namelen == 1 && *(cnp->cn_nameptr) == '.') { - nid = dp->ufs_ino.i_number; + nid = dp->i_number; } else { if (!fmp->sess_init) return (ENOENT); /* got a real entry */ - fbuf = fb_setup(cnp->cn_namelen + 1, dp->ufs_ino.i_number, + fbuf = fb_setup(cnp->cn_namelen + 1, dp->i_number, FBT_LOOKUP, p); memcpy(fbuf->fb_dat, cnp->cn_nameptr, cnp->cn_namelen); @@ -134,7 +134,7 @@ fusefs_lookup(void *v) if ((error = VOP_ACCESS(vdp, VWRITE, cred, cnp->cn_proc)) != 0) goto reclaim; - if (nid == dp->ufs_ino.i_number) + if (nid == dp->i_number) return (EISDIR); error = VFS_VGET(fmp->mp, nid, &tdp); @@ -172,7 +172,7 @@ fusefs_lookup(void *v) } *vpp = tdp; - } else if (nid == dp->ufs_ino.i_number) { + } else if (nid == dp->i_number) { vref(vdp); *vpp = vdp; error = 0; @@ -194,7 +194,7 @@ fusefs_lookup(void *v) return (error); reclaim: - if (nid != dp->ufs_ino.i_number && nid != FUSE_ROOTINO) { + if (nid != dp->i_number && nid != FUSE_ROOTINO) { fbuf = fb_setup(0, nid, FBT_RECLAIM, p); if (fb_queue(fmp->dev, fbuf)) printf("fusefs: libfuse vnode reclaim failed\n"); diff --git a/sys/miscfs/fuse/fuse_vfsops.c b/sys/miscfs/fuse/fuse_vfsops.c index 4a2a7a3110b..ee6b785c322 100644 --- a/sys/miscfs/fuse/fuse_vfsops.c +++ b/sys/miscfs/fuse/fuse_vfsops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fuse_vfsops.c,v 1.47 2024/05/20 09:11:21 mvs Exp $ */ +/* $OpenBSD: fuse_vfsops.c,v 1.48 2024/10/31 13:55:21 claudio Exp $ */ /* * Copyright (c) 2012-2013 Sylvestre Gallon * @@ -276,7 +276,7 @@ retry: /* * check if vnode is in hash. */ - if ((*vpp = ufs_ihashget(fmp->dev, ino)) != NULLVP) + if ((*vpp = fuse_ihashget(fmp->dev, ino)) != NULLVP) return (0); /* @@ -289,17 +289,17 @@ retry: } ip = malloc(sizeof(*ip), M_FUSEFS, M_WAITOK | M_ZERO); - rrw_init_flags(&ip->ufs_ino.i_lock, "fuseinode", + rrw_init_flags(&ip->i_lock, "fuseinode", RWL_DUPOK | RWL_IS_VNODE); nvp->v_data = ip; - ip->ufs_ino.i_vnode = nvp; - ip->ufs_ino.i_dev = fmp->dev; - ip->ufs_ino.i_number = ino; + ip->i_vnode = nvp; + ip->i_dev = fmp->dev; + ip->i_number = ino; for (i = 0; i < FUFH_MAXTYPE; i++) ip->fufh[i].fh_type = FUFH_INVALID; - error = ufs_ihashins(&ip->ufs_ino); + error = fuse_ihashins(ip); if (error) { vrele(nvp); @@ -309,7 +309,7 @@ retry: return (error); } - ip->ufs_ino.i_ump = (struct ufsmount *)fmp; + ip->i_ump = fmp; if (ino == FUSE_ROOTINO) nvp->v_flag |= VROOT; @@ -348,6 +348,7 @@ fusefs_init(struct vfsconf *vfc) { pool_init(&fusefs_fbuf_pool, sizeof(struct fusebuf), 0, 0, PR_WAITOK, "fmsg", NULL); + fuse_ihashinit(); return (0); } diff --git a/sys/miscfs/fuse/fuse_vnops.c b/sys/miscfs/fuse/fuse_vnops.c index 32cf168eba6..a7a521b0aec 100644 --- a/sys/miscfs/fuse/fuse_vnops.c +++ b/sys/miscfs/fuse/fuse_vnops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fuse_vnops.c,v 1.71 2024/10/18 05:52:32 miod Exp $ */ +/* $OpenBSD: fuse_vnops.c,v 1.72 2024/10/31 13:55:21 claudio Exp $ */ /* * Copyright (c) 2012-2013 Sylvestre Gallon * @@ -247,7 +247,7 @@ fusefs_open(void *v) ap = v; vp = ap->a_vp; ip = VTOI(vp); - fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump; + fmp = (struct fusefs_mnt *)ip->i_ump; if (!fmp->sess_init) return (ENXIO); @@ -298,7 +298,7 @@ fusefs_close(void *v) ap = v; ip = VTOI(ap->a_vp); - fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump; + fmp = (struct fusefs_mnt *)ip->i_ump; if (!fmp->sess_init) return (0); @@ -329,7 +329,7 @@ fusefs_close(void *v) if (ip->fufh[fufh_type].fh_type == FUFH_INVALID) return (EBADF); - fbuf = fb_setup(0, ip->ufs_ino.i_number, FBT_FLUSH, ap->a_p); + fbuf = fb_setup(0, ip->i_number, FBT_FLUSH, ap->a_p); fbuf->fb_io_fd = ip->fufh[fufh_type].fh_id; error = fb_queue(fmp->dev, fbuf); fb_delete(fbuf); @@ -358,7 +358,7 @@ fusefs_access(void *v) p = ap->a_p; cred = p->p_ucred; ip = VTOI(ap->a_vp); - fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump; + fmp = (struct fusefs_mnt *)ip->i_ump; /* * Only user that mounted the file system can access it unless @@ -409,7 +409,7 @@ fusefs_getattr(void *v) int error = 0; ip = VTOI(vp); - fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump; + fmp = (struct fusefs_mnt *)ip->i_ump; /* * Only user that mounted the file system can access it unless @@ -427,7 +427,7 @@ fusefs_getattr(void *v) vap->va_uid = fmp->mp->mnt_stat.f_owner; vap->va_gid = fmp->mp->mnt_stat.f_owner; vap->va_fsid = fmp->mp->mnt_stat.f_fsid.val[0]; - vap->va_fileid = ip->ufs_ino.i_number; + vap->va_fileid = ip->i_number; vap->va_size = S_BLKSIZE; vap->va_blocksize = S_BLKSIZE; vap->va_atime.tv_sec = fmp->mp->mnt_stat.f_ctime; @@ -441,7 +441,7 @@ fusefs_getattr(void *v) if (!fmp->sess_init) return (ENXIO); - fbuf = fb_setup(0, ip->ufs_ino.i_number, FBT_GETATTR, p); + fbuf = fb_setup(0, ip->i_number, FBT_GETATTR, p); error = fb_queue(fmp->dev, fbuf); if (error) { @@ -485,7 +485,7 @@ fusefs_setattr(void *v) struct fb_io *io; int error = 0; - fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump; + fmp = (struct fusefs_mnt *)ip->i_ump; /* * Check for unsettable attributes. */ @@ -501,7 +501,7 @@ fusefs_setattr(void *v) if (fmp->undef_op & UNDEF_SETATTR) return (ENOSYS); - fbuf = fb_setup(sizeof(*io), ip->ufs_ino.i_number, FBT_SETATTR, p); + fbuf = fb_setup(sizeof(*io), ip->i_number, FBT_SETATTR, p); io = fbtod(fbuf, struct fb_io *); io->fi_flags = 0; @@ -634,7 +634,7 @@ fusefs_link(void *v) ip = VTOI(vp); dip = VTOI(dvp); - fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump; + fmp = (struct fusefs_mnt *)ip->i_ump; if (!fmp->sess_init) { VOP_ABORTOP(dvp, cnp); @@ -651,10 +651,10 @@ fusefs_link(void *v) goto out2; } - fbuf = fb_setup(cnp->cn_namelen + 1, dip->ufs_ino.i_number, + fbuf = fb_setup(cnp->cn_namelen + 1, dip->i_number, FBT_LINK, p); - fbuf->fb_io_ino = ip->ufs_ino.i_number; + fbuf->fb_io_ino = ip->i_number; memcpy(fbuf->fb_dat, cnp->cn_nameptr, cnp->cn_namelen); fbuf->fb_dat[cnp->cn_namelen] = '\0'; @@ -698,7 +698,7 @@ fusefs_symlink(void *v) int len; dp = VTOI(dvp); - fmp = (struct fusefs_mnt *)dp->ufs_ino.i_ump; + fmp = (struct fusefs_mnt *)dp->i_ump; if (!fmp->sess_init) { error = ENXIO; @@ -712,7 +712,7 @@ fusefs_symlink(void *v) len = strlen(target) + 1; - fbuf = fb_setup(len + cnp->cn_namelen + 1, dp->ufs_ino.i_number, + fbuf = fb_setup(len + cnp->cn_namelen + 1, dp->i_number, FBT_SYMLINK, p); memcpy(fbuf->fb_dat, cnp->cn_nameptr, cnp->cn_namelen); @@ -764,7 +764,7 @@ fusefs_readdir(void *v) p = uio->uio_procp; ip = VTOI(vp); - fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump; + fmp = (struct fusefs_mnt *)ip->i_ump; if (!fmp->sess_init) return (ENXIO); @@ -781,7 +781,7 @@ fusefs_readdir(void *v) } while (uio->uio_resid > 0) { - fbuf = fb_setup(0, ip->ufs_ino.i_number, FBT_READDIR, p); + fbuf = fb_setup(0, ip->i_number, FBT_READDIR, p); fbuf->fb_io_fd = ip->fufh[FUFH_RDONLY].fh_id; fbuf->fb_io_off = uio->uio_offset; @@ -865,7 +865,7 @@ fusefs_inactive(void *v) struct fusefs_mnt *fmp; int type, flags; - fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump; + fmp = (struct fusefs_mnt *)ip->i_ump; /* Close all open file handles. */ for (type = 0; type < FUFH_MAXTYPE; type++) { @@ -912,7 +912,7 @@ fusefs_readlink(void *v) int error = 0; ip = VTOI(vp); - fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump; + fmp = (struct fusefs_mnt *)ip->i_ump; uio = ap->a_uio; p = uio->uio_procp; @@ -922,7 +922,7 @@ fusefs_readlink(void *v) if (fmp->undef_op & UNDEF_READLINK) return (ENOSYS); - fbuf = fb_setup(0, ip->ufs_ino.i_number, FBT_READLINK, p); + fbuf = fb_setup(0, ip->i_number, FBT_READLINK, p); error = fb_queue(fmp->dev, fbuf); @@ -952,7 +952,7 @@ fusefs_reclaim(void *v) struct fusebuf *fbuf; int type, error = 0; - fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump; + fmp = (struct fusefs_mnt *)ip->i_ump; /* Close opened files. */ for (type = 0; type < FUFH_MAXTYPE; type++) { @@ -967,8 +967,8 @@ fusefs_reclaim(void *v) /* * If the fuse connection is opened ask libfuse to free the vnodes. */ - if (fmp->sess_init && ip->ufs_ino.i_number != FUSE_ROOTINO) { - fbuf = fb_setup(0, ip->ufs_ino.i_number, FBT_RECLAIM, p); + if (fmp->sess_init && ip->i_number != FUSE_ROOTINO) { + fbuf = fb_setup(0, ip->i_number, FBT_RECLAIM, p); error = fb_queue(fmp->dev, fbuf); if (error) printf("fusefs: vnode reclaim failed: %d\n", error); @@ -978,7 +978,7 @@ fusefs_reclaim(void *v) /* * Remove the inode from its hash chain. */ - ufs_ihashrem(&ip->ufs_ino); + fuse_ihashrem(ip); free(ip, M_FUSEFS, sizeof(*ip)); vp->v_data = NULL; @@ -996,7 +996,7 @@ fusefs_print(void *v) struct fusefs_node *ip = VTOI(vp); /* Complete the information given by vprint(). */ - printf("tag VT_FUSE, hash id %u ", ip->ufs_ino.i_number); + printf("tag VT_FUSE, hash id %llu ", ip->i_number); printf("\n"); #endif return (0); @@ -1019,7 +1019,7 @@ fusefs_create(void *v) mode_t mode; ip = VTOI(dvp); - fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump; + fmp = (struct fusefs_mnt *)ip->i_ump; mode = MAKEIMODE(vap->va_type, vap->va_mode); if (!fmp->sess_init) { @@ -1032,7 +1032,7 @@ fusefs_create(void *v) return (ENOSYS); } - fbuf = fb_setup(cnp->cn_namelen + 1, ip->ufs_ino.i_number, + fbuf = fb_setup(cnp->cn_namelen + 1, ip->i_number, FBT_MKNOD, p); fbuf->fb_io_mode = mode; @@ -1077,7 +1077,7 @@ fusefs_mknod(void *v) int error = 0; ip = VTOI(dvp); - fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump; + fmp = (struct fusefs_mnt *)ip->i_ump; if (!fmp->sess_init) { VOP_ABORTOP(dvp, cnp); @@ -1089,7 +1089,7 @@ fusefs_mknod(void *v) return (ENOSYS); } - fbuf = fb_setup(cnp->cn_namelen + 1, ip->ufs_ino.i_number, + fbuf = fb_setup(cnp->cn_namelen + 1, ip->i_number, FBT_MKNOD, p); fbuf->fb_io_mode = MAKEIMODE(vap->va_type, vap->va_mode); @@ -1143,7 +1143,7 @@ fusefs_read(void *v) int error=0; ip = VTOI(vp); - fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump; + fmp = (struct fusefs_mnt *)ip->i_ump; if (!fmp->sess_init) return (ENXIO); @@ -1153,7 +1153,7 @@ fusefs_read(void *v) return (EINVAL); while (uio->uio_resid > 0) { - fbuf = fb_setup(0, ip->ufs_ino.i_number, FBT_READ, p); + fbuf = fb_setup(0, ip->i_number, FBT_READ, p); size = MIN(uio->uio_resid, fmp->max_read); fbuf->fb_io_fd = fusefs_fd_get(ip, FUFH_RDONLY); @@ -1197,7 +1197,7 @@ fusefs_write(void *v) int error=0; ip = VTOI(vp); - fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump; + fmp = (struct fusefs_mnt *)ip->i_ump; if (!fmp->sess_init) return (ENXIO); @@ -1213,7 +1213,7 @@ fusefs_write(void *v) while (uio->uio_resid > 0) { len = MIN(uio->uio_resid, fmp->max_read); - fbuf = fb_setup(len, ip->ufs_ino.i_number, FBT_WRITE, p); + fbuf = fb_setup(len, ip->i_number, FBT_WRITE, p); fbuf->fb_io_fd = fusefs_fd_get(ip, FUFH_WRONLY); fbuf->fb_io_off = uio->uio_offset; @@ -1305,7 +1305,7 @@ abortit: goto abortit; dp = VTOI(fdvp); ip = VTOI(fvp); - fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump; + fmp = (struct fusefs_mnt *)ip->i_ump; /* * Be sure we are not renaming ".", "..", or an alias of ".". This @@ -1341,14 +1341,14 @@ abortit: } fbuf = fb_setup(fcnp->cn_namelen + tcnp->cn_namelen + 2, - dp->ufs_ino.i_number, FBT_RENAME, p); + dp->i_number, FBT_RENAME, p); memcpy(fbuf->fb_dat, fcnp->cn_nameptr, fcnp->cn_namelen); fbuf->fb_dat[fcnp->cn_namelen] = '\0'; memcpy(fbuf->fb_dat + fcnp->cn_namelen + 1, tcnp->cn_nameptr, tcnp->cn_namelen); fbuf->fb_dat[fcnp->cn_namelen + tcnp->cn_namelen + 1] = '\0'; - fbuf->fb_io_ino = VTOI(tdvp)->ufs_ino.i_number; + fbuf->fb_io_ino = VTOI(tdvp)->i_number; error = fb_queue(fmp->dev, fbuf); @@ -1394,7 +1394,7 @@ fusefs_mkdir(void *v) int error = 0; ip = VTOI(dvp); - fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump; + fmp = (struct fusefs_mnt *)ip->i_ump; if (!fmp->sess_init) { @@ -1407,7 +1407,7 @@ fusefs_mkdir(void *v) goto out; } - fbuf = fb_setup(cnp->cn_namelen + 1, ip->ufs_ino.i_number, + fbuf = fb_setup(cnp->cn_namelen + 1, ip->i_number, FBT_MKDIR, p); fbuf->fb_io_mode = MAKEIMODE(vap->va_type, vap->va_mode); @@ -1454,7 +1454,7 @@ fusefs_rmdir(void *v) ip = VTOI(vp); dp = VTOI(dvp); - fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump; + fmp = (struct fusefs_mnt *)ip->i_ump; if (!fmp->sess_init) { error = ENXIO; @@ -1468,7 +1468,7 @@ fusefs_rmdir(void *v) VN_KNOTE(dvp, NOTE_WRITE | NOTE_LINK); - fbuf = fb_setup(cnp->cn_namelen + 1, dp->ufs_ino.i_number, + fbuf = fb_setup(cnp->cn_namelen + 1, dp->i_number, FBT_RMDIR, p); memcpy(fbuf->fb_dat, cnp->cn_nameptr, cnp->cn_namelen); fbuf->fb_dat[cnp->cn_namelen] = '\0'; @@ -1514,7 +1514,7 @@ fusefs_remove(void *v) ip = VTOI(vp); dp = VTOI(dvp); - fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump; + fmp = (struct fusefs_mnt *)ip->i_ump; if (!fmp->sess_init) { error = ENXIO; @@ -1526,7 +1526,7 @@ fusefs_remove(void *v) goto out; } - fbuf = fb_setup(cnp->cn_namelen + 1, dp->ufs_ino.i_number, + fbuf = fb_setup(cnp->cn_namelen + 1, dp->i_number, FBT_UNLINK, p); memcpy(fbuf->fb_dat, cnp->cn_nameptr, cnp->cn_namelen); fbuf->fb_dat[cnp->cn_namelen] = '\0'; @@ -1560,7 +1560,7 @@ fusefs_lock(void *v) struct vop_lock_args *ap = v; struct vnode *vp = ap->a_vp; - return rrw_enter(&VTOI(vp)->ufs_ino.i_lock, ap->a_flags & LK_RWFLAGS); + return rrw_enter(&VTOI(vp)->i_lock, ap->a_flags & LK_RWFLAGS); } int @@ -1569,7 +1569,7 @@ fusefs_unlock(void *v) struct vop_unlock_args *ap = v; struct vnode *vp = ap->a_vp; - rrw_exit(&VTOI(vp)->ufs_ino.i_lock); + rrw_exit(&VTOI(vp)->i_lock); return 0; } @@ -1578,7 +1578,7 @@ fusefs_islocked(void *v) { struct vop_islocked_args *ap = v; - return rrw_status(&VTOI(ap->a_vp)->ufs_ino.i_lock); + return rrw_status(&VTOI(ap->a_vp)->i_lock); } int @@ -1587,7 +1587,7 @@ fusefs_advlock(void *v) struct vop_advlock_args *ap = v; struct fusefs_node *ip = VTOI(ap->a_vp); - return (lf_advlock(&ip->ufs_ino.i_lockf, ip->filesize, ap->a_id, + return (lf_advlock(&ip->i_lockf, ip->filesize, ap->a_id, ap->a_op, ap->a_fl, ap->a_flags)); } @@ -1611,7 +1611,7 @@ fusefs_fsync(void *v) return (0); ip = VTOI(vp); - fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump; + fmp = (struct fusefs_mnt *)ip->i_ump; if (!fmp->sess_init) return (ENXIO); @@ -1626,7 +1626,7 @@ fusefs_fsync(void *v) if (fufh->fh_type == FUFH_WRONLY || fufh->fh_type == FUFH_RDWR) { - fbuf = fb_setup(0, ip->ufs_ino.i_number, FBT_FSYNC, p); + fbuf = fb_setup(0, ip->i_number, FBT_FSYNC, p); fbuf->fb_io_fd = fufh->fh_id; /* Always behave as if ap->a_waitfor = MNT_WAIT. */ diff --git a/sys/miscfs/fuse/fusefs_node.h b/sys/miscfs/fuse/fusefs_node.h index 3436c84ae31..ed0bda66d3c 100644 --- a/sys/miscfs/fuse/fusefs_node.h +++ b/sys/miscfs/fuse/fusefs_node.h @@ -1,4 +1,4 @@ -/* $OpenBSD: fusefs_node.h,v 1.4 2016/09/07 17:53:35 natano Exp $ */ +/* $OpenBSD: fusefs_node.h,v 1.5 2024/10/31 13:55:21 claudio Exp $ */ /* * Copyright (c) 2012-2013 Sylvestre Gallon * @@ -18,9 +18,7 @@ #ifndef _FUSEFS_NODE_H_ #define _FUSEFS_NODE_H_ -#include -#include -#include +#include enum fufh_type { FUFH_INVALID = -1, @@ -35,26 +33,38 @@ struct fusefs_filehandle { enum fufh_type fh_type; }; +struct fusefs_mnt; struct fusefs_node { - struct inode ufs_ino; + LIST_ENTRY(fusefs_node) i_hash; /* Hash chain */ + struct vnode *i_vnode;/* Vnode associated with this inode. */ + struct fusefs_mnt *i_ump; + dev_t i_dev; /* Device associated with the inode. */ + ino_t i_number; /* The identity of the inode. */ + struct lockf_state *i_lockf; /* Byte-level lock state. */ + struct rrwlock i_lock; /* Inode lock */ /** I/O **/ struct fusefs_filehandle fufh[FUFH_MAXTYPE]; /** meta **/ - off_t filesize; + off_t filesize; }; #ifdef ITOV # undef ITOV #endif -#define ITOV(ip) ((ip)->ufs_ino.i_vnode) +#define ITOV(ip) ((ip)->i_vnode) #ifdef VTOI # undef VTOI #endif #define VTOI(vp) ((struct fusefs_node *)(vp)->v_data) +void fuse_ihashinit(void); +struct vnode *fuse_ihashget(dev_t, ino_t); +int fuse_ihashins(struct fusefs_node *); +void fuse_ihashrem(struct fusefs_node *); + uint64_t fusefs_fd_get(struct fusefs_node *, enum fufh_type); #endif /* _FUSEFS_NODE_H_ */