sys/vfs/hammer: Add hammer_is_zone2|direct_mapped_index()
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Thu, 3 Dec 2015 12:43:15 +0000 (21:43 +0900)
committerTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Thu, 3 Dec 2015 16:46:38 +0000 (01:46 +0900)
No functional changes.

Just makes the code a bit more readable than having bunch of
assert(zone >= 8 && zone < 16)

sbin/hammer/blockmap.c
sbin/hammer/cmd_blockmap.c
sbin/newfs_hammer/newfs_hammer.c
sys/vfs/hammer/hammer.h
sys/vfs/hammer/hammer_blockmap.c
sys/vfs/hammer/hammer_disk.h
sys/vfs/hammer/hammer_ondisk.c

index a9494da..ceeca79 100644 (file)
@@ -133,7 +133,7 @@ alloc_blockmap(int zone, int bytes, hammer_off_t *result_offp,
         */
        bytes = (bytes + 15) & ~15;
        assert(bytes > 0 && bytes <= HAMMER_BUFSIZE);  /* not HAMMER_XBUFSIZE */
-       assert(zone >= HAMMER_ZONE2_MAPPED_INDEX && zone < HAMMER_MAX_ZONES);
+       assert(hammer_is_zone2_mapped_index(zone));
 
 again:
        assert(blockmap->next_offset != HAMMER_ZONE_ENCODE(zone + 1, 0));
index 2130517..1d777fa 100644 (file)
@@ -256,8 +256,6 @@ hammer_cmd_checkmap(void)
        }
        rel_volume(volume);
 
-       assert(HAMMER_ZONE_UNDO_INDEX < HAMMER_ZONE2_MAPPED_INDEX);
-       assert(HAMMER_ZONE2_MAPPED_INDEX < HAMMER_MAX_ZONES);
        AssertOnFailure = (DebugOpt != 0);
 
        printf("Collecting allocation info from freemap: ");
@@ -614,8 +612,7 @@ dump_collect(collect_t collect, struct zone_stat *stats)
                if (AssertOnFailure) {
                        assert((zone == HAMMER_ZONE_UNDO_INDEX) ||
                                (zone == HAMMER_ZONE_FREEMAP_INDEX) ||
-                               (zone >= HAMMER_ZONE2_MAPPED_INDEX &&
-                                zone < HAMMER_MAX_ZONES));
+                               hammer_is_zone2_mapped_index(zone));
                }
                if (VerboseOpt)
                        hammer_add_zone_stat_layer2(stats, layer2);
