osdmap.h 6.3 KB
Newer Older
S
Sage Weil 已提交
1 2 3 4
#ifndef _FS_CEPH_OSDMAP_H
#define _FS_CEPH_OSDMAP_H

#include <linux/rbtree.h>
5
#include <linux/ceph/types.h>
6
#include <linux/ceph/decode.h>
7
#include <linux/ceph/ceph_fs.h>
8
#include <linux/crush/crush.h>
S
Sage Weil 已提交
9 10 11 12 13 14 15 16 17 18 19 20 21

/*
 * The osd map describes the current membership of the osd cluster and
 * specifies the mapping of objects to placement groups and placement
 * groups to (sets of) osds.  That is, it completely specifies the
 * (desired) distribution of all data objects in the system at some
 * point in time.
 *
 * Each map version is identified by an epoch, which increases monotonically.
 *
 * The map can be updated either via an incremental map (diff) describing
 * the change between two successive epochs, or as a fully encoded map.
 */
22 23 24 25 26
struct ceph_pg {
	uint64_t pool;
	uint32_t seed;
};

I
Ilya Dryomov 已提交
27 28
int ceph_pg_compare(const struct ceph_pg *lhs, const struct ceph_pg *rhs);

29 30
#define CEPH_POOL_FLAG_HASHPSPOOL  1

S
Sage Weil 已提交
31
struct ceph_pg_pool_info {
32
	struct rb_node node;
33 34 35 36 37 38 39
	s64 id;
	u8 type;
	u8 size;
	u8 crush_ruleset;
	u8 object_hash;
	u32 pg_num, pgp_num;
	int pg_num_mask, pgp_num_mask;
40 41
	s64 read_tier;
	s64 write_tier; /* wins for read+write ops */
42
	u64 flags;
43
	char *name;
S
Sage Weil 已提交
44 45
};

46 47 48 49 50 51 52 53 54 55 56 57
static inline bool ceph_can_shift_osds(struct ceph_pg_pool_info *pool)
{
	switch (pool->type) {
	case CEPH_POOL_TYPE_REP:
		return true;
	case CEPH_POOL_TYPE_EC:
		return false;
	default:
		BUG_ON(1);
	}
}

58
struct ceph_object_locator {
59
	s64 pool;
60 61
};

62 63 64 65 66 67 68
/*
 * Maximum supported by kernel client object name length
 *
 * (probably outdated: must be >= RBD_MAX_MD_NAME_LEN -- currently 100)
 */
#define CEPH_MAX_OID_NAME_LEN 100

69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
/*
 * 51-char inline_name is long enough for all cephfs and all but one
 * rbd requests: <imgname> in "<imgname>.rbd"/"rbd_id.<imgname>" can be
 * arbitrarily long (~PAGE_SIZE).  It's done once during rbd map; all
 * other rbd requests fit into inline_name.
 *
 * Makes ceph_object_id 64 bytes on 64-bit.
 */
#define CEPH_OID_INLINE_LEN 52

/*
 * Both inline and external buffers have space for a NUL-terminator,
 * which is carried around.  It's not required though - RADOS object
 * names don't have to be NUL-terminated and may contain NULs.
 */
84
struct ceph_object_id {
85 86
	char *name;
	char inline_name[CEPH_OID_INLINE_LEN];
87 88 89
	int name_len;
};

90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
static inline void ceph_oid_init(struct ceph_object_id *oid)
{
	oid->name = oid->inline_name;
	oid->name_len = 0;
}

static inline bool ceph_oid_empty(const struct ceph_object_id *oid)
{
	return oid->name == oid->inline_name && !oid->name_len;
}

void ceph_oid_copy(struct ceph_object_id *dest,
		   const struct ceph_object_id *src);
__printf(2, 3)
void ceph_oid_printf(struct ceph_object_id *oid, const char *fmt, ...);
__printf(3, 4)
int ceph_oid_aprintf(struct ceph_object_id *oid, gfp_t gfp,
		     const char *fmt, ...);
void ceph_oid_destroy(struct ceph_object_id *oid);

S
Sage Weil 已提交
110 111
struct ceph_pg_mapping {
	struct rb_node node;
112
	struct ceph_pg pgid;
113 114 115 116 117 118

	union {
		struct {
			int len;
			int osds[];
		} pg_temp;
119 120 121
		struct {
			int osd;
		} primary_temp;
122
	};
S
Sage Weil 已提交
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
};

struct ceph_osdmap {
	struct ceph_fsid fsid;
	u32 epoch;
	struct ceph_timespec created, modified;

	u32 flags;         /* CEPH_OSDMAP_* */

	u32 max_osd;       /* size of osd_state, _offload, _addr arrays */
	u8 *osd_state;     /* CEPH_OSD_* */
	u32 *osd_weight;   /* 0 = failed, 0x10000 = 100% normal */
	struct ceph_entity_addr *osd_addr;

