hammer - bring-in cleanup from PR 2771 and 2772
authorMatthew Dillon <dillon@apollo.backplane.com>
Sat, 17 Jan 2015 20:46:01 +0000 (12:46 -0800)
committerMatthew Dillon <dillon@apollo.backplane.com>
Sat, 17 Jan 2015 20:46:01 +0000 (12:46 -0800)
* Bring in a macro/inline cleanup that makes the code
  a bit more clear.

Submitted-by: tkusumi
sys/vfs/hammer/hammer.h
sys/vfs/hammer/hammer_blockmap.c
sys/vfs/hammer/hammer_ondisk.c

index 7464b44..3b4a2ad 100644 (file)
@@ -1355,8 +1355,9 @@ int hammer_blockmap_finalize(hammer_transaction_t trans,
                        hammer_off_t bmap_off, int bytes);
 int hammer_blockmap_getfree(hammer_mount_t hmp, hammer_off_t bmap_off,
                        int *curp, int *errorp);
-hammer_off_t hammer_blockmap_lookup(hammer_mount_t hmp, hammer_off_t bmap_off,
-                       int *errorp);
+hammer_off_t hammer_blockmap_lookup_verify(hammer_mount_t hmp,
+                       hammer_off_t zone_offset, int *errorp);
+
 hammer_off_t hammer_undo_lookup(hammer_mount_t hmp, hammer_off_t bmap_off,
                        int *errorp);
 int64_t hammer_undo_used(hammer_transaction_t trans);
@@ -1613,6 +1614,37 @@ hammer_modify_node_done(hammer_node_t node)
        }
        hammer_modify_buffer_done(node->buffer);
 }
+
+/*
+ * Translate a zone address to zone-2 address.
+ */
+#define hammer_xlate_to_zone2(offset) \
+       (((offset) & ~HAMMER_OFF_ZONE_MASK) | HAMMER_ZONE_RAW_BUFFER)
+
+/*
+ * Lookup a blockmap offset.
+ */
+static __inline hammer_off_t
+hammer_blockmap_lookup(hammer_mount_t hmp, hammer_off_t zone_offset,
+                       int *errorp)
+{
+#if defined INVARIANTS
+       int zone = HAMMER_ZONE_DECODE(zone_offset);
+       KKASSERT(zone >= HAMMER_ZONE_BTREE_INDEX && zone < HAMMER_MAX_ZONES);
+#endif
+
+       /*
+        * We can actually skip blockmap verify by default,
+        * as normal blockmaps are now direct-mapped onto the freemap
+        * and so represent zone-2 addresses.
+        */
+       if (hammer_verify_zone == 0) {
+               *errorp = 0;
+               return hammer_xlate_to_zone2(zone_offset);
+       }
+
+       return hammer_blockmap_lookup_verify(hmp, zone_offset, errorp);
+}
 #endif
 
 #define hammer_modify_volume_field(trans, vol, field)          \
index 2049e1b..7286360 100644 (file)
@@ -282,9 +282,8 @@ again:
         * The bigblock might be reserved by another zone.  If it is reserved
         * by our zone we may have to move next_offset past the append_off.
         */
