client-64bit-file-size-support-20011031
[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 #ifdef AFS_64BIT_CLIENT
227 #ifdef AFS_VM_RDWR_ENV
228     afs_vmMappingEnd = AFS_CHUNKBASE(0x7fffffff);
229 #endif /* AFS_VM_RDWR_ENV */
230 #endif /* AFS_64BIT_CLIENT */
231
232 #if defined(AFS_AIX_ENV)
233     {
234         static void afs_procsize_init(void);
235
236         afs_procsize_init();
237     }
238 #endif
239
240     /* Save the initialization parameters for later pioctl queries. */
241     cm_initParams.cmi_version = CMI_VERSION;
242     cm_initParams.cmi_nChunkFiles = afiles;
243     cm_initParams.cmi_nStatCaches = astatSize;
244     cm_initParams.cmi_nDataCaches = aDentries;
245     cm_initParams.cmi_nVolumeCaches = aVolumes;
246     cm_initParams.cmi_firstChunkSize = AFS_FIRSTCSIZE;
247     cm_initParams.cmi_otherChunkSize = AFS_OTHERCSIZE;
248     cm_initParams.cmi_cacheSize = ablocks;
249     cm_initParams.cmi_setTime = afs_setTime;
250     cm_initParams.cmi_memCache = (aflags & AFSCALL_INIT_MEMCACHE) ? 1 : 0;
251
252     return 0;
253
254 } /*afs_CacheInit*/
255
256
257 /*
258   * afs_ComputeCacheParams
259   *
260   * Description:
261   *     Set some cache parameters.
262   *
263   * Parameters:
264   *     None.
265   */
266
267 void
268 afs_ComputeCacheParms()
269
270 { /*afs_ComputeCacheParms*/
271
272     register afs_int32 i;
273     afs_int32 afs_maxCacheDirty;
274
275     /*
276      * Don't allow more than 2/3 of the files in the cache to be dirty.
277      */
278     afs_maxCacheDirty = (2*afs_cacheFiles) / 3;
279
280     /*
281      * Also, don't allow more than 2/3 of the total space get filled
282      * with dirty chunks.  Compute the total number of chunks required
283      * to fill the cache, make sure we don't set out limit above 2/3 of
284      * that. If the cache size is greater than 1G, avoid overflow at
285      * the expense of precision on the chunk size.
286      */
287     if (afs_cacheBlocks & 0xffe00000) {
288         i = afs_cacheBlocks / (AFS_FIRSTCSIZE >> 10);
289     }
290     else {
291         i = (afs_cacheBlocks << 10) / AFS_FIRSTCSIZE;
292     }
293     i = (2*i) / 3;
294     if (afs_maxCacheDirty > i)
295         afs_maxCacheDirty = i;
296     if (afs_maxCacheDirty < 1)
297         afs_maxCacheDirty = 1;
298     afs_stats_cmperf.cacheMaxDirtyChunks = afs_maxCacheDirty;
299 } /*afs_ComputeCacheParms*/
300
301
302 /*
303  * afs_InitVolumeInfo
304  *
305  * Description:
306  *      Set up the volume info storage file.
307  *
308  * Parameters:
309  *      afile : the file to be declared to be the volume info storage
310  *              file for AFS.  It must be already truncated to 0 length.
311  *
312  * Environment:
313  *      This function is called only during initialization.
314  *
315  *      WARNING: Data will be written to this file over time by AFS.
316  */
317
318 afs_InitVolumeInfo(afile)
319     register char *afile;
320
321 { /*afs_InitVolumeInfo*/
322
323     afs_int32 code;
324     struct osi_file *tfile;
325     struct vnode *filevp;
326     struct fcache fce;
327
328     AFS_STATCNT(afs_InitVolumeInfo);
329 #ifdef AFS_LINUX22_ENV
330     {
331         struct dentry *dp;
332         code = gop_lookupname(afile, AFS_UIOSYS, 0, (struct vnode **) 0, &dp);
333         if (code) return ENOENT;
334         fce.inode = volumeInode = dp->d_inode->i_ino;
335         dput(dp);
336     }
337 #else
338     code = gop_lookupname(afile, AFS_UIOSYS, 0, (struct vnode **) 0, &filevp);
339     if (code) return ENOENT;
340     fce.inode = volumeInode = afs_vnodeToInumber(filevp);
341 #ifdef AFS_DEC_ENV
342     grele(filevp);
343 #else
344     AFS_RELE((struct vnode *)filevp);
345 #endif
346 #endif /* AFS_LINUX22_ENV */
347     tfile = afs_CFileOpen(fce.inode);
348     afs_CFileTruncate(tfile, 0);
349     afs_CFileClose(tfile);
350     return 0;
351
352 } /*afs_InitVolumeInfo*/
353
354 /*
355  * afs_InitCacheInfo
356  *
357  * Description:
358  *      Set up the given file as the AFS cache info file.
359  *
360  * Parameters:
361  *      afile : Name of the file assumed to be the cache info file
362  *              for the Cache Manager; it will be used as such.
363  * Side Effects:  This sets afs_fragsize, which is used in the cache usage 
364  *                calculations such as in afs_adjustsize()
365  *
366  * Environment:
367  *      This function is called only during initialization.  The given
368  *      file should NOT be truncated to 0 lenght; its contents descrebe
369  *      what data is really in the cache.
370  *
371  *      WARNING: data will be written to this file over time by AFS.
372  *
373  * NOTE: Starting to use separate osi_InitCacheInfo() routines to clean up
374  * code.
375  *
376  */
377 afs_InitCacheInfo(afile)
378     register char *afile;
379
380 { /*afs_InitCacheInfo*/
381
382     register afs_int32 code;
383     struct osi_stat tstat;
384     register struct osi_file *tfile;
385     struct afs_fheader theader;
386     struct vnode *filevp;
387     int goodFile;
388
389     AFS_STATCNT(afs_InitCacheInfo);
390     if(cacheDiskType != AFS_FCACHE_TYPE_UFS)
391         osi_Panic("afs_InitCacheInfo --- called for non-ufs cache!");
392 #ifdef AFS_LINUX22_ENV
393     code = osi_InitCacheInfo(afile);
394     if (code) return code;
395 #else
396     code = gop_lookupname(afile, AFS_UIOSYS, 0, (struct vnode **) 0, &filevp);
397     if (code || !filevp) return ENOENT;
398     {
399 #if     defined(AFS_SUN56_ENV)
400       struct statvfs64 st;
401 #else
402 #if     defined(AFS_HPUX102_ENV)
403       struct k_statvfs st;
404 #else
405 #if     defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) ||defined(AFS_HPUX100_ENV)
406       struct statvfs st;
407 #else 
408 #if defined(AFS_DUX40_ENV)
409       struct nstatfs st;
410 #else
411       struct statfs st;
412 #endif /* DUX40 */
413 #endif /* SUN5 SGI */
414 #endif /* HP 10.20 */
415 #endif /* SUN56 */
416
417 #if     defined(AFS_SGI_ENV)
418 #ifdef AFS_SGI65_ENV
419       VFS_STATVFS(filevp->v_vfsp, &st, (struct vnode *)0, code);
420       if (!code) 
421 #else
422       if (!VFS_STATFS(filevp->v_vfsp, &st, (struct vnode *)0))
423 #endif /* AFS_SGI65_ENV */
424 #else /* AFS_SGI_ENV */
425 #if     defined(AFS_SUN5_ENV) || defined(AFS_HPUX100_ENV)
426       if (!VFS_STATVFS(filevp->v_vfsp, &st)) 
427 #else
428 #ifdef  AFS_OSF_ENV
429       
430       VFS_STATFS(filevp->v_vfsp, code);
431       /* struct copy */
432       st = filevp->v_vfsp->m_stat;
433       if (code == 0)
434 #else   /* AFS_OSF_ENV */
435 #ifdef AFS_AIX41_ENV
436       if (!VFS_STATFS(filevp->v_vfsp, &st, &afs_osi_cred))
437 #else
438 #ifdef AFS_LINUX20_ENV
439           {
440               KERNEL_SPACE_DECL;
441               TO_USER_SPACE();
442
443               VFS_STATFS(filevp->v_vfsp, &st);
444               TO_KERNEL_SPACE();
445           }
446 #else
447 #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
448         if (!VFS_STATFS(filevp->v_mount, &st, current_proc()))
449 #else 
450         if (!VFS_STATFS(filevp->v_vfsp, &st))  
451 #endif /* AFS_DARWIN_ENV || AFS_FBSD_ENV */
452 #endif /* AFS_LINUX20_ENV */
453 #endif /* AIX41 */
454 #endif /* OSF */
455 #endif /* SUN5 HP10 */
456 #endif /* SGI */
457 #if     defined(AFS_SUN5_ENV) || defined(AFS_HPUX100_ENV)
458         afs_fsfragsize = st.f_frsize - 1; 
459 #else
460         afs_fsfragsize = st.f_bsize - 1; 
461 #endif
462     }
463 #ifdef AFS_LINUX20_ENV
464     cacheInode = filevp->i_ino;
465     afs_cacheSBp = filevp->i_sb;
466 #else
467 #if defined(AFS_SGI62_ENV) || defined(AFS_HAVE_VXFS) || defined(AFS_DARWIN_ENV)
468     afs_InitDualFSCacheOps(filevp);
469 #endif
470     cacheInode = afs_vnodeToInumber(filevp);
471     cacheDev.dev = afs_vnodeToDev(filevp);
472     afs_cacheVfsp = filevp->v_vfsp;
473 #endif /* AFS_LINUX20_ENV */
474     AFS_RELE((struct vnode *)filevp);
475 #endif /* AFS_LINUX22_ENV */
476     tfile = osi_UFSOpen(cacheInode);
477     afs_osi_Stat(tfile, &tstat);
478     cacheInfoModTime = tstat.mtime;
479     code = afs_osi_Read(tfile, -1, &theader, sizeof(theader));
480     goodFile = 0;
481     if (code == sizeof(theader)) {
482         /* read the header correctly */
483         if (theader.magic == AFS_FHMAGIC &&
484             theader.firstCSize == AFS_FIRSTCSIZE &&
485             theader.otherCSize == AFS_OTHERCSIZE &&
486             theader.version == AFS_CI_VERSION
487         )
488             goodFile = 1;
489     }
490     if (!goodFile) {
491         /* write out a good file label */
492         theader.magic = AFS_FHMAGIC;
493         theader.firstCSize = AFS_FIRSTCSIZE;
494         theader.otherCSize = AFS_OTHERCSIZE;
495         theader.version = AFS_CI_VERSION;
496         afs_osi_Write(tfile, 0, &theader, sizeof(theader));
497         /*
498          * Truncate the rest of the file, since it may be arbitrarily
499          * wrong
500          */
501         osi_UFSTruncate(tfile, sizeof(struct afs_fheader));
502     }
503     /* Leave the file open now, since reopening the file makes public pool
504      * vnode systems (like OSF/Alpha) much harder to handle, That's because
505      * they can do a vnode recycle operation any time we open a file, which
506      * we'd do on any afs_GetDSlot call, etc.
507      */
508     afs_cacheInodep = (struct osi_file *)tfile;
509     return 0;
510
511 } /*afs_InitCacheInfo*/
512
513 int afs_resourceinit_flag = 0;
514 afs_ResourceInit(preallocs)
515   int preallocs;
516 {
517     register afs_int32 i;
518     static struct rx_securityClass *secobj;
519
520     AFS_STATCNT(afs_ResourceInit);
521     RWLOCK_INIT(&afs_xuser, "afs_xuser");
522     RWLOCK_INIT(&afs_xvolume, "afs_xvolume");
523     RWLOCK_INIT(&afs_xcell, "afs_xcell");
524     RWLOCK_INIT(&afs_xserver, "afs_xserver");
525     RWLOCK_INIT(&afs_xinterface, "afs_xinterface");
526     LOCK_INIT(&afs_puttofileLock, "afs_puttofileLock");
527 #ifndef AFS_AIX32_ENV
528     LOCK_INIT(&osi_fsplock, "osi_fsplock");
529 #endif
530     LOCK_INIT(&osi_flplock, "osi_flplock");
531     RWLOCK_INIT(&afs_xconn, "afs_xconn");
532
533     afs_InitCBQueue(1);  /* initialize callback queues */
534
535     if (afs_resourceinit_flag == 0) {
536         afs_resourceinit_flag = 1;
537         for (i=0;i<NFENTRIES;i++)
538             fvTable[i] = 0;
539         for(i=0;i<MAXNUMSYSNAMES;i++)
540           afs_sysnamelist[i] = afs_osi_Alloc(MAXSYSNAME);
541         afs_sysname = afs_sysnamelist[0];
542         strcpy(afs_sysname, SYS_NAME);
543         afs_sysnamecount = 1;
544         QInit(&CellLRU);        
545 #if     defined(AFS_AIX32_ENV) || defined(AFS_HPUX_ENV)
546     {  extern afs_int32 afs_preallocs;
547
548        if ((preallocs > 256) && (preallocs < 3600))
549            afs_preallocs = preallocs;
550        osi_AllocMoreSSpace(afs_preallocs);
551        osi_AllocMoreMSpace(100); 
552     }
553 #endif
554     }
555     
556     secobj = rxnull_NewServerSecurityObject();
557     afs_server =
558         rx_NewService(0, 1, "afs", &secobj, 1, RXAFSCB_ExecuteRequest);
559     afs_server =
560         rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", &secobj, 1,
561                       RXSTATS_ExecuteRequest);
562     rx_StartServer(0);
563     afs_osi_Wakeup(&afs_server);        /* wakeup anyone waiting for it */
564     return 0;
565
566 } /*afs_ResourceInit*/
567
568 #if defined(AFS_AIX_ENV)
569
570 /*
571  * AIX dynamic sizeof(struct proc)
572  *
573  * AIX keeps its proc structures in an array.  The size of struct proc
574  * varies from release to release of the OS.  In order to maintain
575  * binary compatibility with releases later than what we build on, we
576  * need to determine the size of struct proc at run time.
577  *
578  * We need this in order to walk the proc[] array to do PAG garbage
579  * collection.
580  *
581  * We also need this in order to support 'klog -setpag', since the
582  * kernel code needs to locate the proc structure for the parent process
583  * of the current process.
584  *
585  * To compute sizeof(struct proc), we need the addresses of two proc
586  * structures and their corresponding pids.  Given the pids, we can use
587  * the PROCMASK() macro to compute their corresponding indices in the
588  * proc[] array.  By dividing the distance between the pointers by the
589  * number of proc structures, we can compute the size of a single proc
590  * structure.
591  *
592  * We know the base address of the proc table from v.vb_proc:
593  *
594  * <sys/sysconfig.h> declares sysconfig() and SYS_GETPARMS;
595  * (we don't use this, but I note it here for completeness)
596  *
597  * <sys/var.h> declares struct var and external variable v;
598  *
599  * v.v_proc             NPROC
600  * v.vb_proc            &proc[0]
601  * v.ve_proc            &proc[x] (current highwater mark for
602  *                                proc[] array usage)
603  *
604  * The first proc pointer is v.vb_proc, which is the proc structure for
605  * process 0.  Process 0's pointer to its first child is the other proc
606  * pointer.  If process 0 has no children, we simply give up and do not
607  * support features that require knowing the size of struct proc.
608  */
609
610 static void
611 afs_procsize_init(void)
612 {
613     struct proc *p0;    /* pointer to process 0 */
614     struct proc *pN;    /* pointer to process 0's first child */
615     int pN_index;
616     ptrdiff_t pN_offset;
617     int procsize;
618
619     p0 = (struct proc *)v.vb_proc;
620     if (!p0) {
621         afs_gcpags = AFS_GCPAGS_EPROC0;
622         return;
623     }
624
625     pN = p0->p_child;
626     if (!pN) {
627         afs_gcpags = AFS_GCPAGS_EPROCN;
628         return;
629     }
630
631     if (pN->p_pid == p0->p_pid) {
632         afs_gcpags = AFS_GCPAGS_EEQPID;
633         return;
634     }
635
636     pN_index = PROCMASK(pN->p_pid);
637     pN_offset = ((char *)pN - (char *)p0);
638     procsize = pN_offset / pN_index;
639
640     /*
641      * check that the computation was exact
642      */
643
644     if (pN_index * procsize != pN_offset) {
645         afs_gcpags = AFS_GCPAGS_EINEXACT;
646         return;
647     }
648
649     /*
650      * check that the proc table size is a multiple of procsize.
651      */
652
653     if ((((char *)v.ve_proc - (char *)v.vb_proc) % procsize) != 0) {
654         afs_gcpags = AFS_GCPAGS_EPROCEND;
655         return;
656     }
657
658     /* okay, use it */
659
660     afs_gcpags_procsize = procsize;
661 }
662
663 #endif
664
665 /*
666  * shutdown_cache
667  *
668  * Description:
669  *      Clean up and shut down the AFS cache.
670  *
671  * Parameters:
672  *      None.
673  *
674  * Environment:
675  *      Nothing interesting.
676  */
677 void
678 shutdown_cache()
679
680 { /*shutdown_cache*/
681     register struct afs_cbr *tsp, *nsp;
682     extern int afs_cold_shutdown;
683     extern int pagCounter;
684     int i;
685
686   AFS_STATCNT(shutdown_cache);
687   afs_WriteThroughDSlots();
688   if (afs_cold_shutdown) {
689     afs_cacheinit_flag = 0;
690     shutdown_dcache();
691     shutdown_vcache();
692
693     afs_cacheStats = 0;
694     afs_cacheFiles = afs_cacheBlocks = 0;
695     pag_epoch = maxIHint = nihints = usedihint = 0;
696     pagCounter = 0;
697     cacheInode = volumeInode = (ino_t)0;
698
699
700     cacheInfoModTime = 0;
701
702     afs_fsfragsize = 1023;
703     memset((char *)&afs_stats_cmperf, 0, sizeof(afs_stats_cmperf));
704     memset((char *)&cacheDev, 0, sizeof(struct osi_dev));
705     osi_dnlc_shutdown();
706   }
707 } /*shutdown_cache*/
708
709
710 void shutdown_vnodeops()
711 {
712     extern int afs_cold_shutdown;
713 #ifndef AFS_LINUX20_ENV
714     extern int afs_rd_stash_i;
715 #endif
716 #ifndef AFS_SUN5_ENV
717     extern int lastWarnTime;
718 #endif
719 #if !defined(AFS_SGI_ENV) && !defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV)
720     struct buf *afs_bread_freebp = 0;
721 #endif
722     
723
724     AFS_STATCNT(shutdown_vnodeops);
725     if (afs_cold_shutdown) {
726 #ifndef AFS_SUN5_ENV    /* XXX */
727       lastWarnTime = 0;
728 #endif
729 #ifndef AFS_LINUX20_ENV
730       afs_rd_stash_i = 0;      
731 #endif
732 #if !defined(AFS_SGI_ENV) && !defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV)
733       afs_bread_freebp = 0;
734 #endif
735       shutdown_mariner();
736   }
737 }
738
739
740 void shutdown_AFS()
741
742 {
743     int i;
744     register struct srvAddr *sa;
745     extern int afs_cold_shutdown;
746
747     AFS_STATCNT(shutdown_AFS);
748     if (afs_cold_shutdown) {
749       afs_resourceinit_flag = 0; 
750       /* 
751        * Free Cells table allocations 
752        */
753       { 
754         struct cell *tc;
755         register struct afs_q *cq, *tq;
756         for (cq = CellLRU.next; cq != &CellLRU; cq = tq) {
757             tc = QTOC(cq); tq = QNext(cq);
758             if (tc->cellName)
759                 afs_osi_Free(tc->cellName, strlen(tc->cellName)+1);
760             afs_osi_Free(tc, sizeof(struct cell));
761         }
762       }
763       /* 
764        * Free Volumes table allocations 
765        */
766       { 
767         struct volume *tv;
768         for (i = 0; i < NVOLS; i++) {
769             for (tv = afs_volumes[i]; tv; tv = tv->next) {
770                 if (tv->name) {
771                     afs_osi_Free(tv->name, strlen(tv->name)+1);
772                     tv->name = 0;
773                 }
774             }
775             afs_volumes[i] = 0;
776         }
777       }
778
779       /* 
780        * Free FreeVolList allocations 
781        */
782       afs_osi_Free(Initialafs_freeVolList, afs_memvolumes * sizeof(struct volume));
783       afs_freeVolList = Initialafs_freeVolList = 0;
784
785       /* XXX HACK fort MEM systems XXX 
786        *
787        * For -memcache cache managers when we run out of free in memory volumes
788        * we simply malloc more; we won't be able to free those additional volumes.
789        */
790
791       
792
793       /* 
794        * Free Users table allocation 
795        */
796       { 
797         struct unixuser *tu, *ntu;
798         for (i=0; i < NUSERS; i++) {
799             for (tu=afs_users[i]; tu; tu = ntu) {
800                 ntu = tu->next;
801                 if (tu->stp)
802                     afs_osi_Free(tu->stp, tu->stLen);
803                 if (tu->exporter)
804                     EXP_RELE(tu->exporter);
805                 afs_osi_Free(tu, sizeof(struct unixuser));
806             }
807             afs_users[i] = 0;
808         }
809       }
810
811       /* 
812        * Free Servers table allocation 
813        */
814       { 
815         struct server *ts, *nts;
816         struct conn *tc, *ntc;
817         register struct afs_cbr *tcbrp, *tbrp;
818         struct afs_cbr **lcbrpp;
819
820         for (i=0; i < NSERVERS; i++) {
821             for (ts = afs_servers[i]; ts; ts = nts) {
822                 nts = ts->next;
823                 for (sa = ts->addr; sa; sa = sa->next_sa) {     
824                     if (sa->conns) {
825                         /*
826                          * Free all server's connection structs
827                          */
828                         tc = sa->conns;
829                         while (tc) {
830                             ntc = tc->next;
831                             AFS_GUNLOCK();
832                             rx_DestroyConnection(tc->id);
833                             AFS_GLOCK();
834                             afs_osi_Free(tc, sizeof(struct conn));
835                             tc = ntc;
836                         }
837                     }
838                 }
839                 for (tcbrp = ts->cbrs; tcbrp;  tcbrp = tbrp) {
840                     /*
841                      * Free all server's callback structs
842                      */
843                     tbrp = tcbrp->next;
844                     afs_FreeCBR(tcbrp);
845                 }
846                 afs_osi_Free(ts, sizeof(struct server));
847             }
848             afs_servers[i] = 0;
849         }
850       }
851       for (i=0; i<NFENTRIES; i++)
852         fvTable[i] = 0;
853       /* Reinitialize local globals to defaults */
854       for(i=0; i<MAXNUMSYSNAMES; i++)
855         afs_osi_Free(afs_sysnamelist[i], MAXSYSNAME);
856       afs_sysname = 0;
857       afs_sysnamecount = 0;
858       afs_marinerHost = 0;
859       QInit(&CellLRU);      
860       afs_setTimeHost = (struct server *)0;
861       afs_volCounter = 1;
862       afs_waitForever = afs_waitForeverCount = 0;
863       afs_cellindex = 0;
864       afs_nextCellNum = 0x100;
865       afs_FVIndex = -1;
866       afs_server = (struct rx_service *)0;
867       RWLOCK_INIT(&afs_xconn, "afs_xconn");
868       memset((char *)&afs_rootFid, 0, sizeof(struct VenusFid));
869       RWLOCK_INIT(&afs_xuser, "afs_xuser");
870       RWLOCK_INIT(&afs_xvolume, "afs_xvolume"), RWLOCK_INIT(&afs_xcell, "afs_xcell");
871       RWLOCK_INIT(&afs_xserver, "afs_xserver"), LOCK_INIT(&afs_puttofileLock, "afs_puttofileLock");
872     }
873     
874 } /*shutdown_AFS*/