-
Notifications
You must be signed in to change notification settings - Fork 1
/
mvfs_rpcutl.c
1768 lines (1600 loc) · 62 KB
/
mvfs_rpcutl.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 1991, 2013. */
/*
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_rpcutl.c */
#include "mvfs_systm.h"
#include "tbs_errno.h"
#include "mvfs.h"
#include <albd_rpc_kernel.h>
STATIC int
mvfs_find_ccs(int largeinit);
STATIC int MVFS_NOINLINE
mfscall_int(
struct mfs_callinfo *trait,
int op,
XID_T *xidp,
struct mfs_svr *svr,
struct mfs_retryinfo *rinfo,
xdrproc_t xdrargs,
void *argsp,
xdrproc_t xdrres,
void *resp,
CRED_T *cred,
CLIENT *client,
VNODE_T *view
);
STATIC void
mfs_clnt_free_int(
CLIENT *,
VNODE_T *
);
EXTERN int mfs_view_getstatus(void *resp);
EXTERN XID_T mfs_view_getxid(void *resp);
EXTERN void mfs_view_setxid(void *req, time_t bt, XID_T xid);
EXTERN int mfs_albd_getstatus(void *resp);
EXTERN XID_T mfs_albd_getxid(void *resp);
EXTERN void mfs_albd_setxid(void *req, time_t bt, XID_T xid);
STATIC ks_uint32_t mvfs_get_boottime(void);
#if defined(MVFS_COMMON_ALLOC_XID)
EXTERN ks_uint32_t mvfs_alloc_xid(void);
#endif
/* MVFS_CLNT_INIT - init client cache */
/* Note that while this function has code that will try to reduce the cache
* size if memory is not available, the KM_ALLOC call is made with KM_SLEEP
* set. This means that we are more likely to just hang waiting for memory
* if we are trying to oversubscribe memory. The setcache code does use the
* KM_NOSLEEP so that if someone is trying to tune their system, they will
* get an error and not a hang.
*/
int
mvfs_clnt_init(mvfs_cache_sizes_t *mma_sizes)
{
int old_size;
int system_def_ccs;
mvfs_common_data_t *mcdp = MDKI_COMMON_GET_DATAP();
INITLOCK(&(mcdp->mvfs_rpc.mfs_client_lock), "mfscllk");
/*
* mvfs_client_cache_size must be large enough to prevent allocating
* new rpchandles on the fly in order to have good performance.
*/
mcdp->mvfs_init_sizes.size[MVFS_SETCACHE_RPCHANDLES] = mcdp->mvfs_client_cache_size;
system_def_ccs = mvfs_find_ccs(mcdp->mvfs_largeinit);
MVFS_SIZE_DEFLOAD_NONZERO(mcdp->mvfs_client_cache_size, mma_sizes, RPCHANDLES,
system_def_ccs);
while (TRUE) {
old_size = mcdp->mvfs_client_cache_size * sizeof(client_cache_t);
mcdp->mvfs_rpc.mvfs_client_cache = (client_cache_t *)
KMEM_ALLOC(mcdp->mvfs_client_cache_size * sizeof(client_cache_t),
KM_SLEEP);
if (mcdp->mvfs_rpc.mvfs_client_cache != NULL) {
/*
* Success
*/
BZERO(mcdp->mvfs_rpc.mvfs_client_cache,
mcdp->mvfs_client_cache_size * sizeof(client_cache_t));
mcdp->mvfs_rpc.mvfs_client_cache_family = AF_UNSPEC;
break;
/*
* Size was too large, let's try a smaller value.
*/
} else if (mcdp->mvfs_client_cache_size > system_def_ccs) {
/* Try the system calculated default */
mcdp->mvfs_client_cache_size = system_def_ccs;
} else if (mcdp->mvfs_client_cache_size > CLIENT_CACHE_SIZE_SMALL) {
/* Try minium */
mcdp->mvfs_client_cache_size = CLIENT_CACHE_SIZE_SMALL;
} else {
mvfs_log(MFS_LOG_WARN, "Failed to allocate %d bytes for caching of client handles\n",
mcdp->mvfs_client_cache_size * sizeof(client_cache_t));
mcdp->mvfs_client_cache_size = 0;
return ENOMEM;
}
mvfs_log(MFS_LOG_WARN, "Failed to allocate %d bytes for Client handles lowering size to %d\n",
old_size, mcdp->mvfs_client_cache_size * sizeof(client_cache_t));
}
return 0;
}
/* MVFS_CLNT_DESTROY - free up client cache */
void
mvfs_clnt_destroy()
{
register int i;
mvfs_common_data_t *mcdp = MDKI_COMMON_GET_DATAP();
MVFS_LOCK(&(mcdp->mvfs_rpc.mfs_client_lock));
/* clean up the client handles. */
for (i = 0; i < mcdp->mvfs_client_cache_size; i++) {
ASSERT(!mcdp->mvfs_rpc.mvfs_client_cache[i].inuse);
if (mcdp->mvfs_rpc.mvfs_client_cache[i].client)
mfs_clnt_free_int(mcdp->mvfs_rpc.mvfs_client_cache[i].client, NULL);
}
KMEM_FREE(mcdp->mvfs_rpc.mvfs_client_cache,
mcdp->mvfs_client_cache_size*sizeof(client_cache_t));
mcdp->mvfs_rpc.mvfs_client_cache = NULL; /* clean up any traces. */
mcdp->mvfs_client_cache_size = 0;
MVFS_UNLOCK(&(mcdp->mvfs_rpc.mfs_client_lock));
FREELOCK(&(mcdp->mvfs_rpc.mfs_client_lock));
mcdp->mvfs_client_cache_size = mcdp->mvfs_init_sizes.size[MVFS_SETCACHE_RPCHANDLES];
}
/*
* Allocate a different size for the RPC cache, if needed.
* Note that this code will not sleep waiting for memory to prevent the
* process from hanging if this request would oversubscribe memory. The
* initialization code does use KM_SLEEP. The assumption is that the
* value used at startup has been tuned and it is reasonable to wait for
* the needed memory.
* Any in-use client handles will get destroyed/freed when the using thread
* returns the CLIENT * via a call to mfs_clnt_free(). [The client ptr will
* not appear in any client_cache_t in the new array, so the handle will be
* freed.] Any handles not in use must be freed.
*/
int
mvfs_rpc_setcaches(szp)
mvfs_cache_sizes_t *szp;
{
register int i;
client_cache_t *newcache;
u_long newsize;
mvfs_common_data_t *mcdp = MDKI_COMMON_GET_DATAP();
if (MVFS_SIZE_VALID(szp, RPCHANDLES) &&
szp->size[MVFS_SETCACHE_RPCHANDLES] != mcdp->mvfs_client_cache_size)
{
newsize = szp->size[MVFS_SETCACHE_RPCHANDLES];
newcache = (client_cache_t *) KMEM_ALLOC(newsize * sizeof(*newcache),
KM_NOSLEEP);
if (newcache == NULL)
return(ENOMEM);
BZERO(newcache, newsize * sizeof(*newcache));
MVFS_LOCK(&(mcdp->mvfs_rpc.mfs_client_lock));
/*
* We need to free any client handles not in use.
*/
for (i = 0; i < mcdp->mvfs_client_cache_size; i++) {
if (mcdp->mvfs_rpc.mvfs_client_cache[i].client &&
!mcdp->mvfs_rpc.mvfs_client_cache[i].inuse)
mfs_clnt_free_int(mcdp->mvfs_rpc.mvfs_client_cache[i].client, NULL);
}
KMEM_FREE(mcdp->mvfs_rpc.mvfs_client_cache,
mcdp->mvfs_client_cache_size*sizeof(client_cache_t));
mcdp->mvfs_client_cache_size = newsize;
mcdp->mvfs_rpc.mvfs_client_cache_family = AF_UNSPEC;
mcdp->mvfs_rpc.mvfs_client_cache = newcache;
MVFS_UNLOCK(&(mcdp->mvfs_rpc.mfs_client_lock));
}
return 0;
}
int
mvfs_rpc_getcaches(
mvfs_cache_sizes_t *szp
)
{
mvfs_common_data_t *mcdp = MDKI_COMMON_GET_DATAP();
szp->size[MVFS_SETCACHE_RPCHANDLES] = mcdp->mvfs_client_cache_size;
return 0;
}
int
mvfs_rpc_compute_caches(
ks_int32_t scale_factor,
mvfs_cache_sizes_t *szp
)
{
if ((szp->mask & MVFS_CACHEBIT(RPCHANDLES)) == 0) {
szp->size[MVFS_SETCACHE_RPCHANDLES] = mvfs_find_ccs(scale_factor);
szp->mask |= MVFS_CACHEBIT(RPCHANDLES);
}
return 0;
}
int
mvfs_rpc_count(usage)
mvfs_cache_usage_t *usage;
{
register int i, rval;
client_cache_t *clientp;
mvfs_common_data_t *mcdp = MDKI_COMMON_GET_DATAP();
MVFS_LOCK(&(mcdp->mvfs_rpc.mfs_client_lock));
for (i=0, rval=0, clientp = mcdp->mvfs_rpc.mvfs_client_cache;
i < mcdp->mvfs_client_cache_size;
i++, clientp++) {
if ((clientp->client != NULL))
rval++;
}
MVFS_UNLOCK(&(mcdp->mvfs_rpc.mfs_client_lock));
usage->cache_usage[MVFS_CACHE_INUSE][MVFS_CACHE_RPCHANDLES] = rval;
usage->cache_usage[MVFS_CACHE_MAX][MVFS_CACHE_RPCHANDLES] = i;
return 0;
}
/* MVFS_CLNT_GET - get a client handle for an MFS remote call */
int
mvfs_clnt_get(
struct mfs_callinfo *trait,
struct mfs_svr *svr,
struct mfs_retryinfo *rinfo,
CRED_T *cred,
VNODE_T *view,
CLIENT **client_p
)
{
CLIENT *client = NULL;
ks_uint32_t lboottime = 0; /* Initialize to avoid a compiler warning. */
int retrans;
int error = 0;
SPL_T s;
int i;
int found;
int waited = 0;
client_cache_t *clientp;
client_cache_t *entryp = NULL;
MDKI_CLNTKUDP_ADDR_T addr;
mvfs_common_data_t *mcdp = MDKI_COMMON_GET_DATAP();
BUMPSTAT(mfs_clntstat.clntget);
if (view)
BUMP_VCLNTSTATV(view, clntstat.clntget);
retrans = (svr->down) ? 1 : rinfo->retries;
/* Allocate a handle. */
if ((mcdp->mvfs_rpc.mvfs_client_cache_family == svr->addr.ks_ss_s.sa_family))
{
MVFS_LOCK(&(mcdp->mvfs_rpc.mfs_client_lock));
clientp = mcdp->mvfs_rpc.mvfs_client_cache;
for (i=0; i<mcdp->mvfs_client_cache_size; i++) {
if ((clientp->client != NULL) &&
(clientp->proto == trait->proto) &&
(clientp->version == trait->version) &&
(!clientp->inuse)) {
clientp->inuse = 1;
clientp->used++;
client = clientp->client;
clientp->boottime = mvfs_get_boottime();
/* We should find a way to ASSERT the client handle's proto/version
match the cached records and the requested traits */
error = MDKI_CLNTKUDP_INIT(client, &svr->addr.ks_ss_s, retrans, cred,
(!rinfo->nointr), &addr, trait->proto,
trait->version, &svr->knc);
if (error != 0) {
MVFS_UNLOCK(&(mcdp->mvfs_rpc.mfs_client_lock));
return error;
}
MDKI_CLNTKUDP_INTR(client, !rinfo->nointr);
break;
}
clientp++;
}
MVFS_UNLOCK(&(mcdp->mvfs_rpc.mfs_client_lock));
}
if (!client) {
getclient:
error = MDKI_CLNTKUDP_CREATE(&svr->knc, &svr->addr.ks_ss_s, trait,
retrans, (!rinfo->nointr), cred, &client);
/*
* Compute the boottime to go with this CLIENT handle.
*/
lboottime = mvfs_get_boottime();
switch (error) {
case 0:
break;
case EAFNOSUPPORT:
case EPFNOSUPPORT:
/* don't log those errors, and don't retry--just fail immediately */
*client_p = NULL;
return error;
default:
if (waited == 0) {
mvfs_log(MFS_LOG_WARN,
"cannot allocate RPC client handle, retrying (err %d)\n", error);
MDKI_USECDELAY(1000000*5); /* wait 5 sec */
waited++;
goto getclient;
}
mvfs_log(MFS_LOG_ERR,
"cannot allocate RPC client handle, giving up (err %d)\n", error);
/* Fall through */
/* If normal errors have retried and failed again, they will
* fall through to this case. If the error is ERESTART
* (or ERESTARTSYS on Linux) then it means that we have
* received a signal. We will not retry, just log the event
* and get out.
* It turns out that HP-UX does not have ERESTART, so be
* careful with this code, the cases below may not exist
* so this would be a bad place for a break statement.
*/
#ifdef ERESTART
case ERESTART:
#endif
#ifdef ERESTARTSYS
case ERESTARTSYS:
#endif
mvfs_log(MFS_LOG_ERR,
"cannot allocate RPC client handle, giving up (err %d)\n", error);
*client_p = NULL; /* This is bad! */
return error;
}
BUMPSTAT(mfs_clntstat.clntcreate);
if (view)
BUMP_VCLNTSTATV(view, clntstat.clntcreate);
found = 0;
if ((mcdp->mvfs_rpc.mvfs_client_cache_family ==
svr->addr.ks_ss_s.sa_family) ||
(mcdp->mvfs_rpc.mvfs_client_cache_family ==
AF_UNSPEC))
{
MVFS_LOCK(&(mcdp->mvfs_rpc.mfs_client_lock));
clientp = mcdp->mvfs_rpc.mvfs_client_cache;
for (i=0; i<mcdp->mvfs_client_cache_size; i++) {
if (!clientp->client) {
if (mcdp->mvfs_rpc.mvfs_client_cache_family == AF_UNSPEC)
{
mcdp->mvfs_rpc.mvfs_client_cache_family =
svr->addr.ks_ss_s.sa_family;
}
clientp->inuse = 1;
clientp->client = client;
clientp->boottime = lboottime;
clientp->proto = trait->proto;
clientp->version = trait->version;
clientp->used++;
found = 1;
break;
}
if (!entryp && !clientp->inuse)
entryp = clientp;
clientp++;
}
if (!found) {
if (entryp) {
entryp->inuse = 1;
mfs_clnt_free_int(entryp->client, view);
entryp->client = client;
entryp->boottime = lboottime;
entryp->proto = trait->proto;
entryp->version = trait->version;
entryp->used++;
}
}
MVFS_UNLOCK(&(mcdp->mvfs_rpc.mfs_client_lock));
}
}
if (!MDKI_CLNT_AUTH_VALID(client))
MDKI_PANIC("mfs_clnt_alloc: null auth");
*client_p = client;
return 0;
}
/* MVFS_CLNT_FREE - free up an allocated client handle */
void
mvfs_clnt_free(client, error, view)
CLIENT *client;
int error;
VNODE_T *view;
{
SPL_T s;
int i;
client_cache_t *clientp;
mvfs_common_data_t *mcdp = MDKI_COMMON_GET_DATAP();
BUMPSTAT(mfs_clntstat.clntfree);
if (view)
BUMP_VCLNTSTATV(view, clntstat.clntfree);
/*
* Always free the client resources
* because if we don't find it in the table
* we will destroy it.
*/
MDKI_CLNTKUDP_FREE(client);
MVFS_LOCK(&(mcdp->mvfs_rpc.mfs_client_lock));
clientp = mcdp->mvfs_rpc.mvfs_client_cache;
for (i=0; i<mcdp->mvfs_client_cache_size; i++) {
if (clientp->client == client) {
ASSERT(clientp->inuse);
clientp->inuse = 0;
if (!error) {
ASSERT(MDKI_CLNT_AUTH_VALID(client));
MVFS_UNLOCK(&(mcdp->mvfs_rpc.mfs_client_lock));
return;
}
clientp->client = NULL;
break;
}
clientp++;
}
MVFS_UNLOCK(&(mcdp->mvfs_rpc.mfs_client_lock));
mfs_clnt_free_int(client, view);
}
/* MFS_CLNT_FREE_INT - free up an allocated client handle */
STATIC void
mfs_clnt_free_int(client, view)
CLIENT *client;
VNODE_T *view;
{
MDKI_CLNTKUDP_DESTROY(client);
BUMPSTAT(mfs_clntstat.clntdestroy);
if (view)
BUMP_VCLNTSTATV(view, clntstat.clntdestroy);
}
/*
* Find the appropriate default setting for mvfs_client_cache_size based on
* mvfs_largeinit
*/
STATIC int
mvfs_find_ccs(int largeinit)
{
int ccs;
/*
* For large-memory MP systems mvfs_client_cache_size needs to grow rapidly.
* But we don't want to change the number allocated by default on smaller
* systems (defined by mvfs_largeinit <= 2).
*/
if ((largeinit >= 0) && (largeinit <= 2)) {
ccs = (largeinit + 1 ) * CLIENT_CACHE_SIZE_SMALL;
} else {
/* For larger systems, increase it by default */
ccs = (largeinit + 1) * CLIENT_CACHE_SIZE_LARGE;
/* But don't automatically set it too large */
if (ccs > CLIENT_CACHE_SIZE_AUTOMAX)
ccs = CLIENT_CACHE_SIZE_AUTOMAX;
}
return (ccs);
}
/*
* Routines to fetch/set pkt parameters
*/
int
mfs_view_getstatus(resp)
void *resp;
{
return (((view_hdr_reply_t *)resp)->status);
}
XID_T
mfs_view_getxid(resp)
void *resp;
{
return(((view_hdr_reply_t *)resp)->xid);
}
void
mfs_view_setxid(req, bt, xid)
void *req;
time_t bt;
XID_T xid;
{
((view_hdr_req_t *)req)->boot_time = bt;
((view_hdr_req_t *)req)->xid = xid;
}
int
mfs_albd_getstatus(resp)
void *resp;
{
return (((albd_hdr_reply_t *)resp)->status);
}
XID_T
mfs_albd_getxid(resp)
void *resp;
{
return(((albd_hdr_reply_t *)resp)->xid);
}
void
mfs_albd_setxid(req, bt, xid)
void *req;
time_t bt;
XID_T xid;
{
((albd_hdr_req_t *)req)->boot_time = bt;
((albd_hdr_req_t *)req)->xid = xid;
}
/* Routine to initialize or get current boottime */
STATIC ks_uint32_t
mvfs_get_boottime(void)
{
mvfs_common_data_t *mcdp = MDKI_COMMON_GET_DATAP();
if (mcdp->mvfs_boottime == 0) {
mcdp->mvfs_boottime = MDKI_CTIME();
}
return(mcdp->mvfs_boottime);
}
#if defined(MVFS_COMMON_ALLOC_XID)
/* Routine to allocate unique XID for RPCs between MVFS and CC servers */
ks_uint32_t
mvfs_alloc_xid(void)
{
ks_uint32_t xid = 0;
mvfs_common_data_t *mcdp = MDKI_COMMON_GET_DATAP();
retry:
if (MDKI_ATOMIC_CAS_UINT32(&(mcdp->mvfs_xid), MVFS_XID_ULIMIT, 0)) {
mcdp->mvfs_boottime = MDKI_CTIME();
return((ks_uint32_t)MDKI_ATOMIC_INCR_UINT32_NV(&(mcdp->mvfs_xid)));
} else {
xid = MDKI_ATOMIC_READ_UINT32(&(mcdp->mvfs_xid));
if ((xid != MVFS_XID_ULIMIT) &&
MDKI_ATOMIC_CAS_UINT32(&(mcdp->mvfs_xid), xid, xid + 1)) {
return(xid + 1);
} else {
goto retry;
}
}
}
#endif
/*
* Maximum timeout in 10'ths of seconds.
* BACKOFF backs off by powers of two but is clamped to the max
* Issues:
* Max should be large enough so longest transaction not
* a problem.
* Max should not be so long that the user gets impatient waiting
* for a "quit" to take effect.
*
* Protocol Notes:
* The protocol for detecting duplicates at the server is to
* compare the XID with the latest XID serviced for that same
* socket number. The server only keeps a copy of the last
* request serviced to reply on a duplicate pkt. Therefore,
* It is imperative that for a given socket
* (e.g. client handle), that XID's always monotonically
* increase and that old transactions are completed before a new
* one is started. This is done by always grabbing the socket first
* before allocating the XID (XID's are monotonically increasing
* per machine in the order they are grabbed). The same socket
* must be held around until the call either succeeds or
* failure is assumed. Grabbing the socket first prevents
* any scheduling/locking anomalies from causing two processes to get
* XID's in one order, and then use them in a different order
* to the server.
*/
#define MVFS_MAXTIME 300
#define BACKOFF(tim) ((((tim) << 1) > MVFS_MAXTIME) ? MVFS_MAXTIME : ((tim) << 1))
/* VIEW SERVER TABLES */
/* Base time shift for each call. This allows the user
to specify one timeout value for the server, and adjusts
for those calls we know are more timeconsuming. Too short
a timeout for "long" calls would result in unnecessary retries.
A '*' next to the opname in the comment field indicates that
this op is not currently used by the MFS */
int mfs_view_timeshft[VIEW_NUM_PROCS] = {
0, /* NULL */
0, /* 001: VIEW_CONTACT* */
0, /* 002: VIEW_SERVER_EXIT* */
0, /* 003: VIEW_SETATTR */
0, /* 004: VIEW_CREATE */
0, /* 005: VIEW_REMOVE */
0, /* 006: VIEW_RENAME */
0, /* 007: VIEW_SYMLINK */
0, /* 008: VIEW_MKDIR */
0, /* 009: VIEW_RMDIR */
0, /* 010: VIEW_READDIR */
0, /* 011: VIEW_STATFS */
2, /* 012: VIEW_CLTXT */
1, /* 013: VIEW_CHANGE_OID */
0, /* 014: VIEW_READDIR_EXT */
1, /* 015: VIEW_GPATH */
0, /* 016: VIEW_REVALIDATE */
0, /* 017: VIEW_CLTXT_PNAME* */
1, /* 018: VIEW_CHANGE_MTYPE */
0, /* 019: VIEW_INVALIDATE_UUID */
0, /* 020: VIEW_LINK */
0, /* 021: VIEW_LOOKUP */
0, /* 022: VIEW_GETATTR */
1, /* 023: VIEW_REPLICA_ROOT */
0, /* 024: VIEW_LOOKUP_EXT* */
0, /* 025: VIEW_CREATE_CONTAINER* */
0, /* 026: VIEW_REMOVE_CONTAINER* */
0, /* 027: VIEW_RENAME_CONTAINER* */
0, /* 028: VIEW_WINK* */
0, /* 029: VIEW_READLINK */
0 /* 030- : Others* */
};
char *mfs_viewopnames[VIEW_NUM_PROCS] = {
"nil",
"contact", /* 001: */
"srv_exit", /* 002: */
"setattr", /* 003: MVFS */
"create", /* 004: MVFS */
"remove", /* 005: MVFS */
"rename", /* 006: MVFS */
"symlink", /* 007: MVFS */
"mkdir", /* 008: MVFS */
"rmdir", /* 009: MVFS */
"readdir", /* 010: MVFS */
"null", /* 011: */
"getcleartext", /* 012: MVFS */
"choid", /* 013: MVFS */
"rddir_ext", /* 014: MVFS */
"gpath", /* 015: MVFS */
"revalidate", /* 016: MVFS */
"cltxt_pname", /* 017: */
"change_mtype", /* 018: MVFS */
"invalidate", /* 019: MVFS */
"link", /* 020: MVFS */
"lookup_v6", /* 021: MVFS */
"getattr", /* 022: MVFS */
"replica_root", /* 023: MVFS */
"lookup_ext_v6", /* 024: */
"create_cntr", /* 025: */
"remove_cntr", /* 026: */
"rename_cntr", /* 027: */
"wink", /* 028: */
"readlink", /* 029: MVFS */
"view_reload_spec", /* 030: */
"view_bld_session_free", /* 031: */
"view_events_get_vob", /* 032: */
"view_vob_create", /* 033: */
"view_find_oid", /* 034: */
"view_sec_rule", /* 035: */
"view_white_out", /* 036: */
"view_unwhite_out", /* 037: */
"view_bld_get_ref_tim", /* 038: */
"view_recover", /* 039: */
"view_dump", /* 040: */
"view_load", /* 041: */
"view_cr_get", /* 042: */
"view_do_promote", /* 043: */
"view_do_purge_cltxt", /* 044: */
"view_vob_save", /* 045: */
"view_bld_session_flags", /* 046: */
"view_get_text_mode", /* 047: */
"view_cr_add_vob_ref_uuid", /* 048: */
"view_cr_rm_vob_ref_uuid", /* 049: */
"view_vob_get_path_uuid", /* 050: */
"view_vob_rm_path_uuid", /* 051: */
"view_vob_recover_obj_uuid", /* 052: */
"view_cr_save", /* 053: */
"view_getprop", /* 054: */
"view_setprop", /* 055: */
"view_getlic", /* 056: */
"view_inventory_uuids", /* 057: */
"view_setwork_get_vobs", /* 058: */
"view_server_exit_rmtag", /* 059: */
"view_statistics", /* 060: */
"view_set_values", /* 061: */
"view_inventory_vobs_uuids", /* 062: */
"view_setwork_set_vobs", /* 063: */
"view_setwork_cleanup", /* 064: */
"view_hlink_set_vobs", /* 065: */
"view_hlink_cleanup", /* 066: */
"view_hlink_get_vobs", /* 067: */
"view_ws_create_db", /* 068: */
"view_frz_get_scopes", /* 069: */
"view_frz_get_freeze_state", /* 070: */
"view_frz_get_reload_info", /* 071: */
"view_ws_begin_load_sess", /* 072: */
"view_ws_end_load_sess", /* 073: */
"view_frx_ok_to_set_spec", /* 074: */
"view_ws_upd_wso_attrs", /* 075: */
"view_ws_get_scope_aliases", /* 076: */
"view_ws_get_unvisited_wsos", /* 077: */
"view_ws_invalidate_obj", /* 078: */
"view_ws_unload_one_obj", /* 079: */
"view_frz_get_num_frozen", /* 080: */
"view_ws_get_obj_scopes", /* 081: */
"view_ws_rename_obj", /* 082: */
"view_ws_is_frz_obj", /* 083: */
"view_reload_spec_ext", /* 084: */
"view_ws_is_mod_wso_ext", /* 085: */
"view_protect_stg_as_clnt", /* 086: */
"view_protect_stg_check", /* 087: */
"view_unprotect_stg_as_clnt", /* 088: */
"view_unprotect_stg_check", /* 089: */
"view_reparent_vob", /* 090: */
"view_getown_sid", /* 091: */
"view_ws_load_one_obj", /* 092: */
"view_ws_load_one_slink", /* 093: */
"view_get_config_spec", /* 094: */
"view_set_config_spec", /* 095: */
"view_replace_container", /* 096: */
"view_protect_container", /* 097: */
"view_fstat_container", /* 098: */
"view_ws_unload_one_obj_ext", /* 099: */
"view_lookup", /* 100: MVFS */
"view_lookup_ext", /* 101: */
"view_dos_to_unsharable", /* 102: */
"view_get_dos", /* 103: */
"view_dos_found" /* 104: */
};
int mfs_viewopmax = VIEW_NUM_PROCS;
/*
* Keep histogram of RPC delays for following.
* Note that separate histogram is kept for
* cleartext fetch RPC which we expect might take a long time.
* This statically initialized structure is used only as template
* for quick initialization of corresponding structure in mvfs_statistics_data.
*/
struct mfs_rpchist mvfs_init_viewophist = {
{
{ 0, 50000000 }, /* .05 secs */
{ 0, 100000000 }, /* .1 secs */
{ 0, 250000000 }, /* .25 secs */
{ 0, 500000000 }, /* .5 secs */
{ 1, 0 }, /* 1 sec */
{ 2, 0 }, /* 2 sec */
{ 3, 0 }, /* 3 sec */
{ 4, 0 }, /* 4 sec */
{ 8, 0 }, /* 8 sec */
{ 16, 0 }, /* 16 sec */
{ 24, 0 }, /* 24 sec */
{ 32, 0 }, /* 32 sec */
{ 40, 0 }, /* 40 sec */
{ 48, 0 }, /* 48 sec */
{ 64, 0 }, /* 64 sec */
{ 0x7fffffff, 0 }, /* Many moons */
},
{0},
{0},
{ {0} },
MFS_RPCHIST_VERS
};
/* ALBD tables */
int mfs_albd_timeshft[ALBD_NUM_PROCS] = {
0, /* null */
0, 0, 0, 0, /* contact, register, find, idle */
0, 0, 0, 0, /* busy, hostaddr, localpath, licensechk */
0, 0, 0, 0, /* stats, revoke, schedinfo, rembuild */
0, 0, 0, 0, /* rgy_getid, rgy_findbystr, rgy_findbyuuid, rgy_get */
0, 0, 0, 0, /* rgy_add, rgy_rem, svr_alt_uuid, rgy_chk_access */
0, /* rgy_get_dtm */
};
char *mfs_albdopnames[ALBD_NUM_PROCS] = {
"nil",
"contact", "register", "find_svr", "svridle",
"svrbusy", "host2addr", "localpath", "licensechk",
"licstats", "licrevoke", "schedinfo", "rembuild",
"rgy_getid", "rgy_findbystr", "rgy_findbyuuid", "rgy_get",
"rgy_add", "rgy_remove", "svr_alt_uuid", "rgy_chk_access",
"rgy_get_dtm",
};
/* Trait definitions */
struct mfs_callinfo mfs_vwcallstruct = {
VIEW_SERVER, VIEW_SERVER_VERS,
"View",
mfs_viewopnames,
mfs_view_timeshft,
mfs_view_getstatus,
mfs_view_getxid,
mfs_view_setxid,
};
struct mfs_callinfo mfs_albdcallstruct = {
ALBD_SERVER, ALBD_SERVER_VERS,
"Albd",
mfs_albdopnames,
mfs_albd_timeshft,
mfs_albd_getstatus,
mfs_albd_getxid,
mfs_albd_setxid,
};
struct mfs_callinfo *mfs_viewcall = &mfs_vwcallstruct;
struct mfs_callinfo *mfs_albdcall = &mfs_albdcallstruct;
/*
* MVFS_REBINDSVR_PORT - rebind a server's port number
*/
int
mvfs_bindsvr_port(
struct mfs_svr *svr,
VFS_T *vfsp,
CRED_T *cred,
VNODE_T *vw
)
{
/* Declare a type so we can do one allocation to save stack space. */
struct {
struct mfs_svr albd_svr;
struct mfs_retryinfo albd_retry;
albd_find_server_req_t ra;
albd_find_server_v70_reply_t rr_v70;
albd_find_server_reply_t rr;
} *alloc_unitp;
struct mfs_svr *albd_svrp;
struct mfs_retryinfo *albd_retryp;
albd_find_server_req_t *rap;
albd_find_server_v70_reply_t *rrp_v70;
albd_find_server_reply_t *rrp;
mvfs_viewroot_data_t *vrdp = MDKI_VIEWROOT_GET_DATAP();
u_int num_ports;
short real_family;
int error;
/* Must have viewroot vfs for ALBD port number */
if ((vrdp->mfs_viewroot_vfsp) == NULL) return(ECONNREFUSED);
if ((alloc_unitp = KMEM_ALLOC(sizeof(*alloc_unitp), KM_SLEEP)) == NULL) {
return(ENOMEM);
}
albd_svrp = &(alloc_unitp->albd_svr);
albd_retryp = &(alloc_unitp->albd_retry);
rap = &(alloc_unitp->ra);
rrp_v70 = &(alloc_unitp->rr_v70);
rrp = &(alloc_unitp->rr);
albd_svrp->down = 0;
albd_svrp->dprinted = albd_svrp->uprinted = 0;
albd_svrp->svrbound = 1;
albd_svrp->addr = svr->addr; /* View's host addr */
/* We just copied the whole address above, including the family. Now we're
** going to set the port for the ALBD server from the mount info and assume
** the rest of the address is OK. Remember, in mfs_vmount_subr() we
** "misused" the viewroot mmi_svr.addr to save the ALBD port in the IPv4
** port field (and we assume the port is the same for IPv4 and IPv6).
*/
switch (albd_svrp->addr.ks_ss_s.sa_family) {
case AF_INET:
albd_svrp->addr.ks_ss_sin4.sin_port =
VFS_TO_MMI(vrdp->mfs_viewroot_vfsp)->mmi_svr.addr.ks_ss_sin4.sin_port;
break;
case AF_INET6:
albd_svrp->addr.ks_ss_sin6.sin6_port =
VFS_TO_MMI(vrdp->mfs_viewroot_vfsp)->mmi_svr.addr.ks_ss_sin4.sin_port;
break;
default:
error = EPFNOSUPPORT;
goto cleanup;
}
MFS_INIT_STRBUFPN_PAIR_IN(&(albd_svrp->lpn), &("albd"[0]), &("albd"[0]));
albd_svrp->host = svr->host;
albd_svrp->rpn = "albd";
albd_svrp->uuid = TBS_UUID_NULL;
if (vfsp != NULL) {
*albd_retryp = VFS_TO_MMI(vfsp)->mmi_retry;/* Retry params from VOB */
} else {
/* try just once; this branch is for mfs_clnt_inval() */
albd_retryp->soft = 1;
albd_retryp->timeo = MFSMNT_TIMEO_DEFAULT;
albd_retryp->retries = MFSMNT_RETRANS_DEFAULT;
albd_retryp->nointr = 0;
albd_retryp->mbz = 0;
}
albd_retryp->rebind = 0; /* But no rebind */
/* Call the albd to ask for the server's port */
rap->hdr.xid = (u_long)MDKI_ALLOC_XID();
rap->rpc_trait.rpc_prog = VIEW_SERVER;
rap->rpc_trait.rpc_ver = VIEW_SERVER_VERS;
rap->rpc_trait.protocol = ALBD_PROTOCOL_UDP;
rap->uuid = svr->uuid;
rap->path = svr->rpn;
if ((rrp->path = KMEM_ALLOC(MAXPATHLEN, KM_SLEEP)) == NULL) {
error = ENOMEM;
goto cleanup;
}
if ((rrp_v70->path = KMEM_ALLOC(MAXPATHLEN, KM_SLEEP)) == NULL) {
KMEM_FREE(rrp->path, MAXPATHLEN);
error = ENOMEM;
goto cleanup;
}
/* Try the new ALBD_FIND_SERVER RPC call first.
* If it works, then great...that means the server is up-to-date with IPv6
* and it will return an albd_server_port_list_t with multiple IPv4 and/or IPv6
* ports.
* If it does not work, then we must fall back to the old ALBD_FIND_SERVER_V70
* call that returns only an IPv4 address.
*/
error = mfscall(mfs_albdcall, ALBD_FIND_SERVER, 0,
albd_svrp, albd_retryp,
(xdrproc_t) xdr_albd_find_server_req_t, (caddr_t)rap,
(xdrproc_t) xdr_albd_find_server_reply_t, (caddr_t)rrp,
cred, NULL);
if (!error)
error = mfs_geterrno(rrp->hdr.status);
if (!error) {
/*
* We do this check to handle IPv4-mapped IPv6 addresses.
* If we need the port for an IPv4-mapped IPv6 address, then
* we grab the IPv4 port returned from the RPC.
*/
if ((svr->addr.ks_ss_s.sa_family == AF_INET6) &&
(IN6_IS_ADDR_V4MAPPED(&svr->addr.ks_ss_sin6.sin6_addr))) {
real_family = AF_INET;
} else {
real_family = svr->addr.ks_ss_s.sa_family;
}
for (num_ports = 0; num_ports < rrp->port_list.num_ports; num_ports++) {
if (rrp->port_list.ports[num_ports].af ==
real_family) {
switch (svr->addr.ks_ss_s.sa_family) {
case AF_INET:
svr->addr.ks_ss_sin4.sin_port =
htons((u_short)rrp->port_list.ports[num_ports].port);
break;
case AF_INET6:
svr->addr.ks_ss_sin6.sin6_port =
htons((u_short)rrp->port_list.ports[num_ports].port);
break;
default:
error = EPFNOSUPPORT;
goto cleanup;
}
svr->svrbound = 1;
}
}
if (!svr->svrbound)
error = EPFNOSUPPORT;