Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/vfs_vnops.c
| Show First 20 Lines • Show All 2,419 Lines • ▼ Show 20 Lines | vn_pages_remove(struct vnode *vp, vm_pindex_t start, vm_pindex_t end) | ||||
| if ((object = vp->v_object) == NULL) | if ((object = vp->v_object) == NULL) | ||||
| return; | return; | ||||
| VM_OBJECT_WLOCK(object); | VM_OBJECT_WLOCK(object); | ||||
| vm_object_page_remove(object, start, end, 0); | vm_object_page_remove(object, start, end, 0); | ||||
| VM_OBJECT_WUNLOCK(object); | VM_OBJECT_WUNLOCK(object); | ||||
| } | } | ||||
| int | int | ||||
| vn_bmap_seekhole(struct vnode *vp, u_long cmd, off_t *off, struct ucred *cred) | vn_bmap_seekhole_locked(struct vnode *vp, u_long cmd, off_t *off, | ||||
| struct ucred *cred) | |||||
| { | { | ||||
| struct vattr va; | struct vattr va; | ||||
| daddr_t bn, bnp; | daddr_t bn, bnp; | ||||
| uint64_t bsize; | uint64_t bsize; | ||||
| off_t noff; | off_t noff; | ||||
| int error; | int error; | ||||
| KASSERT(cmd == FIOSEEKHOLE || cmd == FIOSEEKDATA, | KASSERT(cmd == FIOSEEKHOLE || cmd == FIOSEEKDATA, | ||||
| ("Wrong command %lu", cmd)); | ("%s: Wrong command %lu", __func__, cmd)); | ||||
| ASSERT_VOP_LOCKED(vp, "vn_bmap_seekhole_locked"); | |||||
| if (vn_lock(vp, LK_SHARED) != 0) | |||||
| return (EBADF); | |||||
| if (vp->v_type != VREG) { | if (vp->v_type != VREG) { | ||||
| error = ENOTTY; | error = ENOTTY; | ||||
| goto unlock; | goto out; | ||||
| } | } | ||||
| error = VOP_GETATTR(vp, &va, cred); | error = VOP_GETATTR(vp, &va, cred); | ||||
| if (error != 0) | if (error != 0) | ||||
| goto unlock; | goto out; | ||||
| noff = *off; | noff = *off; | ||||
| if (noff >= va.va_size) { | if (noff >= va.va_size) { | ||||
| error = ENXIO; | error = ENXIO; | ||||
| goto unlock; | goto out; | ||||
| } | } | ||||
| bsize = vp->v_mount->mnt_stat.f_iosize; | bsize = vp->v_mount->mnt_stat.f_iosize; | ||||
| for (bn = noff / bsize; noff < va.va_size; bn++, noff += bsize - | for (bn = noff / bsize; noff < va.va_size; bn++, noff += bsize - | ||||
| noff % bsize) { | noff % bsize) { | ||||
| error = VOP_BMAP(vp, bn, NULL, &bnp, NULL, NULL); | error = VOP_BMAP(vp, bn, NULL, &bnp, NULL, NULL); | ||||
| if (error == EOPNOTSUPP) { | if (error == EOPNOTSUPP) { | ||||
| error = ENOTTY; | error = ENOTTY; | ||||
| goto unlock; | goto out; | ||||
| } | } | ||||
| if ((bnp == -1 && cmd == FIOSEEKHOLE) || | if ((bnp == -1 && cmd == FIOSEEKHOLE) || | ||||
| (bnp != -1 && cmd == FIOSEEKDATA)) { | (bnp != -1 && cmd == FIOSEEKDATA)) { | ||||
| noff = bn * bsize; | noff = bn * bsize; | ||||
| if (noff < *off) | if (noff < *off) | ||||
| noff = *off; | noff = *off; | ||||
| goto unlock; | goto out; | ||||
markj: This is the only place that really needs a goto, the rest can `return (mumble)`. I don't insist… | |||||
| } | } | ||||
| } | } | ||||
| if (noff > va.va_size) | if (noff > va.va_size) | ||||
| noff = va.va_size; | noff = va.va_size; | ||||
| /* noff == va.va_size. There is an implicit hole at the end of file. */ | /* noff == va.va_size. There is an implicit hole at the end of file. */ | ||||
| if (cmd == FIOSEEKDATA) | if (cmd == FIOSEEKDATA) | ||||
| error = ENXIO; | error = ENXIO; | ||||
| unlock: | out: | ||||
| VOP_UNLOCK(vp); | |||||
| if (error == 0) | if (error == 0) | ||||
| *off = noff; | *off = noff; | ||||
| return (error); | |||||
| } | |||||
| int | |||||
| vn_bmap_seekhole(struct vnode *vp, u_long cmd, off_t *off, struct ucred *cred) | |||||
| { | |||||
| int error; | |||||
| KASSERT(cmd == FIOSEEKHOLE || cmd == FIOSEEKDATA, | |||||
| ("%s: Wrong command %lu", __func__, cmd)); | |||||
| if (vn_lock(vp, LK_SHARED) != 0) | |||||
| return (EBADF); | |||||
| error = vn_bmap_seekhole_locked(vp, cmd, off, cred); | |||||
| VOP_UNLOCK(vp); | |||||
| return (error); | return (error); | ||||
| } | } | ||||
| int | int | ||||
| vn_seek(struct file *fp, off_t offset, int whence, struct thread *td) | vn_seek(struct file *fp, off_t offset, int whence, struct thread *td) | ||||
| { | { | ||||
| struct ucred *cred; | struct ucred *cred; | ||||
| struct vnode *vp; | struct vnode *vp; | ||||
| ▲ Show 20 Lines • Show All 1,043 Lines • Show Last 20 Lines | |||||
This is the only place that really needs a goto, the rest can return (mumble). I don't insist on changing the diff, though.