Add descrip_check_write_mp() helper

... which verifies that given file table does not have file descriptors
referencing vnodes on the specified mount point.  It is up to the caller
to ensure that the check is not racy.

Reviewed by:	mckusick
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D37896
This commit is contained in:
Konstantin Belousov 2022-12-28 20:13:01 +02:00
parent 4ac8f40670
commit 37b9fb1696
2 changed files with 25 additions and 0 deletions

View File

@ -4172,6 +4172,29 @@ mountcheckdirs(struct vnode *olddp, struct vnode *newdp)
vrele(olddp);
}
int
descrip_check_write_mp(struct filedesc *fdp, struct mount *mp)
{
struct file *fp;
struct vnode *vp;
int error, i;
error = 0;
FILEDESC_SLOCK(fdp);
FILEDESC_FOREACH_FP(fdp, i, fp) {
if (fp->f_type != DTYPE_VNODE ||
(atomic_load_int(&fp->f_flag) & FWRITE) == 0)
continue;
vp = fp->f_vnode;
if (vp->v_mount == mp) {
error = EDEADLK;
break;
}
}
FILEDESC_SUNLOCK(fdp);
return (error);
}
struct filedesc_to_leader *
filedesc_to_leader_alloc(struct filedesc_to_leader *old, struct filedesc *fdp,
struct proc *leader)

View File

@ -225,6 +225,7 @@ enum {
#define falloc(td, resultfp, resultfd, flags) \
falloc_caps(td, resultfp, resultfd, flags, NULL)
struct mount;
struct thread;
static __inline void
@ -241,6 +242,7 @@ void filecaps_free(struct filecaps *fcaps);
int closef(struct file *fp, struct thread *td);
void closef_nothread(struct file *fp);
int descrip_check_write_mp(struct filedesc *fdp, struct mount *mp);
int dupfdopen(struct thread *td, struct filedesc *fdp, int dfd, int mode,
int openerror, int *indxp);
int falloc_caps(struct thread *td, struct file **resultfp, int *resultfd,