]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/pohmelfs/inode.c
Staging: Fixed pohmelfs regression because of per-bdi writeback.
[karo-tx-linux.git] / drivers / staging / pohmelfs / inode.c
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 #include <linux/module.h>
17 #include <linux/backing-dev.h>
18 #include <linux/crypto.h>
19 #include <linux/fs.h>
20 #include <linux/jhash.h>
21 #include <linux/hash.h>
22 #include <linux/ktime.h>
23 #include <linux/mm.h>
24 #include <linux/mount.h>
25 #include <linux/pagemap.h>
26 #include <linux/pagevec.h>
27 #include <linux/parser.h>
28 #include <linux/swap.h>
29 #include <linux/slab.h>
30 #include <linux/statfs.h>
31 #include <linux/writeback.h>
32 #include <linux/quotaops.h>
33
34 #include "netfs.h"
35
36 #define POHMELFS_MAGIC_NUM      0x504f482e
37
38 static struct kmem_cache *pohmelfs_inode_cache;
39 static atomic_t psb_bdi_num = ATOMIC_INIT(0);
40
41 /*
42  * Removes inode from all trees, drops local name cache and removes all queued
43  * requests for object removal.
44  */
45 void pohmelfs_inode_del_inode(struct pohmelfs_sb *psb, struct pohmelfs_inode *pi)
46 {
47         mutex_lock(&pi->offset_lock);
48         pohmelfs_free_names(pi);
49         mutex_unlock(&pi->offset_lock);
50
51         dprintk("%s: deleted stuff in ino: %llu.\n", __func__, pi->ino);
52 }
53
54 /*
55  * Sync inode to server.
56  * Returns zero in success and negative error value otherwise.
57  * It will gather path to root directory into structures containing
58  * creation mode, permissions and names, so that the whole path
59  * to given inode could be created using only single network command.
60  */
61 int pohmelfs_write_inode_create(struct inode *inode, struct netfs_trans *trans)
62 {
63         struct pohmelfs_inode *pi = POHMELFS_I(inode);
64         int err = -ENOMEM, size;
65         struct netfs_cmd *cmd;
66         void *data;
67         int cur_len = netfs_trans_cur_len(trans);
68
69         if (unlikely(cur_len < 0))
70                 return -ETOOSMALL;
71
72         cmd = netfs_trans_current(trans);
73         cur_len -= sizeof(struct netfs_cmd);
74
75         data = (void *)(cmd + 1);
76
77         err = pohmelfs_construct_path_string(pi, data, cur_len);
78         if (err < 0)
79                 goto err_out_exit;
80
81         size = err;
82
83         cmd->start = i_size_read(inode);
84         cmd->cmd = NETFS_CREATE;
85         cmd->size = size;
86         cmd->id = pi->ino;
87         cmd->ext = inode->i_mode;
88
89         netfs_convert_cmd(cmd);
90
91         netfs_trans_update(cmd, trans, size);
92
93         return 0;
94
95 err_out_exit:
96         printk("%s: completed ino: %llu, err: %d.\n", __func__, pi->ino, err);
97         return err;
98 }
99
100 static int pohmelfs_write_trans_complete(struct page **pages, unsigned int page_num,
101                 void *private, int err)
102 {
103         unsigned i;
104
105         dprintk("%s: pages: %lu-%lu, page_num: %u, err: %d.\n",
106                         __func__, pages[0]->index, pages[page_num-1]->index,
107                         page_num, err);
108
109         for (i = 0; i < page_num; i++) {
110                 struct page *page = pages[i];
111
112                 if (!page)
113                         continue;
114
115                 end_page_writeback(page);
116
117                 if (err < 0) {
118                         SetPageError(page);
119                         set_page_dirty(page);
120                 }
121
122                 unlock_page(page);
123                 page_cache_release(page);
124
125                 /* dprintk("%s: %3u/%u: page: %p.\n", __func__, i, page_num, page); */
126         }
127         return err;
128 }
129
130 static int pohmelfs_inode_has_dirty_pages(struct address_space *mapping, pgoff_t index)
131 {
132         int ret;
133         struct page *page;
134
135         rcu_read_lock();
136         ret = radix_tree_gang_lookup_tag(&mapping->page_tree,
137                                 (void **)&page, index, 1, PAGECACHE_TAG_DIRTY);
138         rcu_read_unlock();
139         return ret;
140 }
141
142 static int pohmelfs_writepages(struct address_space *mapping, struct writeback_control *wbc)
143 {
144         struct inode *inode = mapping->host;
145         struct pohmelfs_inode *pi = POHMELFS_I(inode);
146         struct pohmelfs_sb *psb = POHMELFS_SB(inode->i_sb);
147         int err = 0;
148         int done = 0;
149         int nr_pages;
150         pgoff_t index;
151         pgoff_t end;            /* Inclusive */
152         int scanned = 0;
153         int range_whole = 0;
154
155         if (wbc->range_cyclic) {
156                 index = mapping->writeback_index; /* Start from prev offset */
157                 end = -1;
158         } else {
159                 index = wbc->range_start >> PAGE_CACHE_SHIFT;
160                 end = wbc->range_end >> PAGE_CACHE_SHIFT;
161                 if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
162                         range_whole = 1;
163                 scanned = 1;
164         }
165 retry:
166         while (!done && (index <= end)) {
167                 unsigned int i = min(end - index, (pgoff_t)psb->trans_max_pages);
168                 int path_len;
169                 struct netfs_trans *trans;
170
171                 err = pohmelfs_inode_has_dirty_pages(mapping, index);
172                 if (!err)
173                         break;
174
175                 err = pohmelfs_path_length(pi);
176                 if (err < 0)
177                         break;
178
179                 path_len = err;
180
181                 if (path_len <= 2) {
182                         err = -ENOENT;
183                         break;
184                 }
185
186                 trans = netfs_trans_alloc(psb, path_len, 0, i);
187                 if (!trans) {
188                         err = -ENOMEM;
189                         break;
190                 }
191                 trans->complete = &pohmelfs_write_trans_complete;
192
193                 trans->page_num = nr_pages = find_get_pages_tag(mapping, &index,
194                                 PAGECACHE_TAG_DIRTY, trans->page_num,
195                                 trans->pages);
196
197                 dprintk("%s: t: %p, nr_pages: %u, end: %lu, index: %lu, max: %u.\n",
198                                 __func__, trans, nr_pages, end, index, trans->page_num);
199
200                 if (!nr_pages)
201                         goto err_out_reset;
202
203                 err = pohmelfs_write_inode_create(inode, trans);
204                 if (err)
205                         goto err_out_reset;
206
207                 err = 0;
208                 scanned = 1;
209
210                 for (i = 0; i < trans->page_num; i++) {
211                         struct page *page = trans->pages[i];
212
213                         lock_page(page);
214
215                         if (unlikely(page->mapping != mapping))
216                                 goto out_continue;
217
218                         if (!wbc->range_cyclic && page->index > end) {
219                                 done = 1;
220                                 goto out_continue;
221                         }
222
223                         if (wbc->sync_mode != WB_SYNC_NONE)
224                                 wait_on_page_writeback(page);
225
226                         if (PageWriteback(page) ||
227                             !clear_page_dirty_for_io(page)) {
228                                 dprintk("%s: not clear for io page: %p, writeback: %d.\n",
229                                                 __func__, page, PageWriteback(page));
230                                 goto out_continue;
231                         }
232
233                         set_page_writeback(page);
234
235                         trans->attached_size += page_private(page);
236                         trans->attached_pages++;
237 #if 0
238                         dprintk("%s: %u/%u added trans: %p, gen: %u, page: %p, [High: %d], size: %lu, idx: %lu.\n",
239                                         __func__, i, trans->page_num, trans, trans->gen, page,
240                                         !!PageHighMem(page), page_private(page), page->index);
241 #endif
242                         wbc->nr_to_write--;
243
244                         if (wbc->nr_to_write <= 0)
245                                 done = 1;
246
247                         continue;
248 out_continue:
249                         unlock_page(page);
250                         trans->pages[i] = NULL;
251                 }
252
253                 err = netfs_trans_finish(trans, psb);
254                 if (err)
255                         break;
256
257                 continue;
258
259 err_out_reset:
260                 trans->result = err;
261                 netfs_trans_reset(trans);
262                 netfs_trans_put(trans);
263                 break;
264         }
265
266         if (!scanned && !done) {
267                 /*
268                  * We hit the last page and there is more work to be done: wrap
269                  * back to the start of the file
270                  */
271                 scanned = 1;
272                 index = 0;
273                 goto retry;
274         }
275
276         if (wbc->range_cyclic || (range_whole && wbc->nr_to_write > 0))
277                 mapping->writeback_index = index;
278
279         return err;
280 }
281
282 /*
283  * Inode writeback creation completion callback.
284  * Only invoked for just created inodes, which do not have pages attached,
285  * like dirs and empty files.
286  */
287 static int pohmelfs_write_inode_complete(struct page **pages, unsigned int page_num,
288                 void *private, int err)
289 {
290         struct inode *inode = private;
291         struct pohmelfs_inode *pi = POHMELFS_I(inode);
292
293         if (inode) {
294                 if (err) {
295                         mark_inode_dirty(inode);
296                         clear_bit(NETFS_INODE_REMOTE_SYNCED, &pi->state);
297                 } else {
298                         set_bit(NETFS_INODE_REMOTE_SYNCED, &pi->state);
299                 }
300
301                 pohmelfs_put_inode(pi);
302         }
303
304         return err;
305 }
306
307 int pohmelfs_write_create_inode(struct pohmelfs_inode *pi)
308 {
309         struct netfs_trans *t;
310         struct inode *inode = &pi->vfs_inode;
311         struct pohmelfs_sb *psb = POHMELFS_SB(inode->i_sb);
312         int err;
313
314         if (test_bit(NETFS_INODE_REMOTE_SYNCED, &pi->state))
315                 return 0;
316
317         dprintk("%s: started ino: %llu.\n", __func__, pi->ino);
318
319         err = pohmelfs_path_length(pi);
320         if (err < 0)
321                 goto err_out_exit;
322
323         t = netfs_trans_alloc(psb, err + 1, 0, 0);
324         if (!t) {
325                 err = -ENOMEM;
326                 goto err_out_exit;
327         }
328         t->complete = pohmelfs_write_inode_complete;
329         t->private = igrab(inode);
330         if (!t->private) {
331                 err = -ENOENT;
332                 goto err_out_put;
333         }
334
335         err = pohmelfs_write_inode_create(inode, t);
336         if (err)
337                 goto err_out_put;
338
339         netfs_trans_finish(t, POHMELFS_SB(inode->i_sb));
340
341         return 0;
342
343 err_out_put:
344         t->result = err;
345         netfs_trans_put(t);
346 err_out_exit:
347         return err;
348 }
349
350 /*
351  * Sync all not-yet-created children in given directory to the server.
352  */
353 static int pohmelfs_write_inode_create_children(struct inode *inode)
354 {
355         struct pohmelfs_inode *parent = POHMELFS_I(inode);
356         struct super_block *sb = inode->i_sb;
357         struct pohmelfs_name *n;
358
359         while (!list_empty(&parent->sync_create_list)) {
360                 n = NULL;
361                 mutex_lock(&parent->offset_lock);
362                 if (!list_empty(&parent->sync_create_list)) {
363                         n = list_first_entry(&parent->sync_create_list,
364                                 struct pohmelfs_name, sync_create_entry);
365                         list_del_init(&n->sync_create_entry);
366                 }
367                 mutex_unlock(&parent->offset_lock);
368
369                 if (!n)
370                         break;
371
372                 inode = ilookup(sb, n->ino);
373
374                 dprintk("%s: parent: %llu, ino: %llu, inode: %p.\n",
375                                 __func__, parent->ino, n->ino, inode);
376
377                 if (inode && (inode->i_state & I_DIRTY)) {
378                         struct pohmelfs_inode *pi = POHMELFS_I(inode);
379                         pohmelfs_write_create_inode(pi);
380                         /* pohmelfs_meta_command(pi, NETFS_INODE_INFO, 0, NULL, NULL, 0); */
381                         iput(inode);
382                 }
383         }
384
385         return 0;
386 }
387
388 /*
389  * Removes given child from given inode on server.
390  */
391 int pohmelfs_remove_child(struct pohmelfs_inode *pi, struct pohmelfs_name *n)
392 {
393         return pohmelfs_meta_command_data(pi, pi->ino, NETFS_REMOVE, NULL, 0, NULL, NULL, 0);
394 }
395
396 /*
397  * Writeback for given inode.
398  */
399 static int pohmelfs_write_inode(struct inode *inode, int sync)
400 {
401         struct pohmelfs_inode *pi = POHMELFS_I(inode);
402
403         pohmelfs_write_create_inode(pi);
404         pohmelfs_write_inode_create_children(inode);
405
406         return 0;
407 }
408
409 /*
410  * It is not exported, sorry...
411  */
412 static inline wait_queue_head_t *page_waitqueue(struct page *page)
413 {
414         const struct zone *zone = page_zone(page);
415
416         return &zone->wait_table[hash_ptr(page, zone->wait_table_bits)];
417 }
418
419 static int pohmelfs_wait_on_page_locked(struct page *page)
420 {
421         struct pohmelfs_sb *psb = POHMELFS_SB(page->mapping->host->i_sb);
422         long ret = psb->wait_on_page_timeout;
423         DEFINE_WAIT_BIT(wait, &page->flags, PG_locked);
424         int err = 0;
425
426         if (!PageLocked(page))
427                 return 0;
428
429         for (;;) {
430                 prepare_to_wait(page_waitqueue(page),
431                                 &wait.wait, TASK_INTERRUPTIBLE);
432
433                 dprintk("%s: page: %p, locked: %d, uptodate: %d, error: %d, flags: %lx.\n",
434                                 __func__, page, PageLocked(page), PageUptodate(page),
435                                 PageError(page), page->flags);
436
437                 if (!PageLocked(page))
438                         break;
439
440                 if (!signal_pending(current)) {
441                         ret = schedule_timeout(ret);
442                         if (!ret)
443                                 break;
444                         continue;
445                 }
446                 ret = -ERESTARTSYS;
447                 break;
448         }
449         finish_wait(page_waitqueue(page), &wait.wait);
450
451         if (!ret)
452                 err = -ETIMEDOUT;
453
454
455         if (!err)
456                 SetPageUptodate(page);
457
458         if (err)
459                 printk("%s: page: %p, uptodate: %d, locked: %d, err: %d.\n",
460                         __func__, page, PageUptodate(page), PageLocked(page), err);
461
462         return err;
463 }
464
465 static int pohmelfs_read_page_complete(struct page **pages, unsigned int page_num,
466                 void *private, int err)
467 {
468         struct page *page = private;
469
470         if (PageChecked(page))
471                 return err;
472
473         if (err < 0) {
474                 dprintk("%s: page: %p, err: %d.\n", __func__, page, err);
475                 SetPageError(page);
476         }
477
478         unlock_page(page);
479
480         return err;
481 }
482
483 /*
484  * Read a page from remote server.
485  * Function will wait until page is unlocked.
486  */
487 static int pohmelfs_readpage(struct file *file, struct page *page)
488 {
489         struct inode *inode = page->mapping->host;
490         struct pohmelfs_sb *psb = POHMELFS_SB(inode->i_sb);
491         struct pohmelfs_inode *pi = POHMELFS_I(inode);
492         struct netfs_trans *t;
493         struct netfs_cmd *cmd;
494         int err, path_len;
495         void *data;
496         u64 isize;
497
498         err = pohmelfs_data_lock(pi, page->index << PAGE_CACHE_SHIFT,
499                         PAGE_SIZE, POHMELFS_READ_LOCK);
500         if (err)
501                 goto err_out_exit;
502
503         isize = i_size_read(inode);
504         if (isize <= page->index << PAGE_CACHE_SHIFT) {
505                 SetPageUptodate(page);
506                 unlock_page(page);
507                 return 0;
508         }
509
510         path_len = pohmelfs_path_length(pi);
511         if (path_len < 0) {
512                 err = path_len;
513                 goto err_out_exit;
514         }
515
516         t = netfs_trans_alloc(psb, path_len, NETFS_TRANS_SINGLE_DST, 0);
517         if (!t) {
518                 err = -ENOMEM;
519                 goto err_out_exit;
520         }
521
522         t->complete = pohmelfs_read_page_complete;
523         t->private = page;
524
525         cmd = netfs_trans_current(t);
526         data = (void *)(cmd + 1);
527
528         err = pohmelfs_construct_path_string(pi, data, path_len);
529         if (err < 0)
530                 goto err_out_free;
531
532         path_len = err;
533
534         cmd->id = pi->ino;
535         cmd->start = page->index;
536         cmd->start <<= PAGE_CACHE_SHIFT;
537         cmd->size = PAGE_CACHE_SIZE + path_len;
538         cmd->cmd = NETFS_READ_PAGE;
539         cmd->ext = path_len;
540
541         dprintk("%s: path: '%s', page: %p, ino: %llu, start: %llu, size: %lu.\n",
542                         __func__, (char *)data, page, pi->ino, cmd->start, PAGE_CACHE_SIZE);
543
544         netfs_convert_cmd(cmd);
545         netfs_trans_update(cmd, t, path_len);
546
547         err = netfs_trans_finish(t, psb);
548         if (err)
549                 goto err_out_return;
550
551         return pohmelfs_wait_on_page_locked(page);
552
553 err_out_free:
554         t->result = err;
555         netfs_trans_put(t);
556 err_out_exit:
557         SetPageError(page);
558         if (PageLocked(page))
559                 unlock_page(page);
560 err_out_return:
561         printk("%s: page: %p, start: %lu, size: %lu, err: %d.\n",
562                 __func__, page, page->index << PAGE_CACHE_SHIFT, PAGE_CACHE_SIZE, err);
563
564         return err;
565 }
566
567 /*
568  * Write begin/end magic.
569  * Allocates a page and writes inode if it was not synced to server before.
570  */
571 static int pohmelfs_write_begin(struct file *file, struct address_space *mapping,
572                 loff_t pos, unsigned len, unsigned flags,
573                 struct page **pagep, void **fsdata)
574 {
575         struct inode *inode = mapping->host;
576         struct page *page;
577         pgoff_t index;
578         unsigned start, end;
579         int err;
580
581         *pagep = NULL;
582
583         index = pos >> PAGE_CACHE_SHIFT;
584         start = pos & (PAGE_CACHE_SIZE - 1);
585         end = start + len;
586
587         page = grab_cache_page(mapping, index);
588 #if 0
589         dprintk("%s: page: %p pos: %llu, len: %u, index: %lu, start: %u, end: %u, uptodate: %d.\n",
590                         __func__, page, pos, len, index, start, end, PageUptodate(page));
591 #endif
592         if (!page) {
593                 err = -ENOMEM;
594                 goto err_out_exit;
595         }
596
597         while (!PageUptodate(page)) {
598                 if (start && test_bit(NETFS_INODE_REMOTE_SYNCED, &POHMELFS_I(inode)->state)) {
599                         err = pohmelfs_readpage(file, page);
600                         if (err)
601                                 goto err_out_exit;
602
603                         lock_page(page);
604                         continue;
605                 }
606
607                 if (len != PAGE_CACHE_SIZE) {
608                         void *kaddr = kmap_atomic(page, KM_USER0);
609
610                         memset(kaddr + start, 0, PAGE_CACHE_SIZE - start);
611                         flush_dcache_page(page);
612                         kunmap_atomic(kaddr, KM_USER0);
613                 }
614                 SetPageUptodate(page);
615         }
616
617         set_page_private(page, end);
618
619         *pagep = page;
620
621         return 0;
622
623 err_out_exit:
624         page_cache_release(page);
625         *pagep = NULL;
626
627         return err;
628 }
629
630 static int pohmelfs_write_end(struct file *file, struct address_space *mapping,
631                         loff_t pos, unsigned len, unsigned copied,
632                         struct page *page, void *fsdata)
633 {
634         struct inode *inode = mapping->host;
635
636         if (copied != len) {
637                 unsigned from = pos & (PAGE_CACHE_SIZE - 1);
638                 void *kaddr = kmap_atomic(page, KM_USER0);
639
640                 memset(kaddr + from + copied, 0, len - copied);
641                 flush_dcache_page(page);
642                 kunmap_atomic(kaddr, KM_USER0);
643         }
644
645         SetPageUptodate(page);
646         set_page_dirty(page);
647 #if 0
648         dprintk("%s: page: %p [U: %d, D: %d, L: %d], pos: %llu, len: %u, copied: %u.\n",
649                         __func__, page,
650                         PageUptodate(page), PageDirty(page), PageLocked(page),
651                         pos, len, copied);
652 #endif
653         flush_dcache_page(page);
654
655         unlock_page(page);
656         page_cache_release(page);
657
658         if (pos + copied > inode->i_size) {
659                 struct pohmelfs_sb *psb = POHMELFS_SB(inode->i_sb);
660
661                 psb->avail_size -= pos + copied - inode->i_size;
662
663                 i_size_write(inode, pos + copied);
664         }
665
666         return copied;
667 }
668
669 static int pohmelfs_readpages_trans_complete(struct page **__pages, unsigned int page_num,
670                 void *private, int err)
671 {
672         struct pohmelfs_inode *pi = private;
673         unsigned int i, num;
674         struct page **pages, *page = (struct page *)__pages;
675         loff_t index = page->index;
676
677         pages = kzalloc(sizeof(void *) * page_num, GFP_NOIO);
678         if (!pages)
679                 return -ENOMEM;
680
681         num = find_get_pages_contig(pi->vfs_inode.i_mapping, index, page_num, pages);
682         if (num <= 0) {
683                 err = num;
684                 goto err_out_free;
685         }
686
687         for (i=0; i<num; ++i) {
688                 page = pages[i];
689
690                 if (err)
691                         printk("%s: %u/%u: page: %p, index: %lu, uptodate: %d, locked: %d, err: %d.\n",
692                                 __func__, i, num, page, page->index,
693                                 PageUptodate(page), PageLocked(page), err);
694
695                 if (!PageChecked(page)) {
696                         if (err < 0)
697                                 SetPageError(page);
698                         unlock_page(page);
699                 }
700                 page_cache_release(page);
701                 page_cache_release(page);
702         }
703
704 err_out_free:
705         kfree(pages);
706         return err;
707 }
708
709 static int pohmelfs_send_readpages(struct pohmelfs_inode *pi, struct page *first, unsigned int num)
710 {
711         struct netfs_trans *t;
712         struct netfs_cmd *cmd;
713         struct pohmelfs_sb *psb = POHMELFS_SB(pi->vfs_inode.i_sb);
714         int err, path_len;
715         void *data;
716
717         err = pohmelfs_data_lock(pi, first->index << PAGE_CACHE_SHIFT,
718                         num * PAGE_SIZE, POHMELFS_READ_LOCK);
719         if (err)
720                 goto err_out_exit;
721
722         path_len = pohmelfs_path_length(pi);
723         if (path_len < 0) {
724                 err = path_len;
725                 goto err_out_exit;
726         }
727
728         t = netfs_trans_alloc(psb, path_len, NETFS_TRANS_SINGLE_DST, 0);
729         if (!t) {
730                 err = -ENOMEM;
731                 goto err_out_exit;
732         }
733
734         cmd = netfs_trans_current(t);
735         data = (void *)(cmd + 1);
736
737         t->complete = pohmelfs_readpages_trans_complete;
738         t->private = pi;
739         t->page_num = num;
740         t->pages = (struct page **)first;
741
742         err = pohmelfs_construct_path_string(pi, data, path_len);
743         if (err < 0)
744                 goto err_out_put;
745
746         path_len = err;
747
748         cmd->cmd = NETFS_READ_PAGES;
749         cmd->start = first->index;
750         cmd->start <<= PAGE_CACHE_SHIFT;
751         cmd->size = (num << 8 | PAGE_CACHE_SHIFT);
752         cmd->id = pi->ino;
753         cmd->ext = path_len;
754
755         dprintk("%s: t: %p, gen: %u, path: '%s', path_len: %u, "
756                         "start: %lu, num: %u.\n",
757                         __func__, t, t->gen, (char *)data, path_len,
758                         first->index, num);
759
760         netfs_convert_cmd(cmd);
761         netfs_trans_update(cmd, t, path_len);
762
763         return netfs_trans_finish(t, psb);
764
765 err_out_put:
766         netfs_trans_free(t);
767 err_out_exit:
768         pohmelfs_readpages_trans_complete((struct page **)first, num, pi, err);
769         return err;
770 }
771
772 #define list_to_page(head) (list_entry((head)->prev, struct page, lru))
773
774 static int pohmelfs_readpages(struct file *file, struct address_space *mapping,
775                         struct list_head *pages, unsigned nr_pages)
776 {
777         unsigned int page_idx, num = 0;
778         struct page *page = NULL, *first = NULL;
779
780         for (page_idx = 0; page_idx < nr_pages; page_idx++) {
781                 page = list_to_page(pages);
782
783                 prefetchw(&page->flags);
784                 list_del(&page->lru);
785
786                 if (!add_to_page_cache_lru(page, mapping,
787                                         page->index, GFP_KERNEL)) {
788
789                         if (!num) {
790                                 num = 1;
791                                 first = page;
792                                 continue;
793                         }
794
795                         dprintk("%s: added to lru page: %p, page_index: %lu, first_index: %lu.\n",
796                                         __func__, page, page->index, first->index);
797
798                         if (unlikely(first->index + num != page->index) || (num > 500)) {
799                                 pohmelfs_send_readpages(POHMELFS_I(mapping->host),
800                                                 first, num);
801                                 first = page;
802                                 num = 0;
803                         }
804
805                         num++;
806                 }
807         }
808         pohmelfs_send_readpages(POHMELFS_I(mapping->host), first, num);
809
810         /*
811          * This will be sync read, so when last page is processed,
812          * all previous are alerady unlocked and ready to be used.
813          */
814         return 0;
815 }
816
817 /*
818  * Small addres space operations for POHMELFS.
819  */
820 const struct address_space_operations pohmelfs_aops = {
821         .readpage               = pohmelfs_readpage,
822         .readpages              = pohmelfs_readpages,
823         .writepages             = pohmelfs_writepages,
824         .write_begin            = pohmelfs_write_begin,
825         .write_end              = pohmelfs_write_end,
826         .set_page_dirty         = __set_page_dirty_nobuffers,
827 };
828
829 /*
830  * ->detroy_inode() callback. Deletes inode from the caches
831  *  and frees private data.
832  */
833 static void pohmelfs_destroy_inode(struct inode *inode)
834 {
835         struct super_block *sb = inode->i_sb;
836         struct pohmelfs_sb *psb = POHMELFS_SB(sb);
837         struct pohmelfs_inode *pi = POHMELFS_I(inode);
838
839         /* pohmelfs_data_unlock(pi, 0, inode->i_size, POHMELFS_READ_LOCK); */
840
841         pohmelfs_inode_del_inode(psb, pi);
842
843         dprintk("%s: pi: %p, inode: %p, ino: %llu.\n",
844                 __func__, pi, &pi->vfs_inode, pi->ino);
845         kmem_cache_free(pohmelfs_inode_cache, pi);
846         atomic_long_dec(&psb->total_inodes);
847 }
848
849 /*
850  * ->alloc_inode() callback. Allocates inode and initilizes private data.
851  */
852 static struct inode *pohmelfs_alloc_inode(struct super_block *sb)
853 {
854         struct pohmelfs_inode *pi;
855
856         pi = kmem_cache_alloc(pohmelfs_inode_cache, GFP_NOIO);
857         if (!pi)
858                 return NULL;
859
860         pi->hash_root = RB_ROOT;
861         mutex_init(&pi->offset_lock);
862
863         INIT_LIST_HEAD(&pi->sync_create_list);
864
865         INIT_LIST_HEAD(&pi->inode_entry);
866
867         pi->lock_type = 0;
868         pi->state = 0;
869         pi->total_len = 0;
870         pi->drop_count = 0;
871
872         dprintk("%s: pi: %p, inode: %p.\n", __func__, pi, &pi->vfs_inode);
873
874         atomic_long_inc(&POHMELFS_SB(sb)->total_inodes);
875
876         return &pi->vfs_inode;
877 }
878
879 /*
880  * We want fsync() to work on POHMELFS.
881  */
882 static int pohmelfs_fsync(struct file *file, struct dentry *dentry, int datasync)
883 {
884         struct inode *inode = file->f_mapping->host;
885         struct writeback_control wbc = {
886                 .sync_mode = WB_SYNC_ALL,
887                 .nr_to_write = 0,       /* sys_fsync did this */
888         };
889
890         return sync_inode(inode, &wbc);
891 }
892
893 ssize_t pohmelfs_write(struct file *file, const char __user *buf,
894                 size_t len, loff_t *ppos)
895 {
896         struct address_space *mapping = file->f_mapping;
897         struct inode *inode = mapping->host;
898         struct pohmelfs_inode *pi = POHMELFS_I(inode);
899         struct iovec iov = { .iov_base = (void __user *)buf, .iov_len = len };
900         struct kiocb kiocb;
901         ssize_t ret;
902         loff_t pos = *ppos;
903
904         init_sync_kiocb(&kiocb, file);
905         kiocb.ki_pos = pos;
906         kiocb.ki_left = len;
907
908         dprintk("%s: len: %zu, pos: %llu.\n", __func__, len, pos);
909
910         mutex_lock(&inode->i_mutex);
911         ret = pohmelfs_data_lock(pi, pos, len, POHMELFS_WRITE_LOCK);
912         if (ret)
913                 goto err_out_unlock;
914
915         ret = __generic_file_aio_write(&kiocb, &iov, 1, &kiocb.ki_pos);
916         *ppos = kiocb.ki_pos;
917
918         mutex_unlock(&inode->i_mutex);
919         WARN_ON(ret < 0);
920
921         if (ret > 0) {
922                 ssize_t err;
923
924                 err = generic_write_sync(file, pos, ret);
925                 if (err < 0)
926                         ret = err;
927                 WARN_ON(ret < 0);
928         }
929
930         return ret;
931
932 err_out_unlock:
933         mutex_unlock(&inode->i_mutex);
934         return ret;
935 }
936
937 static const struct file_operations pohmelfs_file_ops = {
938         .open           = generic_file_open,
939         .fsync          = pohmelfs_fsync,
940
941         .llseek         = generic_file_llseek,
942
943         .read           = do_sync_read,
944         .aio_read       = generic_file_aio_read,
945
946         .mmap           = generic_file_mmap,
947
948         .splice_read    = generic_file_splice_read,
949         .splice_write   = generic_file_splice_write,
950
951         .write          = pohmelfs_write,
952         .aio_write      = generic_file_aio_write,
953 };
954
955 const struct inode_operations pohmelfs_symlink_inode_operations = {
956         .readlink       = generic_readlink,
957         .follow_link    = page_follow_link_light,
958         .put_link       = page_put_link,
959 };
960
961 int pohmelfs_setattr_raw(struct inode *inode, struct iattr *attr)
962 {
963         int err;
964
965         err = inode_change_ok(inode, attr);
966         if (err) {
967                 dprintk("%s: ino: %llu, inode changes are not allowed.\n", __func__, POHMELFS_I(inode)->ino);
968                 goto err_out_exit;
969         }
970
971         if ((attr->ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
972             (attr->ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
973                 err = vfs_dq_transfer(inode, attr) ? -EDQUOT : 0;
974                 if (err)
975                         goto err_out_exit;
976         }
977
978         err = inode_setattr(inode, attr);
979         if (err) {
980                 dprintk("%s: ino: %llu, failed to set the attributes.\n", __func__, POHMELFS_I(inode)->ino);
981                 goto err_out_exit;
982         }
983
984         dprintk("%s: ino: %llu, mode: %o -> %o, uid: %u -> %u, gid: %u -> %u, size: %llu -> %llu.\n",
985                         __func__, POHMELFS_I(inode)->ino, inode->i_mode, attr->ia_mode,
986                         inode->i_uid, attr->ia_uid, inode->i_gid, attr->ia_gid, inode->i_size, attr->ia_size);
987
988         return 0;
989
990 err_out_exit:
991         return err;
992 }
993
994 int pohmelfs_setattr(struct dentry *dentry, struct iattr *attr)
995 {
996         struct inode *inode = dentry->d_inode;
997         struct pohmelfs_inode *pi = POHMELFS_I(inode);
998         int err;
999
1000         err = pohmelfs_data_lock(pi, 0, ~0, POHMELFS_WRITE_LOCK);
1001         if (err)
1002                 goto err_out_exit;
1003
1004         err = security_inode_setattr(dentry, attr);
1005         if (err)
1006                 goto err_out_exit;
1007
1008         err = pohmelfs_setattr_raw(inode, attr);
1009         if (err)
1010                 goto err_out_exit;
1011
1012         return 0;
1013
1014 err_out_exit:
1015         return err;
1016 }
1017
1018 static int pohmelfs_send_xattr_req(struct pohmelfs_inode *pi, u64 id, u64 start,
1019                 const char *name, const void *value, size_t attrsize, int command)
1020 {
1021         struct pohmelfs_sb *psb = POHMELFS_SB(pi->vfs_inode.i_sb);
1022         int err, path_len, namelen = strlen(name) + 1; /* 0-byte */
1023         struct netfs_trans *t;
1024         struct netfs_cmd *cmd;
1025         void *data;
1026
1027         dprintk("%s: id: %llu, start: %llu, name: '%s', attrsize: %zu, cmd: %d.\n",
1028                         __func__, id, start, name, attrsize, command);
1029
1030         path_len = pohmelfs_path_length(pi);
1031         if (path_len < 0) {
1032                 err = path_len;
1033                 goto err_out_exit;
1034         }
1035
1036         t = netfs_trans_alloc(psb, namelen + path_len + attrsize, 0, 0);
1037         if (!t) {
1038                 err = -ENOMEM;
1039                 goto err_out_exit;
1040         }
1041
1042         cmd = netfs_trans_current(t);
1043         data = cmd + 1;
1044
1045         path_len = pohmelfs_construct_path_string(pi, data, path_len);
1046         if (path_len < 0) {
1047                 err = path_len;
1048                 goto err_out_put;
1049         }
1050         data += path_len;
1051
1052         /*
1053          * 'name' is a NUL-terminated string already and
1054          * 'namelen' includes 0-byte.
1055          */
1056         memcpy(data, name, namelen);
1057         data += namelen;
1058
1059         memcpy(data, value, attrsize);
1060
1061         cmd->cmd = command;
1062         cmd->id = id;
1063         cmd->start = start;
1064         cmd->size = attrsize + namelen + path_len;
1065         cmd->ext = path_len;
1066         cmd->csize = 0;
1067         cmd->cpad = 0;
1068
1069         netfs_convert_cmd(cmd);
1070         netfs_trans_update(cmd, t, namelen + path_len + attrsize);
1071
1072         return netfs_trans_finish(t, psb);
1073
1074 err_out_put:
1075         t->result = err;
1076         netfs_trans_put(t);
1077 err_out_exit:
1078         return err;
1079 }
1080
1081 static int pohmelfs_setxattr(struct dentry *dentry, const char *name,
1082                 const void *value, size_t attrsize, int flags)
1083 {
1084         struct inode *inode = dentry->d_inode;
1085         struct pohmelfs_inode *pi = POHMELFS_I(inode);
1086         struct pohmelfs_sb *psb = POHMELFS_SB(inode->i_sb);
1087
1088         if (!(psb->state_flags & POHMELFS_FLAGS_XATTR))
1089                 return -EOPNOTSUPP;
1090
1091         return pohmelfs_send_xattr_req(pi, flags, attrsize, name,
1092                         value, attrsize, NETFS_XATTR_SET);
1093 }
1094
1095 static ssize_t pohmelfs_getxattr(struct dentry *dentry, const char *name,
1096                 void *value, size_t attrsize)
1097 {
1098         struct inode *inode = dentry->d_inode;
1099         struct pohmelfs_inode *pi = POHMELFS_I(inode);
1100         struct pohmelfs_sb *psb = POHMELFS_SB(inode->i_sb);
1101         struct pohmelfs_mcache *m;
1102         int err;
1103         long timeout = psb->mcache_timeout;
1104
1105         if (!(psb->state_flags & POHMELFS_FLAGS_XATTR))
1106                 return -EOPNOTSUPP;
1107
1108         m = pohmelfs_mcache_alloc(psb, 0, attrsize, value);
1109         if (IS_ERR(m))
1110                 return PTR_ERR(m);
1111
1112         dprintk("%s: ino: %llu, name: '%s', size: %zu.\n",
1113                         __func__, pi->ino, name, attrsize);
1114
1115         err = pohmelfs_send_xattr_req(pi, m->gen, attrsize, name, value, 0, NETFS_XATTR_GET);
1116         if (err)
1117                 goto err_out_put;
1118
1119         do {
1120                 err = wait_for_completion_timeout(&m->complete, timeout);
1121                 if (err) {
1122                         err = m->err;
1123                         break;
1124                 }
1125
1126                 /*
1127                  * This loop is a bit ugly, since it waits until reference counter
1128                  * hits 1 and then put object here. Main goal is to prevent race with
1129                  * network thread, when it can start processing given request, i.e.
1130                  * increase its reference counter but yet not complete it, while
1131                  * we will exit from ->getxattr() with timeout, and although request
1132                  * will not be freed (its reference counter was increased by network
1133                  * thread), data pointer provided by user may be released, so we will
1134                  * overwrite already freed area in network thread.
1135                  *
1136                  * Now after timeout we remove request from the cache, so it can not be
1137                  * found by network thread, and wait for its reference counter to hit 1,
1138                  * i.e. if network thread already started to process this request, we wait
1139                  * it to finish, and then free object locally. If reference counter is
1140                  * already 1, i.e. request is not used by anyone else, we can free it without
1141                  * problem.
1142                  */
1143                 err = -ETIMEDOUT;
1144                 timeout = HZ;
1145
1146                 pohmelfs_mcache_remove_locked(psb, m);
1147         } while (atomic_read(&m->refcnt) != 1);
1148
1149         pohmelfs_mcache_put(psb, m);
1150
1151         dprintk("%s: ino: %llu, err: %d.\n", __func__, pi->ino, err);
1152
1153         return err;
1154
1155 err_out_put:
1156         pohmelfs_mcache_put(psb, m);
1157         return err;
1158 }
1159
1160 static int pohmelfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
1161 {
1162         struct inode *inode = dentry->d_inode;
1163 #if 0
1164         struct pohmelfs_inode *pi = POHMELFS_I(inode);
1165         int err;
1166
1167         err = pohmelfs_data_lock(pi, 0, ~0, POHMELFS_READ_LOCK);
1168         if (err)
1169                 return err;
1170         dprintk("%s: ino: %llu, mode: %o, uid: %u, gid: %u, size: %llu.\n",
1171                         __func__, pi->ino, inode->i_mode, inode->i_uid,
1172                         inode->i_gid, inode->i_size);
1173 #endif
1174
1175         generic_fillattr(inode, stat);
1176         return 0;
1177 }
1178
1179 const struct inode_operations pohmelfs_file_inode_operations = {
1180         .setattr        = pohmelfs_setattr,
1181         .getattr        = pohmelfs_getattr,
1182         .setxattr       = pohmelfs_setxattr,
1183         .getxattr       = pohmelfs_getxattr,
1184 };
1185
1186 /*
1187  * Fill inode data: mode, size, operation callbacks and so on...
1188  */
1189 void pohmelfs_fill_inode(struct inode *inode, struct netfs_inode_info *info)
1190 {
1191         inode->i_mode = info->mode;
1192         inode->i_nlink = info->nlink;
1193         inode->i_uid = info->uid;
1194         inode->i_gid = info->gid;
1195         inode->i_blocks = info->blocks;
1196         inode->i_rdev = info->rdev;
1197         inode->i_size = info->size;
1198         inode->i_version = info->version;
1199         inode->i_blkbits = ffs(info->blocksize);
1200
1201         dprintk("%s: inode: %p, num: %lu/%llu inode is regular: %d, dir: %d, link: %d, mode: %o, size: %llu.\n",
1202                         __func__, inode, inode->i_ino, info->ino,
1203                         S_ISREG(inode->i_mode), S_ISDIR(inode->i_mode),
1204                         S_ISLNK(inode->i_mode), inode->i_mode, inode->i_size);
1205
1206         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME_SEC;
1207
1208         /*
1209          * i_mapping is a pointer to i_data during inode initialization.
1210          */
1211         inode->i_data.a_ops = &pohmelfs_aops;
1212
1213         if (S_ISREG(inode->i_mode)) {
1214                 inode->i_fop = &pohmelfs_file_ops;
1215                 inode->i_op = &pohmelfs_file_inode_operations;
1216         } else if (S_ISDIR(inode->i_mode)) {
1217                 inode->i_fop = &pohmelfs_dir_fops;
1218                 inode->i_op = &pohmelfs_dir_inode_ops;
1219         } else if (S_ISLNK(inode->i_mode)) {
1220                 inode->i_op = &pohmelfs_symlink_inode_operations;
1221                 inode->i_fop = &pohmelfs_file_ops;
1222         } else {
1223                 inode->i_fop = &generic_ro_fops;
1224         }
1225 }
1226
1227 static void pohmelfs_drop_inode(struct inode *inode)
1228 {
1229         struct pohmelfs_sb *psb = POHMELFS_SB(inode->i_sb);
1230         struct pohmelfs_inode *pi = POHMELFS_I(inode);
1231
1232         spin_lock(&psb->ino_lock);
1233         list_del_init(&pi->inode_entry);
1234         spin_unlock(&psb->ino_lock);
1235
1236         generic_drop_inode(inode);
1237 }
1238
1239 static struct pohmelfs_inode *pohmelfs_get_inode_from_list(struct pohmelfs_sb *psb,
1240                 struct list_head *head, unsigned int *count)
1241 {
1242         struct pohmelfs_inode *pi = NULL;
1243
1244         spin_lock(&psb->ino_lock);
1245         if (!list_empty(head)) {
1246                 pi = list_entry(head->next, struct pohmelfs_inode,
1247                                         inode_entry);
1248                 list_del_init(&pi->inode_entry);
1249                 *count = pi->drop_count;
1250                 pi->drop_count = 0;
1251         }
1252         spin_unlock(&psb->ino_lock);
1253
1254         return pi;
1255 }
1256
1257 static void pohmelfs_flush_transactions(struct pohmelfs_sb *psb)
1258 {
1259         struct pohmelfs_config *c;
1260
1261         mutex_lock(&psb->state_lock);
1262         list_for_each_entry(c, &psb->state_list, config_entry) {
1263                 pohmelfs_state_flush_transactions(&c->state);
1264         }
1265         mutex_unlock(&psb->state_lock);
1266 }
1267
1268 /*
1269  * ->put_super() callback. Invoked before superblock is destroyed,
1270  *  so it has to clean all private data.
1271  */
1272 static void pohmelfs_put_super(struct super_block *sb)
1273 {
1274         struct pohmelfs_sb *psb = POHMELFS_SB(sb);
1275         struct pohmelfs_inode *pi;
1276         unsigned int count;
1277         unsigned int in_drop_list = 0;
1278         struct inode *inode, *tmp;
1279
1280         dprintk("%s.\n", __func__);
1281
1282         /*
1283          * Kill pending transactions, which could affect inodes in-flight.
1284          */
1285         pohmelfs_flush_transactions(psb);
1286
1287         while ((pi = pohmelfs_get_inode_from_list(psb, &psb->drop_list, &count))) {
1288                 inode = &pi->vfs_inode;
1289
1290                 dprintk("%s: ino: %llu, pi: %p, inode: %p, count: %u.\n",
1291                                 __func__, pi->ino, pi, inode, count);
1292
1293                 if (atomic_read(&inode->i_count) != count) {
1294                         printk("%s: ino: %llu, pi: %p, inode: %p, count: %u, i_count: %d.\n",
1295                                         __func__, pi->ino, pi, inode, count,
1296                                         atomic_read(&inode->i_count));
1297                         count = atomic_read(&inode->i_count);
1298                         in_drop_list++;
1299                 }
1300
1301                 while (count--)
1302                         iput(&pi->vfs_inode);
1303         }
1304
1305         list_for_each_entry_safe(inode, tmp, &sb->s_inodes, i_sb_list) {
1306                 pi = POHMELFS_I(inode);
1307
1308                 dprintk("%s: ino: %llu, pi: %p, inode: %p, i_count: %u.\n",
1309                                 __func__, pi->ino, pi, inode, atomic_read(&inode->i_count));
1310
1311                 /*
1312                  * These are special inodes, they were created during
1313                  * directory reading or lookup, and were not bound to dentry,
1314                  * so they live here with reference counter being 1 and prevent
1315                  * umount from succeed since it believes that they are busy.
1316                  */
1317                 count = atomic_read(&inode->i_count);
1318                 if (count) {
1319                         list_del_init(&inode->i_sb_list);
1320                         while (count--)
1321                                 iput(&pi->vfs_inode);
1322                 }
1323         }
1324
1325         psb->trans_scan_timeout = psb->drop_scan_timeout = 0;
1326         cancel_rearming_delayed_work(&psb->dwork);
1327         cancel_rearming_delayed_work(&psb->drop_dwork);
1328         flush_scheduled_work();
1329
1330         dprintk("%s: stopped workqueues.\n", __func__);
1331
1332         pohmelfs_crypto_exit(psb);
1333         pohmelfs_state_exit(psb);
1334
1335         bdi_destroy(&psb->bdi);
1336
1337         kfree(psb);
1338         sb->s_fs_info = NULL;
1339 }
1340
1341 static int pohmelfs_statfs(struct dentry *dentry, struct kstatfs *buf)
1342 {
1343         struct super_block *sb = dentry->d_sb;
1344         struct pohmelfs_sb *psb = POHMELFS_SB(sb);
1345
1346         /*
1347          * There are no filesystem size limits yet.
1348          */
1349         memset(buf, 0, sizeof(struct kstatfs));
1350
1351         buf->f_type = POHMELFS_MAGIC_NUM; /* 'POH.' */
1352         buf->f_bsize = sb->s_blocksize;
1353         buf->f_files = psb->ino;
1354         buf->f_namelen = 255;
1355         buf->f_files = atomic_long_read(&psb->total_inodes);
1356         buf->f_bfree = buf->f_bavail = psb->avail_size >> PAGE_SHIFT;
1357         buf->f_blocks = psb->total_size >> PAGE_SHIFT;
1358
1359         dprintk("%s: total: %llu, avail: %llu, inodes: %llu, bsize: %lu.\n",
1360                 __func__, psb->total_size, psb->avail_size, buf->f_files, sb->s_blocksize);
1361
1362         return 0;
1363 }
1364
1365 static int pohmelfs_show_options(struct seq_file *seq, struct vfsmount *vfs)
1366 {
1367         struct pohmelfs_sb *psb = POHMELFS_SB(vfs->mnt_sb);
1368
1369         seq_printf(seq, ",idx=%u", psb->idx);
1370         seq_printf(seq, ",trans_scan_timeout=%u", jiffies_to_msecs(psb->trans_scan_timeout));
1371         seq_printf(seq, ",drop_scan_timeout=%u", jiffies_to_msecs(psb->drop_scan_timeout));
1372         seq_printf(seq, ",wait_on_page_timeout=%u", jiffies_to_msecs(psb->wait_on_page_timeout));
1373         seq_printf(seq, ",trans_retries=%u", psb->trans_retries);
1374         seq_printf(seq, ",crypto_thread_num=%u", psb->crypto_thread_num);
1375         seq_printf(seq, ",trans_max_pages=%u", psb->trans_max_pages);
1376         seq_printf(seq, ",mcache_timeout=%u", jiffies_to_msecs(psb->mcache_timeout));
1377         if (psb->crypto_fail_unsupported)
1378                 seq_printf(seq, ",crypto_fail_unsupported");
1379
1380         return 0;
1381 }
1382
1383 enum {
1384         pohmelfs_opt_idx,
1385         pohmelfs_opt_crypto_thread_num,
1386         pohmelfs_opt_trans_max_pages,
1387         pohmelfs_opt_crypto_fail_unsupported,
1388
1389         /* Remountable options */
1390         pohmelfs_opt_trans_scan_timeout,
1391         pohmelfs_opt_drop_scan_timeout,
1392         pohmelfs_opt_wait_on_page_timeout,
1393         pohmelfs_opt_trans_retries,
1394         pohmelfs_opt_mcache_timeout,
1395 };
1396
1397 static struct match_token pohmelfs_tokens[] = {
1398         {pohmelfs_opt_idx, "idx=%u"},
1399         {pohmelfs_opt_crypto_thread_num, "crypto_thread_num=%u"},
1400         {pohmelfs_opt_trans_max_pages, "trans_max_pages=%u"},
1401         {pohmelfs_opt_crypto_fail_unsupported, "crypto_fail_unsupported"},
1402         {pohmelfs_opt_trans_scan_timeout, "trans_scan_timeout=%u"},
1403         {pohmelfs_opt_drop_scan_timeout, "drop_scan_timeout=%u"},
1404         {pohmelfs_opt_wait_on_page_timeout, "wait_on_page_timeout=%u"},
1405         {pohmelfs_opt_trans_retries, "trans_retries=%u"},
1406         {pohmelfs_opt_mcache_timeout, "mcache_timeout=%u"},
1407 };
1408
1409 static int pohmelfs_parse_options(char *options, struct pohmelfs_sb *psb, int remount)
1410 {
1411         char *p;
1412         substring_t args[MAX_OPT_ARGS];
1413         int option, err;
1414
1415         if (!options)
1416                 return 0;
1417
1418         while ((p = strsep(&options, ",")) != NULL) {
1419                 int token;
1420                 if (!*p)
1421                         continue;
1422
1423                 token = match_token(p, pohmelfs_tokens, args);
1424
1425                 err = match_int(&args[0], &option);
1426                 if (err)
1427                         return err;
1428
1429                 if (remount && token <= pohmelfs_opt_crypto_fail_unsupported)
1430                         continue;
1431
1432                 switch (token) {
1433                         case pohmelfs_opt_idx:
1434                                 psb->idx = option;
1435                                 break;
1436                         case pohmelfs_opt_trans_scan_timeout:
1437                                 psb->trans_scan_timeout = msecs_to_jiffies(option);
1438                                 break;
1439                         case pohmelfs_opt_drop_scan_timeout:
1440                                 psb->drop_scan_timeout = msecs_to_jiffies(option);
1441                                 break;
1442                         case pohmelfs_opt_wait_on_page_timeout:
1443                                 psb->wait_on_page_timeout = msecs_to_jiffies(option);
1444                                 break;
1445                         case pohmelfs_opt_mcache_timeout:
1446                                 psb->mcache_timeout = msecs_to_jiffies(option);
1447                                 break;
1448                         case pohmelfs_opt_trans_retries:
1449                                 psb->trans_retries = option;
1450                                 break;
1451                         case pohmelfs_opt_crypto_thread_num:
1452                                 psb->crypto_thread_num = option;
1453                                 break;
1454                         case pohmelfs_opt_trans_max_pages:
1455                                 psb->trans_max_pages = option;
1456                                 break;
1457                         case pohmelfs_opt_crypto_fail_unsupported:
1458                                 psb->crypto_fail_unsupported = 1;
1459                                 break;
1460                         default:
1461                                 return -EINVAL;
1462                 }
1463         }
1464
1465         return 0;
1466 }
1467
1468 static int pohmelfs_remount(struct super_block *sb, int *flags, char *data)
1469 {
1470         int err;
1471         struct pohmelfs_sb *psb = POHMELFS_SB(sb);
1472         unsigned long old_sb_flags = sb->s_flags;
1473
1474         err = pohmelfs_parse_options(data, psb, 1);
1475         if (err)
1476                 goto err_out_restore;
1477
1478         if (!(*flags & MS_RDONLY))
1479                 sb->s_flags &= ~MS_RDONLY;
1480         return 0;
1481
1482 err_out_restore:
1483         sb->s_flags = old_sb_flags;
1484         return err;
1485 }
1486
1487 static void pohmelfs_flush_inode(struct pohmelfs_inode *pi, unsigned int count)
1488 {
1489         struct inode *inode = &pi->vfs_inode;
1490
1491         dprintk("%s: %p: ino: %llu, owned: %d.\n",
1492                 __func__, inode, pi->ino, test_bit(NETFS_INODE_OWNED, &pi->state));
1493
1494         mutex_lock(&inode->i_mutex);
1495         if (test_and_clear_bit(NETFS_INODE_OWNED, &pi->state)) {
1496                 filemap_fdatawrite(inode->i_mapping);
1497                 inode->i_sb->s_op->write_inode(inode, 0);
1498         }
1499
1500 #ifdef POHMELFS_TRUNCATE_ON_INODE_FLUSH
1501         truncate_inode_pages(inode->i_mapping, 0);
1502 #endif
1503
1504         pohmelfs_data_unlock(pi, 0, ~0, POHMELFS_WRITE_LOCK);
1505         mutex_unlock(&inode->i_mutex);
1506 }
1507
1508 static void pohmelfs_put_inode_count(struct pohmelfs_inode *pi, unsigned int count)
1509 {
1510         dprintk("%s: ino: %llu, pi: %p, inode: %p, count: %u.\n",
1511                         __func__, pi->ino, pi, &pi->vfs_inode, count);
1512
1513         if (test_and_clear_bit(NETFS_INODE_NEED_FLUSH, &pi->state))
1514                 pohmelfs_flush_inode(pi, count);
1515
1516         while (count--)
1517                 iput(&pi->vfs_inode);
1518 }
1519
1520 static void pohmelfs_drop_scan(struct work_struct *work)
1521 {
1522         struct pohmelfs_sb *psb =
1523                 container_of(work, struct pohmelfs_sb, drop_dwork.work);
1524         struct pohmelfs_inode *pi;
1525         unsigned int count = 0;
1526
1527         while ((pi = pohmelfs_get_inode_from_list(psb, &psb->drop_list, &count)))
1528                 pohmelfs_put_inode_count(pi, count);
1529
1530         pohmelfs_check_states(psb);
1531
1532         if (psb->drop_scan_timeout)
1533                 schedule_delayed_work(&psb->drop_dwork, psb->drop_scan_timeout);
1534 }
1535
1536 /*
1537  * Run through all transactions starting from the oldest,
1538  * drop transaction from current state and try to send it
1539  * to all remote nodes, which are currently installed.
1540  */
1541 static void pohmelfs_trans_scan_state(struct netfs_state *st)
1542 {
1543         struct rb_node *rb_node;
1544         struct netfs_trans_dst *dst;
1545         struct pohmelfs_sb *psb = st->psb;
1546         unsigned int timeout = psb->trans_scan_timeout;
1547         struct netfs_trans *t;
1548         int err;
1549
1550         mutex_lock(&st->trans_lock);
1551         for (rb_node = rb_first(&st->trans_root); rb_node; ) {
1552                 dst = rb_entry(rb_node, struct netfs_trans_dst, state_entry);
1553                 t = dst->trans;
1554
1555                 if (timeout && time_after(dst->send_time + timeout, jiffies)
1556                                 && dst->retries == 0)
1557                         break;
1558
1559                 dprintk("%s: t: %p, gen: %u, st: %p, retries: %u, max: %u.\n",
1560                         __func__, t, t->gen, st, dst->retries, psb->trans_retries);
1561                 netfs_trans_get(t);
1562
1563                 rb_node = rb_next(rb_node);
1564
1565                 err = -ETIMEDOUT;
1566                 if (timeout && (++dst->retries < psb->trans_retries))
1567                         err = netfs_trans_resend(t, psb);
1568
1569                 if (err || (t->flags & NETFS_TRANS_SINGLE_DST)) {
1570                         if (netfs_trans_remove_nolock(dst, st))
1571                                 netfs_trans_drop_dst_nostate(dst);
1572                 }
1573
1574                 t->result = err;
1575                 netfs_trans_put(t);
1576         }
1577         mutex_unlock(&st->trans_lock);
1578 }
1579
1580 /*
1581  * Walk through all installed network states and resend all
1582  * transactions, which are old enough.
1583  */
1584 static void pohmelfs_trans_scan(struct work_struct *work)
1585 {
1586         struct pohmelfs_sb *psb =
1587                 container_of(work, struct pohmelfs_sb, dwork.work);
1588         struct netfs_state *st;
1589         struct pohmelfs_config *c;
1590
1591         mutex_lock(&psb->state_lock);
1592         list_for_each_entry(c, &psb->state_list, config_entry) {
1593                 st = &c->state;
1594
1595                 pohmelfs_trans_scan_state(st);
1596         }
1597         mutex_unlock(&psb->state_lock);
1598
1599         /*
1600          * If no timeout specified then system is in the middle of umount process,
1601          * so no need to reschedule scanning process again.
1602          */
1603         if (psb->trans_scan_timeout)
1604                 schedule_delayed_work(&psb->dwork, psb->trans_scan_timeout);
1605 }
1606
1607 int pohmelfs_meta_command_data(struct pohmelfs_inode *pi, u64 id, unsigned int cmd_op, char *addon,
1608                 unsigned int flags, netfs_trans_complete_t complete, void *priv, u64 start)
1609 {
1610         struct inode *inode = &pi->vfs_inode;
1611         struct pohmelfs_sb *psb = POHMELFS_SB(inode->i_sb);
1612         int err = 0, sz;
1613         struct netfs_trans *t;
1614         int path_len, addon_len = 0;
1615         void *data;
1616         struct netfs_inode_info *info;
1617         struct netfs_cmd *cmd;
1618
1619         dprintk("%s: ino: %llu, cmd: %u, addon: %p.\n", __func__, pi->ino, cmd_op, addon);
1620
1621         path_len = pohmelfs_path_length(pi);
1622         if (path_len < 0) {
1623                 err = path_len;
1624                 goto err_out_exit;
1625         }
1626
1627         if (addon)
1628                 addon_len = strlen(addon) + 1; /* 0-byte */
1629         sz = addon_len;
1630
1631         if (cmd_op == NETFS_INODE_INFO)
1632                 sz += sizeof(struct netfs_inode_info);
1633
1634         t = netfs_trans_alloc(psb, sz + path_len, flags, 0);
1635         if (!t) {
1636                 err = -ENOMEM;
1637                 goto err_out_exit;
1638         }
1639         t->complete = complete;
1640         t->private = priv;
1641
1642         cmd = netfs_trans_current(t);
1643         data = (void *)(cmd + 1);
1644
1645         if (cmd_op == NETFS_INODE_INFO) {
1646                 info = (struct netfs_inode_info *)(cmd + 1);
1647                 data = (void *)(info + 1);
1648
1649                 /*
1650                  * We are under i_mutex, can read and change whatever we want...
1651                  */
1652                 info->mode = inode->i_mode;
1653                 info->nlink = inode->i_nlink;
1654                 info->uid = inode->i_uid;
1655                 info->gid = inode->i_gid;
1656                 info->blocks = inode->i_blocks;
1657                 info->rdev = inode->i_rdev;
1658                 info->size = inode->i_size;
1659                 info->version = inode->i_version;
1660
1661                 netfs_convert_inode_info(info);
1662         }
1663
1664         path_len = pohmelfs_construct_path_string(pi, data, path_len);
1665         if (path_len < 0)
1666                 goto err_out_free;
1667
1668         dprintk("%s: path_len: %d.\n", __func__, path_len);
1669
1670         if (addon) {
1671                 path_len--; /* Do not place null-byte before the addon */
1672                 path_len += sprintf(data + path_len, "/%s", addon) + 1; /* 0 - byte */
1673         }
1674
1675         sz += path_len;
1676
1677         cmd->cmd = cmd_op;
1678         cmd->ext = path_len;
1679         cmd->size = sz;
1680         cmd->id = id;
1681         cmd->start = start;
1682
1683         netfs_convert_cmd(cmd);
1684         netfs_trans_update(cmd, t, sz);
1685
1686         /*
1687          * Note, that it is possible to leak error here: transaction callback will not
1688          * be invoked for allocation path failure.
1689          */
1690         return netfs_trans_finish(t, psb);
1691
1692 err_out_free:
1693         netfs_trans_free(t);
1694 err_out_exit:
1695         if (complete)
1696                 complete(NULL, 0, priv, err);
1697         return err;
1698 }
1699
1700 int pohmelfs_meta_command(struct pohmelfs_inode *pi, unsigned int cmd_op, unsigned int flags,
1701                 netfs_trans_complete_t complete, void *priv, u64 start)
1702 {
1703         return pohmelfs_meta_command_data(pi, pi->ino, cmd_op, NULL, flags, complete, priv, start);
1704 }
1705
1706 /*
1707  * Send request and wait for POHMELFS root capabilities response,
1708  * which will update server's informaion about size of the export,
1709  * permissions, number of objects, available size and so on.
1710  */
1711 static int pohmelfs_root_handshake(struct pohmelfs_sb *psb)
1712 {
1713         struct netfs_trans *t;
1714         struct netfs_cmd *cmd;
1715         int err = -ENOMEM;
1716
1717         t = netfs_trans_alloc(psb, 0, 0, 0);
1718         if (!t)
1719                 goto err_out_exit;
1720
1721         cmd = netfs_trans_current(t);
1722
1723         cmd->cmd = NETFS_CAPABILITIES;
1724         cmd->id = POHMELFS_ROOT_CAPABILITIES;
1725         cmd->size = 0;
1726         cmd->start = 0;
1727         cmd->ext = 0;
1728         cmd->csize = 0;
1729
1730         netfs_convert_cmd(cmd);
1731         netfs_trans_update(cmd, t, 0);
1732
1733         err = netfs_trans_finish(t, psb);
1734         if (err)
1735                 goto err_out_exit;
1736
1737         psb->flags = ~0;
1738         err = wait_event_interruptible_timeout(psb->wait,
1739                         (psb->flags != ~0),
1740                         psb->wait_on_page_timeout);
1741         if (!err)
1742                 err = -ETIMEDOUT;
1743         else if (err > 0)
1744                 err = -psb->flags;
1745
1746         if (err)
1747                 goto err_out_exit;
1748
1749         return 0;
1750
1751 err_out_exit:
1752         return err;
1753 }
1754
1755 static int pohmelfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
1756 {
1757         struct netfs_state *st;
1758         struct pohmelfs_ctl *ctl;
1759         struct pohmelfs_sb *psb = POHMELFS_SB(mnt->mnt_sb);
1760         struct pohmelfs_config *c;
1761
1762         mutex_lock(&psb->state_lock);
1763
1764         seq_printf(m, "\nidx addr(:port) socket_type protocol active priority permissions\n");
1765
1766         list_for_each_entry(c, &psb->state_list, config_entry) {
1767                 st = &c->state;
1768                 ctl = &st->ctl;
1769
1770                 seq_printf(m, "%u ", ctl->idx);
1771                 if (ctl->addr.sa_family == AF_INET) {
1772                         struct sockaddr_in *sin = (struct sockaddr_in *)&st->ctl.addr;
1773                         seq_printf(m, "%pI4:%u", &sin->sin_addr.s_addr, ntohs(sin->sin_port));
1774                 } else if (ctl->addr.sa_family == AF_INET6) {
1775                         struct sockaddr_in6 *sin = (struct sockaddr_in6 *)&st->ctl.addr;
1776                         seq_printf(m, "%pi6:%u", &sin->sin6_addr, ntohs(sin->sin6_port));
1777                 } else {
1778                         unsigned int i;
1779                         for (i=0; i<ctl->addrlen; ++i)
1780                                 seq_printf(m, "%02x.", ctl->addr.addr[i]);
1781                 }
1782
1783                 seq_printf(m, " %u %u %d %u %x\n",
1784                                 ctl->type, ctl->proto,
1785                                 st->socket != NULL,
1786                                 ctl->prio, ctl->perm);
1787         }
1788         mutex_unlock(&psb->state_lock);
1789
1790         return 0;
1791 }
1792
1793 static const struct super_operations pohmelfs_sb_ops = {
1794         .alloc_inode    = pohmelfs_alloc_inode,
1795         .destroy_inode  = pohmelfs_destroy_inode,
1796         .drop_inode     = pohmelfs_drop_inode,
1797         .write_inode    = pohmelfs_write_inode,
1798         .put_super      = pohmelfs_put_super,
1799         .remount_fs     = pohmelfs_remount,
1800         .statfs         = pohmelfs_statfs,
1801         .show_options   = pohmelfs_show_options,
1802         .show_stats     = pohmelfs_show_stats,
1803 };
1804
1805 /*
1806  * Allocate private superblock and create root dir.
1807  */
1808 static int pohmelfs_fill_super(struct super_block *sb, void *data, int silent)
1809 {
1810         struct pohmelfs_sb *psb;
1811         int err = -ENOMEM;
1812         struct inode *root;
1813         struct pohmelfs_inode *npi;
1814         struct qstr str;
1815
1816         psb = kzalloc(sizeof(struct pohmelfs_sb), GFP_KERNEL);
1817         if (!psb)
1818                 goto err_out_exit;
1819
1820         err = bdi_init(&psb->bdi);
1821         if (err)
1822                 goto err_out_free_sb;
1823
1824         err = bdi_register(&psb->bdi, NULL, "pfs-%d", atomic_inc_return(&psb_bdi_num));
1825         if (err) {
1826                 bdi_destroy(&psb->bdi);
1827                 goto err_out_free_sb;
1828         }
1829
1830         sb->s_fs_info = psb;
1831         sb->s_op = &pohmelfs_sb_ops;
1832         sb->s_magic = POHMELFS_MAGIC_NUM;
1833         sb->s_maxbytes = MAX_LFS_FILESIZE;
1834         sb->s_blocksize = PAGE_SIZE;
1835         sb->s_bdi = &psb->bdi;
1836
1837         psb->sb = sb;
1838
1839         psb->ino = 2;
1840         psb->idx = 0;
1841         psb->active_state = NULL;
1842         psb->trans_retries = 5;
1843         psb->trans_data_size = PAGE_SIZE;
1844         psb->drop_scan_timeout = msecs_to_jiffies(1000);
1845         psb->trans_scan_timeout = msecs_to_jiffies(5000);
1846         psb->wait_on_page_timeout = msecs_to_jiffies(5000);
1847         init_waitqueue_head(&psb->wait);
1848
1849         spin_lock_init(&psb->ino_lock);
1850
1851         INIT_LIST_HEAD(&psb->drop_list);
1852
1853         mutex_init(&psb->mcache_lock);
1854         psb->mcache_root = RB_ROOT;
1855         psb->mcache_timeout = msecs_to_jiffies(5000);
1856         atomic_long_set(&psb->mcache_gen, 0);
1857
1858         psb->trans_max_pages = 100;
1859
1860         psb->crypto_align_size = 16;
1861         psb->crypto_attached_size = 0;
1862         psb->hash_strlen = 0;
1863         psb->cipher_strlen = 0;
1864         psb->perform_crypto = 0;
1865         psb->crypto_thread_num = 2;
1866         psb->crypto_fail_unsupported = 0;
1867         mutex_init(&psb->crypto_thread_lock);
1868         INIT_LIST_HEAD(&psb->crypto_ready_list);
1869         INIT_LIST_HEAD(&psb->crypto_active_list);
1870
1871         atomic_set(&psb->trans_gen, 1);
1872         atomic_long_set(&psb->total_inodes, 0);
1873
1874         mutex_init(&psb->state_lock);
1875         INIT_LIST_HEAD(&psb->state_list);
1876
1877         err = pohmelfs_parse_options((char *) data, psb, 0);
1878         if (err)
1879                 goto err_out_free_bdi;
1880
1881         err = pohmelfs_copy_crypto(psb);
1882         if (err)
1883                 goto err_out_free_bdi;
1884
1885         err = pohmelfs_state_init(psb);
1886         if (err)
1887                 goto err_out_free_strings;
1888
1889         err = pohmelfs_crypto_init(psb);
1890         if (err)
1891                 goto err_out_state_exit;
1892
1893         err = pohmelfs_root_handshake(psb);
1894         if (err)
1895                 goto err_out_crypto_exit;
1896
1897         str.name = "/";
1898         str.hash = jhash("/", 1, 0);
1899         str.len = 1;
1900
1901         npi = pohmelfs_create_entry_local(psb, NULL, &str, 0, 0755|S_IFDIR);
1902         if (IS_ERR(npi)) {
1903                 err = PTR_ERR(npi);
1904                 goto err_out_crypto_exit;
1905         }
1906         set_bit(NETFS_INODE_REMOTE_SYNCED, &npi->state);
1907         clear_bit(NETFS_INODE_OWNED, &npi->state);
1908
1909         root = &npi->vfs_inode;
1910
1911         sb->s_root = d_alloc_root(root);
1912         if (!sb->s_root)
1913                 goto err_out_put_root;
1914
1915         INIT_DELAYED_WORK(&psb->drop_dwork, pohmelfs_drop_scan);
1916         schedule_delayed_work(&psb->drop_dwork, psb->drop_scan_timeout);
1917
1918         INIT_DELAYED_WORK(&psb->dwork, pohmelfs_trans_scan);
1919         schedule_delayed_work(&psb->dwork, psb->trans_scan_timeout);
1920
1921         return 0;
1922
1923 err_out_put_root:
1924         iput(root);
1925 err_out_crypto_exit:
1926         pohmelfs_crypto_exit(psb);
1927 err_out_state_exit:
1928         pohmelfs_state_exit(psb);
1929 err_out_free_strings:
1930         kfree(psb->cipher_string);
1931         kfree(psb->hash_string);
1932 err_out_free_bdi:
1933         bdi_destroy(&psb->bdi);
1934 err_out_free_sb:
1935         kfree(psb);
1936 err_out_exit:
1937
1938         dprintk("%s: err: %d.\n", __func__, err);
1939         return err;
1940 }
1941
1942 /*
1943  * Some VFS magic here...
1944  */
1945 static int pohmelfs_get_sb(struct file_system_type *fs_type,
1946         int flags, const char *dev_name, void *data, struct vfsmount *mnt)
1947 {
1948         return get_sb_nodev(fs_type, flags, data, pohmelfs_fill_super,
1949                                 mnt);
1950 }
1951
1952 /*
1953  * We need this to sync all inodes earlier, since when writeback
1954  * is invoked from the umount/mntput path dcache is already shrunk,
1955  * see generic_shutdown_super(), and no inodes can access the path.
1956  */
1957 static void pohmelfs_kill_super(struct super_block *sb)
1958 {
1959         sync_inodes_sb(sb);
1960         kill_anon_super(sb);
1961 }
1962
1963 static struct file_system_type pohmel_fs_type = {
1964         .owner          = THIS_MODULE,
1965         .name           = "pohmel",
1966         .get_sb         = pohmelfs_get_sb,
1967         .kill_sb        = pohmelfs_kill_super,
1968 };
1969
1970 /*
1971  * Cache and module initializations and freeing routings.
1972  */
1973 static void pohmelfs_init_once(void *data)
1974 {
1975         struct pohmelfs_inode *pi = data;
1976
1977         inode_init_once(&pi->vfs_inode);
1978 }
1979
1980 static int __init pohmelfs_init_inodecache(void)
1981 {
1982         pohmelfs_inode_cache = kmem_cache_create("pohmelfs_inode_cache",
1983                                 sizeof(struct pohmelfs_inode),
1984                                 0, (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
1985                                 pohmelfs_init_once);
1986         if (!pohmelfs_inode_cache)
1987                 return -ENOMEM;
1988
1989         return 0;
1990 }
1991
1992 static void pohmelfs_destroy_inodecache(void)
1993 {
1994         kmem_cache_destroy(pohmelfs_inode_cache);
1995 }
1996
1997 static int __init init_pohmel_fs(void)
1998 {
1999         int err;
2000
2001         err = pohmelfs_config_init();
2002         if (err)
2003                 goto err_out_exit;
2004
2005         err = pohmelfs_init_inodecache();
2006         if (err)
2007                 goto err_out_config_exit;
2008
2009         err = pohmelfs_mcache_init();
2010         if (err)
2011                 goto err_out_destroy;
2012
2013         err = netfs_trans_init();
2014         if (err)
2015                 goto err_out_mcache_exit;
2016
2017         err = register_filesystem(&pohmel_fs_type);
2018         if (err)
2019                 goto err_out_trans;
2020
2021         return 0;
2022
2023 err_out_trans:
2024         netfs_trans_exit();
2025 err_out_mcache_exit:
2026         pohmelfs_mcache_exit();
2027 err_out_destroy:
2028         pohmelfs_destroy_inodecache();
2029 err_out_config_exit:
2030         pohmelfs_config_exit();
2031 err_out_exit:
2032         return err;
2033 }
2034
2035 static void __exit exit_pohmel_fs(void)
2036 {
2037         unregister_filesystem(&pohmel_fs_type);
2038         pohmelfs_destroy_inodecache();
2039         pohmelfs_mcache_exit();
2040         pohmelfs_config_exit();
2041         netfs_trans_exit();
2042 }
2043
2044 module_init(init_pohmel_fs);
2045 module_exit(exit_pohmel_fs);
2046
2047 MODULE_LICENSE("GPL");
2048 MODULE_AUTHOR("Evgeniy Polyakov <zbr@ioremap.net>");
2049 MODULE_DESCRIPTION("Pohmel filesystem");