Sage Weil | 0dee3c2 | 2009-10-06 11:31:06 -0700 | [diff] [blame] | 1 | #ifndef __RADOS_H |
| 2 | #define __RADOS_H |
| 3 | |
| 4 | /* |
| 5 | * Data types for the Ceph distributed object storage layer RADOS |
| 6 | * (Reliable Autonomic Distributed Object Store). |
| 7 | */ |
| 8 | |
| 9 | #include "msgr.h" |
| 10 | |
| 11 | /* |
| 12 | * fs id |
| 13 | */ |
| 14 | struct ceph_fsid { |
| 15 | unsigned char fsid[16]; |
| 16 | }; |
| 17 | |
| 18 | static inline int ceph_fsid_compare(const struct ceph_fsid *a, |
| 19 | const struct ceph_fsid *b) |
| 20 | { |
| 21 | return memcmp(a, b, sizeof(*a)); |
| 22 | } |
| 23 | |
| 24 | /* |
| 25 | * ino, object, etc. |
| 26 | */ |
| 27 | typedef __le64 ceph_snapid_t; |
| 28 | #define CEPH_SNAPDIR ((__u64)(-1)) /* reserved for hidden .snap dir */ |
| 29 | #define CEPH_NOSNAP ((__u64)(-2)) /* "head", "live" revision */ |
| 30 | #define CEPH_MAXSNAP ((__u64)(-3)) /* largest valid snapid */ |
| 31 | |
| 32 | struct ceph_timespec { |
| 33 | __le32 tv_sec; |
| 34 | __le32 tv_nsec; |
| 35 | } __attribute__ ((packed)); |
| 36 | |
| 37 | |
| 38 | /* |
| 39 | * object layout - how objects are mapped into PGs |
| 40 | */ |
| 41 | #define CEPH_OBJECT_LAYOUT_HASH 1 |
| 42 | #define CEPH_OBJECT_LAYOUT_LINEAR 2 |
| 43 | #define CEPH_OBJECT_LAYOUT_HASHINO 3 |
| 44 | |
| 45 | /* |
| 46 | * pg layout -- how PGs are mapped onto (sets of) OSDs |
| 47 | */ |
| 48 | #define CEPH_PG_LAYOUT_CRUSH 0 |
| 49 | #define CEPH_PG_LAYOUT_HASH 1 |
| 50 | #define CEPH_PG_LAYOUT_LINEAR 2 |
| 51 | #define CEPH_PG_LAYOUT_HYBRID 3 |
| 52 | |
| 53 | |
| 54 | /* |
| 55 | * placement group. |
| 56 | * we encode this into one __le64. |
| 57 | */ |
Sage Weil | 5104212 | 2009-11-04 11:39:12 -0800 | [diff] [blame] | 58 | struct ceph_pg { |
| 59 | __le16 preferred; /* preferred primary osd */ |
| 60 | __le16 ps; /* placement seed */ |
| 61 | __le32 pool; /* object pool */ |
Sage Weil | 0dee3c2 | 2009-10-06 11:31:06 -0700 | [diff] [blame] | 62 | } __attribute__ ((packed)); |
| 63 | |
| 64 | /* |
| 65 | * pg_pool is a set of pgs storing a pool of objects |
| 66 | * |
| 67 | * pg_num -- base number of pseudorandomly placed pgs |
| 68 | * |
| 69 | * pgp_num -- effective number when calculating pg placement. this |
| 70 | * is used for pg_num increases. new pgs result in data being "split" |
| 71 | * into new pgs. for this to proceed smoothly, new pgs are intiially |
| 72 | * colocated with their parents; that is, pgp_num doesn't increase |
| 73 | * until the new pgs have successfully split. only _then_ are the new |
| 74 | * pgs placed independently. |
| 75 | * |
| 76 | * lpg_num -- localized pg count (per device). replicas are randomly |
| 77 | * selected. |
| 78 | * |
| 79 | * lpgp_num -- as above. |
| 80 | */ |
| 81 | #define CEPH_PG_TYPE_REP 1 |
| 82 | #define CEPH_PG_TYPE_RAID4 2 |
| 83 | struct ceph_pg_pool { |
| 84 | __u8 type; /* CEPH_PG_TYPE_* */ |
| 85 | __u8 size; /* number of osds in each pg */ |
| 86 | __u8 crush_ruleset; /* crush placement rule */ |
Sage Weil | 1654dd0 | 2009-11-06 21:55:25 -0800 | [diff] [blame] | 87 | __u8 object_hash; /* hash mapping object name to ps */ |
Sage Weil | 0dee3c2 | 2009-10-06 11:31:06 -0700 | [diff] [blame] | 88 | __le32 pg_num, pgp_num; /* number of pg's */ |
| 89 | __le32 lpg_num, lpgp_num; /* number of localized pg's */ |
| 90 | __le32 last_change; /* most recent epoch changed */ |
| 91 | __le64 snap_seq; /* seq for per-pool snapshot */ |
| 92 | __le32 snap_epoch; /* epoch of last snap */ |
| 93 | __le32 num_snaps; |
| 94 | __le32 num_removed_snap_intervals; |
| 95 | } __attribute__ ((packed)); |
| 96 | |
| 97 | /* |
| 98 | * stable_mod func is used to control number of placement groups. |
| 99 | * similar to straight-up modulo, but produces a stable mapping as b |
| 100 | * increases over time. b is the number of bins, and bmask is the |
| 101 | * containing power of 2 minus 1. |
| 102 | * |
| 103 | * b <= bmask and bmask=(2**n)-1 |
| 104 | * e.g., b=12 -> bmask=15, b=123 -> bmask=127 |
| 105 | */ |
| 106 | static inline int ceph_stable_mod(int x, int b, int bmask) |
| 107 | { |
| 108 | if ((x & bmask) < b) |
| 109 | return x & bmask; |
| 110 | else |
| 111 | return x & (bmask >> 1); |
| 112 | } |
| 113 | |
| 114 | /* |
| 115 | * object layout - how a given object should be stored. |
| 116 | */ |
| 117 | struct ceph_object_layout { |
Sage Weil | 5104212 | 2009-11-04 11:39:12 -0800 | [diff] [blame] | 118 | struct ceph_pg ol_pgid; /* raw pg, with _full_ ps precision. */ |
Sage Weil | 0dee3c2 | 2009-10-06 11:31:06 -0700 | [diff] [blame] | 119 | __le32 ol_stripe_unit; /* for per-object parity, if any */ |
| 120 | } __attribute__ ((packed)); |
| 121 | |
| 122 | /* |
| 123 | * compound epoch+version, used by storage layer to serialize mutations |
| 124 | */ |
| 125 | struct ceph_eversion { |
| 126 | __le32 epoch; |
| 127 | __le64 version; |
| 128 | } __attribute__ ((packed)); |
| 129 | |
| 130 | /* |
| 131 | * osd map bits |
| 132 | */ |
| 133 | |
| 134 | /* status bits */ |
| 135 | #define CEPH_OSD_EXISTS 1 |
| 136 | #define CEPH_OSD_UP 2 |
| 137 | |
| 138 | /* osd weights. fixed point value: 0x10000 == 1.0 ("in"), 0 == "out" */ |
| 139 | #define CEPH_OSD_IN 0x10000 |
| 140 | #define CEPH_OSD_OUT 0 |
| 141 | |
| 142 | |
| 143 | /* |
| 144 | * osd map flag bits |
| 145 | */ |
| 146 | #define CEPH_OSDMAP_NEARFULL (1<<0) /* sync writes (near ENOSPC) */ |
| 147 | #define CEPH_OSDMAP_FULL (1<<1) /* no data writes (ENOSPC) */ |
| 148 | #define CEPH_OSDMAP_PAUSERD (1<<2) /* pause all reads */ |
| 149 | #define CEPH_OSDMAP_PAUSEWR (1<<3) /* pause all writes */ |
| 150 | #define CEPH_OSDMAP_PAUSEREC (1<<4) /* pause recovery */ |
| 151 | |
| 152 | /* |
| 153 | * osd ops |
| 154 | */ |
| 155 | #define CEPH_OSD_OP_MODE 0xf000 |
| 156 | #define CEPH_OSD_OP_MODE_RD 0x1000 |
| 157 | #define CEPH_OSD_OP_MODE_WR 0x2000 |
| 158 | #define CEPH_OSD_OP_MODE_RMW 0x3000 |
| 159 | #define CEPH_OSD_OP_MODE_SUB 0x4000 |
| 160 | #define CEPH_OSD_OP_MODE_EXEC 0x8000 |
| 161 | |
| 162 | #define CEPH_OSD_OP_TYPE 0x0f00 |
| 163 | #define CEPH_OSD_OP_TYPE_LOCK 0x0100 |
| 164 | #define CEPH_OSD_OP_TYPE_DATA 0x0200 |
| 165 | #define CEPH_OSD_OP_TYPE_ATTR 0x0300 |
| 166 | #define CEPH_OSD_OP_TYPE_EXEC 0x0400 |
| 167 | #define CEPH_OSD_OP_TYPE_PG 0x0500 |
| 168 | |
| 169 | enum { |
| 170 | /** data **/ |
| 171 | /* read */ |
| 172 | CEPH_OSD_OP_READ = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_DATA | 1, |
| 173 | CEPH_OSD_OP_STAT = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_DATA | 2, |
| 174 | |
| 175 | /* fancy read */ |
| 176 | CEPH_OSD_OP_MASKTRUNC = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_DATA | 4, |
| 177 | |
| 178 | /* write */ |
| 179 | CEPH_OSD_OP_WRITE = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 1, |
| 180 | CEPH_OSD_OP_WRITEFULL = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 2, |
| 181 | CEPH_OSD_OP_TRUNCATE = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 3, |
| 182 | CEPH_OSD_OP_ZERO = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 4, |
| 183 | CEPH_OSD_OP_DELETE = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 5, |
| 184 | |
| 185 | /* fancy write */ |
| 186 | CEPH_OSD_OP_APPEND = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 6, |
| 187 | CEPH_OSD_OP_STARTSYNC = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 7, |
| 188 | CEPH_OSD_OP_SETTRUNC = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 8, |
| 189 | CEPH_OSD_OP_TRIMTRUNC = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 9, |
| 190 | |
| 191 | CEPH_OSD_OP_TMAPUP = CEPH_OSD_OP_MODE_RMW | CEPH_OSD_OP_TYPE_DATA | 10, |
| 192 | CEPH_OSD_OP_TMAPPUT = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 11, |
| 193 | CEPH_OSD_OP_TMAPGET = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_DATA | 12, |
| 194 | |
| 195 | CEPH_OSD_OP_CREATE = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 13, |
| 196 | |
| 197 | /** attrs **/ |
| 198 | /* read */ |
| 199 | CEPH_OSD_OP_GETXATTR = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_ATTR | 1, |
| 200 | CEPH_OSD_OP_GETXATTRS = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_ATTR | 2, |
| 201 | |
| 202 | /* write */ |
| 203 | CEPH_OSD_OP_SETXATTR = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_ATTR | 1, |
| 204 | CEPH_OSD_OP_SETXATTRS = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_ATTR | 2, |
| 205 | CEPH_OSD_OP_RESETXATTRS = CEPH_OSD_OP_MODE_WR|CEPH_OSD_OP_TYPE_ATTR | 3, |
| 206 | CEPH_OSD_OP_RMXATTR = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_ATTR | 4, |
| 207 | |
| 208 | /** subop **/ |
| 209 | CEPH_OSD_OP_PULL = CEPH_OSD_OP_MODE_SUB | 1, |
| 210 | CEPH_OSD_OP_PUSH = CEPH_OSD_OP_MODE_SUB | 2, |
| 211 | CEPH_OSD_OP_BALANCEREADS = CEPH_OSD_OP_MODE_SUB | 3, |
| 212 | CEPH_OSD_OP_UNBALANCEREADS = CEPH_OSD_OP_MODE_SUB | 4, |
| 213 | CEPH_OSD_OP_SCRUB = CEPH_OSD_OP_MODE_SUB | 5, |
| 214 | |
| 215 | /** lock **/ |
| 216 | CEPH_OSD_OP_WRLOCK = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_LOCK | 1, |
| 217 | CEPH_OSD_OP_WRUNLOCK = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_LOCK | 2, |
| 218 | CEPH_OSD_OP_RDLOCK = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_LOCK | 3, |
| 219 | CEPH_OSD_OP_RDUNLOCK = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_LOCK | 4, |
| 220 | CEPH_OSD_OP_UPLOCK = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_LOCK | 5, |
| 221 | CEPH_OSD_OP_DNLOCK = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_LOCK | 6, |
| 222 | |
| 223 | /** exec **/ |
| 224 | CEPH_OSD_OP_CALL = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_EXEC | 1, |
| 225 | |
| 226 | /** pg **/ |
| 227 | CEPH_OSD_OP_PGLS = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_PG | 1, |
| 228 | }; |
| 229 | |
| 230 | static inline int ceph_osd_op_type_lock(int op) |
| 231 | { |
| 232 | return (op & CEPH_OSD_OP_TYPE) == CEPH_OSD_OP_TYPE_LOCK; |
| 233 | } |
| 234 | static inline int ceph_osd_op_type_data(int op) |
| 235 | { |
| 236 | return (op & CEPH_OSD_OP_TYPE) == CEPH_OSD_OP_TYPE_DATA; |
| 237 | } |
| 238 | static inline int ceph_osd_op_type_attr(int op) |
| 239 | { |
| 240 | return (op & CEPH_OSD_OP_TYPE) == CEPH_OSD_OP_TYPE_ATTR; |
| 241 | } |
| 242 | static inline int ceph_osd_op_type_exec(int op) |
| 243 | { |
| 244 | return (op & CEPH_OSD_OP_TYPE) == CEPH_OSD_OP_TYPE_EXEC; |
| 245 | } |
| 246 | static inline int ceph_osd_op_type_pg(int op) |
| 247 | { |
| 248 | return (op & CEPH_OSD_OP_TYPE) == CEPH_OSD_OP_TYPE_PG; |
| 249 | } |
| 250 | |
| 251 | static inline int ceph_osd_op_mode_subop(int op) |
| 252 | { |
| 253 | return (op & CEPH_OSD_OP_MODE) == CEPH_OSD_OP_MODE_SUB; |
| 254 | } |
| 255 | static inline int ceph_osd_op_mode_read(int op) |
| 256 | { |
| 257 | return (op & CEPH_OSD_OP_MODE) == CEPH_OSD_OP_MODE_RD; |
| 258 | } |
| 259 | static inline int ceph_osd_op_mode_modify(int op) |
| 260 | { |
| 261 | return (op & CEPH_OSD_OP_MODE) == CEPH_OSD_OP_MODE_WR; |
| 262 | } |
| 263 | |
| 264 | #define CEPH_OSD_TMAP_HDR 'h' |
| 265 | #define CEPH_OSD_TMAP_SET 's' |
| 266 | #define CEPH_OSD_TMAP_RM 'r' |
| 267 | |
| 268 | extern const char *ceph_osd_op_name(int op); |
| 269 | |
| 270 | |
| 271 | /* |
| 272 | * osd op flags |
| 273 | * |
| 274 | * An op may be READ, WRITE, or READ|WRITE. |
| 275 | */ |
| 276 | enum { |
| 277 | CEPH_OSD_FLAG_ACK = 1, /* want (or is) "ack" ack */ |
| 278 | CEPH_OSD_FLAG_ONNVRAM = 2, /* want (or is) "onnvram" ack */ |
| 279 | CEPH_OSD_FLAG_ONDISK = 4, /* want (or is) "ondisk" ack */ |
| 280 | CEPH_OSD_FLAG_RETRY = 8, /* resend attempt */ |
| 281 | CEPH_OSD_FLAG_READ = 16, /* op may read */ |
| 282 | CEPH_OSD_FLAG_WRITE = 32, /* op may write */ |
| 283 | CEPH_OSD_FLAG_ORDERSNAP = 64, /* EOLDSNAP if snapc is out of order */ |
| 284 | CEPH_OSD_FLAG_PEERSTAT = 128, /* msg includes osd_peer_stat */ |
| 285 | CEPH_OSD_FLAG_BALANCE_READS = 256, |
| 286 | CEPH_OSD_FLAG_PARALLELEXEC = 512, /* execute op in parallel */ |
| 287 | CEPH_OSD_FLAG_PGOP = 1024, /* pg op, no object */ |
| 288 | }; |
| 289 | |
| 290 | enum { |
| 291 | CEPH_OSD_OP_FLAG_EXCL = 1, /* EXCL object create */ |
| 292 | }; |
| 293 | |
| 294 | #define EOLDSNAPC ERESTART /* ORDERSNAP flag set; writer has old snapc*/ |
| 295 | #define EBLACKLISTED ESHUTDOWN /* blacklisted */ |
| 296 | |
| 297 | /* |
| 298 | * an individual object operation. each may be accompanied by some data |
| 299 | * payload |
| 300 | */ |
| 301 | struct ceph_osd_op { |
| 302 | __le16 op; /* CEPH_OSD_OP_* */ |
| 303 | __le32 flags; /* CEPH_OSD_FLAG_* */ |
| 304 | union { |
| 305 | struct { |
| 306 | __le64 offset, length; |
| 307 | } __attribute__ ((packed)) extent; |
| 308 | struct { |
| 309 | __le32 name_len; |
| 310 | __le32 value_len; |
| 311 | } __attribute__ ((packed)) xattr; |
| 312 | struct { |
| 313 | __le64 truncate_size; |
| 314 | __le32 truncate_seq; |
| 315 | } __attribute__ ((packed)) trunc; |
| 316 | struct { |
| 317 | __u8 class_len; |
| 318 | __u8 method_len; |
| 319 | __u8 argc; |
| 320 | __le32 indata_len; |
| 321 | } __attribute__ ((packed)) cls; |
| 322 | struct { |
| 323 | __le64 cookie, count; |
| 324 | } __attribute__ ((packed)) pgls; |
| 325 | }; |
| 326 | __le32 payload_len; |
| 327 | } __attribute__ ((packed)); |
| 328 | |
| 329 | /* |
| 330 | * osd request message header. each request may include multiple |
| 331 | * ceph_osd_op object operations. |
| 332 | */ |
| 333 | struct ceph_osd_request_head { |
| 334 | __le64 tid; /* transaction id */ |
| 335 | __le32 client_inc; /* client incarnation */ |
| 336 | struct ceph_object_layout layout; /* pgid */ |
| 337 | __le32 osdmap_epoch; /* client's osdmap epoch */ |
| 338 | |
| 339 | __le32 flags; |
| 340 | |
| 341 | struct ceph_timespec mtime; /* for mutations only */ |
| 342 | struct ceph_eversion reassert_version; /* if we are replaying op */ |
| 343 | |
| 344 | __le32 object_len; /* length of object name */ |
| 345 | |
| 346 | __le64 snapid; /* snapid to read */ |
| 347 | __le64 snap_seq; /* writer's snap context */ |
| 348 | __le32 num_snaps; |
| 349 | |
| 350 | __le16 num_ops; |
| 351 | struct ceph_osd_op ops[]; /* followed by ops[], obj, ticket, snaps */ |
| 352 | } __attribute__ ((packed)); |
| 353 | |
| 354 | struct ceph_osd_reply_head { |
| 355 | __le64 tid; /* transaction id */ |
| 356 | __le32 client_inc; /* client incarnation */ |
| 357 | __le32 flags; |
| 358 | struct ceph_object_layout layout; |
| 359 | __le32 osdmap_epoch; |
| 360 | struct ceph_eversion reassert_version; /* for replaying uncommitted */ |
| 361 | |
| 362 | __le32 result; /* result code */ |
| 363 | |
| 364 | __le32 object_len; /* length of object name */ |
| 365 | __le32 num_ops; |
| 366 | struct ceph_osd_op ops[0]; /* ops[], object */ |
| 367 | } __attribute__ ((packed)); |
| 368 | |
| 369 | |
| 370 | #endif |