libceph.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. #ifndef _FS_CEPH_LIBCEPH_H
  2. #define _FS_CEPH_LIBCEPH_H
  3. #include "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/fs.h>
  9. #include <linux/mempool.h>
  10. #include <linux/pagemap.h>
  11. #include <linux/wait.h>
  12. #include <linux/writeback.h>
  13. #include <linux/slab.h>
  14. #include "types.h"
  15. #include "messenger.h"
  16. #include "msgpool.h"
  17. #include "mon_client.h"
  18. #include "osd_client.h"
  19. #include "ceph_fs.h"
  20. /*
  21. * Supported features
  22. */
  23. #define CEPH_FEATURE_SUPPORTED_DEFAULT CEPH_FEATURE_NOSRCADDR
  24. #define CEPH_FEATURE_REQUIRED_DEFAULT CEPH_FEATURE_NOSRCADDR
  25. /*
  26. * mount options
  27. */
  28. #define CEPH_OPT_FSID (1<<0)
  29. #define CEPH_OPT_NOSHARE (1<<1) /* don't share client with other sbs */
  30. #define CEPH_OPT_MYIP (1<<2) /* specified my ip */
  31. #define CEPH_OPT_NOCRC (1<<3) /* no data crc on writes */
  32. #define CEPH_OPT_DEFAULT (0)
  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. int mount_timeout;
  42. int osd_idle_ttl;
  43. int osd_timeout;
  44. int osd_keepalive_timeout;
  45. /*
  46. * any type that can't be simply compared or doesn't need need
  47. * to be compared should go beyond this point,
  48. * ceph_compare_options() should be updated accordingly
  49. */
  50. struct ceph_entity_addr *mon_addr; /* should be the first
  51. pointer type of args */
  52. int num_mon;
  53. char *name;
  54. struct ceph_crypto_key *key;
  55. };
  56. /*
  57. * defaults
  58. */
  59. #define CEPH_MOUNT_TIMEOUT_DEFAULT 60
  60. #define CEPH_OSD_TIMEOUT_DEFAULT 60 /* seconds */
  61. #define CEPH_OSD_KEEPALIVE_DEFAULT 5
  62. #define CEPH_OSD_IDLE_TTL_DEFAULT 60
  63. #define CEPH_MSG_MAX_FRONT_LEN (16*1024*1024)
  64. #define CEPH_MSG_MAX_DATA_LEN (16*1024*1024)
  65. #define CEPH_AUTH_NAME_DEFAULT "guest"
  66. /*
  67. * Delay telling the MDS we no longer want caps, in case we reopen
  68. * the file. Delay a minimum amount of time, even if we send a cap
  69. * message for some other reason. Otherwise, take the oppotunity to
  70. * update the mds to avoid sending another message later.
  71. */
  72. #define CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT 5 /* cap release delay */
  73. #define CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT 60 /* cap release delay */
  74. #define CEPH_CAP_RELEASE_SAFETY_DEFAULT (CEPH_CAPS_PER_RELEASE * 4)
  75. /* mount state */
  76. enum {
  77. CEPH_MOUNT_MOUNTING,
  78. CEPH_MOUNT_MOUNTED,
  79. CEPH_MOUNT_UNMOUNTING,
  80. CEPH_MOUNT_UNMOUNTED,
  81. CEPH_MOUNT_SHUTDOWN,
  82. };
  83. /*
  84. * subtract jiffies
  85. */
  86. static inline unsigned long time_sub(unsigned long a, unsigned long b)
  87. {
  88. BUG_ON(time_after(b, a));
  89. return (long)a - (long)b;
  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. u32 supported_features;
  108. u32 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. #endif
  117. };
  118. /*
  119. * snapshots
  120. */
  121. /*
  122. * A "snap context" is the set of existing snapshots when we
  123. * write data. It is used by the OSD to guide its COW behavior.
  124. *
  125. * The ceph_snap_context is refcounted, and attached to each dirty
  126. * page, indicating which context the dirty data belonged when it was
  127. * dirtied.
  128. */
  129. struct ceph_snap_context {
  130. atomic_t nref;
  131. u64 seq;
  132. int num_snaps;
  133. u64 snaps[];
  134. };
  135. static inline struct ceph_snap_context *
  136. ceph_get_snap_context(struct ceph_snap_context *sc)
  137. {
  138. /*
  139. printk("get_snap_context %p %d -> %d\n", sc, atomic_read(&sc->nref),
  140. atomic_read(&sc->nref)+1);
  141. */
  142. if (sc)
  143. atomic_inc(&sc->nref);
  144. return sc;
  145. }
  146. static inline void ceph_put_snap_context(struct ceph_snap_context *sc)
  147. {
  148. if (!sc)
  149. return;
  150. /*
  151. printk("put_snap_context %p %d -> %d\n", sc, atomic_read(&sc->nref),
  152. atomic_read(&sc->nref)-1);
  153. */
  154. if (atomic_dec_and_test(&sc->nref)) {
  155. /*printk(" deleting snap_context %p\n", sc);*/
  156. kfree(sc);
  157. }
  158. }
  159. /*
  160. * calculate the number of pages a given length and offset map onto,
  161. * if we align the data.
  162. */
  163. static inline int calc_pages_for(u64 off, u64 len)
  164. {
  165. return ((off+len+PAGE_CACHE_SIZE-1) >> PAGE_CACHE_SHIFT) -
  166. (off >> PAGE_CACHE_SHIFT);
  167. }
  168. /* ceph_common.c */
  169. extern const char *ceph_msg_type_name(int type);
  170. extern int ceph_check_fsid(struct ceph_client *client, struct ceph_fsid *fsid);
  171. extern struct kmem_cache *ceph_inode_cachep;
  172. extern struct kmem_cache *ceph_cap_cachep;
  173. extern struct kmem_cache *ceph_dentry_cachep;
  174. extern struct kmem_cache *ceph_file_cachep;
  175. extern struct ceph_options *ceph_parse_options(char *options,
  176. const char *dev_name, const char *dev_name_end,
  177. int (*parse_extra_token)(char *c, void *private),
  178. void *private);
  179. extern void ceph_destroy_options(struct ceph_options *opt);
  180. extern int ceph_compare_options(struct ceph_options *new_opt,
  181. struct ceph_client *client);
  182. extern struct ceph_client *ceph_create_client(struct ceph_options *opt,
  183. void *private,
  184. unsigned supported_features,
  185. unsigned required_features);
  186. extern u64 ceph_client_id(struct ceph_client *client);
  187. extern void ceph_destroy_client(struct ceph_client *client);
  188. extern int __ceph_open_session(struct ceph_client *client,
  189. unsigned long started);
  190. extern int ceph_open_session(struct ceph_client *client);
  191. /* pagevec.c */
  192. extern void ceph_release_page_vector(struct page **pages, int num_pages);
  193. extern struct page **ceph_get_direct_page_vector(const char __user *data,
  194. int num_pages,
  195. bool write_page);
  196. extern void ceph_put_page_vector(struct page **pages, int num_pages,
  197. bool dirty);
  198. extern void ceph_release_page_vector(struct page **pages, int num_pages);
  199. extern struct page **ceph_alloc_page_vector(int num_pages, gfp_t flags);
  200. extern int ceph_copy_user_to_page_vector(struct page **pages,
  201. const char __user *data,
  202. loff_t off, size_t len);
  203. extern int ceph_copy_to_page_vector(struct page **pages,
  204. const char *data,
  205. loff_t off, size_t len);
  206. extern int ceph_copy_from_page_vector(struct page **pages,
  207. char *data,
  208. loff_t off, size_t len);
  209. extern int ceph_copy_page_vector_to_user(struct page **pages, char __user *data,
  210. loff_t off, size_t len);
  211. extern void ceph_zero_page_vector_range(int off, int len, struct page **pages);
  212. #endif /* _FS_CEPH_SUPER_H */