afs: Free rx/rxevent resources during shutdown
[openafs.git] / src / afs / afs_init.c
index d588c75..f2414f7 100644 (file)
@@ -99,6 +99,7 @@ afs_CacheInit(afs_int32 astatSize, afs_int32 afiles, afs_int32 ablocks,
              afs_int32 dynamic_vcaches)
 {
     afs_int32 i;
+    int code;
     struct volume *tv;
 
     AFS_STATCNT(afs_CacheInit);
@@ -152,7 +153,10 @@ afs_CacheInit(afs_int32 astatSize, afs_int32 afiles, afs_int32 ablocks,
     afs_cacheFiles = afiles;
     afs_cacheStats = astatSize;
     afs_vcacheInit(astatSize);
-    afs_dcacheInit(afiles, ablocks, aDentries, achunk, aflags);
+    code = afs_dcacheInit(afiles, ablocks, aDentries, achunk, aflags);
+    if (code) {
+        return code;
+    }
 #if defined(AFS_LINUX26_ENV) && defined(STRUCT_TASK_STRUCT_HAS_CRED)
     /*
      * Save current credentials for later access to disk cache files.
@@ -330,11 +334,23 @@ afs_InitVolumeInfo(char *afile)
     if (code)
        return code;
     tfile = afs_CFileOpen(&volumeInode);
+    osi_Assert(tfile);
     afs_CFileTruncate(tfile, 0);
     afs_CFileClose(tfile);
     return 0;
 }
 
+void
+afs_InitFHeader(struct afs_fheader *aheader)
+{
+    memset(aheader, 0, sizeof(*aheader));
+    aheader->magic = AFS_FHMAGIC;
+    aheader->version = AFS_CI_VERSION;
+    aheader->dataSize = sizeof(struct fcache);
+    aheader->firstCSize = AFS_FIRSTCSIZE;
+    aheader->otherCSize = AFS_OTHERCSIZE;
+}
+
 /*
  * afs_InitCacheInfo
  *
@@ -416,7 +432,7 @@ afs_InitCacheInfo(char *afile)
 #elif defined(AFS_DARWIN80_ENV)
         afs_cacheVfsp = vnode_mount(filevp);
        if (afs_cacheVfsp && ((st = *(vfs_statfs(afs_cacheVfsp))),1))
-#elif defined(AFS_FBSD80_ENV)
+#elif defined(AFS_FBSD_ENV)
        if (!VFS_STATFS(filevp->v_mount, &st))
 #elif defined(AFS_NBSD50_ENV)
        if (!VFS_STATVFS(filevp->v_vfsp, &st))
@@ -490,11 +506,7 @@ afs_InitCacheInfo(char *afile)
     }
     if (!goodFile) {
        /* write out a good file label */
-       theader.magic = AFS_FHMAGIC;
-       theader.firstCSize = AFS_FIRSTCSIZE;
-       theader.otherCSize = AFS_OTHERCSIZE;
-       theader.dataSize = sizeof(struct fcache);
-       theader.version = AFS_CI_VERSION;
+       afs_InitFHeader(&theader);
        afs_osi_Write(tfile, 0, &theader, sizeof(theader));
        /*
         * Truncate the rest of the file, since it may be arbitrarily
@@ -685,7 +697,7 @@ void
 shutdown_cache(void)
 {
     AFS_STATCNT(shutdown_cache);
-    afs_WriteThroughDSlots();
+    osi_Assert(afs_WriteThroughDSlots() == 0);
     if (1/*afs_cold_shutdown*/) {
        afs_cacheinit_flag = 0;
        shutdown_dcache();
@@ -808,62 +820,67 @@ shutdown_AFS(void)
     int i;
 
     AFS_STATCNT(shutdown_AFS);
-    if (afs_cold_shutdown) {
-       afs_resourceinit_flag = 0;
 
-       shutdown_volume();
+    afs_resourceinit_flag = 0;
 
-       /*
-        * Free FreeVolList allocations
-        */
-       afs_osi_Free(Initialafs_freeVolList,
-                    afs_memvolumes * sizeof(struct volume));
-       afs_freeVolList = Initialafs_freeVolList = 0;
-
-       /* XXX HACK for MEM systems XXX
-        *
-        * For -memcache cache managers when we run out of free in memory volumes
-        * we simply malloc more; we won't be able to free those additional volumes.
-        */
+    shutdown_volume();
 
-       /*
-        * Free Users table allocation
-        */
-       {
-           struct unixuser *tu, *ntu;
-           for (i = 0; i < NUSERS; i++) {
-               for (tu = afs_users[i]; tu; tu = ntu) {
-                   ntu = tu->next;
-                   if (tu->tokens)
-                       afs_FreeTokens(&tu->tokens);
-                   if (tu->exporter)
-                       EXP_RELE(tu->exporter);
-                   afs_osi_Free(tu, sizeof(struct unixuser));
-               }
-               afs_users[i] = 0;
+    /*
+     * Free FreeVolList allocations
+     */
+    afs_osi_Free(Initialafs_freeVolList,
+                afs_memvolumes * sizeof(struct volume));
+    afs_freeVolList = Initialafs_freeVolList = NULL;
+
+    /* XXX HACK for MEM systems XXX
+     *
+     * For -memcache cache managers when we run out of free in memory volumes
+     * we simply malloc more; we won't be able to free those additional volumes.
+     */
+
+    /*
+     * Free Users table allocation
+     */
+    {
+       struct unixuser *tu, *ntu;
+       for (i = 0; i < NUSERS; i++) {
+           for (tu = afs_users[i]; tu; tu = ntu) {
+               ntu = tu->next;
+               if (tu->tokens)
+                   afs_FreeTokens(&tu->tokens);
+               if (tu->exporter)
+                   EXP_RELE(tu->exporter);
+               afs_osi_Free(tu, sizeof(struct unixuser));
            }
+           afs_users[i] = NULL;
        }
+    }
 
-       for (i = 0; i < NFENTRIES; i++)
-           fvTable[i] = 0;
-       /* Reinitialize local globals to defaults */
-       for (i = 0; i < MAXNUMSYSNAMES; i++)
-           afs_osi_Free(afs_sysnamelist[i], MAXSYSNAME);
-       afs_sysname = 0;
-       afs_sysnamecount = 0;
-       afs_marinerHost = 0;
-       afs_volCounter = 1;
-       afs_waitForever = afs_waitForeverCount = 0;
-       afs_FVIndex = -1;
-       afs_server = (struct rx_service *)0;
+    for (i = 0; i < NFENTRIES; i++)
+       fvTable[i] = 0;
+    /* Reinitialize local globals to defaults */
+    for (i = 0; i < MAXNUMSYSNAMES; i++) {
+       afs_osi_Free(afs_sysnamelist[i], MAXSYSNAME);
+       afs_sysnamelist[i] = NULL;
+    }
+    afs_sysname = NULL;
+    afs_sysnamecount = 0;
+    afs_marinerHost = 0;
+    afs_volCounter = 1;
+    afs_waitForever = afs_waitForeverCount = 0;
+    afs_FVIndex = -1;
+    afs_server = NULL;
+
+    if (afs_cold_shutdown) {
        AFS_RWLOCK_INIT(&afs_xconn, "afs_xconn");
        memset(&afs_rootFid, 0, sizeof(struct VenusFid));
        AFS_RWLOCK_INIT(&afs_xuser, "afs_xuser");
        AFS_RWLOCK_INIT(&afs_xvolume, "afs_xvolume");
        AFS_RWLOCK_INIT(&afs_xserver, "afs_xserver");
        LOCK_INIT(&afs_puttofileLock, "afs_puttofileLock");
-
-       shutdown_cell();
-       shutdown_server();
     }
+    shutdown_cell();
+    shutdown_server();
+    shutdown_rx();
+    shutdown_rxevent();
 }