-
Notifications
You must be signed in to change notification settings - Fork 18
/
zus-vfs.c
794 lines (645 loc) · 18 KB
/
zus-vfs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
/* SPDX-License-Identifier: BSD-3-Clause */
/*
* zus-vfs.c - Abstract FS interface that calls into the um-FS
*
* Copyright (c) 2018 NetApp, Inc. All rights reserved.
*
* See module.c for LICENSE details.
*
* Authors:
* Boaz Harrosh <[email protected]>
*/
#define _GNU_SOURCE
#include <errno.h>
#include <unistd.h>
#include <sys/mman.h>
#include "zus.h"
#include "zuf_call.h"
#include "iom_enc.h"
/* ~~~ mount stuff ~~~ */
/* TODO: Perhaps an md_shadow_size(md) */
static ulong _pmem_map_size(struct multi_devices *md)
{
size_t size = md_p2o(md_t1_blocks(md));\
if (unlikely(md->pmem_info.mdt.s_flags & MDT_F_SHADOW))
size += size;
return size;
}
static int _pmem_mmap(struct multi_devices *md)
{
size_t size = _pmem_map_size(md);
int prot = PROT_WRITE | PROT_READ;
int flags = MAP_SHARED;
int err;
md->p_pmem_addr = mmap(NULL, size, prot, flags, md->fd, 0);
if (md->p_pmem_addr == MAP_FAILED) {
ERROR("mmap failed=> %d: %s\n", errno, strerror(errno));
return -(errno ?: ENOMEM);
}
err = madvise(md->p_pmem_addr, size, MADV_DONTDUMP);
if (err == -1)
ERROR("pmem madvise(DONTDUMP) failed=> %d: %s\n", errno,
strerror(errno));
return 0;
}
static int _pmem_unmap(struct multi_devices *md)
{
size_t size = _pmem_map_size(md);
int err;
err = munmap(md->p_pmem_addr, size);
if (err == -1) {
ERROR("munmap failed=> %d: %s\n", errno, strerror(errno));
return -errno;
}
return 0;
}
static inline size_t _zpages_mmap_size(struct multi_devices *md)
{
/* We must map 2M aligned size so zuf will give us a 2M aligned
* vm pointer. Some FSs bug if this is not so.
*/
return ALIGN(md_t1_blocks(md) * sizeof(struct zus_page), ZUFS_2M_SIZE);
}
static int _zpages_mmap(struct multi_devices *md)
{
size_t size = _zpages_mmap_size(md);
size_t pmem_size = _pmem_map_size(md);
int prot = PROT_WRITE | PROT_READ;
int flags = MAP_SHARED;
md->pages = mmap(NULL, size, prot, flags, md->fd,
pmem_size + ZUFS_2M_SIZE);
if (md->pages == MAP_FAILED) {
ERROR("mmap failed=> %d: %s\n", errno, strerror(errno));
md->pages = NULL;
return -(errno ?: ENOMEM);
}
/* NOTE: It is nice to have the pages state in the mem-dump */
return 0;
}
static int _zpages_unmap(struct multi_devices *md)
{
size_t size = _zpages_mmap_size(md);
int err;
if (unlikely(!md->pages))
return 0;
err = munmap(md->pages, size);
if (err == -1) {
ERROR("munmap failed=> %d: %s\n", errno, strerror(errno));
return -errno;
}
return 0;
}
static int _pmem_grab(struct zus_sb_info *sbi, __u64 sb_id)
{
struct multi_devices *md = &sbi->md;
int err;
md->sbi = sbi;
err = zuf_root_open_tmp(&md->fd);
if (unlikely(err))
return err;
err = zuf_grab_pmem(md->fd, sb_id, &md->pmem_info);
if (unlikely(err))
return err;
err = _pmem_mmap(md);
if (unlikely(err))
return err;
err = md_init_from_pmem_info(md);
if (unlikely(err)) {
ERROR("md_init_from_pmem_info sb_id=%llu => %d\n", sb_id, err);
return err;
}
md->dev_index = md->pmem_info.dev_index;
md->user_page_size = sbi->zfi->user_page_size;
if (!md->user_page_size)
return 0; /* User does not want pages */
if (ZUS_WARN_ON(md->user_page_size != sizeof(struct zus_page)))
return EINVAL;
err = _zpages_mmap(md);
return err;
}
static void _pmem_ungrab(struct zus_sb_info *sbi)
{
/* Kernel makes free easy (close couple files) */
_zpages_unmap(&sbi->md);
md_fini(&sbi->md, true);
_pmem_unmap(&sbi->md);
zuf_root_close(&sbi->md.fd);
sbi->md.p_pmem_addr = NULL;
}
static void _zus_sbi_fini(struct zus_sb_info *sbi)
{
// zus_iput(sbi->z_root); was this done already
if (sbi->zfi->op->sbi_fini)
sbi->zfi->op->sbi_fini(sbi);
_pmem_ungrab(sbi);
sbi->zfi->op->sbi_free(sbi);
}
int zus_private_mount(struct zus_fs_info *zfi, const char *options, ulong flags,
struct zufs_ioc_mount_private **zip_out)
{
struct zufs_ioc_mount_private *zip;
struct zus_sb_info *sbi = NULL;
int zip_len;
int err;
zip_len = sizeof(*zip) + strlen(options) + 1;
zip = calloc(1, zip_len);
if (!zip) {
ERROR("failed to allocate memory\n");
return -ENOMEM;
}
zip->zmi.zus_zfi = zfi;
err = zuf_root_open_tmp((int *)&zip->mount_fd);
if (unlikely(err))
goto fail;
err = zus_numa_map_init(zip->mount_fd);
if (unlikely(err))
goto fail_fd;
err = zus_thread_current_init();
if (unlikely(err))
goto fail_fd;
sbi = zfi->op->sbi_alloc(zfi);
if (unlikely(!sbi)) {
err = -ENOMEM;
goto fail_alloc;
}
zip->hdr.in_len = zip_len;
zip->zmi.po.mount_flags = flags;
zip->zmi.po.mount_options_len = strlen(options);
memcpy(&zip->zmi.po.mount_options, options,
zip->zmi.po.mount_options_len);
memcpy(&zip->rfi, &zfi->rfi, sizeof(struct register_fs_info));
err = zuf_private_mount(zip->mount_fd, zip);
if (unlikely(err))
goto fail_mount;
sbi->zfi = zip->zmi.zus_zfi;
sbi->kern_sb_id = zip->zmi.sb_id;
err = _pmem_grab(sbi, zip->zmi.sb_id);
if (unlikely(err))
goto fail_grab;
err = sbi->zfi->op->sbi_init(sbi, &zip->zmi);
if (unlikely(err)) {
zus_sbi_set_flag(sbi, ZUS_SBIF_ERROR);
goto fail_sbi_init;
}
zip->zmi.zus_sbi = sbi;
zip->zmi._zi = pmem_dpp_t(md_addr_to_offset(&sbi->md, sbi->z_root->zi));
zip->zmi.zus_ii = sbi->z_root;
DBG("[%lld] _zi 0x%lx zus_ii=%p\n",
sbi->z_root->zi->i_ino, (ulong)zip->zmi._zi, zip->zmi.zus_ii);
*zip_out = zip;
return 0;
fail_sbi_init:
if (sbi->z_root)
sbi->z_root->op->evict(sbi->z_root);
if (sbi->zfi->op->sbi_fini)
sbi->zfi->op->sbi_fini(sbi);
_pmem_ungrab(sbi);
fail_grab:
zuf_private_umount(zip->mount_fd, zip);
fail_mount:
zfi->op->sbi_free(sbi);
fail_alloc:
zus_thread_current_fini();
fail_fd:
close(zip->mount_fd);
fail:
free(zip);
return err;
}
int zus_private_umount(struct zufs_ioc_mount_private *zip)
{
struct zus_sb_info *sbi = zip->zmi.zus_sbi;
int err = 0;
/* evict root inode (done by VFS on regular mount) */
if (sbi->z_root)
sbi->z_root->op->evict(sbi->z_root);
if (sbi->zfi->op->sbi_fini)
err = sbi->zfi->op->sbi_fini(sbi);
_pmem_ungrab(sbi);
zuf_private_umount(zip->mount_fd, zip);
sbi->zfi->op->sbi_free(sbi);
zus_thread_current_fini();
close(zip->mount_fd);
free(zip);
return err;
}
int zus_mount(int fd, struct zufs_ioc_mount *zim)
{
struct zus_fs_info *zfi = zim->zmi.zus_zfi;
struct zus_sb_info *sbi;
int err;
sbi = zfi->op->sbi_alloc(zfi);
if (unlikely(!sbi)) {
zim->hdr.err = -ENOMEM;
return zim->hdr.err;
}
sbi->zfi = zim->zmi.zus_zfi;
sbi->kern_sb_id = zim->zmi.sb_id;
err = _pmem_grab(sbi, zim->zmi.sb_id);
if (unlikely(err))
goto err;
err = sbi->zfi->op->sbi_init(sbi, &zim->zmi);
if (unlikely(err))
goto err;
zim->zmi.zus_sbi = sbi;
zim->zmi._zi = pmem_dpp_t(md_addr_to_offset(&sbi->md, sbi->z_root->zi));
zim->zmi.zus_ii = sbi->z_root;
DBG("[%lld] _zi 0x%lx zus_ii=%p\n",
sbi->z_root->zi->i_ino, (ulong)zim->zmi._zi, zim->zmi.zus_ii);
return 0;
err:
zus_sbi_set_flag(sbi, ZUS_SBIF_ERROR);
_zus_sbi_fini(sbi);
zim->hdr.err = err;
return err;
}
int zus_umount(int fd, struct zufs_ioc_mount *zim)
{
_zus_sbi_fini(zim->zmi.zus_sbi);
return 0;
}
int zus_remount(int fd, struct zufs_ioc_mount *zim)
{
struct zus_sb_info *sbi = zim->zmi.zus_sbi;
if (sbi->zfi->op->sbi_remount)
return sbi->zfi->op->sbi_remount(sbi, &zim->zmi);
return 0;
}
/* ~~~ FS operations ~~~~ */
struct zus_inode_info *zus_iget(struct zus_sb_info *sbi, ulong ino)
{
struct zus_inode_info *zii;
int err;
err = sbi->op->iget(sbi, ino, &zii);
if (err)
return NULL;
zii->sbi = sbi;
return zii;
}
static int _new_inode(void *app_ptr, struct zufs_ioc_hdr *hdr)
{
struct zufs_ioc_new_inode *ioc_new = (void *)hdr;
struct zus_sb_info *sbi = ioc_new->dir_ii->sbi;
struct zus_inode_info *zii;
int err;
/* In ZUS protocol we start zero ref, add_dentry increments the refs
* (Kernel gave us a 1 here expect for O_TMPFILE)
*/
ioc_new->zi.i_nlink = 0;
err = sbi->op->new_inode(sbi, app_ptr, ioc_new);
if (unlikely(err))
return err;
zii = ioc_new->zus_ii;
ioc_new->_zi = md_addr_to_offset(&sbi->md, zii->zi);
if (ioc_new->flags & ZI_TMPFILE)
return 0;
err = ioc_new->dir_ii->sbi->op->add_dentry(ioc_new->dir_ii, zii,
&ioc_new->str);
if (unlikely(err))
goto _err_free_inode;
return 0;
_err_free_inode:
zii->sbi->op->free_inode(zii);
return err;
}
static int _evict(struct zufs_ioc_hdr *hdr)
{
struct zufs_ioc_evict_inode *ziei = (void *)hdr;
struct zus_inode_info *zii = ziei->zus_ii;
if (unlikely(!zii)) {
ERROR("!ziei->zus_ii\n");
return 0;
}
if (hdr->operation == ZUFS_OP_FREE_INODE) {
if (likely(zii->sbi->op->free_inode))
zii->sbi->op->free_inode(zii);
} else { /* ZUFS_OP_EVICT_INODE */
/* NOTE: On lookup Kernel ask's zus to allocate a new zii &&
* retrieve the zi, before it inserts it to inode cache, it is
* possible to race, and have two threads do a lookup. The
* loosing thread calls _evict(ZI_LOOKUP_RACE) to de-allocate
* the extra zii. But fs->evict need not be called. Only
* zii_free.
* (So it is possible at FS to see two fs->igets but one
* fs->evict)
*/
if (zii->op->evict)
zii->op->evict(zii);
}
return 0;
}
static int _lookup(struct zufs_ioc_hdr *hdr)
{
struct zufs_ioc_lookup *lookup = (void *)hdr;
struct zufs_str *str = &lookup->str;
struct zus_inode_info *zii;
ulong ino;
if (!str->len || !str->name[0]) {
ERROR("lookup NULL string\n");
return 0;
}
if (0 == strncmp(".", str->name, str->len))
ino = lookup->dir_ii->zi->i_ino;
else if (0 == strncmp("..", str->name, str->len))
ino = lookup->dir_ii->zi->i_dir.parent;
else
ino = lookup->dir_ii->sbi->op->lookup(lookup->dir_ii, str);
if (!ino) {
DBG("[%.*s] NOT FOUND\n", lookup->str.len, lookup->str.name);
return -ENOENT;
}
DBG("[%.*s] ino=%ld\n", lookup->str.len, lookup->str.name, ino);
zii = zus_iget(lookup->dir_ii->sbi, ino);
if (unlikely(!zii))
return -ENOENT;
lookup->_zi = md_addr_to_offset(&zii->sbi->md, zii->zi);
lookup->zus_ii = zii;
return 0;
}
static int _dentry(struct zufs_ioc_hdr *hdr)
{
struct zufs_ioc_dentry *zid = (void *)hdr;
struct zus_inode_info *dir_ii = zid->zus_dir_ii;
struct zus_inode_info *zii = zid->zus_ii;
if (hdr->operation == ZUFS_OP_REMOVE_DENTRY)
return dir_ii->sbi->op->remove_dentry(dir_ii, zii, &zid->str);
return dir_ii->sbi->op->add_dentry(dir_ii, zid->zus_ii, &zid->str);
}
static int _rename(struct zufs_ioc_hdr *hdr)
{
struct zufs_ioc_rename *zir = (void *)hdr;
struct zus_sb_info *sbi = zir->old_dir_ii->sbi;
if (!sbi->op->rename)
return -ENOTSUP;
return sbi->op->rename(zir);
}
static int _readdir(void *app_ptr, struct zufs_ioc_hdr *hdr)
{
struct zufs_ioc_readdir *zir = (void *)hdr;
struct zus_sb_info *sbi = zir->dir_ii->sbi;
if (!sbi->op->readdir)
return -ENOTSUP;
return sbi->op->readdir(app_ptr, zir);
}
static int _clone(struct zufs_ioc_hdr *hdr)
{
struct zufs_ioc_clone *ioc_clone = (void *)hdr;
struct zus_sb_info *sbi = ioc_clone->src_zus_ii->sbi;
if (!sbi->op->clone)
return -ENOTSUP;
return sbi->op->clone(ioc_clone);
}
static int _io_read(ulong *app_ptr, struct zufs_ioc_hdr *hdr)
{
struct zufs_ioc_IO *io = (void *)hdr;
struct zus_inode_info *zii = io->zus_ii;
return zii->op->read(app_ptr, io);
}
static int _io_pre_read(ulong *app_ptr, struct zufs_ioc_hdr *hdr)
{
struct zufs_ioc_IO *io = (void *)hdr;
struct zus_inode_info *zii = io->zus_ii;
if (!zii->op->pre_read)
return -ENOTSUP;
return zii->op->pre_read(app_ptr, io);
}
static int _io_write(ulong *app_ptr, struct zufs_ioc_hdr *hdr)
{
struct zufs_ioc_IO *io = (void *)hdr;
struct zus_inode_info *zii = io->zus_ii;
return zii->op->write(app_ptr, io);
}
static int _get_put_multy(struct zufs_ioc_hdr *hdr)
{
struct zufs_ioc_IO *io = (void *)hdr;
struct zus_inode_info *zii = io->zus_ii;
if (unlikely(!zii->op->get_put_multy)) {
ERROR("No get_put_multy operation set\n");
return -EIO;
}
return zii->op->get_put_multy(zii, io);
}
static int _mmap_close(struct zufs_ioc_hdr *hdr)
{
struct zufs_ioc_mmap_close *mmap_close = (void *)hdr;
struct zus_inode_info *zii = mmap_close->zus_ii;
if (unlikely(!zii->op->mmap_close))
return 0;
return zii->op->mmap_close(zii, mmap_close);
}
static int _setattr(struct zufs_ioc_hdr *hdr)
{
struct zufs_ioc_attr *ioc_attr = (void *)hdr;
struct zus_inode_info *zii = ioc_attr->zus_ii;
if (!zii->op->setattr)
return 0; /* This is fine no flushing needed */
return zii->op->setattr(zii, ioc_attr->zuf_attr);
}
static int _sync(struct zufs_ioc_hdr *hdr)
{
struct zufs_ioc_sync *ioc_range = (void *)hdr;
struct zus_inode_info *zii = ioc_range->zus_ii;
if (!zii->op->sync)
return 0; /* This is fine sync not needed */
return zii->op->sync(zii, ioc_range);
}
static int _fallocate(struct zufs_ioc_hdr *hdr)
{
struct zufs_ioc_IO *ioc_IO = (void *)hdr;
struct zus_inode_info *zii = ioc_IO->zus_ii;
if (!zii->op->fallocate)
return -ENOTSUP;
return zii->op->fallocate(zii, ioc_IO);
}
static int _seek(struct zufs_ioc_hdr *hdr)
{
struct zufs_ioc_seek *ioc_seek = (void *)hdr;
struct zus_inode_info *zii = ioc_seek->zus_ii;
if (!zii->op->seek)
return -ENOTSUP;
return zii->op->seek(zii, ioc_seek);
}
static int _ioc_ioctl(struct zufs_ioc_hdr *hdr)
{
struct zufs_ioc_ioctl *ioc_ioctl = (void *)hdr;
struct zus_inode_info *zii = ioc_ioctl->zus_ii;
if (!zii->op->ioctl)
return -ENOTTY;
return zii->op->ioctl(zii, ioc_ioctl);
}
static int _ioc_xattr(struct zufs_ioc_hdr *hdr)
{
struct zufs_ioc_xattr *ioc_xattr = (void *)hdr;
struct zus_inode_info *zii = ioc_xattr->zus_ii;
if (hdr->operation == ZUFS_OP_XATTR_GET) {
if (!zii->op->getxattr)
return -ENOTSUP;
return zii->op->getxattr(zii, ioc_xattr);
} else if (hdr->operation == ZUFS_OP_XATTR_SET) {
if (!zii->op->setxattr)
return -ENOTSUP;
return zii->op->setxattr(zii, ioc_xattr);
} else if (hdr->operation == ZUFS_OP_XATTR_LIST) {
if (!zii->op->listxattr)
return -ENOTSUP;
return zii->op->listxattr(zii, ioc_xattr);
}
ERROR("Unknown xattr operation!\n");
return -EFAULT;
}
static int _statfs(struct zufs_ioc_hdr *hdr)
{
struct zufs_ioc_statfs *ioc_statfs = (void *)hdr;
struct zus_sb_info *sbi = ioc_statfs->zus_sbi;
if (!sbi->op->statfs)
return -ENOTSUP;
return sbi->op->statfs(sbi, ioc_statfs);
}
static int _fiemap(void *app_ptr, struct zufs_ioc_hdr *hdr)
{
struct zufs_ioc_fiemap *zif = (void *)hdr;
struct zus_inode_info *zii = zif->zus_ii;
if (!zii->op->fiemap)
return -ENOTSUP;
return zii->op->fiemap(app_ptr, zif);
}
static int _show_options(struct zufs_ioc_hdr *hdr)
{
struct zufs_ioc_mount_options *ioc_mount_options = (void *)hdr;
struct zus_sb_info *sbi = ioc_mount_options->zus_sbi;
if (!sbi->op->show_options)
return 0;
return sbi->op->show_options(sbi, ioc_mount_options);
}
static int _iom_done(struct zufs_ioc_hdr *hdr)
{
struct zufs_ioc_iomap_done *ziid = (void *)hdr;
if (unlikely(!(ziid->iomd && ziid->iomd->done))) {
ERROR("iom_done is %p %p\n", ziid->iomd,
ziid->iomd ? ziid->iomd->done: NULL);
return -EINVAL;
}
DBG("%p\n", ziid->iomd);
ziid->iomd->done(ziid->iomd, hdr->err);
return 0;
}
const char *ZUFS_OP_name(enum e_zufs_operation op)
{
#define CASE_ENUM_NAME(e) case e: return #e
switch (op) {
CASE_ENUM_NAME(ZUFS_OP_NULL);
CASE_ENUM_NAME(ZUFS_OP_BREAK);
CASE_ENUM_NAME(ZUFS_OP_STATFS);
CASE_ENUM_NAME(ZUFS_OP_SHOW_OPTIONS);
CASE_ENUM_NAME(ZUFS_OP_NEW_INODE);
CASE_ENUM_NAME(ZUFS_OP_FREE_INODE);
CASE_ENUM_NAME(ZUFS_OP_EVICT_INODE);
CASE_ENUM_NAME(ZUFS_OP_LOOKUP);
CASE_ENUM_NAME(ZUFS_OP_ADD_DENTRY);
CASE_ENUM_NAME(ZUFS_OP_REMOVE_DENTRY);
CASE_ENUM_NAME(ZUFS_OP_RENAME);
CASE_ENUM_NAME(ZUFS_OP_READDIR);
CASE_ENUM_NAME(ZUFS_OP_CLONE);
CASE_ENUM_NAME(ZUFS_OP_COPY);
CASE_ENUM_NAME(ZUFS_OP_READ);
CASE_ENUM_NAME(ZUFS_OP_PRE_READ);
CASE_ENUM_NAME(ZUFS_OP_WRITE);
CASE_ENUM_NAME(ZUFS_OP_MMAP_CLOSE);
CASE_ENUM_NAME(ZUFS_OP_SETATTR);
CASE_ENUM_NAME(ZUFS_OP_SYNC);
CASE_ENUM_NAME(ZUFS_OP_FALLOCATE);
CASE_ENUM_NAME(ZUFS_OP_LLSEEK);
CASE_ENUM_NAME(ZUFS_OP_IOCTL);
CASE_ENUM_NAME(ZUFS_OP_XATTR_GET);
CASE_ENUM_NAME(ZUFS_OP_XATTR_SET);
CASE_ENUM_NAME(ZUFS_OP_XATTR_LIST);
CASE_ENUM_NAME(ZUFS_OP_FIEMAP);
CASE_ENUM_NAME(ZUFS_OP_GET_MULTY);
CASE_ENUM_NAME(ZUFS_OP_PUT_MULTY);
CASE_ENUM_NAME(ZUFS_OP_NOOP);
CASE_ENUM_NAME(ZUFS_OP_IOM_DONE);
CASE_ENUM_NAME(ZUFS_OP_MAX_OPT);
default:
return "UNKNOWN";
}
}
static void _some_pigy_put(struct zufs_ioc_hdr *hdr)
{
while (hdr->flags & ZUFS_H_HAS_PIGY_PUT) {
/* Kernel made sure to update hdr->in_len including the
* iom_n. Kernel also checks bounds.
*/
hdr = (void *)hdr + hdr->in_len;
if (unlikely(hdr->operation != ZUFS_OP_PUT_MULTY)) {
ERROR("Not yet, easily support pigy ANY operation(%s)\n",
ZUFS_OP_name(hdr->operation));
break;
}
_get_put_multy(hdr);
}
}
int zus_do_command(void *app_ptr, struct zufs_ioc_hdr *hdr)
{
DBG("[%s] OP=%d off=0x%x len=0x%x\n", ZUFS_OP_name(hdr->operation),
hdr->operation, hdr->offset, hdr->len);
if (hdr->flags & ZUFS_H_HAS_PIGY_PUT)
_some_pigy_put(hdr);
switch (hdr->operation) {
case ZUFS_OP_NEW_INODE:
return _new_inode(app_ptr, hdr);
case ZUFS_OP_FREE_INODE:
case ZUFS_OP_EVICT_INODE:
return _evict(hdr);
case ZUFS_OP_LOOKUP:
return _lookup(hdr);
case ZUFS_OP_ADD_DENTRY:
case ZUFS_OP_REMOVE_DENTRY:
return _dentry(hdr);
case ZUFS_OP_RENAME:
return _rename(hdr);
case ZUFS_OP_READDIR:
return _readdir(app_ptr, hdr);
case ZUFS_OP_CLONE:
case ZUFS_OP_COPY:
return _clone(hdr);
case ZUFS_OP_READ:
return _io_read(app_ptr, hdr);
case ZUFS_OP_PRE_READ:
return _io_pre_read(app_ptr, hdr);
case ZUFS_OP_WRITE:
return _io_write(app_ptr, hdr);
case ZUFS_OP_MMAP_CLOSE:
return _mmap_close(hdr);
case ZUFS_OP_SETATTR:
return _setattr(hdr);
case ZUFS_OP_SYNC:
return _sync(hdr);
case ZUFS_OP_FALLOCATE:
return _fallocate(hdr);
case ZUFS_OP_LLSEEK:
return _seek(hdr);
case ZUFS_OP_IOCTL:
return _ioc_ioctl(hdr);
case ZUFS_OP_XATTR_GET:
case ZUFS_OP_XATTR_SET:
case ZUFS_OP_XATTR_LIST:
return _ioc_xattr(hdr);
case ZUFS_OP_STATFS:
return _statfs(hdr);
case ZUFS_OP_FIEMAP:
return _fiemap(app_ptr, hdr);
case ZUFS_OP_SHOW_OPTIONS:
return _show_options(hdr);
case ZUFS_OP_GET_MULTY:
case ZUFS_OP_PUT_MULTY:
return _get_put_multy(hdr);
case ZUFS_OP_IOM_DONE:
return _iom_done(hdr);
case ZUFS_OP_NOOP:
case ZUFS_OP_BREAK:
break;
default:
ERROR("Unknown OP=%d\n", hdr->operation);
}
return 0;
}