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