libceph.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. char *secret;
  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_MOUNT_RSIZE_DEFAULT (512*1024) /* readahead */
  64. #define CEPH_MSG_MAX_FRONT_LEN (16*1024*1024)
  65. #define CEPH_MSG_MAX_DATA_LEN (16*1024*1024)
  66. #define CEPH_AUTH_NAME_DEFAULT "guest"
  67. /*
  68. * Delay telling the MDS we no longer want caps, in case we reopen
  69. * the file. Delay a minimum amount of time, even if we send a cap
  70. * message for some other reason. Otherwise, take the oppotunity to
  71. * update the mds to avoid sending another message later.
  72. */
  73. #define CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT 5 /* cap release delay */
  74. #define CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT 60 /* cap release delay */
  75. #define CEPH_CAP_RELEASE_SAFETY_DEFAULT (CEPH_CAPS_PER_RELEASE * 4)
  76. /* mount state */
  77. enum {
  78. CEPH_MOUNT_MOUNTING,
  79. CEPH_MOUNT_MOUNTED,
  80. CEPH_MOUNT_UNMOUNTING,
  81. CEPH_MOUNT_UNMOUNTED,
  82. CEPH_MOUNT_SHUTDOWN,
  83. };
  84. /*
  85. * subtract jiffies
  86. */
  87. static inline unsigned long time_sub(unsigned long a, unsigned long b)
  88. {
  89. BUG_ON(time_after(b, a));
  90. return (long)a - (long)b;
  91. }
  92. struct ceph_mds_client;
  93. /*
  94. * per client state
  95. *
  96. * possibly shared by multiple mount points, if they are
  97. * mounting the same ceph filesystem/cluster.
  98. */
  99. struct ceph_client {
  100. struct ceph_fsid fsid;
  101. bool have_fsid;
  102. void *private;
  103. struct ceph_options *options;
  104. struct mutex mount_mutex; /* serialize mount attempts */
  105. wait_queue_head_t auth_wq;
  106. int auth_err;
  107. int (*extra_mon_dispatch)(struct ceph_client *, struct ceph_msg *);
  108. u32 supported_features;
  109. u32 required_features;
  110. struct ceph_messenger *msgr; /* messenger instance */
  111. struct ceph_mon_client monc;
  112. struct ceph_osd_client osdc;
  113. #ifdef CONFIG_DEBUG_FS
  114. struct dentry *debugfs_dir;
  115. struct dentry *debugfs_monmap;
  116. struct dentry *debugfs_osdmap;
  117. #endif
  118. };
  119. /*
  120. * snapshots
  121. */
  122. /*
  123. * A "snap context" is the set of existing snapshots when we
  124. * write data. It is used by the OSD to guide its COW behavior.
  125. *
  126. * The ceph_snap_context is refcounted, and attached to each dirty
  127. * page, indicating which context the dirty data belonged when it was
  128. * dirtied.
  129. */
  130. struct ceph_snap_context {
  131. atomic_t nref;
  132. u64 seq;
  133. int num_snaps;
  134. u64 snaps[];
  135. };
  136. static inline struct ceph_snap_context *
  137. ceph_get_snap_context(struct ceph_snap_context *sc)
  138. {
  139. /*
  140. printk("get_snap_context %p %d -> %d\n", sc, atomic_read(&sc->nref),
  141. atomic_read(&sc->nref)+1);
  142. */
  143. if (sc)
  144. atomic_inc(&sc->nref);
  145. return sc;
  146. }
  147. static inline void ceph_put_snap_context(struct ceph_snap_context *sc)
  148. {
  149. if (!sc)
  150. return;
  151. /*
  152. printk("put_snap_context %p %d -> %d\n", sc, atomic_read(&sc->nref),
  153. atomic_read(&sc->nref)-1);
  154. */
  155. if (atomic_dec_and_test(&sc->nref)) {
  156. /*printk(" deleting snap_context %p\n", sc);*/
  157. kfree(sc);
  158. }
  159. }
  160. /*
  161. * calculate the number of pages a given length and offset map onto,
  162. * if we align the data.
  163. */
  164. static inline int calc_pages_for(u64 off, u64 len)
  165. {
  166. return ((off+len+PAGE_CACHE_SIZE-1) >> PAGE_CACHE_SHIFT) -
  167. (off >> PAGE_CACHE_SHIFT);
  168. }
  169. /* ceph_common.c */
  170. extern const char *ceph_msg_type_name(int type);
  171. extern int ceph_check_fsid(struct ceph_client *client, struct ceph_fsid *fsid);
  172. extern struct kmem_cache *ceph_inode_cachep;
  173. extern struct kmem_cache *ceph_cap_cachep;
  174. extern struct kmem_cache *ceph_dentry_cachep;
  175. extern struct kmem_cache *ceph_file_cachep;
  176. extern int ceph_parse_options(struct ceph_options **popt, char *options,
  177. const char *dev_name, const char *dev_name_end,
  178. int (*parse_extra_token)(char *c, void *private),
  179. void *private);
  180. extern void ceph_destroy_options(struct ceph_options *opt);
  181. extern int ceph_compare_options(struct ceph_options *new_opt,
  182. struct ceph_client *client);
  183. extern struct ceph_client *ceph_create_client(struct ceph_options *opt,
  184. void *private);
  185. extern u64 ceph_client_id(struct ceph_client *client);
  186. extern void ceph_destroy_client(struct ceph_client *client);
  187. extern int __ceph_open_session(struct ceph_client *client,
  188. unsigned long started);
  189. extern int ceph_open_session(struct ceph_client *client);
  190. /* pagevec.c */
  191. extern void ceph_release_page_vector(struct page **pages, int num_pages);
  192. extern struct page **ceph_get_direct_page_vector(const char __user *data,
  193. int num_pages,
  194. loff_t off, size_t len);
  195. extern void ceph_put_page_vector(struct page **pages, int num_pages);
  196. extern void ceph_release_page_vector(struct page **pages, int num_pages);
  197. extern struct page **ceph_alloc_page_vector(int num_pages, gfp_t flags);
  198. extern int ceph_copy_user_to_page_vector(struct page **pages,
  199. const char __user *data,
  200. loff_t off, size_t len);
  201. extern int ceph_copy_to_page_vector(struct page **pages,
  202. const char *data,
  203. loff_t off, size_t len);
  204. extern int ceph_copy_from_page_vector(struct page **pages,
  205. char *data,
  206. loff_t off, size_t len);
  207. extern int ceph_copy_page_vector_to_user(struct page **pages, char __user *data,
  208. loff_t off, size_t len);
  209. extern void ceph_zero_page_vector_range(int off, int len, struct page **pages);
  210. #endif /* _FS_CEPH_SUPER_H */