ceph主要数据结构解析2-Rados.h文件

(1)文件系统id结构:16个字符组成

struct ceph_fsid {
	unsigned char fsid[16];
};
以及对应的比较函数:
static inline int ceph_fsid_compare(const struct ceph_fsid *a,
				    const struct ceph_fsid *b)
{
	return memcmp(a, b, sizeof(*a));
}
(2)定义保留的snap的id宏
typedef __le64 ceph_snapid_t;
#define CEPH_SNAPDIR ((__u64)(-1))  /* reserved for hidden .snap dir */
#define CEPH_NOSNAP  ((__u64)(-2))  /* "head", "live" revision */
#define CEPH_MAXSNAP ((__u64)(-3))  /* largest valid snapid */

struct ceph_timespec {//自定义的时间描述结构体
	__le32 tv_sec;
	__le32 tv_nsec;
} __attribute__ ((packed));
(3)对象布局宏:对象怎样放到放置组PG里面去(placement group)
#define CEPH_OBJECT_LAYOUT_HASH     1 //哈希
#define CEPH_OBJECT_LAYOUT_LINEAR   2 //线性
#define CEPH_OBJECT_LAYOUT_HASHINO  3 //哈希inode

struct ceph_object_layout {//对象布局
	struct ceph_pg ol_pgid;   /* raw pg, with _full_ ps precision. */
	__le32 ol_stripe_unit;    /* for per-object parity, if any */
} __attribute__ ((packed));
(4)PG布局宏:PG怎样放置到存储设备上去
#define CEPH_PG_LAYOUT_CRUSH  0 //CRUSH算法,伪随机hash
#define CEPH_PG_LAYOUT_HASH   1 //hash
#define CEPH_PG_LAYOUT_LINEAR 2 //线性
#define CEPH_PG_LAYOUT_HYBRID 3 

#define CEPH_PG_MAX_SIZE      16  /* max # osds in a single pg */
(5)PG编码到一个64位
struct ceph_pg {
	__le16 preferred; /* preferred primary osd */参考主osd
	__le16 ps;        /* placement seed */放置种子
	__le32 pool;      /* object pool */对象池
} __attribute__ ((packed));
下面是两种对象池的宏定义:
#define CEPH_PG_TYPE_REP     1 //冗余
#define CEPH_PG_TYPE_RAID4   2 //raid
控制PG数量的函数定义:保证b小于bmask并且bmask是2的n次方的最小值
随着时间b的增加产生一个稳定的映射
static inline int ceph_stable_mod(int x, int b, int bmask)
{
	if ((x & bmask) < b)
		return x & bmask;
	else
		return x & (bmask >> 1);
}
(6)划时代和版本的组合,被用作存储层的序列化突变
struct ceph_eversion {
	__le32 epoch;
	__le64 version;
} __attribute__ ((packed));
(7)osd(对象存储设备)映射位的宏定义:
#define CEPH_OSD_EXISTS  (1<<0) //osd存在
#define CEPH_OSD_UP      (1<<1) //
#define CEPH_OSD_AUTOOUT (1<<2)  /* osd was automatically marked out */自动标出
#define CEPH_OSD_NEW     (1<<3)  /* osd is new, never marked in */新的,从未标记

extern const char *ceph_osd_state_name(int s);//得到对应的名字,实现如下:
const char *ceph_osd_state_name(int s)
{
	switch (s) {
	case CEPH_OSD_EXISTS:
		return "exists";
	case CEPH_OSD_UP:
		return "up";
	case CEPH_OSD_AUTOOUT:
		return "autoout";
	case CEPH_OSD_NEW:
		return "new";
	default:
		return "???";
	}	
}

/* osd weights.  fixed point value: 0x10000 == 1.0 ("in"), 0 == "out" */
osd的权重值:最大为0x10000相当于1.0,最小为0
#define CEPH_OSD_IN  0x10000
#define CEPH_OSD_OUT 0
(8)osd映射标志位定义:
#define CEPH_OSDMAP_NEARFULL (1<<0)  /* sync writes (near ENOSPC) */
#define CEPH_OSDMAP_FULL     (1<<1)  /* no data writes (ENOSPC) */
#define CEPH_OSDMAP_PAUSERD  (1<<2)  /* pause all reads */暂停所有读
#define CEPH_OSDMAP_PAUSEWR  (1<<3)  /* pause all writes */
#define CEPH_OSDMAP_PAUSEREC (1<<4)  /* pause recovery */

/*
 * The error code to return when an OSD can't handle a write
 * because it is too large.
 */因为数据太大导致OSD不能处理些时返回的错误代码
#define OSD_WRITETOOBIG EMSGSIZE
(9)osd的操作
#define CEPH_OSD_OP_MODE       0xf000 //操作模式
#define CEPH_OSD_OP_MODE_RD    0x1000 //读
#define CEPH_OSD_OP_MODE_WR    0x2000 //写
#define CEPH_OSD_OP_MODE_RMW   0x3000 //读修改写
#define CEPH_OSD_OP_MODE_SUB   0x4000 //子操作

