Skip to content

Instantly share code, notes, and snippets.

@coypoop
Last active May 19, 2016 12:40
Show Gist options
  • Save coypoop/5d8a94b65a45ee91b3d054453c4080b7 to your computer and use it in GitHub Desktop.
Save coypoop/5d8a94b65a45ee91b3d054453c4080b7 to your computer and use it in GitHub Desktop.
Combined all patches. you may have reservations about patches 4,5.
From dad83af033474363bbf4ce519adaab7190eceea5 Mon Sep 17 00:00:00 2001
From: coypu <coypu@sdf.org>
Date: Mon, 16 May 2016 18:24:56 +0300
Subject: [PATCH 1/6] Get rid of UFS_WAPBL_BEGIN1/END1
ufs makeinode no longer releases dvp, so incrementing the
usecount for wapbl is unnecessary.
---
sys/ufs/ufs/ufs_vnops.c | 16 ++++++++--------
sys/ufs/ufs/ufs_wapbl.h | 5 -----
2 files changed, 8 insertions(+), 13 deletions(-)
diff --git a/sys/ufs/ufs/ufs_vnops.c b/sys/ufs/ufs/ufs_vnops.c
index 8f0edc1..41154f5 100644
--- a/sys/ufs/ufs/ufs_vnops.c
+++ b/sys/ufs/ufs/ufs_vnops.c
@@ -151,7 +151,7 @@ ufs_create(void *v)
UFS_CHECK_CRAPCOUNTER(VTOI(dvp));
/*
- * UFS_WAPBL_BEGIN1(dvp->v_mount, dvp) performed by successful
+ * UFS_WAPBL_BEGIN(dvp->v_mount) performed by successful
* ufs_makeinode
*/
fstrans_start(dvp->v_mount, FSTRANS_SHARED);
@@ -160,7 +160,7 @@ ufs_create(void *v)
fstrans_done(dvp->v_mount);
return (error);
}
- UFS_WAPBL_END1(dvp->v_mount, dvp);
+ UFS_WAPBL_END(dvp->v_mount);
fstrans_done(dvp->v_mount);
VN_KNOTE(dvp, NOTE_WRITE);
VOP_UNLOCK(*ap->a_vpp);
@@ -194,7 +194,7 @@ ufs_mknod(void *v)
UFS_CHECK_CRAPCOUNTER(VTOI(ap->a_dvp));
/*
- * UFS_WAPBL_BEGIN1(dvp->v_mount, dvp) performed by successful
+ * UFS_WAPBL_BEGIN(dvp->v_mount) performed by successful
* ufs_makeinode
*/
fstrans_start(ap->a_dvp->v_mount, FSTRANS_SHARED);
@@ -204,7 +204,7 @@ ufs_mknod(void *v)
ip = VTOI(*vpp);
ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
UFS_WAPBL_UPDATE(*vpp, NULL, NULL, 0);
- UFS_WAPBL_END1(ap->a_dvp->v_mount, ap->a_dvp);
+ UFS_WAPBL_END(ap->a_dvp->v_mount);
VOP_UNLOCK(*vpp);
out:
fstrans_done(ap->a_dvp->v_mount);
@@ -1200,7 +1200,7 @@ ufs_symlink(void *v)
UFS_CHECK_CRAPCOUNTER(VTOI(ap->a_dvp));
/*
- * UFS_WAPBL_BEGIN1(dvp->v_mount, dvp) performed by successful
+ * UFS_WAPBL_BEGIN(dvp->v_mount) performed by successful
* ufs_makeinode
*/
fstrans_start(ap->a_dvp->v_mount, FSTRANS_SHARED);
@@ -1232,7 +1232,7 @@ ufs_symlink(void *v)
error = ufs_bufio(UIO_WRITE, vp, ap->a_target, len, (off_t)0,
IO_NODELOCKED | IO_JOURNALLOCKED, ap->a_cnp->cn_cred, NULL,
NULL);
- UFS_WAPBL_END1(ap->a_dvp->v_mount, ap->a_dvp);
+ UFS_WAPBL_END(ap->a_dvp->v_mount);
VOP_UNLOCK(vp);
if (error)
vrele(vp);
@@ -1784,7 +1784,7 @@ ufs_makeinode(struct vattr *vap, struct vnode *dvp,
}
*vpp = tvp;
ip = VTOI(tvp);
- error = UFS_WAPBL_BEGIN1(dvp->v_mount, dvp);
+ error = UFS_WAPBL_BEGIN(dvp->v_mount);
if (error) {
vput(tvp);
return (error);
@@ -1832,7 +1832,7 @@ ufs_makeinode(struct vattr *vap, struct vnode *dvp,
DIP_ASSIGN(ip, nlink, 0);
ip->i_flag |= IN_CHANGE;
UFS_WAPBL_UPDATE(tvp, NULL, NULL, 0);
- UFS_WAPBL_END1(dvp->v_mount, dvp);
+ UFS_WAPBL_END(dvp->v_mount);
vput(tvp);
return (error);
}
diff --git a/sys/ufs/ufs/ufs_wapbl.h b/sys/ufs/ufs/ufs_wapbl.h
index 1eab045..b8386cf 100644
--- a/sys/ufs/ufs/ufs_wapbl.h
+++ b/sys/ufs/ufs/ufs_wapbl.h
@@ -134,10 +134,7 @@ ufs_wapbl_end2(struct mount *mp, struct vnode *vp1, struct vnode *vp2)
#define UFS_WAPBL_BEGIN(mp) \
ufs_wapbl_begin2(mp, NULL, NULL, __FUNCTION__, __LINE__)
-#define UFS_WAPBL_BEGIN1(mp, v1) \
- ufs_wapbl_begin2(mp, v1, NULL, __FUNCTION__, __LINE__)
#define UFS_WAPBL_END(mp) ufs_wapbl_end2(mp, NULL, NULL)
-#define UFS_WAPBL_END1(mp, v1) ufs_wapbl_end2(mp, v1, NULL)
#define UFS_WAPBL_UPDATE(vp, access, modify, flags) \
if ((vp)->v_mount->mnt_wapbl) { \
@@ -164,9 +161,7 @@ ufs_wapbl_end2(struct mount *mp, struct vnode *vp1, struct vnode *vp2)
#else /* ! WAPBL */
#define UFS_WAPBL_BEGIN(mp) (__USE(mp), 0)
-#define UFS_WAPBL_BEGIN1(mp, v1) 0
#define UFS_WAPBL_END(mp) do { } while (0)
-#define UFS_WAPBL_END1(mp, v1)
#define UFS_WAPBL_UPDATE(vp, access, modify, flags) do { } while (0)
#define UFS_WAPBL_JLOCK_ASSERT(mp)
#define UFS_WAPBL_JUNLOCK_ASSERT(mp)
--
2.8.1
From 74a1a890f69351e9406ec53cde41f6cea882dc44 Mon Sep 17 00:00:00 2001
From: coypu <coypu@sdf.org>
Date: Mon, 16 May 2016 20:00:46 +0300
Subject: [PATCH 2/6] Simplify ufs_wapbl_begin2/end2, drop 2 suffix
We are no longer calling UFS_WAPBL_BEGIN/END with vnodes (we are giving
NULL as a parameter in all cases), so we can get rid of this input
parameter and the relevant check.
---
sys/ufs/ufs/ufs_wapbl.h | 18 ++++--------------
1 file changed, 4 insertions(+), 14 deletions(-)
diff --git a/sys/ufs/ufs/ufs_wapbl.h b/sys/ufs/ufs/ufs_wapbl.h
index b8386cf..05f41a7 100644
--- a/sys/ufs/ufs/ufs_wapbl.h
+++ b/sys/ufs/ufs/ufs_wapbl.h
@@ -95,16 +95,10 @@ void ufs_wapbl_verify_inodes(struct mount *, const char *);
#endif
static __inline int
-ufs_wapbl_begin2(struct mount *mp, struct vnode *vp1, struct vnode *vp2,
- const char *file, int line)
+ufs_wapbl_begin(struct mount *mp, const char *file, int line)
{
if (mp->mnt_wapbl) {
int error;
-
- if (vp1)
- vref(vp1);
- if (vp2)
- vref(vp2);
error = wapbl_begin(mp->mnt_wapbl, file, line);
if (error)
return error;
@@ -117,7 +111,7 @@ ufs_wapbl_begin2(struct mount *mp, struct vnode *vp1, struct vnode *vp2,
}
static __inline void
-ufs_wapbl_end2(struct mount *mp, struct vnode *vp1, struct vnode *vp2)
+ufs_wapbl_end(struct mount *mp)
{
if (mp->mnt_wapbl) {
#ifdef WAPBL_DEBUG_INODES
@@ -125,16 +119,12 @@ ufs_wapbl_end2(struct mount *mp, struct vnode *vp1, struct vnode *vp2)
ufs_wapbl_verify_inodes(mp, "wapbl_end");
#endif
wapbl_end(mp->mnt_wapbl);
- if (vp2)
- vrele(vp2);
- if (vp1)
- vrele(vp1);
}
}
#define UFS_WAPBL_BEGIN(mp) \
- ufs_wapbl_begin2(mp, NULL, NULL, __FUNCTION__, __LINE__)
-#define UFS_WAPBL_END(mp) ufs_wapbl_end2(mp, NULL, NULL)
+ ufs_wapbl_begin(mp, __FUNCTION__, __LINE__)
+#define UFS_WAPBL_END(mp) ufs_wapbl_end(mp)
#define UFS_WAPBL_UPDATE(vp, access, modify, flags) \
if ((vp)->v_mount->mnt_wapbl) { \
--
2.8.1
From 114d0dce93611f4c8e8b78f38596e23cce089813 Mon Sep 17 00:00:00 2001
From: coypu <coypu@sdf.org>
Date: Mon, 16 May 2016 20:15:29 +0300
Subject: [PATCH 3/6] While here, replace GCC __FUNCTION__ by C99 __func__
---
sys/ufs/ufs/ufs_wapbl.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sys/ufs/ufs/ufs_wapbl.h b/sys/ufs/ufs/ufs_wapbl.h
index 05f41a7..c997e3c 100644
--- a/sys/ufs/ufs/ufs_wapbl.h
+++ b/sys/ufs/ufs/ufs_wapbl.h
@@ -123,7 +123,7 @@ ufs_wapbl_end(struct mount *mp)
}
#define UFS_WAPBL_BEGIN(mp) \
- ufs_wapbl_begin(mp, __FUNCTION__, __LINE__)
+ ufs_wapbl_begin(mp, __func__, __LINE__)
#define UFS_WAPBL_END(mp) ufs_wapbl_end(mp)
#define UFS_WAPBL_UPDATE(vp, access, modify, flags) \
--
2.8.1
From 0041cdff0fb74cdde7f59186ef1229c1579eee26 Mon Sep 17 00:00:00 2001
From: coypu <coypu@sdf.org>
Date: Thu, 19 May 2016 02:32:42 +0300
Subject: [PATCH 4/6] Replace deprecated disabled code by comment
describing what it intends to do, and why it won't work yet
---
sys/kern/vfs_wapbl.c | 34 ++++------------------------------
1 file changed, 4 insertions(+), 30 deletions(-)
diff --git a/sys/kern/vfs_wapbl.c b/sys/kern/vfs_wapbl.c
index e63f228..41797f0 100644
--- a/sys/kern/vfs_wapbl.c
+++ b/sys/kern/vfs_wapbl.c
@@ -1431,44 +1431,18 @@ wapbl_biodone(struct buf *bp)
#endif
if (bp->b_error) {
-#ifdef notyet /* Can't currently handle possible dirty buffer reuse */
/*
- * XXXpooka: interfaces not fully updated
- * Note: this was not enabled in the original patch
- * against netbsd4 either. I don't know if comment
- * above is true or not.
+ * If an error occurs, it would be nice to leave the buffer
+ * as a delayed write on the LRU queue so that we can retry
+ * it later. But buffercache(9) can't handle dirty buffer
+ * reuse, so just mark the log permanently errored out.
*/
-
- /*
- * If an error occurs, report the error and leave the
- * buffer as a delayed write on the LRU queue.
- * restarting the write would likely result in
- * an error spinloop, so let it be done harmlessly
- * by the syncer.
- */
- bp->b_flags &= ~(B_DONE);
- simple_unlock(&bp->b_interlock);
-
- if (we->we_error == 0) {
- mutex_enter(&wl->wl_mtx);
- wl->wl_error_count++;
- mutex_exit(&wl->wl_mtx);
- cv_broadcast(&wl->wl_reclaimable_cv);
- }
- we->we_error = bp->b_error;
- bp->b_error = 0;
- brelse(bp);
- return;
-#else
- /* For now, just mark the log permanently errored out */
-
mutex_enter(&wl->wl_mtx);
if (wl->wl_error_count == 0) {
wl->wl_error_count++;
cv_broadcast(&wl->wl_reclaimable_cv);
}
mutex_exit(&wl->wl_mtx);
-#endif
}
/*
--
2.8.1
From a8e74e2c021cd13743b952037342b54d36a1d59f Mon Sep 17 00:00:00 2001
From: coypu <coypu@sdf.org>
Date: Thu, 19 May 2016 03:01:28 +0300
Subject: [PATCH 5/6] Simplify buffer error handling case.
Don't bother advancing the log when errors occur.
---
sys/kern/vfs_wapbl.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/sys/kern/vfs_wapbl.c b/sys/kern/vfs_wapbl.c
index 41797f0..e983fb6 100644
--- a/sys/kern/vfs_wapbl.c
+++ b/sys/kern/vfs_wapbl.c
@@ -1323,9 +1323,10 @@ wapbl_truncate(struct wapbl *wl, size_t minfree)
return 0;
}
minfree -= avail;
- while ((wl->wl_error_count == 0) &&
- (wl->wl_reclaimable_bytes < minfree)) {
- WAPBL_PRINTF(WAPBL_PRINT_TRUNCATE,
+ while (wl->wl_reclaimable_bytes < minfree) {
+ if (wl->wl_error_count != 0)
+ break;
+ WAPBL_PRINTF(WAPBL_PRINT_TRUNCATE,
("wapbl_truncate: sleeping on %p wl=%p bytes=%zd "
"minfree=%zd\n",
&wl->wl_reclaimable_bytes, wl, wl->wl_reclaimable_bytes,
@@ -1333,11 +1334,12 @@ wapbl_truncate(struct wapbl *wl, size_t minfree)
cv_wait(&wl->wl_reclaimable_cv, &wl->wl_mtx);
}
- if (wl->wl_reclaimable_bytes < minfree) {
+ if (wl->wl_error_count != 0) {
KASSERT(wl->wl_error_count);
/* XXX maybe get actual error from buffer instead someday? */
- error = EIO;
+ return EIO;
}
+
head = wl->wl_head;
tail = wl->wl_tail;
delta = wl->wl_reclaimable_bytes;
@@ -1356,9 +1358,6 @@ wapbl_truncate(struct wapbl *wl, size_t minfree)
wapbl_space_used(wl->wl_circ_size, head, tail));
mutex_exit(&wl->wl_mtx);
- if (error)
- return error;
-
/*
* This is where head, tail and delta are unprotected
* from races against itself or flush. This is ok since
--
2.8.1
From 9c0391939070065963917ef56530a6bd3e61adad Mon Sep 17 00:00:00 2001
From: coypu <coypu@sdf.org>
Date: Thu, 19 May 2016 06:56:33 +0300
Subject: [PATCH 6/6] Enable somewhat excessive diagnostic asserts
They do not trigger panics.
---
sys/kern/vfs_wapbl.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/sys/kern/vfs_wapbl.c b/sys/kern/vfs_wapbl.c
index e983fb6..7512df3 100644
--- a/sys/kern/vfs_wapbl.c
+++ b/sys/kern/vfs_wapbl.c
@@ -1418,7 +1418,6 @@ wapbl_biodone(struct buf *bp)
return;
}
-#ifdef ohbother
KDASSERT(bp->b_oflags & BO_DONE);
KDASSERT(!(bp->b_oflags & BO_DELWRI));
KDASSERT(bp->b_flags & B_ASYNC);
@@ -1427,7 +1426,6 @@ wapbl_biodone(struct buf *bp)
KDASSERT(!(bp->b_flags & B_READ));
KDASSERT(!(bp->b_cflags & BC_INVAL));
KDASSERT(!(bp->b_cflags & BC_NOCACHE));
-#endif
if (bp->b_error) {
/*
--
2.8.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment