resolve-symlinks-from-stat-cache-with-just-lookup-permission-20010719
[openafs.git] / src / afs / afs_init.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /*
11  * afs_init.c - initialize AFS client.
12  *
13  * Implements:
14  */
15
16 #include <afsconfig.h>
17 #include "../afs/param.h"
18
19 RCSID("$Header$");
20
21 #include "../afs/stds.h"
22 #include "../afs/sysincludes.h" /* Standard vendor system headers */
23 #include "../afs/afsincludes.h" /* Afs-based standard headers */
24 #include "../afs/afs_stats.h"   /* afs statistics */
25
26
27 /* Imported variables */
28 extern afs_int32 afs_waitForever;
29 extern short afs_waitForeverCount;
30 extern afs_int32 afs_FVIndex;
31 extern struct server *afs_setTimeHost;
32 extern struct server *afs_servers[NSERVERS];
33 extern struct unixuser *afs_users[NUSERS];
34 extern struct volume *afs_freeVolList;
35 extern struct volume *afs_volumes[NVOLS];
36 extern afs_int32 afs_volCounter;
37
38 extern afs_rwlock_t afs_xaxs;
39 extern afs_rwlock_t afs_xvolume;
40 extern afs_rwlock_t afs_xuser;
41 extern afs_rwlock_t afs_xserver;
42 #ifndef AFS_AIX41_ENV
43 extern afs_lock_t osi_fsplock;
44 #endif
45 extern afs_lock_t osi_flplock;
46 extern afs_int32 fvTable[NFENTRIES];
47
48 /* afs_cell.c */
49 extern afs_rwlock_t afs_xcell;
50 extern struct afs_q CellLRU;
51 extern afs_int32 afs_cellindex;
52 extern afs_int32 afs_nextCellNum;
53
54 /* afs_conn.c */
55 extern afs_rwlock_t afs_xconn;
56 extern afs_rwlock_t afs_xinterface;
57
58 /* afs_mariner.c */
59 extern struct rx_service *afs_server;
60
61
62 /* afs_mariner.c */
63 extern afs_int32 afs_mariner;
64 extern afs_int32 afs_marinerHost;
65
66 /* afs_volume.c */
67 extern ino_t volumeInode;
68
69 /* afs_osi_pag.c */
70 extern afs_uint32 pag_epoch;
71
72 /* afs_dcache.c */
73 extern afs_rwlock_t afs_xdcache;
74 extern int cacheDiskType;
75 extern afs_int32 afs_fsfragsize;
76 extern ino_t cacheInode;
77 extern struct osi_file *afs_cacheInodep;
78 extern afs_int32 afs_freeDCList;                /*Free list for disk cache entries*/
79
80
81 /* afs_vcache.c */
82 extern afs_rwlock_t afs_xvcache;
83 extern afs_rwlock_t afs_xvcb;
84
85 /* VNOPS/afs_vnop_read.c */
86 extern afs_int32 maxIHint;
87 extern afs_int32 nihints;                   /* # of above actually in-use */
88 extern afs_int32 usedihint;
89
90 /* afs_server.c */
91 extern afs_int32 afs_setTime;
92
93 /* Imported functions. */
94 extern struct rx_securityClass *rxnull_NewServerSecurityObject();
95 extern int RXAFSCB_ExecuteRequest();
96 extern int RXSTATS_ExecuteRequest();
97
98
99 /* afs_osi.c */
100 extern afs_lock_t afs_ftf;
101
102 /* Exported variables */
103 struct osi_dev cacheDev;           /*Cache device*/
104 afs_int32 cacheInfoModTime;                     /*Last time cache info modified*/
105 #if defined(AFS_OSF_ENV) || defined(AFS_DEC_ENV) || defined(AFS_DARWIN_ENV)
106 struct mount *afs_cacheVfsp=0;
107 #elif defined(AFS_LINUX20_ENV)
108 struct super_block *afs_cacheSBp = 0;
109 #else
110 struct vfs *afs_cacheVfsp=0;
111 #endif
112 afs_rwlock_t afs_puttofileLock; /* not used */
113 char *afs_sysname = 0;                  /* So that superuser may change the
114                                          * local value of @sys */
115 char *afs_sysnamelist[MAXNUMSYSNAMES];  /* For support of a list of sysname */
116 int afs_sysnamecount = 0;
117 struct volume *Initialafs_freeVolList;
118 int afs_memvolumes = 0;
119
120 /* Local variables */
121
122
123 /*
124  * Initialization order is important.  Must first call afs_CacheInit,
125  * then cache file and volume file initialization routines.  Next, the
126  * individual cache entry initialization routines are called.
127  */
128
129
130 /*
131  * afs_CacheInit
132  *
133  * Description:
134  *
135  * Parameters:
136  *      astatSize : The number of stat cache (vnode) entries to
137  *                  allocate.
138  *      afiles    : The number of disk files to allocate to the cache
139  *      ablocks   : The max number of 1 Kbyte blocks that all of
140  *                  the files in the cache may occupy.
141  *      aDentries : Number of dcache entries to allocate.
142  *      aVolumes  : Number of volume cache entries to allocate.
143  *      achunk    : Power of 2 to make the chunks.
144  *      aflags    : Flags passed in.
145  *      inodes    : max inodes to pin down in inode[]
146  *      users     : what should size of per-user access cache be?
147  *
148  * Environment:
149  *      This routine should only be called at initialization time, since
150  *      it reclaims no resources and doesn't sufficiently synchronize
151  *      with other processes.
152  */
153
154 struct cm_initparams cm_initParams;
155 static int afs_cacheinit_flag = 0;
156 int
157 afs_CacheInit(astatSize, afiles, ablocks, aDentries, aVolumes, achunk, aflags,
158               ninodes, nusers)
159     afs_int32 afiles;
160     afs_int32 astatSize, ablocks; 
161     afs_int32 achunk, aflags, ninodes, nusers;
162     afs_int32 aDentries;
163 { /*afs_CacheInit*/
164     extern int afs_memvolumes;
165     register afs_int32 i, preallocs;
166     register struct volume *tv;
167     long code;
168
169     AFS_STATCNT(afs_CacheInit);
170     /*
171      * Jot down the epoch time, namely when this incarnation of the
172      * Cache Manager started.
173      */
174     afs_stats_cmperf.epoch = pag_epoch = osi_Time();
175 #ifdef SYS_NAME_ID
176     afs_stats_cmperf.sysName_ID = SYS_NAME_ID;
177 #else
178     afs_stats_cmperf.sysName_ID = SYS_NAME_ID_UNDEFINED;
179 #endif /* SYS_NAME_ID */
180
181     printf("Starting AFS cache scan...");
182     if (afs_cacheinit_flag)
183         return 0;
184     afs_cacheinit_flag = 1;
185     cacheInfoModTime = 0;
186     maxIHint = ninodes;
187     nihints = 0;
188     usedihint = 0;
189
190     LOCK_INIT(&afs_ftf, "afs_ftf");
191     RWLOCK_INIT(&afs_xaxs, "afs_xaxs");
192     osi_dnlc_init();
193
194
195 #if     defined(AFS_AIX32_ENV) || defined(AFS_HPUX_ENV)
196     /*
197      * We want to also reserve space for the gnode struct which is associated
198      * with each vnode (vcache) one; we want to use the pinned pool for them   
199      * since they're referenced at interrupt level.
200      */
201     if (afs_stats_cmperf.SmallBlocksAlloced + astatSize < 3600)
202       preallocs = astatSize;
203     else {
204       preallocs = 3600 - afs_stats_cmperf.SmallBlocksAlloced;
205       if (preallocs <= 0) preallocs = 10;
206     }
207     osi_AllocMoreSSpace(preallocs);
208 #endif
209     /* 
210      * create volume list structure 
211      */
212     if ( aVolumes < 50 )     aVolumes = 50;  
213     if (aVolumes > 3000) aVolumes = 3000;
214
215     tv = (struct volume *) afs_osi_Alloc(aVolumes * sizeof(struct volume));
216     for (i=0;i<aVolumes-1;i++)
217         tv[i].next = &tv[i+1];
218     tv[aVolumes-1].next = (struct volume *) 0;
219     afs_freeVolList = Initialafs_freeVolList = tv;
220     afs_memvolumes = aVolumes;
221
222     afs_cacheFiles = afiles;
223     afs_cacheStats = astatSize;
224     afs_vcacheInit(astatSize);
225     afs_dcacheInit(afiles, ablocks, aDentries, achunk, aflags);
226
227 #if defined(AFS_AIX_ENV)
228     {
229         static void afs_procsize_init(void);
230
231         afs_procsize_init();
232     }
233 #endif
234
235     /* Save the initialization parameters for later pioctl queries. */
236     cm_initParams.cmi_version = CMI_VERSION;
237     cm_initParams.cmi_nChunkFiles = afiles;
238     cm_initParams.cmi_nStatCaches = astatSize;
239     cm_initParams.cmi_nDataCaches = aDentries;
240     cm_initParams.cmi_nVolumeCaches = aVolumes;
241     cm_initParams.cmi_firstChunkSize = AFS_FIRSTCSIZE;
242     cm_initParams.cmi_otherChunkSize = AFS_OTHERCSIZE;
243     cm_initParams.cmi_cacheSize = ablocks;
244     cm_initParams.cmi_setTime = afs_setTime;
245     cm_initParams.cmi_memCache = (aflags & AFSCALL_INIT_MEMCACHE) ? 1 : 0;
246
247     return 0;
248
249 } /*afs_CacheInit*/
250
251
252 /*
253   * afs_ComputeCacheParams
254   *
255   * Description:
256   *     Set some cache parameters.
257   *
258   * Parameters:
259   *     None.
260   */
261
262 void
263 afs_ComputeCacheParms()
264
265 { /*afs_ComputeCacheParms*/
266
267     register afs_int32 i;
268     afs_int32 afs_maxCacheDirty;
269
270     /*
271      * Don't allow more than 2/3 of the files in the cache to be dirty.
272      */
273     afs_maxCacheDirty = (2*afs_cacheFiles) / 3;
274
275     /*
276      * Also, don't allow more than 2/3 of the total space get filled
277      * with dirty chunks.  Compute the total number of chunks required
278      * to fill the cache, make sure we don't set out limit above 2/3 of
279      * that. If the cache size is greater than 1G, avoid overflow at
280      * the expense of precision on the chunk size.
281      */
282     if (afs_cacheBlocks & 0xffe00000) {
283         i = afs_cacheBlocks / (AFS_FIRSTCSIZE >> 10);
284     }
285     else {
286         i = (afs_cacheBlocks << 10) / AFS_FIRSTCSIZE;
287     }
288     i = (2*i) / 3;
289     if (afs_maxCacheDirty > i)
290         afs_maxCacheDirty = i;
291     if (afs_maxCacheDirty < 1)
292         afs_maxCacheDirty = 1;
293     afs_stats_cmperf.cacheMaxDirtyChunks = afs_maxCacheDirty;
294 } /*afs_ComputeCacheParms*/
295
296
297 /*
298  * afs_InitVolumeInfo
299  *
300  * Description:
301  *      Set up the volume info storage file.
302  *
303  * Parameters:
304  *      afile : the file to be declared to be the volume info storage
305  *              file for AFS.  It must be already truncated to 0 length.
306  *
307  * Environment:
308  *      This function is called only during initialization.
309  *
310  *      WARNING: Data will be written to this file over time by AFS.
311  */
312
313 afs_InitVolumeInfo(afile)
314     register char *afile;
315
316 { /*afs_InitVolumeInfo*/
317
318     afs_int32 code;
319     struct osi_file *tfile;
320     struct vnode *filevp;
321     struct fcache fce;
322
323     AFS_STATCNT(afs_InitVolumeInfo);
324 #ifdef AFS_LINUX22_ENV
325     {
326         struct dentry *dp;
327         code = gop_lookupname(afile, AFS_UIOSYS, 0, (struct vnode **) 0, &dp);
328         if (code) return ENOENT;
329         fce.inode = volumeInode = dp->d_inode->i_ino;
330         dput(dp);
331     }
332 #else
333     code = gop_lookupname(afile, AFS_UIOSYS, 0, (struct vnode **) 0, &filevp);
334     if (code) return ENOENT;
335     fce.inode = volumeInode = afs_vnodeToInumber(filevp);
336 #ifdef AFS_DEC_ENV
337     grele(filevp);
338 #else
339     AFS_RELE((struct vnode *)filevp);
340 #endif
341 #endif /* AFS_LINUX22_ENV */
342     tfile = afs_CFileOpen(fce.inode);
343     afs_CFileTruncate(tfile, 0);
344     afs_CFileClose(tfile);
345     return 0;
346
347 } /*afs_InitVolumeInfo*/
348
349 /*
350  * afs_InitCacheInfo
351  *
352  * Description:
353  *      Set up the given file as the AFS cache info file.
354  *
355  * Parameters:
356  *      afile : Name of the file assumed to be the cache info file
357  *              for the Cache Manager; it will be used as such.
358  * Side Effects:  This sets afs_fragsize, which is used in the cache usage 
359  *                calculations such as in afs_adjustsize()
360  *
361  * Environment:
362  *      This function is called only during initialization.  The given
363  *      file should NOT be truncated to 0 lenght; its contents descrebe
364  *      what data is really in the cache.
365  *
366  *      WARNING: data will be written to this file over time by AFS.
367  *
368  * NOTE: Starting to use separate osi_InitCacheInfo() routines to clean up
369  * code.
370  *
371  */
372 afs_InitCacheInfo(afile)
373     register char *afile;
374
375 { /*afs_InitCacheInfo*/
376
377     register afs_int32 code;
378     struct osi_stat tstat;
379     register struct osi_file *tfile;
380     struct afs_fheader theader;
381     struct vnode *filevp;
382     int goodFile;
383
384     AFS_STATCNT(afs_InitCacheInfo);
385     if(cacheDiskType != AFS_FCACHE_TYPE_UFS)
386         osi_Panic("afs_InitCacheInfo --- called for non-ufs cache!");
387 #ifdef AFS_LINUX22_ENV
388     code = osi_InitCacheInfo(afile);
389     if (code) return code;
390 #else
391     code = gop_lookupname(afile, AFS_UIOSYS, 0, (struct vnode **) 0, &filevp);
392     if (code || !filevp) return ENOENT;
393     {
394 #if     defined(AFS_SUN56_ENV)
395       struct statvfs64 st;
396 #else
397 #if     defined(AFS_HPUX102_ENV)
398       struct k_statvfs st;
399 #else
400 #if     defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) ||defined(AFS_HPUX100_ENV)
401       struct statvfs st;
402 #else 
403 #if defined(AFS_DUX40_ENV)
404       struct nstatfs st;
405 #else
406       struct statfs st;
407 #endif /* DUX40 */
408 #endif /* SUN5 SGI */
409 #endif /* HP 10.20 */
410 #endif /* SUN56 */
411
412 #if     defined(AFS_SGI_ENV)
413 #ifdef AFS_SGI65_ENV
414       VFS_STATVFS(filevp->v_vfsp, &st, (struct vnode *)0, code);
415       if (!code) 
416 #else
417       if (!VFS_STATFS(filevp->v_vfsp, &st, (struct vnode *)0))
418 #endif /* AFS_SGI65_ENV */
419 #else /* AFS_SGI_ENV */
420 #if     defined(AFS_SUN5_ENV) || defined(AFS_HPUX100_ENV)
421       if (!VFS_STATVFS(filevp->v_vfsp, &st)) 
422 #else
423 #ifdef  AFS_OSF_ENV
424       
425       VFS_STATFS(filevp->v_vfsp, code);
426       /* struct copy */
427       st = filevp->v_vfsp->m_stat;
428       if (code == 0)
429 #else   /* AFS_OSF_ENV */
430 #ifdef AFS_AIX41_ENV
431       if (!VFS_STATFS(filevp->v_vfsp, &st, &afs_osi_cred))
432 #else
433 #ifdef AFS_LINUX20_ENV
434           {
435               KERNEL_SPACE_DECL;
436               TO_USER_SPACE();
437
438               VFS_STATFS(filevp->v_vfsp, &st);
439               TO_KERNEL_SPACE();
440           }
441 #else
442 #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
443         if (!VFS_STATFS(filevp->v_mount, &st, current_proc()))
444 #else 
445         if (!VFS_STATFS(filevp->v_vfsp, &st))  
446 #endif /* AFS_DARWIN_ENV || AFS_FBSD_ENV */
447 #endif /* AFS_LINUX20_ENV */
448 #endif /* AIX41 */
449 #endif /* OSF */
450 #endif /* SUN5 HP10 */
451 #endif /* SGI */
452 #if     defined(AFS_SUN5_ENV) || defined(AFS_HPUX100_ENV)
453         afs_fsfragsize = st.f_frsize - 1; 
454 #else
455         afs_fsfragsize = st.f_bsize - 1; 
456 #endif
457     }
458 #ifdef AFS_LINUX20_ENV
459     cacheInode = filevp->i_ino;
460     afs_cacheSBp = filevp->i_sb;
461 #else
462 #if defined(AFS_SGI62_ENV) || defined(AFS_HAVE_VXFS) || defined(AFS_DARWIN_ENV)
463     afs_InitDualFSCacheOps(filevp);
464 #endif
465     cacheInode = afs_vnodeToInumber(filevp);
466     cacheDev.dev = afs_vnodeToDev(filevp);
467     afs_cacheVfsp = filevp->v_vfsp;
468 #endif /* AFS_LINUX20_ENV */
469     AFS_RELE((struct vnode *)filevp);
470 #endif /* AFS_LINUX22_ENV */
471     tfile = osi_UFSOpen(cacheInode);
472     afs_osi_Stat(tfile, &tstat);
473     cacheInfoModTime = tstat.mtime;
474     code = afs_osi_Read(tfile, -1, &theader, sizeof(theader));
475     goodFile = 0;
476     if (code == sizeof(theader)) {
477         /* read the header correctly */
478         if (theader.magic == AFS_FHMAGIC &&
479             theader.firstCSize == AFS_FIRSTCSIZE &&
480             theader.otherCSize == AFS_OTHERCSIZE &&
481             theader.version == AFS_CI_VERSION
482         )
483             goodFile = 1;
484     }
485     if (!goodFile) {
486         /* write out a good file label */
487         theader.magic = AFS_FHMAGIC;
488         theader.firstCSize = AFS_FIRSTCSIZE;
489         theader.otherCSize = AFS_OTHERCSIZE;
490         theader.version = AFS_CI_VERSION;
491         afs_osi_Write(tfile, 0, &theader, sizeof(theader));
492         /*
493          * Truncate the rest of the file, since it may be arbitrarily
494          * wrong
495          */
496         osi_UFSTruncate(tfile, sizeof(struct afs_fheader));
497     }
498     /* Leave the file open now, since reopening the file makes public pool
499      * vnode systems (like OSF/Alpha) much harder to handle, That's because
500      * they can do a vnode recycle operation any time we open a file, which
501      * we'd do on any afs_GetDSlot call, etc.
502      */
503     afs_cacheInodep = (struct osi_file *)tfile;
504     return 0;
505
506 } /*afs_InitCacheInfo*/
507
508 int afs_resourceinit_flag = 0;
509 afs_ResourceInit(preallocs)
510   int preallocs;
511 {
512     register afs_int32 i;
513     static struct rx_securityClass *secobj;
514
515     AFS_STATCNT(afs_ResourceInit);
516     RWLOCK_INIT(&afs_xuser, "afs_xuser");
517     RWLOCK_INIT(&afs_xvolume, "afs_xvolume");
518     RWLOCK_INIT(&afs_xcell, "afs_xcell");
519     RWLOCK_INIT(&afs_xserver, "afs_xserver");
520     RWLOCK_INIT(&afs_xinterface, "afs_xinterface");
521     LOCK_INIT(&afs_puttofileLock, "afs_puttofileLock");
522 #ifndef AFS_AIX32_ENV
523     LOCK_INIT(&osi_fsplock, "osi_fsplock");
524 #endif
525     LOCK_INIT(&osi_flplock, "osi_flplock");
526     RWLOCK_INIT(&afs_xconn, "afs_xconn");
527
528     afs_InitCBQueue(1);  /* initialize callback queues */
529
530     if (afs_resourceinit_flag == 0) {
531         afs_resourceinit_flag = 1;
532         for (i=0;i<NFENTRIES;i++)
533             fvTable[i] = 0;
534         for(i=0;i<MAXNUMSYSNAMES;i++)
535           afs_sysnamelist[i] = afs_osi_Alloc(MAXSYSNAME);
536         afs_sysname = afs_sysnamelist[0];
537         strcpy(afs_sysname, SYS_NAME);
538         afs_sysnamecount = 1;
539         QInit(&CellLRU);        
540 #if     defined(AFS_AIX32_ENV) || defined(AFS_HPUX_ENV)
541     {  extern afs_int32 afs_preallocs;
542
543        if ((preallocs > 256) && (preallocs < 3600))
544            afs_preallocs = preallocs;
545        osi_AllocMoreSSpace(afs_preallocs);
546        osi_AllocMoreMSpace(100); 
547     }
548 #endif
549     }
550     
551     secobj = rxnull_NewServerSecurityObject();
552     afs_server =
553         rx_NewService(0, 1, "afs", &secobj, 1, RXAFSCB_ExecuteRequest);
554     afs_server =
555         rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", &secobj, 1,
556                       RXSTATS_ExecuteRequest);
557     rx_StartServer(0);
558     afs_osi_Wakeup(&afs_server);        /* wakeup anyone waiting for it */
559     return 0;
560
561 } /*afs_ResourceInit*/
562
563 #if defined(AFS_AIX_ENV)
564
565 /*
566  * AIX dynamic sizeof(struct proc)
567  *
568  * AIX keeps its proc structures in an array.  The size of struct proc
569  * varies from release to release of the OS.  In order to maintain
570  * binary compatibility with releases later than what we build on, we
571  * need to determine the size of struct proc at run time.
572  *
573  * We need this in order to walk the proc[] array to do PAG garbage
574  * collection.
575  *
576  * We also need this in order to support 'klog -setpag', since the
577  * kernel code needs to locate the proc structure for the parent process
578  * of the current process.
579  *
580  * To compute sizeof(struct proc), we need the addresses of two proc
581  * structures and their corresponding pids.  Given the pids, we can use
582  * the PROCMASK() macro to compute their corresponding indices in the
583  * proc[] array.  By dividing the distance between the pointers by the
584  * number of proc structures, we can compute the size of a single proc
585  * structure.
586  *
587  * We know the base address of the proc table from v.vb_proc:
588  *
589  * <sys/sysconfig.h> declares sysconfig() and SYS_GETPARMS;
590  * (we don't use this, but I note it here for completeness)
591  *
592  * <sys/var.h> declares struct var and external variable v;
593  *
594  * v.v_proc             NPROC
595  * v.vb_proc            &proc[0]
596  * v.ve_proc            &proc[x] (current highwater mark for
597  *                                proc[] array usage)
598  *
599  * The first proc pointer is v.vb_proc, which is the proc structure for
600  * process 0.  Process 0's pointer to its first child is the other proc
601  * pointer.  If process 0 has no children, we simply give up and do not
602  * support features that require knowing the size of struct proc.
603  */
604
605 static void
606 afs_procsize_init(void)
607 {
608     struct proc *p0;    /* pointer to process 0 */
609     struct proc *pN;    /* pointer to process 0's first child */
610     int pN_index;
611     ptrdiff_t pN_offset;
612     int procsize;
613
614     p0 = (struct proc *)v.vb_proc;
615     if (!p0) {
616         afs_gcpags = AFS_GCPAGS_EPROC0;
617         return;
618     }
619
620     pN = p0->p_child;
621     if (!pN) {
622         afs_gcpags = AFS_GCPAGS_EPROCN;
623         return;
624     }
625
626     if (pN->p_pid == p0->p_pid) {
627         afs_gcpags = AFS_GCPAGS_EEQPID;
628         return;
629     }
630
631     pN_index = PROCMASK(pN->p_pid);
632     pN_offset = ((char *)pN - (char *)p0);
633     procsize = pN_offset / pN_index;
634
635     /*
636      * check that the computation was exact
637      */
638
639     if (pN_index * procsize != pN_offset) {
640         afs_gcpags = AFS_GCPAGS_EINEXACT;
641         return;
642     }
643
644     /*
645      * check that the proc table size is a multiple of procsize.
646      */
647
648     if ((((char *)v.ve_proc - (char *)v.vb_proc) % procsize) != 0) {
649         afs_gcpags = AFS_GCPAGS_EPROCEND;
650         return;
651     }
652
653     /* okay, use it */
654
655     afs_gcpags_procsize = procsize;
656 }
657
658 #endif
659
660 /*
661  * shutdown_cache
662  *
663  * Description:
664  *      Clean up and shut down the AFS cache.
665  *
666  * Parameters:
667  *      None.
668  *
669  * Environment:
670  *      Nothing interesting.
671  */
672 void
673 shutdown_cache()
674
675 { /*shutdown_cache*/
676     register struct afs_cbr *tsp, *nsp;
677     extern int afs_cold_shutdown;
678     extern int pagCounter;
679     int i;
680
681   AFS_STATCNT(shutdown_cache);
682   afs_WriteThroughDSlots();
683   if (afs_cold_shutdown) {
684     afs_cacheinit_flag = 0;
685     shutdown_dcache();
686     shutdown_vcache();
687
688     afs_cacheStats = 0;
689     afs_cacheFiles = afs_cacheBlocks = 0;
690     pag_epoch = maxIHint = nihints = usedihint = 0;
691     pagCounter = 0;
692     cacheInode = volumeInode = (ino_t)0;
693
694
695     cacheInfoModTime = 0;
696
697     afs_fsfragsize = 1023;
698     bzero((char *)&afs_stats_cmperf, sizeof(afs_stats_cmperf));
699     bzero((char *)&cacheDev, sizeof(struct osi_dev));
700     osi_dnlc_shutdown();
701   }
702 } /*shutdown_cache*/
703
704
705 void shutdown_vnodeops()
706 {
707     extern int afs_cold_shutdown;
708 #ifndef AFS_LINUX20_ENV
709     extern int afs_rd_stash_i;
710 #endif
711 #ifndef AFS_SUN5_ENV
712     extern int lastWarnTime;
713 #endif
714 #if !defined(AFS_SGI_ENV) && !defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV)
715     struct buf *afs_bread_freebp = 0;
716 #endif
717     
718
719     AFS_STATCNT(shutdown_vnodeops);
720     if (afs_cold_shutdown) {
721 #ifndef AFS_SUN5_ENV    /* XXX */
722       lastWarnTime = 0;
723 #endif
724 #ifndef AFS_LINUX20_ENV
725       afs_rd_stash_i = 0;      
726 #endif
727 #if !defined(AFS_SGI_ENV) && !defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV)
728       afs_bread_freebp = 0;
729 #endif
730       shutdown_mariner();
731   }
732 }
733
734
735 void shutdown_AFS()
736
737 {
738     int i;
739     register struct srvAddr *sa;
740     extern int afs_cold_shutdown;
741
742     AFS_STATCNT(shutdown_AFS);
743     if (afs_cold_shutdown) {
744       afs_resourceinit_flag = 0; 
745       /* 
746        * Free Cells table allocations 
747        */
748       { 
749         struct cell *tc;
750         register struct afs_q *cq, *tq;
751         for (cq = CellLRU.next; cq != &CellLRU; cq = tq) {
752             tc = QTOC(cq); tq = QNext(cq);
753             if (tc->cellName)
754                 afs_osi_Free(tc->cellName, strlen(tc->cellName)+1);
755             afs_osi_Free(tc, sizeof(struct cell));
756         }
757       }
758       /* 
759        * Free Volumes table allocations 
760        */
761       { 
762         struct volume *tv;
763         for (i = 0; i < NVOLS; i++) {
764             for (tv = afs_volumes[i]; tv; tv = tv->next) {
765                 if (tv->name) {
766                     afs_osi_Free(tv->name, strlen(tv->name)+1);
767                     tv->name = 0;
768                 }
769             }
770             afs_volumes[i] = 0;
771         }
772       }
773
774       /* 
775        * Free FreeVolList allocations 
776        */
777       afs_osi_Free(Initialafs_freeVolList, afs_memvolumes * sizeof(struct volume));
778       afs_freeVolList = Initialafs_freeVolList = 0;
779
780       /* XXX HACK fort MEM systems XXX 
781        *
782        * For -memcache cache managers when we run out of free in memory volumes
783        * we simply malloc more; we won't be able to free those additional volumes.
784        */
785
786       
787
788       /* 
789        * Free Users table allocation 
790        */
791       { 
792         struct unixuser *tu, *ntu;
793         for (i=0; i < NUSERS; i++) {
794             for (tu=afs_users[i]; tu; tu = ntu) {
795                 ntu = tu->next;
796                 if (tu->stp)
797                     afs_osi_Free(tu->stp, tu->stLen);
798                 if (tu->exporter)
799                     EXP_RELE(tu->exporter);
800                 afs_osi_Free(tu, sizeof(struct unixuser));
801             }
802             afs_users[i] = 0;
803         }
804       }
805
806       /* 
807        * Free Servers table allocation 
808        */
809       { 
810         struct server *ts, *nts;
811         struct conn *tc, *ntc;
812         register struct afs_cbr *tcbrp, *tbrp;
813         struct afs_cbr **lcbrpp;
814
815         for (i=0; i < NSERVERS; i++) {
816             for (ts = afs_servers[i]; ts; ts = nts) {
817                 nts = ts->next;
818                 for (sa = ts->addr; sa; sa = sa->next_sa) {     
819                     if (sa->conns) {
820                         /*
821                          * Free all server's connection structs
822                          */
823                         tc = sa->conns;
824                         while (tc) {
825                             ntc = tc->next;
826                             AFS_GUNLOCK();
827                             rx_DestroyConnection(tc->id);
828                             AFS_GLOCK();
829                             afs_osi_Free(tc, sizeof(struct conn));
830                             tc = ntc;
831                         }
832                     }
833                 }
834                 for (tcbrp = ts->cbrs; tcbrp;  tcbrp = tbrp) {
835                     /*
836                      * Free all server's callback structs
837                      */
838                     tbrp = tcbrp->next;
839                     afs_FreeCBR(tcbrp);
840                 }
841                 afs_osi_Free(ts, sizeof(struct server));
842             }
843             afs_servers[i] = 0;
844         }
845       }
846       for (i=0; i<NFENTRIES; i++)
847         fvTable[i] = 0;
848       /* Reinitialize local globals to defaults */
849       for(i=0; i<MAXNUMSYSNAMES; i++)
850         afs_osi_Free(afs_sysnamelist[i], MAXSYSNAME);
851       afs_sysname = 0;
852       afs_sysnamecount = 0;
853       afs_marinerHost = 0;
854       QInit(&CellLRU);      
855       afs_setTimeHost = (struct server *)0;
856       afs_volCounter = 1;
857       afs_waitForever = afs_waitForeverCount = 0;
858       afs_cellindex = 0;
859       afs_nextCellNum = 0x100;
860       afs_FVIndex = -1;
861       afs_server = (struct rx_service *)0;
862       RWLOCK_INIT(&afs_xconn, "afs_xconn");
863       bzero((char *)&afs_rootFid, sizeof(struct VenusFid));
864       RWLOCK_INIT(&afs_xuser, "afs_xuser");
865       RWLOCK_INIT(&afs_xvolume, "afs_xvolume"), RWLOCK_INIT(&afs_xcell, "afs_xcell");
866       RWLOCK_INIT(&afs_xserver, "afs_xserver"), LOCK_INIT(&afs_puttofileLock, "afs_puttofileLock");
867     }
868     
869 } /*shutdown_AFS*/