ceph_rados.h

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

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

  1. struct ceph_fsid {  
  2.     unsigned char fsid[16];  
  3. };  
以及对应的比较函数:
  1. static inline int ceph_fsid_compare(const struct ceph_fsid *a,  
  2.                     const struct ceph_fsid *b)  
  3. {  
  4.     return memcmp(a, b, sizeof(*a));  
  5. }  
(2)定义保留的snap的id宏
  1. typedef __le64 ceph_snapid_t;  
  2. #define CEPH_SNAPDIR ((__u64)(-1))  /* reserved for hidden .snap dir */  
  3. #define CEPH_NOSNAP  ((__u64)(-2))  /* "head", "live" revision */  
  4. #define CEPH_MAXSNAP ((__u64)(-3))  /* largest valid snapid */  
  5.   
  6. struct ceph_timespec {//自定义的时间描述结构体  
  7.     __le32 tv_sec;  
  8.     __le32 tv_nsec;  
  9. } __attribute__ ((packed));  
(3)对象布局宏:对象怎样放到放置组PG里面去(placement group)
  1. #define CEPH_OBJECT_LAYOUT_HASH     1 //哈希  
  2. #define CEPH_OBJECT_LAYOUT_LINEAR   2 //线性  
  3. #define CEPH_OBJECT_LAYOUT_HASHINO  3 //哈希inode  
  4.   
  5. struct ceph_object_layout {//对象布局  
  6.     struct ceph_pg ol_pgid;   /* raw pg, with _full_ ps precision. */  
  7.     __le32 ol_stripe_unit;    /* for per-object parity, if any */  
  8. } __attribute__ ((packed));  
(4)PG布局宏:PG怎样放置到存储设备上去
  1. #define CEPH_PG_LAYOUT_CRUSH  0 //CRUSH算法,伪随机hash  
  2. #define CEPH_PG_LAYOUT_HASH   1 //hash  
  3. #define CEPH_PG_LAYOUT_LINEAR 2 //线性  
  4. #define CEPH_PG_LAYOUT_HYBRID 3   
  5.   
  6. #define CEPH_PG_MAX_SIZE      16  /* max # osds in a single pg */  
(5)PG编码到一个64位
  1. struct ceph_pg {  
  2.     __le16 preferred; /* preferred primary osd */参考主osd  
  3.     __le16 ps;        /* placement seed */放置种子  
  4.     __le32 pool;      /* object pool */对象池  
  5. } __attribute__ ((packed));  
下面是两种对象池的宏定义:
  1. #define CEPH_PG_TYPE_REP     1 //冗余  
  2. #define CEPH_PG_TYPE_RAID4   2 //raid  
控制PG数量的函数定义:保证b小于bmask并且bmask是2的n次方的最小值
随着时间b的增加产生一个稳定的映射
  1. static inline int ceph_stable_mod(int x, int b, int bmask)  
  2. {  
  3.     if ((x & bmask) < b)  
  4.         return x & bmask;  
  5.     else  
  6.         return x & (bmask >> 1);  
  7. }  
(6)划时代和版本的组合,被用作存储层的序列化突变
  1. struct ceph_eversion {  
  2.     __le32 epoch;  
  3.     __le64 version;  
  4. } __attribute__ ((packed));  
(7)osd(对象存储设备)映射位的宏定义:
  1. #define CEPH_OSD_EXISTS  (1<<0) //osd存在  
  2. #define CEPH_OSD_UP      (1<<1) //  
  3. #define CEPH_OSD_AUTOOUT (1<<2)  /* osd was automatically marked out */自动标出  
  4. #define CEPH_OSD_NEW     (1<<3)  /* osd is new, never marked in */新的,从未标记  
  5.   
  6. extern const char *ceph_osd_state_name(int s);//得到对应的名字,实现如下:  
  7. const char *ceph_osd_state_name(int s)  
  8. {  
  9.     switch (s) {  
  10.     case CEPH_OSD_EXISTS:  
  11.         return "exists";  
  12.     case CEPH_OSD_UP:  
  13.         return "up";  
  14.     case CEPH_OSD_AUTOOUT:  
  15.         return "autoout";  
  16.     case CEPH_OSD_NEW:  
  17.         return "new";  
  18.     default:  
  19.         return "???";  
  20.     }     
  21. }  
  22.   
  23. /* osd weights.  fixed point value: 0x10000 == 1.0 ("in"), 0 == "out" */  
  24. osd的权重值:最大为0x10000相当于1.0,最小为0  
  25. #define CEPH_OSD_IN  0x10000  
  26. #define CEPH_OSD_OUT 0  
