summaryrefslogtreecommitdiff
path: root/sys/ufs
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2018-01-09 10:51:44 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2018-01-09 10:51:44 +0000
commitc999b435276a735c04758efb44cfb41b2427ab22 (patch)
treee64e96f5827bb0aac3c876d161941e7b7db0f653 /sys/ufs
parente51e3c7e73a9c284f2f071d0868ef74de0bf19b6 (diff)
downloadsrc-test2-c999b435276a735c04758efb44cfb41b2427ab22.tar.gz
src-test2-c999b435276a735c04758efb44cfb41b2427ab22.zip
Notes
Diffstat (limited to 'sys/ufs')
-rw-r--r--sys/ufs/ffs/ffs_softdep.c79
1 files changed, 45 insertions, 34 deletions
diff --git a/sys/ufs/ffs/ffs_softdep.c b/sys/ufs/ffs/ffs_softdep.c
index 04d8220f130e..d6076020190b 100644
--- a/sys/ufs/ffs/ffs_softdep.c
+++ b/sys/ufs/ffs/ffs_softdep.c
@@ -906,6 +906,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 *);
@@ -7249,9 +7250,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) {
@@ -9976,9 +9977,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 */
@@ -10978,9 +10979,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
@@ -11020,8 +11021,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;
@@ -13895,6 +13897,39 @@ 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) {
+ 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
@@ -13918,36 +13953,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) {