On 08 Apr 2015, at 15:03, Ted Unangst <t...@tedunangst.com> wrote: > Also, this only helps if you're sure that the code reading the flag will do so > in an smp safe way. In many cases, the reading code will also need to acquire > a lock in order to correctly do something after reading the flag. From the > diff context, it looks like most of this code will definitely already have > some other lock. What do you think about f_offset protection? Lock file struct object within of_read or fo_write routine? For example for vn_read()
int vn_read(struct file *fp, off_t *poff, struct uio *uio, struct ucred *cred) { struct vnode *vp = (struct vnode *)fp->f_data; int error = 0; size_t count = uio->uio_resid; struct proc *p = uio->uio_procp; FILE_LOCK(fp); /* no wrap around of offsets except on character devices */ if (vp->v_type != VCHR && count > LLONG_MAX - *poff) { FILE_UNLOCK(fp); return (EINVAL); } vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); uio->uio_offset = *poff; if (vp->v_type != VDIR) error = VOP_READ(vp, uio, (fp->f_flag & FNONBLOCK) ? IO_NDELAY : 0, cred); *poff += count - uio->uio_resid; VOP_UNLOCK(vp, 0, p); FILE_UNLOCK(fp); return (error); } Is it a good idea?