Skip to content

Commit b459be7

Browse files
committed
crush: sync up with userspace
.. up to ceph.git commit 1db1abc8328d ("crush: eliminate ad hoc diff between kernel and userspace"). This fixes a bunch of recently pulled coding style issues and makes includes a bit cleaner. A patch "crush:Make the function crush_ln static" from Nicholas Krause <xerofoify@gmail.com> is folded in as crush_ln() has been made static in userspace as well. Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
1 parent 8f52979 commit b459be7

7 files changed

Lines changed: 160 additions & 78 deletions

File tree

‎include/linux/crush/crush.h‎

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
#ifndef CEPH_CRUSH_CRUSH_H
22
#define CEPH_CRUSH_CRUSH_H
33

4-
#include <linux/types.h>
4+
#ifdef __KERNEL__
5+
# include <linux/types.h>
6+
#else
7+
# include "crush_compat.h"
8+
#endif
59

610
/*
711
* CRUSH is a pseudo-random data distribution algorithm that
@@ -20,7 +24,11 @@
2024
#define CRUSH_MAGIC 0x00010000ul /* for detecting algorithm revisions */
2125

2226
#define CRUSH_MAX_DEPTH 10 /* max crush hierarchy depth */
27+
#define CRUSH_MAX_RULESET (1<<8) /* max crush ruleset number */
28+
#define CRUSH_MAX_RULES CRUSH_MAX_RULESET /* should be the same as max rulesets */
2329

30+
#define CRUSH_MAX_DEVICE_WEIGHT (100u * 0x10000u)
31+
#define CRUSH_MAX_BUCKET_WEIGHT (65535u * 0x10000u)
2432

2533
#define CRUSH_ITEM_UNDEF 0x7ffffffe /* undefined result (internal use only) */
2634
#define CRUSH_ITEM_NONE 0x7fffffff /* no result */
@@ -108,6 +116,15 @@ enum {
108116
};
109117
extern const char *crush_bucket_alg_name(int alg);
110118

