From 7ad2a82da2b51b8c803c82a460e513f58f5a1737 Mon Sep 17 00:00:00 2001 From: Mateusz Guzik Date: Wed, 19 Aug 2020 02:51:17 +0000 Subject: [PATCH] vfs: drop the error parameter from vn_isdisk, introduce vn_isdisk_error Most consumers pass NULL. --- sys/cam/ctl/ctl_backend_block.c | 4 ++-- sys/compat/linux/linux_stats.c | 4 ++-- sys/dev/xen/blkback/blkback.c | 2 +- sys/fs/cd9660/cd9660_vfsops.c | 2 +- sys/fs/ext2fs/ext2_vfsops.c | 2 +- sys/fs/msdosfs/msdosfs_vfsops.c | 2 +- sys/fs/udf/udf_vfsops.c | 2 +- sys/kern/vfs_aio.c | 2 +- sys/kern/vfs_bio.c | 8 ++++---- sys/kern/vfs_subr.c | 15 +++++++++++---- sys/sys/vnode.h | 3 ++- sys/ufs/ffs/ffs_softdep.c | 2 +- sys/ufs/ffs/ffs_vfsops.c | 2 +- sys/vm/swap_pager.c | 8 ++++---- sys/vm/vnode_pager.c | 4 ++-- 15 files changed, 35 insertions(+), 27 deletions(-) diff --git a/sys/cam/ctl/ctl_backend_block.c b/sys/cam/ctl/ctl_backend_block.c index 2953a8fb6e32..643be93d8318 100644 --- a/sys/cam/ctl/ctl_backend_block.c +++ b/sys/cam/ctl/ctl_backend_block.c @@ -2184,7 +2184,7 @@ again: be_lun->vn = nd.ni_vp; /* We only support disks and files. */ - if (vn_isdisk(be_lun->vn, &error)) { + if (vn_isdisk_error(be_lun->vn, &error)) { error = ctl_be_block_open_dev(be_lun, req); } else if (be_lun->vn->v_type == VREG) { error = ctl_be_block_open_file(be_lun, req); @@ -2547,7 +2547,7 @@ ctl_be_block_modify(struct ctl_be_block_softc *softc, struct ctl_lun_req *req) control_softc->ha_mode == CTL_HA_MODE_SER_ONLY) { if (be_lun->vn == NULL) error = ctl_be_block_open(be_lun, req); - else if (vn_isdisk(be_lun->vn, &error)) + else if (vn_isdisk_error(be_lun->vn, &error)) error = ctl_be_block_open_dev(be_lun, req); else if (be_lun->vn->v_type == VREG) { vn_lock(be_lun->vn, LK_SHARED | LK_RETRY); diff --git a/sys/compat/linux/linux_stats.c b/sys/compat/linux/linux_stats.c index 33c9609022e0..5304590fc485 100644 --- a/sys/compat/linux/linux_stats.c +++ b/sys/compat/linux/linux_stats.c @@ -65,7 +65,7 @@ translate_vnhook_major_minor(struct vnode *vp, struct stat *sb) { int major, minor; - if (vn_isdisk(vp, NULL)) { + if (vn_isdisk(vp)) { sb->st_mode &= ~S_IFMT; sb->st_mode |= S_IFBLK; } @@ -131,7 +131,7 @@ translate_fd_major_minor(struct thread *td, int fd, struct stat *buf) fget(td, fd, &cap_no_rights, &fp) != 0) return; vp = fp->f_vnode; - if (vp != NULL && vn_isdisk(vp, NULL)) { + if (vp != NULL && vn_isdisk(vp)) { buf->st_mode &= ~S_IFMT; buf->st_mode |= S_IFBLK; } diff --git a/sys/dev/xen/blkback/blkback.c b/sys/dev/xen/blkback/blkback.c index 8d8452f21a3f..bbb2b04f3d73 100644 --- a/sys/dev/xen/blkback/blkback.c +++ b/sys/dev/xen/blkback/blkback.c @@ -2735,7 +2735,7 @@ xbb_open_backend(struct xbb_softc *xbb) xbb->vn = nd.ni_vp; /* We only support disks and files. */ - if (vn_isdisk(xbb->vn, &error)) { + if (vn_isdisk_error(xbb->vn, &error)) { error = xbb_open_dev(xbb); } else if (xbb->vn->v_type == VREG) { error = xbb_open_file(xbb); diff --git a/sys/fs/cd9660/cd9660_vfsops.c b/sys/fs/cd9660/cd9660_vfsops.c index ceaaca827147..4300b4468054 100644 --- a/sys/fs/cd9660/cd9660_vfsops.c +++ b/sys/fs/cd9660/cd9660_vfsops.c @@ -165,7 +165,7 @@ cd9660_mount(struct mount *mp) NDFREE(&ndp, NDF_ONLY_PNBUF); devvp = ndp.ni_vp; - if (!vn_isdisk(devvp, &error)) { + if (!vn_isdisk_error(devvp, &error)) { vput(devvp); return (error); } diff --git a/sys/fs/ext2fs/ext2_vfsops.c b/sys/fs/ext2fs/ext2_vfsops.c index 5aff9bdb2ff2..4fc67773c663 100644 --- a/sys/fs/ext2fs/ext2_vfsops.c +++ b/sys/fs/ext2fs/ext2_vfsops.c @@ -247,7 +247,7 @@ ext2_mount(struct mount *mp) NDFREE(ndp, NDF_ONLY_PNBUF); devvp = ndp->ni_vp; - if (!vn_isdisk(devvp, &error)) { + if (!vn_isdisk_error(devvp, &error)) { vput(devvp); return (error); } diff --git a/sys/fs/msdosfs/msdosfs_vfsops.c b/sys/fs/msdosfs/msdosfs_vfsops.c index 8d0686469068..40da41aa7469 100644 --- a/sys/fs/msdosfs/msdosfs_vfsops.c +++ b/sys/fs/msdosfs/msdosfs_vfsops.c @@ -343,7 +343,7 @@ msdosfs_mount(struct mount *mp) devvp = ndp.ni_vp; NDFREE(&ndp, NDF_ONLY_PNBUF); - if (!vn_isdisk(devvp, &error)) { + if (!vn_isdisk_error(devvp, &error)) { vput(devvp); return (error); } diff --git a/sys/fs/udf/udf_vfsops.c b/sys/fs/udf/udf_vfsops.c index 0f30b5ef36e9..5a71640e3783 100644 --- a/sys/fs/udf/udf_vfsops.c +++ b/sys/fs/udf/udf_vfsops.c @@ -233,7 +233,7 @@ udf_mount(struct mount *mp) NDFREE(ndp, NDF_ONLY_PNBUF); devvp = ndp->ni_vp; - if (vn_isdisk(devvp, &error) == 0) { + if (!vn_isdisk_error(devvp, &error)) { vput(devvp); return (error); } diff --git a/sys/kern/vfs_aio.c b/sys/kern/vfs_aio.c index c0b55960abe5..9040865d7b0a 100644 --- a/sys/kern/vfs_aio.c +++ b/sys/kern/vfs_aio.c @@ -1972,7 +1972,7 @@ sys_aio_cancel(struct thread *td, struct aio_cancel_args *uap) if (fp->f_type == DTYPE_VNODE) { vp = fp->f_vnode; - if (vn_isdisk(vp, &error)) { + if (vn_isdisk(vp)) { fdrop(fp, td); td->td_retval[0] = AIO_NOTCANCELED; return (0); diff --git a/sys/kern/vfs_bio.c b/sys/kern/vfs_bio.c index adc44082d972..9ff8628e9b10 100644 --- a/sys/kern/vfs_bio.c +++ b/sys/kern/vfs_bio.c @@ -2724,7 +2724,7 @@ brelse(struct buf *bp) if ((bp->b_flags & B_VMIO) && (bp->b_flags & B_NOCACHE || (bp->b_ioflags & BIO_ERROR && bp->b_iocmd == BIO_READ)) && (v_mnt == NULL || (v_mnt->mnt_vfc->vfc_flags & VFCF_NETWORK) == 0 || - vn_isdisk(bp->b_vp, NULL) || (bp->b_flags & B_DELWRI) == 0)) { + vn_isdisk(bp->b_vp) || (bp->b_flags & B_DELWRI) == 0)) { vfs_vmio_invalidate(bp); allocbuf(bp, 0); } @@ -3757,7 +3757,7 @@ bp_unmapped_get_kva(struct buf *bp, daddr_t blkno, int size, int gbflags) * Calculate the amount of the address space we would reserve * if the buffer was mapped. */ - bsize = vn_isdisk(bp->b_vp, NULL) ? DEV_BSIZE : bp->b_bufobj->bo_bsize; + bsize = vn_isdisk(bp->b_vp) ? DEV_BSIZE : bp->b_bufobj->bo_bsize; KASSERT(bsize != 0, ("bsize == 0, check bo->bo_bsize")); offset = blkno * bsize; maxsize = size + (offset & PAGE_MASK); @@ -4013,7 +4013,7 @@ newbuf_unlocked: if (flags & GB_NOCREAT) return (EEXIST); - bsize = vn_isdisk(vp, NULL) ? DEV_BSIZE : bo->bo_bsize; + bsize = vn_isdisk(vp) ? DEV_BSIZE : bo->bo_bsize; KASSERT(bsize != 0, ("bsize == 0, check bo->bo_bsize")); offset = blkno * bsize; vmio = vp->v_object != NULL; @@ -4026,7 +4026,7 @@ newbuf_unlocked: } maxsize = imax(maxsize, bsize); if ((flags & GB_NOSPARSE) != 0 && vmio && - !vn_isdisk(vp, NULL)) { + !vn_isdisk(vp)) { error = VOP_BMAP(vp, blkno, NULL, &d_blkno, 0, 0); KASSERT(error != EOPNOTSUPP, ("GB_NOSPARSE from fs not supporting bmap, vp %p", diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index 2df609d9118b..388e576fcde4 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -4977,8 +4977,8 @@ vn_need_pageq_flush(struct vnode *vp) /* * Check if vnode represents a disk device */ -int -vn_isdisk(struct vnode *vp, int *errp) +bool +vn_isdisk_error(struct vnode *vp, int *errp) { int error; @@ -4996,11 +4996,18 @@ vn_isdisk(struct vnode *vp, int *errp) error = ENOTBLK; dev_unlock(); out: - if (errp != NULL) - *errp = error; + *errp = error; return (error == 0); } +bool +vn_isdisk(struct vnode *vp) +{ + int error; + + return (vn_isdisk_error(vp, &error)); +} + /* * VOP_FPLOOKUP_VEXEC routines are subject to special circumstances, see * the comment above cache_fplookup for details. diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h index ef58d54d0b47..2cb951d4ffd2 100644 --- a/sys/sys/vnode.h +++ b/sys/sys/vnode.h @@ -718,7 +718,8 @@ int vn_generic_copy_file_range(struct vnode *invp, off_t *inoffp, unsigned int flags, struct ucred *incred, struct ucred *outcred, struct thread *fsize_td); int vn_need_pageq_flush(struct vnode *vp); -int vn_isdisk(struct vnode *vp, int *errp); +bool vn_isdisk_error(struct vnode *vp, int *errp); +bool vn_isdisk(struct vnode *vp); int _vn_lock(struct vnode *vp, int flags, const char *file, int line); #define vn_lock(vp, flags) _vn_lock(vp, flags, __FILE__, __LINE__) int vn_open(struct nameidata *ndp, int *flagp, int cmode, struct file *fp); diff --git a/sys/ufs/ffs/ffs_softdep.c b/sys/ufs/ffs/ffs_softdep.c index 577ddfa7e8d2..768604f03001 100644 --- a/sys/ufs/ffs/ffs_softdep.c +++ b/sys/ufs/ffs/ffs_softdep.c @@ -12723,7 +12723,7 @@ softdep_fsync_mountdev(vp) struct worklist *wk; struct bufobj *bo; - if (!vn_isdisk(vp, NULL)) + if (!vn_isdisk(vp)) panic("softdep_fsync_mountdev: vnode not a disk"); bo = &vp->v_bufobj; restart: diff --git a/sys/ufs/ffs/ffs_vfsops.c b/sys/ufs/ffs/ffs_vfsops.c index e02af7499c1f..ae6e9fa907d3 100644 --- a/sys/ufs/ffs/ffs_vfsops.c +++ b/sys/ufs/ffs/ffs_vfsops.c @@ -728,7 +728,7 @@ ffs_mount(struct mount *mp) return (error); NDFREE(&ndp, NDF_ONLY_PNBUF); devvp = ndp.ni_vp; - if (!vn_isdisk(devvp, &error)) { + if (!vn_isdisk_error(devvp, &error)) { vput(devvp); return (error); } diff --git a/sys/vm/swap_pager.c b/sys/vm/swap_pager.c index fee8d1474c45..128870606f06 100644 --- a/sys/vm/swap_pager.c +++ b/sys/vm/swap_pager.c @@ -919,7 +919,7 @@ sysctl_swap_fragmentation(SYSCTL_HANDLER_ARGS) sbuf_new_for_sysctl(&sbuf, NULL, 128, req); mtx_lock(&sw_dev_mtx); TAILQ_FOREACH(sp, &swtailq, sw_list) { - if (vn_isdisk(sp->sw_vp, NULL)) + if (vn_isdisk(sp->sw_vp)) devname = devtoname(sp->sw_vp->v_rdev); else devname = "[file]"; @@ -2325,7 +2325,7 @@ sys_swapon(struct thread *td, struct swapon_args *uap) NDFREE(&nd, NDF_ONLY_PNBUF); vp = nd.ni_vp; - if (vn_isdisk(vp, &error)) { + if (vn_isdisk_error(vp, &error)) { error = swapongeom(vp); } else if (vp->v_type == VREG && (vp->v_mount->mnt_vfc->vfc_flags & VFCF_NETWORK) != 0 && @@ -2548,7 +2548,7 @@ swapoff_all(void) mtx_lock(&sw_dev_mtx); TAILQ_FOREACH_SAFE(sp, &swtailq, sw_list, spt) { mtx_unlock(&sw_dev_mtx); - if (vn_isdisk(sp->sw_vp, NULL)) + if (vn_isdisk(sp->sw_vp)) devname = devtoname(sp->sw_vp->v_rdev); else devname = "[file]"; @@ -2596,7 +2596,7 @@ swap_dev_info(int name, struct xswdev *xs, char *devname, size_t len) xs->xsw_nblks = sp->sw_nblks; xs->xsw_used = sp->sw_used; if (devname != NULL) { - if (vn_isdisk(sp->sw_vp, NULL)) + if (vn_isdisk(sp->sw_vp)) tmp_devname = devtoname(sp->sw_vp->v_rdev); else tmp_devname = "[file]"; diff --git a/sys/vm/vnode_pager.c b/sys/vm/vnode_pager.c index f10153235b30..72ef91487352 100644 --- a/sys/vm/vnode_pager.c +++ b/sys/vm/vnode_pager.c @@ -152,7 +152,7 @@ vnode_create_vobject(struct vnode *vp, off_t isize, struct thread *td) struct vattr va; bool last; - if (!vn_isdisk(vp, NULL) && vn_canvmio(vp) == FALSE) + if (!vn_isdisk(vp) && vn_canvmio(vp) == FALSE) return (0); object = vp->v_object; @@ -160,7 +160,7 @@ vnode_create_vobject(struct vnode *vp, off_t isize, struct thread *td) return (0); if (size == 0) { - if (vn_isdisk(vp, NULL)) { + if (vn_isdisk(vp)) { size = IDX_TO_OFF(INT_MAX); } else { if (VOP_GETATTR(vp, &va, td->td_ucred))