(8)osd映射标志位定义:
  1. #define CEPH_OSDMAP_NEARFULL (1<<0)  /* sync writes (near ENOSPC) */  
  2. #define CEPH_OSDMAP_FULL     (1<<1)  /* no data writes (ENOSPC) */  
  3. #define CEPH_OSDMAP_PAUSERD  (1<<2)  /* pause all reads */暂停所有读  
  4. #define CEPH_OSDMAP_PAUSEWR  (1<<3)  /* pause all writes */  
  5. #define CEPH_OSDMAP_PAUSEREC (1<<4)  /* pause recovery */  
  6.   
  7. /* 
  8.  * The error code to return when an OSD can't handle a write 
  9.  * because it is too large. 
  10.  */因为数据太大导致OSD不能处理些时返回的错误代码  
  11. #define OSD_WRITETOOBIG EMSGSIZE  
(9)osd的操作
  1. #define CEPH_OSD_OP_MODE       0xf000 //操作模式  
  2. #define CEPH_OSD_OP_MODE_RD    0x1000 //读  
  3. #define CEPH_OSD_OP_MODE_WR    0x2000 //写  
  4. #define CEPH_OSD_OP_MODE_RMW   0x3000 //读修改写  
  5. #define CEPH_OSD_OP_MODE_SUB   0x4000 //子操作  
  6.   
  7. #define CEPH_OSD_OP_TYPE       0x0f00 //操作类型  
  8. #define CEPH_OSD_OP_TYPE_LOCK  0x0100  //锁  
  9. #define CEPH_OSD_OP_TYPE_DATA  0x0200 //数据  
  10. #define CEPH_OSD_OP_TYPE_ATTR  0x0300 //属性  
  11. #define CEPH_OSD_OP_TYPE_EXEC  0x0400 //执行  
  12. #define CEPH_OSD_OP_TYPE_PG    0x0500 //PG  
  13. #define CEPH_OSD_OP_TYPE_MULTI 0x0600 /* multiobject */多对象  
下面是定义操作模式与类型组合的枚举:
  1. enum {  
  2.     CEPH_OSD_OP_READ = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_DATA | 1,  
  3. 中间省略很多...  
  4.     CEPH_OSD_OP_PGLS_FILTER = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_PG | 2,  
  5. };  
以及定义了判断操作是否为每一种类型或模式的操作,如判断是否为锁操作类型的函数如下:
  1. static inline int ceph_osd_op_type_lock(int op)  
  2. {  
  3.     return (op & CEPH_OSD_OP_TYPE) == CEPH_OSD_OP_TYPE_LOCK;  
  4. }  
返回操作名称的函数:
  1. extern const char *ceph_osd_op_name(int op);  
(10)osd操作标志定义:有详细的英文注释了
  1. enum {  
  2.     CEPH_OSD_FLAG_ACK =            0x0001,  /* want (or is) "ack" ack */  
  3.     CEPH_OSD_FLAG_ONNVRAM =        0x0002,  /* want (or is) "onnvram" ack */  
  4.     CEPH_OSD_FLAG_ONDISK =         0x0004,  /* want (or is) "ondisk" ack */  
  5.     CEPH_OSD_FLAG_RETRY =          0x0008,  /* resend attempt */  
  6.     CEPH_OSD_FLAG_READ =           0x0010,  /* op may read */  
  7.     CEPH_OSD_FLAG_WRITE =          0x0020,  /* op may write */  
  8.     CEPH_OSD_FLAG_ORDERSNAP =      0x0040,  /* EOLDSNAP if snapc is out of order */  
  9.     CEPH_OSD_FLAG_PEERSTAT_OLD =   0x0080,  /* DEPRECATED msg includes osd_peer_stat */  
  10.     CEPH_OSD_FLAG_BALANCE_READS =  0x0100,  
  11.     CEPH_OSD_FLAG_PARALLELEXEC =   0x0200,  /* execute op in parallel */  
  12.     CEPH_OSD_FLAG_PGOP =           0x0400,  /* pg op, no object */  
  13.     CEPH_OSD_FLAG_EXEC =           0x0800,  /* op may exec */  
  14.     CEPH_OSD_FLAG_EXEC_PUBLIC =    0x1000,  /* op may exec (public) */  
  15.     CEPH_OSD_FLAG_LOCALIZE_READS = 0x2000,  /* read from nearby replica, if any */  
  16.     CEPH_OSD_FLAG_RWORDERED =      0x4000,  /* order wrt concurrent reads */  
  17. };  
  18.   
  19. enum {  
  20.     CEPH_OSD_OP_FLAG_EXCL = 1,      /* EXCL object create */  
  21.     CEPH_OSD_OP_FLAG_FAILOK = 2,    /* continue despite failure */  
  22. };  
  23.   
  24. #define EOLDSNAPC    85  /* ORDERSNAP flag set; writer has old snapc*/  
  25. #define EBLACKLISTED 108 /* blacklisted */  
