sys/vfs/hammer: Add hammer_is_zone_xxx()
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Sat, 19 Mar 2016 07:01:59 +0000 (16:01 +0900)
committerTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Sat, 19 Mar 2016 19:50:14 +0000 (04:50 +0900)
sbin/hammer/ondisk.c
sys/vfs/hammer/hammer_blockmap.c
sys/vfs/hammer/hammer_disk.h
sys/vfs/hammer/hammer_io.c
sys/vfs/hammer/hammer_ondisk.c
sys/vfs/hammer/hammer_undo.c
sys/vfs/hammer/hammer_vnops.c

index c97f729..5595981 100644 (file)
@@ -293,7 +293,7 @@ get_buffer(hammer_off_t buf_offset, int isnew)
        }
        if (buf_offset == HAMMER_OFF_BAD)
                return(NULL);
-       assert((buf_offset & HAMMER_OFF_ZONE_MASK) == HAMMER_ZONE_RAW_BUFFER);
+       assert(hammer_is_zone_raw_buffer(buf_offset));
 
        vol_no = HAMMER_VOL_DECODE(buf_offset);
        volume = get_volume(vol_no);
index 76ce293..aa9dff5 100644 (file)
@@ -817,8 +817,7 @@ hammer_blockmap_reserve_complete(hammer_mount_t hmp, hammer_reserve_t resv)
        int error;
 
        KKASSERT(resv->refs > 0);
-       KKASSERT((resv->zone_offset & HAMMER_OFF_ZONE_MASK) ==
-                HAMMER_ZONE_RAW_BUFFER);
+       KKASSERT(hammer_is_zone_raw_buffer(resv->zone_offset));
 
        /*
         * Setting append_off to the max prevents any new allocations
index 48ecc3a..9c7e551 100644 (file)
@@ -172,6 +172,25 @@ typedef uint32_t hammer_crc_t;
 
 #define HAMMER_ZONE(offset)            ((offset) & HAMMER_OFF_ZONE_MASK)
 
+#define hammer_is_zone_raw_volume(offset)              \
+       (HAMMER_ZONE(offset) == HAMMER_ZONE_RAW_VOLUME)
+#define hammer_is_zone_raw_buffer(offset)              \
+       (HAMMER_ZONE(offset) == HAMMER_ZONE_RAW_BUFFER)
+#define hammer_is_zone_undo(offset)                    \
+       (HAMMER_ZONE(offset) == HAMMER_ZONE_UNDO)
+#define hammer_is_zone_freemap(offset)                 \
+       (HAMMER_ZONE(offset) == HAMMER_ZONE_FREEMAP)
+#define hammer_is_zone_btree(offset)                   \
+       (HAMMER_ZONE(offset) == HAMMER_ZONE_BTREE)
+#define hammer_is_zone_meta(offset)                    \
+       (HAMMER_ZONE(offset) == HAMMER_ZONE_META)
+#define hammer_is_zone_large_data(offset)              \
+       (HAMMER_ZONE(offset) == HAMMER_ZONE_LARGE_DATA)
+#define hammer_is_zone_small_data(offset)              \
+       (HAMMER_ZONE(offset) == HAMMER_ZONE_SMALL_DATA)
+#define hammer_is_zone_unavail(offset)                 \
+       (HAMMER_ZONE(offset) == HAMMER_ZONE_UNAVAIL)
+
 /*
  * Test if the zone is directly mapped to zone-2 offset via freemap.
  */
