blob: 29818fc3fa493ea084e19f8f57b88d6e7aa2cd00 [file] [log] [blame]
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001#ifndef _FS_CEPH_LIBCEPH_H
2#define _FS_CEPH_LIBCEPH_H
3
David Howellsa1ce3922012-10-02 18:01:25 +01004#include <linux/ceph/ceph_debug.h>
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07005
6#include <asm/unaligned.h>
7#include <linux/backing-dev.h>
8#include <linux/completion.h>
9#include <linux/exportfs.h>
Paul Gortmaker187f1882011-11-23 20:12:59 -050010#include <linux/bug.h>
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070011#include <linux/fs.h>
12#include <linux/mempool.h>
13#include <linux/pagemap.h>
14#include <linux/wait.h>
15#include <linux/writeback.h>
16#include <linux/slab.h>
17
David Howellsa1ce3922012-10-02 18:01:25 +010018#include <linux/ceph/types.h>
19#include <linux/ceph/messenger.h>
20#include <linux/ceph/msgpool.h>
21#include <linux/ceph/mon_client.h>
22#include <linux/ceph/osd_client.h>
23#include <linux/ceph/ceph_fs.h>
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070024
25/*
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070026 * mount options
27 */
28#define CEPH_OPT_FSID (1<<0)
29#define CEPH_OPT_NOSHARE (1<<1) /* don't share client with other sbs */
30#define CEPH_OPT_MYIP (1<<2) /* specified my ip */
31#define CEPH_OPT_NOCRC (1<<3) /* no data crc on writes */
32
Phil Carmody497888c2011-07-14 15:07:13 +030033#define CEPH_OPT_DEFAULT (0)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070034
35#define ceph_set_opt(client, opt) \
36 (client)->options->flags |= CEPH_OPT_##opt;
37#define ceph_test_opt(client, opt) \
38 (!!((client)->options->flags & CEPH_OPT_##opt))
39
40struct ceph_options {
41 int flags;
42 struct ceph_fsid fsid;
43 struct ceph_entity_addr my_addr;
44 int mount_timeout;
45 int osd_idle_ttl;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070046 int osd_keepalive_timeout;
47
48 /*
49 * any type that can't be simply compared or doesn't need need
50 * to be compared should go beyond this point,
51 * ceph_compare_options() should be updated accordingly
52 */
53
54 struct ceph_entity_addr *mon_addr; /* should be the first
55 pointer type of args */
56 int num_mon;
57 char *name;
Tommi Virtanen8323c3a2011-03-25 16:32:57 -070058 struct ceph_crypto_key *key;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070059};
60
61/*
62 * defaults
63 */
64#define CEPH_MOUNT_TIMEOUT_DEFAULT 60
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070065#define CEPH_OSD_KEEPALIVE_DEFAULT 5
66#define CEPH_OSD_IDLE_TTL_DEFAULT 60
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070067
68#define CEPH_MSG_MAX_FRONT_LEN (16*1024*1024)
69#define CEPH_MSG_MAX_DATA_LEN (16*1024*1024)
70
71#define CEPH_AUTH_NAME_DEFAULT "guest"
72
73/*
74 * Delay telling the MDS we no longer want caps, in case we reopen
75 * the file. Delay a minimum amount of time, even if we send a cap
76 * message for some other reason. Otherwise, take the oppotunity to
77 * update the mds to avoid sending another message later.
78 */
79#define CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT 5 /* cap release delay */
80#define CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT 60 /* cap release delay */
81
82#define CEPH_CAP_RELEASE_SAFETY_DEFAULT (CEPH_CAPS_PER_RELEASE * 4)
83
84/* mount state */
85enum {
86 CEPH_MOUNT_MOUNTING,
87 CEPH_MOUNT_MOUNTED,
88 CEPH_MOUNT_UNMOUNTING,
89 CEPH_MOUNT_UNMOUNTED,
90 CEPH_MOUNT_SHUTDOWN,
91};
92
93/*
94 * subtract jiffies
95 */
96static inline unsigned long time_sub(unsigned long a, unsigned long b)
97{
98 BUG_ON(time_after(b, a));
99 return (long)a - (long)b;
100}
101
102struct ceph_mds_client;
103
104/*
105 * per client state
106 *
107 * possibly shared by multiple mount points, if they are
108 * mounting the same ceph filesystem/cluster.
109 */
110struct ceph_client {
111 struct ceph_fsid fsid;
112 bool have_fsid;
113
114 void *private;
115
116 struct ceph_options *options;
117
118 struct mutex mount_mutex; /* serialize mount attempts */
119 wait_queue_head_t auth_wq;
120 int auth_err;
121
122 int (*extra_mon_dispatch)(struct ceph_client *, struct ceph_msg *);
123
124 u32 supported_features;
125 u32 required_features;
126
Alex Elder15d98822012-05-26 23:26:43 -0500127 struct ceph_messenger msgr; /* messenger instance */
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700128 struct ceph_mon_client monc;
129 struct ceph_osd_client osdc;
130
131#ifdef CONFIG_DEBUG_FS
132 struct dentry *debugfs_dir;
133 struct dentry *debugfs_monmap;
134 struct dentry *debugfs_osdmap;
135#endif
136};
137
138
139
140/*
141 * snapshots
142 */
143
144/*
145 * A "snap context" is the set of existing snapshots when we
146 * write data. It is used by the OSD to guide its COW behavior.
147 *
148 * The ceph_snap_context is refcounted, and attached to each dirty
149 * page, indicating which context the dirty data belonged when it was
150 * dirtied.
151 */
152struct ceph_snap_context {
153 atomic_t nref;
154 u64 seq;
Alex Elderaa711ee2012-07-13 20:35:11 -0500155 u32 num_snaps;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700156 u64 snaps[];
157};
158
159static inline struct ceph_snap_context *
160ceph_get_snap_context(struct ceph_snap_context *sc)
161{
162 /*
163 printk("get_snap_context %p %d -> %d\n", sc, atomic_read(&sc->nref),
164 atomic_read(&sc->nref)+1);
165 */
166 if (sc)
167 atomic_inc(&sc->nref);
168 return sc;
169}
170
171static inline void ceph_put_snap_context(struct ceph_snap_context *sc)
172{
173 if (!sc)
174 return;
175 /*
176 printk("put_snap_context %p %d -> %d\n", sc, atomic_read(&sc->nref),
177 atomic_read(&sc->nref)-1);
178 */
179 if (atomic_dec_and_test(&sc->nref)) {
180 /*printk(" deleting snap_context %p\n", sc);*/
181 kfree(sc);
182 }
183}
184
185/*
186 * calculate the number of pages a given length and offset map onto,
187 * if we align the data.
188 */
189static inline int calc_pages_for(u64 off, u64 len)
190{
191 return ((off+len+PAGE_CACHE_SIZE-1) >> PAGE_CACHE_SHIFT) -
192 (off >> PAGE_CACHE_SHIFT);
193}
194
195/* ceph_common.c */
Alex Elder72fe25e2013-01-30 11:13:33 -0600196extern bool libceph_compatible(void *data);
197
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700198extern const char *ceph_msg_type_name(int type);
199extern int ceph_check_fsid(struct ceph_client *client, struct ceph_fsid *fsid);
200extern struct kmem_cache *ceph_inode_cachep;
201extern struct kmem_cache *ceph_cap_cachep;
202extern struct kmem_cache *ceph_dentry_cachep;
203extern struct kmem_cache *ceph_file_cachep;
204
Alex Elderee577412012-01-24 10:08:36 -0600205extern struct ceph_options *ceph_parse_options(char *options,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700206 const char *dev_name, const char *dev_name_end,
207 int (*parse_extra_token)(char *c, void *private),
208 void *private);
209extern void ceph_destroy_options(struct ceph_options *opt);
210extern int ceph_compare_options(struct ceph_options *new_opt,
211 struct ceph_client *client);
212extern struct ceph_client *ceph_create_client(struct ceph_options *opt,
Sage Weil6ab00d42011-08-09 09:41:59 -0700213 void *private,
214 unsigned supported_features,
215 unsigned required_features);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700216extern u64 ceph_client_id(struct ceph_client *client);
217extern void ceph_destroy_client(struct ceph_client *client);
218extern int __ceph_open_session(struct ceph_client *client,
219 unsigned long started);
220extern int ceph_open_session(struct ceph_client *client);
221
222/* pagevec.c */
223extern void ceph_release_page_vector(struct page **pages, int num_pages);
224
Alex Elderb3248142013-02-06 13:11:38 -0600225extern struct page **ceph_get_direct_page_vector(const void __user *data,
Henry C Changb6aa5902010-12-15 20:45:41 -0800226 int num_pages,
227 bool write_page);
228extern void ceph_put_page_vector(struct page **pages, int num_pages,
229 bool dirty);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700230extern void ceph_release_page_vector(struct page **pages, int num_pages);
231extern struct page **ceph_alloc_page_vector(int num_pages, gfp_t flags);
232extern int ceph_copy_user_to_page_vector(struct page **pages,
Alex Elderb3248142013-02-06 13:11:38 -0600233 const void __user *data,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700234 loff_t off, size_t len);
Alex Elder903bb322013-02-06 13:11:38 -0600235extern void ceph_copy_to_page_vector(struct page **pages,
Alex Elderb3248142013-02-06 13:11:38 -0600236 const void *data,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700237 loff_t off, size_t len);
Alex Elder903bb322013-02-06 13:11:38 -0600238extern void ceph_copy_from_page_vector(struct page **pages,
Alex Elderb3248142013-02-06 13:11:38 -0600239 void *data,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700240 loff_t off, size_t len);
Alex Elderb3248142013-02-06 13:11:38 -0600241extern int ceph_copy_page_vector_to_user(struct page **pages, void __user *data,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700242 loff_t off, size_t len);
243extern void ceph_zero_page_vector_range(int off, int len, struct page **pages);
244
245
246#endif /* _FS_CEPH_SUPER_H */