libceph.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. /*
  22. * mount options
  23. */
  24. #define CEPH_OPT_FSID (1<<0)
  25. #define CEPH_OPT_NOSHARE (1<<1) /* don't share client with other sbs */
  26. #define CEPH_OPT_MYIP (1<<2) /* specified my ip */
  27. #define CEPH_OPT_NOCRC (1<<3) /* no data crc on writes */
  28. #define CEPH_OPT_DEFAULT (0)
  29. #define ceph_set_opt(client, opt) \
  30. (client)->options->flags |= CEPH_OPT_##opt;
  31. #define ceph_test_opt(client, opt) \
  32. (!!((client)->options->flags & CEPH_OPT_##opt))
  33. struct ceph_options {
  34. int flags;
  35. struct ceph_fsid fsid;
  36. struct ceph_entity_addr my_addr;
  37. int mount_timeout;
  38. int osd_idle_ttl;
  39. int osd_keepalive_timeout;
  40. /*
  41. * any type that can't be simply compared or doesn't need need
  42. * to be compared should go beyond this point,
  43. * ceph_compare_options() should be updated accordingly
  44. */
  45. struct ceph_entity_addr *mon_addr; /* should be the first
  46. pointer type of args */
  47. int num_mon;
  48. char *name;
  49. struct ceph_crypto_key *key;
  50. };
  51. /*
  52. * defaults
  53. */
  54. #define CEPH_MOUNT_TIMEOUT_DEFAULT 60
  55. #define CEPH_OSD_KEEPALIVE_DEFAULT 5
  56. #define CEPH_OSD_IDLE_TTL_DEFAULT 60
  57. #define CEPH_MSG_MAX_FRONT_LEN (16*1024*1024)
  58. #define CEPH_MSG_MAX_MIDDLE_LEN (16*1024*1024)
  59. #define CEPH_MSG_MAX_DATA_LEN (16*1024*1024)
  60. #define CEPH_AUTH_NAME_DEFAULT "guest"
  61. /*
  62. * Delay telling the MDS we no longer want caps, in case we reopen
  63. * the file. Delay a minimum amount of time, even if we send a cap
  64. * message for some other reason. Otherwise, take the oppotunity to
  65. * update the mds to avoid sending another message later.
  66. */
  67. #define CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT 5 /* cap release delay */
  68. #define CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT 60 /* cap release delay */
  69. #define CEPH_CAP_RELEASE_SAFETY_DEFAULT (CEPH_CAPS_PER_RELEASE * 4)
  70. /* mount state */
  71. enum {
  72. CEPH_MOUNT_MOUNTING,
  73. CEPH_MOUNT_MOUNTED,
  74. CEPH_MOUNT_UNMOUNTING,
  75. CEPH_MOUNT_UNMOUNTED,
  76. CEPH_MOUNT_SHUTDOWN,
  77. };
  78. /*
  79. * subtract jiffies
  80. */
  81. static inline unsigned long time_sub(unsigned long a, unsigned long b)
  82. {
  83. BUG_ON(time_after(b, a));
  84. return (long)a - (long)b;
  85. }
  86. struct ceph_mds_client;
  87. /*
  88. * per client state
  89. *
  90. * possibly shared by multiple mount points, if they are
  91. * mounting the same ceph filesystem/cluster.
  92. */
  93. struct ceph_client {
  94. struct ceph_fsid fsid;
  95. bool have_fsid;
  96. void *private;
  97. struct ceph_options *options;
  98. struct mutex mount_mutex; /* serialize mount attempts */
  99. wait_queue_head_t auth_wq;
  100. int auth_err;
  101. int (*extra_mon_dispatch)(struct ceph_client *, struct ceph_msg *);
  102. u32 supported_features;
  103. u32 required_features;
  104. struct ceph_messenger msgr; /* messenger instance */
  105. struct ceph_mon_client monc;
  106. struct ceph_osd_client osdc;
  107. #ifdef CONFIG_DEBUG_FS
  108. struct dentry *debugfs_dir;
  109. struct dentry *debugfs_monmap;
  110. struct dentry *debugfs_osdmap;
  111. #endif
  112. };
  113. /*
  114. * snapshots
  115. */
  116. /*
  117. * A "snap context" is the set of existing snapshots when we
  118. * write data. It is used by the OSD to guide its COW behavior.
  119. *
  120. * The ceph_snap_context is refcounted, and attached to each dirty
  121. * page, indicating which context the dirty data belonged when it was
  122. * dirtied.
  123. */
  124. struct ceph_snap_context {
  125. atomic_t nref;
  126. u64 seq;
  127. u32 num_snaps;
  128. u64 snaps[];
  129. };
  130. extern struct ceph_snap_context *ceph_create_snap_context(u32 snap_count,
  131. gfp_t gfp_flags);
  132. extern struct ceph_snap_context *ceph_get_snap_context(
  133. struct ceph_snap_context *sc);
  134. extern void ceph_put_snap_context(struct ceph_snap_context *sc);
  135. /*
  136. * calculate the number of pages a given length and offset map onto,
  137. * if we align the data.
  138. */
  139. static inline int calc_pages_for(u64 off, u64 len)
  140. {
  141. return ((off+len+PAGE_CACHE_SIZE-1) >> PAGE_CACHE_SHIFT) -
  142. (off >> PAGE_CACHE_SHIFT);
  143. }
  144. /* ceph_common.c */
  145. extern bool libceph_compatible(void *data);
  146. extern const char *ceph_msg_type_name(int type);
  147. extern int ceph_check_fsid(struct ceph_client *client, struct ceph_fsid *fsid);
  148. extern struct kmem_cache *ceph_inode_cachep;
  149. extern struct kmem_cache *ceph_cap_cachep;
  150. extern struct kmem_cache *ceph_dentry_cachep;
  151. extern struct kmem_cache *ceph_file_cachep;
  152. extern struct ceph_options *ceph_parse_options(char *options,
  153. const char *dev_name, const char *dev_name_end,
  154. int (*parse_extra_token)(char *c, void *private),
  155. void *private);
  156. extern void ceph_destroy_options(struct ceph_options *opt);
  157. extern int ceph_compare_options(struct ceph_options *new_opt,
  158. struct ceph_client *client);
  159. extern struct ceph_client *ceph_create_client(struct ceph_options *opt,
  160. void *private,
  161. unsigned supported_features,
  162. unsigned required_features);
  163. extern u64 ceph_client_id(struct ceph_client *client);
  164. extern void ceph_destroy_client(struct ceph_client *client);
  165. extern int __ceph_open_session(struct ceph_client *client,
  166. unsigned long started);
  167. extern int ceph_open_session(struct ceph_client *client);
  168. /* pagevec.c */
  169. extern void ceph_release_page_vector(struct page **pages, int num_pages);
  170. extern struct page **ceph_get_direct_page_vector(const void __user *data,
  171. int num_pages,
  172. bool write_page);
  173. extern void ceph_put_page_vector(struct page **pages, int num_pages,
  174. bool dirty);
  175. extern void ceph_release_page_vector(struct page **pages, int num_pages);
  176. extern struct page **ceph_alloc_page_vector(int num_pages, gfp_t flags);
  177. extern int ceph_copy_user_to_page_vector(struct page **pages,
  178. const void __user *data,
  179. loff_t off, size_t len);
  180. extern void ceph_copy_to_page_vector(struct page **pages,
  181. const void *data,
  182. loff_t off, size_t len);
  183. extern void ceph_copy_from_page_vector(struct page **pages,
  184. void *data,
  185. loff_t off, size_t len);
  186. extern int ceph_copy_page_vector_to_user(struct page **pages, void __user *data,
  187. loff_t off, size_t len);
  188. extern void ceph_zero_page_vector_range(int off, int len, struct page **pages);
  189. #endif /* _FS_CEPH_SUPER_H */