index 877b6d7..736bb02 100644 (file)
@@ -532,8 +532,9 @@ format_volume(struct volume_info *vol, int nvols, const char *label,
                /*
                 * Format zones that are mapped to zone-2.
                 */
-               for (i = HAMMER_ZONE2_MAPPED_INDEX; i < HAMMER_MAX_ZONES; ++i) {
-                       format_blockmap(&ondisk->vol0_blockmap[i], i, 0);
+               for (i = 0; i < HAMMER_MAX_ZONES; ++i) {
+                       if (hammer_is_zone2_mapped_index(i))
+                               format_blockmap(&ondisk->vol0_blockmap[i], i, 0);
                }
 
                /*
index f143094..aeeb54b 100644 (file)
@@ -1636,7 +1636,7 @@ hammer_blockmap_lookup(hammer_mount_t hmp, hammer_off_t zone_offset,
 {
 #if defined INVARIANTS
        int zone = HAMMER_ZONE_DECODE(zone_offset);
-       KKASSERT(zone >= HAMMER_ZONE2_MAPPED_INDEX && zone < HAMMER_MAX_ZONES);
+       KKASSERT(hammer_is_zone2_mapped_index(zone));
 #endif
 
        /*
index 702b846..e0b7e3a 100644 (file)
@@ -101,7 +101,7 @@ hammer_blockmap_alloc(hammer_transaction_t trans, int zone, int bytes,
         */
        bytes = (bytes + 15) & ~15;
        KKASSERT(bytes > 0 && bytes <= HAMMER_XBUFSIZE);
-       KKASSERT(zone >= HAMMER_ZONE2_MAPPED_INDEX && zone < HAMMER_MAX_ZONES);
+       KKASSERT(hammer_is_zone2_mapped_index(zone));
 
        /*
         * Setup
@@ -430,7 +430,7 @@ hammer_blockmap_reserve(hammer_mount_t hmp, int zone, int bytes,
        /*
         * Setup
         */
-       KKASSERT(zone >= HAMMER_ZONE2_MAPPED_INDEX && zone < HAMMER_MAX_ZONES);
+       KKASSERT(hammer_is_zone2_mapped_index(zone));
        root_volume = hammer_get_root_volume(hmp, errorp);
        if (*errorp)
                return(NULL);
@@ -665,7 +665,7 @@ hammer_blockmap_reserve_dedup(hammer_mount_t hmp, int zone, int bytes,
        /*
         * Setup
         */
-       KKASSERT(zone >= HAMMER_ZONE2_MAPPED_INDEX && zone < HAMMER_MAX_ZONES);
+       KKASSERT(hammer_is_zone2_mapped_index(zone));
        root_volume = hammer_get_root_volume(hmp, errorp);
        if (*errorp)
                return (NULL);
@@ -975,7 +975,7 @@ hammer_blockmap_free(hammer_transaction_t trans,
         * Basic zone validation & locking
         */
        zone = HAMMER_ZONE_DECODE(zone_offset);
-       KKASSERT(zone >= HAMMER_ZONE2_MAPPED_INDEX && zone < HAMMER_MAX_ZONES);
+       KKASSERT(hammer_is_zone2_mapped_index(zone));
        root_volume = trans->rootvol;
        error = 0;
 
@@ -1110,7 +1110,7 @@ hammer_blockmap_dedup(hammer_transaction_t trans,
         * Basic zone validation & locking
         */
        zone = HAMMER_ZONE_DECODE(zone_offset);
-       KKASSERT(zone >= HAMMER_ZONE2_MAPPED_INDEX && zone < HAMMER_MAX_ZONES);
+       KKASSERT(hammer_is_zone2_mapped_index(zone));
        error = 0;
 
        freemap = &hmp->blockmap[HAMMER_ZONE_FREEMAP_INDEX];
@@ -1218,7 +1218,7 @@ hammer_blockmap_finalize(hammer_transaction_t trans,
         * Basic zone validation & locking
         */
        zone = HAMMER_ZONE_DECODE(zone_offset);
-       KKASSERT(zone >= HAMMER_ZONE2_MAPPED_INDEX && zone < HAMMER_MAX_ZONES);
+       KKASSERT(hammer_is_zone2_mapped_index(zone));
        root_volume = trans->rootvol;
        error = 0;
 
@@ -1337,7 +1337,7 @@ hammer_blockmap_getfree(hammer_mount_t hmp, hammer_off_t zone_offset,
        int zone;
 
        zone = HAMMER_ZONE_DECODE(zone_offset);
-       KKASSERT(zone >= HAMMER_ZONE2_MAPPED_INDEX && zone < HAMMER_MAX_ZONES);
+       KKASSERT(hammer_is_zone2_mapped_index(zone));
        root_volume = hammer_get_root_volume(hmp, errorp);
        if (*errorp) {
                *curp = 0;
index 0440de2..d27a45e 100644 (file)
@@ -171,10 +171,19 @@ typedef uint32_t hammer_crc_t;
 #define HAMMER_MAX_ZONES               16
 
 /*
- * Backend zones that are mapped to zone-2 (except for zone-3)
- * starts from this index which is 8.
+ * Test if the zone is directly mapped to zone-2 offset via freemap.
  */
-#define HAMMER_ZONE2_MAPPED_INDEX      HAMMER_ZONE_BTREE_INDEX
+#define hammer_is_zone2_mapped_index(zone)             \
+       ((zone) >= HAMMER_ZONE_BTREE_INDEX &&           \
+        (zone) < HAMMER_MAX_ZONES)
+/*
+ * Test if the zone is directly mapped to zone-2 offset. The word
+ * directly here means the zone is neither RAW_VOLUME nor UNDO zone.
+ */
+#define hammer_is_direct_mapped_index(zone)            \
+       (((zone) == HAMMER_ZONE_RAW_BUFFER_INDEX) ||    \
+        ((zone) == HAMMER_ZONE_FREEMAP_INDEX) ||       \
+        hammer_is_zone2_mapped_index(zone))
 
 #define HAMMER_ZONE_ENCODE(zone, ham_off)              \
        (((hammer_off_t)(zone) << 60) | (ham_off))
index 21f1458..d05f41c 100644 (file)
@@ -586,18 +586,9 @@ hammer_get_installed_volumes(hammer_mount_t hmp)
 static __inline int
 hammer_direct_zone(hammer_off_t buf_offset)
 {
-       switch(HAMMER_ZONE_DECODE(buf_offset)) {
-       case HAMMER_ZONE_RAW_BUFFER_INDEX:
-       case HAMMER_ZONE_FREEMAP_INDEX:
-       case HAMMER_ZONE_BTREE_INDEX:
-       case HAMMER_ZONE_META_INDEX:
-       case HAMMER_ZONE_LARGE_DATA_INDEX:
-       case HAMMER_ZONE_SMALL_DATA_INDEX:
-               return(1);
-       default:
-               return(0);
-       }
-       /* NOT REACHED */
+       int zone = HAMMER_ZONE_DECODE(buf_offset);
+
+       return(hammer_is_direct_mapped_index(zone));
 }
 
 hammer_buffer_t
@@ -714,11 +705,12 @@ found_aliased:
        /*
         * Handle blockmap offset translations
         */
-       if (zone >= HAMMER_ZONE2_MAPPED_INDEX) {
+       if (hammer_is_zone2_mapped_index(zone)) {
                zone2_offset = hammer_blockmap_lookup(hmp, buf_offset, errorp);
        } else if (zone == HAMMER_ZONE_UNDO_INDEX) {
                zone2_offset = hammer_undo_lookup(hmp, buf_offset, errorp);
        } else {
+               /* Must be zone-2 (not 1 or 4 or 15) */
                KKASSERT(zone == HAMMER_ZONE_RAW_BUFFER_INDEX);
                zone2_offset = buf_offset;
                *errorp = 0;