libceph.h 6.6 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/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 "types.h"
  16. #include "messenger.h"
  17. #include "msgpool.h"
  18. #include "mon_client.h"
  19. #include "osd_client.h"
  20. #include "ceph_fs.h"
  21. /*
  22. * Supported features
  23. */
  24. #define CEPH_FEATURE_SUPPORTED_DEFAULT CEPH_FEATURE_NOSRCADDR
  25. #define CEPH_FEATURE_REQUIRED_DEFAULT CEPH_FEATURE_NOSRCADDR
  26. /*
  27. * mount options
  28. */
  29. #define CEPH_OPT_FSID (1<<0)
  30. #define CEPH_OPT_NOSHARE (1<<1) /* don't share client with other sbs */
  31. #define CEPH_OPT_MYIP (1<<2) /* specified my ip */
  32. #define CEPH_OPT_NOCRC (1<<3) /* no data crc on writes */
  33. #define CEPH_OPT_DEFAULT (0)
  34. #define ceph_set_opt(client, opt) \
  35. (client)->options->flags |= CEPH_OPT_##opt;
  36. #define ceph_test_opt(client, opt) \
  37. (!!((client)->options->flags & CEPH_OPT_##opt))
  38. struct ceph_options {
  39. int flags;
  40. struct ceph_fsid fsid;
  41. struct ceph_entity_addr my_addr;
  42. int mount_timeout;
  43. int osd_idle_ttl;
  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_KEEPALIVE_DEFAULT 5
  61. #define CEPH_OSD_IDLE_TTL_DEFAULT 60
  62. #define CEPH_MSG_MAX_FRONT_LEN (16*1024*1024)
  63. #define CEPH_MSG_MAX_DATA_LEN (16*1024*1024)
  64. #define CEPH_AUTH_NAME_DEFAULT "guest"
  65. /*
  66. * Delay telling the MDS we no longer want caps, in case we reopen
  67. * the file. Delay a minimum amount of time, even if we send a cap
  68. * message for some other reason. Otherwise, take the oppotunity to
  69. * update the mds to avoid sending another message later.
  70. */
  71. #define CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT 5 /* cap release delay */
  72. #define CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT 60 /* cap release delay */
  73. #define CEPH_CAP_RELEASE_SAFETY_DEFAULT (CEPH_CAPS_PER_RELEASE * 4)
  74. /* mount state */
  75. enum {
  76. CEPH_MOUNT_MOUNTING,
  77. CEPH_MOUNT_MOUNTED,
  78. CEPH_MOUNT_UNMOUNTING,
  79. CEPH_MOUNT_UNMOUNTED,
  80. CEPH_MOUNT_SHUTDOWN,
  81. };
  82. /*
  83. * subtract jiffies
  84. */
  85. static inline unsigned long time_sub(unsigned long a, unsigned long b)
  86. {
  87. BUG_ON(time_after(b, a));
  88. return (long)a - (long)b;
  89. }
  90. struct ceph_mds_client;
  91. /*
  92. * per client state
  93. *
  94. * possibly shared by multiple mount points, if they are
  95. * mounting the same ceph filesystem/cluster.
  96. */
  97. struct ceph_client {
  98. struct ceph_fsid fsid;
  99. bool have_fsid;
  100. void *private;
  101. struct ceph_options *options;
  102. struct mutex mount_mutex; /* serialize mount attempts */
  103. wait_queue_head_t auth_wq;
  104. int auth_err;
  105. int (*extra_mon_dispatch)(struct ceph_client *, struct ceph_msg *);
  106. u32 supported_features;
  107. u32 required_features;
  108. struct ceph_messenger msgr; /* messenger instance */
  109. struct ceph_mon_client monc;
  110. struct ceph_osd_client osdc;
  111. #ifdef CONFIG_DEBUG_FS
  112. struct dentry *debugfs_dir;
  113. struct dentry *debugfs_monmap;
  114. struct dentry *debugfs_osdmap;
  115. #endif
  116. };
  117. /*
  118. * snapshots
  119. */
  120. /*
  121. * A "snap context" is the set of existing snapshots when we
  122. * write data. It is used by the OSD to guide its COW behavior.
  123. *
  124. * The ceph_snap_context is refcounted, and attached to each dirty
  125. * page, indicating which context the dirty data belonged when it was
  126. * dirtied.
  127. */
  128. struct ceph_snap_context {
  129. atomic_t nref;
  130. u64 seq;
  131. int num_snaps;
  132. u64 snaps[];
  133. };
  134. static inline struct ceph_snap_context *
  135. ceph_get_snap_context(struct ceph_snap_context *sc)
  136. {
  137. /*
  138. printk("get_snap_context %p %d -> %d\n", sc, atomic_read(&sc->nref),
  139. atomic_read(&sc->nref)+1);
  140. */
  141. if (sc)
  142. atomic_inc(&sc->nref);
  143. return sc;
  144. }
  145. static inline void ceph_put_snap_context(struct ceph_snap_context *sc)
  146. {
  147. if (!sc)
  148. return;
  149. /*
  150. printk("put_snap_context %p %d -> %d\n", sc, atomic_read(&sc->nref),
  151. atomic_read(&sc->nref)-1);
  152. */
  153. if (atomic_dec_and_test(&sc->nref)) {
  154. /*printk(" deleting snap_context %p\n", sc);*/
  155. kfree(sc);
  156. }
  157. }
  158. /*
  159. * calculate the number of pages a given length and offset map onto,
  160. * if we align the data.
  161. */
  162. static inline int calc_pages_for(u64 off, u64 len)
  163. {
  164. return ((off+len+PAGE_CACHE_SIZE-1) >> PAGE_CACHE_SHIFT) -
  165. (off >> PAGE_CACHE_SHIFT);
  166. }
  167. /* ceph_common.c */
  168. extern const char *ceph_msg_type_name(int type);
  169. extern int ceph_check_fsid(struct ceph_client *client, struct ceph_fsid *fsid);
  170. extern struct kmem_cache *ceph_inode_cachep;
  171. extern struct kmem_cache *ceph_cap_cachep;
  172. extern struct kmem_cache *ceph_dentry_cachep;
  173. extern struct kmem_cache *ceph_file_cachep;
  174. extern struct ceph_options *ceph_parse_options(char *options,
  175. const char *dev_name, const char *dev_name_end,
  176. int (*parse_extra_token)(char *c, void *private),
  177. void *private);
  178. extern void ceph_destroy_options(struct ceph_options *opt);
  179. extern int ceph_compare_options(struct ceph_options *new_opt,
  180. struct ceph_client *client);
  181. extern struct ceph_client *ceph_create_client(struct ceph_options *opt,
  182. void *private,
  183. unsigned supported_features,
  184. unsigned required_features);
  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. bool write_page);
  195. extern void ceph_put_page_vector(struct page **pages, int num_pages,
  196. bool dirty);
  197. extern void ceph_release_page_vector(struct page **pages, int num_pages);
  198. extern struct page **ceph_alloc_page_vector(int num_pages, gfp_t flags);
  199. extern int ceph_copy_user_to_page_vector(struct page **pages,
  200. const char __user *data,
  201. loff_t off, size_t len);
  202. extern int ceph_copy_to_page_vector(struct page **pages,
  203. const char *data,
  204. loff_t off, size_t len);
  205. extern int ceph_copy_from_page_vector(struct page **pages,
  206. char *data,
  207. loff_t off, size_t len);
  208. extern int ceph_copy_page_vector_to_user(struct page **pages, char __user *data,
  209. loff_t off, size_t len);
  210. extern void ceph_zero_page_vector_range(int off, int len, struct page **pages);
  211. #endif /* _FS_CEPH_SUPER_H */