-       base_off = (next_offset &
-                   (~HAMMER_LARGEBLOCK_MASK64 & ~HAMMER_OFF_ZONE_MASK)) | 
-                   HAMMER_ZONE_RAW_BUFFER;
+       base_off = hammer_xlate_to_zone2(next_offset &
+                                       ~HAMMER_LARGEBLOCK_MASK64);
        resv = RB_LOOKUP(hammer_res_rb_tree, &hmp->rb_resv_root, base_off);
        if (resv) {
                if (resv->zone != zone) {
@@ -560,9 +559,8 @@ again:
         * The bigblock might be reserved by another zone.  If it is reserved
         * by our zone we may have to move next_offset past the append_off.
         */
-       base_off = (next_offset &
-                   (~HAMMER_LARGEBLOCK_MASK64 & ~HAMMER_OFF_ZONE_MASK)) |
-                   HAMMER_ZONE_RAW_BUFFER;
+       base_off = hammer_xlate_to_zone2(next_offset &
+                                       ~HAMMER_LARGEBLOCK_MASK64);
        resv = RB_LOOKUP(hammer_res_rb_tree, &hmp->rb_resv_root, base_off);
        if (resv) {
                if (resv->zone != zone) {
@@ -723,9 +721,8 @@ hammer_blockmap_reserve_dedup(hammer_mount_t hmp, int zone, int bytes,
                goto failed;
        }
 
-       base_off = (zone_offset &
-                   (~HAMMER_LARGEBLOCK_MASK64 & ~HAMMER_OFF_ZONE_MASK)) |
-                   HAMMER_ZONE_RAW_BUFFER;
+       base_off = hammer_xlate_to_zone2(zone_offset &
+                                       ~HAMMER_LARGEBLOCK_MASK64);
        resv = RB_LOOKUP(hammer_res_rb_tree, &hmp->rb_resv_root, base_off);
        if (resv) {
                if (resv->zone != zone) {
@@ -1039,7 +1036,8 @@ hammer_blockmap_free(hammer_transaction_t trans,
         * occuring.
         */
        if (layer2->bytes_free == HAMMER_LARGEBLOCK_SIZE) {
-               base_off = (zone_offset & (~HAMMER_LARGEBLOCK_MASK64 & ~HAMMER_OFF_ZONE_MASK)) | HAMMER_ZONE_RAW_BUFFER;
+               base_off = hammer_xlate_to_zone2(zone_offset &
+                                               ~HAMMER_LARGEBLOCK_MASK64);
 
                hammer_reserve_setdelay_offset(hmp, base_off, zone, layer2);
                if (layer2->bytes_free == HAMMER_LARGEBLOCK_SIZE) {
@@ -1398,11 +1396,11 @@ failed:
 
 
 /*
- * Lookup a blockmap offset.
+ * Lookup a blockmap offset and verify blockmap layers.
  */
 hammer_off_t
-hammer_blockmap_lookup(hammer_mount_t hmp, hammer_off_t zone_offset,
-                      int *errorp)
+hammer_blockmap_lookup_verify(hammer_mount_t hmp, hammer_off_t zone_offset,
+                       int *errorp)
 {
        hammer_volume_t root_volume;
        hammer_blockmap_t freemap;
@@ -1420,19 +1418,7 @@ hammer_blockmap_lookup(hammer_mount_t hmp, hammer_off_t zone_offset,
         * Calculate the zone-2 offset.
         */
        zone = HAMMER_ZONE_DECODE(zone_offset);
-       KKASSERT(zone >= HAMMER_ZONE_BTREE_INDEX && zone < HAMMER_MAX_ZONES);
-
-       result_offset = (zone_offset & ~HAMMER_OFF_ZONE_MASK) |
-                       HAMMER_ZONE_RAW_BUFFER;
-
-       /*
-        * We can actually stop here, normal blockmaps are now direct-mapped
-        * onto the freemap and so represent zone-2 addresses.
-        */
-       if (hammer_verify_zone == 0) {
-               *errorp = 0;
-               return(result_offset);
-       }
+       result_offset = hammer_xlate_to_zone2(zone_offset);
 
        /*
         * Validate the allocation zone
@@ -1469,13 +1455,14 @@ hammer_blockmap_lookup(hammer_mount_t hmp, hammer_off_t zone_offset,
        if (*errorp)
                goto failed;
        if (layer2->zone == 0) {
-               base_off = (zone_offset & (~HAMMER_LARGEBLOCK_MASK64 & ~HAMMER_OFF_ZONE_MASK)) | HAMMER_ZONE_RAW_BUFFER;
+               base_off = hammer_xlate_to_zone2(zone_offset &
+                                               ~HAMMER_LARGEBLOCK_MASK64);
                resv = RB_LOOKUP(hammer_res_rb_tree, &hmp->rb_resv_root,
                                 base_off);
                KKASSERT(resv && resv->zone == zone);
 
        } else if (layer2->zone != zone) {
-               panic("hammer_blockmap_lookup: bad zone %d/%d",
+               panic("hammer_blockmap_lookup_verify: bad zone %d/%d",
                        layer2->zone, zone);
        }
        if (layer2->entry_crc != crc32(layer2, HAMMER_LAYER2_CRCSIZE)) {
@@ -1490,7 +1477,7 @@ failed:
                hammer_rel_buffer(buffer, 0);
        hammer_rel_volume(root_volume, 0);
        if (hammer_debug_general & 0x0800) {
-               kprintf("hammer_blockmap_lookup: %016llx -> %016llx\n",
+               kprintf("hammer_blockmap_lookup_verify: %016llx -> %016llx\n",
                        (long long)zone_offset, (long long)result_offset);
        }
        return(result_offset);
index 24985fb..876c5fe 100644 (file)
@@ -624,8 +624,7 @@ found_aliased:
                 * the mount is rw.
                 */
                buffer = RB_LOOKUP(hammer_buf_rb_tree, &hmp->rb_bufs_root,
-                                  (buf_offset & ~HAMMER_OFF_ZONE_MASK) |
-                                  HAMMER_ZONE_RAW_BUFFER);
+                                  hammer_xlate_to_zone2(buf_offset));
                if (buffer) {
                        kprintf("HAMMER: recovered aliased %016jx\n",
                                (intmax_t)buf_offset);