Merge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[cris-mirror.git] / include / linux / ceph / ceph_frag.h
blob97bab0adc58ac4cc4f8704ec9661178548e3adbc
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef FS_CEPH_FRAG_H
3 #define FS_CEPH_FRAG_H
5 /*
6 * "Frags" are a way to describe a subset of a 32-bit number space,
7 * using a mask and a value to match against that mask. Any given frag
8 * (subset of the number space) can be partitioned into 2^n sub-frags.
10 * Frags are encoded into a 32-bit word:
11 * 8 upper bits = "bits"
12 * 24 lower bits = "value"
13 * (We could go to 5+27 bits, but who cares.)
15 * We use the _most_ significant bits of the 24 bit value. This makes
16 * values logically sort.
18 * Unfortunately, because the "bits" field is still in the high bits, we
19 * can't sort encoded frags numerically. However, it does allow you
20 * to feed encoded frags as values into frag_contains_value.
22 static inline __u32 ceph_frag_make(__u32 b, __u32 v)
24 return (b << 24) |
25 (v & (0xffffffu << (24-b)) & 0xffffffu);
27 static inline __u32 ceph_frag_bits(__u32 f)
29 return f >> 24;
31 static inline __u32 ceph_frag_value(__u32 f)
33 return f & 0xffffffu;
35 static inline __u32 ceph_frag_mask(__u32 f)
37 return (0xffffffu << (24-ceph_frag_bits(f))) & 0xffffffu;
39 static inline __u32 ceph_frag_mask_shift(__u32 f)
41 return 24 - ceph_frag_bits(f);
44 static inline bool ceph_frag_contains_value(__u32 f, __u32 v)
46 return (v & ceph_frag_mask(f)) == ceph_frag_value(f);
49 static inline __u32 ceph_frag_make_child(__u32 f, int by, int i)
51 int newbits = ceph_frag_bits(f) + by;
52 return ceph_frag_make(newbits,
53 ceph_frag_value(f) | (i << (24 - newbits)));
55 static inline bool ceph_frag_is_leftmost(__u32 f)
57 return ceph_frag_value(f) == 0;
59 static inline bool ceph_frag_is_rightmost(__u32 f)
61 return ceph_frag_value(f) == ceph_frag_mask(f);
63 static inline __u32 ceph_frag_next(__u32 f)
65 return ceph_frag_make(ceph_frag_bits(f),
66 ceph_frag_value(f) + (0x1000000 >> ceph_frag_bits(f)));
70 * comparator to sort frags logically, as when traversing the
71 * number space in ascending order...
73 int ceph_frag_compare(__u32 a, __u32 b);
75 #endif