	struct rb_root pg_temp;
138 139
	struct rb_root primary_temp;

140 141
	u32 *osd_primary_affinity;

142 143
	struct rb_root pg_pools;
	u32 pool_max;
S
Sage Weil 已提交
144 145 146 147

	/* the CRUSH map specifies the mapping of placement groups to
	 * the list of osds that store+replicate them. */
	struct crush_map *crush;
148 149 150

	struct mutex crush_scratch_mutex;
	int crush_scratch_ary[CEPH_PG_MAX_SIZE * 3];
S
Sage Weil 已提交
151 152
};

153 154 155 156 157 158
static inline int ceph_osd_exists(struct ceph_osdmap *map, int osd)
{
	return osd >= 0 && osd < map->max_osd &&
	       (map->osd_state[osd] & CEPH_OSD_EXISTS);
}

S
Sage Weil 已提交
159 160
static inline int ceph_osd_is_up(struct ceph_osdmap *map, int osd)
{
161 162 163 164 165 166 167
	return ceph_osd_exists(map, osd) &&
	       (map->osd_state[osd] & CEPH_OSD_UP);
}

static inline int ceph_osd_is_down(struct ceph_osdmap *map, int osd)
{
	return !ceph_osd_is_up(map, osd);
S
Sage Weil 已提交
168 169 170 171 172 173 174 175
}

static inline bool ceph_osdmap_flag(struct ceph_osdmap *map, int flag)
{
	return map && (map->flags & flag);
}

extern char *ceph_osdmap_state_str(char *str, int len, int state);
176
extern u32 ceph_get_primary_affinity(struct ceph_osdmap *map, int osd);
S
Sage Weil 已提交
177 178 179 180 181 182 183 184 185

static inline struct ceph_entity_addr *ceph_osd_addr(struct ceph_osdmap *map,
						     int osd)
{
	if (osd >= map->max_osd)
		return NULL;
	return &map->osd_addr[osd];
}

186 187 188 189 190
static inline int ceph_decode_pgid(void **p, void *end, struct ceph_pg *pgid)
{
	__u8 version;

	if (!ceph_has_room(p, end, 1 + 8 + 4 + 4)) {
191
		pr_warn("incomplete pg encoding\n");
192 193 194 195
		return -EINVAL;
	}
	version = ceph_decode_8(p);
	if (version > 1) {
196
		pr_warn("do not understand pg encoding %d > 1\n",
197 198 199 200 201 202 203 204 205 206 207
			(int)version);
		return -EINVAL;
	}

	pgid->pool = ceph_decode_64(p);
	pgid->seed = ceph_decode_32(p);
	*p += 4;	/* skip deprecated preferred value */

	return 0;
}

208
extern struct ceph_osdmap *ceph_osdmap_decode(void **p, void *end);
209 210
struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end,
					     struct ceph_osdmap *map);
S
Sage Weil 已提交
211 212
extern void ceph_osdmap_destroy(struct ceph_osdmap *map);

213 214 215 216 217 218 219 220 221 222 223 224 225 226
struct ceph_osds {
	int osds[CEPH_PG_MAX_SIZE];
	int size;
	int primary; /* id, NOT index */
};

static inline void ceph_osds_init(struct ceph_osds *set)
{
	set->size = 0;
	set->primary = -1;
}

void ceph_osds_copy(struct ceph_osds *dest, const struct ceph_osds *src);

S
Sage Weil 已提交
227
/* calculate mapping of a file extent to an object */
S
Sage Weil 已提交
228
extern int ceph_calc_file_object_mapping(struct ceph_file_layout *layout,
229
					 u64 off, u64 len,
S
Sage Weil 已提交
230
					 u64 *bno, u64 *oxoff, u64 *oxlen);
S
Sage Weil 已提交
231

232 233 234 235
int ceph_object_locator_to_pg(struct ceph_osdmap *osdmap,
			      struct ceph_object_id *oid,
			      struct ceph_object_locator *oloc,
			      struct ceph_pg *raw_pgid);
236

237 238 239 240
void ceph_pg_to_up_acting_osds(struct ceph_osdmap *osdmap,
			       const struct ceph_pg *raw_pgid,
			       struct ceph_osds *up,
			       struct ceph_osds *acting);
241 242
int ceph_pg_to_acting_primary(struct ceph_osdmap *osdmap,
			      const struct ceph_pg *raw_pgid);
S
Sage Weil 已提交
243

I
Ilya Dryomov 已提交
244 245 246
extern struct ceph_pg_pool_info *ceph_pg_pool_by_id(struct ceph_osdmap *map,
						    u64 id);

247
extern const char *ceph_pg_pool_name_by_id(struct ceph_osdmap *map, u64 id);
Y
Yehuda Sadeh 已提交
248 249
extern int ceph_pg_poolid_by_name(struct ceph_osdmap *map, const char *name);

S
Sage Weil 已提交
250
#endif