Module Name:    src
Committed By:   christos
Date:           Sat Jan  8 20:37:05 UTC 2011

Modified Files:
        src/sys/kern: vfs_wapbl.c

Log Message:
Add two sysctls one that does verbose transaction logging and a second one
that disables flushing the disk cache (which is fast but dangerous for
data integrity). From simon a long while back.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/kern/vfs_wapbl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/vfs_wapbl.c
diff -u src/sys/kern/vfs_wapbl.c:1.38 src/sys/kern/vfs_wapbl.c:1.39
--- src/sys/kern/vfs_wapbl.c:1.38	Tue Nov  9 11:30:26 2010
+++ src/sys/kern/vfs_wapbl.c	Sat Jan  8 15:37:05 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_wapbl.c,v 1.38 2010/11/09 16:30:26 hannken Exp $	*/
+/*	$NetBSD: vfs_wapbl.c,v 1.39 2011/01/08 20:37:05 christos Exp $	*/
 
 /*-
  * Copyright (c) 2003, 2008, 2009 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
 #define WAPBL_INTERNAL
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_wapbl.c,v 1.38 2010/11/09 16:30:26 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_wapbl.c,v 1.39 2011/01/08 20:37:05 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/bitops.h>
@@ -45,6 +45,7 @@
 #include <sys/param.h>
 #include <sys/namei.h>
 #include <sys/proc.h>
+#include <sys/sysctl.h>
 #include <sys/uio.h>
 #include <sys/vnode.h>
 #include <sys/file.h>
@@ -73,6 +74,10 @@
 #define	wapbl_calloc(n, s) malloc((n)*(s), M_WAPBL, M_WAITOK | M_ZERO)
 #endif
 
+static struct sysctllog *wapbl_sysctl;
+static int wapbl_flush_disk_cache = 1;
+static int wapbl_verbose_commit = 0;
+
 #else /* !_KERNEL */
 #include <assert.h>
 #include <errno.h>
@@ -260,6 +265,66 @@
 };
 
 static int
