Give vn_isdisk() a second argument where it can return a suitable errno.

Suggested by:	bde
This commit is contained in:
Poul-Henning Kamp 2000-01-10 12:04:27 +00:00
parent 54294f4494
commit ba4ad1fcea
26 changed files with 90 additions and 79 deletions

View File

@ -3744,7 +3744,7 @@ softdep_fsync_mountdev(vp)
struct buf *bp, *nbp;
struct worklist *wk;
if (!vn_isdisk(vp))
if (!vn_isdisk(vp, NULL))
panic("softdep_fsync_mountdev: vnode not a disk");
ACQUIRE_LOCK(&lk);
for (bp = TAILQ_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) {
@ -3806,7 +3806,7 @@ softdep_sync_metadata(ap)
* Check whether this vnode is involved in a filesystem
* that is doing soft dependency processing.
*/
if (!vn_isdisk(vp)) {
if (!vn_isdisk(vp, NULL)) {
if (!DOINGSOFTDEP(vp))
return (0);
} else
@ -4031,7 +4031,8 @@ softdep_sync_metadata(ap)
* way to accomplish this is to sync the entire filesystem (luckily
* this happens rarely).
*/
if (vn_isdisk(vp) && vp->v_specmountpoint && !VOP_ISLOCKED(vp, NULL) &&
if (vn_isdisk(vp, NULL) &&
vp->v_specmountpoint && !VOP_ISLOCKED(vp, NULL) &&
(error = VFS_SYNC(vp->v_specmountpoint, MNT_WAIT, ap->a_cred,
ap->a_p)) != 0)
return (error);

View File

@ -1603,10 +1603,8 @@ ccdlookup(path, p, vpp)
goto bad;
}
if (!vn_isdisk(vp)) {
error = ENOTBLK;
if (!vn_isdisk(vp, &error))
goto bad;
}
#ifdef DEBUG
if (ccddebug & CCDB_VNODE)

View File

@ -77,16 +77,15 @@ open_drive(struct drive *drive, struct proc *p, int verbose)
drive->devicename,
drive->vp->v_usecount);
}
if (!vn_isdisk(drive->vp)) { /* only consider disks */
NDFREE(&nd, NDF_ONLY_PNBUF);
if (!vn_isdisk(drive->vp, &drive->lasterror)) { /* only consider disks */
NDFREE(&nd, NDF_ONLY_PNBUF);
VOP_UNLOCK(drive->vp, 0, drive->p);
close_drive(drive);
drive->lasterror = ENOTBLK;
if (verbose)
log(LOG_WARNING,
"vinum open_drive %s: Not a block device\n",
drive->devicename);
return ENOTBLK;
return drive->lasterror;
}
drive->vp->v_numoutput = 0;
VOP_UNLOCK(drive->vp, 0, drive->p);

View File

@ -220,9 +220,9 @@ cd9660_mount(mp, path, data, ndp, p)
vrele(devvp);
return (ENXIO);
}
if (!vn_isdisk(devvp)) {
if (!vn_isdisk(devvp, &error)) {
vrele(devvp);
return (ENOTBLK);
return (error);
}
/*

View File

@ -238,10 +238,8 @@ hpfs_mount (
devvp = ndp->ni_vp;
#if defined(__FreeBSD__)
if (!vn_isdisk(devvp)) {
err = ENOTBLK;
if (!vn_isdisk(devvp, &err))
goto error_2;
}
#else /* defined(__NetBSD__) */
if (devvp->v_type != VBLK) {
err = ENOTBLK;

View File

@ -291,9 +291,9 @@ msdosfs_mount(mp, path, data, ndp, p)
devvp = ndp->ni_vp;
NDFREE(ndp, NDF_ONLY_PNBUF);
if (!vn_isdisk(devvp)) {
if (!vn_isdisk(devvp, &error)) {
vrele(devvp);
return (ENOTBLK);
return (error);
}
/*
* If mount by non-root, then verify that user has necessary

View File

@ -321,10 +321,8 @@ ntfs_mount (
devvp = ndp->ni_vp;
#if defined(__FreeBSD__)
if (!vn_isdisk(devvp)) {
err = ENOTBLK;
if (!vn_isdisk(devvp, &err))
goto error_2;
}
#else
if (devvp->v_type != VBLK) {
err = ENOTBLK;

View File

@ -159,7 +159,8 @@ spec_open(ap)
* XXX: take this into account, and consequently they need to
* XXX: live in the diskslicing code. Some checks do.
*/
if (vn_isdisk(vp) && ap->a_cred != FSCRED && (ap->a_mode & FWRITE)) {
if (vn_isdisk(vp, NULL) && ap->a_cred != FSCRED &&
(ap->a_mode & FWRITE)) {
/*
* Never allow opens for write if the device is mounted R/W
*/
@ -204,7 +205,7 @@ spec_open(ap)
}
}
if (vn_isdisk(vp)) {
if (vn_isdisk(vp, NULL)) {
if (!dev->si_bsize_phys)
dev->si_bsize_phys = DEV_BSIZE;
}
@ -337,7 +338,7 @@ spec_fsync(ap)
struct buf *nbp;
int s;
if (!vn_isdisk(vp))
if (!vn_isdisk(vp, NULL))
return (0);
/*
@ -415,7 +416,7 @@ spec_strategy(ap)
* and write counts for disks that have associated filesystems.
*/
vp = ap->a_vp;
if (vn_isdisk(vp) && (mp = vp->v_specmountpoint) != NULL) {
if (vn_isdisk(vp, NULL) && (mp = vp->v_specmountpoint) != NULL) {
if ((bp->b_flags & B_READ) == 0) {
if (bp->b_lock.lk_lockholder == LK_KERNPROC)
mp->mnt_stat.f_asyncwrites++;
@ -640,7 +641,7 @@ spec_getpages(ap)
* block device is mounted. However, we can use v_rdev.
*/
if (vn_isdisk(vp))
if (vn_isdisk(vp, NULL))
blksiz = vp->v_rdev->si_bsize_phys;
else
blksiz = DEV_BSIZE;

View File

@ -1603,10 +1603,8 @@ ccdlookup(path, p, vpp)
goto bad;
}
if (!vn_isdisk(vp)) {
error = ENOTBLK;
if (!vn_isdisk(vp, &error))
goto bad;
}
#ifdef DEBUG
if (ccddebug & CCDB_VNODE)

View File

@ -268,9 +268,9 @@ ext2_mount(mp, path, data, ndp, p)
NDFREE(ndp, NDF_ONLY_PNBUF);
devvp = ndp->ni_vp;
if (!vn_isdisk(devvp)) {
if (!vn_isdisk(devvp, &error)) {
vrele(devvp);
return (ENOTBLK);
return (error);
}
/*

View File

@ -268,9 +268,9 @@ ext2_mount(mp, path, data, ndp, p)
NDFREE(ndp, NDF_ONLY_PNBUF);
devvp = ndp->ni_vp;
if (!vn_isdisk(devvp)) {
if (!vn_isdisk(devvp, &error)) {
vrele(devvp);
return (ENOTBLK);
return (error);
}
/*

View File

@ -220,9 +220,9 @@ cd9660_mount(mp, path, data, ndp, p)
vrele(devvp);
return (ENXIO);
}
if (!vn_isdisk(devvp)) {
if (!vn_isdisk(devvp, &error)) {
vrele(devvp);
return (ENOTBLK);
return (error);
}
/*

View File

@ -934,8 +934,8 @@ aio_qphysio(p, aiocbe)
vp = (struct vnode *)fp->f_data;
if (!vn_isdisk(vp))
return (-1);
if (!vn_isdisk(vp, &error))
return (error);
if (cb->aio_nbytes % vp->v_rdev->si_bsize_phys)
return (-1);

View File

@ -1016,7 +1016,7 @@ brelse(struct buf * bp)
*/
if ((bp->b_flags & B_VMIO)
&& !(bp->b_vp->v_tag == VT_NFS &&
!vn_isdisk(bp->b_vp) &&
!vn_isdisk(bp->b_vp, NULL) &&
(bp->b_flags & B_DELWRI) &&
(bp->b_xflags & BX_BKGRDINPROG))
) {
@ -2230,7 +2230,7 @@ getblk(struct vnode * vp, daddr_t blkno, int size, int slpflag, int slptimeo)
int bsize, maxsize, vmio;
off_t offset;
if (vn_isdisk(vp))
if (vn_isdisk(vp, NULL))
bsize = DEV_BSIZE;
else if (vp->v_mountedhere)
bsize = vp->v_mountedhere->mnt_stat.f_iosize;
@ -2817,7 +2817,7 @@ biodone(register struct buf * bp)
(int) m->pindex, (int)(foff >> 32),
(int) foff & 0xffffffff, resid, i);
#endif
if (!vn_isdisk(vp))
if (!vn_isdisk(vp, NULL))
#if !defined(MAX_PERF)
printf(" iosize: %ld, lblkno: %d, flags: 0x%lx, npages: %d\n",
bp->b_vp->v_mount->mnt_stat.f_iosize,

View File

@ -1012,7 +1012,7 @@ sched_sync(void)
* slot we are safe.
*/
if (TAILQ_EMPTY(&vp->v_dirtyblkhd) &&
!vn_isdisk(vp))
!vn_isdisk(vp, NULL))
panic("sched_sync: fsync failed vp %p tag %d", vp, vp->v_tag);
/*
* Put us back on the worklist. The worklist
@ -2516,7 +2516,7 @@ vfs_object_create(vp, p, cred)
vm_object_t object;
int error = 0;
if (!vn_isdisk(vp) && vn_canvmio(vp) == FALSE)
if (!vn_isdisk(vp, NULL) && vn_canvmio(vp) == FALSE)
return 0;
retry:
@ -2875,15 +2875,27 @@ vn_todev(vp)
* Check if vnode represents a disk device
*/
int
vn_isdisk(vp)
vn_isdisk(vp, errp)
struct vnode *vp;
int *errp;
{
if (vp->v_type != VBLK && vp->v_type != VCHR)
if (vp->v_type != VBLK && vp->v_type != VCHR) {
if (errp != NULL)
*errp = ENOTBLK;
return (0);
if (!devsw(vp->v_rdev))
}
if (!devsw(vp->v_rdev)) {
if (errp != NULL)
*errp = ENXIO;
return (0);
if (!(devsw(vp->v_rdev)->d_flags & D_DISK))
}
if (!(devsw(vp->v_rdev)->d_flags & D_DISK)) {
if (errp != NULL)
*errp = ENOTBLK;
return (0);
}
if (errp != NULL)
*errp = 0;
return (1);
}

View File

@ -1012,7 +1012,7 @@ sched_sync(void)
* slot we are safe.
*/
if (TAILQ_EMPTY(&vp->v_dirtyblkhd) &&
!vn_isdisk(vp))
!vn_isdisk(vp, NULL))
panic("sched_sync: fsync failed vp %p tag %d", vp, vp->v_tag);
/*
* Put us back on the worklist. The worklist
@ -2516,7 +2516,7 @@ vfs_object_create(vp, p, cred)
vm_object_t object;
int error = 0;
if (!vn_isdisk(vp) && vn_canvmio(vp) == FALSE)
if (!vn_isdisk(vp, NULL) && vn_canvmio(vp) == FALSE)
return 0;
retry:
@ -2875,15 +2875,27 @@ vn_todev(vp)
* Check if vnode represents a disk device
*/
int
vn_isdisk(vp)
vn_isdisk(vp, errp)
struct vnode *vp;
int *errp;
{
if (vp->v_type != VBLK && vp->v_type != VCHR)
if (vp->v_type != VBLK && vp->v_type != VCHR) {
if (errp != NULL)
*errp = ENOTBLK;
return (0);
if (!devsw(vp->v_rdev))
}
if (!devsw(vp->v_rdev)) {
if (errp != NULL)
*errp = ENXIO;
return (0);
if (!(devsw(vp->v_rdev)->d_flags & D_DISK))
}
if (!(devsw(vp->v_rdev)->d_flags & D_DISK)) {
if (errp != NULL)
*errp = ENOTBLK;
return (0);
}
if (errp != NULL)
*errp = 0;
return (1);
}

View File

@ -473,9 +473,7 @@ vn_stat(vp, sb, p)
if (vap->va_type == VREG) {
sb->st_blksize = vap->va_blocksize;
} else if ((vp->v_type == VBLK || vp->v_type == VCHR) &&
devsw(vp->v_rdev) && (devsw(vp->v_rdev)->d_flags & D_DISK)) {
/* XXX use vn_isdisk() above once VCHR is also disk */
} else if (vn_isdisk(vp, NULL)) {
sb->st_blksize = vp->v_rdev->si_bsize_best;
if (sb->st_blksize < vp->v_rdev->si_bsize_phys)
sb->st_blksize = vp->v_rdev->si_bsize_phys;

View File

@ -1316,7 +1316,7 @@ devfs_open( struct vop_open_args *ap)
if ( (dsw == NULL) || (dsw->d_open == NULL))
return ENXIO;
if (ap->a_cred != FSCRED && (ap->a_mode & FWRITE) &&
vn_isdisk(vp)) {
vn_isdisk(vp, NULL)) {
/*
* When running in very secure mode, do not allow
* opens for writing of any disk devices.

View File

@ -159,7 +159,8 @@ spec_open(ap)
* XXX: take this into account, and consequently they need to
* XXX: live in the diskslicing code. Some checks do.
*/
if (vn_isdisk(vp) && ap->a_cred != FSCRED && (ap->a_mode & FWRITE)) {
if (vn_isdisk(vp, NULL) && ap->a_cred != FSCRED &&
(ap->a_mode & FWRITE)) {
/*
* Never allow opens for write if the device is mounted R/W
*/
@ -204,7 +205,7 @@ spec_open(ap)
}
}
if (vn_isdisk(vp)) {
if (vn_isdisk(vp, NULL)) {
if (!dev->si_bsize_phys)
dev->si_bsize_phys = DEV_BSIZE;
}
@ -337,7 +338,7 @@ spec_fsync(ap)
struct buf *nbp;
int s;
if (!vn_isdisk(vp))
if (!vn_isdisk(vp, NULL))
return (0);
/*
@ -415,7 +416,7 @@ spec_strategy(ap)
* and write counts for disks that have associated filesystems.
*/
vp = ap->a_vp;
if (vn_isdisk(vp) && (mp = vp->v_specmountpoint) != NULL) {
if (vn_isdisk(vp, NULL) && (mp = vp->v_specmountpoint) != NULL) {
if ((bp->b_flags & B_READ) == 0) {
if (bp->b_lock.lk_lockholder == LK_KERNPROC)
mp->mnt_stat.f_asyncwrites++;
@ -640,7 +641,7 @@ spec_getpages(ap)
* block device is mounted. However, we can use v_rdev.
*/
if (vn_isdisk(vp))
if (vn_isdisk(vp, NULL))
blksiz = vp->v_rdev->si_bsize_phys;
else
blksiz = DEV_BSIZE;

View File

@ -291,9 +291,9 @@ msdosfs_mount(mp, path, data, ndp, p)
devvp = ndp->ni_vp;
NDFREE(ndp, NDF_ONLY_PNBUF);
if (!vn_isdisk(devvp)) {
if (!vn_isdisk(devvp, &error)) {
vrele(devvp);
return (ENOTBLK);
return (error);
}
/*
* If mount by non-root, then verify that user has necessary

View File

@ -321,10 +321,8 @@ ntfs_mount (
devvp = ndp->ni_vp;
#if defined(__FreeBSD__)
if (!vn_isdisk(devvp)) {
err = ENOTBLK;
if (!vn_isdisk(devvp, &err))
goto error_2;
}
#else
if (devvp->v_type != VBLK) {
err = ENOTBLK;

View File

@ -569,7 +569,7 @@ int vrecycle __P((struct vnode *vp, struct simplelock *inter_lkp,
struct proc *p));
int vn_close __P((struct vnode *vp,
int flags, struct ucred *cred, struct proc *p));
int vn_isdisk __P((struct vnode *vp));
int vn_isdisk __P((struct vnode *vp, int *errp));
int vn_lock __P((struct vnode *vp, int flags, struct proc *p));
#ifdef DEBUG_LOCKS
int debug_vn_lock __P((struct vnode *vp, int flags, struct proc *p,

View File

@ -3744,7 +3744,7 @@ softdep_fsync_mountdev(vp)
struct buf *bp, *nbp;
struct worklist *wk;
if (!vn_isdisk(vp))
if (!vn_isdisk(vp, NULL))
panic("softdep_fsync_mountdev: vnode not a disk");
ACQUIRE_LOCK(&lk);
for (bp = TAILQ_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) {
@ -3806,7 +3806,7 @@ softdep_sync_metadata(ap)
* Check whether this vnode is involved in a filesystem
* that is doing soft dependency processing.
*/
if (!vn_isdisk(vp)) {
if (!vn_isdisk(vp, NULL)) {
if (!DOINGSOFTDEP(vp))
return (0);
} else
@ -4031,7 +4031,8 @@ softdep_sync_metadata(ap)
* way to accomplish this is to sync the entire filesystem (luckily
* this happens rarely).
*/
if (vn_isdisk(vp) && vp->v_specmountpoint && !VOP_ISLOCKED(vp, NULL) &&
if (vn_isdisk(vp, NULL) &&
vp->v_specmountpoint && !VOP_ISLOCKED(vp, NULL) &&
(error = VFS_SYNC(vp->v_specmountpoint, MNT_WAIT, ap->a_cred,
ap->a_p)) != 0)
return (error);

View File

@ -280,10 +280,8 @@ ffs_mount( mp, path, data, ndp, p)
NDFREE(ndp, NDF_ONLY_PNBUF);
devvp = ndp->ni_vp;
if (!vn_isdisk(devvp)) {
err = ENOTBLK;
if (!vn_isdisk(devvp, &err))
goto error_2;
}
/*
* If mount by non-root, then verify that user has necessary
@ -442,7 +440,7 @@ ffs_reload(mp, cred, p)
* Only VMIO the backing device if the backing device is a real
* block device. See ffs_mountmfs() for more details.
*/
if (devvp->v_tag != VT_MFS && vn_isdisk(devvp)) {
if (devvp->v_tag != VT_MFS && vn_isdisk(devvp, NULL)) {
vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, p);
vfs_object_create(devvp, p, p->p_ucred);
simple_lock(&devvp->v_interlock);
@ -599,7 +597,7 @@ ffs_mountfs(devvp, mp, p, malloctype)
* Note that it is optional that the backing device be VMIOed. This
* increases the opportunity for metadata caching.
*/
if (devvp->v_tag != VT_MFS && vn_isdisk(devvp)) {
if (devvp->v_tag != VT_MFS && vn_isdisk(devvp, NULL)) {
vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, p);
vfs_object_create(devvp, p, p->p_ucred);
simple_lock(&devvp->v_interlock);

View File

@ -126,9 +126,8 @@ ffs_fsync(ap)
int s, error, wait, passes, skipmeta;
daddr_t lbn;
wait = (ap->a_waitfor == MNT_WAIT);
if (vn_isdisk(vp)) {
if (vn_isdisk(vp, NULL)) {
lbn = INT_MAX;
if (vp->v_specmountpoint != NULL &&
(vp->v_specmountpoint->mnt_flag & MNT_SOFTDEP))
@ -265,7 +264,7 @@ ffs_fsync(ap)
goto loop;
}
#ifdef DIAGNOSTIC
if (!vn_isdisk(vp))
if (!vn_isdisk(vp, NULL))
vprint("ffs_fsync: dirty", vp);
#endif
}

View File

@ -202,8 +202,7 @@ swapon(p, uap)
NDFREE(&nd, NDF_ONLY_PNBUF);
vp = nd.ni_vp;
if (!vn_isdisk(vp))
error = ENOTBLK;
vn_isdisk(vp, &error);
if (!error)
error = swaponvp(p, vp, vp->v_rdev, 0);