]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - drivers/staging/pohmelfs/netfs.h
7700e2bf3cc78158197caf6859987e8ae7a67ca4
[mirror_ubuntu-bionic-kernel.git] / drivers / staging / pohmelfs / netfs.h
1 /*
2 * 2007+ Copyright (c) Evgeniy Polyakov <zbr@ioremap.net>
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16 #ifndef __NETFS_H
17 #define __NETFS_H
18
19 #include <linux/types.h>
20 #include <linux/connector.h>
21
22 #define POHMELFS_CN_IDX 5
23 #define POHMELFS_CN_VAL 0
24
25 #define POHMELFS_CTLINFO_ACK 1
26 #define POHMELFS_NOINFO_ACK 2
27
28
29 /*
30 * Network command structure.
31 * Will be extended.
32 */
33 struct netfs_cmd
34 {
35 __u16 cmd; /* Command number */
36 __u16 csize; /* Attached crypto information size */
37 __u16 cpad; /* Attached padding size */
38 __u16 ext; /* External flags */
39 __u32 size; /* Size of the attached data */
40 __u32 trans; /* Transaction id */
41 __u64 id; /* Object ID to operate on. Used for feedback.*/
42 __u64 start; /* Start of the object. */
43 __u64 iv; /* IV sequence */
44 __u8 data[0];
45 };
46
47 static inline void netfs_convert_cmd(struct netfs_cmd *cmd)
48 {
49 cmd->id = __be64_to_cpu(cmd->id);
50 cmd->start = __be64_to_cpu(cmd->start);
51 cmd->iv = __be64_to_cpu(cmd->iv);
52 cmd->cmd = __be16_to_cpu(cmd->cmd);
53 cmd->ext = __be16_to_cpu(cmd->ext);
54 cmd->csize = __be16_to_cpu(cmd->csize);
55 cmd->cpad = __be16_to_cpu(cmd->cpad);
56 cmd->size = __be32_to_cpu(cmd->size);
57 }
58
59 #define NETFS_TRANS_SINGLE_DST (1<<0)
60
61 enum {
62 NETFS_READDIR = 1, /* Read directory for given inode number */
63 NETFS_READ_PAGE, /* Read data page from the server */
64 NETFS_WRITE_PAGE, /* Write data page to the server */
65 NETFS_CREATE, /* Create directory entry */
66 NETFS_REMOVE, /* Remove directory entry */
67
68 NETFS_LOOKUP, /* Lookup single object */
69 NETFS_LINK, /* Create a link */
70 NETFS_TRANS, /* Transaction */
71 NETFS_OPEN, /* Open intent */
72 NETFS_INODE_INFO, /* Metadata cache coherency synchronization message */
73
74 NETFS_PAGE_CACHE, /* Page cache invalidation message */
75 NETFS_READ_PAGES, /* Read multiple contiguous pages in one go */
76 NETFS_RENAME, /* Rename object */
77 NETFS_CAPABILITIES, /* Capabilities of the client, for example supported crypto */
78 NETFS_LOCK, /* Distributed lock message */
79
80 NETFS_XATTR_SET, /* Set extended attribute */
81 NETFS_XATTR_GET, /* Get extended attribute */
82 NETFS_CMD_MAX
83 };
84
85 enum {
86 POHMELFS_FLAGS_ADD = 0, /* Network state control message for ADD */
87 POHMELFS_FLAGS_DEL, /* Network state control message for DEL */
88 POHMELFS_FLAGS_SHOW, /* Network state control message for SHOW */
89 POHMELFS_FLAGS_CRYPTO, /* Crypto data control message */
90 };
91
92 /*
93 * Always wanted to copy it from socket headers into public one,
94 * since they are __KERNEL__ protected there.
95 */
96 #define _K_SS_MAXSIZE 128
97
98 struct saddr
99 {
100 unsigned short sa_family;
101 char addr[_K_SS_MAXSIZE];
102 };
103
104 enum {
105 POHMELFS_CRYPTO_HASH = 0,
106 POHMELFS_CRYPTO_CIPHER,
107 };
108
109 struct pohmelfs_crypto
110 {
111 unsigned int idx; /* Config index */
112 unsigned short strlen; /* Size of the attached crypto string including 0-byte
113 * "cbc(aes)" for example */
114 unsigned short type; /* HMAC, cipher, both */
115 unsigned int keysize; /* Key size */
116 unsigned char data[0]; /* Algorithm string, key and IV */
117 };
118
119 #define POHMELFS_IO_PERM_READ (1<<0)
120 #define POHMELFS_IO_PERM_WRITE (1<<1)
121
122 /*
123 * Configuration command used to create table of different remote servers.
124 */
125 struct pohmelfs_ctl
126 {
127 __u32 idx; /* Config index */
128 __u32 type; /* Socket type */
129 __u32 proto; /* Socket protocol */
130 __u16 addrlen; /* Size of the address */
131 __u16 perm; /* IO permission */
132 __u16 prio; /* IO priority */
133 struct saddr addr; /* Remote server address */
134 };
135
136 /*
137 * Ack for userspace about requested command.
138 */
139 struct pohmelfs_cn_ack
140 {
141 struct cn_msg msg;
142 int error;
143 int msg_num;
144 int unused[3];
145 struct pohmelfs_ctl ctl;
146 };
147
148 /*
149 * Inode info structure used to sync with server.
150 * Check what stat() returns.
151 */
152 struct netfs_inode_info
153 {
154 unsigned int mode;
155 unsigned int nlink;
156 unsigned int uid;
157 unsigned int gid;
158 unsigned int blocksize;
159 unsigned int padding;
160 __u64 ino;
161 __u64 blocks;
162 __u64 rdev;
163 __u64 size;
164 __u64 version;
165 };
166
167 static inline void netfs_convert_inode_info(struct netfs_inode_info *info)
168 {
169 info->mode = __cpu_to_be32(info->mode);
170 info->nlink = __cpu_to_be32(info->nlink);
171 info->uid = __cpu_to_be32(info->uid);
172 info->gid = __cpu_to_be32(info->gid);
173 info->blocksize = __cpu_to_be32(info->blocksize);
174 info->blocks = __cpu_to_be64(info->blocks);
175 info->rdev = __cpu_to_be64(info->rdev);
176 info->size = __cpu_to_be64(info->size);
177 info->version = __cpu_to_be64(info->version);
178 info->ino = __cpu_to_be64(info->ino);
179 }
180
181 /*
182 * Cache state machine.
183 */
184 enum {
185 NETFS_COMMAND_PENDING = 0, /* Command is being executed */
186 NETFS_INODE_REMOTE_SYNCED, /* Inode was synced to server */
187 NETFS_INODE_REMOTE_DIR_SYNCED, /* Inode (directory) was synced from the server */
188 NETFS_INODE_OWNED, /* Inode is owned by given host */
189 NETFS_INODE_NEED_FLUSH, /* Inode has to be flushed to the server */
190 };
191
192 /*
193 * POHMELFS capabilities: information about supported
194 * crypto operations (hash/cipher, modes, key sizes and so on),
195 * root informaion (used/available size, number of objects, permissions)
196 */
197 enum pohmelfs_capabilities {
198 POHMELFS_CRYPTO_CAPABILITIES = 0,
199 POHMELFS_ROOT_CAPABILITIES,
200 };
201
202 /* Read-only mount */
203 #define POHMELFS_FLAGS_RO (1<<0)
204 /* Extended attributes support on/off */
205 #define POHMELFS_FLAGS_XATTR (1<<1)
206
207 struct netfs_root_capabilities
208 {
209 __u64 nr_files;
210 __u64 used, avail;
211 __u64 flags;
212 };
213
214 static inline void netfs_convert_root_capabilities(struct netfs_root_capabilities *cap)
215 {
216 cap->nr_files = __cpu_to_be64(cap->nr_files);
217 cap->used = __cpu_to_be64(cap->used);
218 cap->avail = __cpu_to_be64(cap->avail);
219 cap->flags = __cpu_to_be64(cap->flags);
220 }
221
222 struct netfs_crypto_capabilities
223 {
224 unsigned short hash_strlen; /* Hash string length, like "hmac(sha1) including 0 byte "*/
225 unsigned short cipher_strlen; /* Cipher string length with the same format */
226 unsigned int cipher_keysize; /* Cipher key size */
227 };
228
229 static inline void netfs_convert_crypto_capabilities(struct netfs_crypto_capabilities *cap)
230 {
231 cap->hash_strlen = __cpu_to_be16(cap->hash_strlen);
232 cap->cipher_strlen = __cpu_to_be16(cap->cipher_strlen);
233 cap->cipher_keysize = __cpu_to_be32(cap->cipher_keysize);
234 }
235
236 enum pohmelfs_lock_type {
237 POHMELFS_LOCK_GRAB = (1<<15),
238
239 POHMELFS_READ_LOCK = 0,
240 POHMELFS_WRITE_LOCK,
241 };
242
243 struct netfs_lock
244 {
245 __u64 start;
246 __u64 ino;
247 __u32 size;
248 __u32 type;
249 };
250
251 static inline void netfs_convert_lock(struct netfs_lock *lock)
252 {
253 lock->start = __cpu_to_be64(lock->start);
254 lock->ino = __cpu_to_be64(lock->ino);
255 lock->size = __cpu_to_be32(lock->size);
256 lock->type = __cpu_to_be32(lock->type);
257 }
258
259 #ifdef __KERNEL__
260
261 #include <linux/kernel.h>
262 #include <linux/completion.h>
263 #include <linux/rbtree.h>
264 #include <linux/net.h>
265 #include <linux/poll.h>
266
267 /*
268 * Private POHMELFS cache of objects in directory.
269 */
270 struct pohmelfs_name
271 {
272 struct rb_node hash_node;
273
274 struct list_head sync_create_entry;
275
276 u64 ino;
277
278 u32 hash;
279 u32 mode;
280 u32 len;
281
282 char *data;
283 };
284
285 /*
286 * POHMELFS inode. Main object.
287 */
288 struct pohmelfs_inode
289 {
290 struct list_head inode_entry; /* Entry in superblock list.
291 * Objects which are not bound to dentry require to be dropped
292 * in ->put_super()
293 */
294 struct rb_root hash_root; /* The same, but indexed by name hash and len */
295 struct mutex offset_lock; /* Protect both above trees */
296
297 struct list_head sync_create_list; /* List of created but not yet synced to the server children */
298
299 unsigned int drop_count;
300
301 int lock_type; /* How this inode is locked: read or write */
302
303 int error; /* Transaction error for given inode */
304
305 long state; /* State machine above */
306
307 u64 ino; /* Inode number */
308 u64 total_len; /* Total length of all children names, used to create offsets */
309
310 struct inode vfs_inode;
311 };
312
313 struct netfs_trans;
314 typedef int (* netfs_trans_complete_t)(struct page **pages, unsigned int page_num,
315 void *private, int err);
316
317 struct netfs_state;
318 struct pohmelfs_sb;
319
320 struct netfs_trans
321 {
322 /*
323 * Transaction header and attached contiguous data live here.
324 */
325 struct iovec iovec;
326
327 /*
328 * Pages attached to transaction.
329 */
330 struct page **pages;
331
332 /*
333 * List and protecting lock for transaction destination
334 * network states.
335 */
336 spinlock_t dst_lock;
337 struct list_head dst_list;
338
339 /*
340 * Number of users for given transaction.
341 * For example each network state attached to transaction
342 * via dst_list increases it.
343 */
344 atomic_t refcnt;
345
346 /*
347 * Number of pages attached to given transaction.
348 * Some slots in above page array can be NULL, since
349 * for example page can be under writeback already,
350 * so we skip it in this transaction.
351 */
352 unsigned int page_num;
353
354 /*
355 * Transaction flags: single dst or broadcast and so on.
356 */
357 unsigned int flags;
358
359 /*
360 * Size of the data, which can be placed into
361 * iovec.iov_base area.
362 */
363 unsigned int total_size;
364
365 /*
366 * Number of pages to be sent to remote server.
367 * Usually equal to above page_num, but in case of partial
368 * writeback it can accumulate only pages already completed
369 * previous writeback.
370 */
371 unsigned int attached_pages;
372
373 /*
374 * Attached number of bytes in all above pages.
375 */
376 unsigned int attached_size;
377
378 /*
379 * Unique transacton generation number.
380 * Used as identity in the network state tree of transactions.
381 */
382 unsigned int gen;
383
384 /*
385 * Transaction completion status.
386 */
387 int result;
388
389 /*
390 * Superblock this transaction belongs to
391 */
392 struct pohmelfs_sb *psb;
393
394 /*
395 * Crypto engine, which processed this transaction.
396 * Can be not NULL only if crypto engine holds encrypted pages.
397 */
398 struct pohmelfs_crypto_engine *eng;
399
400 /* Private data */
401 void *private;
402
403 /* Completion callback, invoked just before transaction is destroyed */
404 netfs_trans_complete_t complete;
405 };
406
407 static inline int netfs_trans_cur_len(struct netfs_trans *t)
408 {
409 return (signed)(t->total_size - t->iovec.iov_len);
410 }
411
412 static inline void *netfs_trans_current(struct netfs_trans *t)
413 {
414 return t->iovec.iov_base + t->iovec.iov_len;
415 }
416
417 struct netfs_trans *netfs_trans_alloc(struct pohmelfs_sb *psb, unsigned int size,
418 unsigned int flags, unsigned int nr);
419 void netfs_trans_free(struct netfs_trans *t);
420 int netfs_trans_finish(struct netfs_trans *t, struct pohmelfs_sb *psb);
421 int netfs_trans_finish_send(struct netfs_trans *t, struct pohmelfs_sb *psb);
422
423 static inline void netfs_trans_reset(struct netfs_trans *t)
424 {
425 t->complete = NULL;
426 }
427
428 struct netfs_trans_dst
429 {
430 struct list_head trans_entry;
431 struct rb_node state_entry;
432
433 unsigned long send_time;
434
435 /*
436 * Times this transaction was resent to its old or new,
437 * depending on flags, destinations. When it reaches maximum
438 * allowed number, specified in superblock->trans_retries,
439 * transaction will be freed with ETIMEDOUT error.
440 */
441 unsigned int retries;
442
443 struct netfs_trans *trans;
444 struct netfs_state *state;
445 };
446
447 struct netfs_trans_dst *netfs_trans_search(struct netfs_state *st, unsigned int gen);
448 void netfs_trans_drop_dst(struct netfs_trans_dst *dst);
449 void netfs_trans_drop_dst_nostate(struct netfs_trans_dst *dst);
450 void netfs_trans_drop_trans(struct netfs_trans *t, struct netfs_state *st);
451 void netfs_trans_drop_last(struct netfs_trans *t, struct netfs_state *st);
452 int netfs_trans_resend(struct netfs_trans *t, struct pohmelfs_sb *psb);
453 int netfs_trans_remove_nolock(struct netfs_trans_dst *dst, struct netfs_state *st);
454
455 int netfs_trans_init(void);
456 void netfs_trans_exit(void);
457
458 struct pohmelfs_crypto_engine
459 {
460 u64 iv; /* Crypto IV for current operation */
461 unsigned long timeout; /* Crypto waiting timeout */
462 unsigned int size; /* Size of crypto scratchpad */
463 void *data; /* Temporal crypto scratchpad */
464 /*
465 * Crypto operations performed on objects.
466 */
467 struct crypto_hash *hash;
468 struct crypto_ablkcipher *cipher;
469
470 struct pohmelfs_crypto_thread *thread; /* Crypto thread which hosts this engine */
471
472 struct page **pages;
473 unsigned int page_num;
474 };
475
476 struct pohmelfs_crypto_thread
477 {
478 struct list_head thread_entry;
479
480 struct task_struct *thread;
481 struct pohmelfs_sb *psb;
482
483 struct pohmelfs_crypto_engine eng;
484
485 struct netfs_trans *trans;
486
487 wait_queue_head_t wait;
488 int error;
489
490 unsigned int size;
491 struct page *page;
492 };
493
494 void pohmelfs_crypto_thread_make_ready(struct pohmelfs_crypto_thread *th);
495
496 /*
497 * Network state, attached to one server.
498 */
499 struct netfs_state
500 {
501 struct mutex __state_lock; /* Can not allow to use the same socket simultaneously */
502 struct mutex __state_send_lock;
503 struct netfs_cmd cmd; /* Cached command */
504 struct netfs_inode_info info; /* Cached inode info */
505
506 void *data; /* Cached some data */
507 unsigned int size; /* Size of that data */
508
509 struct pohmelfs_sb *psb; /* Superblock */
510
511 struct task_struct *thread; /* Async receiving thread */
512
513 /* Waiting/polling machinery */
514 wait_queue_t wait;
515 wait_queue_head_t *whead;
516 wait_queue_head_t thread_wait;
517
518 struct mutex trans_lock;
519 struct rb_root trans_root;
520
521 struct pohmelfs_ctl ctl; /* Remote peer */
522
523 struct socket *socket; /* Socket object */
524 struct socket *read_socket; /* Cached pointer to socket object.
525 * Used to determine if between lock drops socket was changed.
526 * Never used to read data or any kind of access.
527 */
528 /*
529 * Crypto engines to process incoming data.
530 */
531 struct pohmelfs_crypto_engine eng;
532
533 int need_reset;
534 };
535
536 int netfs_state_init(struct netfs_state *st);
537 void netfs_state_exit(struct netfs_state *st);
538
539 static inline void netfs_state_lock_send(struct netfs_state *st)
540 {
541 mutex_lock(&st->__state_send_lock);
542 }
543
544 static inline int netfs_state_trylock_send(struct netfs_state *st)
545 {
546 return mutex_trylock(&st->__state_send_lock);
547 }
548
549 static inline void netfs_state_unlock_send(struct netfs_state *st)
550 {
551 BUG_ON(!mutex_is_locked(&st->__state_send_lock));
552
553 mutex_unlock(&st->__state_send_lock);
554 }
555
556 static inline void netfs_state_lock(struct netfs_state *st)
557 {
558 mutex_lock(&st->__state_lock);
559 }
560
561 static inline void netfs_state_unlock(struct netfs_state *st)
562 {
563 BUG_ON(!mutex_is_locked(&st->__state_lock));
564
565 mutex_unlock(&st->__state_lock);
566 }
567
568 static inline unsigned int netfs_state_poll(struct netfs_state *st)
569 {
570 unsigned int revents = POLLHUP | POLLERR;
571
572 netfs_state_lock(st);
573 if (st->socket)
574 revents = st->socket->ops->poll(NULL, st->socket, NULL);
575 netfs_state_unlock(st);
576
577 return revents;
578 }
579
580 struct pohmelfs_config;
581
582 struct pohmelfs_sb
583 {
584 struct rb_root mcache_root;
585 struct mutex mcache_lock;
586 atomic_long_t mcache_gen;
587 unsigned long mcache_timeout;
588
589 unsigned int idx;
590
591 unsigned int trans_retries;
592
593 atomic_t trans_gen;
594
595 unsigned int crypto_attached_size;
596 unsigned int crypto_align_size;
597
598 unsigned int crypto_fail_unsupported;
599
600 unsigned int crypto_thread_num;
601 struct list_head crypto_active_list, crypto_ready_list;
602 struct mutex crypto_thread_lock;
603
604 unsigned int trans_max_pages;
605 unsigned long trans_data_size;
606 unsigned long trans_timeout;
607
608 unsigned long drop_scan_timeout;
609 unsigned long trans_scan_timeout;
610
611 unsigned long wait_on_page_timeout;
612
613 struct list_head flush_list;
614 struct list_head drop_list;
615 spinlock_t ino_lock;
616 u64 ino;
617
618 /*
619 * Remote nodes POHMELFS connected to.
620 */
621 struct list_head state_list;
622 struct mutex state_lock;
623
624 /*
625 * Currently active state to request data from.
626 */
627 struct pohmelfs_config *active_state;
628
629
630 wait_queue_head_t wait;
631
632 /*
633 * Timed checks: stale transactions, inodes to be freed and so on.
634 */
635 struct delayed_work dwork;
636 struct delayed_work drop_dwork;
637
638 struct super_block *sb;
639
640 /*
641 * Algorithm strings.
642 */
643 char *hash_string;
644 char *cipher_string;
645
646 u8 *hash_key;
647 u8 *cipher_key;
648
649 /*
650 * Algorithm string lengths.
651 */
652 unsigned int hash_strlen;
653 unsigned int cipher_strlen;
654 unsigned int hash_keysize;
655 unsigned int cipher_keysize;
656
657 /*
658 * Controls whether to perfrom crypto processing or not.
659 */
660 int perform_crypto;
661
662 /*
663 * POHMELFS statistics.
664 */
665 u64 total_size;
666 u64 avail_size;
667 atomic_long_t total_inodes;
668
669 /*
670 * Xattr support, read-only and so on.
671 */
672 u64 state_flags;
673
674 /*
675 * Temporary storage to detect changes in the wait queue.
676 */
677 long flags;
678 };
679
680 static inline void netfs_trans_update(struct netfs_cmd *cmd,
681 struct netfs_trans *t, unsigned int size)
682 {
683 unsigned int sz = ALIGN(size, t->psb->crypto_align_size);
684
685 t->iovec.iov_len += sizeof(struct netfs_cmd) + sz;
686 cmd->cpad = __cpu_to_be16(sz - size);
687 }
688
689 static inline struct pohmelfs_sb *POHMELFS_SB(struct super_block *sb)
690 {
691 return sb->s_fs_info;
692 }
693
694 static inline struct pohmelfs_inode *POHMELFS_I(struct inode *inode)
695 {
696 return container_of(inode, struct pohmelfs_inode, vfs_inode);
697 }
698
699 static inline u64 pohmelfs_new_ino(struct pohmelfs_sb *psb)
700 {
701 u64 ino;
702
703 spin_lock(&psb->ino_lock);
704 ino = psb->ino++;
705 spin_unlock(&psb->ino_lock);
706
707 return ino;
708 }
709
710 static inline void pohmelfs_put_inode(struct pohmelfs_inode *pi)
711 {
712 struct pohmelfs_sb *psb = POHMELFS_SB(pi->vfs_inode.i_sb);
713
714 spin_lock(&psb->ino_lock);
715 list_move_tail(&pi->inode_entry, &psb->drop_list);
716 pi->drop_count++;
717 spin_unlock(&psb->ino_lock);
718 }
719
720 struct pohmelfs_config
721 {
722 struct list_head config_entry;
723
724 struct netfs_state state;
725 };
726
727 struct pohmelfs_config_group
728 {
729 /*
730 * Entry in the global config group list.
731 */
732 struct list_head group_entry;
733
734 /*
735 * Index of the current group.
736 */
737 unsigned int idx;
738 /*
739 * Number of config_list entries in this group entry.
740 */
741 unsigned int num_entry;
742 /*
743 * Algorithm strings.
744 */
745 char *hash_string;
746 char *cipher_string;
747
748 /*
749 * Algorithm string lengths.
750 */
751 unsigned int hash_strlen;
752 unsigned int cipher_strlen;
753
754 /*
755 * Key and its size.
756 */
757 unsigned int hash_keysize;
758 unsigned int cipher_keysize;
759 u8 *hash_key;
760 u8 *cipher_key;
761
762 /*
763 * List of config entries (network state info) for given idx.
764 */
765 struct list_head config_list;
766 };
767
768 int __init pohmelfs_config_init(void);
769 void pohmelfs_config_exit(void);
770 int pohmelfs_copy_config(struct pohmelfs_sb *psb);
771 int pohmelfs_copy_crypto(struct pohmelfs_sb *psb);
772 int pohmelfs_config_check(struct pohmelfs_config *config, int idx);
773 int pohmelfs_state_init_one(struct pohmelfs_sb *psb, struct pohmelfs_config *conf);
774
775 extern const struct file_operations pohmelfs_dir_fops;
776 extern const struct inode_operations pohmelfs_dir_inode_ops;
777
778 int pohmelfs_state_init(struct pohmelfs_sb *psb);
779 void pohmelfs_state_exit(struct pohmelfs_sb *psb);
780 void pohmelfs_state_flush_transactions(struct netfs_state *st);
781
782 void pohmelfs_fill_inode(struct inode *inode, struct netfs_inode_info *info);
783
784 void pohmelfs_name_del(struct pohmelfs_inode *parent, struct pohmelfs_name *n);
785 void pohmelfs_free_names(struct pohmelfs_inode *parent);
786 struct pohmelfs_name *pohmelfs_search_hash(struct pohmelfs_inode *pi, u32 hash);
787
788 void pohmelfs_inode_del_inode(struct pohmelfs_sb *psb, struct pohmelfs_inode *pi);
789
790 struct pohmelfs_inode *pohmelfs_create_entry_local(struct pohmelfs_sb *psb,
791 struct pohmelfs_inode *parent, struct qstr *str, u64 start, int mode);
792
793 int pohmelfs_write_create_inode(struct pohmelfs_inode *pi);
794
795 int pohmelfs_write_inode_create(struct inode *inode, struct netfs_trans *trans);
796 int pohmelfs_remove_child(struct pohmelfs_inode *parent, struct pohmelfs_name *n);
797
798 struct pohmelfs_inode *pohmelfs_new_inode(struct pohmelfs_sb *psb,
799 struct pohmelfs_inode *parent, struct qstr *str,
800 struct netfs_inode_info *info, int link);
801
802 int pohmelfs_setattr(struct dentry *dentry, struct iattr *attr);
803 int pohmelfs_setattr_raw(struct inode *inode, struct iattr *attr);
804
805 int pohmelfs_meta_command(struct pohmelfs_inode *pi, unsigned int cmd_op, unsigned int flags,
806 netfs_trans_complete_t complete, void *priv, u64 start);
807 int pohmelfs_meta_command_data(struct pohmelfs_inode *pi, u64 id, unsigned int cmd_op, char *addon,
808 unsigned int flags, netfs_trans_complete_t complete, void *priv, u64 start);
809
810 void pohmelfs_check_states(struct pohmelfs_sb *psb);
811 void pohmelfs_switch_active(struct pohmelfs_sb *psb);
812
813 int pohmelfs_construct_path_string(struct pohmelfs_inode *pi, void *data, int len);
814 int pohmelfs_path_length(struct pohmelfs_inode *pi);
815
816 struct pohmelfs_crypto_completion
817 {
818 struct completion complete;
819 int error;
820 };
821
822 int pohmelfs_trans_crypt(struct netfs_trans *t, struct pohmelfs_sb *psb);
823 void pohmelfs_crypto_exit(struct pohmelfs_sb *psb);
824 int pohmelfs_crypto_init(struct pohmelfs_sb *psb);
825
826 int pohmelfs_crypto_engine_init(struct pohmelfs_crypto_engine *e, struct pohmelfs_sb *psb);
827 void pohmelfs_crypto_engine_exit(struct pohmelfs_crypto_engine *e);
828
829 int pohmelfs_crypto_process_input_data(struct pohmelfs_crypto_engine *e, u64 iv,
830 void *data, struct page *page, unsigned int size);
831 int pohmelfs_crypto_process_input_page(struct pohmelfs_crypto_engine *e,
832 struct page *page, unsigned int size, u64 iv);
833
834 static inline u64 pohmelfs_gen_iv(struct netfs_trans *t)
835 {
836 u64 iv = t->gen;
837
838 iv <<= 32;
839 iv |= ((unsigned long)t) & 0xffffffff;
840
841 return iv;
842 }
843
844 int pohmelfs_data_lock(struct pohmelfs_inode *pi, u64 start, u32 size, int type);
845 int pohmelfs_data_unlock(struct pohmelfs_inode *pi, u64 start, u32 size, int type);
846 int pohmelfs_data_lock_response(struct netfs_state *st);
847
848 static inline int pohmelfs_need_lock(struct pohmelfs_inode *pi, int type)
849 {
850 if (test_bit(NETFS_INODE_OWNED, &pi->state)) {
851 if (type == pi->lock_type)
852 return 0;
853 if ((type == POHMELFS_READ_LOCK) && (pi->lock_type == POHMELFS_WRITE_LOCK))
854 return 0;
855 }
856
857 if (!test_bit(NETFS_INODE_REMOTE_SYNCED, &pi->state))
858 return 0;
859
860 return 1;
861 }
862
863 int __init pohmelfs_mcache_init(void);
864 void pohmelfs_mcache_exit(void);
865
866 //#define CONFIG_POHMELFS_DEBUG
867
868 #ifdef CONFIG_POHMELFS_DEBUG
869 #define dprintka(f, a...) printk(f, ##a)
870 #define dprintk(f, a...) printk("%d: " f, task_pid_vnr(current), ##a)
871 #else
872 #define dprintka(f, a...) do {} while (0)
873 #define dprintk(f, a...) do {} while (0)
874 #endif
875
876 static inline void netfs_trans_get(struct netfs_trans *t)
877 {
878 atomic_inc(&t->refcnt);
879 }
880
881 static inline void netfs_trans_put(struct netfs_trans *t)
882 {
883 if (atomic_dec_and_test(&t->refcnt)) {
884 dprintk("%s: t: %p, gen: %u, err: %d.\n",
885 __func__, t, t->gen, t->result);
886 if (t->complete)
887 t->complete(t->pages, t->page_num,
888 t->private, t->result);
889 netfs_trans_free(t);
890 }
891 }
892
893 struct pohmelfs_mcache
894 {
895 struct rb_node mcache_entry;
896 struct completion complete;
897
898 atomic_t refcnt;
899
900 u64 gen;
901
902 void *data;
903 u64 start;
904 u32 size;
905 int err;
906
907 struct netfs_inode_info info;
908 };
909
910 struct pohmelfs_mcache *pohmelfs_mcache_alloc(struct pohmelfs_sb *psb, u64 start,
911 unsigned int size, void *data);
912 void pohmelfs_mcache_free(struct pohmelfs_sb *psb, struct pohmelfs_mcache *m);
913 struct pohmelfs_mcache *pohmelfs_mcache_search(struct pohmelfs_sb *psb, u64 gen);
914 void pohmelfs_mcache_remove_locked(struct pohmelfs_sb *psb, struct pohmelfs_mcache *m);
915
916 static inline void pohmelfs_mcache_get(struct pohmelfs_mcache *m)
917 {
918 atomic_inc(&m->refcnt);
919 }
920
921 static inline void pohmelfs_mcache_put(struct pohmelfs_sb *psb,
922 struct pohmelfs_mcache *m)
923 {
924 if (atomic_dec_and_test(&m->refcnt))
925 pohmelfs_mcache_free(psb, m);
926 }
927
928 #endif /* __KERNEL__*/
929
930 #endif /* __NETFS_H */