libceph.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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_NOMSGAUTH (1<<4) /* not require cephx message signature */
  29. #define CEPH_OPT_TCP_NODELAY (1<<5) /* TCP_NODELAY on TCP sockets */
  30. #define CEPH_OPT_DEFAULT (CEPH_OPT_TCP_NODELAY)
  31. #define ceph_set_opt(client, opt) \
  32. (client)->options->flags |= CEPH_OPT_##opt;
  33. #define ceph_test_opt(client, opt) \
  34. (!!((client)->options->flags & CEPH_OPT_##opt))
  35. struct ceph_options {
  36. int flags;
  37. struct ceph_fsid fsid;
  38. struct ceph_entity_addr my_addr;
  39. unsigned long mount_timeout; /* jiffies */
  40. unsigned long osd_idle_ttl; /* jiffies */
  41. unsigned long osd_keepalive_timeout; /* jiffies */
  42. unsigned long monc_ping_timeout; /* jiffies */
  43. /*
  44. * any type that can't be simply compared or doesn't need need
  45. * to be compared should go beyond this point,
  46. * ceph_compare_options() should be updated accordingly
  47. */
  48. struct ceph_entity_addr *mon_addr; /* should be the first
  49. pointer type of args */
  50. int num_mon;
  51. char *name;
  52. struct ceph_crypto_key *key;
  53. };
  54. /*
  55. * defaults
  56. */
  57. #define CEPH_MOUNT_TIMEOUT_DEFAULT msecs_to_jiffies(60 * 1000)
  58. #define CEPH_OSD_KEEPALIVE_DEFAULT msecs_to_jiffies(5 * 1000)
  59. #define CEPH_OSD_IDLE_TTL_DEFAULT msecs_to_jiffies(60 * 1000)
  60. #define CEPH_MONC_PING_TIMEOUT_DEFAULT msecs_to_jiffies(30 * 1000)
  61. #define CEPH_MSG_MAX_FRONT_LEN (16*1024*1024)
  62. #define CEPH_MSG_MAX_MIDDLE_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. static inline unsigned long ceph_timeout_jiffies(unsigned long timeout)
  83. {
  84. return timeout ?: MAX_SCHEDULE_TIMEOUT;
  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. u64 supported_features;
  103. u64 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. struct dentry *debugfs_options;
  112. #endif
  113. };
  114. /*
  115. * snapshots
  116. */
  117. /*
  118. * A "snap context" is the set of existing snapshots when we
  119. * write data. It is used by the OSD to guide its COW behavior.
  120. *
  121. * The ceph_snap_context is refcounted, and attached to each dirty
  122. * page, indicating which context the dirty data belonged when it was
  123. * dirtied.
  124. */
  125. struct ceph_snap_context {
  126. atomic_t nref;
  127. u64 seq;
  128. u32 num_snaps;
  129. u64 snaps[];
  130. };
  131. extern struct ceph_snap_context *ceph_create_snap_context(u32 snap_count,
  132. gfp_t gfp_flags);
  133. extern struct ceph_snap_context *ceph_get_snap_context(
  134. struct ceph_snap_context *sc);
  135. extern void ceph_put_snap_context(struct ceph_snap_context *sc);
  136. /*
  137. * calculate the number of pages a given length and offset map onto,
  138. * if we align the data.
  139. */
  140. static inline int calc_pages_for(u64 off, u64 len)
  141. {
  142. return ((off+len+PAGE_CACHE_SIZE-1) >> PAGE_CACHE_SHIFT) -
  143. (off >> PAGE_CACHE_SHIFT);
  144. }
  145. extern struct kmem_cache *ceph_inode_cachep;
  146. extern struct kmem_cache *ceph_cap_cachep;
  147. extern struct kmem_cache *ceph_cap_flush_cachep;
  148. extern struct kmem_cache *ceph_dentry_cachep;
  149. extern struct kmem_cache *ceph_file_cachep;
  150. /* ceph_common.c */
  151. extern bool libceph_compatible(void *data);
  152. extern const char *ceph_msg_type_name(int type);
  153. extern int ceph_check_fsid(struct ceph_client *client, struct ceph_fsid *fsid);
  154. extern void *ceph_kvmalloc(size_t size, gfp_t flags);
  155. extern struct ceph_options *ceph_parse_options(char *options,
  156. const char *dev_name, const char *dev_name_end,
  157. int (*parse_extra_token)(char *c, void *private),
  158. void *private);
  159. int ceph_print_client_options(struct seq_file *m, struct ceph_client *client);
  160. extern void ceph_destroy_options(struct ceph_options *opt);
  161. extern int ceph_compare_options(struct ceph_options *new_opt,
  162. struct ceph_client *client);
  163. extern struct ceph_client *ceph_create_client(struct ceph_options *opt,
  164. void *private,
  165. u64 supported_features,
  166. u64 required_features);
  167. extern u64 ceph_client_id(struct ceph_client *client);
  168. extern void ceph_destroy_client(struct ceph_client *client);
  169. extern int __ceph_open_session(struct ceph_client *client,
  170. unsigned long started);
  171. extern int ceph_open_session(struct ceph_client *client);
  172. /* pagevec.c */
  173. extern void ceph_release_page_vector(struct page **pages, int num_pages);
  174. extern struct page **ceph_get_direct_page_vector(const void __user *data,
  175. int num_pages,
  176. bool write_page);
  177. extern void ceph_put_page_vector(struct page **pages, int num_pages,
  178. bool dirty);
  179. extern struct page **ceph_alloc_page_vector(int num_pages, gfp_t flags);
  180. extern int ceph_copy_user_to_page_vector(struct page **pages,
  181. const void __user *data,
  182. loff_t off, size_t len);
  183. extern void ceph_copy_to_page_vector(struct page **pages,
  184. const void *data,
  185. loff_t off, size_t len);
  186. extern void ceph_copy_from_page_vector(struct page **pages,
  187. void *data,
  188. loff_t off, size_t len);
  189. extern void ceph_zero_page_vector_range(int off, int len, struct page **pages);
  190. #endif /* _FS_CEPH_SUPER_H */