sys/vfs/hammer: Add hammer_xlate_to_phys()
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Wed, 9 Dec 2015 13:21:35 +0000 (22:21 +0900)
committerTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Wed, 9 Dec 2015 13:56:48 +0000 (22:56 +0900)
This macro is zone2 --> physical offset version of
hammer_xlate_to_zone2() and hammer_xlate_to_zoneX().

sbin/hammer/ondisk.c
sys/vfs/hammer/hammer_disk.h
sys/vfs/hammer/hammer_io.c
sys/vfs/hammer/hammer_ondisk.c

index cd465d7..71f0ba7 100644 (file)
@@ -291,8 +291,8 @@ get_buffer(hammer_off_t buf_offset, int isnew)
                                buf);
                }
                buf->buf_offset = buf_offset;
-               buf->raw_offset = volume->ondisk->vol_buf_beg +
-                                 (buf_offset & HAMMER_OFF_SHORT_MASK);
+               buf->raw_offset = hammer_xlate_to_phys(volume->ondisk,
+                                                       buf_offset);
                buf->volume = volume;
                hi = buffer_hash(buf_offset);
                TAILQ_INSERT_TAIL(&volume->buffer_lists[hi], buf, entry);
index 49f54c1..b8b3c89 100644 (file)
@@ -703,6 +703,13 @@ typedef struct hammer_volume_ondisk *hammer_volume_ondisk_t;
 #define HAMMER_VOL_VERSION_FIVE                5       /* dedup (2.9+) */
 #define HAMMER_VOL_VERSION_SIX         6       /* DIRHASH_ALG1 */
 
+/*
+ * Translate a zone-2 address to physical address
+ */
+#define hammer_xlate_to_phys(volume, zone2_offset)     \
+       ((volume)->vol_buf_beg +                        \
+        ((zone2_offset) & HAMMER_OFF_SHORT_MASK))
+
 /*
  * Record types are fairly straightforward.  The B-Tree includes the record
  * type in its index sort.
index a10dc8f..74e4b8b 100644 (file)
@@ -454,8 +454,7 @@ hammer_io_inval(hammer_volume_t volume, hammer_off_t zone2_offset)
         * offset use that, otherwise instantiate a buffer to cover any
         * related VM pages, set BNOCACHE, and brelse().
         */
-       phys_offset = volume->ondisk->vol_buf_beg +
-                     (zone2_offset & HAMMER_OFF_SHORT_MASK);
+       phys_offset = hammer_xlate_to_phys(volume->ondisk, zone2_offset);
        if ((bp = findblk(volume->devvp, phys_offset, 0)) != NULL)
                bremfree(bp);
        else
@@ -1448,8 +1447,8 @@ hammer_io_direct_read(hammer_mount_t hmp, struct bio *bio,
                 * 3rd level bio (the caller has already pushed once)
                 */
                nbio = push_bio(bio);
-               nbio->bio_offset = volume->ondisk->vol_buf_beg +
-                                  (zone2_offset & HAMMER_OFF_SHORT_MASK);
+               nbio->bio_offset = hammer_xlate_to_phys(volume->ondisk,
+                                                       zone2_offset);
                hammer_stats_disk_read += bp->b_bufsize;
                vn_strategy(volume->devvp, nbio);
        }
@@ -1524,8 +1523,7 @@ hammer_io_indirect_read(hammer_mount_t hmp, struct bio *bio,
                 * Convert to the raw volume->devvp offset and acquire
                 * the buf, issuing async I/O if necessary.
                 */
-               buf_offset = volume->ondisk->vol_buf_beg +
-                            (zone2_offset & HAMMER_OFF_SHORT_MASK);
+               buf_offset = hammer_xlate_to_phys(volume->ondisk, zone2_offset);
 
                if (leaf && hammer_verify_data) {
                        bio->bio_caller_info1.uvalue32 = leaf->data_crc;
@@ -1676,10 +1674,9 @@ hammer_io_direct_write(hammer_mount_t hmp, struct bio *bio,
                         * Third level bio - raw offset specific to the
                         * correct volume.
                         */
-                       zone2_offset &= HAMMER_OFF_SHORT_MASK;
                        nbio = push_bio(nbio);
-                       nbio->bio_offset = volume->ondisk->vol_buf_beg +
-                                          zone2_offset;
+                       nbio->bio_offset = hammer_xlate_to_phys(volume->ondisk,
+                                                               zone2_offset);
                        hammer_stats_disk_write += bp->b_bufsize;
                        hammer_ip_replace_bulk(hmp, record);
                        vn_strategy(volume->devvp, nbio);
index 7662ec3..518d77a 100644 (file)
@@ -741,8 +741,7 @@ found_aliased:
        buffer->zoneX_offset = buf_offset;
 
        hammer_io_init(&buffer->io, volume, iotype);
-       buffer->io.offset = volume->ondisk->vol_buf_beg +
-                           (zone2_offset & HAMMER_OFF_SHORT_MASK);
+       buffer->io.offset = hammer_xlate_to_phys(volume->ondisk, zone2_offset);
        buffer->io.bytes = bytes;
        TAILQ_INIT(&buffer->clist);
        hammer_ref_interlock_true(&buffer->io.lock);