libceph.h 6.3 KB

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