/
mvfs_linux_iops.c
1604 lines (1478 loc) · 46.2 KB
/
mvfs_linux_iops.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
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 1999, 2012 IBM Corporation.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*
* Author: IBM Corporation
* This module is part of the IBM (R) Rational (R) ClearCase (R)
* Multi-version file system (MVFS).
* For support, please visit http://www.ibm.com/software/support
*/
#include "vnode_linux.h"
#include "mvfs_linux_shadow.h"
/* Inode operations (and some utilities) for MVFS */
extern int
vnode_iop_create(
INODE_T * parent,
DENT_T * dentry,
int mode,
struct nameidata *nd
);
extern DENT_T *
vnode_iop_lookup(
INODE_T *dir,
DENT_T *file,
struct nameidata *nd
);
extern int
vnode_iop_link(
DENT_T * oldfile,
INODE_T * parent,
DENT_T * newfile
);
extern int
vnode_iop_unlink(
INODE_T *dir,
DENT_T *file
);
extern int
vnode_iop_symlink(
INODE_T *parent,
DENT_T *new,
const char *oldname
);
extern int
vnode_iop_mkdir(
INODE_T *parent,
DENT_T *new,
int mode
);
extern int
vnode_iop_rmdir(
INODE_T *parent,
DENT_T *target
);
extern int
vnode_iop_mknod(
INODE_T *parent,
DENT_T *new,
int mode,
dev_t dev
);
extern int
vnode_iop_rename(
INODE_T *odir,
DENT_T *odent,
INODE_T *ndir,
DENT_T *ndent
);
extern int
vnode_iop_permission(
INODE_T *ip,
int permtype
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
, struct nameidata *nd
#endif
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,32)
, unsigned int flags
#endif
);
extern int
vnode_iop_getattr(
struct vfsmount *mnt,
DENT_T *dentry,
struct kstat *kstat
);
/* vnode_iop_notify_change in common header for shadow code */
extern int
vnode_iop_readlink(
DENT_T *dentry,
char * buf,
int buflen
);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
void *
#else
int
#endif
vnode_iop_follow_link(
DENT_T *base, /* parent */
struct nameidata *nd /* entry we are trying to resolve */
);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
extern void
vnode_iop_put_link(
struct dentry *dentry,
struct nameidata *nd,
void *cookie
);
#endif
extern int
vnode_iop_setxattr(
struct dentry *dentry,
const char *name,
const void *value,
size_t size,
int flags
);
extern ssize_t
vnode_iop_getxattr(
struct dentry *dentry,
const char *name,
void *value,
size_t size
);
extern ssize_t
vnode_iop_listxattr(
struct dentry *dentry,
char *name,
size_t size
);
extern int
vnode_iop_removexattr(
struct dentry *dentry,
const char *name
);
IN_OPS_T vnode_file_inode_ops = {
.permission = &vnode_iop_permission,
.getattr = &vnode_iop_getattr,
.setattr = &vnode_iop_notify_change,
};
IN_OPS_T vnode_file_mmap_inode_ops = {
.permission = &vnode_iop_permission,
.getattr = &vnode_iop_getattr,
.setattr = &vnode_iop_notify_change,
};
IN_OPS_T vnode_slink_inode_ops = {
.readlink = &vnode_iop_readlink,
.follow_link = &vnode_iop_follow_link,
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
.put_link = &vnode_iop_put_link,
#endif
.permission = &vnode_iop_permission,
.getattr = &vnode_iop_getattr,
};
IN_OPS_T vnode_dir_inode_ops = {
.create = &vnode_iop_create,
.lookup = &vnode_iop_lookup,
.link = &vnode_iop_link,
.unlink = &vnode_iop_unlink,
.symlink = &vnode_iop_symlink,
.mkdir = &vnode_iop_mkdir,
.rmdir = &vnode_iop_rmdir,
.mknod = &vnode_iop_mknod,
.rename = &vnode_iop_rename,
.permission = &vnode_iop_permission,
.getattr = &vnode_iop_getattr,
.setattr = &vnode_iop_notify_change,
.setxattr = &vnode_iop_setxattr,
.getxattr = &vnode_iop_getxattr,
.listxattr = &vnode_iop_listxattr,
.removexattr = &vnode_iop_removexattr,
};
/* make this use a kmem_cache someday */
#define VATTR_ALLOC() KMEM_ALLOC(sizeof(VATTR_T), KM_SLEEP)
#define VATTR_FREE(vap) KMEM_FREE(vap, sizeof(VATTR_T))
/* Inode operations */
/* This is VOP_ACCESS().
* permtype = bitwise-OR of MAY_READ, MAY_WRITE, MAY_EXEC
* For 2.6.27 and beyond we may need to handle other
* permission requests than the tradional MAY_[RWX], like
* MAY_ACCESS.
*/
extern int
vnode_iop_permission(
INODE_T *ip,
int permtype
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
, struct nameidata *nd
#endif
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,32)
, unsigned int flags
#endif
)
{
int err;
CALL_DATA_T cd;
ASSERT_I_SEM_NOT_MINE(ip);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38)
/* We can't deal with RCU lookups, the lookup will happen after
* a rcu_read_lock call, which means we can't block. Additionally,
* vfsmount_lock is locked, which means we can't call mntput
* (and other functions). We use the permission callback to detect
* and refuse RCU operations, which are then retried without using RCU.
*/
if (flags & IPERM_FLAG_RCU)
return -ECHILD;
#endif
mdki_linux_init_call_data(&cd);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
/* we are not dealing with MAY_ACCESS and MAY_OPEN */
permtype &= (MAY_READ | MAY_WRITE | MAY_EXEC);
#endif
/*
* Vnode core wants the mode test bits to be in the user position, not the
* low bits. Bits are in same order as standard UNIX rwx.
*/
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
err = VOP_ACCESS(ITOV(ip), permtype << 6, 0, &cd, (nameidata_ctx *) nd);
#elif LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,32)
err = VOP_ACCESS(ITOV(ip), permtype << 6, 0, &cd, NULL);
#else
err = VOP_ACCESS(ITOV(ip), permtype << 6, 0, &cd,
(nameidata_ctx *) (unsigned long) flags);
#endif
err = mdki_errno_unix_to_linux(err);
mdki_linux_destroy_call_data(&cd);
return err;
}
STATIC int
vnlayer_getattr(
DENT_T *dentry,
VATTR_T *vap
)
{
INODE_T *ip;
VNODE_T *vp;
CALL_DATA_T cd;
int err;
ip = dentry->d_inode;
ASSERT_KERNEL_UNLOCKED();
mdki_linux_init_call_data(&cd);
vp = ITOV(ip);
/* implicit and explicit attribute pullup to the vnode */
VATTR_SET_MASK(vap, AT_ALL);
err = VOP_GETATTR(vp, vap, GETATTR_FLAG_PULLUP_ATTRS, &cd);
err = mdki_errno_unix_to_linux(err);
mdki_linux_destroy_call_data(&cd);
return err;
}
STATIC void
vnlayer_linux_vattr2kstat(
VATTR_T *src,
struct kstat *dst
)
{
BZERO(dst, sizeof(*dst));
/* We could assume all the "pullup" stuff happened in getattr so the inode
** matches what we have in the vattr and then use generic_fillattr(ip, dst)
** (and fix the dev field since it's not in the inode anymore). However,
** there could be a race on vob roots if we did that, so just get
** everything out of the passed in vattr structure.
*/
#define GET(lll, UUU) dst->lll = VATTR_GET_ ## UUU(src)
#define GET_TIME(lll, UUU) VATTR_GET_ ## UUU ## _TS(src, &(dst->lll))
GET(dev, FSID);
GET(ino, NODEID);
GET(mode, MODE);
dst->mode |= vnlayer_vtype_to_mode(VATTR_GET_TYPE(src));
GET(nlink, NLINK);
GET(uid, UID);
GET(gid, GID);
GET(rdev, RDEV);
GET_TIME(atime, ATIME);
GET_TIME(mtime, MTIME);
GET_TIME(ctime, CTIME);
GET(size, SIZE);
GET(blocks, NBLOCKS);
GET(blksize, BLKSIZE);
#undef GET_TIME
#undef GET
}
extern int
vnode_iop_getattr(
struct vfsmount *mnt,
DENT_T *dentry,
struct kstat *kstat
)
{
VATTR_T *vap;
int err;
vap = VATTR_ALLOC();
if (vap == NULL)
return -ENOMEM;
err = vnlayer_getattr(dentry, vap);
/* Fill in the return structure, if we should. */
if ((err == 0) && (kstat != NULL)) {
vnlayer_linux_vattr2kstat(vap, kstat);
}
VATTR_FREE(vap);
return(err);
}
STATIC void
vnode_iop_iattr2vattr(
struct iattr *src,
VATTR_T *dst
)
{
struct timespec curtime = CURRENT_TIME;
VATTR_NULL(dst);
if (src->ia_valid & ATTR_MODE) {
VATTR_SET_TYPE(dst, vnlayer_mode_to_vtype(src->ia_mode));
VATTR_SET_MODE_RIGHTS(dst, src->ia_mode);
dst->va_mask |= AT_MODE|AT_TYPE;
}
#define SET(UUU,lll) \
if (src->ia_valid & ATTR_ ## UUU) { \
VATTR_SET_ ## UUU(dst, src->ia_ ## lll); \
dst->va_mask |= AT_ ## UUU; \
}
SET(UID,uid)
SET(GID,gid)
SET(SIZE,size)
#undef SET
if (src->ia_valid & ATTR_ATIME) {
/*
* If ATTR_ATIME is provided, but not ATTR_ATIME_SET, then we need
* the current time. We have to pass ATTR_ATIME_SET through because
* Linux uses it to control its validation.
*/
if (src->ia_valid & ATTR_ATIME_SET) {
VATTR_SET_ATIME_TS(dst, &(src->ia_atime));
} else {
VATTR_SET_ATIME_TS(dst, &curtime);
}
dst->va_mask |= AT_ATIME;
}
if (src->ia_valid & ATTR_ATIME_SET) dst->va_mask |= AT_ATIME_SET;
if (src->ia_valid & ATTR_MTIME) {
/*
* If ATTR_MTIME is provided, but not ATTR_MTIME_SET, then we need
* the current time. We have to pass ATTR_MTIME_SET through because
* Linux uses it to control its validation.
*/
if (src->ia_valid & ATTR_MTIME_SET) {
VATTR_SET_MTIME_TS(dst, &(src->ia_mtime));
} else {
VATTR_SET_MTIME_TS(dst, &curtime);
}
dst->va_mask |= AT_MTIME;
}
if (src->ia_valid & ATTR_MTIME_SET) dst->va_mask |= AT_MTIME_SET;
/* No current time hack needed for ctime. */
if (src->ia_valid & ATTR_CTIME) {
VATTR_SET_CTIME_TS(dst, &(src->ia_ctime));
dst->va_mask |= AT_CTIME;
}
if (src->ia_valid & ATTR_ATTR_FLAG) {
MDKI_VFS_LOG(VFS_LOG_ERR, "What to do with ATTR_FLAGs?: caller %p\n", mdki_getmycaller());
}
return;
}
/* This is really VOP_SETATTR() in sheep's clothing */
int
vnode_iop_notify_change(
DENT_T *dent_p,
struct iattr * iattr_p
)
{
VNODE_T *vp;
VATTR_T *vap;
VNODE_T *cvp;
int err = 0;
DENT_T *rdent;
CALL_DATA_T cd;
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36)
mdki_boolean_t tooksem = FALSE;
#endif
if (iattr_p->ia_valid & ATTR_SIZE) {
ASSERT_I_SEM_MINE(dent_p->d_inode);
}
if (MDKI_INOISMVFS(dent_p->d_inode)) {
vap = VATTR_ALLOC();
if (vap != NULL) {
vnode_iop_iattr2vattr(iattr_p, vap);
/* reject attempts to use setattr to change object type */
vap->va_mask &= ~AT_TYPE;
mdki_linux_init_call_data(&cd);
vp = ITOV(dent_p->d_inode);
err = VOP_SETATTR(vp, vap, 0, &cd);
err = mdki_errno_unix_to_linux(err);
/* Any underlying cleartxt got its inode truncated via changeattr
* if there's a need to change its size.
*/
if (!err)
mdki_linux_vattr_pullup(vp, vap, vap->va_mask);
VATTR_FREE(vap);
mdki_linux_destroy_call_data(&cd);
} else {
err = -ENOMEM;
}
} else {
rdent = REALDENTRY_LOCKED(dent_p, &cvp);
VNODE_DGET(rdent);
if (rdent && rdent->d_inode) {
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36)
err = inode_setattr(dent_p->d_inode, iattr_p);
if (err == 0) {
if (iattr_p->ia_valid & ATTR_SIZE) {
LOCK_INODE(rdent->d_inode);
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
#if !defined RHEL_UPDATE || RHEL_UPDATE < 5
down_write(&rdent->d_inode->i_alloc_sem);
#endif
#endif
/*
* be paranoid and record the 'taken'ness in case
* the called function squashes ia_valid (as is
* done in nfs_setattr).
*/
tooksem = TRUE;
}
err = MDKI_NOTIFY_CHANGE(rdent, CVN_TO_VFSMNT(cvp), iattr_p);
if (tooksem) {
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
#if !defined(RHEL_UPDATE) || RHEL_UPDATE < 5
up_write(&rdent->d_inode->i_alloc_sem);
#endif
#endif
UNLOCK_INODE(rdent->d_inode);
}
}
#else /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) */
err = simple_setattr(dent_p, iattr_p);
if (err == 0)
err = MDKI_NOTIFY_CHANGE(rdent, CVN_TO_VFSMNT(cvp), iattr_p);
#endif /* else LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) */
} else {
/* It looks as though someone removed the realdentry on us.
* I am not sure why this should happen.
*/
err = -ENOENT;
}
if (rdent) {
VNODE_DPUT(rdent);
REALDENTRY_UNLOCK(dent_p, cvp);
}
}
return err;
}
extern int
vnode_iop_readlink(
DENT_T *dentry,
char * buf,
int buflen
)
{
INODE_T *ip;
struct uio uio;
iovec_t iov;
int err = 0;
CALL_DATA_T cd;
/*
* This routine is not called for shadow objects which need
* special handling; they're done in shadow_readlink.
*/
uio.uio_iov = &iov;
mdki_linux_uioset(&uio, buf, buflen, 0, UIO_USERSPACE);
mdki_linux_init_call_data(&cd);
ip = dentry->d_inode;
ASSERT_KERNEL_UNLOCKED();
ASSERT_I_SEM_NOT_MINE(ip);
err = VOP_READLINK(ITOV(ip), &uio, &cd);
err = mdki_errno_unix_to_linux(err);
mdki_linux_destroy_call_data(&cd);
if (err == 0) {
/* return count of bytes */
err = buflen - uio.uio_resid;
}
return(err);
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
/* The return pointer points to a cookie to be given to put_link() to clean
** stuff up if necessary.
*/
void *
#else
int
#endif
vnode_iop_follow_link(
DENT_T *dentry, /* link */
struct nameidata *nd /* link resolution */
)
{
INODE_T *ip;
struct uio uio;
iovec_t iov;
int err = 0;
char *buf = KMEM_ALLOC(PATH_MAX, KM_SLEEP);
CALL_DATA_T cd;
if (buf == NULL)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
return ERR_PTR(-ENOMEM);
#else
return -ENOMEM;
#endif
uio.uio_iov = &iov;
mfs_uioset(&uio, buf, PATH_MAX-1, 0, UIO_SYSSPACE);
mdki_linux_init_call_data(&cd);
ip = dentry->d_inode;
ASSERT_KERNEL_UNLOCKED();
ASSERT_I_SEM_NOT_MINE(ip);
err = VOP_READLINK(ITOV(ip), &uio, &cd);
err = mdki_errno_unix_to_linux(err);
mdki_linux_destroy_call_data(&cd);
if (err == 0) {
if (uio.uio_resid == 0)
err = -ENAMETOOLONG;
else {
/* readlink doesn't copy a NUL at the end, we must do it */
buf[uio.uio_offset] = '\0';
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
/* follow the link */
err = vfs_follow_link(nd, buf);
#else
nd_set_link(nd, buf);
return(buf); /* vnop_iop_put_link() will free this buf. */
#endif
}
}
KMEM_FREE(buf, PATH_MAX);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
return ERR_PTR(err);
#else
return(err);
#endif
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
void
vnode_iop_put_link(
struct dentry *dentry,
struct nameidata *nd,
void *cookie)
{
KMEM_FREE(cookie, PATH_MAX);
return;
}
#endif
/* This function is called when a file is being created in a directory.
* The dentry is the negative dentry to be filled in by the create.
* The parent is a pointer to the parent inode.
* We are called with the parent inode locked. We have to lock the
* real parent as well. We run the risk of deadlock here. However,
* if we always lock the shadow inode before the real inode, we should
* be OK. (See mvop_linux_create().)
* We did a dget on the real dentry when we put the pointer into the
* shadow inode. We shouldn't need to do it again, I don't think.
*/
extern int
vnode_iop_create(
INODE_T * parent,
struct dentry * dentry,
int mode,
struct nameidata *nd
)
{
int err = 0;
VATTR_T *vap;
VNODE_T *newvp;
struct create_ctx ctx;
CALL_DATA_T cd;
ASSERT_I_SEM_MINE(parent);
ASSERT(MDKI_INOISMVFS(parent));
vap = VATTR_ALLOC();
if (vap == NULL)
return -ENOMEM;
VATTR_NULL(vap);
mdki_linux_init_call_data(&cd);
/*
* Solaris sends only type, mode, size, so we will too.
*/
vap->va_type = VREG;
vap->va_mode = mode & ~S_IFMT;
vap->va_size = 0;
vap->va_mask = AT_TYPE|AT_MODE|AT_SIZE;
newvp = NULL;
dentry->d_inode = NULL;
ctx.dentry = dentry;
ctx.parent = parent;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38)
/* break any rcu-walk in progress */
# if defined(MRG)
write_seqlock_barrier(&dentry->d_lock);
# else /* defined (MRG) */
write_seqcount_barrier(&dentry->d_seq);
# endif /* else defined (MRG) */
#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38) */
err = VOP_CREATE(ITOV(parent),
(/* drop const */ char *) dentry->d_name.name,
vap,
NONEXCL, /* XXX handled by generic layer? */
mode, /* not used except for passthrough, see vap->va_mode */
&newvp,
&cd,
&ctx);
err = mdki_errno_unix_to_linux(err);
/* dentry reference uses the hold count from a successful create */
if (!err) {
if (dentry->d_inode == NULL) {
/* Not a shadow object */
ASSERT(newvp != NULL);
ASSERT(VTOI(newvp) != NULL);
VNODE_D_INSTANTIATE(dentry, VTOI(newvp));
VATTR_SET_MASK(vap, AT_ALL);
if (VOP_GETATTR(newvp, vap, 0, &cd) == 0)
mdki_linux_vattr_pullup(newvp, vap, AT_ALL);
} else {
/* drop the extra ref returned in newvp */
VN_RELE(newvp);
}
/* I nuked the code checking not VCHR, VREG--we are always VREG */
} else {
ASSERT(!dentry->d_inode);
ASSERT(!newvp);
}
VATTR_FREE(vap);
mdki_linux_destroy_call_data(&cd);
return(err);
}
/* vnode_iop_lookup
* Wrapper routine for mfs_lookup.
* Args: INODE_T *dir Directory inode.
* dentry *file Dcache entry for file we are looking up.
* FIXME: We still have to figure out how to keep from cacheing this
* dentry. We want the VFS to always call us to resolve
* pathnames. (not possible, we just try to keep the VFS
* calling us all the time by claiming dentries are not valid)
*/
DENT_T *
vnode_iop_lookup(
INODE_T *dir,
struct dentry *dent,
struct nameidata *nd
)
{
char *name;
mdki_boolean_t rele = FALSE;
int err;
VNODE_T *dvp;
VNODE_T *rt_vnode; /* returned vnode */
INODE_T *rt_inode = NULL; /* returned inode ptr */
DENT_T * real_dentry;
DENT_T *found_dentry = dent;
VATTR_T *vap;
struct lookup_ctx ctx;
CALL_DATA_T cd;
ASSERT_I_SEM_MINE(dir);
/* We can find our parent entry via the dentry provided to us. */
ASSERT(dent->d_parent->d_inode == dir);
if (dent->d_name.len > NAME_MAX)
return ERR_PTR(-ENAMETOOLONG);
name = /* drop the const */(char *) dent->d_name.name;
mdki_linux_init_call_data(&cd);
/* We pass along the dentry, as well as the parent inode so that
* mvop_linux_lookup_* has everything it needs, even if it is passed in
* the realvp, and it gets back a negative dentry.
*/
dvp = ITOV(dir);
ctx.dentrypp = &found_dentry;
ctx.flags = LOOKUP_CTX_VALID;
err = VOP_LOOKUP(dvp, name, &rt_vnode, (struct pathname *)NULL,
VNODE_LF_LOOKUP, NULL, &cd, &ctx);
err = mdki_errno_unix_to_linux(err);
if (!err) {
ASSERT(rt_vnode != NULL);
if (MDKI_INOISCLRVN(VTOI(rt_vnode))) {
/* unwrap to the real object */
ASSERT(CVN_TO_DENT(rt_vnode));
rt_inode = CVN_TO_INO(rt_vnode);
if (MDKI_INOISMVFS(rt_inode)) {
VN_HOLD(ITOV(rt_inode));
VN_RELE(rt_vnode);
rt_vnode = ITOV(rt_inode);
} else {
igrab(rt_inode);
VN_RELE(rt_vnode);
rt_vnode = NULL;
}
} else
rt_inode = VTOI(rt_vnode);
}
if (!err && (found_dentry != dent)) {
mdki_linux_destroy_call_data(&cd);
/* The hold was granted in makeloopnode() in the 'nocover' case. */
if (rt_vnode != NULL)
VN_RELE(rt_vnode);
else
iput(rt_inode);
/*
* found_dentry is the real socket/block/char device node's dentry.
* See mvop_linux_lookup_component().
*
* For sockets, we use a dentry in our tree (we fill in the
* provided dentry "dent") linked to the inode of the real
* object. This lets file name operations work in our
* namespace, and lets socket connections all work (as they're
* keyed off of the inode address) from inside to outside &
* v.v.
*
* We also do this for VCHR, VBLK devices, and it seems to work OK
* (e.g. make a node the same as /dev/tty, you can write to it)
*/
switch (found_dentry->d_inode->i_mode & S_IFMT) {
case S_IFSOCK:
case S_IFCHR:
case S_IFBLK:
ASSERT(dent->d_inode == NULL);
MDKI_SET_DOPS(dent, &vnode_shadow_dentry_ops);
igrab(found_dentry->d_inode);
VNODE_D_ADD(dent, found_dentry->d_inode);
VNODE_DPUT(found_dentry);
found_dentry = NULL; /* tell caller to use original dentry */
break;
default:
/* use returned dentry */
break;
}
return(found_dentry);
}
/* We need to pass back dentry ops even for negative dentries, I think.
* Shadow inodes will have been taken care of in lookup_component.
*/
if (dent->d_op != &vnode_shadow_dentry_ops) {
if (dent->d_parent->d_op == &vnode_setview_dentry_ops)
MDKI_SET_DOPS(dent, &vnode_setview_dentry_ops);
else
MDKI_SET_DOPS(dent, &vnode_dentry_ops);
}
vap = VATTR_ALLOC();
if (vap == NULL) {
err = -ENOMEM;
goto alloc_err;
}
if (!err && MDKI_INOISMVFS(rt_inode)) {
/* fetch attributes & place in inode */
VATTR_SET_MASK(vap, AT_ALL);
err = VOP_GETATTR(rt_vnode, vap, GETATTR_FLAG_UPDATE_ATTRS, &cd);
err = mdki_errno_unix_to_linux(err);
if (err == -EOPNOTSUPP) /* ignore it */
err = 0;
else if (err)
rele = TRUE;
else if ((rt_vnode->v_flag & VLOOPROOT) != 0 &&
rt_inode == vnlayer_get_urdir_inode())
{
/* return the real root */
VN_RELE(rt_vnode);
VATTR_FREE(vap);
mdki_linux_destroy_call_data(&cd);
return VNODE_DGET(vnlayer_get_root_dentry());
}
else if (vnlayer_looproot_vp != NULL &&
rt_vnode == vnlayer_looproot_vp &&
(real_dentry = MVOP_DENT(rt_inode,
&vnode_dentry_ops)) != NULL)
{
/* return the real /view */
VN_RELE(rt_vnode);
VATTR_FREE(vap);
mdki_linux_destroy_call_data(&cd);
return real_dentry;
}
}
VATTR_FREE(vap);
alloc_err:
mdki_linux_destroy_call_data(&cd);
/* It's an mnode-based object, set up a dentry for it */
/* We don't return ENOENT. For Linux, the negative dentry is enough */
switch (err) {
case -ENOENT:
err = 0;
ASSERT(rt_inode == NULL);
VNODE_D_ADD(dent, rt_inode);
break;
case 0:
/* We will consume the count on rt_inode as a reference for dent */
/*
* For VOB vnodes, we maintain two separate dentry trees for
* the vnodes. One tree is for setview-mode names (process
* sets to a view context, then looks directly at the VOB
* mountpoint without any cover vnodes in the path). The
* other tree is for view-extended naming into a VOB, with
* dentries starting at the view tag and covering non-VOB
* objects until crossing a mount point into a VOB.
*
* Mostly the system doesn't care, as long as it goes down the
* tree from parent to child, since it will be traversing only one
* of the dentry trees. But when the cache misses, the system calls
* this lookup method and wants to get a dentry in return.
* There are standard interfaces ( d_splice_alias() in 2.6)
* which can find a good dentry referencing the inode returned
* by the file system's lookup method, but these methods don't
* work right when we have VOB directory vnodes with both setview
* and view-extended dentries. We implement our own function
* [vnlayer_inode2dentry_internal()] which knows the
* distinctions and the rules for determining that an existing
* attached dentry is valid for the lookup request.
*
* We have our own d_compare() function which forces all VOB
* lookups to come to the inode lookup method (this function),
* and then we get to choose the right dentry to return. We
* have our own lookup cache inside MVFS so we don't care that
* the dentry cache is always missing on our names.
*
* If we have to make a new dentry, we may need to merge it
* with an NFS-created temporary dentry using d_move()
* (d_splice_alias() would do this for us, but we can't use it
* for reasons listed above).
*/
/*
* We want to find the "right" dentry (if there is one), so
* look for one that has a d_parent with the same dentry ops
* (indicating it's in the same dentry tree).
*/
if (S_ISDIR(rt_inode->i_mode)) {
/*
* It has been empirically shown that we have to check the
* parent of the dentry. If the parent has been checked out
* it is possible for the cache lookup to return an inode
* from the tree below the old parent directory. If this
* happens on a rename, the system will panic because the
* Linux rename code checks the parent of the returned
* dentry to see that it matches what it has for a parent.
*/
found_dentry = vnlayer_inode2dentry_internal(rt_inode,
dent->d_parent, NULL,
dent->d_op);
} else {
/*
* For non-directories, we also need to consider the
* parent & the requested name so that
* vnlayer_inode2dentry_internal() finds the right dentry.
* (There may be multiple hard links; we want the one in
* the same directory with the same name)
*/
found_dentry = vnlayer_inode2dentry_internal(rt_inode,
dent->d_parent,
&dent->d_name,
dent->d_op);
}
if (found_dentry != NULL) {
ASSERT(found_dentry->d_inode == rt_inode);
/*
* If the existing one is a disconnected dentry, we need
* to move the old one to the new one (just like
* d_splice_alias) to get the proper name/parent attached
* in the dcache.
*/
if ((found_dentry->d_flags & DCACHE_DISCONNECTED) != 0) {
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,7)
ASSERT((dent->d_flags & DCACHE_UNHASHED) != 0);
#else
ASSERT((dent->d_vfs_flags & DCACHE_UNHASHED) != 0);
#endif
d_rehash(dent);
d_move(found_dentry, dent);
}
/* Release our count. found_dentry also references inode. */
iput(rt_inode);
return found_dentry;
}
/*
* Nothing suitable, wire it up to the proposed dentry.
*/
VNODE_D_ADD(dent, rt_inode);
break;
default:
/* some other error case */
if (rele)
VN_RELE(rt_vnode);
break;
}
if (err)
return ERR_PTR(err);
else
return NULL;
}
extern int
vnode_iop_link(
DENT_T * olddent,
INODE_T * parent,
DENT_T * newdent
)
{
int err = 0;
struct link_ctx ctx;
VATTR_T *vap;
VNODE_T *parentvp;
ASSERT_I_SEM_MINE(olddent->d_inode);
ASSERT_I_SEM_MINE(parent);
ASSERT(MDKI_INOISMVFS(parent));
if (!vnlayer_link_eligible(olddent))
return -EXDEV;
/* VOP_REALVP will check that the parent is a loopback directory and
* return EINVAL if it isn't.
*/
if (VOP_REALVP(ITOV(parent), &parentvp) == 0) {
/* We are creating a shadow link so bypass the mvfs for the rest */
err = vnlayer_do_linux_link(parentvp, olddent, parent, newdent);
err = mdki_errno_unix_to_linux(err);
} else {
/* This needs to be passed on to the mvfs to deal with */