libceph.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. #ifndef _FS_CEPH_LIBCEPH_H
  2. #define _FS_CEPH_LIBCEPH_H
  3. #include <linux/ceph/ceph_debug.h>
  4. #include <asm/unaligned.h>
  5. #include <linux/backing-dev.h>
  6. #include <linux/completion.h>
  7. #include <linux/exportfs.h>
  8. #include <linux/bug.h>
  9. #include <linux/fs.h>
  10. #include <linux/mempool.h>
  11. #include <linux/pagemap.h>
  12. #include <linux/wait.h>
  13. #include <linux/writeback.h>
  14. #include <linux/slab.h>
  15. #include <linux/ceph/types.h>
  16. #include <linux/ceph/messenger.h>
  17. #include <linux/ceph/msgpool.h>
  18. #include <linux/ceph/mon_client.h>
  19. #include <linux/ceph/osd_client.h>
  20. #include <linux/ceph/ceph_fs.h>
  21. #include <linux/ceph/string_table.h>
  22. /*
  23. * mount options
  24. */
  25. #define CEPH_OPT_FSID (1<<0)
  26. #define CEPH_OPT_NOSHARE (1<<1) /* don't share client with other sbs */
  27. #define CEPH_OPT_MYIP (1<<2) /* specified my ip */
  28. #define CEPH_OPT_NOCRC (1<<3) /* no data crc on writes */
  29. #define CEPH_OPT_NOMSGAUTH (1<<4) /* don't require msg signing feat */
  30. #define CEPH_OPT_TCP_NODELAY (1<<5) /* TCP_NODELAY on TCP sockets */
  31. #define CEPH_OPT_NOMSGSIGN (1<<6) /* don't sign msgs */
  32. #define CEPH_OPT_DEFAULT (CEPH_OPT_TCP_NODELAY)
  33. #define ceph_set_opt(client, opt) \
  34. (client)->options->flags |= CEPH_OPT_##opt;
  35. #define ceph_test_opt(client, opt) \
  36. (!!((client)->options->flags & CEPH_OPT_##opt))
  37. struct ceph_options {
  38. int flags;
  39. struct ceph_fsid fsid;
  40. struct ceph_entity_addr my_addr;
  41. unsigned long mount_timeout; /* jiffies */
  42. unsigned long osd_idle_ttl; /* jiffies */
  43. unsigned long osd_keepalive_timeout; /* jiffies */
  44. /*
  45. * any type that can't be simply compared or doesn't need need
  46. * to be compared should go beyond this point,
  47. * ceph_compare_options() should be updated accordingly
  48. */
  49. struct ceph_entity_addr *mon_addr; /* should be the first
  50. pointer type of args */
  51. int num_mon;
  52. char *name;
  53. struct ceph_crypto_key *key;
  54. };
  55. /*
  56. * defaults
  57. */
  58. #define CEPH_MOUNT_TIMEOUT_DEFAULT msecs_to_jiffies(60 * 1000)
  59. #define CEPH_OSD_KEEPALIVE_DEFAULT msecs_to_jiffies(5 * 1000)
  60. #define CEPH_OSD_IDLE_TTL_DEFAULT msecs_to_jiffies(60 * 1000)
  61. #define CEPH_MONC_HUNT_INTERVAL msecs_to_jiffies(3 * 1000)
  62. #define CEPH_MONC_PING_INTERVAL msecs_to_jiffies(10 * 1000)
  63. #define CEPH_MONC_PING_TIMEOUT msecs_to_jiffies(30 * 1000)
  64. #define CEPH_MONC_HUNT_BACKOFF 2
  65. #define CEPH_MONC_HUNT_MAX_MULT 10
  66. #define CEPH_MSG_MAX_FRONT_LEN (16*1024*1024)
  67. #define CEPH_MSG_MAX_MIDDLE_LEN (16*1024*1024)
  68. #define CEPH_MSG_MAX_DATA_LEN (16*1024*1024)
  69. #define CEPH_AUTH_NAME_DEFAULT "guest"
  70. /*
  71. * Delay telling the MDS we no longer want caps, in case we reopen
  72. * the file. Delay a minimum amount of time, even if we send a cap
  73. * message for some other reason. Otherwise, take the oppotunity to
  74. * update the mds to avoid sending another message later.
  75. */
  76. #define CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT 5 /* cap release delay */
  77. #define CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT 60 /* cap release delay */
  78. #define CEPH_CAP_RELEASE_SAFETY_DEFAULT (CEPH_CAPS_PER_RELEASE * 4)
  79. /* mount state */
  80. enum {
  81. CEPH_MOUNT_MOUNTING,
  82. CEPH_MOUNT_MOUNTED,
  83. CEPH_MOUNT_UNMOUNTING,
  84. CEPH_MOUNT_UNMOUNTED,
  85. CEPH_MOUNT_SHUTDOWN,
  86. };
  87. static inline unsigned long ceph_timeout_jiffies(unsigned long timeout)
  88. {
  89. return timeout ?: MAX_SCHEDULE_TIMEOUT;
  90. }
  91. struct ceph_mds_client;
  92. /*
  93. * per client state
  94. *
  95. * possibly shared by multiple mount points, if they are
  96. * mounting the same ceph filesystem/cluster.
  97. */
  98. struct ceph_client {
  99. struct ceph_fsid fsid;
  100. bool have_fsid;
  101. void *private;
  102. struct ceph_options *options;
  103. struct mutex mount_mutex; /* serialize mount attempts */
  104. wait_queue_head_t auth_wq;
  105. int auth_err;
  106. int (*extra_mon_dispatch)(struct ceph_client *, struct ceph_msg *);
  107. u64 supported_features;
  108. u64 required_features;
  109. struct ceph_messenger msgr; /* messenger instance */
  110. struct ceph_mon_client monc;
  111. struct ceph_osd_client osdc;
  112. #ifdef CONFIG_DEBUG_FS
  113. struct dentry *debugfs_dir;
  114. struct dentry *debugfs_monmap;
  115. struct dentry *debugfs_osdmap;
  116. struct dentry *debugfs_options;
  117. #endif
  118. };
  119. #define from_msgr(ms) container_of(ms, struct ceph_client, msgr)
  120. /*
  121. * snapshots
  122. */
  123. /*
  124. * A "snap context" is the set of existing snapshots when we
  125. * write data. It is used by the OSD to guide its COW behavior.
  126. *
  127. * The ceph_snap_context is refcounted, and attached to each dirty
  128. * page, indicating which context the dirty data belonged when it was
  129. * dirtied.
  130. */
  131. struct ceph_snap_context {
  132. atomic_t nref;
  133. u64 seq;
  134. u32 num_snaps;
  135. u64 snaps[];
  136. };
  137. extern struct ceph_snap_context *ceph_create_snap_context(u32 snap_count,
  138. gfp_t gfp_flags);
  139. extern struct ceph_snap_context *ceph_get_snap_context(
  140. struct ceph_snap_context *sc);
  141. extern void ceph_put_snap_context(struct ceph_snap_context *sc);
  142. /*
  143. * calculate the number of pages a given length and offset map onto,
  144. * if we align the data.
  145. */
  146. static inline int calc_pages_for(u64 off, u64 len)
  147. {
  148. return ((off+len+PAGE_SIZE-1) >> PAGE_SHIFT) -
  149. (off >> PAGE_SHIFT);
  150. }
  151. /*
  152. * These are not meant to be generic - an integer key is assumed.
  153. */
  154. #define DEFINE_RB_INSDEL_FUNCS(name, type, keyfld, nodefld) \
  155. static void insert_##name(struct rb_root *root, type *t) \
  156. { \
  157. struct rb_node **n = &root->rb_node; \
  158. struct rb_node *parent = NULL; \
  159. \
  160. BUG_ON(!RB_EMPTY_NODE(&t->nodefld)); \
  161. \
  162. while (*n) { \
  163. type *cur = rb_entry(*n, type, nodefld); \
  164. \
  165. parent = *n; \
  166. if (t->keyfld < cur->keyfld) \
  167. n = &(*n)->rb_left; \
  168. else if (t->keyfld > cur->keyfld) \
  169. n = &(*n)->rb_right; \
  170. else \
  171. BUG(); \
  172. } \
  173. \
  174. rb_link_node(&t->nodefld, parent, n); \
  175. rb_insert_color(&t->nodefld, root); \
  176. } \
  177. static void erase_##name(struct rb_root *root, type *t) \
  178. { \
  179. BUG_ON(RB_EMPTY_NODE(&t->nodefld)); \
  180. rb_erase(&t->nodefld, root); \
  181. RB_CLEAR_NODE(&t->nodefld); \
  182. }
  183. #define DEFINE_RB_LOOKUP_FUNC(name, type, keyfld, nodefld) \
  184. extern type __lookup_##name##_key; \
  185. static type *lookup_##name(struct rb_root *root, \
  186. typeof(__lookup_##name##_key.keyfld) key) \
  187. { \
  188. struct rb_node *n = root->rb_node; \
  189. \
  190. while (n) { \
  191. type *cur = rb_entry(n, type, nodefld); \
  192. \
  193. if (key < cur->keyfld) \
  194. n = n->rb_left; \
  195. else if (key > cur->keyfld) \
  196. n = n->rb_right; \
  197. else \
  198. return cur; \
  199. } \
  200. \
  201. return NULL; \
  202. }
  203. #define DEFINE_RB_FUNCS(name, type, keyfld, nodefld) \
  204. DEFINE_RB_INSDEL_FUNCS(name, type, keyfld, nodefld) \
  205. DEFINE_RB_LOOKUP_FUNC(name, type, keyfld, nodefld)
  206. extern struct kmem_cache *ceph_inode_cachep;
  207. extern struct kmem_cache *ceph_cap_cachep;
  208. extern struct kmem_cache *ceph_cap_flush_cachep;
  209. extern struct kmem_cache *ceph_dentry_cachep;
  210. extern struct kmem_cache *ceph_file_cachep;
  211. /* ceph_common.c */
  212. extern bool libceph_compatible(void *data);
  213. extern const char *ceph_msg_type_name(int type);
  214. extern int ceph_check_fsid(struct ceph_client *client, struct ceph_fsid *fsid);
  215. extern void *ceph_kvmalloc(size_t size, gfp_t flags);
  216. extern struct ceph_options *ceph_parse_options(char *options,
  217. const char *dev_name, const char *dev_name_end,
  218. int (*parse_extra_token)(char *c, void *private),
  219. void *private);
  220. int ceph_print_client_options(struct seq_file *m, struct ceph_client *client);
  221. extern void ceph_destroy_options(struct ceph_options *opt);
  222. extern int ceph_compare_options(struct ceph_options *new_opt,
  223. struct ceph_client *client);
  224. extern struct ceph_client *ceph_create_client(struct ceph_options *opt,
  225. void *private,
  226. u64 supported_features,
  227. u64 required_features);
  228. struct ceph_entity_addr *ceph_client_addr(struct ceph_client *client);
  229. u64 ceph_client_gid(struct ceph_client *client);
  230. extern void ceph_destroy_client(struct ceph_client *client);
  231. extern int __ceph_open_session(struct ceph_client *client,
  232. unsigned long started);
  233. extern int ceph_open_session(struct ceph_client *client);
  234. /* pagevec.c */
  235. extern void ceph_release_page_vector(struct page **pages, int num_pages);
  236. extern struct page **ceph_get_direct_page_vector(const void __user *data,
  237. int num_pages,
  238. bool write_page);
  239. extern void ceph_put_page_vector(struct page **pages, int num_pages,
  240. bool dirty);
  241. extern struct page **ceph_alloc_page_vector(int num_pages, gfp_t flags);
  242. extern int ceph_copy_user_to_page_vector(struct page **pages,
  243. const void __user *data,
  244. loff_t off, size_t len);
  245. extern void ceph_copy_to_page_vector(struct page **pages,
  246. const void *data,
  247. loff_t off, size_t len);
  248. extern void ceph_copy_from_page_vector(struct page **pages,
  249. void *data,
  250. loff_t off, size_t len);
  251. extern void ceph_zero_page_vector_range(int off, int len, struct page **pages);
  252. #endif /* _FS_CEPH_SUPER_H */