git: sys/vfs/hammer: Use bitwise OR to generate ondisk localization
Tomohiro Kusumi
tkusumi at crater.dragonflybsd.org
Sun Dec 6 09:08:32 PST 2015
commit 7e52af608f079f188f697efc1c0effd28763aff9
Author: Tomohiro Kusumi <kusumi.tomohiro at gmail.com>
Date: Sat Dec 5 16:32:38 2015 +0900
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.
Summary of changes:
sbin/newfs_hammer/newfs_hammer.c | 4 ++--
sys/vfs/hammer/hammer.h | 4 ++--
sys/vfs/hammer/hammer_btree.h | 11 ++++++++---
sys/vfs/hammer/hammer_inode.c | 14 +++++++-------
sys/vfs/hammer/hammer_ioctl.c | 22 +++++++++++-----------
sys/vfs/hammer/hammer_mirror.c | 18 +++++++++---------
sys/vfs/hammer/hammer_object.c | 10 +++++-----
sys/vfs/hammer/hammer_pfs.c | 6 +++---
sys/vfs/hammer/hammer_prune.c | 4 ++--
sys/vfs/hammer/hammer_rebalance.c | 6 +++---
sys/vfs/hammer/hammer_reblock.c | 6 +++---
sys/vfs/hammer/hammer_vfsops.c | 2 +-
sys/vfs/hammer/hammer_vnops.c | 16 ++++++++--------
13 files changed, 64 insertions(+), 59 deletions(-)
http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/7e52af608f079f188f697efc1c0effd28763aff9
--
DragonFly BSD source repository
More information about the Commits
mailing list