(11)扩展属性比较操作枚举定义:
  1. enum {  
  2.     CEPH_OSD_CMPXATTR_OP_NOP = 0,  
  3.     CEPH_OSD_CMPXATTR_OP_EQ  = 1,  
  4.     CEPH_OSD_CMPXATTR_OP_NE  = 2,  
  5.     CEPH_OSD_CMPXATTR_OP_GT  = 3,  
  6.     CEPH_OSD_CMPXATTR_OP_GTE = 4,  
  7.     CEPH_OSD_CMPXATTR_OP_LT  = 5,  
  8.     CEPH_OSD_CMPXATTR_OP_LTE = 6  
  9. };  
  10.   
  11. enum {  
  12.     CEPH_OSD_CMPXATTR_MODE_STRING = 1,  
  13.     CEPH_OSD_CMPXATTR_MODE_U64    = 2  
  14. };  
(12)osd操作结构体封装定义,可能是来至数据有效负载:
  1. struct ceph_osd_op {  
  2.     __le16 op;           /* CEPH_OSD_OP_* */  
  3.     __le32 flags;        /* CEPH_OSD_FLAG_* */  
  4.     union {//各种数据包格式定义  
  5.         struct {  
  6.             __le64 offset, length;//偏移量和长度  
  7.             __le64 truncate_size;  
  8.             __le32 truncate_seq;  
  9.         } __attribute__ ((packed)) extent;  
  10.         struct {  
  11.             __le32 name_len;  
  12.             __le32 value_len;  
  13.             __u8 cmp_op;       /* CEPH_OSD_CMPXATTR_OP_* */  
  14.             __u8 cmp_mode;     /* CEPH_OSD_CMPXATTR_MODE_* */  
  15.         } __attribute__ ((packed)) xattr;  
  16.         struct {  
  17.             __u8 class_len;  
  18.             __u8 method_len;  
  19.             __u8 argc;  
  20.             __le32 indata_len;  
  21.         } __attribute__ ((packed)) cls;  
  22.         struct {  
  23.             __le64 count;  
  24.             __le32 start_epoch; /* for the pgls sequence */  
  25.         } __attribute__ ((packed)) pgls;  
  26.             struct {  
  27.                 __le64 snapid;  
  28.             } __attribute__ ((packed)) snap;  
  29.         struct {  
  30.             __le64 cookie;  
  31.             __le64 ver;  
  32.             __u8 flag;  /* 0 = unwatch, 1 = watch */  
  33.         } __attribute__ ((packed)) watch;  
  34.         struct {  
  35.             __le64 offset, length;  
  36.             __le64 src_offset;  
  37.         } __attribute__ ((packed)) clonerange;  
  38.     };  
  39.     __le32 payload_len;//数据长度  
  40. } __attribute__ ((packed));  
  41.   
  42. struct ceph_osd_reply_head {//回复头部  
  43.     __le32 client_inc;                /* client incarnation */  
  44.     __le32 flags;  
  45.     struct ceph_object_layout layout;  
  46.     __le32 osdmap_epoch;  
  47.     struct ceph_eversion reassert_version; /* for replaying uncommitted */  
  48.   
  49.     __le32 result;                    /* result code */  
  50.   
  51.     __le32 object_len;                /* length of object name */  
  52.     __le32 num_ops; //操作数量  
  53.     struct ceph_osd_op ops[0];  /* ops[], object */存放所有操作  
  54. } __attribute__ ((packed));  

转载于:https://my.oschina.net/guyson/blog/357149

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值