sys/vfs/hammer: Add hammer_xlate_to_undo()
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Sat, 12 Nov 2016 05:37:26 +0000 (14:37 +0900)
committerTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Sat, 12 Nov 2016 06:46:56 +0000 (15:46 +0900)
sbin/hammer/blockmap.c
sys/vfs/hammer/hammer_disk.h
sys/vfs/hammer/hammer_undo.c

index b41b3a1..6b08e89 100644 (file)
@@ -214,6 +214,7 @@ blockmap_lookup(hammer_off_t zone_offset,
                int *errorp)
 {
        struct volume_info *root_volume = NULL;
+       hammer_volume_ondisk_t ondisk;
        hammer_blockmap_t blockmap;
        hammer_blockmap_t freemap;
        hammer_blockmap_layer1_t layer1;
@@ -224,7 +225,6 @@ blockmap_lookup(hammer_off_t zone_offset,
        hammer_off_t layer2_offset;
        hammer_off_t result_offset;
        int zone;
-       int i;
        int error = 0;
 
        if (save_layer1)
@@ -244,19 +244,18 @@ blockmap_lookup(hammer_off_t zone_offset,
        }
 
        root_volume = get_root_volume();
-       blockmap = &root_volume->ondisk->vol0_blockmap[zone];
+       ondisk = root_volume->ondisk;
+       blockmap = &ondisk->vol0_blockmap[zone];
 
        if (zone == HAMMER_ZONE_RAW_BUFFER_INDEX) {
                result_offset = zone_offset;
        } else if (zone == HAMMER_ZONE_UNDO_INDEX) {
-               i = HAMMER_OFF_SHORT_ENCODE(zone_offset) / HAMMER_BIGBLOCK_SIZE;
                if (zone_offset >= blockmap->alloc_offset) {
                        error = -3;
                        result_offset = HAMMER_OFF_BAD;
                        goto done;
                }
-               result_offset = root_volume->ondisk->vol0_undo_array[i] +
-                               (zone_offset & HAMMER_BIGBLOCK_MASK64);
+               result_offset = hammer_xlate_to_undo(ondisk, zone_offset);
        } else {
                result_offset = hammer_xlate_to_zone2(zone_offset);
        }
@@ -276,7 +275,7 @@ blockmap_lookup(hammer_off_t zone_offset,
         * assign save_layer{1,2}.
         */
 
-       freemap = &root_volume->ondisk->vol0_blockmap[HAMMER_ZONE_FREEMAP_INDEX];
+       freemap = &ondisk->vol0_blockmap[HAMMER_ZONE_FREEMAP_INDEX];
        /*
         * Dive layer 1.
         */
index 849e361..bdd1c0d 100644 (file)
@@ -816,6 +816,16 @@ typedef struct hammer_volume_ondisk {
 #define hammer_xlate_to_phys(volume, zone2_offset)     \
        ((volume)->vol_buf_beg + HAMMER_OFF_SHORT_ENCODE(zone2_offset))
 
+/*
+ * Translate a zone-3 address to zone-2 address
+ */
+#define HAMMER_UNDO_INDEX(zone3_offset)                        \
+       (HAMMER_OFF_SHORT_ENCODE(zone3_offset) / HAMMER_BIGBLOCK_SIZE)
+
+#define hammer_xlate_to_undo(volume, zone3_offset)                     \
+       ((volume)->vol0_undo_array[HAMMER_UNDO_INDEX(zone3_offset)] +   \
+        (zone3_offset & HAMMER_BIGBLOCK_MASK64))
+
 /*
  * Effective per-volume filesystem capacity including big-blocks for layer1/2
  */
index 7179b6a..b348ff7 100644 (file)
@@ -60,7 +60,6 @@ hammer_undo_lookup(hammer_mount_t hmp, hammer_off_t zone3_off, int *errorp)
        hammer_volume_t root_volume;
        hammer_blockmap_t undomap __debugvar;
        hammer_off_t result_offset;
-       int i;
 
        KKASSERT(hammer_is_zone_undo(zone3_off));
        root_volume = hammer_get_root_volume(hmp, errorp);
@@ -70,14 +69,7 @@ hammer_undo_lookup(hammer_mount_t hmp, hammer_off_t zone3_off, int *errorp)
        KKASSERT(HAMMER_ZONE_DECODE(undomap->alloc_offset) == HAMMER_ZONE_UNDO_INDEX);
        KKASSERT(zone3_off < undomap->alloc_offset);
 
-       /*
-        * undo offsets[i] in zone-2 +
-        * big-block offset of zone-3 address
-        * which results zone-2 address
-        */
-       i = HAMMER_OFF_SHORT_ENCODE(zone3_off) / HAMMER_BIGBLOCK_SIZE;
-       result_offset = root_volume->ondisk->vol0_undo_array[i] +
-                       (zone3_off & HAMMER_BIGBLOCK_MASK64);
+       result_offset = hammer_xlate_to_undo(root_volume->ondisk, zone3_off);
 
        hammer_rel_volume(root_volume, 0);
        return(result_offset);