diff options
author | kib <kib@FreeBSD.org> | 2018-01-16 10:58:31 +0000 |
---|---|---|
committer | kib <kib@FreeBSD.org> | 2018-01-16 10:58:31 +0000 |
commit | 397b6ec550aef190d456f3d9c8c7c7a8d52d608c (patch) | |
tree | ef9579e3cc2d4d8f239ce249dcfbc5afb12f1183 /sys/ufs | |
parent | ed3319b0fa55d62c258f5e38cebbafecd6eccca3 (diff) | |
download | FreeBSD-src-397b6ec550aef190d456f3d9c8c7c7a8d52d608c.zip FreeBSD-src-397b6ec550aef190d456f3d9c8c7c7a8d52d608c.tar.gz |
MFC r327723, r327821:
Generalize the fix from r322757 and apply it to several more places.
Diffstat (limited to 'sys/ufs')
-rw-r--r-- | sys/ufs/ffs/ffs_softdep.c | 80 |
1 files changed, 46 insertions, 34 deletions
diff --git a/sys/ufs/ffs/ffs_softdep.c b/sys/ufs/ffs/ffs_softdep.c index 20c6f9c..6c82e6c 100644 --- a/sys/ufs/ffs/ffs_softdep.c +++ b/sys/ufs/ffs/ffs_softdep.c @@ -904,6 +904,7 @@ static int request_cleanup(struct mount *, int); static int softdep_request_cleanup_flush(struct mount *, struct ufsmount *); static void schedule_cleanup(struct mount *); static void softdep_ast_cleanup_proc(struct thread *); +static struct ufsmount *softdep_bp_to_mp(struct buf *bp); static int process_worklist_item(struct mount *, int, int); static void process_removes(struct vnode *); static void process_truncates(struct vnode *); @@ -7245,9 +7246,9 @@ deallocate_dependencies(bp, freeblks, off) struct worklist *wk, *wkn; struct ufsmount *ump; - if ((wk = LIST_FIRST(&bp->b_dep)) == NULL) + ump = softdep_bp_to_mp(bp); + if (ump == NULL) goto done; - ump = VFSTOUFS(wk->wk_mp); ACQUIRE_LOCK(ump); LIST_FOREACH_SAFE(wk, &bp->b_dep, wk_list, wkn) { switch (wk->wk_type) { @@ -9972,9 +9973,9 @@ softdep_disk_io_initiation(bp) panic("softdep_disk_io_initiation: Writing buffer with " "background write in progress: %p", bp); - if ((wk = LIST_FIRST(&bp->b_dep)) == NULL) + ump = softdep_bp_to_mp(bp); + if (ump == NULL) return; - ump = VFSTOUFS(wk->wk_mp); marker.wk_type = D_LAST + 1; /* Not a normal workitem */ PHOLD(curproc); /* Don't swap out kernel stack */ @@ -10974,9 +10975,9 @@ softdep_disk_write_complete(bp) struct freeblks *freeblks; struct buf *sbp; - if ((wk = LIST_FIRST(&bp->b_dep)) == NULL) + ump = softdep_bp_to_mp(bp); + if (ump == NULL) return; - ump = VFSTOUFS(wk->wk_mp); /* * If an error occurred while doing the write, then the data @@ -11016,8 +11017,9 @@ softdep_disk_write_complete(bp) return; } LIST_INIT(&reattach); + /* - * This lock must not be released anywhere in this code segment. + * Ump SU lock must not be released anywhere in this code segment. */ sbp = NULL; owk = NULL; @@ -13885,6 +13887,40 @@ softdep_freework(wkhd) FREE_LOCK(ump); } +static struct ufsmount * +softdep_bp_to_mp(bp) + struct buf *bp; +{ + struct mount *mp; + struct vnode *vp; + + if (LIST_EMPTY(&bp->b_dep)) + return (NULL); + vp = bp->b_vp; + + /* + * The ump mount point is stable after we get a correct + * pointer, since bp is locked and this prevents unmount from + * proceeding. But to get to it, we cannot dereference bp->b_dep + * head wk_mp, because we do not yet own SU ump lock and + * workitem might be freed while dereferenced. + */ +retry: + if (vp->v_type == VCHR) { + VI_LOCK(vp); + mp = vp->v_type == VCHR ? vp->v_rdev->si_mountpt : NULL; + VI_UNLOCK(vp); + if (mp == NULL) + goto retry; + } else if (vp->v_type == VREG || vp->v_type == VDIR || + vp->v_type == VLNK) { + mp = vp->v_mount; + } else { + return (NULL); + } + return (VFSTOUFS(mp)); +} + /* * Function to determine if the buffer has outstanding dependencies * that will cause a roll-back if the buffer is written. If wantcount @@ -13908,36 +13944,12 @@ softdep_count_dependencies(bp, wantcount) struct newblk *newblk; struct mkdir *mkdir; struct diradd *dap; - struct vnode *vp; - struct mount *mp; int i, retval; - retval = 0; - if (LIST_EMPTY(&bp->b_dep)) + ump = softdep_bp_to_mp(bp); + if (ump == NULL) return (0); - vp = bp->b_vp; - - /* - * The ump mount point is stable after we get a correct - * pointer, since bp is locked and this prevents unmount from - * proceed. But to get to it, we cannot dereference bp->b_dep - * head wk_mp, because we do not yet own SU ump lock and - * workitem might be freed while dereferenced. - */ -retry: - if (vp->v_type == VCHR) { - VI_LOCK(vp); - mp = vp->v_type == VCHR ? vp->v_rdev->si_mountpt : NULL; - VI_UNLOCK(vp); - if (mp == NULL) - goto retry; - } else if (vp->v_type == VREG) { - mp = vp->v_mount; - } else { - return (0); - } - ump = VFSTOUFS(mp); - + retval = 0; ACQUIRE_LOCK(ump); LIST_FOREACH(wk, &bp->b_dep, wk_list) { switch (wk->wk_type) { |