+wapbl_sysctl_init(void)
+{
+	int rv;
+	const struct sysctlnode *rnode, *cnode;
+
+	wapbl_sysctl = NULL;
+
+	rv = sysctl_createv(&wapbl_sysctl, 0, NULL, &rnode,
+		       CTLFLAG_PERMANENT,
+		       CTLTYPE_NODE, "vfs", NULL,
+		       NULL, 0, NULL, 0,
+		       CTL_VFS, CTL_EOL);
+	if (rv)
+		return rv;
+
+	rv = sysctl_createv(&wapbl_sysctl, 0, &rnode, &rnode,
+		       CTLFLAG_PERMANENT,
+		       CTLTYPE_NODE, "wapbl",
+		       SYSCTL_DESCR("WAPBL journaling options"),
+		       NULL, 0, NULL, 0,
+		       CTL_CREATE, CTL_EOL);
+	if (rv)
+		return rv;
+
+	rv = sysctl_createv(&wapbl_sysctl, 0, &rnode, &cnode,
+		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
+		       CTLTYPE_INT, "flush_disk_cache",
+		       SYSCTL_DESCR("flush disk cache"),
+		       NULL, 0, &wapbl_flush_disk_cache, 0,
+		       CTL_CREATE, CTL_EOL);
+	if (rv)
+		return rv;
+
+	rv = sysctl_createv(&wapbl_sysctl, 0, &rnode, &cnode,
+		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
+		       CTLTYPE_INT, "verbose_commit",
+		       SYSCTL_DESCR("show time and size of wapbl log commits"),
+		       NULL, 0, &wapbl_verbose_commit, 0,
+		       CTL_CREATE, CTL_EOL);
+	return rv;
+}
+
+static void
+wapbl_init(void)
+{
+	malloc_type_attach(M_WAPBL);
+	wapbl_sysctl_init();
+}
+
+#ifdef notyet
+static int
+wapbl_fini(bool interface)
+{
+	if (aio_sysctl != NULL)
+		 sysctl_teardown(&aio_sysctl);
+	return 0;
+}
+#endif
+
+static int
 wapbl_start_flush_inodes(struct wapbl *wl, struct wapbl_replay *wr)
 {
 	int error, i;
@@ -1327,6 +1392,13 @@
 
 	/* Calculate amount of space needed to flush */
 	flushsize = wapbl_transaction_len(wl);
+	if (wapbl_verbose_commit) {
+		struct timespec ts;
+		getnanotime(&ts);
+		printf("%s: %lld.%06ld this transaction = %zu bytes\n",
+		    __func__, (long long)ts.tv_sec,
+		    (long)ts.tv_nsec, flushsize);
+	}
 
 	if (flushsize > (wl->wl_circ_size - wl->wl_reserved_bytes)) {
 		/*
@@ -1791,7 +1863,7 @@
 
 	KASSERT(iph > 0);
 
-	return MAX(1, howmany(wl->wl_inohashcnt, iph))*blocklen;
+	return MAX(1, howmany(wl->wl_inohashcnt, iph)) * blocklen;
 }
 
 
@@ -1810,8 +1882,8 @@
 	KASSERT(bph > 0);
 
 	len = wl->wl_bcount;
-	len += howmany(wl->wl_bufcount, bph)*blocklen;
-	len += howmany(wl->wl_dealloccnt, bph)*blocklen;
+	len += howmany(wl->wl_bufcount, bph) * blocklen;
+	len += howmany(wl->wl_dealloccnt, bph) * blocklen;
 	len += wapbl_transaction_inodes_len(wl);
 
 	return len;
@@ -1834,12 +1906,15 @@
 	int force = 1;
 	daddr_t pbn;
 
-	/* XXX Calc checksum here, instead we do this for now */
-	error = VOP_IOCTL(wl->wl_devvp, DIOCCACHESYNC, &force, FWRITE, FSCRED);
-	if (error) {
-		WAPBL_PRINTF(WAPBL_PRINT_ERROR,
-		    ("wapbl_write_commit: DIOCCACHESYNC on dev 0x%"PRIx64
-		    " returned %d\n", wl->wl_devvp->v_rdev, error));
+	if (wapbl_flush_disk_cache) {
+		/* XXX Calc checksum here, instead we do this for now */
+		error = VOP_IOCTL(wl->wl_devvp, DIOCCACHESYNC, &force,
+		    FWRITE, FSCRED);
+		if (error) {
+			WAPBL_PRINTF(WAPBL_PRINT_ERROR,
+			    ("wapbl_write_commit: DIOCCACHESYNC on dev 0x%x "
+			    "returned %d\n", wl->wl_devvp->v_rdev, error));
+		}
 	}
 
 	wc->wc_head = head;
@@ -1867,11 +1942,14 @@
 	if (error)
 		return error;
 
-	error = VOP_IOCTL(wl->wl_devvp, DIOCCACHESYNC, &force, FWRITE, FSCRED);
-	if (error) {
-		WAPBL_PRINTF(WAPBL_PRINT_ERROR,
-		    ("wapbl_write_commit: DIOCCACHESYNC on dev 0x%"PRIx64
-		    " returned %d\n", wl->wl_devvp->v_rdev, error));
+	if (wapbl_flush_disk_cache) {
+		error = VOP_IOCTL(wl->wl_devvp, DIOCCACHESYNC, &force,
+		    FWRITE, FSCRED);
+		if (error) {
+			WAPBL_PRINTF(WAPBL_PRINT_ERROR,
+			    ("wapbl_write_commit: DIOCCACHESYNC on dev 0x%x "
+			    "returned %d\n", wl->wl_devvp->v_rdev, error));
+		}
 	}
 
 	/*
@@ -2723,9 +2801,12 @@
 
 	switch (cmd) {
 	case MODULE_CMD_INIT:
-		malloc_type_attach(M_WAPBL);
+		wapbl_init();
 		return 0;
 	case MODULE_CMD_FINI:
+#ifdef notyet
+		return wapbl_fini(true);
+#endif
 		return EOPNOTSUPP;
 	default:
 		return ENOTTY;

Reply via email to