sys/vfs/hammer: Add HAMMER_ENCODE_UNDO()
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Thu, 3 Nov 2016 12:06:14 +0000 (21:06 +0900)
committerTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Thu, 3 Nov 2016 12:46:51 +0000 (21:46 +0900)
Add and use HAMMER_ENCODE_UNDO(offset) instead of
HAMMER_ZONE_ENCODE(HAMMER_ZONE_UNDO_INDEX, offset),
just like other ENCODE macros available for other zones.

Since zone-3 doesn't take volume# by design (see L136 of
sys/vfs/hammer/hammer_disk.h), HAMMER_ENCODE_UNDO() only
takes offset, but not (volume#, offset). In other words,
UNDO/REDO FIFO is in the root volume.

sys/vfs/hammer/hammer_disk.h
 * zone 1 (z,v,o): raw volume relative (offset 0 is the volume header)
 * zone 2 (z,v,o): raw buffer relative (offset 0 is the first buffer)
 * zone 3 (z,o): undo/redo fifo - fixed zone-2 offset array in volume header
 * zone 4 (z,v,o): freemap - only real blockmap
 * zone 8 (z,v,o): B-Tree - actually zone-2 address
 * zone 9 (z,v,o): meta - actually zone-2 address
 * zone 10 (z,v,o): large-data - actually zone-2 address
 * zone 11 (z,v,o): small-data - actually zone-2 address

sbin/hammer/cmd_blockmap.c
sbin/hammer/cmd_show.c
sbin/hammer/ondisk.c
sys/vfs/hammer/hammer_disk.h
sys/vfs/hammer/hammer_recover.c
sys/vfs/hammer/hammer_redo.c
sys/vfs/hammer/hammer_undo.c

index 119c6c0..ba03334 100644 (file)
@@ -340,7 +340,7 @@ check_undo(hammer_blockmap_t undomap)
        hammer_off_t scan_offset;
        hammer_fifo_head_t head;
 
-       scan_offset = HAMMER_ZONE_ENCODE(HAMMER_ZONE_UNDO_INDEX, 0);
+       scan_offset = HAMMER_ENCODE_UNDO(0);
        while (scan_offset < undomap->alloc_offset) {
                head = get_buffer_data(scan_offset, &buffer, 0);
                switch (head->hdr_type) {
index 57754dc..3b870d8 100644 (file)
@@ -1020,7 +1020,7 @@ hammer_cmd_show_undo(void)
 
        print_blockmap(volume);
 
-       scan_offset = HAMMER_ZONE_ENCODE(HAMMER_ZONE_UNDO_INDEX, 0);
+       scan_offset = HAMMER_ENCODE_UNDO(0);
        while (scan_offset < rootmap->alloc_offset) {
                head = get_buffer_data(scan_offset, &data_buffer, 0);
                printf("%016jx ", scan_offset);
index 730892f..9cb3d87 100644 (file)
@@ -666,7 +666,6 @@ count_freemap(struct volume_info *vol)
 void
 format_undomap(struct volume_info *root_vol, int64_t *undo_buffer_size)
 {
-       const int undo_zone = HAMMER_ZONE_UNDO_INDEX;
        hammer_off_t undo_limit;
        hammer_blockmap_t blockmap;
        hammer_volume_ondisk_t ondisk;
@@ -705,12 +704,12 @@ format_undomap(struct volume_info *root_vol, int64_t *undo_buffer_size)
                undo_limit = HAMMER_BIGBLOCK_SIZE * HAMMER_MAX_UNDO_BIGBLOCKS;
        *undo_buffer_size = undo_limit;
 
-       blockmap = &ondisk->vol0_blockmap[undo_zone];
+       blockmap = &ondisk->vol0_blockmap[HAMMER_ZONE_UNDO_INDEX];
        bzero(blockmap, sizeof(*blockmap));
        blockmap->phys_offset = HAMMER_BLOCKMAP_UNAVAIL;
-       blockmap->first_offset = HAMMER_ZONE_ENCODE(undo_zone, 0);
+       blockmap->first_offset = HAMMER_ENCODE_UNDO(0);
        blockmap->next_offset = blockmap->first_offset;
-       blockmap->alloc_offset = HAMMER_ZONE_ENCODE(undo_zone, undo_limit);
+       blockmap->alloc_offset = HAMMER_ENCODE_UNDO(undo_limit);
        hammer_crc_set_blockmap(blockmap);
 
        limit_index = undo_limit / HAMMER_BIGBLOCK_SIZE;
index 82ef2c4..82c3ed4 100644 (file)
@@ -296,6 +296,8 @@ typedef uint32_t hammer_crc_t;
        HAMMER_ENCODE(HAMMER_ZONE_RAW_VOLUME_INDEX, vol_no, offset)
 #define HAMMER_ENCODE_RAW_BUFFER(vol_no, offset)       \
        HAMMER_ENCODE(HAMMER_ZONE_RAW_BUFFER_INDEX, vol_no, offset)
+#define HAMMER_ENCODE_UNDO(offset)                     \
+       HAMMER_ENCODE(HAMMER_ZONE_UNDO_INDEX, HAMMER_ROOT_VOLNO, offset)
 #define HAMMER_ENCODE_FREEMAP(vol_no, offset)          \
        HAMMER_ENCODE(HAMMER_ZONE_FREEMAP_INDEX, vol_no, offset)
 
index 73377f7..fa2e5fb 100644 (file)
@@ -786,10 +786,9 @@ hammer_recover_scan_rev(hammer_mount_t hmp, hammer_volume_t root_volume,
 
        if (hammer_debug_general & 0x0080)
                hdkprintf("rev scan_offset %016jx\n", (intmax_t)scan_offset);
-       if (scan_offset == HAMMER_ZONE_ENCODE(HAMMER_ZONE_UNDO_INDEX, 0))
+       if (scan_offset == HAMMER_ENCODE_UNDO(0))
                scan_offset = rootmap->alloc_offset;
-       if (scan_offset - sizeof(*tail) <
-           HAMMER_ZONE_ENCODE(HAMMER_ZONE_UNDO_INDEX, 0)) {
+       if (scan_offset - sizeof(*tail) < HAMMER_ENCODE_UNDO(0)) {
                hvkprintf(root_volume,
                        "UNDO record at %016jx FIFO underflow\n",
                        (intmax_t)scan_offset);
@@ -840,7 +839,7 @@ hammer_recover_scan_fwd(hammer_mount_t hmp, hammer_volume_t root_volume,
        if (hammer_debug_general & 0x0080)
                hdkprintf("fwd scan_offset %016jx\n", (intmax_t)scan_offset);
        if (scan_offset == rootmap->alloc_offset)
-               scan_offset = HAMMER_ZONE_ENCODE(HAMMER_ZONE_UNDO_INDEX, 0);
+               scan_offset = HAMMER_ENCODE_UNDO(0);
 
        head = hammer_bread(hmp, scan_offset, errorp, bufferp);
        if (*errorp) {
@@ -859,7 +858,7 @@ hammer_recover_scan_fwd(hammer_mount_t hmp, hammer_volume_t root_volume,
        }
        scan_offset += head->head.hdr_size;
        if (scan_offset == rootmap->alloc_offset)
-               scan_offset = HAMMER_ZONE_ENCODE(HAMMER_ZONE_UNDO_INDEX, 0);
+               scan_offset = HAMMER_ENCODE_UNDO(0);
        *scan_offsetp = scan_offset;
 
        return (head);
index e036638..0aec97d 100644 (file)
@@ -99,10 +99,8 @@ hammer_generate_redo(hammer_transaction_t trans, hammer_inode_t ip,
                 * Fetch the layout offset in the UNDO FIFO, wrap it as
                 * necessary.
                 */
-               if (undomap->next_offset == undomap->alloc_offset) {
-                       undomap->next_offset =
-                               HAMMER_ZONE_ENCODE(HAMMER_ZONE_UNDO_INDEX, 0);
-               }
+               if (undomap->next_offset == undomap->alloc_offset)
+                       undomap->next_offset = HAMMER_ENCODE_UNDO(0);
                next_offset = undomap->next_offset;
 
                /*
index ed66081..7179b6a 100644 (file)
@@ -152,10 +152,8 @@ hammer_generate_undo(hammer_transaction_t trans,
                 * Fetch the layout offset in the UNDO FIFO, wrap it as
                 * necessary.
                 */
-               if (undomap->next_offset == undomap->alloc_offset) {
-                       undomap->next_offset =
-                               HAMMER_ZONE_ENCODE(HAMMER_ZONE_UNDO_INDEX, 0);
-               }
+               if (undomap->next_offset == undomap->alloc_offset)
+                       undomap->next_offset = HAMMER_ENCODE_UNDO(0);
                next_offset = undomap->next_offset;
 
                /*
@@ -372,7 +370,7 @@ hammer_upgrade_undo_4(hammer_transaction_t trans)
        /*
         * Adjust the in-core undomap and the on-disk undomap.
         */
-       next_offset = HAMMER_ZONE_ENCODE(HAMMER_ZONE_UNDO_INDEX, 0);
+       next_offset = HAMMER_ENCODE_UNDO(0);
        undomap = &hmp->blockmap[HAMMER_ZONE_UNDO_INDEX];
        undomap->next_offset = next_offset;
        undomap->first_offset = next_offset;