diff options
Diffstat (limited to 'sys/fs')
52 files changed, 749 insertions, 517 deletions
diff --git a/sys/fs/cd9660/cd9660_lookup.c b/sys/fs/cd9660/cd9660_lookup.c index 75fcdc9152cd..4d0bf73ab235 100644 --- a/sys/fs/cd9660/cd9660_lookup.c +++ b/sys/fs/cd9660/cd9660_lookup.c @@ -386,7 +386,7 @@ found: return (error); *vpp = tdp; } else if (dp->i_number == i_ino) { - VREF(vdp); /* we want ourself, ie "." */ + vref(vdp); /* we want ourself, ie "." */ /* * When we lookup "." we still can be asked to lock it * differently. diff --git a/sys/fs/cd9660/cd9660_vfsops.c b/sys/fs/cd9660/cd9660_vfsops.c index b4db4c4f7331..ce6d03b73290 100644 --- a/sys/fs/cd9660/cd9660_vfsops.c +++ b/sys/fs/cd9660/cd9660_vfsops.c @@ -617,13 +617,13 @@ cd9660_fhtovp(struct mount *mp, struct fid *fhp, int flags, struct vnode **vpp) #endif if ((error = VFS_VGET(mp, ifh.ifid_ino, LK_EXCLUSIVE, &nvp)) != 0) { - *vpp = NULLVP; + *vpp = NULL; return (error); } ip = VTOI(nvp); if (ip->inode.iso_mode == 0) { vput(nvp); - *vpp = NULLVP; + *vpp = NULL; return (ESTALE); } *vpp = nvp; @@ -704,7 +704,7 @@ cd9660_vget_internal(struct mount *mp, ino_t ino, int flags, /* Allocate a new vnode/iso_node. */ if ((error = getnewvnode("isofs", mp, &cd9660_vnodeops, &vp)) != 0) { - *vpp = NULLVP; + *vpp = NULL; return (error); } ip = malloc(sizeof(struct iso_node), M_ISOFSNODE, @@ -717,7 +717,7 @@ cd9660_vget_internal(struct mount *mp, ino_t ino, int flags, error = insmntque(vp, mp); if (error != 0) { free(ip, M_ISOFSNODE); - *vpp = NULLVP; + *vpp = NULL; return (error); } error = vfs_hash_insert(vp, ino, flags, td, vpp, cd9660_vfs_hash_cmp, diff --git a/sys/fs/cuse/cuse.c b/sys/fs/cuse/cuse.c index d63a7d4691cf..b2524324584a 100644 --- a/sys/fs/cuse/cuse.c +++ b/sys/fs/cuse/cuse.c @@ -195,12 +195,14 @@ static const struct filterops cuse_client_kqfilter_read_ops = { .f_isfd = 1, .f_detach = cuse_client_kqfilter_read_detach, .f_event = cuse_client_kqfilter_read_event, + .f_copy = knote_triv_copy, }; static const struct filterops cuse_client_kqfilter_write_ops = { .f_isfd = 1, .f_detach = cuse_client_kqfilter_write_detach, .f_event = cuse_client_kqfilter_write_event, + .f_copy = knote_triv_copy, }; static d_open_t cuse_client_open; diff --git a/sys/fs/deadfs/dead_vnops.c b/sys/fs/deadfs/dead_vnops.c index 296cf058f8c9..137c86b65058 100644 --- a/sys/fs/deadfs/dead_vnops.c +++ b/sys/fs/deadfs/dead_vnops.c @@ -122,18 +122,18 @@ dead_read(struct vop_read_args *ap) { /* - * Return EOF for tty devices, EIO for others + * Return EOF for tty devices, ENXIO for others */ - if ((ap->a_vp->v_vflag & VV_ISTTY) == 0) - return (EIO); - return (0); + if (ap->a_vp->v_vflag & VV_ISTTY) + return (0); + return (ENXIO); } int dead_write(struct vop_write_args *ap) { - return (EIO); + return (ENXIO); } int diff --git a/sys/fs/devfs/devfs_dir.c b/sys/fs/devfs/devfs_dir.c index 3dc87538017d..aad87606e738 100644 --- a/sys/fs/devfs/devfs_dir.c +++ b/sys/fs/devfs/devfs_dir.c @@ -162,7 +162,7 @@ int devfs_pathpath(const char *p1, const char *p2) { - for (;;p1++, p2++) { + for (;; p1++, p2++) { if (*p1 != *p2) { if (*p1 == '/' && *p2 == '\0') return (1); diff --git a/sys/fs/devfs/devfs_int.h b/sys/fs/devfs/devfs_int.h index 916297425b53..9fa75c0e90ad 100644 --- a/sys/fs/devfs/devfs_int.h +++ b/sys/fs/devfs/devfs_int.h @@ -67,6 +67,7 @@ struct cdev_priv { void *cdp_dtr_cb_arg; LIST_HEAD(, cdev_privdata) cdp_fdpriv; + u_int cdp_fdpriv_dtrc; struct mtx cdp_threadlock; }; diff --git a/sys/fs/devfs/devfs_vnops.c b/sys/fs/devfs/devfs_vnops.c index 3a64c205186f..323f1e0fa961 100644 --- a/sys/fs/devfs/devfs_vnops.c +++ b/sys/fs/devfs/devfs_vnops.c @@ -200,14 +200,25 @@ devfs_foreach_cdevpriv(struct cdev *dev, int (*cb)(void *data, void *arg), void devfs_destroy_cdevpriv(struct cdev_privdata *p) { + struct file *fp; + struct cdev_priv *cdp; mtx_assert(&cdevpriv_mtx, MA_OWNED); - KASSERT(p->cdpd_fp->f_cdevpriv == p, - ("devfs_destoy_cdevpriv %p != %p", p->cdpd_fp->f_cdevpriv, p)); - p->cdpd_fp->f_cdevpriv = NULL; + fp = p->cdpd_fp; + KASSERT(fp->f_cdevpriv == p, + ("devfs_destoy_cdevpriv %p != %p", fp->f_cdevpriv, p)); + cdp = cdev2priv((struct cdev *)fp->f_data); + cdp->cdp_fdpriv_dtrc++; + fp->f_cdevpriv = NULL; LIST_REMOVE(p, cdpd_list); mtx_unlock(&cdevpriv_mtx); (p->cdpd_dtr)(p->cdpd_data); + mtx_lock(&cdevpriv_mtx); + MPASS(cdp->cdp_fdpriv_dtrc >= 1); + cdp->cdp_fdpriv_dtrc--; + if (cdp->cdp_fdpriv_dtrc == 0) + wakeup(&cdp->cdp_fdpriv_dtrc); + mtx_unlock(&cdevpriv_mtx); free(p, M_CDEVPDATA); } @@ -1061,7 +1072,7 @@ devfs_lookupx(struct vop_lookup_args *ap, int *dm_unlock) mp = dvp->v_mount; dmp = VFSTODEVFS(mp); dd = dvp->v_data; - *vpp = NULLVP; + *vpp = NULL; if ((flags & ISLASTCN) && nameiop == RENAME) return (EOPNOTSUPP); @@ -1080,7 +1091,7 @@ devfs_lookupx(struct vop_lookup_args *ap, int *dm_unlock) if ((flags & ISLASTCN) && nameiop != LOOKUP) return (EINVAL); *vpp = dvp; - VREF(dvp); + vref(dvp); return (0); } @@ -1170,7 +1181,7 @@ devfs_lookupx(struct vop_lookup_args *ap, int *dm_unlock) if (error) return (error); if (*vpp == dvp) { - VREF(dvp); + vref(dvp); *vpp = dvp; return (0); } diff --git a/sys/fs/ext2fs/ext2_lookup.c b/sys/fs/ext2fs/ext2_lookup.c index c80e0f99ab56..bb830d07b126 100644 --- a/sys/fs/ext2fs/ext2_lookup.c +++ b/sys/fs/ext2fs/ext2_lookup.c @@ -579,7 +579,7 @@ found: if (dd_ino != NULL) return (0); if (dp->i_number == ino) { - VREF(vdp); + vref(vdp); *vpp = vdp; return (0); } @@ -675,7 +675,7 @@ found: } *vpp = tdp; } else if (dp->i_number == ino) { - VREF(vdp); /* we want ourself, ie "." */ + vref(vdp); /* we want ourself, ie "." */ /* * When we lookup "." we still can be asked to lock it * differently. diff --git a/sys/fs/ext2fs/ext2_vfsops.c b/sys/fs/ext2fs/ext2_vfsops.c index 9e7a03fffd71..0f3808a7c747 100644 --- a/sys/fs/ext2fs/ext2_vfsops.c +++ b/sys/fs/ext2fs/ext2_vfsops.c @@ -1334,14 +1334,14 @@ ext2_fhtovp(struct mount *mp, struct fid *fhp, int flags, struct vnode **vpp) error = VFS_VGET(mp, ufhp->ufid_ino, LK_EXCLUSIVE, &nvp); if (error) { - *vpp = NULLVP; + *vpp = NULL; return (error); } ip = VTOI(nvp); if (ip->i_mode == 0 || ip->i_gen != ufhp->ufid_gen || ip->i_nlink <= 0) { vput(nvp); - *vpp = NULLVP; + *vpp = NULL; return (ESTALE); } *vpp = nvp; diff --git a/sys/fs/ext2fs/ext2_vnops.c b/sys/fs/ext2fs/ext2_vnops.c index 00389c927087..35e7ca77c732 100644 --- a/sys/fs/ext2fs/ext2_vnops.c +++ b/sys/fs/ext2fs/ext2_vnops.c @@ -905,7 +905,7 @@ abortit: error = ext2_checkpath(ip, dp, tcnp->cn_cred); if (error) goto out; - VREF(tdvp); + vref(tdvp); error = vfs_relookup(tdvp, &tvp, tcnp, true); if (error) goto out; @@ -1031,7 +1031,7 @@ abortit: */ fcnp->cn_flags &= ~MODMASK; fcnp->cn_flags |= LOCKPARENT | LOCKLEAF; - VREF(fdvp); + vref(fdvp); error = vfs_relookup(fdvp, &fvp, fcnp, true); if (error == 0) vrele(fdvp); diff --git a/sys/fs/fdescfs/fdesc_vnops.c b/sys/fs/fdescfs/fdesc_vnops.c index 58a22b8bdc50..c1188c3819e7 100644 --- a/sys/fs/fdescfs/fdesc_vnops.c +++ b/sys/fs/fdescfs/fdesc_vnops.c @@ -196,7 +196,7 @@ loop: if (error != 0) { vgone(vp); vput(vp); - *vpp = NULLVP; + *vpp = NULL; return (error); } @@ -211,7 +211,7 @@ loop: mtx_unlock(&fdesc_hashmtx); vgone(vp); vput(vp); - *vpp = NULLVP; + *vpp = NULL; return (-1); } @@ -227,7 +227,7 @@ loop: vput(vp); /* If we didn't get it, return no vnode. */ if (error) - vp2 = NULLVP; + vp2 = NULL; *vpp = vp2; return (error); } @@ -301,7 +301,7 @@ fdesc_lookup(struct vop_lookup_args *ap) if (cnp->cn_namelen == 1 && *pname == '.') { *vpp = dvp; - VREF(dvp); + vref(dvp); return (0); } diff --git a/sys/fs/fuse/fuse_device.c b/sys/fs/fuse/fuse_device.c index 57b3559731f7..cee477865c42 100644 --- a/sys/fs/fuse/fuse_device.c +++ b/sys/fs/fuse/fuse_device.c @@ -126,11 +126,13 @@ static const struct filterops fuse_device_rfiltops = { .f_isfd = 1, .f_detach = fuse_device_filt_detach, .f_event = fuse_device_filt_read, + .f_copy = knote_triv_copy, }; static const struct filterops fuse_device_wfiltops = { .f_isfd = 1, .f_event = fuse_device_filt_write, + .f_copy = knote_triv_copy, }; /**************************** @@ -548,6 +550,13 @@ fuse_device_write(struct cdev *dev, struct uio *uio, int ioflag) } else if (ohead.unique == 0){ /* unique == 0 means asynchronous notification */ SDT_PROBE1(fusefs, , device, fuse_device_write_notify, &ohead); + if (data->mp == NULL) { + SDT_PROBE2(fusefs, , device, trace, 1, + "asynchronous notification before mount" + " or after unmount"); + return (EXTERROR(ENODEV, + "This FUSE session is not mounted")); + } mp = data->mp; vfs_ref(mp); err = vfs_busy(mp, 0); diff --git a/sys/fs/fuse/fuse_internal.c b/sys/fs/fuse/fuse_internal.c index 61fe2ed032f6..eba0a8a79ff3 100644 --- a/sys/fs/fuse/fuse_internal.c +++ b/sys/fs/fuse/fuse_internal.c @@ -1063,6 +1063,8 @@ fuse_internal_init_callback(struct fuse_ticket *tick, struct uio *uio) if (!fuse_libabi_geq(data, 7, 28)) fsess_set_notimpl(data->mp, FUSE_COPY_FILE_RANGE); + if (fuse_libabi_geq(data, 7, 33) && (fiio->flags & FUSE_SETXATTR_EXT)) + data->dataflags |= FSESS_SETXATTR_EXT; out: if (err) { fdata_set_dead(data); @@ -1115,7 +1117,8 @@ fuse_internal_send_init(struct fuse_data *data, struct thread *td) */ fiii->flags = FUSE_ASYNC_READ | FUSE_POSIX_LOCKS | FUSE_EXPORT_SUPPORT | FUSE_BIG_WRITES | FUSE_WRITEBACK_CACHE - | FUSE_NO_OPEN_SUPPORT | FUSE_NO_OPENDIR_SUPPORT; + | FUSE_NO_OPEN_SUPPORT | FUSE_NO_OPENDIR_SUPPORT + | FUSE_SETXATTR_EXT; fuse_insert_callback(fdi.tick, fuse_internal_init_callback); fuse_insert_message(fdi.tick, false); diff --git a/sys/fs/fuse/fuse_ipc.c b/sys/fs/fuse/fuse_ipc.c index a751c09159ff..bc36f0070d7d 100644 --- a/sys/fs/fuse/fuse_ipc.c +++ b/sys/fs/fuse/fuse_ipc.c @@ -193,7 +193,6 @@ fuse_interrupt_send(struct fuse_ticket *otick, int err) struct fuse_data *data = otick->tk_data; struct fuse_ticket *tick, *xtick; struct ucred reused_creds; - gid_t reused_groups[1]; if (otick->irq_unique == 0) { /* @@ -237,8 +236,7 @@ fuse_interrupt_send(struct fuse_ticket *otick, int err) */ ftick_hdr = fticket_in_header(otick); reused_creds.cr_uid = ftick_hdr->uid; - reused_groups[0] = ftick_hdr->gid; - reused_creds.cr_groups = reused_groups; + reused_creds.cr_gid = ftick_hdr->gid; fdisp_init(&fdi, sizeof(*fii)); fdisp_make_pid(&fdi, FUSE_INTERRUPT, data, ftick_hdr->nodeid, ftick_hdr->pid, &reused_creds); @@ -696,7 +694,7 @@ fuse_body_audit(struct fuse_ticket *ftick, size_t blen) break; case FUSE_FORGET: - panic("FUSE: a handler has been intalled for FUSE_FORGET"); + panic("FUSE: a handler has been installed for FUSE_FORGET"); break; case FUSE_GETATTR: diff --git a/sys/fs/fuse/fuse_ipc.h b/sys/fs/fuse/fuse_ipc.h index 3bfc859dbac9..d9d79f38c269 100644 --- a/sys/fs/fuse/fuse_ipc.h +++ b/sys/fs/fuse/fuse_ipc.h @@ -243,6 +243,7 @@ struct fuse_data { #define FSESS_MNTOPTS_MASK ( \ FSESS_DAEMON_CAN_SPY | FSESS_PUSH_SYMLINKS_IN | \ FSESS_DEFAULT_PERMISSIONS | FSESS_INTR) +#define FSESS_SETXATTR_EXT 0x8000000 /* extended fuse_setxattr_in */ extern int fuse_data_cache_mode; diff --git a/sys/fs/fuse/fuse_vfsops.c b/sys/fs/fuse/fuse_vfsops.c index 1b858a988289..b617925c4e5f 100644 --- a/sys/fs/fuse/fuse_vfsops.c +++ b/sys/fs/fuse/fuse_vfsops.c @@ -278,13 +278,13 @@ fuse_vfsop_fhtovp(struct mount *mp, struct fid *fhp, int flags, error = VFS_VGET(mp, ffhp->nid, LK_EXCLUSIVE, &nvp); if (error) { - *vpp = NULLVP; + *vpp = NULL; return (error); } fvdat = VTOFUD(nvp); if (fvdat->generation != ffhp->gen ) { vput(nvp); - *vpp = NULLVP; + *vpp = NULL; return (ESTALE); } *vpp = nvp; diff --git a/sys/fs/fuse/fuse_vnops.c b/sys/fs/fuse/fuse_vnops.c index de60a4717dd4..ef5aee5de34c 100644 --- a/sys/fs/fuse/fuse_vnops.c +++ b/sys/fs/fuse/fuse_vnops.c @@ -284,7 +284,7 @@ fuse_flush(struct vnode *vp, struct ucred *cred, pid_t pid, int fflag) struct mount *mp = vnode_mount(vp); int err; - if (fsess_not_impl(vnode_mount(vp), FUSE_FLUSH)) + if (fsess_not_impl(mp, FUSE_FLUSH)) return 0; err = fuse_filehandle_getrw(vp, fflag, &fufh, cred, pid); @@ -292,7 +292,7 @@ fuse_flush(struct vnode *vp, struct ucred *cred, pid_t pid, int fflag) return err; if (fufh->fuse_open_flags & FOPEN_NOFLUSH && - (!fsess_opt_writeback(vnode_mount(vp)))) + (!fsess_opt_writeback(mp))) return (0); fdisp_init(&fdi, sizeof(*ffi)); @@ -625,7 +625,7 @@ fuse_vnop_allocate(struct vop_allocate_args *ap) return (EROFS); if (fsess_not_impl(mp, FUSE_FALLOCATE)) - return (EXTERROR(EINVAL, "This server does not implement " + return (EXTERROR(EOPNOTSUPP, "This server does not implement " "FUSE_FALLOCATE")); io.uio_offset = *offset; @@ -656,14 +656,14 @@ fuse_vnop_allocate(struct vop_allocate_args *ap) if (err == ENOSYS) { fsess_set_notimpl(mp, FUSE_FALLOCATE); - err = EXTERROR(EINVAL, "This server does not implement " + err = EXTERROR(EOPNOTSUPP, "This server does not implement " "FUSE_ALLOCATE"); } else if (err == EOPNOTSUPP) { /* * The file system server does not support FUSE_FALLOCATE with * the supplied mode for this particular file. */ - err = EXTERROR(EINVAL, "This file can't be pre-allocated"); + err = EXTERROR(EOPNOTSUPP, "This file can't be pre-allocated"); } else if (!err) { *offset += *len; *len = 0; @@ -795,11 +795,15 @@ fuse_vnop_close(struct vop_close_args *ap) struct mount *mp = vnode_mount(vp); struct ucred *cred = ap->a_cred; int fflag = ap->a_fflag; - struct thread *td = ap->a_td; - pid_t pid = td->td_proc->p_pid; + struct thread *td; struct fuse_vnode_data *fvdat = VTOFUD(vp); + pid_t pid; int err = 0; + /* NB: a_td will be NULL from some async kernel contexts */ + td = ap->a_td ? ap->a_td : curthread; + pid = td->td_proc->p_pid; + if (fuse_isdeadfs(vp)) return 0; if (vnode_isdir(vp)) @@ -838,7 +842,7 @@ fuse_vnop_close(struct vop_close_args *ap) } /* TODO: close the file handle, if we're sure it's no longer used */ if ((fvdat->flag & FN_SIZECHANGE) != 0) { - fuse_vnode_savesize(vp, cred, td->td_proc->p_pid); + fuse_vnode_savesize(vp, cred, pid); } return err; } @@ -953,7 +957,7 @@ fuse_vnop_copy_file_range(struct vop_copy_file_range_args *ap) *ap->a_outoffp += fwo->size; fuse_internal_clear_suid_on_write(outvp, outcred, td); if (*ap->a_outoffp > outfvdat->cached_attrs.va_size) { - fuse_vnode_setsize(outvp, *ap->a_outoffp, false); + fuse_vnode_setsize(outvp, *ap->a_outoffp, false); getnanouptime(&outfvdat->last_local_modify); } fuse_vnode_update(invp, FN_ATIMECHANGE); @@ -2752,7 +2756,7 @@ fuse_vnop_setextattr(struct vop_setextattr_args *ap) */ if (fsess_not_impl(mp, FUSE_REMOVEXATTR)) return (EXTERROR(EOPNOTSUPP, "This server does not " - "implement removing extended attributess")); + "implement removing extended attributes")); else return (EXTERROR(EINVAL, "DELETEEXTATTR should be used " "to remove extattrs")); @@ -2773,7 +2777,7 @@ fuse_vnop_setextattr(struct vop_setextattr_args *ap) strlen(ap->a_name) + 1; /* older FUSE servers use a smaller fuse_setxattr_in struct*/ - if (fuse_libabi_geq(fuse_get_mpdata(mp), 7, 33)) + if (fuse_get_mpdata(mp)->dataflags & FSESS_SETXATTR_EXT) struct_size = sizeof(*set_xattr_in); fdisp_init(&fdi, len + struct_size + uio->uio_resid); @@ -2782,7 +2786,7 @@ fuse_vnop_setextattr(struct vop_setextattr_args *ap) set_xattr_in = fdi.indata; set_xattr_in->size = uio->uio_resid; - if (fuse_libabi_geq(fuse_get_mpdata(mp), 7, 33)) { + if (fuse_get_mpdata(mp)->dataflags & FSESS_SETXATTR_EXT) { set_xattr_in->setxattr_flags = 0; set_xattr_in->padding = 0; } diff --git a/sys/fs/msdosfs/msdosfs_lookup.c b/sys/fs/msdosfs/msdosfs_lookup.c index 8ab6d35a2685..58ce8eff9dbd 100644 --- a/sys/fs/msdosfs/msdosfs_lookup.c +++ b/sys/fs/msdosfs/msdosfs_lookup.c @@ -515,7 +515,7 @@ foundroot: * Save directory inode pointer in ndp->ni_dvp for dirremove(). */ if (dp->de_StartCluster == scn && isadir) { /* "." */ - VREF(vdp); + vref(vdp); *vpp = vdp; return (0); } @@ -602,7 +602,7 @@ foundroot: msdosfs_integrity_error(pmp); return (EBADF); } - VREF(vdp); /* we want ourself, ie "." */ + vref(vdp); /* we want ourself, ie "." */ *vpp = vdp; } else { if ((error = deget(pmp, cluster, blkoff, LK_EXCLUSIVE, diff --git a/sys/fs/msdosfs/msdosfs_vfsops.c b/sys/fs/msdosfs/msdosfs_vfsops.c index 4431d36c8a8e..30c63cfa8a35 100644 --- a/sys/fs/msdosfs/msdosfs_vfsops.c +++ b/sys/fs/msdosfs/msdosfs_vfsops.c @@ -1184,7 +1184,7 @@ msdosfs_fhtovp(struct mount *mp, struct fid *fhp, int flags, struct vnode **vpp) error = deget(pmp, defhp->defid_dirclust, defhp->defid_dirofs, LK_EXCLUSIVE, &dep); if (error) { - *vpp = NULLVP; + *vpp = NULL; return (error); } *vpp = DETOV(dep); diff --git a/sys/fs/msdosfs/msdosfs_vnops.c b/sys/fs/msdosfs/msdosfs_vnops.c index 33e0d94954d7..6dfac1b4ebd2 100644 --- a/sys/fs/msdosfs/msdosfs_vnops.c +++ b/sys/fs/msdosfs/msdosfs_vnops.c @@ -1944,6 +1944,9 @@ msdosfs_pathconf(struct vop_pathconf_args *ap) case _PC_HAS_HIDDENSYSTEM: *ap->a_retval = 1; return (0); + case _PC_CASE_INSENSITIVE: + *ap->a_retval = 1; + return (0); default: return (vop_stdpathconf(ap)); } diff --git a/sys/fs/nfs/nfs_commonport.c b/sys/fs/nfs/nfs_commonport.c index e5fdb395c9f7..862780741ee7 100644 --- a/sys/fs/nfs/nfs_commonport.c +++ b/sys/fs/nfs/nfs_commonport.c @@ -371,8 +371,6 @@ nfsrv_atroot(struct vnode *vp, uint64_t *retp) /* * Set the credentials to refer to root. - * If only the various BSDen could agree on whether cr_gid is a separate - * field or cr_groups[0]... */ void newnfs_setroot(struct ucred *cred) diff --git a/sys/fs/nfs/nfs_commonsubs.c b/sys/fs/nfs/nfs_commonsubs.c index 7f5b29ca2085..707ad5749ab2 100644 --- a/sys/fs/nfs/nfs_commonsubs.c +++ b/sys/fs/nfs/nfs_commonsubs.c @@ -194,7 +194,6 @@ struct nfsv4_opflag nfsv4_opflag[NFSV42_NOPS] = { { 0, 1, 1, 1, LK_EXCLUSIVE, 1, 1 }, /* Removexattr */ }; -static int ncl_mbuf_mhlen = MHLEN; struct nfsrv_lughash { struct mtx mtx; struct nfsuserhashhead lughead; @@ -216,10 +215,17 @@ NFSD_VNET_DEFINE_STATIC(u_char *, nfsrv_dnsname) = NULL; * marked 0 in this array, the code will still work, just not quite as * efficiently.) */ -static int nfs_bigreply[NFSV42_NPROCS] = { 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 }; +static bool nfs_bigreply[NFSV42_NPROCS] = { + [NFSPROC_GETACL] = true, + [NFSPROC_GETEXTATTR] = true, + [NFSPROC_LISTEXTATTR] = true, + [NFSPROC_LOOKUP] = true, + [NFSPROC_READ] = true, + [NFSPROC_READDIR] = true, + [NFSPROC_READDIRPLUS] = true, + [NFSPROC_READDS] = true, + [NFSPROC_READLINK] = true, +}; /* local functions */ static int nfsrv_skipace(struct nfsrv_descript *nd, int *acesizep); @@ -232,6 +238,8 @@ static int nfsrv_getrefstr(struct nfsrv_descript *, u_char **, u_char **, static void nfsrv_refstrbigenough(int, u_char **, u_char **, int *); static uint32_t vtonfsv4_type(struct vattr *); static __enum_uint8(vtype) nfsv4tov_type(uint32_t, uint16_t *); +static void nfsv4_setsequence(struct nfsmount *, struct nfsrv_descript *, + struct nfsclsession *, bool, struct ucred *); static struct { int op; @@ -632,6 +640,7 @@ nfscl_fillsattr(struct nfsrv_descript *nd, struct vattr *vap, if ((flags & NFSSATTR_FULL) && vap->va_size != VNOVAL) NFSSETBIT_ATTRBIT(&attrbits, NFSATTRBIT_SIZE); if ((flags & NFSSATTR_FULL) && vap->va_flags != VNOVAL) { + NFSSETBIT_ATTRBIT(&attrbits, NFSATTRBIT_ARCHIVE); NFSSETBIT_ATTRBIT(&attrbits, NFSATTRBIT_HIDDEN); NFSSETBIT_ATTRBIT(&attrbits, NFSATTRBIT_SYSTEM); } @@ -649,7 +658,7 @@ nfscl_fillsattr(struct nfsrv_descript *nd, struct vattr *vap, NFSSETBIT_ATTRBIT(&attrbits, NFSATTRBIT_TIMECREATE); (void) nfsv4_fillattr(nd, vp->v_mount, vp, NULL, vap, NULL, 0, &attrbits, NULL, NULL, 0, 0, 0, 0, (uint64_t)0, NULL, - false, false, false, 0); + false, false, false, 0, NULL, false); break; } } @@ -760,7 +769,7 @@ nfsm_dissct(struct nfsrv_descript *nd, int siz, int how) nd->nd_dpos += siz; } else if (nd->nd_md->m_next == NULL) { return (retp); - } else if (siz > ncl_mbuf_mhlen) { + } else if (siz > MHLEN) { panic("nfs S too big"); } else { MGET(mp2, how, MT_DATA); @@ -1663,9 +1672,17 @@ nfsv4_loadattr(struct nfsrv_descript *nd, vnode_t vp, attrsum += NFSX_UNSIGNED; break; case NFSATTRBIT_ARCHIVE: - NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED); - if (compare && !(*retcmpp)) - *retcmpp = NFSERR_ATTRNOTSUPP; + NFSM_DISSECT(tl, uint32_t *, NFSX_UNSIGNED); + if (compare) { + if (!(*retcmpp) && ((*tl == newnfs_true && + (nap->na_flags & UF_ARCHIVE) == 0) || + (*tl == newnfs_false && + (nap->na_flags & UF_ARCHIVE) != 0))) + *retcmpp = NFSERR_NOTSAME; + } else if (nap != NULL) { + if (*tl == newnfs_true) + nap->na_flags |= UF_ARCHIVE; + } attrsum += NFSX_UNSIGNED; break; case NFSATTRBIT_CANSETTIME: @@ -1689,11 +1706,18 @@ nfsv4_loadattr(struct nfsrv_descript *nd, vnode_t vp, attrsum += NFSX_UNSIGNED; break; case NFSATTRBIT_CASEINSENSITIVE: - NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED); + NFSM_DISSECT(tl, uint32_t *, NFSX_UNSIGNED); if (compare) { if (!(*retcmpp)) { - if (*tl != newnfs_false) - *retcmpp = NFSERR_NOTSAME; + if (vp == NULL || VOP_PATHCONF(vp, + _PC_CASE_INSENSITIVE, + &has_pathconf) != 0) + has_pathconf = 0; + if ((has_pathconf != 0 && + *tl != newnfs_true) || + (has_pathconf == 0 && + *tl != newnfs_false)) + *retcmpp = NFSERR_NOTSAME; } } else if (pc != NULL) { pc->pc_caseinsensitive = @@ -2673,7 +2697,8 @@ nfsv4_fillattr(struct nfsrv_descript *nd, struct mount *mp, vnode_t vp, nfsattrbit_t *attrbitp, struct ucred *cred, NFSPROC_T *p, int isdgram, int reterr, int supports_nfsv4acls, int at_root, uint64_t mounted_on_fileno, struct statfs *pnfssf, bool xattrsupp, bool has_hiddensystem, - bool has_namedattr, uint32_t clone_blksize) + bool has_namedattr, uint32_t clone_blksize, fsid_t *fsidp, + bool has_caseinsensitive) { int bitpos, retnum = 0; u_int32_t *tl; @@ -2795,6 +2820,7 @@ nfsv4_fillattr(struct nfsrv_descript *nd, struct mount *mp, vnode_t vp, if (!has_hiddensystem) { NFSCLRBIT_ATTRBIT(&attrbits, NFSATTRBIT_HIDDEN); NFSCLRBIT_ATTRBIT(&attrbits, NFSATTRBIT_SYSTEM); + NFSCLRBIT_ATTRBIT(&attrbits, NFSATTRBIT_ARCHIVE); } if (clone_blksize == 0) NFSCLRBIT_ATTRBIT(&attrbits, @@ -2847,10 +2873,12 @@ nfsv4_fillattr(struct nfsrv_descript *nd, struct mount *mp, vnode_t vp, break; case NFSATTRBIT_FSID: NFSM_BUILD(tl, u_int32_t *, NFSX_V4FSID); + if (fsidp == NULL) + fsidp = &mp->mnt_stat.f_fsid; *tl++ = 0; - *tl++ = txdr_unsigned(mp->mnt_stat.f_fsid.val[0]); + *tl++ = txdr_unsigned(fsidp->val[0]); *tl++ = 0; - *tl = txdr_unsigned(mp->mnt_stat.f_fsid.val[1]); + *tl = txdr_unsigned(fsidp->val[1]); retnum += NFSX_V4FSID; break; case NFSATTRBIT_UNIQUEHANDLES: @@ -2879,6 +2907,14 @@ nfsv4_fillattr(struct nfsrv_descript *nd, struct mount *mp, vnode_t vp, *tl = txdr_unsigned(NFSV4ACE_SUPTYPES); retnum += NFSX_UNSIGNED; break; + case NFSATTRBIT_ARCHIVE: + NFSM_BUILD(tl, uint32_t *, NFSX_UNSIGNED); + if ((vap->va_flags & UF_ARCHIVE) != 0) + *tl = newnfs_true; + else + *tl = newnfs_false; + retnum += NFSX_UNSIGNED; + break; case NFSATTRBIT_CANSETTIME: NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED); if (fsinf.fs_properties & NFSV3FSINFO_CANSETTIME) @@ -2888,8 +2924,11 @@ nfsv4_fillattr(struct nfsrv_descript *nd, struct mount *mp, vnode_t vp, retnum += NFSX_UNSIGNED; break; case NFSATTRBIT_CASEINSENSITIVE: - NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED); - *tl = newnfs_false; + NFSM_BUILD(tl, uint32_t *, NFSX_UNSIGNED); + if (has_caseinsensitive) + *tl = newnfs_true; + else + *tl = newnfs_false; retnum += NFSX_UNSIGNED; break; case NFSATTRBIT_CASEPRESERVING: @@ -4165,10 +4204,15 @@ nfssvc_idname(struct nfsd_idargs *nidp) nidp->nid_namelen); if (error == 0 && nidp->nid_ngroup > 0 && (nidp->nid_flag & NFSID_ADDUID) != 0) { - grps = malloc(sizeof(gid_t) * nidp->nid_ngroup, M_TEMP, - M_WAITOK); - error = copyin(nidp->nid_grps, grps, - sizeof(gid_t) * nidp->nid_ngroup); + grps = NULL; + if (nidp->nid_ngroup > NGROUPS_MAX) + error = EINVAL; + if (error == 0) { + grps = malloc(sizeof(gid_t) * nidp->nid_ngroup, M_TEMP, + M_WAITOK); + error = copyin(nidp->nid_grps, grps, + sizeof(gid_t) * nidp->nid_ngroup); + } if (error == 0) { /* * Create a credential just like svc_getcred(), @@ -5021,9 +5065,9 @@ nfsv4_seqsess_cacherep(uint32_t slotid, struct nfsslot *slots, int repstat, /* * Generate the xdr for an NFSv4.1 Sequence Operation. */ -void +static void nfsv4_setsequence(struct nfsmount *nmp, struct nfsrv_descript *nd, - struct nfsclsession *sep, int dont_replycache, struct ucred *cred) + struct nfsclsession *sep, bool dont_replycache, struct ucred *cred) { uint32_t *tl, slotseq = 0; int error, maxslot, slotpos; @@ -5054,7 +5098,7 @@ nfsv4_setsequence(struct nfsmount *nmp, struct nfsrv_descript *nd, *tl++ = txdr_unsigned(slotseq); *tl++ = txdr_unsigned(slotpos); *tl++ = txdr_unsigned(maxslot); - if (dont_replycache == 0) + if (!dont_replycache) *tl = newnfs_true; else *tl = newnfs_false; diff --git a/sys/fs/nfs/nfs_var.h b/sys/fs/nfs/nfs_var.h index 61083ecf2d66..7db3952ecf5c 100644 --- a/sys/fs/nfs/nfs_var.h +++ b/sys/fs/nfs/nfs_var.h @@ -361,8 +361,6 @@ int nfsv4_getipaddr(struct nfsrv_descript *, struct sockaddr_in *, int nfsv4_seqsession(uint32_t, uint32_t, uint32_t, struct nfsslot *, struct mbuf **, uint16_t); void nfsv4_seqsess_cacherep(uint32_t, struct nfsslot *, int, struct mbuf **); -void nfsv4_setsequence(struct nfsmount *, struct nfsrv_descript *, - struct nfsclsession *, int, struct ucred *); int nfsv4_sequencelookup(struct nfsmount *, struct nfsclsession *, int *, int *, uint32_t *, uint8_t *, bool); void nfsv4_freeslot(struct nfsclsession *, int, bool); @@ -400,7 +398,7 @@ void nfsrv_wcc(struct nfsrv_descript *, int, struct nfsvattr *, int, int nfsv4_fillattr(struct nfsrv_descript *, struct mount *, vnode_t, NFSACL_T *, struct vattr *, fhandle_t *, int, nfsattrbit_t *, struct ucred *, NFSPROC_T *, int, int, int, int, uint64_t, struct statfs *, bool, bool, - bool, uint32_t); + bool, uint32_t, fsid_t *, bool); void nfsrv_fillattr(struct nfsrv_descript *, struct nfsvattr *); struct mbuf *nfsrv_adj(struct mbuf *, int, int); void nfsrv_postopattr(struct nfsrv_descript *, int, struct nfsvattr *); @@ -742,7 +740,7 @@ int nfsvno_updfilerev(vnode_t, struct nfsvattr *, struct nfsrv_descript *, int nfsvno_fillattr(struct nfsrv_descript *, struct mount *, vnode_t, struct nfsvattr *, fhandle_t *, int, nfsattrbit_t *, struct ucred *, NFSPROC_T *, int, int, int, int, uint64_t, bool, bool, - bool, uint32_t); + bool, uint32_t, bool); int nfsrv_sattr(struct nfsrv_descript *, vnode_t, struct nfsvattr *, nfsattrbit_t *, NFSACL_T *, NFSPROC_T *); int nfsv4_sattr(struct nfsrv_descript *, vnode_t, struct nfsvattr *, nfsattrbit_t *, diff --git a/sys/fs/nfs/nfsproto.h b/sys/fs/nfs/nfsproto.h index d628108bdc1a..13fec8a102a3 100644 --- a/sys/fs/nfs/nfsproto.h +++ b/sys/fs/nfs/nfsproto.h @@ -1135,6 +1135,7 @@ struct nfsv3_sattr { NFSATTRBM_RDATTRERROR | \ NFSATTRBM_ACL | \ NFSATTRBM_ACLSUPPORT | \ + NFSATTRBM_ARCHIVE | \ NFSATTRBM_CANSETTIME | \ NFSATTRBM_CASEINSENSITIVE | \ NFSATTRBM_CASEPRESERVING | \ @@ -1217,6 +1218,7 @@ struct nfsv3_sattr { #define NFSATTRBIT_SETABLE0 \ (NFSATTRBM_SIZE | \ NFSATTRBM_HIDDEN | \ + NFSATTRBM_ARCHIVE | \ NFSATTRBM_ACL) #define NFSATTRBIT_SETABLE1 \ (NFSATTRBM_MODE | \ @@ -1262,6 +1264,7 @@ struct nfsv3_sattr { NFSATTRBM_CHANGE | \ NFSATTRBM_SIZE | \ NFSATTRBM_FSID | \ + NFSATTRBM_ARCHIVE | \ NFSATTRBM_FILEID | \ NFSATTRBM_HIDDEN | \ NFSATTRBM_MAXREAD) @@ -1298,6 +1301,7 @@ struct nfsv3_sattr { NFSATTRBM_CHANGE | \ NFSATTRBM_SIZE | \ NFSATTRBM_FSID | \ + NFSATTRBM_ARCHIVE | \ NFSATTRBM_FILEID | \ NFSATTRBM_HIDDEN | \ NFSATTRBM_MAXREAD) diff --git a/sys/fs/nfsclient/nfs_clport.c b/sys/fs/nfsclient/nfs_clport.c index e9f1dc23ddbe..77e71d4153c9 100644 --- a/sys/fs/nfsclient/nfs_clport.c +++ b/sys/fs/nfsclient/nfs_clport.c @@ -1098,9 +1098,10 @@ newnfs_copyincred(struct ucred *cr, struct nfscred *nfscr) KASSERT(cr->cr_ngroups >= 0, ("newnfs_copyincred: negative cr_ngroups")); nfscr->nfsc_uid = cr->cr_uid; - nfscr->nfsc_ngroups = MIN(cr->cr_ngroups, NFS_MAXGRPS + 1); - for (i = 0; i < nfscr->nfsc_ngroups; i++) - nfscr->nfsc_groups[i] = cr->cr_groups[i]; + nfscr->nfsc_ngroups = MIN(cr->cr_ngroups + 1, NFS_MAXGRPS + 1); + nfscr->nfsc_groups[0] = cr->cr_gid; + for (i = 1; i < nfscr->nfsc_ngroups; i++) + nfscr->nfsc_groups[i] = cr->cr_groups[i - 1]; } /* diff --git a/sys/fs/nfsclient/nfs_clrpcops.c b/sys/fs/nfsclient/nfs_clrpcops.c index 4ec621de2eff..f5deef183efb 100644 --- a/sys/fs/nfsclient/nfs_clrpcops.c +++ b/sys/fs/nfsclient/nfs_clrpcops.c @@ -2212,7 +2212,7 @@ nfsrpc_writerpc(vnode_t vp, struct uio *uiop, int *iomode, NFSM_DISSECT(tl, u_int32_t *, 2 * NFSX_UNSIGNED + NFSX_VERF); rlen = fxdr_unsigned(int, *tl++); - if (rlen == 0) { + if (rlen <= 0 || rlen > len) { error = NFSERR_IO; goto nfsmout; } else if (rlen < len) { @@ -3981,7 +3981,7 @@ nfsrpc_readdirplus(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep, int len, left; struct dirent *dp = NULL; u_int32_t *tl; - vnode_t newvp = NULLVP; + vnode_t newvp = NULL; struct nfsrv_descript nfsd, *nd = &nfsd; struct nameidata nami, *ndp = &nami; struct componentname *cnp = &ndp->ni_cnd; @@ -4162,9 +4162,12 @@ nfsrpc_readdirplus(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep, NFSATTRBIT_TIMECREATE)) NFSCLRBIT_ATTRBIT(&attrbits, NFSATTRBIT_TIMECREATE); if (!NFSISSET_ATTRBIT(&dnp->n_vattr.na_suppattr, + NFSATTRBIT_ARCHIVE) || + !NFSISSET_ATTRBIT(&dnp->n_vattr.na_suppattr, NFSATTRBIT_HIDDEN) || !NFSISSET_ATTRBIT(&dnp->n_vattr.na_suppattr, NFSATTRBIT_SYSTEM)) { + NFSCLRBIT_ATTRBIT(&attrbits, NFSATTRBIT_ARCHIVE); NFSCLRBIT_ATTRBIT(&attrbits, NFSATTRBIT_HIDDEN); NFSCLRBIT_ATTRBIT(&attrbits, NFSATTRBIT_SYSTEM); } @@ -4387,7 +4390,7 @@ nfsrpc_readdirplus(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep, attr_ok = true; if (NFSRV_CMPFH(nfhp->nfh_fh, nfhp->nfh_len, dnp->n_fhp->nfh_fh, dnp->n_fhp->nfh_len)) { - VREF(vp); + vref(vp); newvp = vp; unlocknewvp = 0; free(nfhp, M_NFSFH); @@ -4436,7 +4439,7 @@ nfsrpc_readdirplus(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep, } } nfhp = NULL; - if (newvp != NULLVP) { + if (newvp != NULL) { if (attr_ok) error = nfscl_loadattrcache(&newvp, &nfsva, NULL, 0, 0); @@ -4466,7 +4469,7 @@ nfsrpc_readdirplus(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep, vput(newvp); else vrele(newvp); - newvp = NULLVP; + newvp = NULL; } } } else if (nfhp != NULL) { @@ -5281,7 +5284,7 @@ nfsrpc_getdirpath(struct nfsmount *nmp, u_char *dirpath, struct ucred *cred, struct nfsrv_descript nfsd; struct nfsrv_descript *nd = &nfsd; u_char *cp, *cp2, *fhp; - int error, cnt, len, setnil; + int error, cnt, i, len, setnil; u_int32_t *opcntp; nfscl_reqstart(nd, NFSPROC_PUTROOTFH, nmp, NULL, 0, &opcntp, NULL, 0, @@ -5322,8 +5325,12 @@ nfsrpc_getdirpath(struct nfsmount *nmp, u_char *dirpath, struct ucred *cred, if (error) return (error); if (nd->nd_repstat == 0) { - NFSM_DISSECT(tl, u_int32_t *, (3 + 2 * cnt) * NFSX_UNSIGNED); - tl += (2 + 2 * cnt); + NFSM_DISSECT(tl, uint32_t *, 3 * NFSX_UNSIGNED); + tl += 2; + for (i = 0; i < cnt; i++) { + NFSM_DISSECT(tl, uint32_t *, 2 * NFSX_UNSIGNED); + tl++; + } if ((len = fxdr_unsigned(int, *tl)) <= 0 || len > NFSX_FHMAX) { nd->nd_repstat = NFSERR_BADXDR; @@ -5445,7 +5452,7 @@ nfsrpc_setaclrpc(vnode_t vp, struct ucred *cred, NFSPROC_T *p, NFSSETBIT_ATTRBIT(&attrbits, NFSATTRBIT_ACL); (void) nfsv4_fillattr(nd, vp->v_mount, vp, aclp, NULL, NULL, 0, &attrbits, NULL, NULL, 0, 0, 0, 0, (uint64_t)0, NULL, false, false, - false, 0); + false, 0, NULL, false); error = nfscl_request(nd, vp, p, cred); if (error) return (error); @@ -5596,7 +5603,7 @@ nfsrpc_createsession(struct nfsmount *nmp, struct nfsclsession *sep, } *tl++ = txdr_unsigned(4096); /* Max response size cached */ *tl++ = txdr_unsigned(20); /* Max operations */ - *tl++ = txdr_unsigned(64); /* Max slots */ + *tl++ = txdr_unsigned(NFSV4_SLOTS); /* Max slots */ *tl = 0; /* No rdma ird */ /* Fill in back channel attributes. */ @@ -5665,6 +5672,11 @@ nfsrpc_createsession(struct nfsmount *nmp, struct nfsclsession *sep, sep->nfsess_maxcache = fxdr_unsigned(int, *tl++); tl++; sep->nfsess_foreslots = fxdr_unsigned(uint16_t, *tl++); + if (sep->nfsess_foreslots == 0) { + error = NFSERR_BADXDR; + goto nfsmout; + } else if (sep->nfsess_foreslots > NFSV4_SLOTS) + sep->nfsess_foreslots = NFSV4_SLOTS; NFSCL_DEBUG(4, "fore slots=%d\n", (int)sep->nfsess_foreslots); irdcnt = fxdr_unsigned(int, *tl); if (irdcnt < 0 || irdcnt > 1) { @@ -5678,6 +5690,8 @@ nfsrpc_createsession(struct nfsmount *nmp, struct nfsclsession *sep, NFSM_DISSECT(tl, uint32_t *, 7 * NFSX_UNSIGNED); tl += 5; sep->nfsess_backslots = fxdr_unsigned(uint16_t, *tl); + if (sep->nfsess_backslots > NFSV4_CBSLOTS) + sep->nfsess_backslots = NFSV4_CBSLOTS; NFSCL_DEBUG(4, "back slots=%d\n", (int)sep->nfsess_backslots); } error = nd->nd_repstat; @@ -5797,7 +5811,8 @@ nfsrpc_getdeviceinfo(struct nfsmount *nmp, uint8_t *deviceid, int layouttype, NFSM_DISSECT(tl, uint32_t *, NFSX_UNSIGNED); stripecnt = fxdr_unsigned(int, *tl); NFSCL_DEBUG(4, "stripecnt=%d\n", stripecnt); - if (stripecnt < 1 || stripecnt > 4096) { + if (stripecnt >= MHLEN / NFSX_UNSIGNED || + stripecnt < 1) { printf("pNFS File layout devinfo stripecnt %d:" " out of range\n", stripecnt); error = NFSERR_BADXDR; @@ -7246,7 +7261,7 @@ nfsrpc_writeds(vnode_t vp, struct uio *uiop, int *iomode, int *must_commit, NFSM_DISSECT(tl, uint32_t *, 2 * NFSX_UNSIGNED + NFSX_VERF); rlen = fxdr_unsigned(int, *tl++); NFSCL_DEBUG(4, "nfsrpc_writeds: len=%d rlen=%d\n", len, rlen); - if (rlen == 0) { + if (rlen <= 0 || rlen > len) { error = NFSERR_IO; goto nfsmout; } else if (rlen < len) { @@ -8243,7 +8258,7 @@ nfsrv_parseug(struct nfsrv_descript *nd, int dogrp, uid_t *uidp, gid_t *gidp, NFSPROC_T *p) { uint32_t *tl; - char *cp, *str, str0[NFSV4_SMALLSTR + 1]; + char *str, str0[NFSV4_SMALLSTR + 1]; uint32_t len = 0; int error = 0; @@ -8266,9 +8281,9 @@ nfsrv_parseug(struct nfsrv_descript *nd, int dogrp, uid_t *uidp, gid_t *gidp, str = malloc(len + 1, M_TEMP, M_WAITOK); else str = str0; - NFSM_DISSECT(cp, char *, NFSM_RNDUP(len)); - NFSBCOPY(cp, str, len); - str[len] = '\0'; + error = nfsrv_mtostr(nd, str, len); + if (error != 0) + goto nfsmout; NFSCL_DEBUG(4, "nfsrv_parseug: str=%s\n", str); if (dogrp != 0) error = nfsv4_strtogid(nd, str, len, gidp); @@ -9745,7 +9760,7 @@ nfsm_split(struct mbuf *mp, uint64_t xfer) pgno++; } while (pgno < m->m_epg_npgs); if (pgno == m->m_epg_npgs) - panic("nfsm_split: eroneous ext_pgs mbuf"); + panic("nfsm_split: erroneous ext_pgs mbuf"); m2 = mb_alloc_ext_pgs(M_WAITOK, mb_free_mext_pgs, 0); m2->m_epg_flags |= EPG_FLAG_ANON; diff --git a/sys/fs/nfsclient/nfs_clstate.c b/sys/fs/nfsclient/nfs_clstate.c index aa9d01fc4632..712d49c7160c 100644 --- a/sys/fs/nfsclient/nfs_clstate.c +++ b/sys/fs/nfsclient/nfs_clstate.c @@ -3701,7 +3701,8 @@ nfscl_docb(struct nfsrv_descript *nd, NFSPROC_T *p) if (!error) (void) nfsv4_fillattr(nd, NULL, NULL, NULL, &va, NULL, 0, &rattrbits, NULL, p, 0, 0, 0, 0, - (uint64_t)0, NULL, false, false, false, 0); + (uint64_t)0, NULL, false, false, false, 0, + NULL, false); break; case NFSV4OP_CBRECALL: NFSCL_DEBUG(4, "cbrecall\n"); diff --git a/sys/fs/nfsclient/nfs_clvfsops.c b/sys/fs/nfsclient/nfs_clvfsops.c index 5ea7eab07632..212c88f28930 100644 --- a/sys/fs/nfsclient/nfs_clvfsops.c +++ b/sys/fs/nfsclient/nfs_clvfsops.c @@ -927,7 +927,7 @@ nfs_mount(struct mount *mp) struct vnode *vp; struct thread *td; char *hst; - u_char nfh[NFSX_FHMAX], krbname[100], dirpath[100], srvkrbname[100]; + u_char nfh[NFSX_FHMAX], krbname[100], *dirpath, srvkrbname[100]; char *cp, *opt, *name, *secname, *tlscertname; int nametimeo = NFS_DEFAULT_NAMETIMEO; int negnametimeo = NFS_DEFAULT_NEGNAMETIMEO; @@ -943,6 +943,7 @@ nfs_mount(struct mount *mp) newflag = 0; tlscertname = NULL; hst = malloc(MNAMELEN, M_TEMP, M_WAITOK); + dirpath = malloc(MNAMELEN, M_TEMP, M_WAITOK); if (vfs_filteropt(mp->mnt_optnew, nfs_opts)) { error = EINVAL; goto out; @@ -1329,7 +1330,7 @@ nfs_mount(struct mount *mp) goto out; } else if (nfs_mount_parse_from(mp->mnt_optnew, &args.hostname, (struct sockaddr_in **)&nam, dirpath, - sizeof(dirpath), &dirlen) == 0) { + MNAMELEN, &dirlen) == 0) { has_nfs_from_opt = 1; bcopy(args.hostname, hst, MNAMELEN); hst[MNAMELEN - 1] = '\0'; @@ -1387,7 +1388,7 @@ nfs_mount(struct mount *mp) if (has_nfs_from_opt == 0) { if (vfs_getopt(mp->mnt_optnew, "dirpath", (void **)&name, NULL) == 0) - strlcpy(dirpath, name, sizeof (dirpath)); + strlcpy(dirpath, name, MNAMELEN); else dirpath[0] = '\0'; dirlen = strlen(dirpath); @@ -1472,6 +1473,7 @@ out: MNT_IUNLOCK(mp); } free(hst, M_TEMP); + free(dirpath, M_TEMP); return (error); } diff --git a/sys/fs/nfsclient/nfs_clvnops.c b/sys/fs/nfsclient/nfs_clvnops.c index eee571a04821..193d8b6cd5eb 100644 --- a/sys/fs/nfsclient/nfs_clvnops.c +++ b/sys/fs/nfsclient/nfs_clvnops.c @@ -1081,12 +1081,14 @@ nfs_setattr(struct vop_setattr_args *ap) #endif /* - * Only setting of UF_HIDDEN and UF_SYSTEM are supported and + * Only setting of UF_ARCHIVE, UF_HIDDEN and UF_SYSTEM are supported and * only for NFSv4 servers that support them. */ nmp = VFSTONFS(vp->v_mount); if (vap->va_flags != VNOVAL && (!NFSHASNFSV4(nmp) || - (vap->va_flags & ~(UF_HIDDEN | UF_SYSTEM)) != 0 || + (vap->va_flags & ~(UF_ARCHIVE | UF_HIDDEN | UF_SYSTEM)) != 0 || + ((vap->va_flags & UF_ARCHIVE) != 0 && + !NFSISSET_ATTRBIT(&np->n_vattr.na_suppattr, NFSATTRBIT_ARCHIVE)) || ((vap->va_flags & UF_HIDDEN) != 0 && !NFSISSET_ATTRBIT(&np->n_vattr.na_suppattr, NFSATTRBIT_HIDDEN)) || ((vap->va_flags & UF_SYSTEM) != 0 && @@ -1284,7 +1286,7 @@ nfs_lookup(struct vop_lookup_args *ap) bool is_nameddir, needs_nameddir, opennamed; dattrflag = 0; - *vpp = NULLVP; + *vpp = NULL; nmp = VFSTONFS(mp); opennamed = (flags & (OPENNAMED | ISLASTCN)) == (OPENNAMED | ISLASTCN); if (opennamed && (!NFSHASNFSV4(nmp) || !NFSHASNFSV4N(nmp))) @@ -1309,7 +1311,7 @@ nfs_lookup(struct vop_lookup_args *ap) /* * If the named attribute directory is needed, acquire it now. */ - newvp = NULLVP; + newvp = NULL; if (needs_nameddir) { KASSERT(np->n_v4 == NULL, ("nfs_lookup: O_NAMEDATTR when" " n_v4 not NULL")); @@ -1322,10 +1324,10 @@ nfs_lookup(struct vop_lookup_args *ap) } dvp = newvp; np = VTONFS(dvp); - newvp = NULLVP; + newvp = NULL; } else if (opennamed && cnp->cn_namelen == 1 && *cnp->cn_nameptr == '.') { - VREF(dvp); + vref(dvp); *vpp = dvp; return (0); } @@ -1399,7 +1401,7 @@ nfs_lookup(struct vop_lookup_args *ap) vput(newvp); else vrele(newvp); - *vpp = NULLVP; + *vpp = NULL; } else if (error == ENOENT) { if (VN_IS_DOOMED(dvp)) return (ENOENT); @@ -1450,7 +1452,7 @@ nfs_lookup(struct vop_lookup_args *ap) NFSUNLOCKMNT(nmp); #endif - newvp = NULLVP; + newvp = NULL; NFSINCRGLOBAL(nfsstatsv1.lookupcache_misses); nanouptime(&ts); error = nfsrpc_lookup(dvp, cnp->cn_nameptr, cnp->cn_namelen, @@ -1464,9 +1466,9 @@ nfs_lookup(struct vop_lookup_args *ap) } handle_error: if (error) { - if (newvp != NULLVP) { + if (newvp != NULL) { vput(newvp); - *vpp = NULLVP; + *vpp = NULL; } if (error != ENOENT) { @@ -1587,7 +1589,7 @@ handle_error: 0, 1); } else if (NFS_CMPFH(np, nfhp->nfh_fh, nfhp->nfh_len)) { free(nfhp, M_NFSFH); - VREF(dvp); + vref(dvp); newvp = dvp; if (attrflag) (void) nfscl_loadattrcache(&newvp, &nfsva, NULL, @@ -2863,7 +2865,7 @@ nfs_sillyrename(struct vnode *dvp, struct vnode *vp, struct componentname *cnp) M_NEWNFSREQ, M_WAITOK); sp->s_cred = crhold(cnp->cn_cred); sp->s_dvp = dvp; - VREF(dvp); + vref(dvp); /* * Fudge together a funny name. @@ -2961,7 +2963,7 @@ nfs_lookitup(struct vnode *dvp, char *name, int len, struct ucred *cred, newvp = NFSTOV(np); } else if (NFS_CMPFH(dnp, nfhp->nfh_fh, nfhp->nfh_len)) { free(nfhp, M_NFSFH); - VREF(dvp); + vref(dvp); newvp = dvp; } else { cn.cn_nameptr = name; @@ -3894,11 +3896,15 @@ nfs_allocate(struct vop_allocate_args *ap) mtx_lock(&nmp->nm_mtx); nmp->nm_privflag |= NFSMNTP_NOALLOCATE; mtx_unlock(&nmp->nm_mtx); - error = EINVAL; + error = EOPNOTSUPP; } } else { + /* + * Pre-v4.2 NFS server that doesn't support it, or a newer + * NFS server that has indicated that it doesn't support it. + */ mtx_unlock(&nmp->nm_mtx); - error = EINVAL; + error = EOPNOTSUPP; } if (attrflag != 0) { ret = nfscl_loadattrcache(&vp, &nfsva, NULL, 0, 1); @@ -4675,12 +4681,13 @@ nfs_pathconf(struct vop_pathconf_args *ap) clone_blksize = 0; if ((NFS_ISV34(vp) && (ap->a_name == _PC_LINK_MAX || ap->a_name == _PC_NAME_MAX || ap->a_name == _PC_CHOWN_RESTRICTED || - ap->a_name == _PC_NO_TRUNC)) || + ap->a_name == _PC_NO_TRUNC || + ap->a_name == _PC_CASE_INSENSITIVE)) || (NFS_ISV4(vp) && (ap->a_name == _PC_ACL_NFS4 || ap->a_name == _PC_HAS_NAMEDATTR || ap->a_name == _PC_CLONE_BLKSIZE))) { /* - * Since only the above 4 a_names are returned by the NFSv3 + * Since only the above 5 a_names are returned by the NFSv3 * Pathconf RPC, there is no point in doing it for others. * For NFSv4, the Pathconf RPC (actually a Getattr Op.) can * be used for _PC_ACL_NFS4, _PC_HAS_NAMEDATTR and @@ -4835,6 +4842,8 @@ nfs_pathconf(struct vop_pathconf_args *ap) break; case _PC_HAS_HIDDENSYSTEM: if (NFS_ISV4(vp) && NFSISSET_ATTRBIT(&np->n_vattr.na_suppattr, + NFSATTRBIT_ARCHIVE) && + NFSISSET_ATTRBIT(&np->n_vattr.na_suppattr, NFSATTRBIT_HIDDEN) && NFSISSET_ATTRBIT(&np->n_vattr.na_suppattr, NFSATTRBIT_SYSTEM)) @@ -4845,6 +4854,9 @@ nfs_pathconf(struct vop_pathconf_args *ap) case _PC_CLONE_BLKSIZE: *ap->a_retval = clone_blksize; break; + case _PC_CASE_INSENSITIVE: + *ap->a_retval = pc.pc_caseinsensitive; + break; default: error = vop_stdpathconf(ap); diff --git a/sys/fs/nfsserver/nfs_nfsdport.c b/sys/fs/nfsserver/nfs_nfsdport.c index 7040c4afb797..841ec2315f1c 100644 --- a/sys/fs/nfsserver/nfs_nfsdport.c +++ b/sys/fs/nfsserver/nfs_nfsdport.c @@ -675,7 +675,7 @@ nfsvno_namei(struct nfsrv_descript *nd, struct nameidata *ndp, } if (islocked) NFSVOPUNLOCK(dp); - VREF(dp); + vref(dp); *retdirp = dp; if (NFSVNO_EXRDONLY(exp)) cnp->cn_flags |= RDONLY; @@ -697,7 +697,7 @@ nfsvno_namei(struct nfsrv_descript *nd, struct nameidata *ndp, goto out; } dp = rootvnode; - VREF(dp); + vref(dp); } } else if ((nfsrv_enable_crossmntpt == 0 && NFSVNO_EXPORTED(exp)) || (nd->nd_flag & ND_NFSV4) == 0) { @@ -814,7 +814,7 @@ nfsvno_namei(struct nfsrv_descript *nd, struct nameidata *ndp, if (cnp->cn_pnbuf[0] == '/') { vrele(ndp->ni_dvp); ndp->ni_dvp = ndp->ni_rootdir; - VREF(ndp->ni_dvp); + vref(ndp->ni_dvp); } ndp->ni_startdir = ndp->ni_dvp; ndp->ni_dvp = NULL; @@ -2114,7 +2114,7 @@ nfsvno_fillattr(struct nfsrv_descript *nd, struct mount *mp, struct vnode *vp, struct ucred *cred, struct thread *p, int isdgram, int reterr, int supports_nfsv4acls, int at_root, uint64_t mounted_on_fileno, bool xattrsupp, bool has_hiddensystem, bool has_namedattr, - uint32_t clone_blksize) + uint32_t clone_blksize, bool has_caseinsensitive) { struct statfs *sf; int error; @@ -2135,7 +2135,7 @@ nfsvno_fillattr(struct nfsrv_descript *nd, struct mount *mp, struct vnode *vp, error = nfsv4_fillattr(nd, mp, vp, NULL, &nvap->na_vattr, fhp, rderror, attrbitp, cred, p, isdgram, reterr, supports_nfsv4acls, at_root, mounted_on_fileno, sf, xattrsupp, has_hiddensystem, has_namedattr, - clone_blksize); + clone_blksize, NULL, has_caseinsensitive); free(sf, M_TEMP); NFSEXITCODE2(0, nd); return (error); @@ -2468,7 +2468,7 @@ nfsrvd_readdirplus(struct nfsrv_descript *nd, int isdgram, int bextpg0, bextpg1, bextpgsiz0, bextpgsiz1; size_t atsiz; long pathval; - bool has_hiddensystem, has_namedattr, xattrsupp; + bool has_caseinsensitive, has_hiddensystem, has_namedattr, xattrsupp; if (nd->nd_repstat) { nfsrv_postopattr(nd, getret, &at); @@ -2949,6 +2949,7 @@ ateof: xattrsupp = false; has_hiddensystem = false; has_namedattr = false; + has_caseinsensitive = false; clone_blksize = 0; if (nvp != NULL) { supports_nfsv4acls = @@ -2978,6 +2979,11 @@ ateof: &pathval) != 0) pathval = 0; clone_blksize = pathval; + if (VOP_PATHCONF(nvp, + _PC_CASE_INSENSITIVE, + &pathval) != 0) + pathval = 0; + has_caseinsensitive = pathval > 0; NFSVOPUNLOCK(nvp); } else supports_nfsv4acls = 0; @@ -2999,7 +3005,7 @@ ateof: supports_nfsv4acls, at_root, mounted_on_fileno, xattrsupp, has_hiddensystem, has_namedattr, - clone_blksize); + clone_blksize, has_caseinsensitive); } else { dirlen += nfsvno_fillattr(nd, new_mp, nvp, nvap, &nfh, r, &attrbits, @@ -3007,7 +3013,7 @@ ateof: supports_nfsv4acls, at_root, mounted_on_fileno, xattrsupp, has_hiddensystem, has_namedattr, - clone_blksize); + clone_blksize, has_caseinsensitive); } if (nvp != NULL) vrele(nvp); @@ -3193,7 +3199,8 @@ nfsv4_sattr(struct nfsrv_descript *nd, vnode_t vp, struct nfsvattr *nvap, bitpos = NFSATTRBIT_MAX; } else { bitpos = 0; - if (NFSISSET_ATTRBIT(attrbitp, NFSATTRBIT_HIDDEN) || + if (NFSISSET_ATTRBIT(attrbitp, NFSATTRBIT_ARCHIVE) || + NFSISSET_ATTRBIT(attrbitp, NFSATTRBIT_HIDDEN) || NFSISSET_ATTRBIT(attrbitp, NFSATTRBIT_SYSTEM)) nvap->na_flags = 0; } @@ -3226,9 +3233,11 @@ nfsv4_sattr(struct nfsrv_descript *nd, vnode_t vp, struct nfsvattr *nvap, attrsum += aclsize; break; case NFSATTRBIT_ARCHIVE: - NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED); - if (!nd->nd_repstat) - nd->nd_repstat = NFSERR_ATTRNOTSUPP; + NFSM_DISSECT(tl, uint32_t *, NFSX_UNSIGNED); + if (nd->nd_repstat == 0) { + if (*tl == newnfs_true) + nvap->na_flags |= UF_ARCHIVE; + } attrsum += NFSX_UNSIGNED; break; case NFSATTRBIT_HIDDEN: @@ -3478,11 +3487,6 @@ nfsd_excred(struct nfsrv_descript *nd, struct nfsexstuff *exp, (nd->nd_flag & ND_AUTHNONE) != 0) { nd->nd_cred->cr_uid = credanon->cr_uid; nd->nd_cred->cr_gid = credanon->cr_gid; - /* - * 'credanon' is already a 'struct ucred' that was built - * internally with calls to crsetgroups_and_egid(), so - * we don't need a fallback here. - */ crsetgroups(nd->nd_cred, credanon->cr_ngroups, credanon->cr_groups); } else if ((nd->nd_flag & ND_GSS) == 0) { @@ -6407,7 +6411,7 @@ nfsrv_setacldsdorpc(fhandle_t *fhp, struct ucred *cred, NFSPROC_T *p, * the same type (VREG). */ nfsv4_fillattr(nd, NULL, vp, aclp, NULL, NULL, 0, &attrbits, NULL, - NULL, 0, 0, 0, 0, 0, NULL, false, false, false, 0); + NULL, 0, 0, 0, 0, 0, NULL, false, false, false, 0, NULL, false); error = newnfs_request(nd, nmp, NULL, &nmp->nm_sockreq, NULL, p, cred, NFS_PROG, NFS_VER4, NULL, 1, NULL, NULL); if (error != 0) { diff --git a/sys/fs/nfsserver/nfs_nfsdserv.c b/sys/fs/nfsserver/nfs_nfsdserv.c index a881968b03be..394b63c2ab07 100644 --- a/sys/fs/nfsserver/nfs_nfsdserv.c +++ b/sys/fs/nfsserver/nfs_nfsdserv.c @@ -252,7 +252,7 @@ nfsrvd_getattr(struct nfsrv_descript *nd, int isdgram, struct thread *p = curthread; size_t atsiz; long pathval; - bool has_hiddensystem, has_namedattr, xattrsupp; + bool has_caseinsensitive, has_hiddensystem, has_namedattr, xattrsupp; uint32_t clone_blksize; if (nd->nd_repstat) @@ -336,13 +336,17 @@ nfsrvd_getattr(struct nfsrv_descript *nd, int isdgram, &pathval) != 0) pathval = 0; clone_blksize = pathval; + if (VOP_PATHCONF(vp, _PC_CASE_INSENSITIVE, + &pathval) != 0) + pathval = 0; + has_caseinsensitive = pathval > 0; mp = vp->v_mount; if (nfsrv_enable_crossmntpt != 0 && vp->v_type == VDIR && (vp->v_vflag & VV_ROOT) != 0 && vp != rootvnode) { tvp = mp->mnt_vnodecovered; - VREF(tvp); + vref(tvp); at_root = 1; } else at_root = 0; @@ -371,7 +375,8 @@ nfsrvd_getattr(struct nfsrv_descript *nd, int isdgram, isdgram, 1, supports_nfsv4acls, at_root, mounted_on_fileno, xattrsupp, has_hiddensystem, - has_namedattr, clone_blksize); + has_namedattr, clone_blksize, + has_caseinsensitive); vfs_unbusy(mp); } vrele(vp); @@ -436,6 +441,7 @@ nfsrvd_setattr(struct nfsrv_descript *nd, __unused int isdgram, /* For NFSv4, only va_uid and va_flags is used from nva2. */ NFSSETBIT_ATTRBIT(&retbits, NFSATTRBIT_OWNER); + NFSSETBIT_ATTRBIT(&retbits, NFSATTRBIT_ARCHIVE); NFSSETBIT_ATTRBIT(&retbits, NFSATTRBIT_HIDDEN); NFSSETBIT_ATTRBIT(&retbits, NFSATTRBIT_SYSTEM); preat_ret = nfsvno_getattr(vp, &nva2, nd, p, 1, &retbits); @@ -569,8 +575,15 @@ nfsrvd_setattr(struct nfsrv_descript *nd, __unused int isdgram, } } if (!nd->nd_repstat && - (NFSISSET_ATTRBIT(&attrbits, NFSATTRBIT_HIDDEN) || + (NFSISSET_ATTRBIT(&attrbits, NFSATTRBIT_ARCHIVE) || + NFSISSET_ATTRBIT(&attrbits, NFSATTRBIT_HIDDEN) || NFSISSET_ATTRBIT(&attrbits, NFSATTRBIT_SYSTEM))) { + if (NFSISSET_ATTRBIT(&attrbits, NFSATTRBIT_ARCHIVE)) { + if ((nva.na_flags & UF_ARCHIVE) != 0) + oldflags |= UF_ARCHIVE; + else + oldflags &= ~UF_ARCHIVE; + } if (NFSISSET_ATTRBIT(&attrbits, NFSATTRBIT_HIDDEN)) { if ((nva.na_flags & UF_HIDDEN) != 0) oldflags |= UF_HIDDEN; @@ -588,6 +601,8 @@ nfsrvd_setattr(struct nfsrv_descript *nd, __unused int isdgram, nd->nd_repstat = nfsvno_setattr(vp, &nva2, nd->nd_cred, p, exp); if (!nd->nd_repstat) { + if (NFSISSET_ATTRBIT(&attrbits, NFSATTRBIT_ARCHIVE)) + NFSSETBIT_ATTRBIT(&retbits, NFSATTRBIT_ARCHIVE); if (NFSISSET_ATTRBIT(&attrbits, NFSATTRBIT_HIDDEN)) NFSSETBIT_ATTRBIT(&retbits, NFSATTRBIT_HIDDEN); if (NFSISSET_ATTRBIT(&attrbits, NFSATTRBIT_SYSTEM)) @@ -1766,7 +1781,7 @@ nfsrvd_rename(struct nfsrv_descript *nd, int isdgram, /* If this is the same file handle, just VREF() the vnode. */ if (!NFSBCMP(tfh.nfsrvfh_data, &fh, NFSX_MYFH)) { - VREF(dp); + vref(dp); tdp = dp; tnes = *exp; tdirfor_ret = nfsvno_getattr(tdp, &tdirfor, nd, p, 1, @@ -5128,6 +5143,11 @@ nfsrvd_layoutcommit(struct nfsrv_descript *nd, __unused int isdgram, NFSM_DISSECT(tl, uint32_t *, 2 * NFSX_UNSIGNED); layouttype = fxdr_unsigned(int, *tl++); maxcnt = fxdr_unsigned(int, *tl); + /* There is no limit in the RFC, so use 1000 as a sanity limit. */ + if (maxcnt < 0 || maxcnt > 1000) { + error = NFSERR_BADXDR; + goto nfsmout; + } if (maxcnt > 0) { layp = malloc(maxcnt + 1, M_TEMP, M_WAITOK); error = nfsrv_mtostr(nd, layp, maxcnt); diff --git a/sys/fs/nfsserver/nfs_nfsdsocket.c b/sys/fs/nfsserver/nfs_nfsdsocket.c index 636c4735a131..201f3b74b946 100644 --- a/sys/fs/nfsserver/nfs_nfsdsocket.c +++ b/sys/fs/nfsserver/nfs_nfsdsocket.c @@ -1110,7 +1110,7 @@ nfsrvd_compound(struct nfsrv_descript *nd, int isdgram, u_char *tag, if (vp != savevp) { if (savevp) vrele(savevp); - VREF(vp); + vref(vp); savevp = vp; savevpnes = vpnes; save_fsid = cur_fsid; @@ -1155,7 +1155,7 @@ nfsrvd_compound(struct nfsrv_descript *nd, int isdgram, u_char *tag, nfsvno_testexp(nd, &savevpnes); if (nd->nd_repstat == 0) { - VREF(savevp); + vref(savevp); vrele(vp); vp = savevp; vpnes = savevpnes; @@ -1235,7 +1235,7 @@ tryagain: break; } } - VREF(vp); + vref(vp); if (nfsv4_opflag[op].modifyfs) vn_start_write(vp, &temp_mp, V_WAIT); error = (*(nfsrv4_ops1[op]))(nd, isdgram, vp, @@ -1279,8 +1279,8 @@ tryagain: if (nfsv4_opflag[op].modifyfs) vn_start_write(savevp, &temp_mp, V_WAIT); if (NFSVOPLOCK(savevp, LK_EXCLUSIVE) == 0) { - VREF(vp); - VREF(savevp); + vref(vp); + vref(savevp); error = (*(nfsrv4_ops2[op]))(nd, isdgram, savevp, vp, &savevpnes, &vpnes); } else @@ -1301,7 +1301,7 @@ tryagain: lktype = LK_SHARED; } if (NFSVOPLOCK(vp, lktype) == 0) - VREF(vp); + vref(vp); else nd->nd_repstat = NFSERR_PERM; } else { diff --git a/sys/fs/nullfs/null.h b/sys/fs/nullfs/null.h index 0a93878c859f..7bfdc20a3f67 100644 --- a/sys/fs/nullfs/null.h +++ b/sys/fs/nullfs/null.h @@ -35,7 +35,11 @@ #ifndef FS_NULL_H #define FS_NULL_H -#define NULLM_CACHE 0x0001 +#include <sys/ck.h> +#include <vm/uma.h> + +#define NULLM_CACHE 0x0001 +#define NULLM_NOUNPBYPASS 0x0002 struct null_mount { struct mount *nullm_vfs; @@ -50,7 +54,7 @@ struct null_mount { * A cache of vnode references */ struct null_node { - LIST_ENTRY(null_node) null_hash; /* Hash list */ + CK_SLIST_ENTRY(null_node) null_hash; /* Hash list */ struct vnode *null_lowervp; /* VREFed once */ struct vnode *null_vnode; /* Back pointer */ u_int null_flags; @@ -61,6 +65,7 @@ struct null_node { #define MOUNTTONULLMOUNT(mp) ((struct null_mount *)((mp)->mnt_data)) #define VTONULL(vp) ((struct null_node *)(vp)->v_data) +#define VTONULL_SMR(vp) ((struct null_node *)vn_load_v_data_smr(vp)) #define NULLTOV(xp) ((xp)->null_vnode) int nullfs_init(struct vfsconf *vfsp); @@ -78,10 +83,18 @@ struct vnode *null_checkvp(struct vnode *vp, char *fil, int lno); #endif extern struct vop_vector null_vnodeops; +extern struct vop_vector null_vnodeops_no_unp_bypass; -#ifdef MALLOC_DECLARE -MALLOC_DECLARE(M_NULLFSNODE); -#endif +static inline bool +null_is_nullfs_vnode(struct vnode *vp) +{ + const struct vop_vector *op; + + op = vp->v_op; + return (op == &null_vnodeops || op == &null_vnodeops_no_unp_bypass); +} + +extern uma_zone_t null_node_zone; #ifdef NULLFS_DEBUG #define NULLFSDEBUG(format, args...) printf(format ,## args) diff --git a/sys/fs/nullfs/null_subr.c b/sys/fs/nullfs/null_subr.c index 7dcc83880bb9..a843ae44f121 100644 --- a/sys/fs/nullfs/null_subr.c +++ b/sys/fs/nullfs/null_subr.c @@ -36,14 +36,19 @@ #include <sys/systm.h> #include <sys/kernel.h> #include <sys/lock.h> -#include <sys/rwlock.h> #include <sys/malloc.h> #include <sys/mount.h> #include <sys/proc.h> +#include <sys/rwlock.h> +#include <sys/smr.h> #include <sys/vnode.h> #include <fs/nullfs/null.h> +#include <vm/uma.h> + +VFS_SMR_DECLARE; + /* * Null layer cache: * Each cache entry holds a reference to the lower vnode @@ -54,12 +59,12 @@ #define NULL_NHASH(vp) (&null_node_hashtbl[vfs_hash_index(vp) & null_hash_mask]) -static LIST_HEAD(null_node_hashhead, null_node) *null_node_hashtbl; +static CK_SLIST_HEAD(null_node_hashhead, null_node) *null_node_hashtbl; static struct rwlock null_hash_lock; static u_long null_hash_mask; static MALLOC_DEFINE(M_NULLFSHASH, "nullfs_hash", "NULLFS hash table"); -MALLOC_DEFINE(M_NULLFSNODE, "nullfs_node", "NULLFS vnode private part"); +uma_zone_t __read_mostly null_node_zone; static void null_hashins(struct mount *, struct null_node *); @@ -73,6 +78,10 @@ nullfs_init(struct vfsconf *vfsp) null_node_hashtbl = hashinit(desiredvnodes, M_NULLFSHASH, &null_hash_mask); rw_init(&null_hash_lock, "nullhs"); + null_node_zone = uma_zcreate("nullfs node", sizeof(struct null_node), + NULL, NULL, NULL, NULL, 0, UMA_ZONE_ZINIT); + VFS_SMR_ZONE_SET(null_node_zone); + return (0); } @@ -80,6 +89,7 @@ int nullfs_uninit(struct vfsconf *vfsp) { + uma_zdestroy(null_node_zone); rw_destroy(&null_hash_lock); hashdestroy(null_node_hashtbl, M_NULLFSHASH, null_hash_mask); return (0); @@ -96,7 +106,7 @@ null_hashget_locked(struct mount *mp, struct vnode *lowervp) struct null_node *a; struct vnode *vp; - ASSERT_VOP_LOCKED(lowervp, "null_hashget"); + ASSERT_VOP_LOCKED(lowervp, __func__); rw_assert(&null_hash_lock, RA_LOCKED); /* @@ -106,37 +116,57 @@ null_hashget_locked(struct mount *mp, struct vnode *lowervp) * reference count (but NOT the lower vnode's VREF counter). */ hd = NULL_NHASH(lowervp); - LIST_FOREACH(a, hd, null_hash) { - if (a->null_lowervp == lowervp && NULLTOV(a)->v_mount == mp) { - /* - * Since we have the lower node locked the nullfs - * node can not be in the process of recycling. If - * it had been recycled before we grabed the lower - * lock it would not have been found on the hash. - */ - vp = NULLTOV(a); - vref(vp); - return (vp); - } + CK_SLIST_FOREACH(a, hd, null_hash) { + if (a->null_lowervp != lowervp) + continue; + /* + * Since we have the lower node locked the nullfs + * node can not be in the process of recycling. If + * it had been recycled before we grabed the lower + * lock it would not have been found on the hash. + */ + vp = NULLTOV(a); + VNPASS(!VN_IS_DOOMED(vp), vp); + if (vp->v_mount != mp) + continue; + vref(vp); + return (vp); } - return (NULLVP); + return (NULL); } struct vnode * null_hashget(struct mount *mp, struct vnode *lowervp) { struct null_node_hashhead *hd; + struct null_node *a; struct vnode *vp; + enum vgetstate vs; - hd = NULL_NHASH(lowervp); - if (LIST_EMPTY(hd)) - return (NULLVP); + ASSERT_VOP_LOCKED(lowervp, __func__); + rw_assert(&null_hash_lock, RA_UNLOCKED); - rw_rlock(&null_hash_lock); - vp = null_hashget_locked(mp, lowervp); - rw_runlock(&null_hash_lock); - - return (vp); + vfs_smr_enter(); + hd = NULL_NHASH(lowervp); + CK_SLIST_FOREACH(a, hd, null_hash) { + if (a->null_lowervp != lowervp) + continue; + /* + * See null_hashget_locked as to why the nullfs vnode can't be + * doomed here. + */ + vp = NULLTOV(a); + VNPASS(!VN_IS_DOOMED(vp), vp); + if (vp->v_mount != mp) + continue; + vs = vget_prep_smr(vp); + vfs_smr_exit(); + VNPASS(vs != VGET_NONE, vp); + vget_finish_ref(vp, vs); + return (vp); + } + vfs_smr_exit(); + return (NULL); } static void @@ -151,7 +181,7 @@ null_hashins(struct mount *mp, struct null_node *xp) hd = NULL_NHASH(xp->null_lowervp); #ifdef INVARIANTS - LIST_FOREACH(oxp, hd, null_hash) { + CK_SLIST_FOREACH(oxp, hd, null_hash) { if (oxp->null_lowervp == xp->null_lowervp && NULLTOV(oxp)->v_mount == mp) { VNASSERT(0, NULLTOV(oxp), @@ -159,7 +189,7 @@ null_hashins(struct mount *mp, struct null_node *xp) } } #endif - LIST_INSERT_HEAD(hd, xp, null_hash); + CK_SLIST_INSERT_HEAD(hd, xp, null_hash); } static void @@ -174,7 +204,7 @@ null_destroy_proto(struct vnode *vp, void *xp) VI_UNLOCK(vp); vgone(vp); vput(vp); - free(xp, M_NULLFSNODE); + uma_zfree_smr(null_node_zone, xp); } /* @@ -208,12 +238,14 @@ null_nodeget(struct mount *mp, struct vnode *lowervp, struct vnode **vpp) * Note that duplicate can only appear in hash if the lowervp is * locked LK_SHARED. */ - xp = malloc(sizeof(struct null_node), M_NULLFSNODE, M_WAITOK); + xp = uma_zalloc_smr(null_node_zone, M_WAITOK); - error = getnewvnode("nullfs", mp, &null_vnodeops, &vp); + error = getnewvnode("nullfs", mp, (MOUNTTONULLMOUNT(mp)->nullm_flags & + NULLM_NOUNPBYPASS) != 0 ? &null_vnodeops_no_unp_bypass : + &null_vnodeops, &vp); if (error) { vput(lowervp); - free(xp, M_NULLFSNODE); + uma_zfree_smr(null_node_zone, xp); return (error); } @@ -261,8 +293,8 @@ null_nodeget(struct mount *mp, struct vnode *lowervp, struct vnode **vpp) return (error); } - null_hashins(mp, xp); vn_set_state(vp, VSTATE_CONSTRUCTED); + null_hashins(mp, xp); rw_wunlock(&null_hash_lock); *vpp = vp; @@ -275,9 +307,11 @@ null_nodeget(struct mount *mp, struct vnode *lowervp, struct vnode **vpp) void null_hashrem(struct null_node *xp) { + struct null_node_hashhead *hd; + hd = NULL_NHASH(xp->null_lowervp); rw_wlock(&null_hash_lock); - LIST_REMOVE(xp, null_hash); + CK_SLIST_REMOVE(hd, xp, null_node, null_hash); rw_wunlock(&null_hash_lock); } @@ -298,7 +332,7 @@ null_checkvp(struct vnode *vp, char *fil, int lno) panic("null_checkvp"); } #endif - if (a->null_lowervp == NULLVP) { + if (a->null_lowervp == NULL) { /* Should never happen */ panic("null_checkvp %p", vp); } diff --git a/sys/fs/nullfs/null_vfsops.c b/sys/fs/nullfs/null_vfsops.c index 4cddf24a5745..170a3dd51cd8 100644 --- a/sys/fs/nullfs/null_vfsops.c +++ b/sys/fs/nullfs/null_vfsops.c @@ -85,6 +85,10 @@ nullfs_mount(struct mount *mp) char *target; int error, len; bool isvnunlocked; + static const char cache_opt_name[] = "cache"; + static const char nocache_opt_name[] = "nocache"; + static const char unixbypass_opt_name[] = "unixbypass"; + static const char nounixbypass_opt_name[] = "nounixbypass"; NULLFSDEBUG("nullfs_mount(mp = %p)\n", (void *)mp); @@ -116,7 +120,7 @@ nullfs_mount(struct mount *mp) /* * Unlock lower node to avoid possible deadlock. */ - if (mp->mnt_vnodecovered->v_op == &null_vnodeops && + if (null_is_nullfs_vnode(mp->mnt_vnodecovered) && VOP_ISLOCKED(mp->mnt_vnodecovered) == LK_EXCLUSIVE) { VOP_UNLOCK(mp->mnt_vnodecovered); isvnunlocked = true; @@ -150,7 +154,7 @@ nullfs_mount(struct mount *mp) /* * Check multi null mount to avoid `lock against myself' panic. */ - if (mp->mnt_vnodecovered->v_op == &null_vnodeops) { + if (null_is_nullfs_vnode(mp->mnt_vnodecovered)) { nn = VTONULL(mp->mnt_vnodecovered); if (nn == NULL || lowerrootvp == nn->null_lowervp) { NULLFSDEBUG("nullfs_mount: multi null mount?\n"); @@ -205,9 +209,10 @@ nullfs_mount(struct mount *mp) MNT_IUNLOCK(mp); } - if (vfs_getopt(mp->mnt_optnew, "cache", NULL, NULL) == 0) { + if (vfs_getopt(mp->mnt_optnew, cache_opt_name, NULL, NULL) == 0) { xmp->nullm_flags |= NULLM_CACHE; - } else if (vfs_getopt(mp->mnt_optnew, "nocache", NULL, NULL) == 0) { + } else if (vfs_getopt(mp->mnt_optnew, nocache_opt_name, NULL, + NULL) == 0) { ; } else if (null_cache_vnodes && (xmp->nullm_vfs->mnt_kern_flag & MNTK_NULL_NOCACHE) == 0) { @@ -219,6 +224,13 @@ nullfs_mount(struct mount *mp) &xmp->notify_node); } + if (vfs_getopt(mp->mnt_optnew, unixbypass_opt_name, NULL, NULL) == 0) { + ; + } else if (vfs_getopt(mp->mnt_optnew, nounixbypass_opt_name, NULL, + NULL) == 0) { + xmp->nullm_flags |= NULLM_NOUNPBYPASS; + } + if (lowerrootvp == mp->mnt_vnodecovered) { vn_lock(lowerrootvp, LK_EXCLUSIVE | LK_RETRY | LK_CANRECURSE); lowerrootvp->v_vflag |= VV_CROSSLOCK; diff --git a/sys/fs/nullfs/null_vnops.c b/sys/fs/nullfs/null_vnops.c index 74c1a8f3acb6..d4baabeb40ab 100644 --- a/sys/fs/nullfs/null_vnops.c +++ b/sys/fs/nullfs/null_vnops.c @@ -174,6 +174,8 @@ #include <sys/mount.h> #include <sys/mutex.h> #include <sys/namei.h> +#include <sys/proc.h> +#include <sys/smr.h> #include <sys/sysctl.h> #include <sys/vnode.h> #include <sys/stat.h> @@ -185,6 +187,8 @@ #include <vm/vm_object.h> #include <vm/vnode_pager.h> +VFS_SMR_DECLARE; + static int null_bug_bypass = 0; /* for debugging: enables bypass printf'ing */ SYSCTL_INT(_debug, OID_AUTO, nullfs_bug_bypass, CTLFLAG_RW, &null_bug_bypass, 0, ""); @@ -273,9 +277,9 @@ null_bypass(struct vop_generic_args *ap) * are of our type. Check for and don't map any * that aren't. (We must always map first vp or vclean fails.) */ - if (i != 0 && (*this_vp_p == NULLVP || - (*this_vp_p)->v_op != &null_vnodeops)) { - old_vps[i] = NULLVP; + if (i != 0 && (*this_vp_p == NULL || + !null_is_nullfs_vnode(*this_vp_p))) { + old_vps[i] = NULL; } else { old_vps[i] = *this_vp_p; *(vps_p[i]) = NULLVPTOLOWERVP(*this_vp_p); @@ -306,7 +310,7 @@ null_bypass(struct vop_generic_args *ap) * with the modified argument structure. */ if (vps_p[0] != NULL && *vps_p[0] != NULL) { - error = VCALL(ap); + error = ap->a_desc->vdesc_call(ap); } else { printf("null_bypass: no map for %s\n", descp->vdesc_name); error = EINVAL; @@ -336,7 +340,7 @@ null_bypass(struct vop_generic_args *ap) * must move lock ownership from lower to * upper (reclaimed) vnode. */ - if (lvp != NULLVP) { + if (lvp != NULL) { null_copy_inotify(old_vps[i], lvp, VIRF_INOTIFY); null_copy_inotify(old_vps[i], lvp, @@ -494,7 +498,7 @@ null_lookup(struct vop_lookup_args *ap) if ((error == 0 || error == EJUSTRETURN) && lvp != NULL) { if (ldvp == lvp) { *ap->a_vpp = dvp; - VREF(dvp); + vref(dvp); vrele(lvp); } else { error = null_nodeget(mp, lvp, &vp); @@ -665,7 +669,7 @@ null_remove(struct vop_remove_args *ap) vp = ap->a_vp; if (vrefcnt(vp) > 1) { lvp = NULLVPTOLOWERVP(vp); - VREF(lvp); + vref(lvp); vreleit = 1; } else vreleit = 0; @@ -768,83 +772,111 @@ null_rmdir(struct vop_rmdir_args *ap) } /* - * We need to process our own vnode lock and then clear the - * interlock flag as it applies only to our vnode, not the - * vnodes below us on the stack. + * We need to process our own vnode lock and then clear the interlock flag as + * it applies only to our vnode, not the vnodes below us on the stack. + * + * We have to hold the vnode here to solve a potential reclaim race. If we're + * forcibly vgone'd while we still have refs, a thread could be sleeping inside + * the lowervp's vop_lock routine. When we vgone we will drop our last ref to + * the lowervp, which would allow it to be reclaimed. The lowervp could then + * be recycled, in which case it is not legal to be sleeping in its VOP. We + * prevent it from being recycled by holding the vnode here. */ +static struct vnode * +null_lock_prep_with_smr(struct vop_lock1_args *ap) +{ + struct null_node *nn; + struct vnode *lvp; + + lvp = NULL; + + vfs_smr_enter(); + + nn = VTONULL_SMR(ap->a_vp); + if (__predict_true(nn != NULL)) { + lvp = nn->null_lowervp; + if (lvp != NULL && !vhold_smr(lvp)) + lvp = NULL; + } + + vfs_smr_exit(); + return (lvp); +} + +static struct vnode * +null_lock_prep_with_interlock(struct vop_lock1_args *ap) +{ + struct null_node *nn; + struct vnode *lvp; + + ASSERT_VI_LOCKED(ap->a_vp, __func__); + + ap->a_flags &= ~LK_INTERLOCK; + + lvp = NULL; + + nn = VTONULL(ap->a_vp); + if (__predict_true(nn != NULL)) { + lvp = nn->null_lowervp; + if (lvp != NULL) + vholdnz(lvp); + } + VI_UNLOCK(ap->a_vp); + return (lvp); +} + static int null_lock(struct vop_lock1_args *ap) { - struct vnode *vp = ap->a_vp; - int flags; - struct null_node *nn; struct vnode *lvp; - int error; + int error, flags; - if ((ap->a_flags & LK_INTERLOCK) == 0) - VI_LOCK(vp); - else - ap->a_flags &= ~LK_INTERLOCK; - flags = ap->a_flags; - nn = VTONULL(vp); + if (__predict_true((ap->a_flags & LK_INTERLOCK) == 0)) { + lvp = null_lock_prep_with_smr(ap); + if (__predict_false(lvp == NULL)) { + VI_LOCK(ap->a_vp); + lvp = null_lock_prep_with_interlock(ap); + } + } else { + lvp = null_lock_prep_with_interlock(ap); + } + + ASSERT_VI_UNLOCKED(ap->a_vp, __func__); + + if (__predict_false(lvp == NULL)) + return (vop_stdlock(ap)); + + VNPASS(lvp->v_holdcnt > 0, lvp); + error = VOP_LOCK(lvp, ap->a_flags); /* - * If we're still active we must ask the lower layer to - * lock as ffs has special lock considerations in its - * vop lock. + * We might have slept to get the lock and someone might have + * clean our vnode already, switching vnode lock from one in + * lowervp to v_lock in our own vnode structure. Handle this + * case by reacquiring correct lock in requested mode. */ - if (nn != NULL && (lvp = NULLVPTOLOWERVP(vp)) != NULL) { - /* - * We have to hold the vnode here to solve a potential - * reclaim race. If we're forcibly vgone'd while we - * still have refs, a thread could be sleeping inside - * the lowervp's vop_lock routine. When we vgone we will - * drop our last ref to the lowervp, which would allow it - * to be reclaimed. The lowervp could then be recycled, - * in which case it is not legal to be sleeping in its VOP. - * We prevent it from being recycled by holding the vnode - * here. - */ - vholdnz(lvp); - VI_UNLOCK(vp); - error = VOP_LOCK(lvp, flags); - - /* - * We might have slept to get the lock and someone might have - * clean our vnode already, switching vnode lock from one in - * lowervp to v_lock in our own vnode structure. Handle this - * case by reacquiring correct lock in requested mode. - */ - if (VTONULL(vp) == NULL && error == 0) { - ap->a_flags &= ~LK_TYPE_MASK; - switch (flags & LK_TYPE_MASK) { - case LK_SHARED: - ap->a_flags |= LK_SHARED; - break; - case LK_UPGRADE: - case LK_EXCLUSIVE: - ap->a_flags |= LK_EXCLUSIVE; - break; - default: - panic("Unsupported lock request %d\n", - ap->a_flags); - } - VOP_UNLOCK(lvp); - error = vop_stdlock(ap); + if (VTONULL(ap->a_vp) == NULL && error == 0) { + VOP_UNLOCK(lvp); + + flags = ap->a_flags; + ap->a_flags &= ~LK_TYPE_MASK; + switch (flags & LK_TYPE_MASK) { + case LK_SHARED: + ap->a_flags |= LK_SHARED; + break; + case LK_UPGRADE: + case LK_EXCLUSIVE: + ap->a_flags |= LK_EXCLUSIVE; + break; + default: + panic("Unsupported lock request %d\n", + flags); } - vdrop(lvp); - } else { - VI_UNLOCK(vp); error = vop_stdlock(ap); } - + vdrop(lvp); return (error); } -/* - * We need to process our own vnode unlock and then clear the - * interlock flag as it applies only to our vnode, not the - * vnodes below us on the stack. - */ static int null_unlock(struct vop_unlock_args *ap) { @@ -853,11 +885,20 @@ null_unlock(struct vop_unlock_args *ap) struct vnode *lvp; int error; + /* + * Contrary to null_lock, we don't need to hold the vnode around + * unlock. + * + * We hold the lock, which means we can't be racing against vgone. + * + * At the same time VOP_UNLOCK promises to not touch anything after + * it finishes unlock, just like we don't. + * + * vop_stdunlock for a doomed vnode matches doomed locking in null_lock. + */ nn = VTONULL(vp); if (nn != NULL && (lvp = NULLVPTOLOWERVP(vp)) != NULL) { - vholdnz(lvp); error = VOP_UNLOCK(lvp); - vdrop(lvp); } else { error = vop_stdunlock(ap); } @@ -961,7 +1002,7 @@ null_reclaim(struct vop_reclaim_args *ap) vunref(lowervp); else vput(lowervp); - free(xp, M_NULLFSNODE); + uma_zfree_smr(null_node_zone, xp); return (0); } @@ -1215,3 +1256,11 @@ struct vop_vector null_vnodeops = { .vop_copy_file_range = VOP_PANIC, }; VFS_VOP_VECTOR_REGISTER(null_vnodeops); + +struct vop_vector null_vnodeops_no_unp_bypass = { + .vop_default = &null_vnodeops, + .vop_unp_bind = vop_stdunp_bind, + .vop_unp_connect = vop_stdunp_connect, + .vop_unp_detach = vop_stdunp_detach, +}; +VFS_VOP_VECTOR_REGISTER(null_vnodeops_no_unp_bypass); diff --git a/sys/fs/p9fs/p9_transport.c b/sys/fs/p9fs/p9_transport.c index c82d81fedcd7..25eee984265c 100644 --- a/sys/fs/p9fs/p9_transport.c +++ b/sys/fs/p9fs/p9_transport.c @@ -34,9 +34,8 @@ TAILQ_HEAD(, p9_trans_module) transports; static void -p9_transport_init(void) +p9_transport_init(void *dummy __unused) { - TAILQ_INIT(&transports); } diff --git a/sys/fs/p9fs/p9fs_vfsops.c b/sys/fs/p9fs/p9fs_vfsops.c index e0e91e7e1709..953e6eda547a 100644 --- a/sys/fs/p9fs/p9fs_vfsops.c +++ b/sys/fs/p9fs/p9fs_vfsops.c @@ -287,7 +287,7 @@ p9fs_vget_common(struct mount *mp, struct p9fs_node *np, int flags, node->flags |= P9FS_NODE_DELETED; vput(vp); - *vpp = NULLVP; + *vpp = NULL; vp = NULL; } else { *vpp = vp; @@ -308,7 +308,7 @@ p9fs_vget_common(struct mount *mp, struct p9fs_node *np, int flags, /* Allocate a new vnode. */ if ((error = getnewvnode("p9fs", mp, &p9fs_vnops, &vp)) != 0) { - *vpp = NULLVP; + *vpp = NULL; P9_DEBUG(ERROR, "%s: getnewvnode failed: %d\n", __func__, error); return (error); } @@ -397,7 +397,7 @@ out: vput(vp); } - *vpp = NULLVP; + *vpp = NULL; return (error); } @@ -525,14 +525,14 @@ p9fs_root(struct mount *mp, int lkflags, struct vnode **vpp) if (vfid == NULL && clnt->trans_status == P9FS_BEGIN_DISCONNECT) vfid = vmp->p9fs_session.mnt_fid; else { - *vpp = NULLVP; + *vpp = NULL; return (error); } } error = p9fs_vget_common(mp, np, lkflags, np, vfid, vpp, NULL); if (error != 0) { - *vpp = NULLVP; + *vpp = NULL; return (error); } np->v_node = *vpp; diff --git a/sys/fs/p9fs/p9fs_vnops.c b/sys/fs/p9fs/p9fs_vnops.c index acb73973d93b..2ed1be82b57f 100644 --- a/sys/fs/p9fs/p9fs_vnops.c +++ b/sys/fs/p9fs/p9fs_vnops.c @@ -233,7 +233,7 @@ p9fs_lookup(struct vop_lookup_args *ap) dnp = P9FS_VTON(dvp); error = 0; flags = cnp->cn_flags; - *vpp = NULLVP; + *vpp = NULL; if (dnp == NULL) return (ENOENT); @@ -329,7 +329,7 @@ p9fs_lookup(struct vop_lookup_args *ap) else vrele(vp); - *vpp = NULLVP; + *vpp = NULL; } else if (error == ENOENT) { if (VN_IS_DOOMED(dvp)) goto out; @@ -341,7 +341,7 @@ p9fs_lookup(struct vop_lookup_args *ap) } /* Reset values */ error = 0; - vp = NULLVP; + vp = NULL; tmpchr = cnp->cn_nameptr[cnp->cn_namelen]; cnp->cn_nameptr[cnp->cn_namelen] = '\0'; diff --git a/sys/fs/procfs/procfs_status.c b/sys/fs/procfs/procfs_status.c index 38070e0946bb..49c084d02ff8 100644 --- a/sys/fs/procfs/procfs_status.c +++ b/sys/fs/procfs/procfs_status.c @@ -141,13 +141,9 @@ procfs_doprocstatus(PFS_FILL_ARGS) (u_long)cr->cr_uid, (u_long)cr->cr_ruid, (u_long)cr->cr_rgid); - - /* egid (cr->cr_svgid) is equal to cr_ngroups[0] - see also getegid(2) in /sys/kern/kern_prot.c */ - - for (i = 0; i < cr->cr_ngroups; i++) { + sbuf_printf(sb, ",%lu", (u_long)cr->cr_gid); + for (i = 0; i < cr->cr_ngroups; i++) sbuf_printf(sb, ",%lu", (u_long)cr->cr_groups[i]); - } if (jailed(cr)) { mtx_lock(&cr->cr_prison->pr_mtx); diff --git a/sys/fs/pseudofs/pseudofs_vncache.c b/sys/fs/pseudofs/pseudofs_vncache.c index e58aced7f81b..4fd493f8b9d3 100644 --- a/sys/fs/pseudofs/pseudofs_vncache.c +++ b/sys/fs/pseudofs/pseudofs_vncache.c @@ -202,7 +202,7 @@ alloc: error = insmntque(*vpp, mp); if (error != 0) { free(pvd, M_PFSVNCACHE); - *vpp = NULLVP; + *vpp = NULL; return (error); } vn_set_state(*vpp, VSTATE_CONSTRUCTED); diff --git a/sys/fs/pseudofs/pseudofs_vnops.c b/sys/fs/pseudofs/pseudofs_vnops.c index 8cd092118d0e..a30b5e4f551d 100644 --- a/sys/fs/pseudofs/pseudofs_vnops.c +++ b/sys/fs/pseudofs/pseudofs_vnops.c @@ -485,7 +485,7 @@ pfs_lookup(struct vop_cachedlookup_args *va) if (namelen == 1 && pname[0] == '.') { pn = pd; *vpp = vn; - VREF(vn); + vref(vn); PFS_RETURN (0); } diff --git a/sys/fs/smbfs/smbfs_vnops.c b/sys/fs/smbfs/smbfs_vnops.c index 63b249c93771..e960d8d78b66 100644 --- a/sys/fs/smbfs/smbfs_vnops.c +++ b/sys/fs/smbfs/smbfs_vnops.c @@ -1121,13 +1121,13 @@ smbfs_lookup(struct vop_lookup_args *ap) vput(vp); else vrele(vp); - *vpp = NULLVP; + *vpp = NULL; } /* * entry is not in the cache or has been expired */ error = 0; - *vpp = NULLVP; + *vpp = NULL; scred = smbfs_malloc_scred(); smb_makescred(scred, td, cnp->cn_cred); fap = &fattr; @@ -1174,7 +1174,7 @@ smbfs_lookup(struct vop_lookup_args *ap) if (error) goto out; if (isdot) { - VREF(dvp); + vref(dvp); *vpp = dvp; goto out; } diff --git a/sys/fs/tarfs/tarfs_vfsops.c b/sys/fs/tarfs/tarfs_vfsops.c index a534b18ebf34..4cc70e4d5781 100644 --- a/sys/fs/tarfs/tarfs_vfsops.c +++ b/sys/fs/tarfs/tarfs_vfsops.c @@ -1201,7 +1201,7 @@ tarfs_vget(struct mount *mp, ino_t ino, int lkflags, struct vnode **vpp) return (0); bad: - *vpp = NULLVP; + *vpp = NULL; return (error); } @@ -1220,7 +1220,7 @@ tarfs_fhtovp(struct mount *mp, struct fid *fhp, int flags, struct vnode **vpp) error = VFS_VGET(mp, tfp->ino, LK_EXCLUSIVE, &nvp); if (error != 0) { - *vpp = NULLVP; + *vpp = NULL; return (error); } tnp = VP_TO_TARFS_NODE(nvp); @@ -1228,7 +1228,7 @@ tarfs_fhtovp(struct mount *mp, struct fid *fhp, int flags, struct vnode **vpp) tnp->gen != tfp->gen || tnp->nlink <= 0) { vput(nvp); - *vpp = NULLVP; + *vpp = NULL; return (ESTALE); } *vpp = nvp; diff --git a/sys/fs/tarfs/tarfs_vnops.c b/sys/fs/tarfs/tarfs_vnops.c index c110107bb210..70fd7a441d81 100644 --- a/sys/fs/tarfs/tarfs_vnops.c +++ b/sys/fs/tarfs/tarfs_vnops.c @@ -231,7 +231,7 @@ tarfs_lookup(struct vop_cachedlookup_args *ap) vpp = ap->a_vpp; cnp = ap->a_cnp; - *vpp = NULLVP; + *vpp = NULL; dirnode = VP_TO_TARFS_NODE(dvp); parent = dirnode->parent; tmp = dirnode->tmp; @@ -256,7 +256,7 @@ tarfs_lookup(struct vop_cachedlookup_args *ap) if (error != 0) return (error); } else if (cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.') { - VREF(dvp); + vref(dvp); *vpp = dvp; #ifdef TARFS_DEBUG } else if (dirnode == dirnode->tmp->root && @@ -585,7 +585,7 @@ tarfs_reclaim(struct vop_reclaim_args *ap) vfs_hash_remove(vp); TARFS_NODE_LOCK(tnp); - tnp->vnode = NULLVP; + tnp->vnode = NULL; vp->v_data = NULL; TARFS_NODE_UNLOCK(tnp); diff --git a/sys/fs/tmpfs/tmpfs_vnops.c b/sys/fs/tmpfs/tmpfs_vnops.c index 0f4ea2fdc28c..5082ee1ebdd0 100644 --- a/sys/fs/tmpfs/tmpfs_vnops.c +++ b/sys/fs/tmpfs/tmpfs_vnops.c @@ -98,7 +98,7 @@ tmpfs_lookup1(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp) /* Caller assumes responsibility for ensuring access (VEXEC). */ dnode = VP_TO_TMPFS_DIR(dvp); - *vpp = NULLVP; + *vpp = NULL; /* We cannot be requesting the parent directory of the root node. */ MPASS(IMPLIES(dnode->tn_type == VDIR && @@ -120,7 +120,7 @@ tmpfs_lookup1(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp) if (error != 0) goto out; } else if (cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.') { - VREF(dvp); + vref(dvp); *vpp = dvp; error = 0; } else { @@ -222,7 +222,7 @@ out: * locked. */ if (error == 0) { - MPASS(*vpp != NULLVP); + MPASS(*vpp != NULL); ASSERT_VOP_LOCKED(*vpp, __func__); } else { MPASS(*vpp == NULL); diff --git a/sys/fs/udf/osta.c b/sys/fs/udf/osta.c index f79b86993367..1a083d8c26b1 100644 --- a/sys/fs/udf/osta.c +++ b/sys/fs/udf/osta.c @@ -383,7 +383,7 @@ int UDFTransName( int maxFilenameLen; /* Translate extension, and store it in ext. */ for(index = 0; index<EXT_SIZE && - extIndex + index +1 < udfLen; index++ ) { + extIndex + index +1 < udfLen; index++) { current = udfName[extIndex + index + 1]; if (IsIllegal(current) || !UnicodeIsPrint(current)) { @@ -432,7 +432,7 @@ int UDFTransName( /* Place a translated extension at end, if found. */ if (hasExt) { newName[newIndex++] = PERIOD; - for (index = 0;index < localExtIndex ;index++ ) { + for (index = 0; index < localExtIndex; index++) { newName[newIndex++] = ext[index]; } } diff --git a/sys/fs/udf/udf_vfsops.c b/sys/fs/udf/udf_vfsops.c index c5ef1f686093..c1627285a174 100644 --- a/sys/fs/udf/udf_vfsops.c +++ b/sys/fs/udf/udf_vfsops.c @@ -736,14 +736,14 @@ udf_fhtovp(struct mount *mp, struct fid *fhp, int flags, struct vnode **vpp) ifhp = (struct ifid *)fhp; if ((error = VFS_VGET(mp, ifhp->ifid_ino, LK_EXCLUSIVE, &nvp)) != 0) { - *vpp = NULLVP; + *vpp = NULL; return (error); } np = VTON(nvp); fsize = le64toh(np->fentry->inf_len); if (fsize > OFF_MAX) { - *vpp = NULLVP; + *vpp = NULL; return (EIO); } diff --git a/sys/fs/udf/udf_vnops.c b/sys/fs/udf/udf_vnops.c index 37889241e8c3..ec61618b6e18 100644 --- a/sys/fs/udf/udf_vnops.c +++ b/sys/fs/udf/udf_vnops.c @@ -1226,7 +1226,7 @@ lookloop: if (flags & ISDOTDOT) { error = vn_vget_ino(dvp, id, lkflags, &tdp); } else if (node->hash_id == id) { - VREF(dvp); /* we want ourself, ie "." */ + vref(dvp); /* we want ourself, ie "." */ /* * When we lookup "." we still can be asked to lock it * differently. diff --git a/sys/fs/unionfs/union_subr.c b/sys/fs/unionfs/union_subr.c index edcc6716b674..b6d6db60ca3d 100644 --- a/sys/fs/unionfs/union_subr.c +++ b/sys/fs/unionfs/union_subr.c @@ -160,7 +160,7 @@ unionfs_get_cached_vnode_locked(struct vnode *lookup, struct vnode *dvp) if (VN_IS_DOOMED(vp) || ((vp->v_iflag & VI_DOINGINACT) != 0)) { VI_UNLOCK(vp); - vp = NULLVP; + vp = NULL; } else { vrefl(vp); VI_UNLOCK(vp); @@ -169,7 +169,7 @@ unionfs_get_cached_vnode_locked(struct vnode *lookup, struct vnode *dvp) } } - return (NULLVP); + return (NULL); } @@ -182,11 +182,11 @@ unionfs_get_cached_vnode(struct vnode *uvp, struct vnode *lvp, { struct vnode *vp; - vp = NULLVP; + vp = NULL; VI_LOCK(dvp); - if (uvp != NULLVP) + if (uvp != NULL) vp = unionfs_get_cached_vnode_locked(uvp, dvp); - else if (lvp != NULLVP) + else if (lvp != NULL) vp = unionfs_get_cached_vnode_locked(lvp, dvp); VI_UNLOCK(dvp); @@ -203,22 +203,22 @@ unionfs_ins_cached_vnode(struct unionfs_node *uncp, struct unionfs_node_hashhead *hd; struct vnode *vp; - vp = NULLVP; + vp = NULL; VI_LOCK(dvp); - if (uncp->un_uppervp != NULLVP) { + if (uncp->un_uppervp != NULL) { ASSERT_VOP_ELOCKED(uncp->un_uppervp, __func__); KASSERT(uncp->un_uppervp->v_type == VDIR, ("%s: v_type != VDIR", __func__)); vp = unionfs_get_cached_vnode_locked(uncp->un_uppervp, dvp); - } else if (uncp->un_lowervp != NULLVP) { + } else if (uncp->un_lowervp != NULL) { ASSERT_VOP_ELOCKED(uncp->un_lowervp, __func__); KASSERT(uncp->un_lowervp->v_type == VDIR, ("%s: v_type != VDIR", __func__)); vp = unionfs_get_cached_vnode_locked(uncp->un_lowervp, dvp); } - if (vp == NULLVP) { - hd = unionfs_get_hashhead(dvp, (uncp->un_uppervp != NULLVP ? - uncp->un_uppervp : uncp->un_lowervp)); + if (vp == NULL) { + hd = unionfs_get_hashhead(dvp, (uncp->un_uppervp != NULL ? + uncp->un_uppervp : uncp->un_lowervp)); LIST_INSERT_HEAD(hd, uncp, un_hash); } VI_UNLOCK(dvp); @@ -233,8 +233,8 @@ static void unionfs_rem_cached_vnode(struct unionfs_node *unp, struct vnode *dvp) { KASSERT(unp != NULL, ("%s: null node", __func__)); - KASSERT(dvp != NULLVP, - ("%s: null parent vnode", __func__)); + KASSERT(dvp != NULL, + ("%s: null parent vnode", __func__)); VI_LOCK(dvp); if (unp->un_hash.le_prev != NULL) { @@ -274,13 +274,13 @@ unionfs_nodeget_cleanup(struct vnode *vp, struct unionfs_node *unp) vgone(vp); vput(vp); - if (unp->un_dvp != NULLVP) + if (unp->un_dvp != NULL) vrele(unp->un_dvp); - if (unp->un_uppervp != NULLVP) { + if (unp->un_uppervp != NULL) { vput(unp->un_uppervp); - if (unp->un_lowervp != NULLVP) + if (unp->un_lowervp != NULL) vrele(unp->un_lowervp); - } else if (unp->un_lowervp != NULLVP) + } else if (unp->un_lowervp != NULL) vput(unp->un_lowervp); if (unp->un_hashtbl != NULL) hashdestroy(unp->un_hashtbl, M_UNIONFSHASH, UNIONFSHASHMASK); @@ -313,21 +313,21 @@ unionfs_nodeget(struct mount *mp, struct vnode *uppervp, ump = MOUNTTOUNIONFSMOUNT(mp); lkflags = (cnp ? cnp->cn_lkflags : 0); path = (cnp ? cnp->cn_nameptr : NULL); - *vpp = NULLVP; + *vpp = NULL; - if (uppervp == NULLVP && lowervp == NULLVP) + if (uppervp == NULL && lowervp == NULL) panic("%s: upper and lower are both null", __func__); - vt = (uppervp != NULLVP ? uppervp->v_type : lowervp->v_type); + vt = (uppervp != NULL ? uppervp->v_type : lowervp->v_type); /* If it has no ISLASTCN flag, path check is skipped. */ if (cnp && !(cnp->cn_flags & ISLASTCN)) path = NULL; /* check the cache */ - if (dvp != NULLVP && vt == VDIR) { + if (dvp != NULL && vt == VDIR) { vp = unionfs_get_cached_vnode(uppervp, lowervp, dvp); - if (vp != NULLVP) { + if (vp != NULL) { *vpp = vp; if (lkflags != 0) vn_lock(*vpp, lkflags | LK_RETRY); @@ -343,11 +343,11 @@ unionfs_nodeget(struct mount *mp, struct vnode *uppervp, free(unp, M_UNIONFSNODE); return (error); } - if (dvp != NULLVP) + if (dvp != NULL) vref(dvp); - if (uppervp != NULLVP) + if (uppervp != NULL) vref(uppervp); - if (lowervp != NULLVP) + if (lowervp != NULL) vref(lowervp); if (vt == VDIR) { @@ -361,7 +361,7 @@ unionfs_nodeget(struct mount *mp, struct vnode *uppervp, unp->un_uppervp = uppervp; unp->un_lowervp = lowervp; unp->un_dvp = dvp; - if (uppervp != NULLVP) + if (uppervp != NULL) vp->v_vnlock = uppervp->v_vnlock; else vp->v_vnlock = lowervp->v_vnlock; @@ -407,7 +407,7 @@ unionfs_nodeget(struct mount *mp, struct vnode *uppervp, * possibility of deadlock due to some other agent on the system * attempting to lock those two specific vnodes in the opposite order. */ - if (uppervp != NULLVP) + if (uppervp != NULL) vn_lock(uppervp, LK_EXCLUSIVE | LK_RETRY); else vn_lock(lowervp, LK_EXCLUSIVE | LK_RETRY); @@ -426,16 +426,16 @@ unionfs_nodeget(struct mount *mp, struct vnode *uppervp, * blocked on our vnode lock, effectively also preventing unmount * of the underlying filesystems. */ - VNASSERT(lowervp == NULLVP || !VN_IS_DOOMED(lowervp), vp, + VNASSERT(lowervp == NULL || !VN_IS_DOOMED(lowervp), vp, ("%s: doomed lowervp %p", __func__, lowervp)); - VNASSERT(uppervp == NULLVP || !VN_IS_DOOMED(uppervp), vp, + VNASSERT(uppervp == NULL || !VN_IS_DOOMED(uppervp), vp, ("%s: doomed lowervp %p", __func__, uppervp)); vn_set_state(vp, VSTATE_CONSTRUCTED); - if (dvp != NULLVP && vt == VDIR) + if (dvp != NULL && vt == VDIR) *vpp = unionfs_ins_cached_vnode(unp, dvp); - if (*vpp != NULLVP) { + if (*vpp != NULL) { unionfs_nodeget_cleanup(vp, unp); if (lkflags != 0) vn_lock(*vpp, lkflags | LK_RETRY); @@ -484,7 +484,7 @@ unionfs_noderem(struct vnode *vp) lvp = unp->un_lowervp; uvp = unp->un_uppervp; dvp = unp->un_dvp; - unlock_lvp = (uvp == NULLVP); + unlock_lvp = (uvp == NULL); /* * Lock the lower vnode in addition to the upper vnode lock in order @@ -496,7 +496,7 @@ unionfs_noderem(struct vnode *vp) * Moreover, during unmount of a non-"below" unionfs mount, the lower * root vnode will already be locked as it is the covered vnode. */ - if (uvp != NULLVP && lvp != NULLVP && (vp->v_vflag & VV_ROOT) == 0) { + if (uvp != NULL && lvp != NULL && (vp->v_vflag & VV_ROOT) == 0) { vn_lock_pair(uvp, true, LK_EXCLUSIVE, lvp, false, LK_EXCLUSIVE); unlock_lvp = true; } @@ -508,7 +508,7 @@ unionfs_noderem(struct vnode *vp) * prevent faults in unionfs_lock(). */ VI_LOCK(vp); - unp->un_lowervp = unp->un_uppervp = NULLVP; + unp->un_lowervp = unp->un_uppervp = NULL; vp->v_vnlock = &(vp->v_lock); vp->v_data = NULL; vp->v_object = NULL; @@ -543,14 +543,14 @@ unionfs_noderem(struct vnode *vp) ("%s: write reference without upper vnode", __func__)); VOP_ADD_WRITECOUNT(uvp, -writerefs); } - if (uvp != NULLVP) + if (uvp != NULL) vput(uvp); if (unlock_lvp) vput(lvp); - else if (lvp != NULLVP) + else if (lvp != NULL) vrele(lvp); - if (dvp != NULLVP) + if (dvp != NULL) unionfs_rem_cached_vnode(unp, dvp); if (unp->un_path != NULL) { @@ -567,7 +567,7 @@ unionfs_noderem(struct vnode *vp) LIST_REMOVE(unsp, uns_list); free(unsp, M_TEMP); } - if (dvp != NULLVP) { + if (dvp != NULL) { mtx_lock(&unionfs_deferred_rele_lock); STAILQ_INSERT_TAIL(&unionfs_deferred_rele_list, unp, un_rele); mtx_unlock(&unionfs_deferred_rele_lock); @@ -587,6 +587,7 @@ unionfs_find_node_status(struct unionfs_node *unp, struct thread *td) struct unionfs_node_status *unsp; pid_t pid; + MPASS(td != NULL); pid = td->td_proc->p_pid; ASSERT_VOP_ELOCKED(UNIONFSTOV(unp), __func__); @@ -612,6 +613,7 @@ unionfs_get_node_status(struct unionfs_node *unp, struct thread *td, struct unionfs_node_status *unsp; pid_t pid; + MPASS(td != NULL); pid = td->td_proc->p_pid; KASSERT(NULL != unspp, ("%s: NULL status", __func__)); @@ -793,7 +795,7 @@ unionfs_node_update(struct unionfs_node *unp, struct vnode *uvp, /* * Re-cache the unionfs vnode against the upper vnode */ - if (dvp != NULLVP && vp->v_type == VDIR) { + if (dvp != NULL && vp->v_type == VDIR) { VI_LOCK(dvp); if (unp->un_hash.le_prev != NULL) { LIST_REMOVE(unp, un_hash); @@ -841,7 +843,7 @@ unionfs_set_in_progress_flag(struct vnode *vp, unsigned int flag) if (unp == NULL) error = ENOENT; else if (flag == UNIONFS_COPY_IN_PROGRESS && - unp->un_uppervp != NULLVP) + unp->un_uppervp != NULL) error = EJUSTRETURN; else if (flag == UNIONFS_LOOKUP_IN_PROGRESS) error = ERELOOKUP; @@ -902,7 +904,7 @@ unionfs_mkshadowdir(struct vnode *dvp, struct vnode *vp, ASSERT_VOP_ELOCKED(vp, __func__); ump = MOUNTTOUNIONFSMOUNT(vp->v_mount); unp = VTOUNIONFS(vp); - if (unp->un_uppervp != NULLVP) + if (unp->un_uppervp != NULL) return (EEXIST); dunp = VTOUNIONFS(dvp); udvp = dunp->un_uppervp; @@ -914,7 +916,7 @@ unionfs_mkshadowdir(struct vnode *dvp, struct vnode *vp, return (error); lvp = unp->un_lowervp; - uvp = NULLVP; + uvp = NULL; credbk = cnp->cn_cred; /* Authority change to root */ @@ -953,7 +955,7 @@ unionfs_mkshadowdir(struct vnode *dvp, struct vnode *vp, vput(udvp); goto unionfs_mkshadowdir_relock; } - if (uvp != NULLVP) { + if (uvp != NULL) { if (udvp == uvp) vrele(uvp); else @@ -1218,7 +1220,7 @@ unionfs_mkwhiteout(struct vnode *dvp, struct vnode *vp, ASSERT_VOP_ELOCKED(vp, __func__); udvp = VTOUNIONFS(dvp)->un_uppervp; - wvp = NULLVP; + wvp = NULL; NDPREINIT(&nd); vref(udvp); VOP_UNLOCK(vp); @@ -1226,7 +1228,7 @@ unionfs_mkwhiteout(struct vnode *dvp, struct vnode *vp, pathlen, CREATE))) { goto unionfs_mkwhiteout_cleanup; } - if (wvp != NULLVP) { + if (wvp != NULL) { if (udvp == wvp) vrele(wvp); else @@ -1281,7 +1283,7 @@ unionfs_vn_create_on_upper(struct vnode **vpp, struct vnode *udvp, ASSERT_VOP_ELOCKED(vp, __func__); unp = VTOUNIONFS(vp); ump = MOUNTTOUNIONFSMOUNT(UNIONFSTOV(unp)->v_mount); - uvp = NULLVP; + uvp = NULL; lvp = unp->un_lowervp; cred = td->td_ucred; fmode = FFLAGS(O_WRONLY | O_CREAT | O_TRUNC | O_EXCL); @@ -1310,7 +1312,7 @@ unionfs_vn_create_on_upper(struct vnode **vpp, struct vnode *udvp, return (error); } - if (uvp != NULLVP) { + if (uvp != NULL) { if (uvp == udvp) vrele(uvp); else @@ -1433,23 +1435,23 @@ unionfs_copyfile(struct vnode *vp, int docopy, struct ucred *cred, ASSERT_VOP_ELOCKED(vp, __func__); unp = VTOUNIONFS(vp); lvp = unp->un_lowervp; - uvp = NULLVP; + uvp = NULL; if ((UNIONFSTOV(unp)->v_mount->mnt_flag & MNT_RDONLY)) return (EROFS); - if (unp->un_dvp == NULLVP) + if (unp->un_dvp == NULL) return (EINVAL); - if (unp->un_uppervp != NULLVP) + if (unp->un_uppervp != NULL) return (EEXIST); - udvp = NULLVP; + udvp = NULL; VI_LOCK(unp->un_dvp); dunp = VTOUNIONFS(unp->un_dvp); if (dunp != NULL) udvp = dunp->un_uppervp; VI_UNLOCK(unp->un_dvp); - if (udvp == NULLVP) + if (udvp == NULL) return (EROFS); if ((udvp->v_mount->mnt_flag & MNT_RDONLY)) return (EROFS); @@ -1646,7 +1648,7 @@ unionfs_check_rmdir(struct vnode *vp, struct ucred *cred, struct thread *td) cn.cn_cred = cred; error = VOP_LOOKUP(uvp, &tvp, &cn); - if (tvp != NULLVP) + if (tvp != NULL) vput(tvp); if (error != 0 && error != ENOENT && error != EJUSTRETURN) break; diff --git a/sys/fs/unionfs/union_vfsops.c b/sys/fs/unionfs/union_vfsops.c index 9342317ad08e..284b24a604f4 100644 --- a/sys/fs/unionfs/union_vfsops.c +++ b/sys/fs/unionfs/union_vfsops.c @@ -256,7 +256,7 @@ unionfs_domount(struct mount *mp) ump->um_lowervp = lowerrootvp; ump->um_uppervp = upperrootvp; } - ump->um_rootvp = NULLVP; + ump->um_rootvp = NULL; ump->um_uid = uid; ump->um_gid = gid; ump->um_udir = udir; @@ -280,7 +280,7 @@ unionfs_domount(struct mount *mp) * Get the unionfs root vnode. */ error = unionfs_nodeget(mp, ump->um_uppervp, ump->um_lowervp, - NULLVP, &(ump->um_rootvp), NULL); + NULL, &(ump->um_rootvp), NULL); if (error != 0) { vrele(upperrootvp); free(ump, M_UNIONFSMNT); @@ -558,7 +558,7 @@ unionfs_extattrctl(struct mount *mp, int cmd, struct vnode *filename_vp, ump = MOUNTTOUNIONFSMOUNT(mp); unp = VTOUNIONFS(filename_vp); - if (unp->un_uppervp != NULLVP) { + if (unp->un_uppervp != NULL) { return (VFS_EXTATTRCTL(ump->um_uppermp, cmd, unp->un_uppervp, namespace, attrname)); } else { diff --git a/sys/fs/unionfs/union_vnops.c b/sys/fs/unionfs/union_vnops.c index 03130f0ca949..66fee97a07d5 100644 --- a/sys/fs/unionfs/union_vnops.c +++ b/sys/fs/unionfs/union_vnops.c @@ -114,9 +114,9 @@ unionfs_lookup(struct vop_cachedlookup_args *ap) dunp = VTOUNIONFS(dvp); udvp = dunp->un_uppervp; ldvp = dunp->un_lowervp; - vp = uvp = lvp = NULLVP; + vp = uvp = lvp = NULL; td = curthread; - *(ap->a_vpp) = NULLVP; + *(ap->a_vpp) = NULL; UNIONFS_INTERNAL_DEBUG( "unionfs_lookup: enter: nameiop=%ld, flags=%lx, path=%s\n", @@ -159,7 +159,7 @@ unionfs_lookup(struct vop_cachedlookup_args *ap) * lookup dotdot */ if (cnflags & ISDOTDOT) { - if (LOOKUP != nameiop && udvp == NULLVP) { + if (LOOKUP != nameiop && udvp == NULL) { error = EROFS; goto unionfs_lookup_return; } @@ -170,7 +170,7 @@ unionfs_lookup(struct vop_cachedlookup_args *ap) goto unionfs_lookup_return; } - if (udvp != NULLVP) + if (udvp != NULL) dtmpvp = udvp; else dtmpvp = ldvp; @@ -186,7 +186,7 @@ unionfs_lookup(struct vop_cachedlookup_args *ap) * reference, or (if dvp was reclaimed) we'll need to drop * vp's lock and reference to return early. */ - if (vp != NULLVP) + if (vp != NULL) vput(vp); dunp = VTOUNIONFS(dvp); if (error == 0 && dunp == NULL) @@ -202,7 +202,7 @@ unionfs_lookup(struct vop_cachedlookup_args *ap) if (VN_IS_DOOMED(dtmpvp)) { vput(dtmpvp); - *(ap->a_vpp) = NULLVP; + *(ap->a_vpp) = NULL; error = ENOENT; } vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY); @@ -219,11 +219,11 @@ unionfs_lookup(struct vop_cachedlookup_args *ap) * The cost of this is that we may end up performing an unnecessary * lower layer lookup if a whiteout is present in the upper layer. */ - if (ldvp != NULLVP && !(cnflags & DOWHITEOUT)) { + if (ldvp != NULL && !(cnflags & DOWHITEOUT)) { struct componentname lcn; bool is_dot; - if (udvp != NULLVP) { + if (udvp != NULL) { vref(ldvp); VOP_UNLOCK(dvp); vn_lock(ldvp, LK_EXCLUSIVE | LK_RETRY); @@ -235,18 +235,18 @@ unionfs_lookup(struct vop_cachedlookup_args *ap) lcn.cn_flags = cnflags; is_dot = false; - if (udvp == NULLVP) + if (udvp == NULL) unionfs_forward_vop_start(ldvp, &lkflags); lerror = VOP_LOOKUP(ldvp, &lvp, &lcn); - if (udvp == NULLVP && + if (udvp == NULL && unionfs_forward_vop_finish(dvp, ldvp, lkflags)) { - if (lvp != NULLVP) + if (lvp != NULL) VOP_UNLOCK(lvp); error = ENOENT; goto unionfs_lookup_cleanup; } - if (udvp == NULLVP) + if (udvp == NULL) cnp->cn_flags = lcn.cn_flags; if (lerror == 0) { @@ -256,11 +256,11 @@ unionfs_lookup(struct vop_cachedlookup_args *ap) vref(dvp); is_dot = true; error = lerror; - } else if (lvp != NULLVP) + } else if (lvp != NULL) VOP_UNLOCK(lvp); } - if (udvp != NULLVP) { + if (udvp != NULL) { vput(ldvp); vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY); if (VN_IS_DOOMED(dvp)) @@ -274,13 +274,13 @@ unionfs_lookup(struct vop_cachedlookup_args *ap) /* * lookup upper layer */ - if (udvp != NULLVP) { + if (udvp != NULL) { bool iswhiteout = false; unionfs_forward_vop_start(udvp, &lkflags); uerror = VOP_LOOKUP(udvp, &uvp, cnp); if (unionfs_forward_vop_finish(dvp, udvp, lkflags)) { - if (uvp != NULLVP) + if (uvp != NULL) VOP_UNLOCK(uvp); error = ENOENT; goto unionfs_lookup_cleanup; @@ -288,7 +288,7 @@ unionfs_lookup(struct vop_cachedlookup_args *ap) if (uerror == 0) { if (udvp == uvp) { /* is dot */ - if (lvp != NULLVP) + if (lvp != NULL) vrele(lvp); vrele(uvp); *(ap->a_vpp) = dvp; @@ -296,7 +296,7 @@ unionfs_lookup(struct vop_cachedlookup_args *ap) error = uerror; goto unionfs_lookup_return; - } else if (uvp != NULLVP) + } else if (uvp != NULL) VOP_UNLOCK(uvp); } @@ -308,9 +308,9 @@ unionfs_lookup(struct vop_cachedlookup_args *ap) (va.va_flags & OPAQUE)) iswhiteout = true; - if (iswhiteout && lvp != NULLVP) { + if (iswhiteout && lvp != NULL) { vrele(lvp); - lvp = NULLVP; + lvp = NULL; } #if 0 @@ -323,29 +323,29 @@ unionfs_lookup(struct vop_cachedlookup_args *ap) /* * check lookup result */ - if (uvp == NULLVP && lvp == NULLVP) { - error = (udvp != NULLVP ? uerror : lerror); + if (uvp == NULL && lvp == NULL) { + error = (udvp != NULL ? uerror : lerror); goto unionfs_lookup_return; } /* * check vnode type */ - if (uvp != NULLVP && lvp != NULLVP && uvp->v_type != lvp->v_type) { + if (uvp != NULL && lvp != NULL && uvp->v_type != lvp->v_type) { vrele(lvp); - lvp = NULLVP; + lvp = NULL; } /* * check shadow dir */ - if (uerror != 0 && uerror != EJUSTRETURN && udvp != NULLVP && - lerror == 0 && lvp != NULLVP && lvp->v_type == VDIR && + if (uerror != 0 && uerror != EJUSTRETURN && udvp != NULL && + lerror == 0 && lvp != NULL && lvp->v_type == VDIR && !(dvp->v_mount->mnt_flag & MNT_RDONLY) && (1 < cnp->cn_namelen || '.' != *(cnp->cn_nameptr))) { /* get unionfs vnode in order to create a new shadow dir. */ - error = unionfs_nodeget(dvp->v_mount, NULLVP, lvp, dvp, &vp, - cnp); + error = unionfs_nodeget(dvp->v_mount, NULL, lvp, dvp, &vp, + cnp); if (error != 0) goto unionfs_lookup_cleanup; @@ -382,7 +382,7 @@ unionfs_lookup(struct vop_cachedlookup_args *ap) * get unionfs vnode. */ else { - if (uvp != NULLVP) + if (uvp != NULL) error = uerror; else error = lerror; @@ -409,14 +409,14 @@ unionfs_lookup(struct vop_cachedlookup_args *ap) cache_enter(dvp, vp, cnp); unionfs_lookup_cleanup: - if (uvp != NULLVP) + if (uvp != NULL) vrele(uvp); - if (lvp != NULLVP) + if (lvp != NULL) vrele(lvp); if (error == ENOENT && (cnflags & MAKEENTRY) != 0 && !VN_IS_DOOMED(dvp)) - cache_enter(dvp, NULLVP, cnp); + cache_enter(dvp, NULL, cnp); unionfs_lookup_return: unionfs_clear_in_progress_flag(dvp, UNIONFS_LOOKUP_IN_PROGRESS); @@ -444,7 +444,7 @@ unionfs_create(struct vop_create_args *ap) udvp = dunp->un_uppervp; error = EROFS; - if (udvp != NULLVP) { + if (udvp != NULL) { int lkflags; bool vp_created = false; unionfs_forward_vop_start(udvp, &lkflags); @@ -457,8 +457,8 @@ unionfs_create(struct vop_create_args *ap) } if (error == 0) { VOP_UNLOCK(vp); - error = unionfs_nodeget(ap->a_dvp->v_mount, vp, NULLVP, - ap->a_dvp, ap->a_vpp, cnp); + error = unionfs_nodeget(ap->a_dvp->v_mount, vp, NULL, + ap->a_dvp, ap->a_vpp, cnp); vrele(vp); } else if (vp_created) vput(vp); @@ -486,7 +486,7 @@ unionfs_whiteout(struct vop_whiteout_args *ap) udvp = dunp->un_uppervp; error = EOPNOTSUPP; - if (udvp != NULLVP) { + if (udvp != NULL) { int lkflags; switch (ap->a_flags) { case CREATE: @@ -525,7 +525,7 @@ unionfs_mknod(struct vop_mknod_args *ap) udvp = dunp->un_uppervp; error = EROFS; - if (udvp != NULLVP) { + if (udvp != NULL) { int lkflags; bool vp_created = false; unionfs_forward_vop_start(udvp, &lkflags); @@ -538,8 +538,8 @@ unionfs_mknod(struct vop_mknod_args *ap) } if (error == 0) { VOP_UNLOCK(vp); - error = unionfs_nodeget(ap->a_dvp->v_mount, vp, NULLVP, - ap->a_dvp, ap->a_vpp, cnp); + error = unionfs_nodeget(ap->a_dvp->v_mount, vp, NULL, + ap->a_dvp, ap->a_vpp, cnp); vrele(vp); } else if (vp_created) vput(vp); @@ -611,7 +611,7 @@ unionfs_lock_lvp(struct vnode *vp, int *lkflags) vn_lock(lvp, *lkflags | LK_RETRY); if (VN_IS_DOOMED(lvp)) { vput(lvp); - lvp = NULLVP; + lvp = NULL; vn_lock(vp, *lkflags | LK_RETRY); } return (lvp); @@ -656,7 +656,7 @@ unionfs_open(struct vop_open_args *ap) error = 0; vp = ap->a_vp; - targetvp = NULLVP; + targetvp = NULL; cred = ap->a_cred; td = ap->a_td; open_lvp = lock_lvp = false; @@ -686,10 +686,10 @@ unionfs_open(struct vop_open_args *ap) if (targetvp == lvp && (ap->a_mode & FWRITE) && lvp->v_type == VREG) - targetvp = NULLVP; + targetvp = NULL; } - if (targetvp == NULLVP) { - if (uvp == NULLVP) { + if (targetvp == NULL) { + if (uvp == NULL) { if ((ap->a_mode & FWRITE) && lvp->v_type == VREG) { error = unionfs_copyfile(vp, !(ap->a_mode & O_TRUNC), cred, td); @@ -704,16 +704,16 @@ unionfs_open(struct vop_open_args *ap) targetvp = uvp; } - if (targetvp == uvp && uvp->v_type == VDIR && lvp != NULLVP && + if (targetvp == uvp && uvp->v_type == VDIR && lvp != NULL && unsp->uns_lower_opencnt <= 0) open_lvp = true; - else if (targetvp == lvp && uvp != NULLVP) + else if (targetvp == lvp && uvp != NULL) lock_lvp = true; if (lock_lvp) { unp = NULL; lvp = unionfs_lock_lvp(vp, &lkflags); - if (lvp == NULLVP) { + if (lvp == NULL) { error = ENOENT; goto unionfs_open_abort; } @@ -736,7 +736,7 @@ unionfs_open(struct vop_open_args *ap) if (open_lvp) { unp = NULL; lvp = unionfs_lock_lvp(vp, &lkflags); - if (lvp == NULLVP) { + if (lvp == NULL) { error = ENOENT; goto unionfs_open_abort; } @@ -814,7 +814,7 @@ unionfs_close(struct vop_close_args *ap) unp = VTOUNIONFS(vp); lvp = unp->un_lowervp; uvp = unp->un_uppervp; - unsp = unionfs_find_node_status(unp, td); + unsp = (td != NULL) ? unionfs_find_node_status(unp, td) : NULL; if (unsp == NULL || (unsp->uns_lower_opencnt <= 0 && unsp->uns_upper_opencnt <= 0)) { @@ -822,7 +822,7 @@ unionfs_close(struct vop_close_args *ap) if (unsp != NULL) printf("unionfs_close: warning: open count is 0\n"); #endif - if (uvp != NULLVP) + if (uvp != NULL) ovp = uvp; else ovp = lvp; @@ -831,11 +831,11 @@ unionfs_close(struct vop_close_args *ap) else ovp = lvp; - if (ovp == lvp && uvp != NULLVP) { + if (ovp == lvp && uvp != NULL) { lock_lvp = true; unp = NULL; lvp = unionfs_lock_lvp(vp, &lkflags); - if (lvp == NULLVP) { + if (lvp == NULL) { error = ENOENT; goto unionfs_close_abort; } @@ -861,7 +861,7 @@ unionfs_close(struct vop_close_args *ap) if (unsp->uns_node_flag & UNS_OPENL_4_READDIR) { unp = NULL; lvp = unionfs_lock_lvp(vp, &lkflags); - if (lvp == NULLVP) { + if (lvp == NULL) { error = ENOENT; goto unionfs_close_abort; } @@ -978,7 +978,7 @@ unionfs_access(struct vop_access_args *ap) } } - if (uvp != NULLVP) { + if (uvp != NULL) { error = VOP_ACCESS(uvp, accmode, ap->a_cred, td); UNIONFS_INTERNAL_DEBUG("unionfs_access: leave (%d)\n", error); @@ -986,7 +986,7 @@ unionfs_access(struct vop_access_args *ap) return (error); } - if (lvp != NULLVP) { + if (lvp != NULL) { if (accmode & VWRITE) { if ((ump->um_uppermp->mnt_flag & MNT_RDONLY) != 0) { switch (ap->a_vp->v_type) { @@ -1044,7 +1044,7 @@ unionfs_getattr(struct vop_getattr_args *ap) lvp = unp->un_lowervp; td = curthread; - if (uvp != NULLVP) { + if (uvp != NULL) { if ((error = VOP_GETATTR(uvp, ap->a_vap, ap->a_cred)) == 0) ap->a_vap->va_fsid = ap->a_vp->v_mount->mnt_stat.f_fsid.val[0]; @@ -1106,7 +1106,7 @@ unionfs_setattr(struct vop_setattr_args *ap) vap->va_mtime.tv_sec != VNOVAL || vap->va_mode != (mode_t)VNOVAL)) return (EROFS); - if (uvp == NULLVP && lvp->v_type == VREG) { + if (uvp == NULL && lvp->v_type == VREG) { error = unionfs_copyfile(ap->a_vp, (vap->va_size != 0), ap->a_cred, td); if (error != 0) @@ -1114,7 +1114,7 @@ unionfs_setattr(struct vop_setattr_args *ap) uvp = unp->un_uppervp; } - if (uvp != NULLVP) { + if (uvp != NULL) { int lkflags; unionfs_forward_vop_start(uvp, &lkflags); error = VOP_SETATTR(uvp, vap, ap->a_cred); @@ -1138,7 +1138,7 @@ unionfs_read(struct vop_read_args *ap) KASSERT_UNIONFS_VNODE(ap->a_vp); unp = VTOUNIONFS(ap->a_vp); - tvp = (unp->un_uppervp != NULLVP ? unp->un_uppervp : unp->un_lowervp); + tvp = (unp->un_uppervp != NULL ? unp->un_uppervp : unp->un_lowervp); error = VOP_READ(tvp, ap->a_uio, ap->a_ioflag, ap->a_cred); @@ -1160,7 +1160,7 @@ unionfs_write(struct vop_write_args *ap) KASSERT_UNIONFS_VNODE(ap->a_vp); unp = VTOUNIONFS(ap->a_vp); - tvp = (unp->un_uppervp != NULLVP ? unp->un_uppervp : unp->un_lowervp); + tvp = (unp->un_uppervp != NULL ? unp->un_uppervp : unp->un_lowervp); unionfs_forward_vop_start(tvp, &lkflags); error = VOP_WRITE(tvp, ap->a_uio, ap->a_ioflag, ap->a_cred); @@ -1190,7 +1190,7 @@ unionfs_ioctl(struct vop_ioctl_args *ap) unionfs_tryrem_node_status(unp, unsp); VOP_UNLOCK(ap->a_vp); - if (ovp == NULLVP) + if (ovp == NULL) return (EBADF); error = VOP_IOCTL(ovp, ap->a_command, ap->a_data, ap->a_fflag, @@ -1217,7 +1217,7 @@ unionfs_poll(struct vop_poll_args *ap) unionfs_tryrem_node_status(unp, unsp); VOP_UNLOCK(ap->a_vp); - if (ovp == NULLVP) + if (ovp == NULL) return (EBADF); return (VOP_POLL(ovp, ap->a_events, ap->a_cred, ap->a_td)); @@ -1246,7 +1246,7 @@ unionfs_fsync(struct vop_fsync_args *ap) unionfs_downgrade_lock(ap->a_vp, lkstatus); - if (ovp == NULLVP) + if (ovp == NULL) return (EBADF); unionfs_forward_vop_start(ovp, &lkflags); @@ -1289,20 +1289,20 @@ unionfs_remove(struct vop_remove_args *ap) path = unp->un_path; pathlen = unp->un_pathlen; - if (udvp == NULLVP) + if (udvp == NULL) return (EROFS); - if (uvp != NULLVP) { + if (uvp != NULL) { int udvp_lkflags, uvp_lkflags; if (ump == NULL || ump->um_whitemode == UNIONFS_WHITE_ALWAYS || - lvp != NULLVP) + lvp != NULL) cnp->cn_flags |= DOWHITEOUT; unionfs_forward_vop_start_pair(udvp, &udvp_lkflags, uvp, &uvp_lkflags); error = VOP_REMOVE(udvp, uvp, cnp); unionfs_forward_vop_finish_pair(ap->a_dvp, udvp, udvp_lkflags, ap->a_vp, uvp, uvp_lkflags); - } else if (lvp != NULLVP) { + } else if (lvp != NULL) { error = unionfs_mkwhiteout(ap->a_dvp, ap->a_vp, cnp, td, path, pathlen); } @@ -1332,16 +1332,16 @@ unionfs_link(struct vop_link_args *ap) dunp = VTOUNIONFS(ap->a_tdvp); unp = NULL; udvp = dunp->un_uppervp; - uvp = NULLVP; + uvp = NULL; cnp = ap->a_cnp; td = curthread; - if (udvp == NULLVP) + if (udvp == NULL) return (EROFS); unp = VTOUNIONFS(ap->a_vp); - if (unp->un_uppervp == NULLVP) { + if (unp->un_uppervp == NULL) { if (ap->a_vp->v_type != VREG) return (EOPNOTSUPP); @@ -1405,7 +1405,7 @@ unionfs_rename(struct vop_rename_args *ap) /* check for cross device rename */ if (fvp->v_mount != tdvp->v_mount || - (tvp != NULLVP && fvp->v_mount != tvp->v_mount)) { + (tvp != NULL && fvp->v_mount != tvp->v_mount)) { if (fvp->v_op != &unionfs_vnodeops) error = ENODEV; else @@ -1418,7 +1418,7 @@ unionfs_rename(struct vop_rename_args *ap) goto unionfs_rename_abort; KASSERT_UNIONFS_VNODE(tdvp); - if (tvp != NULLVP) + if (tvp != NULL) KASSERT_UNIONFS_VNODE(tvp); if (fdvp != tdvp) VI_LOCK(fdvp); @@ -1433,7 +1433,7 @@ unionfs_rename(struct vop_rename_args *ap) UNIONFS_INTERNAL_DEBUG("fdvp=%p, ufdvp=%p, lfdvp=%p\n", fdvp, unp->un_uppervp, unp->un_lowervp); #endif - if (unp->un_uppervp == NULLVP) { + if (unp->un_uppervp == NULL) { error = ENODEV; } else { rfdvp = unp->un_uppervp; @@ -1460,10 +1460,10 @@ unionfs_rename(struct vop_rename_args *ap) * If we only have a lower vnode, copy the source file to the upper * FS so that the rename operation can be issued against the upper FS. */ - if (unp->un_uppervp == NULLVP) { + if (unp->un_uppervp == NULL) { bool unlock_fdvp = false, relock_tdvp = false; VI_UNLOCK(fvp); - if (tvp != NULLVP) + if (tvp != NULL) VOP_UNLOCK(tvp); if (fvp->v_type == VREG) { /* @@ -1496,7 +1496,7 @@ unionfs_rename(struct vop_rename_args *ap) unp = VTOUNIONFS(fvp); if (unp == NULL) error = ENOENT; - else if (unp->un_uppervp == NULLVP) { + else if (unp->un_uppervp == NULL) { switch (fvp->v_type) { case VREG: error = unionfs_copyfile(fvp, 1, fcnp->cn_cred, td); @@ -1514,7 +1514,7 @@ unionfs_rename(struct vop_rename_args *ap) VOP_UNLOCK(fdvp); if (relock_tdvp) vn_lock(tdvp, LK_EXCLUSIVE | LK_RETRY); - if (tvp != NULLVP) + if (tvp != NULL) vn_lock(tvp, LK_EXCLUSIVE | LK_RETRY); /* * Since we've dropped tdvp's lock at some point in the copy @@ -1526,7 +1526,7 @@ unionfs_rename(struct vop_rename_args *ap) goto unionfs_rename_abort; } - if (unp->un_lowervp != NULLVP) + if (unp->un_lowervp != NULL) fcnp->cn_flags |= DOWHITEOUT; rfvp = unp->un_uppervp; vref(rfvp); @@ -1539,14 +1539,14 @@ unionfs_rename(struct vop_rename_args *ap) UNIONFS_INTERNAL_DEBUG("tdvp=%p, utdvp=%p, ltdvp=%p\n", tdvp, unp->un_uppervp, unp->un_lowervp); #endif - if (unp->un_uppervp == NULLVP) { + if (unp->un_uppervp == NULL) { error = ENODEV; goto unionfs_rename_abort; } rtdvp = unp->un_uppervp; vref(rtdvp); - if (tvp != NULLVP) { + if (tvp != NULL) { unp = VTOUNIONFS(tvp); if (unp == NULL) { error = ENOENT; @@ -1556,8 +1556,8 @@ unionfs_rename(struct vop_rename_args *ap) UNIONFS_INTERNAL_DEBUG("tvp=%p, utvp=%p, ltvp=%p\n", tvp, unp->un_uppervp, unp->un_lowervp); #endif - if (unp->un_uppervp == NULLVP) - rtvp = NULLVP; + if (unp->un_uppervp == NULL) + rtvp = NULL; else { if (tvp->v_type == VDIR) { error = EINVAL; @@ -1574,7 +1574,7 @@ unionfs_rename(struct vop_rename_args *ap) error = VOP_RENAME(rfdvp, rfvp, fcnp, rtdvp, rtvp, tcnp); if (error == 0) { - if (rtvp != NULLVP && rtvp->v_type == VDIR) + if (rtvp != NULL && rtvp->v_type == VDIR) cache_purge(tdvp); if (fvp->v_type == VDIR && fdvp != tdvp) cache_purge(fdvp); @@ -1582,8 +1582,8 @@ unionfs_rename(struct vop_rename_args *ap) if (tdvp != rtdvp) vrele(tdvp); - if (tvp != rtvp && tvp != NULLVP) { - if (rtvp == NULLVP) + if (tvp != rtvp && tvp != NULL) { + if (rtvp == NULL) vput(tvp); else vrele(tvp); @@ -1601,13 +1601,13 @@ unionfs_rename_abort: vput(tdvp); if (tdvp != rtdvp) vrele(rtdvp); - if (tvp != NULLVP) { + if (tvp != NULL) { if (tdvp != tvp) vput(tvp); else vrele(tvp); } - if (tvp != rtvp && rtvp != NULLVP) + if (tvp != rtvp && rtvp != NULL) vrele(rtvp); if (fdvp != rfdvp) vrele(rfdvp); @@ -1644,7 +1644,7 @@ unionfs_mkdir(struct vop_mkdir_args *ap) lkflags = cnp->cn_lkflags; udvp = dunp->un_uppervp; - if (udvp != NULLVP) { + if (udvp != NULL) { /* check opaque */ if (!(cnp->cn_flags & ISWHITEOUT)) { error = VOP_GETATTR(udvp, &va, cnp->cn_cred); @@ -1666,8 +1666,8 @@ unionfs_mkdir(struct vop_mkdir_args *ap) if (error == 0) { VOP_UNLOCK(uvp); cnp->cn_lkflags = LK_EXCLUSIVE; - error = unionfs_nodeget(dvp->v_mount, uvp, NULLVP, - dvp, ap->a_vpp, cnp); + error = unionfs_nodeget(dvp->v_mount, uvp, NULL, + dvp, ap->a_vpp, cnp); vrele(uvp); cnp->cn_lkflags = lkflags; } else if (uvp_created) @@ -1707,14 +1707,14 @@ unionfs_rmdir(struct vop_rmdir_args *ap) uvp = unp->un_uppervp; lvp = unp->un_lowervp; - if (udvp == NULLVP) + if (udvp == NULL) return (EROFS); if (udvp == uvp) return (EOPNOTSUPP); - if (uvp != NULLVP) { - if (lvp != NULLVP) { + if (uvp != NULL) { + if (lvp != NULL) { /* * We need to keep dvp and vp's upper vnodes locked * going into the VOP_RMDIR() call, but the empty @@ -1752,7 +1752,7 @@ unionfs_rmdir(struct vop_rmdir_args *ap) return (error); } ump = MOUNTTOUNIONFSMOUNT(ap->a_vp->v_mount); - if (ump->um_whitemode == UNIONFS_WHITE_ALWAYS || lvp != NULLVP) + if (ump->um_whitemode == UNIONFS_WHITE_ALWAYS || lvp != NULL) cnp->cn_flags |= (DOWHITEOUT | IGNOREWHITEOUT); int udvp_lkflags, uvp_lkflags; unionfs_forward_vop_start_pair(udvp, &udvp_lkflags, @@ -1760,7 +1760,7 @@ unionfs_rmdir(struct vop_rmdir_args *ap) error = VOP_RMDIR(udvp, uvp, cnp); unionfs_forward_vop_finish_pair(ap->a_dvp, udvp, udvp_lkflags, ap->a_vp, uvp, uvp_lkflags); - } else if (lvp != NULLVP) { + } else if (lvp != NULL) { error = unionfs_mkwhiteout(ap->a_dvp, ap->a_vp, cnp, td, unp->un_path, unp->un_pathlen); } @@ -1795,7 +1795,7 @@ unionfs_symlink(struct vop_symlink_args *ap) lkflags = cnp->cn_lkflags; udvp = dunp->un_uppervp; - if (udvp != NULLVP) { + if (udvp != NULL) { int udvp_lkflags; bool uvp_created = false; unionfs_forward_vop_start(udvp, &udvp_lkflags); @@ -1808,8 +1808,8 @@ unionfs_symlink(struct vop_symlink_args *ap) if (error == 0) { VOP_UNLOCK(uvp); cnp->cn_lkflags = LK_EXCLUSIVE; - error = unionfs_nodeget(ap->a_dvp->v_mount, uvp, NULLVP, - ap->a_dvp, ap->a_vpp, cnp); + error = unionfs_nodeget(ap->a_dvp->v_mount, uvp, NULL, + ap->a_dvp, ap->a_vpp, cnp); vrele(uvp); cnp->cn_lkflags = lkflags; } else if (uvp_created) @@ -1849,8 +1849,8 @@ unionfs_readdir(struct vop_readdir_args *ap) eofflag = 0; uio_offset_bk = 0; uio = ap->a_uio; - uvp = NULLVP; - lvp = NULLVP; + uvp = NULL; + lvp = NULL; td = uio->uio_td; ncookies_bk = 0; cookies_bk = NULL; @@ -1872,8 +1872,8 @@ unionfs_readdir(struct vop_readdir_args *ap) lvp = unp->un_lowervp; /* check the open count. unionfs needs open before readdir. */ unionfs_get_node_status(unp, td, &unsp); - if ((uvp != NULLVP && unsp->uns_upper_opencnt <= 0) || - (lvp != NULLVP && unsp->uns_lower_opencnt <= 0)) { + if ((uvp != NULL && unsp->uns_upper_opencnt <= 0) || + (lvp != NULL && unsp->uns_lower_opencnt <= 0)) { unionfs_tryrem_node_status(unp, unsp); error = EBADF; } @@ -1883,15 +1883,15 @@ unionfs_readdir(struct vop_readdir_args *ap) goto unionfs_readdir_exit; /* check opaque */ - if (uvp != NULLVP && lvp != NULLVP) { + if (uvp != NULL && lvp != NULL) { if ((error = VOP_GETATTR(uvp, &va, ap->a_cred)) != 0) goto unionfs_readdir_exit; if (va.va_flags & OPAQUE) - lvp = NULLVP; + lvp = NULL; } /* upper only */ - if (uvp != NULLVP && lvp == NULLVP) { + if (uvp != NULL && lvp == NULL) { unionfs_forward_vop_start(uvp, &lkflags); error = VOP_READDIR(uvp, uio, ap->a_cred, ap->a_eofflag, ap->a_ncookies, ap->a_cookies); @@ -1904,7 +1904,7 @@ unionfs_readdir(struct vop_readdir_args *ap) } /* lower only */ - if (uvp == NULLVP && lvp != NULLVP) { + if (uvp == NULL && lvp != NULL) { unionfs_forward_vop_start(lvp, &lkflags); error = VOP_READDIR(lvp, uio, ap->a_cred, ap->a_eofflag, ap->a_ncookies, ap->a_cookies); @@ -1919,8 +1919,8 @@ unionfs_readdir(struct vop_readdir_args *ap) /* * readdir upper and lower */ - KASSERT(uvp != NULLVP, ("unionfs_readdir: null upper vp")); - KASSERT(lvp != NULLVP, ("unionfs_readdir: null lower vp")); + KASSERT(uvp != NULL, ("unionfs_readdir: null upper vp")); + KASSERT(lvp != NULL, ("unionfs_readdir: null lower vp")); if (uio->uio_offset == 0) unsp->uns_readdir_status = 0; @@ -2040,7 +2040,7 @@ unionfs_readlink(struct vop_readlink_args *ap) KASSERT_UNIONFS_VNODE(ap->a_vp); unp = VTOUNIONFS(ap->a_vp); - vp = (unp->un_uppervp != NULLVP ? unp->un_uppervp : unp->un_lowervp); + vp = (unp->un_uppervp != NULL ? unp->un_uppervp : unp->un_lowervp); error = VOP_READLINK(vp, ap->a_uio, ap->a_cred); @@ -2061,7 +2061,7 @@ unionfs_getwritemount(struct vop_getwritemount_args *ap) error = 0; vp = ap->a_vp; - uvp = NULLVP; + uvp = NULL; VI_LOCK(vp); unp = VTOUNIONFS(vp); @@ -2073,7 +2073,7 @@ unionfs_getwritemount(struct vop_getwritemount_args *ap) * We may be initiating a write operation that will produce a * new upper vnode through CoW. */ - if (uvp == NULLVP && unp != NULL) { + if (uvp == NULL && unp != NULL) { ovp = vp; vp = unp->un_dvp; /* @@ -2086,11 +2086,11 @@ unionfs_getwritemount(struct vop_getwritemount_args *ap) unp = VTOUNIONFS(vp); if (unp != NULL) uvp = unp->un_uppervp; - if (uvp == NULLVP) + if (uvp == NULL) error = EACCES; } - if (uvp != NULLVP) { + if (uvp != NULL) { vholdnz(uvp); VI_UNLOCK(vp); error = VOP_GETWRITEMOUNT(uvp, ap->a_mpp); @@ -2141,9 +2141,9 @@ unionfs_print(struct vop_print_args *ap) unsp->uns_upper_opencnt, unsp->uns_lower_opencnt); */ - if (unp->un_uppervp != NULLVP) + if (unp->un_uppervp != NULL) vn_printf(unp->un_uppervp, "unionfs: upper "); - if (unp->un_lowervp != NULLVP) + if (unp->un_lowervp != NULL) vn_printf(unp->un_lowervp, "unionfs: lower "); return (0); @@ -2208,7 +2208,6 @@ unionfs_lock_restart: vholdnz(tvp); VI_UNLOCK(vp); error = VOP_LOCK(tvp, flags); - vdrop(tvp); if (error == 0 && (lvp_locked || VTOUNIONFS(vp) == NULL)) { /* * After dropping the interlock above, there exists a window @@ -2232,8 +2231,9 @@ unionfs_lock_restart: * lower vnode lock here. */ unp = VTOUNIONFS(vp); - if (unp == NULL || unp->un_uppervp != NULLVP) { + if (unp == NULL || unp->un_uppervp != NULL) { VOP_UNLOCK(tvp); + vdrop(tvp); /* * If we previously held the lock, the upgrade may * have temporarily dropped the lock, in which case @@ -2249,6 +2249,7 @@ unionfs_lock_restart: goto unionfs_lock_restart; } } + vdrop(tvp); return (error); } @@ -2259,7 +2260,6 @@ unionfs_unlock(struct vop_unlock_args *ap) struct vnode *vp; struct vnode *tvp; struct unionfs_node *unp; - int error; KASSERT_UNIONFS_VNODE(ap->a_vp); @@ -2271,11 +2271,7 @@ unionfs_unlock(struct vop_unlock_args *ap) tvp = (unp->un_uppervp != NULL ? unp->un_uppervp : unp->un_lowervp); - vholdnz(tvp); - error = VOP_UNLOCK(tvp); - vdrop(tvp); - - return (error); + return (VOP_UNLOCK(tvp)); } static int @@ -2287,7 +2283,7 @@ unionfs_pathconf(struct vop_pathconf_args *ap) KASSERT_UNIONFS_VNODE(ap->a_vp); unp = VTOUNIONFS(ap->a_vp); - vp = (unp->un_uppervp != NULLVP ? unp->un_uppervp : unp->un_lowervp); + vp = (unp->un_uppervp != NULL ? unp->un_uppervp : unp->un_lowervp); return (VOP_PATHCONF(vp, ap->a_name, ap->a_retval)); } @@ -2314,7 +2310,7 @@ unionfs_advlock(struct vop_advlock_args *ap) unp = VTOUNIONFS(ap->a_vp); uvp = unp->un_uppervp; - if (uvp == NULLVP) { + if (uvp == NULL) { error = unionfs_copyfile(ap->a_vp, 1, td->td_ucred, td); if (error != 0) goto unionfs_advlock_abort; @@ -2360,10 +2356,10 @@ unionfs_strategy(struct vop_strategy_args *ap) KASSERT_UNIONFS_VNODE(ap->a_vp); unp = VTOUNIONFS(ap->a_vp); - vp = (unp->un_uppervp != NULLVP ? unp->un_uppervp : unp->un_lowervp); + vp = (unp->un_uppervp != NULL ? unp->un_uppervp : unp->un_lowervp); #ifdef DIAGNOSTIC - if (vp == NULLVP) + if (vp == NULL) panic("unionfs_strategy: nullvp"); if (ap->a_bp->b_iocmd == BIO_WRITE && vp == unp->un_lowervp) @@ -2383,7 +2379,7 @@ unionfs_getacl(struct vop_getacl_args *ap) KASSERT_UNIONFS_VNODE(ap->a_vp); unp = VTOUNIONFS(ap->a_vp); - vp = (unp->un_uppervp != NULLVP ? unp->un_uppervp : unp->un_lowervp); + vp = (unp->un_uppervp != NULL ? unp->un_uppervp : unp->un_lowervp); UNIONFS_INTERNAL_DEBUG("unionfs_getacl: enter\n"); @@ -2416,13 +2412,13 @@ unionfs_setacl(struct vop_setacl_args *ap) if (ap->a_vp->v_mount->mnt_flag & MNT_RDONLY) return (EROFS); - if (uvp == NULLVP && lvp->v_type == VREG) { + if (uvp == NULL && lvp->v_type == VREG) { if ((error = unionfs_copyfile(ap->a_vp, 1, ap->a_cred, td)) != 0) return (error); uvp = unp->un_uppervp; } - if (uvp != NULLVP) { + if (uvp != NULL) { int lkflags; unionfs_forward_vop_start(uvp, &lkflags); error = VOP_SETACL(uvp, ap->a_type, ap->a_aclp, ap->a_cred, td); @@ -2446,7 +2442,7 @@ unionfs_aclcheck(struct vop_aclcheck_args *ap) KASSERT_UNIONFS_VNODE(ap->a_vp); unp = VTOUNIONFS(ap->a_vp); - vp = (unp->un_uppervp != NULLVP ? unp->un_uppervp : unp->un_lowervp); + vp = (unp->un_uppervp != NULL ? unp->un_uppervp : unp->un_lowervp); error = VOP_ACLCHECK(vp, ap->a_type, ap->a_aclp, ap->a_cred, ap->a_td); @@ -2467,7 +2463,7 @@ unionfs_openextattr(struct vop_openextattr_args *ap) vp = ap->a_vp; unp = VTOUNIONFS(vp); - tvp = (unp->un_uppervp != NULLVP ? unp->un_uppervp : unp->un_lowervp); + tvp = (unp->un_uppervp != NULL ? unp->un_uppervp : unp->un_lowervp); if ((tvp == unp->un_uppervp && (unp->un_flag & UNIONFS_OPENEXTU)) || (tvp == unp->un_lowervp && (unp->un_flag & UNIONFS_OPENEXTL))) @@ -2502,14 +2498,14 @@ unionfs_closeextattr(struct vop_closeextattr_args *ap) vp = ap->a_vp; unp = VTOUNIONFS(vp); - tvp = NULLVP; + tvp = NULL; if (unp->un_flag & UNIONFS_OPENEXTU) tvp = unp->un_uppervp; else if (unp->un_flag & UNIONFS_OPENEXTL) tvp = unp->un_lowervp; - if (tvp == NULLVP) + if (tvp == NULL) return (EOPNOTSUPP); error = VOP_CLOSEEXTATTR(tvp, ap->a_commit, ap->a_cred, ap->a_td); @@ -2538,14 +2534,14 @@ unionfs_getextattr(struct vop_getextattr_args *ap) KASSERT_UNIONFS_VNODE(ap->a_vp); unp = VTOUNIONFS(ap->a_vp); - vp = NULLVP; + vp = NULL; if (unp->un_flag & UNIONFS_OPENEXTU) vp = unp->un_uppervp; else if (unp->un_flag & UNIONFS_OPENEXTL) vp = unp->un_lowervp; - if (vp == NULLVP) + if (vp == NULL) return (EOPNOTSUPP); return (VOP_GETEXTATTR(vp, ap->a_attrnamespace, ap->a_name, @@ -2569,7 +2565,7 @@ unionfs_setextattr(struct vop_setextattr_args *ap) unp = VTOUNIONFS(ap->a_vp); uvp = unp->un_uppervp; lvp = unp->un_lowervp; - ovp = NULLVP; + ovp = NULL; cred = ap->a_cred; td = ap->a_td; @@ -2584,12 +2580,12 @@ unionfs_setextattr(struct vop_setextattr_args *ap) else if (unp->un_flag & UNIONFS_OPENEXTL) ovp = unp->un_lowervp; - if (ovp == NULLVP) + if (ovp == NULL) return (EOPNOTSUPP); if (ovp == lvp && lvp->v_type == VREG) { VOP_CLOSEEXTATTR(lvp, 0, cred, td); - if (uvp == NULLVP && + if (uvp == NULL && (error = unionfs_copyfile(ap->a_vp, 1, cred, td)) != 0) { unionfs_setextattr_reopen: unp = VTOUNIONFS(ap->a_vp); @@ -2633,14 +2629,14 @@ unionfs_listextattr(struct vop_listextattr_args *ap) KASSERT_UNIONFS_VNODE(ap->a_vp); unp = VTOUNIONFS(ap->a_vp); - vp = NULLVP; + vp = NULL; if (unp->un_flag & UNIONFS_OPENEXTU) vp = unp->un_uppervp; else if (unp->un_flag & UNIONFS_OPENEXTL) vp = unp->un_lowervp; - if (vp == NULLVP) + if (vp == NULL) return (EOPNOTSUPP); return (VOP_LISTEXTATTR(vp, ap->a_attrnamespace, ap->a_uio, @@ -2664,7 +2660,7 @@ unionfs_deleteextattr(struct vop_deleteextattr_args *ap) unp = VTOUNIONFS(ap->a_vp); uvp = unp->un_uppervp; lvp = unp->un_lowervp; - ovp = NULLVP; + ovp = NULL; cred = ap->a_cred; td = ap->a_td; @@ -2679,12 +2675,12 @@ unionfs_deleteextattr(struct vop_deleteextattr_args *ap) else if (unp->un_flag & UNIONFS_OPENEXTL) ovp = unp->un_lowervp; - if (ovp == NULLVP) + if (ovp == NULL) return (EOPNOTSUPP); if (ovp == lvp && lvp->v_type == VREG) { VOP_CLOSEEXTATTR(lvp, 0, cred, td); - if (uvp == NULLVP && + if (uvp == NULL && (error = unionfs_copyfile(ap->a_vp, 1, cred, td)) != 0) { unionfs_deleteextattr_reopen: unp = VTOUNIONFS(ap->a_vp); @@ -2737,13 +2733,13 @@ unionfs_setlabel(struct vop_setlabel_args *ap) if (ap->a_vp->v_mount->mnt_flag & MNT_RDONLY) return (EROFS); - if (uvp == NULLVP && lvp->v_type == VREG) { + if (uvp == NULL && lvp->v_type == VREG) { if ((error = unionfs_copyfile(ap->a_vp, 1, ap->a_cred, td)) != 0) return (error); uvp = unp->un_uppervp; } - if (uvp != NULLVP) + if (uvp != NULL) error = VOP_SETLABEL(uvp, ap->a_label, ap->a_cred, td); UNIONFS_INTERNAL_DEBUG("unionfs_setlabel: leave (%d)\n", error); @@ -2796,10 +2792,10 @@ unionfs_vput_pair(struct vop_vput_pair_args *ap) dvp = ap->a_dvp; vpp = ap->a_vpp; - vp = NULLVP; - lvp = NULLVP; - uvp = NULLVP; - tvp = NULLVP; + vp = NULL; + lvp = NULL; + uvp = NULL; + tvp = NULL; unp = NULL; dunp = VTOUNIONFS(dvp); @@ -2819,11 +2815,11 @@ unionfs_vput_pair(struct vop_vput_pair_args *ap) if (vpp != NULL) vp = *vpp; - if (vp != NULLVP) { + if (vp != NULL) { unp = VTOUNIONFS(vp); uvp = unp->un_uppervp; lvp = unp->un_lowervp; - if (uvp != NULLVP) + if (uvp != NULL) tvp = uvp; else tvp = lvp; @@ -2838,9 +2834,9 @@ unionfs_vput_pair(struct vop_vput_pair_args *ap) */ if (!ap->a_unlock_vp) { vhold(vp); - if (uvp != NULLVP) + if (uvp != NULL) vhold(uvp); - if (lvp != NULLVP) + if (lvp != NULL) vhold(lvp); mp = vp->v_mount; vfs_ref(mp); @@ -2850,12 +2846,12 @@ unionfs_vput_pair(struct vop_vput_pair_args *ap) ASSERT_VOP_LOCKED(tdvp, __func__); ASSERT_VOP_LOCKED(tvp, __func__); - if (tdvp == dunp->un_uppervp && tvp != NULLVP && tvp == lvp) { + if (tdvp == dunp->un_uppervp && tvp != NULL && tvp == lvp) { vput(tvp); vput(tdvp); res = 0; } else { - res = VOP_VPUT_PAIR(tdvp, tvp != NULLVP ? &tvp : NULL, true); + res = VOP_VPUT_PAIR(tdvp, tvp != NULL ? &tvp : NULL, true); } ASSERT_VOP_UNLOCKED(tdvp, __func__); @@ -2865,11 +2861,11 @@ unionfs_vput_pair(struct vop_vput_pair_args *ap) * VOP_VPUT_PAIR() dropped the references we added to the underlying * vnodes, now drop the caller's reference to the unionfs vnodes. */ - if (vp != NULLVP && ap->a_unlock_vp) + if (vp != NULL && ap->a_unlock_vp) vrele(vp); vrele(dvp); - if (vp == NULLVP || ap->a_unlock_vp) + if (vp == NULL || ap->a_unlock_vp) return (res); /* @@ -2887,9 +2883,9 @@ unionfs_vput_pair(struct vop_vput_pair_args *ap) vget(vp, LK_EXCLUSIVE | LK_RETRY); vfs_unbusy(mp); } - if (lvp != NULLVP) + if (lvp != NULL) vdrop(lvp); - if (uvp != NULLVP) + if (uvp != NULL) vdrop(uvp); vdrop(vp); vfs_rel(mp); |
