From: natano Date: Tue, 30 Aug 2016 16:45:54 +0000 (+0000) Subject: Use struct stat for storing attributes in fusebufs, because using struct X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=6f9b594291a08bb8ef9193202bf248be575aca61;p=openbsd Use struct stat for storing attributes in fusebufs, because using struct vattr in userspace is suboptimal as some related helpers are not available, e.g. VATTR_NULL() and IFTOVT(). The conversion is now done in the kernel where it belongs. As a side effect the include can be removed from libfuse. tweaks and ok guenther --- diff --git a/lib/libfuse/fuse_ops.c b/lib/libfuse/fuse_ops.c index ed79977f6d0..ebbadfd1417 100644 --- a/lib/libfuse/fuse_ops.c +++ b/lib/libfuse/fuse_ops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fuse_ops.c,v 1.24 2014/02/05 20:13:58 syl Exp $ */ +/* $OpenBSD: fuse_ops.c,v 1.25 2016/08/30 16:45:54 natano Exp $ */ /* * Copyright (c) 2013 Sylvestre Gallon * @@ -30,53 +30,30 @@ return (0); \ } -static void -stat2attr(struct vattr *v, struct stat *st) -{ - v->va_fileid = st->st_ino; - v->va_bytes = st->st_blocks; - v->va_mode = st->st_mode; - v->va_nlink = st->st_nlink; - v->va_uid = st->st_uid; - v->va_gid = st->st_gid; - v->va_rdev = st->st_rdev; - v->va_size = st->st_size; - v->va_blocksize = st->st_blksize; - v->va_atime.tv_sec = st->st_atime; - v->va_atime.tv_nsec = st->st_atimensec; - v->va_mtime.tv_sec = st->st_mtime; - v->va_mtime.tv_nsec = st->st_mtimensec; - v->va_ctime.tv_sec = st->st_ctime; - v->va_ctime.tv_nsec = st->st_ctimensec; -} - static int -update_vattr(struct fuse *f, struct vattr *attr, const char *realname, +update_attr(struct fuse *f, struct stat *attr, const char *realname, struct fuse_vnode *vn) { - struct stat st; int ret; - bzero(&st, sizeof(st)); - ret = f->op.getattr(realname, &st); + memset(attr, 0, sizeof(struct stat)); + ret = f->op.getattr(realname, attr); - if (st.st_blksize == 0) - st.st_blksize = 512; - if (st.st_blocks == 0) - st.st_blocks = 4; + if (attr->st_blksize == 0) + attr->st_blksize = 512; + if (attr->st_blocks == 0) + attr->st_blocks = 4; - st.st_ino = vn->ino; + attr->st_ino = vn->ino; if (f->conf.set_mode) - st.st_mode = (st.st_mode & S_IFMT) | (0777 & ~f->conf.umask); + attr->st_mode = (attr->st_mode & S_IFMT) | (0777 & ~f->conf.umask); if (f->conf.set_uid) - st.st_uid = f->conf.uid; + attr->st_uid = f->conf.uid; if (f->conf.set_gid) - st.st_gid = f->conf.gid; - - stat2attr(attr, &st); + attr->st_gid = f->conf.gid; return (ret); } @@ -107,7 +84,7 @@ ifuse_ops_getattr(struct fuse *f, struct fusebuf *fbuf) DPRINTF("Opcode:\tgetattr\n"); DPRINTF("Inode:\t%llu\n", (unsigned long long)fbuf->fb_ino); - bzero(&fbuf->fb_vattr, sizeof(fbuf->fb_vattr)); + memset(&fbuf->fb_attr, 0, sizeof(struct stat)); vn = tree_get(&f->vnode_tree, fbuf->fb_ino); if (vn == NULL) { @@ -121,7 +98,7 @@ ifuse_ops_getattr(struct fuse *f, struct fusebuf *fbuf) return (0); } - fbuf->fb_err = update_vattr(f, &fbuf->fb_vattr, realname, vn); + fbuf->fb_err = update_attr(f, &fbuf->fb_attr, realname, vn); free(realname); return (0); @@ -474,7 +451,7 @@ ifuse_ops_lookup(struct fuse *f, struct fusebuf *fbuf) return (0); } - fbuf->fb_err = update_vattr(f, &fbuf->fb_vattr, realname, vn); + fbuf->fb_err = update_attr(f, &fbuf->fb_attr, realname, vn); free(fbuf->fb_dat); free(realname); @@ -614,9 +591,9 @@ ifuse_ops_create(struct fuse *f, struct fusebuf *fbuf) fbuf->fb_err = -ENOSYS; if (!fbuf->fb_err) { - fbuf->fb_err = update_vattr(f, &fbuf->fb_vattr, realname, vn); - fbuf->fb_ino = fbuf->fb_vattr.va_fileid; - fbuf->fb_io_mode = fbuf->fb_vattr.va_mode; + fbuf->fb_err = update_attr(f, &fbuf->fb_attr, realname, vn); + fbuf->fb_ino = fbuf->fb_attr.st_ino; + fbuf->fb_io_mode = fbuf->fb_attr.st_mode; } free(realname); @@ -650,8 +627,8 @@ ifuse_ops_mkdir(struct fuse *f, struct fusebuf *fbuf) fbuf->fb_err = f->op.mkdir(realname, mode); if (!fbuf->fb_err) { - fbuf->fb_err = update_vattr(f, &fbuf->fb_vattr, realname, vn); - fbuf->fb_io_mode = fbuf->fb_vattr.va_mode; + fbuf->fb_err = update_attr(f, &fbuf->fb_attr, realname, vn); + fbuf->fb_io_mode = fbuf->fb_attr.st_mode; fbuf->fb_ino = vn->ino; } free(realname); @@ -857,7 +834,7 @@ ifuse_ops_setattr(struct fuse *f, struct fusebuf *fbuf) if (io->fi_flags & FUSE_FATTR_MODE) { if (f->op.chmod) fbuf->fb_err = f->op.chmod(realname, - fbuf->fb_vattr.va_mode); + fbuf->fb_attr.st_mode); else fbuf->fb_err = -ENOSYS; } @@ -865,9 +842,9 @@ ifuse_ops_setattr(struct fuse *f, struct fusebuf *fbuf) if (!fbuf->fb_err && (io->fi_flags & FUSE_FATTR_UID || io->fi_flags & FUSE_FATTR_GID) ) { uid = (io->fi_flags & FUSE_FATTR_UID) ? - fbuf->fb_vattr.va_uid : (gid_t)-1; + fbuf->fb_attr.st_uid : (gid_t)-1; gid = (io->fi_flags & FUSE_FATTR_GID) ? - fbuf->fb_vattr.va_gid : (uid_t)-1; + fbuf->fb_attr.st_gid : (uid_t)-1; if (f->op.chown) fbuf->fb_err = f->op.chown(realname, uid, gid); else @@ -876,10 +853,8 @@ ifuse_ops_setattr(struct fuse *f, struct fusebuf *fbuf) if (!fbuf->fb_err && ( io->fi_flags & FUSE_FATTR_MTIME || io->fi_flags & FUSE_FATTR_ATIME)) { - ts[0].tv_sec = fbuf->fb_vattr.va_atime.tv_sec; - ts[0].tv_nsec = fbuf->fb_vattr.va_atime.tv_nsec; - ts[1].tv_sec = fbuf->fb_vattr.va_mtime.tv_sec; - ts[1].tv_nsec = fbuf->fb_vattr.va_mtime.tv_nsec; + ts[0] = fbuf->fb_attr.st_atim; + ts[1] = fbuf->fb_attr.st_mtim; tbuf.actime = ts[0].tv_sec; tbuf.modtime = ts[1].tv_sec; @@ -894,15 +869,15 @@ ifuse_ops_setattr(struct fuse *f, struct fusebuf *fbuf) if (!fbuf->fb_err && (io->fi_flags & FUSE_FATTR_SIZE)) { if (f->op.truncate) fbuf->fb_err = f->op.truncate(realname, - fbuf->fb_vattr.va_size); + fbuf->fb_attr.st_size); else fbuf->fb_err = -ENOSYS; } - bzero(&fbuf->fb_vattr, sizeof(fbuf->fb_vattr)); + memset(&fbuf->fb_attr, 0, sizeof(struct stat)); if (!fbuf->fb_err) - fbuf->fb_err = update_vattr(f, &fbuf->fb_vattr, realname, vn); + fbuf->fb_err = update_attr(f, &fbuf->fb_attr, realname, vn); free(realname); free(fbuf->fb_dat); @@ -1054,9 +1029,9 @@ ifuse_ops_mknod(struct fuse *f, struct fusebuf *fbuf) fbuf->fb_err = f->op.mknod(realname, mode, dev); if (!fbuf->fb_err) { - fbuf->fb_err = update_vattr(f, &fbuf->fb_vattr, realname, vn); - fbuf->fb_io_mode = fbuf->fb_vattr.va_mode; - fbuf->fb_ino = fbuf->fb_vattr.va_fileid; + fbuf->fb_err = update_attr(f, &fbuf->fb_attr, realname, vn); + fbuf->fb_io_mode = fbuf->fb_attr.st_mode; + fbuf->fb_ino = fbuf->fb_attr.st_ino; } free(realname); diff --git a/lib/libfuse/fuse_private.h b/lib/libfuse/fuse_private.h index 957796dc83f..2fe2d23bc86 100644 --- a/lib/libfuse/fuse_private.h +++ b/lib/libfuse/fuse_private.h @@ -1,4 +1,4 @@ -/* $OpenBSD: fuse_private.h,v 1.12 2016/08/27 01:57:27 guenther Exp $ */ +/* $OpenBSD: fuse_private.h,v 1.13 2016/08/30 16:45:54 natano Exp $ */ /* * Copyright (c) 2013 Sylvestre Gallon * @@ -19,10 +19,11 @@ #define _FUSE_SUBR_H_ #include +#include #include +#include #include -#include -#include +#include #include #include diff --git a/share/man/man9/fb_setup.9 b/share/man/man9/fb_setup.9 index d72fc1664bc..d39f3340fad 100644 --- a/share/man/man9/fb_setup.9 +++ b/share/man/man9/fb_setup.9 @@ -1,4 +1,4 @@ -.\" $OpenBSD: fb_setup.9,v 1.5 2016/05/16 20:12:20 jmc Exp $ +.\" $OpenBSD: fb_setup.9,v 1.6 2016/08/30 16:45:54 natano Exp $ .\" .\" Copyright (c) 2013 Sylvestre Gallon .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: May 16 2016 $ +.Dd $Mdocdate: August 30 2016 $ .Dt FB_SETUP 9 .Os .Sh NAME @@ -56,11 +56,11 @@ struct fusebuf { struct fb_hdr fb_hdr; union { struct statvfs FD_stat; - struct vattr FD_vattr; + struct stat FD_attr; struct fb_io FD_io; } FD; - uint8_t *F_databuf; + uint8_t *fb_dat; }; #define fb_next fb_hdr.fh_next @@ -71,14 +71,13 @@ struct fusebuf { #define fb_uuid fb_hdr.fh_uuid #define fb_stat FD.FD_stat -#define fb_vattr FD.FD_vattr +#define fb_attr FD.FD_attr #define fb_io_fd FD.FD_io.fi_fd #define fb_io_ino FD.FD_io.fi_ino #define fb_io_off FD.FD_io.fi_off #define fb_io_len FD.FD_io.fi_len #define fb_io_mode FD.FD_io.fi_mode #define fb_io_flags FD.FD_io.fi_flags -#define fb_dat F_databuf .Ed .Sh DESCRIPTION These functions provide a way to manage the kernel messaging mechanism for @@ -206,7 +205,7 @@ The union contains the following elements: A struct .Xr statvfs 3 filled in by the FUSE client statfs for the FUSE VFS statfs code. -.It Fa FD_vattr +.It Fa FD_attr Used by the getattr and setattr calls. .It Fa FD_io Contains all fields commonly used by FUSE client callbacks to @@ -215,7 +214,7 @@ It is used by access, readdir, release, releasedir, read, write, create, mkdir, and setattr. .El .Pp -Setattr uses a struct fb_io and a struct vattr. +Setattr uses a struct fb_io and a struct stat. Settattr uses .Fa FD_stat and encapsulates a struct fb_io in diff --git a/sys/miscfs/fuse/fuse_device.c b/sys/miscfs/fuse/fuse_device.c index 520736a6a0e..0bdd0b27d60 100644 --- a/sys/miscfs/fuse/fuse_device.c +++ b/sys/miscfs/fuse/fuse_device.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fuse_device.c,v 1.20 2016/01/22 17:09:43 stefan Exp $ */ +/* $OpenBSD: fuse_device.c,v 1.21 2016/08/30 16:45:54 natano Exp $ */ /* * Copyright (c) 2012-2013 Sylvestre Gallon * @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include diff --git a/sys/miscfs/fuse/fuse_file.c b/sys/miscfs/fuse/fuse_file.c index bbba4e34ca9..b944b756315 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.8 2014/03/18 08:51:53 mpi Exp $ */ +/* $OpenBSD: fuse_file.c,v 1.9 2016/08/30 16:45:54 natano Exp $ */ /* * Copyright (c) 2012-2013 Sylvestre Gallon * @@ -17,6 +17,7 @@ #include #include +#include #include #include #include diff --git a/sys/miscfs/fuse/fuse_lookup.c b/sys/miscfs/fuse/fuse_lookup.c index a0d2fc49aa6..d781065d5b3 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.14 2016/08/21 09:23:33 natano Exp $ */ +/* $OpenBSD: fuse_lookup.c,v 1.15 2016/08/30 16:45:54 natano Exp $ */ /* * Copyright (c) 2012-2013 Sylvestre Gallon * @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -109,7 +110,7 @@ fusefs_lookup(void *v) goto out; } - nid = fbuf->fb_vattr.va_fileid; + nid = fbuf->fb_attr.st_ino; } if (nameiop == DELETE && (flags & ISLASTCN)) { @@ -139,7 +140,7 @@ fusefs_lookup(void *v) if (error) goto out; - tdp->v_type = IFTOVT(fbuf->fb_vattr.va_mode); + tdp->v_type = IFTOVT(fbuf->fb_attr.st_mode); *vpp = tdp; cnp->cn_flags |= SAVENAME; @@ -177,7 +178,7 @@ fusefs_lookup(void *v) if (error) goto out; - tdp->v_type = IFTOVT(fbuf->fb_vattr.va_mode); + tdp->v_type = IFTOVT(fbuf->fb_attr.st_mode); if (vdp != NULL && vdp->v_type == VDIR) VTOI(tdp)->parent = dp->ufs_ino.i_number; diff --git a/sys/miscfs/fuse/fuse_vfsops.c b/sys/miscfs/fuse/fuse_vfsops.c index 9780f0760f1..81796bdb80b 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.26 2016/08/15 07:39:46 natano Exp $ */ +/* $OpenBSD: fuse_vfsops.c,v 1.27 2016/08/30 16:45:54 natano Exp $ */ /* * Copyright (c) 2012-2013 Sylvestre Gallon * @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include diff --git a/sys/miscfs/fuse/fuse_vnops.c b/sys/miscfs/fuse/fuse_vnops.c index 496729bb9a9..fc1bc844d6c 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.31 2016/08/21 09:23:33 natano Exp $ */ +/* $OpenBSD: fuse_vnops.c,v 1.32 2016/08/30 16:45:54 natano Exp $ */ /* * Copyright (c) 2012-2013 Sylvestre Gallon * @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -372,6 +373,7 @@ fusefs_getattr(void *v) struct proc *p = ap->a_p; struct fusefs_node *ip; struct fusebuf *fbuf; + struct stat *st; int error = 0; ip = VTOI(vp); @@ -388,12 +390,23 @@ fusefs_getattr(void *v) return (error); } - memcpy(vap, &fbuf->fb_vattr, sizeof(*vap)); + VATTR_NULL(vap); + st = &fbuf->fb_attr; + vap->va_type = IFTOVT(st->st_mode); + vap->va_mode = st->st_mode & ~S_IFMT; + vap->va_nlink = st->st_nlink; + vap->va_uid = st->st_uid; + vap->va_gid = st->st_gid; vap->va_fsid = fmp->mp->mnt_stat.f_fsid.val[0]; - vap->va_type = IFTOVT(vap->va_mode); - vap->va_bytes *= S_BLKSIZE; - vap->va_mode &= ~S_IFMT; + vap->va_fileid = st->st_ino; + vap->va_size = st->st_size; + vap->va_blocksize = st->st_blksize; + vap->va_atime = st->st_atim; + vap->va_mtime = st->st_mtim; + vap->va_ctime = st->st_ctim; + vap->va_rdev = st->st_rdev; + vap->va_bytes = st->st_blocks * S_BLKSIZE; fb_delete(fbuf); return (error); @@ -437,7 +450,7 @@ fusefs_setattr(void *v) error = EROFS; goto out; } - fbuf->fb_vattr.va_uid = vap->va_uid; + fbuf->fb_attr.st_uid = vap->va_uid; io->fi_flags |= FUSE_FATTR_UID; } @@ -446,7 +459,7 @@ fusefs_setattr(void *v) error = EROFS; goto out; } - fbuf->fb_vattr.va_gid = vap->va_gid; + fbuf->fb_attr.st_gid = vap->va_gid; io->fi_flags |= FUSE_FATTR_GID; } @@ -466,7 +479,7 @@ fusefs_setattr(void *v) break; } - fbuf->fb_vattr.va_size = vap->va_size; + fbuf->fb_attr.st_size = vap->va_size; io->fi_flags |= FUSE_FATTR_SIZE; } @@ -475,8 +488,7 @@ fusefs_setattr(void *v) error = EROFS; goto out; } - fbuf->fb_vattr.va_atime.tv_sec = vap->va_atime.tv_sec; - fbuf->fb_vattr.va_atime.tv_nsec = vap->va_atime.tv_nsec; + fbuf->fb_attr.st_atim = vap->va_atime; io->fi_flags |= FUSE_FATTR_ATIME; } @@ -485,8 +497,7 @@ fusefs_setattr(void *v) error = EROFS; goto out; } - fbuf->fb_vattr.va_mtime.tv_sec = vap->va_mtime.tv_sec; - fbuf->fb_vattr.va_mtime.tv_nsec = vap->va_mtime.tv_nsec; + fbuf->fb_attr.st_mtim = vap->va_mtime; io->fi_flags |= FUSE_FATTR_MTIME; } /* XXX should set a flag if (vap->va_vaflags & VA_UTIMES_CHANGE) */ @@ -496,7 +507,7 @@ fusefs_setattr(void *v) error = EROFS; goto out; } - fbuf->fb_vattr.va_mode = vap->va_mode & ALLPERMS; + fbuf->fb_attr.st_mode = vap->va_mode & ALLPERMS; io->fi_flags |= FUSE_FATTR_MODE; } @@ -504,11 +515,6 @@ fusefs_setattr(void *v) goto out; } - if (io->fi_flags & FUSE_FATTR_SIZE && vp->v_type == VDIR) { - error = EISDIR; - goto out; - } - error = fb_queue(fmp->dev, fbuf); if (error) { if (error == ENOSYS) diff --git a/sys/miscfs/fuse/fusebuf.c b/sys/miscfs/fuse/fusebuf.c index 73eb17a0094..44add882aff 100644 --- a/sys/miscfs/fuse/fusebuf.c +++ b/sys/miscfs/fuse/fusebuf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fusebuf.c,v 1.11 2015/03/14 03:38:51 jsg Exp $ */ +/* $OpenBSD: fusebuf.c,v 1.12 2016/08/30 16:45:54 natano Exp $ */ /* * Copyright (c) 2012-2013 Sylvestre Gallon * @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include diff --git a/sys/sys/fusebuf.h b/sys/sys/fusebuf.h index fb23973b7e6..83f0e83bb80 100644 --- a/sys/sys/fusebuf.h +++ b/sys/sys/fusebuf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: fusebuf.h,v 1.10 2016/08/13 11:42:46 natano Exp $ */ +/* $OpenBSD: fusebuf.h,v 1.11 2016/08/30 16:45:54 natano Exp $ */ /* * Copyright (c) 2013 Sylvestre Gallon * Copyright (c) 2013 Martin Pieuchot @@ -62,10 +62,10 @@ struct fusebuf { struct fb_hdr fb_hdr; union { struct statvfs FD_stat; /* vfs statfs */ - struct vattr FD_vattr; /* for attr vnops */ + struct stat FD_attr; /* for attr vnops */ struct fb_io FD_io; /* for file io vnops */ } FD; - uint8_t *F_databuf; /* data's */ + uint8_t *fb_dat; /* data's */ }; #define fb_next fb_hdr.fh_next @@ -76,7 +76,7 @@ struct fusebuf { #define fb_uuid fb_hdr.fh_uuid #define fb_stat FD.FD_stat -#define fb_vattr FD.FD_vattr +#define fb_attr FD.FD_attr #define fb_io_fd FD.FD_io.fi_fd #define fb_io_ino FD.FD_io.fi_ino #define fb_io_off FD.FD_io.fi_off @@ -84,7 +84,6 @@ struct fusebuf { #define fb_io_mode FD.FD_io.fi_mode #define fb_io_flags FD.FD_io.fi_flags #define fb_io_rdev FD.FD_io.fi_rdev -#define fb_dat F_databuf /* * Macros for type conversion