Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef FS_CEPH_FRAG_H
0003 #define FS_CEPH_FRAG_H
0004 
0005 /*
0006  * "Frags" are a way to describe a subset of a 32-bit number space,
0007  * using a mask and a value to match against that mask.  Any given frag
0008  * (subset of the number space) can be partitioned into 2^n sub-frags.
0009  *
0010  * Frags are encoded into a 32-bit word:
0011  *   8 upper bits = "bits"
0012  *  24 lower bits = "value"
0013  * (We could go to 5+27 bits, but who cares.)
0014  *
0015  * We use the _most_ significant bits of the 24 bit value.  This makes
0016  * values logically sort.
0017  *
0018  * Unfortunately, because the "bits" field is still in the high bits, we
0019  * can't sort encoded frags numerically.  However, it does allow you
0020  * to feed encoded frags as values into frag_contains_value.
0021  */
0022 static inline __u32 ceph_frag_make(__u32 b, __u32 v)
0023 {
0024     return (b << 24) |
0025         (v & (0xffffffu << (24-b)) & 0xffffffu);
0026 }
0027 static inline __u32 ceph_frag_bits(__u32 f)
0028 {
0029     return f >> 24;
0030 }
0031 static inline __u32 ceph_frag_value(__u32 f)
0032 {
0033     return f & 0xffffffu;
0034 }
0035 static inline __u32 ceph_frag_mask(__u32 f)
0036 {
0037     return (0xffffffu << (24-ceph_frag_bits(f))) & 0xffffffu;
0038 }
0039 static inline __u32 ceph_frag_mask_shift(__u32 f)
0040 {
0041     return 24 - ceph_frag_bits(f);
0042 }
0043 
0044 static inline bool ceph_frag_contains_value(__u32 f, __u32 v)
0045 {
0046     return (v & ceph_frag_mask(f)) == ceph_frag_value(f);
0047 }
0048 
0049 static inline __u32 ceph_frag_make_child(__u32 f, int by, int i)
0050 {
0051     int newbits = ceph_frag_bits(f) + by;
0052     return ceph_frag_make(newbits,
0053              ceph_frag_value(f) | (i << (24 - newbits)));
0054 }
0055 static inline bool ceph_frag_is_leftmost(__u32 f)
0056 {
0057     return ceph_frag_value(f) == 0;
0058 }
0059 static inline bool ceph_frag_is_rightmost(__u32 f)
0060 {
0061     return ceph_frag_value(f) == ceph_frag_mask(f);
0062 }
0063 static inline __u32 ceph_frag_next(__u32 f)
0064 {
0065     return ceph_frag_make(ceph_frag_bits(f),
0066              ceph_frag_value(f) + (0x1000000 >> ceph_frag_bits(f)));
0067 }
0068 
0069 /*
0070  * comparator to sort frags logically, as when traversing the
0071  * number space in ascending order...
0072  */
0073 int ceph_frag_compare(__u32 a, __u32 b);
0074 
0075 #endif