sys/vfs/hammer: Use HAMMER_OFF_{SHORT,LONG}_ENCODE()
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Tue, 1 Nov 2016 12:44:06 +0000 (21:44 +0900)
committerTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Tue, 1 Nov 2016 13:44:12 +0000 (22:44 +0900)
HAMMER_OFF_XXX_ENCODE() macros cast result to hammer_off_t,
which is uint64_t, but makes no difference in these cases.

sbin/hammer/blockmap.c
sbin/hammer/misc.c
sbin/hammer/ondisk.c
sbin/newfs_hammer/newfs_hammer.c
sys/vfs/hammer/hammer_disk.h
sys/vfs/hammer/hammer_recover.c
sys/vfs/hammer/hammer_undo.c

index 6137e82..30ddd75 100644 (file)
@@ -243,8 +243,7 @@ blockmap_lookup(hammer_off_t zone_offset,
        if (zone == HAMMER_ZONE_RAW_BUFFER_INDEX) {
                result_offset = zone_offset;
        } else if (zone == HAMMER_ZONE_UNDO_INDEX) {
-               i = (zone_offset & HAMMER_OFF_SHORT_MASK) /
-                   HAMMER_BIGBLOCK_SIZE;
+               i = HAMMER_OFF_SHORT_ENCODE(zone_offset) / HAMMER_BIGBLOCK_SIZE;
                if (zone_offset >= blockmap->alloc_offset) {
                        error = -3;
                        result_offset = HAMMER_OFF_BAD;
index df664cb..fdcb0c1 100644 (file)
@@ -283,7 +283,7 @@ hammer_add_zone_stat(struct zone_stat *stats, hammer_off_t offset, int bytes)
        zone = HAMMER_ZONE_DECODE(offset);
        vol = HAMMER_VOL_DECODE(offset);
 
-       offset &= HAMMER_OFF_SHORT_MASK;  /* cut off volume bits from layer1 */
+       offset = HAMMER_OFF_SHORT_ENCODE(offset); /* cut off volume bits */
        i = HAMMER_BLOCKMAP_LAYER1_INDEX(offset);
        j = HAMMER_BLOCKMAP_LAYER2_INDEX(offset);
 
index 42b95fa..730892f 100644 (file)
@@ -728,7 +728,7 @@ format_undomap(struct volume_info *root_vol, int64_t *undo_buffer_size)
         * Pre-initialize the UNDO blocks (HAMMER version 4+)
         */
        printf("initializing the undo map (%jd MB)\n",
-               (intmax_t)(blockmap->alloc_offset & HAMMER_OFF_LONG_MASK) /
+               (intmax_t)HAMMER_OFF_LONG_ENCODE(blockmap->alloc_offset) /
                (1024 * 1024));
 
        scan = blockmap->first_offset;
@@ -801,12 +801,12 @@ print_blockmap(const struct volume_info *vol)
               (uintmax_t)ondisk->vol0_next_tid);
 
        blockmap = &ondisk->vol0_blockmap[HAMMER_ZONE_UNDO_INDEX];
-       size = blockmap->alloc_offset & HAMMER_OFF_LONG_MASK;
+       size = HAMMER_OFF_LONG_ENCODE(blockmap->alloc_offset);
        if (blockmap->first_offset <= blockmap->next_offset)
                used = blockmap->next_offset - blockmap->first_offset;
        else
                used = blockmap->alloc_offset - blockmap->first_offset +
-                       (blockmap->next_offset & HAMMER_OFF_LONG_MASK);
+                       HAMMER_OFF_LONG_ENCODE(blockmap->next_offset);
        printf(INDENT"undo_size\t%s\n", sizetostr(size));
        printf(INDENT"undo_used\t%s\n", sizetostr(used));
 
index 128d91c..1f0f6ae 100644 (file)
@@ -286,7 +286,7 @@ print_volume(const struct volume_info *vol)
        printf("undo-buffer-size:    %s\n",
                sizetostr(HAMMER_OFF_LONG_ENCODE(blockmap->alloc_offset)));
        printf("total-pre-allocated: %s\n",
-               sizetostr(vol->vol_free_off & HAMMER_OFF_SHORT_MASK));
+               sizetostr(HAMMER_OFF_SHORT_ENCODE(vol->vol_free_off)));
        printf("fsid:                %s\n", fsidstr);
        printf("\n");
        printf("NOTE: Please remember that you may have to manually set up a\n"
index 3833381..80f7192 100644 (file)
@@ -733,8 +733,7 @@ typedef struct hammer_volume_ondisk {
  * Translate a zone-2 address to physical address
  */
 #define hammer_xlate_to_phys(volume, zone2_offset)     \
-       ((volume)->vol_buf_beg +                        \
-        ((zone2_offset) & HAMMER_OFF_SHORT_MASK))
+       ((volume)->vol_buf_beg + HAMMER_OFF_SHORT_ENCODE(zone2_offset))
 
 /*
  * Effective per-volume filesystem capacity including big-blocks for layer1/2
index 08221e9..73377f7 100644 (file)
@@ -319,10 +319,10 @@ hammer_recover_stage1(hammer_mount_t hmp, hammer_volume_t root_volume)
                                bytes = last_offset - scan_offset;
                        } else {
                                bytes = rootmap->alloc_offset - scan_offset +
-                                       (last_offset & HAMMER_OFF_LONG_MASK);
+                                       HAMMER_OFF_LONG_ENCODE(last_offset);
                        }
                        if (bytes >
-                           (rootmap->alloc_offset & HAMMER_OFF_LONG_MASK) *
+                           HAMMER_OFF_LONG_ENCODE(rootmap->alloc_offset) *
                            4 / 5) {
                                hvkprintf(root_volume,
                                        "recovery forward scan is "
@@ -365,7 +365,7 @@ hammer_recover_stage1(hammer_mount_t hmp, hammer_volume_t root_volume)
                bytes = last_offset - first_offset;
        } else {
                bytes = rootmap->alloc_offset - first_offset +
-                       (last_offset & HAMMER_OFF_LONG_MASK);
+                       HAMMER_OFF_LONG_ENCODE(last_offset);
        }
        if (bytes == 0) {
                degenerate_case = 1;
@@ -379,7 +379,7 @@ hammer_recover_stage1(hammer_mount_t hmp, hammer_volume_t root_volume)
                (intmax_t)last_offset,
                (intmax_t)bytes,
                (hmp->ronly ? " (RO)" : "(RW)"));
-       if (bytes > (rootmap->alloc_offset & HAMMER_OFF_LONG_MASK)) {
+       if (bytes > HAMMER_OFF_LONG_ENCODE(rootmap->alloc_offset)) {
                hkprintf("Undo size is absurd, unable to mount\n");
                error = EIO;
                goto done;
@@ -585,7 +585,7 @@ hammer_recover_stage2(hammer_mount_t hmp, hammer_volume_t root_volume)
                bytes = last_offset - first_offset;
        } else {
                bytes = rootmap->alloc_offset - first_offset +
-                       (last_offset & HAMMER_OFF_LONG_MASK);
+                       HAMMER_OFF_LONG_ENCODE(last_offset);
        }
        hvkprintf(root_volume,
                "recovery redo  %016jx-%016jx (%jd bytes)%s\n",
@@ -594,7 +594,7 @@ hammer_recover_stage2(hammer_mount_t hmp, hammer_volume_t root_volume)
                (intmax_t)bytes,
                (hmp->ronly ? " (RO)" : "(RW)"));
        verbose = 1;
-       if (bytes > (rootmap->alloc_offset & HAMMER_OFF_LONG_MASK)) {
+       if (bytes > HAMMER_OFF_LONG_ENCODE(rootmap->alloc_offset)) {
                hkprintf("Undo size is absurd, unable to mount\n");
                error = EIO;
                goto fatal;
@@ -620,7 +620,7 @@ hammer_recover_stage2(hammer_mount_t hmp, hammer_volume_t root_volume)
                } else if (ext_offset > last_offset) {
                        dorscan = 1;
                        ext_bytes = (rootmap->alloc_offset - ext_offset) +
-                                   (first_offset & HAMMER_OFF_LONG_MASK);
+                                   HAMMER_OFF_LONG_ENCODE(first_offset);
                } else {
                        ext_bytes = -(ext_offset - first_offset);
                        dorscan = 0;
@@ -631,7 +631,7 @@ hammer_recover_stage2(hammer_mount_t hmp, hammer_volume_t root_volume)
                 */
                if (ext_offset < last_offset) {
                        ext_bytes = -((rootmap->alloc_offset - first_offset) +
-                                   (ext_offset & HAMMER_OFF_LONG_MASK));
+                                   HAMMER_OFF_LONG_ENCODE(ext_offset));
                        dorscan = 0;
                } else if (ext_offset > first_offset) {
                        ext_bytes = -(ext_offset - first_offset);
index b70491f..ea54934 100644 (file)
@@ -75,7 +75,7 @@ hammer_undo_lookup(hammer_mount_t hmp, hammer_off_t zone3_off, int *errorp)
         * big-block offset of zone-3 address
         * which results zone-2 address
         */
-       i = (zone3_off & HAMMER_OFF_SHORT_MASK) / HAMMER_BIGBLOCK_SIZE;
+       i = HAMMER_OFF_SHORT_ENCODE(zone3_off) / HAMMER_BIGBLOCK_SIZE;
        result_offset = root_volume->ondisk->vol0_undo_array[i] +
                        (zone3_off & HAMMER_BIGBLOCK_MASK64);
 
@@ -500,9 +500,9 @@ hammer_undo_used(hammer_transaction_t trans)
                bytes = cundomap->next_offset - dundomap->first_offset;
        } else {
                bytes = cundomap->alloc_offset - dundomap->first_offset +
-                       (cundomap->next_offset & HAMMER_OFF_LONG_MASK);
+                       HAMMER_OFF_LONG_ENCODE(cundomap->next_offset);
        }
-       max_bytes = cundomap->alloc_offset & HAMMER_OFF_SHORT_MASK;
+       max_bytes = HAMMER_OFF_SHORT_ENCODE(cundomap->alloc_offset);
        KKASSERT(bytes <= max_bytes);
        return(bytes);
 }
@@ -517,7 +517,7 @@ hammer_undo_space(hammer_transaction_t trans)
        int64_t max_bytes;
 
        rootmap = &trans->hmp->blockmap[HAMMER_ZONE_UNDO_INDEX];
-       max_bytes = rootmap->alloc_offset & HAMMER_OFF_SHORT_MASK;
+       max_bytes = HAMMER_OFF_SHORT_ENCODE(rootmap->alloc_offset);
        return(max_bytes - hammer_undo_used(trans));
 }
 
@@ -528,7 +528,7 @@ hammer_undo_max(hammer_mount_t hmp)
        int64_t max_bytes;
 
        rootmap = &hmp->blockmap[HAMMER_ZONE_UNDO_INDEX];
-       max_bytes = rootmap->alloc_offset & HAMMER_OFF_SHORT_MASK;
+       max_bytes = HAMMER_OFF_SHORT_ENCODE(rootmap->alloc_offset);
 
        return(max_bytes);
 }