Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern Move block number computations to callers of wapl_r...



details:   https://anonhg.NetBSD.org/src/rev/23bc35c48a8e
branches:  trunk
changeset: 752488:23bc35c48a8e
user:      mlelstv <mlelstv%NetBSD.org@localhost>
date:      Sat Feb 27 16:51:03 2010 +0000

description:
Move block number computations to callers of wapl_read/wapl_write and
conditionally build DEV_BSIZE adjustments for kernel. fsck_ffs shares
the same code but accesses physical blocks.

Also compute correct block numbers for each physical sector.

diffstat:

 sys/kern/vfs_wapbl.c |  71 +++++++++++++++++++++++++++++++--------------------
 1 files changed, 43 insertions(+), 28 deletions(-)

diffs (216 lines):

diff -r 43bccaf2c0bb -r 23bc35c48a8e sys/kern/vfs_wapbl.c
--- a/sys/kern/vfs_wapbl.c      Sat Feb 27 16:13:28 2010 +0000
+++ b/sys/kern/vfs_wapbl.c      Sat Feb 27 16:51:03 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_wapbl.c,v 1.33 2010/02/27 12:04:19 mlelstv Exp $   */
+/*     $NetBSD: vfs_wapbl.c,v 1.34 2010/02/27 16:51:03 mlelstv 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.33 2010/02/27 12:04:19 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_wapbl.c,v 1.34 2010/02/27 16:51:03 mlelstv Exp $");
 
 #include <sys/param.h>
 #include <sys/bitops.h>
@@ -344,10 +344,6 @@
        if (blksize % DEV_BSIZE)
                return EINVAL;
 
-       /* Kernel uses DEV_BSIZE units */
-       off = btodb(off << log_dev_bshift);
-       count = btodb(count << log_dev_bshift);
-
        /* XXXTODO: verify that the full load is writable */
 
        /*
@@ -383,7 +379,7 @@
 
        /* Reserve two log device blocks for the commit headers */
        wl->wl_circ_off = 2<<wl->wl_log_dev_bshift;
-       wl->wl_circ_size = ((count * DEV_BSIZE) - wl->wl_circ_off);
+       wl->wl_circ_size = ((count * blksize) - wl->wl_circ_off);
        /* truncate the log usage to a multiple of log_dev_bshift */
        wl->wl_circ_size >>= wl->wl_log_dev_bshift;
        wl->wl_circ_size <<= wl->wl_log_dev_bshift;
@@ -740,6 +736,7 @@
        size_t slen;
        off_t off = *offp;
        int error;
+       daddr_t pbn;
 
        KDASSERT(((len >> wl->wl_log_dev_bshift) <<
            wl->wl_log_dev_bshift) == len);
@@ -748,16 +745,22 @@
                off = wl->wl_circ_off;
        slen = wl->wl_circ_off + wl->wl_circ_size - off;
        if (slen < len) {
-               error = wapbl_write(data, slen, wl->wl_devvp,
-                   wl->wl_logpbn + btodb(off));
+               pbn = wl->wl_logpbn + (off >> wl->wl_log_dev_bshift);
+#ifdef _KERNEL
+               pbn = btodb(pbn << wl->wl_log_dev_bshift);
+#endif
+               error = wapbl_write(data, slen, wl->wl_devvp, pbn);
                if (error)
                        return error;
                data = (uint8_t *)data + slen;
                len -= slen;
                off = wl->wl_circ_off;
        }
-       error = wapbl_write(data, len, wl->wl_devvp,
-                           wl->wl_logpbn + btodb(off));
+       pbn = wl->wl_logpbn + (off >> wl->wl_log_dev_bshift);
+#ifdef _KERNEL
+       pbn = btodb(pbn << wl->wl_log_dev_bshift);
+#endif
+       error = wapbl_write(data, len, wl->wl_devvp, pbn);
        if (error)
                return error;
        off += len;
@@ -1832,6 +1835,7 @@
        struct timespec ts;
        int error;
        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);
@@ -1858,9 +1862,11 @@
         * over second commit header before trying to write both headers.
         */
 
-       error = wapbl_write(wc, wc->wc_len, wl->wl_devvp,
-           wl->wl_logpbn +
-           ((wc->wc_generation % 2) << (wc->wc_log_dev_bshift - DEV_BSHIFT)));
+       pbn = wl->wl_logpbn + (wc->wc_generation % 2);
+#ifdef _KERNEL
+       pbn = btodb(pbn << wc->wc_log_dev_bshift);
+#endif
+       error = wapbl_write(wc, wc->wc_len, wl->wl_devvp, pbn);
        if (error)
                return error;
 
@@ -2183,23 +2189,31 @@
        size_t slen;
        off_t off = *offp;
        int error;
+       daddr_t pbn;
 
        KASSERT(((len >> wr->wr_log_dev_bshift) <<
            wr->wr_log_dev_bshift) == len);
