sys/vfs/hammer: Add HAMMER_BLOCKMAP_LAYER2_DOALIGN()
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Sun, 6 Nov 2016 05:47:26 +0000 (14:47 +0900)
committerTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Sun, 6 Nov 2016 09:58:20 +0000 (18:58 +0900)
The only reason it's "DOALIGN" instead of just "ALIGN" is
because that's how macros have been named in HAMMER1/2.
"ALIGN" macros represent alignment size.

sbin/hammer/ondisk.c
sys/vfs/hammer/hammer_disk.h
sys/vfs/hammer/hammer_volume.c

index 8839dc0..3ce6444 100644 (file)
@@ -540,8 +540,7 @@ initialize_freemap(struct volume_info *vol)
        root_vol = get_root_volume();
 
        assert_volume_offset(vol);
-       aligned_vol_free_end = (vol->vol_free_end + HAMMER_BLOCKMAP_LAYER2_MASK)
-                               & ~HAMMER_BLOCKMAP_LAYER2_MASK;
+       aligned_vol_free_end = HAMMER_BLOCKMAP_LAYER2_DOALIGN(vol->vol_free_end);
 
        printf("initialize freemap volume %d\n", vol->vol_no);
 
@@ -635,8 +634,7 @@ count_freemap(struct volume_info *vol)
        vol_free_off = HAMMER_ENCODE_RAW_BUFFER(vol->vol_no, 0);
 
        assert_volume_offset(vol);
-       aligned_vol_free_end = (vol->vol_free_end + HAMMER_BLOCKMAP_LAYER2_MASK)
-                               & ~HAMMER_BLOCKMAP_LAYER2_MASK;
+       aligned_vol_free_end = HAMMER_BLOCKMAP_LAYER2_DOALIGN(vol->vol_free_end);
 
        if (vol->vol_no == HAMMER_ROOT_VOLNO)
                vol_free_off += HAMMER_BIGBLOCK_SIZE;
index 82c3ed4..2caa904 100644 (file)
@@ -452,6 +452,10 @@ typedef struct hammer_blockmap_layer2 {
 #define HAMMER_BLOCKMAP_LAYER1_MASK    (HAMMER_BLOCKMAP_LAYER1 - 1)
 #define HAMMER_BLOCKMAP_LAYER2_MASK    (HAMMER_BLOCKMAP_LAYER2 - 1)
 
+#define HAMMER_BLOCKMAP_LAYER2_DOALIGN(offset)                 \
+       (((offset) + HAMMER_BLOCKMAP_LAYER2_MASK) &             \
+        ~HAMMER_BLOCKMAP_LAYER2_MASK)
+
 /*
  * Index within layer1 or layer2 big-block for the entry representing
  * a zone-2 physical offset.
index ef42ee1..73bc10c 100644 (file)
@@ -403,8 +403,7 @@ hammer_format_freemap(hammer_transaction_t trans, hammer_volume_t volume)
        KKASSERT((vol_buf_size & ~HAMMER_OFF_SHORT_MASK) == 0);
        vol_free_end = HAMMER_ENCODE_RAW_BUFFER(ondisk->vol_no,
                        vol_buf_size & ~HAMMER_BIGBLOCK_MASK64);
-       aligned_vol_free_end = (vol_free_end + HAMMER_BLOCKMAP_LAYER2_MASK)
-                       & ~HAMMER_BLOCKMAP_LAYER2_MASK;
+       aligned_vol_free_end = HAMMER_BLOCKMAP_LAYER2_DOALIGN(vol_free_end);
 
        freemap = &hmp->blockmap[HAMMER_ZONE_FREEMAP_INDEX];
        alloc_offset = HAMMER_ENCODE_RAW_BUFFER(volume->vol_no, 0);
@@ -521,8 +520,7 @@ hammer_free_freemap(hammer_transaction_t trans, hammer_volume_t volume)
        KKASSERT((vol_buf_size & ~HAMMER_OFF_SHORT_MASK) == 0);
        vol_free_end = HAMMER_ENCODE_RAW_BUFFER(ondisk->vol_no,
                        vol_buf_size & ~HAMMER_BIGBLOCK_MASK64);
-       aligned_vol_free_end = (vol_free_end + HAMMER_BLOCKMAP_LAYER2_MASK)
-                       & ~HAMMER_BLOCKMAP_LAYER2_MASK;
+       aligned_vol_free_end = HAMMER_BLOCKMAP_LAYER2_DOALIGN(vol_free_end);
 
        freemap = &hmp->blockmap[HAMMER_ZONE_FREEMAP_INDEX];
 
@@ -775,8 +773,7 @@ hammer_count_bigblocks(hammer_mount_t hmp, hammer_volume_t volume,
        KKASSERT((vol_buf_size & ~HAMMER_OFF_SHORT_MASK) == 0);
        vol_free_end = HAMMER_ENCODE_RAW_BUFFER(ondisk->vol_no,
                        vol_buf_size & ~HAMMER_BIGBLOCK_MASK64);
-       aligned_vol_free_end = (vol_free_end + HAMMER_BLOCKMAP_LAYER2_MASK)
-                       & ~HAMMER_BLOCKMAP_LAYER2_MASK;
+       aligned_vol_free_end = HAMMER_BLOCKMAP_LAYER2_DOALIGN(vol_free_end);
 
        freemap = &hmp->blockmap[HAMMER_ZONE_FREEMAP_INDEX];