sys/vfs/hammer: Add HAMMER_DATA_DOALIGN() and variants
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Sun, 6 Nov 2016 06:17:37 +0000 (15:17 +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/blockmap.c
sbin/hammer/cmd_blockmap.c
sys/vfs/hammer/hammer_blockmap.c
sys/vfs/hammer/hammer_disk.h
sys/vfs/hammer/hammer_vnops.c

index 30ddd75..04f5f70 100644 (file)
@@ -126,7 +126,7 @@ alloc_blockmap(int zone, int bytes, hammer_off_t *result_offp,
         * Alignment and buffer-boundary issues.  If the allocation would
         * cross a buffer boundary we have to skip to the next buffer.
         */
-       bytes = (bytes + 15) & ~15;
+       bytes = HAMMER_DATA_DOALIGN(bytes);
        assert(bytes > 0 && bytes <= HAMMER_BUFSIZE);  /* not HAMMER_XBUFSIZE */
        assert(hammer_is_zone2_mapped_index(zone));
 
index ba03334..ed6092b 100644 (file)
@@ -439,7 +439,7 @@ collect_btree_leaf(hammer_btree_elm_t elm)
                break;
        }
        collect_blockmap(elm->leaf.data_offset,
-               (elm->leaf.data_len + 15) & ~15, zone);
+               HAMMER_DATA_DOALIGN(elm->leaf.data_len), zone);
 }
 
 static __inline
index 1daa608..d62ad01 100644 (file)
@@ -99,7 +99,7 @@ hammer_blockmap_alloc(hammer_transaction_t trans, int zone, int bytes,
         * Be careful, certain primary alignments are used below to allocate
         * new blockmap blocks.
         */
-       bytes = (bytes + 15) & ~15;
+       bytes = HAMMER_DATA_DOALIGN(bytes);
        KKASSERT(bytes > 0 && bytes <= HAMMER_XBUFSIZE);
        KKASSERT(hammer_is_zone2_mapped_index(zone));
 
@@ -116,7 +116,7 @@ hammer_blockmap_alloc(hammer_transaction_t trans, int zone, int bytes,
         * Use the hint if we have one.
         */
        if (hint && HAMMER_ZONE_DECODE(hint) == zone) {
-               next_offset = (hint + 15) & ~(hammer_off_t)15;
+               next_offset = HAMMER_DATA_DOALIGN_WITH(hammer_off_t, hint);
                use_hint = 1;
        } else {
                next_offset = blockmap->next_offset;
@@ -446,7 +446,7 @@ hammer_blockmap_reserve(hammer_mount_t hmp, int zone, int bytes,
         * Be careful, certain primary alignments are used below to allocate
         * new blockmap blocks.
         */
-       bytes = (bytes + 15) & ~15;
+       bytes = HAMMER_DATA_DOALIGN(bytes);
        KKASSERT(bytes > 0 && bytes <= HAMMER_XBUFSIZE);
 
        next_offset = blockmap->next_offset;
@@ -675,7 +675,7 @@ hammer_blockmap_reserve_dedup(hammer_mount_t hmp, int zone, int bytes,
        freemap = &hmp->blockmap[HAMMER_ZONE_FREEMAP_INDEX];
        KKASSERT(freemap->phys_offset != 0);
 
-       bytes = (bytes + 15) & ~15;
+       bytes = HAMMER_DATA_DOALIGN(bytes);
        KKASSERT(bytes > 0 && bytes <= HAMMER_XBUFSIZE);
 
        /*
@@ -967,7 +967,7 @@ hammer_blockmap_free(hammer_transaction_t trans,
        /*
         * Alignment
         */
-       bytes = (bytes + 15) & ~15;
+       bytes = HAMMER_DATA_DOALIGN(bytes);
        KKASSERT(bytes <= HAMMER_XBUFSIZE);
        KKASSERT(((zone_offset ^ (zone_offset + (bytes - 1))) &
                  ~HAMMER_BIGBLOCK_MASK64) == 0);
@@ -1101,7 +1101,7 @@ hammer_blockmap_dedup(hammer_transaction_t trans,
        /*
         * Alignment
         */
-       bytes = (bytes + 15) & ~15;
+       bytes = HAMMER_DATA_DOALIGN(bytes);
        KKASSERT(bytes <= HAMMER_BIGBLOCK_SIZE);
        KKASSERT(((zone_offset ^ (zone_offset + (bytes - 1))) &
                  ~HAMMER_BIGBLOCK_MASK64) == 0);
@@ -1211,7 +1211,7 @@ hammer_blockmap_finalize(hammer_transaction_t trans,
        /*
         * Alignment
         */
-       bytes = (bytes + 15) & ~15;
+       bytes = HAMMER_DATA_DOALIGN(bytes);
        KKASSERT(bytes <= HAMMER_XBUFSIZE);
 
        /*
index fcde716..3e928f7 100644 (file)
@@ -905,6 +905,11 @@ typedef struct hammer_inode_data {
 #define HAMMER_INODE_CAP_DIRHASH_ALG3  0x03
 #define HAMMER_INODE_CAP_DIR_LOCAL_INO 0x04    /* use inode localization */
 
+#define HAMMER_DATA_DOALIGN(offset)                            \
+       (((offset) + 15) & ~15)
+#define HAMMER_DATA_DOALIGN_WITH(type, offset)                 \
+       (((type)(offset) + 15) & (~(type)15))
+
 /*
  * A HAMMER directory entry associates a HAMMER filesystem object with a
  * namespace.  It is hooked into a pseudo-filesystem (with its own inode
index 5a6696f..55549fb 100644 (file)
@@ -1061,7 +1061,7 @@ hammer_vop_getattr(struct vop_getattr_args *ap)
                vap->va_bytes = (ip->ino_data.size + HAMMER_BUFMASK64) &
                                ~HAMMER_BUFMASK64;
        } else {
-               vap->va_bytes = (ip->ino_data.size + 15) & ~15;
+               vap->va_bytes = HAMMER_DATA_DOALIGN(ip->ino_data.size);
        }
 
        vap->va_type = hammer_get_vnode_type(ip->ino_data.obj_type);
@@ -3268,7 +3268,7 @@ hammer_vop_strategy_write(struct vop_strategy_args *ap)
        if (bio->bio_offset || ip->ino_data.size > HAMMER_HBUFSIZE)
                bytes = bp->b_bufsize;
        else
-               bytes = ((int)ip->ino_data.size + 15) & ~15;
+               bytes = HAMMER_DATA_DOALIGN_WITH(int, ip->ino_data.size);
 
        record = hammer_ip_add_bulk(ip, bio->bio_offset, bp->b_data,
                                    bytes, &error);