Fix dentry disk namelen declaration
[pohmelfs.git] / fs / pohmelfs / pohmelfs.h
blobb8ca5910bbadfcb71ed492cdf5fe3c202a8055c0
1 /*
2 * Copyright (C) 2011+ Evgeniy Polyakov <zbr@ioremap.net>
3 */
5 #ifndef __POHMELFS_H
6 #define __POHMELFS_H
8 #include <linux/backing-dev.h>
9 #include <linux/crypto.h>
10 #include <linux/fs.h>
11 #include <linux/kref.h>
12 #include <linux/list.h>
13 #include <linux/mutex.h>
14 #include <linux/net.h>
15 #include <linux/pagemap.h>
16 #include <linux/pagevec.h>
17 #include <linux/printk.h>
18 #include <linux/slab.h>
19 #include <linux/time.h>
20 #include <linux/wait.h>
21 #include <linux/workqueue.h>
23 #include <crypto/sha.h>
25 #define dnet_bswap16(x) cpu_to_le16(x)
26 #define dnet_bswap32(x) cpu_to_le32(x)
27 #define dnet_bswap64(x) cpu_to_le64(x)
29 /* theese are needed for packet.h below to compile */
30 #define DNET_ID_SIZE SHA512_DIGEST_SIZE
31 #define DNET_CSUM_SIZE SHA512_DIGEST_SIZE
33 #define POHMELFS_INODE_COLUMN 3
36 * is not used in kernel, but we want to share the same header
37 * with userspace, so I put it here for compiler to shut up
39 int gettimeofday(struct timeval *, struct timezone *);
41 #include "packet.h"
43 static inline struct timespec pohmelfs_date(struct dnet_time *tm)
45 struct timespec ts;
47 ts.tv_sec = tm->tsec;
48 ts.tv_nsec = tm->tnsec;
50 return ts;
53 struct pohmelfs_cmd {
54 struct dnet_cmd cmd;
55 struct dnet_attr attr;
56 union {
57 struct dnet_io_attr io;
58 } p;
62 * Compare two IDs.
63 * Returns 1 when id1 > id2
64 * -1 when id1 < id2
65 * 0 when id1 = id2
67 static inline int dnet_id_cmp_str(const unsigned char *id1, const unsigned char *id2)
69 unsigned int i = 0;
71 for (i*=sizeof(unsigned long); i<DNET_ID_SIZE; ++i) {
72 if (id1[i] < id2[i])
73 return -1;
74 if (id1[i] > id2[i])
75 return 1;
78 return 0;
81 struct pohmelfs_state;
82 struct pohmelfs_sb;
83 struct pohmelfs_trans;
85 struct pohmelfs_trans_cb {
86 int (* init)(struct pohmelfs_trans *t);
87 int (* complete)(struct pohmelfs_trans *t, struct pohmelfs_state *recv);
88 int (* recv_reply)(struct pohmelfs_trans *t, struct pohmelfs_state *recv);
89 void (* destroy)(struct pohmelfs_trans *t);
92 struct pohmelfs_trans {
93 struct list_head trans_entry;
95 struct kref refcnt;
97 unsigned long trans;
99 struct inode *inode;
101 struct pohmelfs_state *st;
103 struct pohmelfs_cmd cmd;
105 u64 header_size, data_size;
107 void *data;
109 unsigned long long recv_offset;
110 void *recv_data;
112 struct pohmelfs_write_ctl *wctl;
113 void *priv;
115 struct pohmelfs_trans_cb cb;
118 struct pohmelfs_trans *pohmelfs_trans_alloc(struct inode *inode);
119 struct pohmelfs_trans *pohmelfs_trans_alloc_io_buf(struct inode *inode, int group, int command,
120 void *data, u64 offset, u64 size, int aflags, int ioflags, int type);
121 void pohmelfs_trans_put(struct pohmelfs_trans *t);
123 int pohmelfs_trans_insert(struct pohmelfs_trans *t);
124 struct pohmelfs_trans *pohmelfs_trans_lookup(struct pohmelfs_state *st, struct dnet_cmd *cmd);
126 struct pohmelfs_state {
127 struct pohmelfs_sb *psb;
128 struct list_head state_entry;
130 struct sockaddr_storage sa;
131 int addrlen;
132 struct socket *sock;
134 int group_id;
136 struct mutex trans_lock;
137 struct list_head trans_list;
138 struct list_head sent_trans_list;
140 struct kref refcnt;
142 int routes;
144 /* Waiting/polling machinery */
145 wait_queue_t wait;
146 wait_queue_head_t *whead;
148 struct work_struct send_work;
149 struct work_struct recv_work;
151 /* is set when dnet_cmd is being read, otherwise attached data */
152 int cmd_read;
153 /* currently read command reply */
154 struct dnet_cmd cmd;
156 uint64_t bsize; /* Block size */
157 uint64_t frsize; /* Fragment size */
158 uint64_t blocks; /* Filesystem size in frsize units */
159 uint64_t bfree; /* # free blocks */
160 uint64_t bavail; /* # free blocks for non-root */
163 struct pohmelfs_state *pohmelfs_state_create(struct pohmelfs_sb *psb, struct sockaddr_storage *sa, int addrlen,
164 int ask_route, int group_id);
165 struct pohmelfs_state *pohmelfs_state_lookup(struct pohmelfs_sb *psb, struct dnet_raw_id *id, int group);
166 int pohmelfs_grab_states(struct pohmelfs_sb *psb, struct pohmelfs_state ***stp);
168 static inline void pohmelfs_state_get(struct pohmelfs_state *st)
170 kref_get(&st->refcnt);
173 void pohmelfs_state_put(struct pohmelfs_state *st);
174 void pohmelfs_state_kill(struct pohmelfs_state *st);
176 struct pohmelfs_state *pohmelfs_addr_exist(struct pohmelfs_sb *psb, struct sockaddr_storage *sa, int addrlen);
178 void pohmelfs_state_schedule(struct pohmelfs_state *st);
180 __attribute__ ((format (printf, 2, 3))) void pohmelfs_print_addr(struct sockaddr_storage *addr, const char *fmt, ...);
182 #define POHMELFS_INODE_INFO_REMOVED (1<<0)
184 struct pohmelfs_inode_info {
185 struct dnet_raw_id id;
187 unsigned int mode;
188 unsigned int nlink;
189 unsigned int uid;
190 unsigned int gid;
191 unsigned int blocksize;
192 unsigned int namelen;
193 __u64 ino;
194 __u64 blocks;
195 __u64 rdev;
196 __u64 size;
197 __u64 version;
199 __u64 flags;
201 struct dnet_time ctime;
202 struct dnet_time mtime;
203 struct dnet_time atime;
204 } __attribute__ ((packed));
206 void pohmelfs_fill_inode_info(struct inode *inode, struct pohmelfs_inode_info *info);
207 void pohmelfs_fill_inode(struct inode *inode, struct pohmelfs_inode_info *info);
208 void pohmelfs_convert_inode_info(struct pohmelfs_inode_info *info);
210 struct pohmelfs_inode {
211 struct inode vfs_inode;
212 struct dnet_raw_id id;
213 struct dnet_raw_id parent_id;
215 struct rb_node node;
217 struct mutex lock;
219 int *groups;
220 int group_num;
222 time_t update;
223 int local;
226 int pohmelfs_send_dentry(struct pohmelfs_inode *pi, struct dnet_raw_id *id, const char *sname, int len, int sync);
227 struct pohmelfs_inode *pohmelfs_sb_inode_lookup(struct pohmelfs_sb *psb, struct dnet_raw_id *id);
229 struct pohmelfs_reconnect {
230 struct list_head reconnect_entry;
231 struct sockaddr_storage sa;
232 int addrlen;
233 int group_id;
236 int pohmelfs_state_add_reconnect(struct pohmelfs_state *st);
238 struct pohmelfs_path {
239 struct mutex lock;
240 char *data;
243 int pohmelfs_http_compat_id(struct pohmelfs_inode *pi);
245 struct pohmelfs_sb {
246 struct super_block *sb;
247 struct backing_dev_info bdi;
249 struct pohmelfs_inode *root;
251 spinlock_t inode_lock;
252 struct rb_root inode_root;
254 int http_compat;
255 struct pohmelfs_path *path;
257 int bdi_num;
259 struct rb_root route_root;
260 struct list_head state_list;
261 spinlock_t state_lock;
263 long read_wait_timeout;
264 long write_wait_timeout;
266 long sync_timeout;
267 struct delayed_work sync_work;
269 char *fsid;
270 int fsid_len;
272 int no_read_csum;
274 int need_exit;
276 atomic_long_t ino;
277 atomic_long_t trans;
279 struct crypto_hash *hash;
281 struct workqueue_struct *wq;
283 int *groups;
284 int group_num;
287 * number of copies to be successfully written to mark write as successful
288 * if not set, half of groups plus one must be successfully written, i.e. plain write quorum
290 int successful_write_count;
292 struct mutex reconnect_lock;
293 struct list_head reconnect_list;
294 struct list_head kill_state_list;
295 struct delayed_work reconnect_work;
296 long reconnect_timeout;
298 int keepalive_cnt, keepalive_interval, keepalive_idle;
300 int readdir_allocation;
302 int sync_on_close;
305 static inline struct pohmelfs_sb *pohmelfs_sb(struct super_block *sb)
307 return (struct pohmelfs_sb *)sb->s_fs_info;
310 static inline struct pohmelfs_inode *pohmelfs_inode(struct inode *inode)
312 return container_of(inode, struct pohmelfs_inode, vfs_inode);
315 struct pohmelfs_wait {
316 wait_queue_head_t wq;
317 struct pohmelfs_inode *pi;
318 void *ret;
319 atomic_long_t count;
320 int condition;
321 struct kref refcnt;
324 int pohmelfs_wait_init(struct pohmelfs_wait *wait, struct pohmelfs_inode *pi);
325 struct pohmelfs_wait *pohmelfs_wait_alloc(struct pohmelfs_inode *pi);
326 void pohmelfs_wait_put(struct pohmelfs_wait *wait);
327 static inline void pohmelfs_wait_get(struct pohmelfs_wait *wait)
329 kref_get(&wait->refcnt);
332 struct pohmelfs_inode_info_binary_package {
333 struct pohmelfs_inode_info info;
335 struct pohmelfs_wait wait;
338 struct pohmelfs_write_ctl {
339 struct pagevec pvec;
340 struct pohmelfs_inode_info *info;
342 struct kref refcnt;
343 atomic_t good_writes;
346 struct pohmelfs_dentry_disk {
347 struct dnet_raw_id id;
348 uint64_t ino;
349 int pad0;
350 short pad1;
351 unsigned char type;
352 unsigned char len;
353 char name[0];
356 struct pohmelfs_dentry {
357 struct dnet_raw_id parent_id;
358 struct pohmelfs_dentry_disk disk;
361 extern struct kmem_cache *pohmelfs_inode_cache;
362 extern struct kmem_cache *pohmelfs_trans_cache;
363 extern struct kmem_cache *pohmelfs_inode_info_cache;
364 extern struct kmem_cache *pohmelfs_route_cache;
365 extern struct kmem_cache *pohmelfs_wait_cache;
366 extern struct kmem_cache *pohmelfs_io_cache;
367 extern struct kmem_cache *pohmelfs_inode_info_binary_package_cache;
368 extern struct kmem_cache *pohmelfs_write_cache;
369 extern struct kmem_cache *pohmelfs_dentry_cache;
371 struct inode *pohmelfs_alloc_inode(struct super_block *sb);
372 void pohmelfs_destroy_inode(struct inode *);
374 struct pohmelfs_inode *pohmelfs_existing_inode(struct pohmelfs_sb *psb, struct pohmelfs_inode_info *info);
375 struct pohmelfs_inode *pohmelfs_new_inode(struct pohmelfs_sb *psb, int mode);
376 int pohmelfs_hash(struct pohmelfs_sb *psb, const void *data, const size_t size, struct dnet_raw_id *id);
378 char *pohmelfs_dump_id(const unsigned char *id);
379 char *pohmelfs_dump_id_len_raw(const unsigned char *id, unsigned int len, char *dst);
381 int pohmelfs_write_command(struct pohmelfs_inode *pi, struct pohmelfs_write_ctl *ctl, loff_t offset, size_t len);
382 void pohmelfs_write_ctl_release(struct kref *kref);
383 int pohmelfs_metadata_inode(struct pohmelfs_inode *pi, int sync);
385 extern const struct file_operations pohmelfs_dir_fops;
386 extern const struct inode_operations pohmelfs_dir_inode_operations;
388 extern const struct file_operations pohmelfs_file_ops;
389 extern const struct inode_operations pohmelfs_file_inode_operations;
391 extern const struct inode_operations pohmelfs_symlink_inode_operations;
392 extern const struct inode_operations pohmelfs_special_inode_operations;
394 extern void *pohmelfs_scratch_buf;
395 extern int pohmelfs_scratch_buf_size;
398 * if this flag is set, pohmelfs_inode_info->data is owned by the caller,
399 * so sending path may use it on its own and free (using kfree) when it's done
401 * This logic does not work for shared buffers or
402 * when multiple transactions will be sent for single pohmelfs_inode_info
404 #define POHMELFS_IO_OWN (1<<0)
406 struct pohmelfs_io {
407 struct pohmelfs_inode *pi;
409 struct dnet_raw_id *id;
411 int cmd;
412 int type;
414 u64 offset, size;
415 u64 start, num;
417 u32 cflags;
418 u32 aflags;
419 u32 ioflags;
421 int group_id;
423 u32 alloc_flags;
424 void *data;
426 struct pohmelfs_write_ctl *wctl;
427 void *priv;
429 struct pohmelfs_trans_cb cb;
432 int pohmelfs_send_io_group(struct pohmelfs_io *pio, int group_id);
433 int pohmelfs_send_io(struct pohmelfs_io *pio);
434 int pohmelfs_send_buf_single(struct pohmelfs_io *pio, struct pohmelfs_state *st);
435 int pohmelfs_send_buf(struct pohmelfs_io *pio);
437 int pohmelfs_data_recv(struct pohmelfs_state *st, void *buf, u64 size, unsigned int flags);
438 int pohmelfs_recv(struct pohmelfs_trans *t, struct pohmelfs_state *recv, void *data, int size);
440 struct pohmelfs_route {
441 struct rb_node node;
442 int group_id;
443 struct dnet_raw_id id;
444 struct pohmelfs_state *st;
447 int pohmelfs_route_request(struct pohmelfs_state *st);
448 void pohmelfs_route_remove_all(struct pohmelfs_state *st);
450 struct pohmelfs_script_req {
451 char *obj_name;
452 int obj_len;
454 char *script_name;
455 int script_namelen;
457 void *binary;
458 int binary_size;
460 int group_id;
462 unsigned int cflags;
463 int sync;
465 struct dnet_raw_id *id;
467 int (* complete)(struct pohmelfs_trans *t, struct pohmelfs_state *recv);
468 void *ret;
469 int ret_cond;
472 int pohmelfs_send_script_request(struct pohmelfs_inode *parent, struct pohmelfs_script_req *req);
474 int pohmelfs_stat(struct pohmelfs_sb *psb, int sync);
476 static inline int pohmelfs_need_resync(struct pohmelfs_inode *pi)
478 struct pohmelfs_sb *psb = pohmelfs_sb(pi->vfs_inode.i_sb);
479 return get_seconds() > pi->update + psb->sync_timeout;
482 #endif /* __POHMELFS_H */