+
        if (off < wr->wr_circ_off)
                off = wr->wr_circ_off;
        slen = wr->wr_circ_off + wr->wr_circ_size - off;
        if (slen < len) {
-               error = wapbl_read(data, slen, wr->wr_devvp,
-                   wr->wr_logpbn + (off >> wr->wr_log_dev_bshift));
+               pbn = wr->wr_logpbn + (off >> wr->wr_log_dev_bshift);
+#ifdef _KERNEL
+               pbn = btodb(pbn << wr->wr_log_dev_bshift);
+#endif
+               error = wapbl_read(data, slen, wr->wr_devvp, pbn);
                if (error)
                        return error;
                data = (uint8_t *)data + slen;
                len -= slen;
                off = wr->wr_circ_off;
        }
-       error = wapbl_read(data, len, wr->wr_devvp,
-           wr->wr_logpbn + (off >> wr->wr_log_dev_bshift));
+       pbn = wr->wr_logpbn + (off >> wr->wr_log_dev_bshift);
+#ifdef _KERNEL
+       pbn = btodb(pbn << wr->wr_log_dev_bshift);
+#endif
+       error = wapbl_read(data, len, wr->wr_devvp, pbn);
        if (error)
                return error;
        off += len;
@@ -2247,6 +2261,7 @@
        /* Use this until we read the actual log header */
        int log_dev_bshift = ilog2(blksize);
        size_t used;
+       daddr_t pbn;
 
        WAPBL_PRINTF(WAPBL_PRINT_REPLAY,
            ("wapbl_replay_start: vp=%p off=%"PRId64 " count=%zu blksize=%zu\n",
@@ -2261,10 +2276,6 @@
                return EINVAL;
 
 #ifdef _KERNEL
-       /* Kernel uses DEV_BSIZE units */
-       off = btodb(off << log_dev_bshift);
-       count = btodb(count << log_dev_bshift);
-
 #if 0
        /* XXX vp->v_size isn't reliably set for VBLK devices,
         * especially root.  However, we might still want to verify
@@ -2272,7 +2283,6 @@
        if ((off + count) * blksize > vp->v_size)
                return EINVAL;
 #endif
-
        if ((error = VOP_BMAP(vp, off, &devvp, &logpbn, 0)) != 0) {
                return error;
        }
@@ -2283,7 +2293,11 @@
 
        scratch = wapbl_malloc(MAXBSIZE);
 
-       error = wapbl_read(scratch, 2<<log_dev_bshift, devvp, logpbn);
+       pbn = logpbn;
+#ifdef _KERNEL
+       pbn = btodb(pbn << log_dev_bshift);
+#endif
+       error = wapbl_read(scratch, 2<<log_dev_bshift, devvp, pbn);
        if (error)
                goto errout;
 
@@ -2392,7 +2406,7 @@
                 */
                n = wc->wc_blocks[i].wc_dlen >> wr->wr_fs_dev_bshift;
                for (j = 0; j < n; j++) {
-                       wapbl_blkhash_ins(wr, wc->wc_blocks[i].wc_daddr + j,
+                       wapbl_blkhash_ins(wr, wc->wc_blocks[i].wc_daddr + btodb(j * fsblklen),
                            *offp);
                        wapbl_circ_advance(wr, fsblklen, offp);
                }
@@ -2404,6 +2418,7 @@
 {
        struct wapbl_wc_blocklist *wc =
            (struct wapbl_wc_blocklist *)wr->wr_scratch;
+       int fsblklen = 1 << wr->wr_fs_dev_bshift;
        int i, j, n;
 
        for (i = 0; i < wc->wc_blkcount; i++) {
@@ -2412,7 +2427,7 @@
                 */
                n = wc->wc_blocks[i].wc_dlen >> wr->wr_fs_dev_bshift;
                for (j = 0; j < n; j++)
-                       wapbl_blkhash_rem(wr, wc->wc_blocks[i].wc_daddr + j);
+                       wapbl_blkhash_rem(wr, wc->wc_blocks[i].wc_daddr + btodb(j * fsblklen));
        }
 }
 
@@ -2548,7 +2563,7 @@
                                        for (j = 0; j < n; j++) {
                                                struct wapbl_blk *wb =
                                                   wapbl_blkhash_get(wr,
-                                                  wc->wc_blocks[i].wc_daddr + j);
+                                                  wc->wc_blocks[i].wc_daddr + btodb(j * fsblklen));
                                                if (wb && (wb->wb_off == off)) {
                                                        foundcnt++;
                                                        error =
@@ -2592,7 +2607,7 @@
                                                for (j = 0; j < n; j++) {
                                                        struct wapbl_blk *wb =
                                                           wapbl_blkhash_get(wr,
-                                                          wc->wc_blocks[i].wc_daddr + j);
+                                                          wc->wc_blocks[i].wc_daddr + btodb(j * fsblklen));
                                                        if (wb &&
                                                          (wb->wb_off == off)) {
                                                                wapbl_blkhash_rem(wr, wb->wb_blk);



Home | Main Index | Thread Index | Old Index