119+
/*
120+
* although tree was a legacy algorithm, it has been buggy, so
121+
* exclude it.
122+
*/
123+
#define CRUSH_LEGACY_ALLOWED_BUCKET_ALGS ( \
124+
(1 << CRUSH_BUCKET_UNIFORM) | \
125+
(1 << CRUSH_BUCKET_LIST) | \
126+
(1 << CRUSH_BUCKET_STRAW))
127+
111128
struct crush_bucket {
112129
__s32 id; /* this'll be negative */
113130
__u16 type; /* non-zero; type=0 is reserved for devices */
@@ -174,7 +191,7 @@ struct crush_map {
174191
/* choose local attempts using a fallback permutation before
175192
* re-descent */
176193
__u32 choose_local_fallback_tries;
177-
/* choose attempts before giving up */
194+
/* choose attempts before giving up */
178195
__u32 choose_total_tries;
179196
/* attempt chooseleaf inner descent once for firstn mode; on
180197
* reject retry outer descent. Note that this does *not*
@@ -187,6 +204,25 @@ struct crush_map {
187204
* that want to limit reshuffling, a value of 3 or 4 will make the
188205
* mappings line up a bit better with previous mappings. */
189206
__u8 chooseleaf_vary_r;
207+
208+
#ifndef __KERNEL__
209+
/*
210+
* version 0 (original) of straw_calc has various flaws. version 1
211+
* fixes a few of them.
212+
*/
213+
__u8 straw_calc_version;
214+
215+
/*
216+
* allowed bucket algs is a bitmask, here the bit positions
217+
* are CRUSH_BUCKET_*. note that these are *bits* and
218+
* CRUSH_BUCKET_* values are not, so we need to or together (1
219+
* << CRUSH_BUCKET_WHATEVER). The 0th bit is not used to
220+
* minimize confusion (bucket type values start at 1).
221+
*/
222+
__u32 allowed_bucket_algs;
223+
224+
__u32 *choose_tries;
225+
#endif
190226
};
191227

192228

‎include/linux/crush/hash.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
#ifndef CEPH_CRUSH_HASH_H
22
#define CEPH_CRUSH_HASH_H
33

4+
#ifdef __KERNEL__
5+
# include <linux/types.h>
6+
#else
7+
# include "crush_compat.h"
8+
#endif
9+
410
#define CRUSH_HASH_RJENKINS1 0
511

612
#define CRUSH_HASH_DEFAULT CRUSH_HASH_RJENKINS1

‎include/linux/crush/mapper.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* LGPL2
99
*/
1010

11-
#include <linux/crush/crush.h>
11+
#include "crush.h"
1212

1313
extern int crush_find_rule(const struct crush_map *map, int ruleset, int type, int size);
1414
extern int crush_do_rule(const struct crush_map *map,

‎net/ceph/crush/crush.c‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
21
#ifdef __KERNEL__
32
# include <linux/slab.h>
3+
# include <linux/crush/crush.h>
44
#else
5-
# include <stdlib.h>
6-
# include <assert.h>
7-
# define kfree(x) do { if (x) free(x); } while (0)
8-
# define BUG_ON(x) assert(!(x))
5+
# include "crush_compat.h"
6+
# include "crush.h"
97
#endif
108

11-
#include <linux/crush/crush.h>
12-
139
const char *crush_bucket_alg_name(int alg)
1410
{
1511
switch (alg) {
@@ -134,6 +130,9 @@ void crush_destroy(struct crush_map *map)
134130
kfree(map->rules);
135131
}
136132

133+
#ifndef __KERNEL__
134+
kfree(map->choose_tries);
135+
#endif
137136
kfree(map);
138137
}
139138

‎net/ceph/crush/crush_ln_table.h‎

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@
1010
*
1111
*/
1212

13-
#if defined(__linux__)
14-
#include <linux/types.h>
15-
#elif defined(__FreeBSD__)
16-
#include <sys/types.h>
17-
#endif
18-
1913
#ifndef CEPH_CRUSH_LN_H
2014
#define CEPH_CRUSH_LN_H
2115

16+
#ifdef __KERNEL__
17+
# include <linux/types.h>
18+
#else
19+
# include "crush_compat.h"
20+
#endif
2221

23-
// RH_LH_tbl[2*k] = 2^48/(1.0+k/128.0)
24-
// RH_LH_tbl[2*k+1] = 2^48*log2(1.0+k/128.0)
25-
26-
static int64_t __RH_LH_tbl[128*2+2] = {
22+
/*
23+
* RH_LH_tbl[2*k] = 2^48/(1.0+k/128.0)
24+
* RH_LH_tbl[2*k+1] = 2^48*log2(1.0+k/128.0)
25+
*/
26+
static __s64 __RH_LH_tbl[128*2+2] = {
2727
0x0001000000000000ll, 0x0000000000000000ll, 0x0000fe03f80fe040ll, 0x000002dfca16dde1ll,
2828
0x0000fc0fc0fc0fc1ll, 0x000005b9e5a170b4ll, 0x0000fa232cf25214ll, 0x0000088e68ea899all,
2929
0x0000f83e0f83e0f9ll, 0x00000b5d69bac77ell, 0x0000f6603d980f67ll, 0x00000e26fd5c8555ll,
@@ -89,11 +89,12 @@ static int64_t __RH_LH_tbl[128*2+2] = {
8989
0x0000820820820821ll, 0x0000fa2f045e7832ll, 0x000081848da8faf1ll, 0x0000fba577877d7dll,
9090
0x0000810204081021ll, 0x0000fd1a708bbe11ll, 0x0000808080808081ll, 0x0000fe8df263f957ll,
9191
0x0000800000000000ll, 0x0000ffff00000000ll,
92-
};
93-
92+
};
9493

95-
// LL_tbl[k] = 2^48*log2(1.0+k/2^15);
96-
static int64_t __LL_tbl[256] = {
94+
/*
95+
* LL_tbl[k] = 2^48*log2(1.0+k/2^15)
96+
*/
97+
static __s64 __LL_tbl[256] = {
9798
0x0000000000000000ull, 0x00000002e2a60a00ull, 0x000000070cb64ec5ull, 0x00000009ef50ce67ull,
9899
0x0000000cd1e588fdull, 0x0000000fb4747e9cull, 0x0000001296fdaf5eull, 0x0000001579811b58ull,
99100
0x000000185bfec2a1ull, 0x0000001b3e76a552ull, 0x0000001e20e8c380ull, 0x0000002103551d43ull,
@@ -160,7 +161,4 @@ static int64_t __LL_tbl[256] = {
160161
0x000002d4562d2ec6ull, 0x000002d73330209dull, 0x000002da102d63b0ull, 0x000002dced24f814ull,
161162
};
162163

163-
164-
165-
166164
#endif

‎net/ceph/crush/hash.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
2-
#include <linux/types.h>
3-
#include <linux/crush/hash.h>
1+
#ifdef __KERNEL__
2+
# include <linux/crush/hash.h>
3+
#else
4+
# include "hash.h"
5+
#endif
46

57
/*
68
* Robert Jenkins' function for mixing 32-bit values

0 commit comments

Comments
 (0)