-
Notifications
You must be signed in to change notification settings - Fork 3
/
mvfs_clearops.c
1731 lines (1530 loc) · 54.1 KB
/
mvfs_clearops.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
/* * (C) Copyright IBM Corporation 1990, 2012. */
/*
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
*/
/* mvfs_clearops.c */
/*
* Description:
*
* A word about locking protocols is important here. The cleartext
* operations all require that the mnode be locked before calling
* the cleartext op.
*/
#include "mvfs_systm.h"
#include "mvfs.h"
/*
* Prototypes for internal routines
*/
EXTERN int
mvfs_translate_path(
char *text,
size_t size,
mvfs_sp_ent_t *table,
int tlen,
char **replacement_p
);
STATIC void
mfs_clear_closevp(
VNODE_T *vp,
CRED_T *cred
);
#ifdef MVFS_DEBUG
int mvfs_cltxt_creds_enabled = 1; /* not STATIC, so it's patchable */
#endif
STATIC CRED_T *
mvfs_find_cred(
mvfs_clr_creds_t *aclist,
CRED_T *cred
);
STATIC void
mvfs_clear_release_credlist(mvfs_clr_creds_t *a_clist);
/* MFS_CLEARPERR - print an error on a cleartext file */
void
mfs_clearperr(vp, s, error)
VNODE_T *vp;
char *s;
int error;
{
char *pn;
int pri;
ASSERT(MFS_ISVOB(VTOM(vp)));
pn = VTOM(vp)->mn_vob.cleartext.nm;
pri = MFS_LOG_ERR;
/*
* Lower priority msg for ESTALE/EINTR - they are expected!
* Warn if error is 0, this is used for "incomplete writes".
*/
if (error == ESTALE) pri = MFS_LOG_ESTALE;
if (error == 0) pri = MFS_LOG_WARN;
if (error == EINTR || error == ENOSPC) pri = MFS_LOG_DEBUG;
/*
* Put more post-mortem info into the system console log.
*/
mvfs_log(pri, "%s view=%s vob=%s dbid=0x%x%s\n", s, mfs_vp2vw(vp),
mfs_vp2dev(vp), mfs_vp2dbid(vp), mfs_strerr(error));
if (pn) {
mvfs_log(pri, "cleartext pname= %s\n", pn);
}
/* Ignore blurt to user on ESTALE/EINTR */
if (pri > MFS_LOG_ERR) return;
/* Blurt to user with just cleartext pname.
* Often the most useful name to give.
* FIXME: someday, use "name" of object for user instead of
* a name from underlying implementation.
*/
/* FIXME: need an abstraction for cleartext uprintf here. */
UPRINTF(("%s view=%s vob=%s dbid=0x%x%s\n", s, mfs_vp2vw(vp),
mfs_vp2dev(vp), mfs_vp2dbid(vp), mfs_strerr(error)));
if (pn) {
UPRINTF(("cleartext pname= %s\n", pn));
}
}
/* MFS_CLEAR_ERROR - common cleartext error handling from vnode ops */
void
mfs_clear_error(vp, s, error)
VNODE_T *vp;
char *s;
int error;
{
mfs_mnode_t *mnp;
if (error == 0) return;
mnp = VTOM(vp);
ASSERT(MFS_ISVOB(mnp));
switch (error) {
case 0: return;
/*
* Don't mark the vnode rwerr just because the user passed
* in an invalid address.
*/
case EFAULT: return;
/* Expected errors */
case EINVAL: /* FIXME: reconsider for plain return */
case EAGAIN:
case EDEADLK:
case EFBIG:
case ETIMEDOUT:
case EINTR:
/*
* Record error. This will cause the MFS to release
* (purge) the cleartext on inactive, so we won't get
* burned by a sticky NFS error on a completely different
* open of the file.
*/
mfs_clear_mark_rwerr(vp);
break;
case ESTALE:
mfs_clear_mark_rwerr(vp);
break;
default:
mfs_clearperr(vp, s, error);
mfs_clear_mark_rwerr(vp);
break;
}
return;
}
void
mvfs_clear_log_stale(
VNODE_T *vp
)
{
mfs_mnode_t *mnp = VTOM(vp);
char *pn;
ASSERT(MISLOCKED(mnp));
ASSERT(MFS_ISVOB(mnp));
if (mnp->mn_vob.cleartext.ostale_logged) {
MDB_XLOG((MDB_CLEAROPS, "mnp %lx already stale logged\n", mnp));
return;
}
pn = mnp->mn_vob.cleartext.nm;
mvfs_log(MFS_LOG_INFO,
/* FIXME: more than 80 characters of text on one line.
Poor form, but three lines of error message seem
excessive. */
"cannot access file with stale cleartext "
"(still open by another process or file descriptor)\n");
mvfs_log(MFS_LOG_INFO,
"open file: view=%s vob=%s dbid=0x%x%s%s\n",
mfs_vp2vw(vp),
mfs_vp2dev(vp), mfs_vp2dbid(vp),
(pn != NULL) ? " cltxt pname=" : "",
(pn != NULL) ? pn : "");
mnp->mn_vob.cleartext.ostale_logged = 1;
}
EXTERN int
mvfs_translate_path(
char *text,
size_t size,
mvfs_sp_ent_t *table,
int tlen,
char **replacement_p
)
{
register size_t remainder;
register size_t substlen;
register int i;
for (i = 0; i < tlen; i++) {
if (size < table[i].sp_prlen) /* table prefix too long--no match */
continue;
if (STRNCMP(table[i].sp_prefix, text, table[i].sp_prlen) == 0) {
/* The prefix matches--do the substitution. We assume that
* sp_target includes a pathname separator on the
* end---the mount code insures this for us. Allocate
* space for the replacement prefix, the remainder of the path
* component, plus one for NUL terminator, and shuffle the bytes.
*/
remainder = size - table[i].sp_prlen;
substlen = table[i].sp_tglen;
*replacement_p = KMEM_ALLOC(substlen + remainder + 1,
KM_SLEEP|KM_PAGED);
if (*replacement_p == NULL)
return ENOMEM;
BCOPY(table[i].sp_target, *replacement_p, substlen);
BCOPY(text + table[i].sp_prlen,
(*replacement_p) + substlen,
remainder);
(*replacement_p)[substlen + remainder] = '\0';
break;
} else {
*replacement_p = NULL;
}
}
return 0; /* no error */
}
/* MFS_SET_CPNAME - set the cleartext pname in the mnode */
int
mfs_set_cpname(mnp, text, text_size)
register mfs_mnode_t *mnp;
char *text;
size_t text_size;
{
char *cp;
size_t cplen;
struct mfs_mntinfo *mmi;
VNODE_T *vp;
char *trans_text;
int err;
int sep_len = 0; /* length (in characters) of a separator */
ASSERT(MISLOCKED(mnp));
ASSERT(MFS_ISVOB(mnp));
if (mnp->mn_vob.cleartext.nm) {
PN_STRFREE(mnp->mn_vob.cleartext.nm);
}
vp = MTOV(mnp);
mmi = V_TO_MMI(vp);
/*
* Allocate enough room for pname and trailing null.
* I make a copy here to save kernel memory space since the
* size of the text buffer is usually MAXPATHLEN
*/
if (mnp->mn_vob.cleartext.isvob) {
if (mmi->mmi_sptable) {
/* We have a pathname translation prefix table for this VOB.
Apply it to the text name. */
err = mvfs_translate_path(text, text_size,
mmi->mmi_sptable,
mmi->mmi_sptable_len,
&trans_text);
if (err != 0)
return err;
if (trans_text) {
mnp->mn_vob.cleartext.nm = trans_text;
return 0;
}
}
cp = (char *) MFS_STRBUFPN_PAIR_GET_KPN(&(mmi->mmi_svr.lpn)).s;
} else {
#ifdef ATRIA_NT_60
/* Windows only, Vista and above platforms
*
* If we attached to the view storage via a mup enabled name, use that
* instead of the local pathname to the view storage.
*/
if (((cp = VTOM(mnp->mn_hdr.viewvp)->mn_view.svr.net_pn) == NULL))
cp = (char *) MFS_STRBUFPN_PAIR_GET_KPN(
&(VTOM(mnp->mn_hdr.viewvp)->mn_view.svr.lpn)).s;
#else
cp = (char *) MFS_STRBUFPN_PAIR_GET_KPN(
&(VTOM(mnp->mn_hdr.viewvp)->mn_view.svr.lpn)).s;
#endif
}
cplen = STRLEN(cp);
ASSERT(cp);
ASSERT(cplen);
/* Check to see if we will need a separator or not (changes length) */
if ((cplen == 0) || (MVFS_TRAILING_SEPS(cp, cplen) == 0)) {
sep_len = 1;
}
mnp->mn_vob.cleartext.nm = KMEM_ALLOC(cplen+sep_len+text_size+1,
KM_SLEEP|KM_PAGED);
if (mnp->mn_vob.cleartext.nm) {
BCOPY(cp, mnp->mn_vob.cleartext.nm, cplen);
/* Add a separator if not already there */
if (sep_len == 1) {
mnp->mn_vob.cleartext.nm[cplen++] = MVFS_PN_SEP_CHAR;
}
BCOPY(text, &mnp->mn_vob.cleartext.nm[cplen], text_size);
mnp->mn_vob.cleartext.nm[cplen+text_size] = '\0';
return(0);
} else {
return(ENOMEM);
}
}
/*
* MFS_CLEAR_MARK_DOC - mark cleartext vnode as delete on close.
*/
void
mfs_clear_mark_doc(vp)
VNODE_T *vp;
{
mfs_mnode_t *mnp = VTOM(vp);
if (!MFS_ISVOB(mnp)) return; /* Vob objects only */
if (mnp->mn_hdr.realvp) {
mnp->mn_vob.cleartext.delete_on_close = 1;
}
}
/*
* MFS_CLEAR_MARK_PURGE - mark cleartext vnode for purge when inactivated
* This is used when the vnode is invalid (needs to be re-looked up),
* but we think the pathname is probably still valid.
*/
void
mfs_clear_mark_purge(vp)
VNODE_T *vp;
{
mfs_mnode_t *mnp = VTOM(vp);
if (!MFS_ISVOB(mnp)) return; /* Vob objects only */
#ifdef NFSV4_SHADOW_VNODE
if (mnp->mn_hdr.realvp || mnp->mn_hdr.realvp_master) {
#else
if (mnp->mn_hdr.realvp) {
#endif
mnp->mn_vob.cleartext.purge_cvp = 1;
}
}
/*
* MFS_CLEAR_MARK_NAME_PURGE - mark cleartext for purge when inactivated, and
* be sure to flush any name
* This is used when both the pathname and any cleartext vnode are suspected
* of being wrong.
*/
void
mfs_clear_mark_name_purge(vp)
VNODE_T *vp;
{
mfs_mnode_t *mnp = VTOM(vp);
if (!MFS_ISVOB(mnp)) return; /* Vob objects only */
#ifdef NFSV4_SHADOW_VNODE
if (mnp->mn_hdr.realvp || mnp->mn_hdr.realvp_master) {
#else
if (mnp->mn_hdr.realvp) {
#endif
mnp->mn_vob.cleartext.purge_cvp = 1;
}
mnp->mn_vob.cleartext.purge_nm = 1;
}
/*
* MFS_CLEAR_MARK_RWERR - mark cleartext for 'read-write' error
* Will eventually cause pathname and cleartext vnode ptr (if set)
* to be purged on inactive(). In addition, it causes the MVFS
* not to continue I/O, or trust the attributes of the cleartext
* after the read/write error.
*/
void
mfs_clear_mark_rwerr(vp)
VNODE_T *vp;
{
mfs_mnode_t *mnp = VTOM(vp);
if (!MFS_ISVOB(mnp)) return; /* Vob objects only */
#ifdef NFSV4_SHADOW_VNODE
if (mnp->mn_hdr.realvp || mnp->mn_hdr.realvp_master) {
#else
if (mnp->mn_hdr.realvp) {
#endif
mnp->mn_vob.cleartext.purge_cvp = 1;
}
mnp->mn_vob.cleartext.purge_nm = 1;
mnp->mn_vob.cleartext.rwerr = 1;
}
/* MFS_CLEAR_RELE - release cleartext vnode ptr */
void
mfs_clear_rele(
VNODE_T *vp,
CRED_T *cred
)
{
register struct mfs_mnode *mnp;
VNODE_T *cvp;
mnp = VTOM(vp);
ASSERT(MISLOCKED(mnp));
ASSERT(MFS_ISVOB(mnp));
/* Nothing to do if no purges set */
if (!(mnp->mn_vob.cleartext.rwerr ||
mnp->mn_vob.cleartext.purge_nm ||
mnp->mn_vob.cleartext.purge_cvp)) return;
/* Mistake to purge while open_count > 0 */
if (mnp->mn_vob.open_count > 0) {
if (mdb_traps & 0x100)
MDKI_PANIC("purging cleartext while vnode open");
else {
mvfs_log(MFS_LOG_ERR, ("clear_rele: purging cleartext while vnode open\n"));
/*
* We need to preserve the OPEN/CLOSE set
* for the underlying cleartext vnode, so
* let closes it.
*/
if (mnp->mn_hdr.realvp)
mfs_clear_closevp(vp,cred);
}
}
MDB_XLOG((MDB_CLEAROPS,"rele: mnp=%"KS_FMT_PTR_T", cvp=%"KS_FMT_PTR_T", purge=%d\n",
mnp, mnp->mn_hdr.realvp,
mnp->mn_vob.cleartext.purge_cvp));
#ifdef NFSV4_SHADOW_VNODE
if ((mnp->mn_hdr.realvp || mnp->mn_hdr.realvp_master) && mnp->mn_vob.cleartext.purge_cvp) {
#else
if (mnp->mn_hdr.realvp && mnp->mn_vob.cleartext.purge_cvp) {
#endif
/*
* Drop the cleartext vnode.
*/
mvfs_new_cltxt(vp, NULL);
}
/* 06/07/93 - name is cached if no error on vnode */
if (mnp->mn_vob.cleartext.nm && mnp->mn_vob.cleartext.purge_nm) {
/* purge creds if not dropped above by mvfs_new_cltxt() */
if (!mnp->mn_vob.cleartext.purge_cvp)
MVFS_RELEASE_CREDLIST(mnp);
PN_STRFREE(mnp->mn_vob.cleartext.nm);
}
/* Clear some "sticky bits" */
mnp->mn_vob.cleartext.rwerr = 0;
mnp->mn_vob.cleartext.purge_nm = 0;
mnp->mn_vob.cleartext.purge_cvp = 0;
mnp->mn_vob.cleartext.ostale_logged = 0;
/* pages will get flushed when underlying filesystem inactivate is called */
mnp->mn_hdr.clear_dirty = 0;
}
/* MFS_CLEAR_WRITABLE - check if cleartext writable and display error if not */
int
mfs_clear_writable(vp)
VNODE_T *vp;
{
mfs_mnode_t *mnp = VTOM(vp);
ASSERT(MFS_ISVOB(mnp));
ASSERT(MISLOCKED(mnp));
if (MFS_CLRTEXT_RO(mnp)) {
mfs_clearperr(vp, "writing shared cleartext files not allowed", EROFS);
return(0);
}
return(1);
}
/* MVFS_CLEARATTR - update cleartext attributes */
int
mvfs_clearattr(
VNODE_T *vp,
VATTR_T *vap, /* look only at mask to determine behavior */
CRED_T *cred
)
{
int error = 0;
register struct mfs_mnode *mnp;
CLR_VNODE_T *cvp;
struct timeval o_mtime;
struct timeval n_mtime;
VATTR_SIZE_T sz;
int modified = 0;
u_long mask;
VATTR_T va;
mnp = VTOM(vp);
ASSERT(MISLOCKED(mnp));
ASSERT(MFS_ISVOB(mnp));
cvp = mnp->mn_hdr.realvp;
if (cvp != NULL) {
MFS_CHKSP(STK_GETATTR);
ASSERT(!MFS_VPISMFS(MVFS_CVP_TO_VP(cvp)));
VATTR_GET_MTIME_TV(&mnp->mn_vob.cleartext.va, &o_mtime);
sz = VATTR_GET_SIZE(&mnp->mn_vob.cleartext.va);
/*
* NFS performance hack: Some platforms force a synchronous
* write of any delayed/buffered data before returning full
* file attributes via MVOP_GETATTR() (in order to get mtime,
* and perhaps nblocks, updated). If the caller of
* nfs_getattr() only asks for the file size, the underlying
* NFS will not do a flush. So, we see what our caller asked
* for, treating AT_SIZE specially. A request for any other
* attributes, or for unknown attributes (vap == NULL) and we
* do a regular MVOP_GETATTR().
*/
if (vap) {
mask = VATTR_GET_MASK(vap);
if (mask == AT_SIZE) {
VATTR_NULL(&va);
VATTR_SET_MASK(&va, mask);
error = MVOP_GETATTR(MVFS_CVP_TO_VP(cvp), cvp, &va, 0, cred);
if (!error)
VATTR_SET_SIZE(&mnp->mn_vob.cleartext.va,
VATTR_GET_SIZE(&va));
MVFS_FREE_VATTR_FIELDS(&va);
} else {
/*
* don't bother with VATTR_NULL, the MVOP_GETATTR() will
* fill in everything (AT_ALL).
*
* NOTE: mfs_mnclean must free the cleartext vattr data.
*/
VATTR_SET_MASK(&mnp->mn_vob.cleartext.va, AT_ALL);
error = MVOP_GETATTR(MVFS_CVP_TO_VP(cvp), cvp,
&mnp->mn_vob.cleartext.va, 0, cred);
}
} else {
/*
* don't bother with VATTR_NULL, the MVOP_GETATTR() will
* fill in everything (AT_ALL).
*
* NOTE: mfs_mnclean must free the cleartext vattr data.
*/
VATTR_SET_MASK(&mnp->mn_vob.cleartext.va, AT_ALL);
error = MVOP_GETATTR(MVFS_CVP_TO_VP(cvp), cvp,
&mnp->mn_vob.cleartext.va, 0, cred);
}
if (!error) {
/* Sync with wrapper (if required) */
MVFS_WRAP_SYNC_SIZE(vp,
VATTR_GET_SIZE(&mnp->mn_vob.cleartext.va),
TRUE);
/* See if file appears modified */
VATTR_GET_MTIME_TV(&mnp->mn_vob.cleartext.va, &n_mtime);
modified = (!MFS_TVEQ(n_mtime, o_mtime) ||
sz != VATTR_GET_SIZE(&mnp->mn_vob.cleartext.va));
/* Data modified .. don't care unless this is procedure
text in which case we should kill the processes using it. */
if (modified) {
PVN_FLUSHTEXT(vp);
mnp->mn_vob.sync_ctime = 1; /* known out of date */
}
} else {
mfs_clearperr(vp, "cleartext getattr", error);
if (error == ESTALE) {
mfs_clear_mark_purge(vp); /* Mark for purge */
}
}
#ifdef MVFS_DEBUG
VATTR_GET_ATIME_TV(&mnp->mn_vob.cleartext.va, &o_mtime);
VATTR_GET_MTIME_TV(&mnp->mn_vob.cleartext.va, &n_mtime);
MDB_XLOG((MDB_CLEAROPS, "attr: mnp=%"KS_FMT_PTR_T", a/m= %"KS_FMT_TV_SEC_T_D".%"KS_FMT_TV_USEC_T_D"/%"KS_FMT_TV_SEC_T_D".%"KS_FMT_TV_USEC_T_D", mod=%d size= %"MVFS_FMT_VATTR_SIZE_T_D", err=%d\n",
mnp, o_mtime.tv_sec, o_mtime.tv_usec, n_mtime.tv_sec,
n_mtime.tv_usec, modified,
VATTR_GET_SIZE(&mnp->mn_vob.cleartext.va),error));
#endif
}
return(error);
}
/*
* MFS_CLEAROWNER - probe over the wire for cleartext owner
* FIXME: for NT this should become a general "cleartext" access
* check for ability to do 'setattr' ops.
*/
int
mfs_clearowner(
VNODE_T *vp,
u_long mask, /* AT_xxx mask for attr's to probe */
CALL_DATA_T *cd
)
{
int error;
VATTR_T *xvap;
mfs_mnode_t *mnp;
mnp = VTOM(vp);
ASSERT(MISLOCKED(mnp));
ASSERT(MFS_ISVOB(mnp));
if (MFS_REALVP(vp) == NULL) {
return(ENXIO);
}
ASSERT(!MFS_VPISMFS(MFS_REALVP(vp)));
/*
* This routine is fundamentally a risky hack! What we want
* to do is probe over the wire (if a network FS) to the cleartext
* for the rights we will have on operations to that cleartext.
* This can't just be done by looking at the rights because many
* network FS's transform your identity (esp for root) to another
* identity at the server.
*
* Since there is no call to check these access over the wire
* what I do is a "SETATTR" of the fields in question (uid, gid, and/or
* mode) their current values (owner check).
* This has the inherent risk of racing
* with a third party node actually changing that field and
* causing the change by some other node to get lost! What's
* a fella to do...
*/
/* Get latest attributes to narrow race window... */
/*
* don't bother with VATTR_NULL, the MVOP_GETATTR() will
* fill in everything (AT_ALL).
*
* NOTE: mfs_mnclean must free the cleartext vattr data.
*/
VATTR_SET_MASK(&mnp->mn_vob.cleartext.va, AT_ALL);
error = MVOP_GETATTR(MFS_REALVP(vp), MFS_CLRVP(vp),
&mnp->mn_vob.cleartext.va, 0, MVFS_CD2CRED(cd));
if (!error) {
xvap = MVFS_VATTR_ALLOC();
if (xvap == NULL) return(ENOMEM);
VATTR_NULL(xvap);
/* For now, we only support uid/gid/mode */
if (mask & AT_UID) {
MVFS_COPY_UID(xvap, &mnp->mn_vob.cleartext.va, mnp, &error);
}
if (mask & AT_GID && !error)
{
MVFS_COPY_GID(xvap, &mnp->mn_vob.cleartext.va, mnp, &error);
}
if ((mask & AT_MODE) && !error)
{
VATTR_SET_MODE_TYPE(xvap,
VATTR_GET_MODE(&mnp->mn_vob.cleartext.va));
VATTR_SET_MODE_RIGHTS(xvap,
VATTR_GET_MODE(&mnp->mn_vob.cleartext.va));
}
if (!error) {
VATTR_SET_MASK(xvap, mask & (AT_UID|AT_GID|AT_MODE));
error = MVOP_SETATTR(MFS_CVP(vp), xvap, 0, cd, NULL);
/* Normal setuid hack! */
if (error == EPERM && MDKI_CR_IS_SETUID_ROOT(MVFS_CD2CRED(cd)))
{
MDKI_CR_SET_E2RUID(MVFS_CD2CRED(cd));
error = MVOP_SETATTR(MFS_CVP(vp), xvap, 0, cd, NULL);
MDKI_CR_SET_E2ROOTUID(MVFS_CD2CRED(cd));
}
}
MVFS_FREE_VATTR_FIELDS(xvap);
MVFS_VATTR_FREE(xvap);
}
return(error);
}
/*
* MFS_GETCLEARTEXT_NM - fetch cleartext pathname.
* On success, returns with cleartext name valid.
* On failure, cleartext name is NULL.
*/
int
mfs_getcleartext_nm(
VNODE_T *vp,
CALL_DATA_T *cd
)
{
int error;
error = mfs_clnt_cltxt_locked(vp, cd);
if (!error) {
ASSERT(VTOM(vp)->mn_vob.cleartext.nm);
}
return(error);
}
EXTERN void
mvfs_new_cltxt(
VNODE_T *vp,
CLR_VNODE_T *new_cvp
)
{
register struct mfs_mnode *mnp = VTOM(vp);
/* Must prevent paging while dropping realvp */
MVFS_PVN_INH_PAGING(vp);
#ifdef NFSV4_SHADOW_VNODE
/* NFSv4 Compliance: RATLC01011478: NFSv4 introduces the concept of shadow
* vnodes. Refer mvfs_openv_ctx() and the CR for the considerations and
* changes in MVFS to handle shadow vnodes. All the callers of
* mvfs_new_cltxt() have ensured that mn_vob.open_count is 0 before the
* call. If so, realvp_master must have been unset when open count became zero
* (refer mvfs_closev_ctx()). Therefore realvp_master is not expected
* to be set.
*/
if (mnp->mn_hdr.realvp_master) {
mvfs_log(MFS_LOG_ERR,
"new cltxt: unexpected NFSv4 master vnode in cleartext cache. master="
KS_FMT_PTR_T", realvp="KS_FMT_PTR_T"\n",
mnp->mn_hdr.realvp_master, mnp->mn_hdr.realvp);
CVN_RELE(mnp->mn_hdr.realvp_master);
mnp->mn_hdr.realvp_master = NULL;
}
#endif
CVN_RELE(mnp->mn_hdr.realvp); /* drop reference to old cltxt vnode */
mnp->mn_hdr.realvp = new_cvp;
if (mnp->mn_hdr.realvp != NULL) {
/* new_cvp is often NULL, but if it's not we better hold what we're
** saving away. */
CVN_HOLD(mnp->mn_hdr.realvp);
}
MVFS_PVN_ENB_PAGING(vp);
/* drop cache of creds used for lookups */
MVFS_RELEASE_CREDLIST(mnp);
}
/*
* Credentials caching for lookups:
*
* The MVFS caches cleartext vnodes (realvp) in the mnode. To properly
* enforce access controls to the file, it is not sufficient to just
* check access permissions on the realvp, because while the vnode
* itself may have permissive mode bits, there may be components in the
* pathname used to look up the realvp which are not accessible to
* another user. We must look up the cleartext via the name for each
* distinct CRED_T to verify that it has permission to get to the
* cleartext.
*
* In order to avoid looking up the name on every cleartext activation,
* we cache the CRED_Ts which have already been used to activate the
* cleartext on a particular mnode. (The cache is flushed whenever the
* cleartext is deactivated.) If no equivalent CRED_T has looked up
* the name, the caller looks it up and (if successful) adds itself to
* the linked list of validated CRED_Ts for that mnode. Error handling
* is a bit troublesome--if the caller has trouble finding the realvp
* or finds one but it doesn't match the already-known realvp, we have
* to be careful to respond appropriately.
*
* When a CRED_T is being added to an mnode, it is first looked up in a
* system-wide hash table of known CRED_Ts. There may be an equivalent
* CRED_T already known to MVFS, and if so that CRED_T is referenced
* and linked to the mnode. This is particularly desirable for non-CC
* access: the NFS daemon generates new distinct CRED_Ts on each RPC,
* and if we didn't use a common CRED_T for a user, we could be
* referencing a different CRED_T on each mnode touched by the user.
* By sharing as much as possible with already-known CRED_Ts, we hope
* to reduce the memory impact of the cache.
*/
/*
* MFS_GETCLEARTEXT - activate an existing cleartext file for rdwr
* On success, returns with realvp, cleartext name, bits, and attrs
* valid.
* On failure, all of the above are NULL.
*/
int
mfs_getcleartext(
VNODE_T *vp,
CLR_VNODE_T **cvpp,
CALL_DATA_T *cd
)
{
int error = 0;
register struct mfs_mnode *mnp;
CLR_VNODE_T *cvp = NULL; /* Set to known value for Asserts */
timestruc_t stime; /* For statistics */
timestruc_t dtime;
int clookup_retries = 0; /* Clookup retries */
tbs_boolean_t record_creds = TRUE;
CRED_T *fcred;
mnp = VTOM(vp);
ASSERT(MISLOCKED(mnp));
ASSERT(MFS_ISVOB(mnp));
/* For now, regular files only please... */
if (!MVFS_ISVTYPE(vp, VREG)) {
error = EISDIR;
goto out;
}
/*
* This routine returns a validated (non-stale), held, cleartext
* vnode to the caller. It uses multiple levels of caching
* to speed up the operation of going from the
* MFS vnode object to the real vnode object
* The levels are:
* (1) Active held cleartext vnode in mnp->mn_hdr.realvp
* FIXME: add validation to this vnode after a timeout
* by doing an MVOP_OPEN/CLOSE pair or a getattr_otw.
* (2) NYI: for local files, cache a FID (from VOP_FID).
* (3) Just cache the pname. If the lookup fails,
* they dump the pname and get the object again.
* (4) Everything missed - go to the view.
*/
if (mnp->mn_hdr.realvp != NULL) {
/*
* Verify that this caller has permissions to look up the cleartext
* name (alas, requiring a lookup if we don't find their creds
* in our list). See comments above for a full explanation of what's
* going on here.
*/
if (DO_CLTXT_CREDS()) {
MCILOCK(mnp);
fcred = mvfs_find_cred(mnp->mn_vob.cleartext.ok_creds,
MVFS_CD2CRED(cd));
MCIUNLOCK(mnp);
if (fcred == NULL) {
/* needs to run a lookup */
BUMPSTAT(mfs_clearstat.cleargetlkup);
goto findit;
} else {
MDB_XLOG((MDB_CLEAROPS, "mnp %"KS_FMT_PTR_T" found cred %"KS_FMT_PTR_T" as %"KS_FMT_PTR_T"\n",
mnp, MVFS_CD2CRED(cd), fcred));
record_creds = FALSE; /* found them */
}
}
/*
* If still in revalidation window, then just used
* the cached cleartext and update the time validated.
* If the caller of this routine gets an error, he will mark
* the cleartext for purging on inactive, and the revalidate_time
* won't matter. It he doesn't get an error, then the op succeeded
* and so it was right to update the revalidate time.
*/
if (MDKI_CTIME() < mnp->mn_vob.cleartext.revalidate_time) {
/*
* Randomize time a bit with mnode number low-bits.
* To avoid revalidating a pile of cleartexts all at once.
*/
mnp->mn_vob.cleartext.revalidate_time =
MDKI_CTIME() + 3600 + (mnp->mn_hdr.mnum & 0xff);
error = 0;
if (mnp->mn_vob.cleartext.used == 0) {
BUMPSTAT(mfs_clearstat.clearreclaim);
}
goto out;
} else {
/*
* Time expired. Revalidate the cleartext ptr by doing an
* a getattr on the cleartext. You can't do an open/close
* pair (which would force a getattr on the file over NFS),
* because that could mess up file-locks on the cleartext.
* Since this only happens after an egregiously long timeout
* ( ~ 1 hr), I'm willing to bet the getattr will go over the wire
* for NFS.
*/
/*
* don't bother with VATTR_NULL, the MVOP_GETATTR() will
* fill in everything (AT_ALL).
*
* NOTE: mfs_mnclean must free the cleartext vattr data.
*/
VATTR_SET_MASK(&mnp->mn_vob.cleartext.va, AT_ALL);
error = MVOP_GETATTR(MVFS_CVP_TO_VP(mnp->mn_hdr.realvp),
mnp->mn_hdr.realvp,
&mnp->mn_vob.cleartext.va, 0,
MVFS_CD2CRED(cd));
if (!error) {
if (mnp->mn_vob.cleartext.used == 0) {
BUMPSTAT(mfs_clearstat.clearreclaim);
}
goto out; /* Cleartext validated OK */
}
/*
* Release cleartext here iff no active opens.
* If there are opens, then we can't rebind
* the cleartext because we don't know how many
* of what kinds of opens to do.
*/
if (mnp->mn_vob.open_count == 0) {
mvfs_new_cltxt(vp, NULL); /* drop old cltxt */
} else {
/* Can't rebind, but mark for purging on inactive */
mfs_clear_mark_purge(vp);
error = ESTALE;
goto out;
}
}
}
/*
* If we once had a cleartext but didn't find it attached now,
* count that as a miss.
*/
if (mnp->mn_vob.cleartext.hadonce) {
BUMPSTAT(mfs_clearstat.clearreclaim);
BUMPSTAT(mfs_clearstat.clearreclaimmiss);
}
findit:
/*
* Keep stats counter on number of getcleartexts
* that required any lookups
*/
BUMPSTAT(mfs_clearstat.clearget);
/*
* If there is a cleartext pname still cached, then try to
* open that pname. This pname may be stale (or not found),
* in which case we must flush this pname and fall through
* to refetching the cleartext pname from the view.
*
* The important requirement for this to work
* is that no "writable" cleartext is ever scrubbed from
* underneath the MFS. This will lose data which can not be
* reconstructed.
*/
if (mnp->mn_vob.cleartext.nm) {
/* Keep time stats over lookup ops only */
MDKI_HRTIME(&stime);
error = LOOKUP_STORAGE_FILE(MFS_CLRTEXT_RO(mnp),
mnp->mn_vob.cleartext.nm, NULL, &cvp, MVFS_CD2CRED(cd));
MVFS_BUMPTIME(stime, dtime, mfs_clearstat.clearget_time);
if (mnp->mn_hdr.realvp != NULL) {
/* we were looking up to check this caller's permissions */
if (!error) {
/* looked up OK */
if (!CVN_CMP(mnp->mn_hdr.realvp, cvp)) {
/* whoops, lookup intended for permission checking only,
* yet returned a different (effective) vnode!
* If no active opens, we can drop the old
* cleartext vp, as is done in other cases here, and
* use the new. Case like this can happen if old ctxt is
* scrubbed and ctxt gets re-created by a different client.
*/
MDB_XLOG((MDB_CLEAROPS, "getcleartext: mnp %"
KS_FMT_PTR_T" cvp mismatch, old %"
KS_FMT_PTR_T" new %"KS_FMT_PTR_T"\n",
mnp, mnp->mn_hdr.realvp, cvp));
if (mnp->mn_vob.open_count == 0) {
/* drop old ctxt & creds, take extra hold on the new */
mvfs_new_cltxt(vp, cvp);
mnp->mn_vob.cleartext.rwerr = 0;