sys/vfs/hammer: Use bitwise OR to generate ondisk localization
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Sat, 5 Dec 2015 07:32:38 +0000 (16:32 +0900)
committerTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Sun, 6 Dec 2015 16:41:39 +0000 (01:41 +0900)
commit7e52af608f079f188f697efc1c0effd28763aff9
tree0368f0a5e3dc45388cce15eac94a1a5328da4114
parente429799c5e286cd0b40316a902f731bc4c8d690d
sys/vfs/hammer: Use bitwise OR to generate ondisk localization

Use |= to generate localization field for B-Tree elements and
cursor keys instead of +=, since lower 16 bits are bitfields
(or safer to treat INODE=0x1 and MISC=0x2 as bitfields).

The typical code to generate ondisk localization value is to
do either of the followings.

  ondisk_lo = local_variable          + {INODE or MISC};
  ondisk_lo = ip->obj_localization    + {INODE or MISC};
  ondisk_lo = HAMMER_XXX_LOCALIZATION + {INODE or MISC};
              ^^^^^^^^^^^^^^^^^^^^^^^   ^^^^^^^^^^^^^^^
              (A)32 bits localization   (B)lower 16 bits
                 with usually 0 for
                 lower 16 bits for type

Adding (A) and (B) to synthesize PFS id and localization type
could lead to a potential bug if (A) already has type bits set
to either INODE or MISC. For example if (A) had INODE for type
bits and the code is to += INODE for (B), then type bits turn
into MISC (1+1=2) which is not the intention of the code.

This could potentially occur with the first example of above
three where (A) is a local variable or a function argument.
It is not too obvious from the code whether that local variable
has 0 for the lower 16 bits (which basically should be).
If the code just always uses |= no such thing will happen.
13 files changed:
sbin/newfs_hammer/newfs_hammer.c
sys/vfs/hammer/hammer.h
sys/vfs/hammer/hammer_btree.h
sys/vfs/hammer/hammer_inode.c
sys/vfs/hammer/hammer_ioctl.c
sys/vfs/hammer/hammer_mirror.c
sys/vfs/hammer/hammer_object.c
sys/vfs/hammer/hammer_pfs.c
sys/vfs/hammer/hammer_prune.c
sys/vfs/hammer/hammer_rebalance.c
sys/vfs/hammer/hammer_reblock.c
sys/vfs/hammer/hammer_vfsops.c
sys/vfs/hammer/hammer_vnops.c