libceph.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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) /* don't require msg signing feat */
  29. #define CEPH_OPT_TCP_NODELAY (1<<5) /* TCP_NODELAY on TCP sockets */
  30. #define CEPH_OPT_NOMSGSIGN (1<<6) /* don't sign msgs */
  31. #define CEPH_OPT_DEFAULT (CEPH_OPT_TCP_NODELAY)
  32. #define ceph_set_opt(client, opt) \
  33. (client)->options->flags |= CEPH_OPT_##opt;
  34. #define ceph_test_opt(client, opt) \
  35. (!!((client)->options->flags & CEPH_OPT_##opt))
  36. struct ceph_options {
  37. int flags;
  38. struct ceph_fsid fsid;
  39. struct ceph_entity_addr my_addr;
  40. unsigned long mount_timeout; /* jiffies */
  41. unsigned long osd_idle_ttl; /* jiffies */
  42. unsigned long osd_keepalive_timeout; /* jiffies */
  43. unsigned long monc_ping_timeout; /* jiffies */
  44. /*
  45. * any type that can't be simply compared or doesn't need need
  46. * to be compared should go beyond this point,
  47. * ceph_compare_options() should be updated accordingly
  48. */
  49. struct ceph_entity_addr *mon_addr; /* should be the first
  50. pointer type of args */
  51. int num_mon;
  52. char *name;
  53. struct ceph_crypto_key *key;
  54. };
  55. /*
  56. * defaults
  57. */
  58. #define CEPH_MOUNT_TIMEOUT_DEFAULT msecs_to_jiffies(60 * 1000)
  59. #define CEPH_OSD_KEEPALIVE_DEFAULT msecs_to_jiffies(5 * 1000)
  60. #define CEPH_OSD_IDLE_TTL_DEFAULT msecs_to_jiffies(60 * 1000)
  61. #define CEPH_MONC_PING_TIMEOUT_DEFAULT msecs_to_jiffies(30 * 1000)
  62. #define CEPH_MSG_MAX_FRONT_LEN (16*1024*1024)
  63. #define CEPH_MSG_MAX_MIDDLE_LEN (16*1024*1024)
  64. /*
  65. * Handle the largest possible rbd object in one message.
  66. * There is no limit on the size of cephfs objects, but it has to obey
  67. * rsize and wsize mount options anyway.
  68. */
  69. #define CEPH_MSG_MAX_DATA_LEN (32*1024*1024)
  70. #define CEPH_AUTH_NAME_DEFAULT "guest"
  71. /*
  72. * Delay telling the MDS we no longer want caps, in case we reopen
  73. * the file. Delay a minimum amount of time, even if we send a cap
  74. * message for some other reason. Otherwise, take the oppotunity to
  75. * update the mds to avoid sending another message later.
  76. */
  77. #define CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT 5 /* cap release delay */
  78. #define CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT 60 /* cap release delay */
  79. #define CEPH_CAP_RELEASE_SAFETY_DEFAULT (CEPH_CAPS_PER_RELEASE * 4)
  80. /* mount state */
  81. enum {
  82. CEPH_MOUNT_MOUNTING,
  83. CEPH_MOUNT_MOUNTED,
  84. CEPH_MOUNT_UNMOUNTING,
  85. CEPH_MOUNT_UNMOUNTED,
  86. CEPH_MOUNT_SHUTDOWN,
  87. };
  88. static inline unsigned long ceph_timeout_jiffies(unsigned long timeout)
  89. {
  90. return timeout ?: MAX_SCHEDULE_TIMEOUT;
  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. u64 supported_features;
  109. u64 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. struct dentry *debugfs_options;
  118. #endif
  119. };
  120. #define from_msgr(ms) container_of(ms, struct ceph_client, msgr)
  121. /*
  122. * snapshots
  123. */
  124. /*
  125. * A "snap context" is the set of existing snapshots when we
  126. * write data. It is used by the OSD to guide its COW behavior.
  127. *
  128. * The ceph_snap_context is refcounted, and attached to each dirty
  129. * page, indicating which context the dirty data belonged when it was
  130. * dirtied.
  131. */
  132. struct ceph_snap_context {
  133. atomic_t nref;
  134. u64 seq;
  135. u32 num_snaps;
  136. u64 snaps[];
  137. };
  138. extern struct ceph_snap_context *ceph_create_snap_context(u32 snap_count,
  139. gfp_t gfp_flags);
  140. extern struct ceph_snap_context *ceph_get_snap_context(
  141. struct ceph_snap_context *sc);
  142. extern void ceph_put_snap_context(struct ceph_snap_context *sc);
  143. /*
  144. * calculate the number of pages a given length and offset map onto,
  145. * if we align the data.
  146. */
  147. static inline int calc_pages_for(u64 off, u64 len)
  148. {
  149. return ((off+len+PAGE_CACHE_SIZE-1) >> PAGE_CACHE_SHIFT) -
  150. (off >> PAGE_CACHE_SHIFT);
  151. }
  152. extern struct kmem_cache *ceph_inode_cachep;
  153. extern struct kmem_cache *ceph_cap_cachep;
  154. extern struct kmem_cache *ceph_cap_flush_cachep;
  155. extern struct kmem_cache *ceph_dentry_cachep;
  156. extern struct kmem_cache *ceph_file_cachep;
  157. /* ceph_common.c */
  158. extern bool libceph_compatible(void *data);
  159. extern const char *ceph_msg_type_name(int type);
  160. extern int ceph_check_fsid(struct ceph_client *client, struct ceph_fsid *fsid);
  161. extern void *ceph_kvmalloc(size_t size, gfp_t flags);
  162. extern struct ceph_options *ceph_parse_options(char *options,
  163. const char *dev_name, const char *dev_name_end,
  164. int (*parse_extra_token)(char *c, void *private),
  165. void *private);
  166. int ceph_print_client_options(struct seq_file *m, struct ceph_client *client);
  167. extern void ceph_destroy_options(struct ceph_options *opt);
  168. extern int ceph_compare_options(struct ceph_options *new_opt,
  169. struct ceph_client *client);
  170. extern struct ceph_client *ceph_create_client(struct ceph_options *opt,
  171. void *private,
  172. u64 supported_features,
  173. u64 required_features);
  174. extern u64 ceph_client_id(struct ceph_client *client);
  175. extern void ceph_destroy_client(struct ceph_client *client);
  176. extern int __ceph_open_session(struct ceph_client *client,
  177. unsigned long started);
  178. extern int ceph_open_session(struct ceph_client *client);
  179. /* pagevec.c */
  180. extern void ceph_release_page_vector(struct page **pages, int num_pages);
  181. extern struct page **ceph_get_direct_page_vector(const void __user *data,
  182. int num_pages,
  183. bool write_page);
  184. extern void ceph_put_page_vector(struct page **pages, int num_pages,
  185. bool dirty);
  186. extern struct page **ceph_alloc_page_vector(int num_pages, gfp_t flags);
  187. extern int ceph_copy_user_to_page_vector(struct page **pages,
  188. const void __user *data,
  189. loff_t off, size_t len);
  190. extern void ceph_copy_to_page_vector(struct page **pages,
  191. const void *data,
  192. loff_t off, size_t len);
  193. extern void ceph_copy_from_page_vector(struct page **pages,
  194. void *data,
  195. loff_t off, size_t len);
  196. extern void ceph_zero_page_vector_range(int off, int len, struct page **pages);
  197. #endif /* _FS_CEPH_SUPER_H */