#define CEPH_OSD_OP_TYPE       0x0f00 //操作类型
#define CEPH_OSD_OP_TYPE_LOCK  0x0100  //锁
#define CEPH_OSD_OP_TYPE_DATA  0x0200 //数据
#define CEPH_OSD_OP_TYPE_ATTR  0x0300 //属性
#define CEPH_OSD_OP_TYPE_EXEC  0x0400 //执行
#define CEPH_OSD_OP_TYPE_PG    0x0500 //PG
#define CEPH_OSD_OP_TYPE_MULTI 0x0600 /* multiobject */多对象
下面是定义操作模式与类型组合的枚举:
enum {
	CEPH_OSD_OP_READ = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_DATA | 1,
中间省略很多...
	CEPH_OSD_OP_PGLS_FILTER = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_PG | 2,
};
以及定义了判断操作是否为每一种类型或模式的操作,如判断是否为锁操作类型的函数如下:
static inline int ceph_osd_op_type_lock(int op)
{
	return (op & CEPH_OSD_OP_TYPE) == CEPH_OSD_OP_TYPE_LOCK;
}
返回操作名称的函数:
extern const char *ceph_osd_op_name(int op);
(10)osd操作标志定义:有详细的英文注释了
enum {
	CEPH_OSD_FLAG_ACK =            0x0001,  /* want (or is) "ack" ack */
	CEPH_OSD_FLAG_ONNVRAM =        0x0002,  /* want (or is) "onnvram" ack */
	CEPH_OSD_FLAG_ONDISK =         0x0004,  /* want (or is) "ondisk" ack */
	CEPH_OSD_FLAG_RETRY =          0x0008,  /* resend attempt */
	CEPH_OSD_FLAG_READ =           0x0010,  /* op may read */
	CEPH_OSD_FLAG_WRITE =          0x0020,  /* op may write */
	CEPH_OSD_FLAG_ORDERSNAP =      0x0040,  /* EOLDSNAP if snapc is out of order */
	CEPH_OSD_FLAG_PEERSTAT_OLD =   0x0080,  /* DEPRECATED msg includes osd_peer_stat */
	CEPH_OSD_FLAG_BALANCE_READS =  0x0100,
	CEPH_OSD_FLAG_PARALLELEXEC =   0x0200,  /* execute op in parallel */
	CEPH_OSD_FLAG_PGOP =           0x0400,  /* pg op, no object */
	CEPH_OSD_FLAG_EXEC =           0x0800,  /* op may exec */
	CEPH_OSD_FLAG_EXEC_PUBLIC =    0x1000,  /* op may exec (public) */
	CEPH_OSD_FLAG_LOCALIZE_READS = 0x2000,  /* read from nearby replica, if any */
	CEPH_OSD_FLAG_RWORDERED =      0x4000,  /* order wrt concurrent reads */
};

enum {
	CEPH_OSD_OP_FLAG_EXCL = 1,      /* EXCL object create */
	CEPH_OSD_OP_FLAG_FAILOK = 2,    /* continue despite failure */
};

#define EOLDSNAPC    85  /* ORDERSNAP flag set; writer has old snapc*/
#define EBLACKLISTED 108 /* blacklisted */
(11)扩展属性比较操作枚举定义:
enum {
	CEPH_OSD_CMPXATTR_OP_NOP = 0,
	CEPH_OSD_CMPXATTR_OP_EQ  = 1,
	CEPH_OSD_CMPXATTR_OP_NE  = 2,
	CEPH_OSD_CMPXATTR_OP_GT  = 3,
	CEPH_OSD_CMPXATTR_OP_GTE = 4,
	CEPH_OSD_CMPXATTR_OP_LT  = 5,
	CEPH_OSD_CMPXATTR_OP_LTE = 6
};

enum {
	CEPH_OSD_CMPXATTR_MODE_STRING = 1,
	CEPH_OSD_CMPXATTR_MODE_U64    = 2
};
(12)osd操作结构体封装定义,可能是来至数据有效负载:
struct ceph_osd_op {
	__le16 op;           /* CEPH_OSD_OP_* */
	__le32 flags;        /* CEPH_OSD_FLAG_* */
	union {//各种数据包格式定义
		struct {
			__le64 offset, length;//偏移量和长度
			__le64 truncate_size;
			__le32 truncate_seq;
		} __attribute__ ((packed)) extent;
		struct {
			__le32 name_len;
			__le32 value_len;
			__u8 cmp_op;       /* CEPH_OSD_CMPXATTR_OP_* */
			__u8 cmp_mode;     /* CEPH_OSD_CMPXATTR_MODE_* */
		} __attribute__ ((packed)) xattr;
		struct {
			__u8 class_len;
			__u8 method_len;
			__u8 argc;
			__le32 indata_len;
		} __attribute__ ((packed)) cls;
		struct {
			__le64 count;
			__le32 start_epoch; /* for the pgls sequence */
		} __attribute__ ((packed)) pgls;
	        struct {
		        __le64 snapid;
	        } __attribute__ ((packed)) snap;
		struct {
			__le64 cookie;
			__le64 ver;
			__u8 flag;	/* 0 = unwatch, 1 = watch */
		} __attribute__ ((packed)) watch;
		struct {
			__le64 offset, length;
			__le64 src_offset;
		} __attribute__ ((packed)) clonerange;
	};
	__le32 payload_len;//数据长度
} __attribute__ ((packed));

struct ceph_osd_reply_head {//回复头部
	__le32 client_inc;                /* client incarnation */
	__le32 flags;
	struct ceph_object_layout layout;
	__le32 osdmap_epoch;
	struct ceph_eversion reassert_version; /* for replaying uncommitted */

	__le32 result;                    /* result code */

	__le32 object_len;                /* length of object name */
	__le32 num_ops; //操作数量
	struct ceph_osd_op ops[0];  /* ops[], object */存放所有操作
} __attribute__ ((packed));


posted @ 2013-08-16 18:34  pangbangb  阅读(927)  评论(0编辑  收藏  举报