index 6ae63cc..4d32a24 100644 (file)
@@ -1410,8 +1410,7 @@ hammer_io_direct_read(hammer_mount_t hmp, struct bio *bio,
        int error;
 
        buf_offset = bio->bio_offset;
-       KKASSERT((buf_offset & HAMMER_OFF_ZONE_MASK) ==
-                HAMMER_ZONE_LARGE_DATA);
+       KKASSERT(hammer_is_zone_large_data(buf_offset));
 
        /*
         * The buffer cache may have an aliased buffer (the reblocker can
@@ -1429,8 +1428,7 @@ hammer_io_direct_read(hammer_mount_t hmp, struct bio *bio,
        zone2_offset = hammer_blockmap_lookup(hmp, buf_offset, &error);
        if (error)
                goto done;
-       KKASSERT((zone2_offset & HAMMER_OFF_ZONE_MASK) ==
-                HAMMER_ZONE_RAW_BUFFER);
+       KKASSERT(hammer_is_zone_raw_buffer(zone2_offset));
 
        /*
         * Resolve volume and raw-offset for 3rd level bio.  The
@@ -1486,8 +1484,7 @@ hammer_io_indirect_read(hammer_mount_t hmp, struct bio *bio,
        int error;
 
        buf_offset = bio->bio_offset;
-       KKASSERT((buf_offset & HAMMER_OFF_ZONE_MASK) ==
-                HAMMER_ZONE_LARGE_DATA);
+       KKASSERT(hammer_is_zone_large_data(buf_offset));
 
        /*
         * The buffer cache may have an aliased buffer (the reblocker can
@@ -1505,8 +1502,7 @@ hammer_io_indirect_read(hammer_mount_t hmp, struct bio *bio,
        zone2_offset = hammer_blockmap_lookup(hmp, buf_offset, &error);
        if (error)
                goto done;
-       KKASSERT((zone2_offset & HAMMER_OFF_ZONE_MASK) ==
-                HAMMER_ZONE_RAW_BUFFER);
+       KKASSERT(hammer_is_zone_raw_buffer(zone2_offset));
 
        /*
         * Resolve volume and raw-offset for 3rd level bio.  The
index 08c32a2..dbbcca6 100644 (file)
@@ -722,8 +722,7 @@ found_aliased:
         * NOTE: zone2_offset and maxbuf_off are both full zone-2 offset
         * specifications.
         */
-       KKASSERT((zone2_offset & HAMMER_OFF_ZONE_MASK) ==
-                HAMMER_ZONE_RAW_BUFFER);
+       KKASSERT(hammer_is_zone_raw_buffer(zone2_offset));
        vol_no = HAMMER_VOL_DECODE(zone2_offset);
        volume = hammer_get_volume(hmp, vol_no, errorp);
        if (volume == NULL)
@@ -796,8 +795,7 @@ hammer_sync_buffers(hammer_mount_t hmp, hammer_off_t base_offset, int bytes)
        hammer_buffer_t buffer;
        int error;
 
-       KKASSERT((base_offset & HAMMER_OFF_ZONE_MASK) ==
-                HAMMER_ZONE_LARGE_DATA);
+       KKASSERT(hammer_is_zone_large_data(base_offset));
 
        while (bytes > 0) {
                buffer = RB_LOOKUP(hammer_buf_rb_tree, &hmp->rb_bufs_root,
@@ -931,8 +929,7 @@ hammer_load_buffer(hammer_buffer_t buffer, int isnew)
                 */
                if (isnew) {
                        error = hammer_io_new(volume->devvp, &buffer->io);
-               } else if ((buffer->zoneX_offset & HAMMER_OFF_ZONE_MASK) ==
-                          HAMMER_ZONE_LARGE_DATA) {
+               } else if (hammer_is_zone_large_data(buffer->zoneX_offset)) {
                        error = hammer_io_read(volume->devvp, &buffer->io,
                                               buffer->io.bytes);
                } else {
@@ -1238,7 +1235,7 @@ hammer_get_node(hammer_transaction_t trans, hammer_off_t node_offset,
        hammer_node_t node;
        int doload;
 
-       KKASSERT((node_offset & HAMMER_OFF_ZONE_MASK) == HAMMER_ZONE_BTREE);
+       KKASSERT(hammer_is_zone_btree(node_offset));
 
        /*
         * Locate the structure, allocating one if necessary.
index b58a71f..db35910 100644 (file)
@@ -62,7 +62,7 @@ hammer_undo_lookup(hammer_mount_t hmp, hammer_off_t zone3_off, int *errorp)
        hammer_off_t result_offset;
        int i;
 
-       KKASSERT((zone3_off & HAMMER_OFF_ZONE_MASK) == HAMMER_ZONE_UNDO);
+       KKASSERT(hammer_is_zone_undo(zone3_off));
        root_volume = hammer_get_root_volume(hmp, errorp);
        if (*errorp)
                return(0);
index 471ee8f..9c6fbbd 100644 (file)
@@ -2676,8 +2676,7 @@ hammer_vop_strategy_read(struct vop_strategy_args *ap)
         * device.
         */
        nbio = push_bio(bio);
-       if ((nbio->bio_offset & HAMMER_OFF_ZONE_MASK) ==
-           HAMMER_ZONE_LARGE_DATA) {
+       if (hammer_is_zone_large_data(nbio->bio_offset)) {
                if (hammer_double_buffer == 0) {
                        lwkt_gettoken(&hmp->fs_token);
                        error = hammer_io_direct_read(hmp, nbio, NULL);
@@ -2854,8 +2853,7 @@ hammer_vop_strategy_read(struct vop_strategy_args *ap)
                        /*
                         * Direct read case
                         */
-                       KKASSERT((disk_offset & HAMMER_OFF_ZONE_MASK) ==
-                                HAMMER_ZONE_LARGE_DATA);
+                       KKASSERT(hammer_is_zone_large_data(disk_offset));
                        nbio->bio_offset = disk_offset;
                        error = hammer_io_direct_read(hmp, nbio, cursor.leaf);
                        if (hammer_live_dedup && error == 0)
@@ -2869,8 +2867,7 @@ hammer_vop_strategy_read(struct vop_strategy_args *ap)
                         * gets a hit later so we can just add the entry
                         * now.
                         */
-                       KKASSERT((disk_offset & HAMMER_OFF_ZONE_MASK) ==
-                                HAMMER_ZONE_LARGE_DATA);
+                       KKASSERT(hammer_is_zone_large_data(disk_offset));
                        nbio->bio_offset = disk_offset;
                        if (hammer_live_dedup)
                                hammer_dedup_cache_add(ip, cursor.leaf);
@@ -3162,7 +3159,7 @@ hammer_vop_bmap(struct vop_bmap_args *ap)
         */
        disk_offset = base_disk_offset + (ap->a_loffset - base_offset);
 
-       if ((disk_offset & HAMMER_OFF_ZONE_MASK) != HAMMER_ZONE_LARGE_DATA) {
+       if (!hammer_is_zone_large_data(disk_offset)) {
                /*
                 * Only large-data zones can be direct-IOd
                 */