afs: Actually free resources during warm shutdown 16/13716/3
authorAndrew Deason <adeason@dson.org>
Sun, 21 Jul 2019 22:02:34 +0000 (17:02 -0500)
committerBenjamin Kaduk <kaduk@mit.edu>
Fri, 30 Aug 2019 15:03:12 +0000 (11:03 -0400)
Currently, the shutdown_*() code paths for several subsystems only
free the memory for that subsystem for "cold" shutdowns, and not for
"warm" shutdowns. This means the memory gets leaked during a "warm"
shutdown, since we never free these resources anywhere else.
Specifically, this happens in shutdown_bufferpackage, shutdown_AFS,
and shutdown_osinet.

To avoid these leaks for warm shutdowns, just move the
afs_cold_shutdown check around a little, so we free the relevant items
in either codepath.

Change-Id: I748311784f512b3e2f25bdcaa6629108a5790212
Reviewed-on: https://gerrit.openafs.org/13716
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

src/afs/afs_buffer.c
src/afs/afs_cell.c
src/afs/afs_init.c
src/afs/afs_osi_alloc.c

index cb99d07..8bccee4 100644 (file)
@@ -583,17 +583,20 @@ shutdown_bufferpackage(void)
     AFS_STATCNT(shutdown_bufferpackage);
     /* Free all allocated Buffers and associated buffer pages */
     DFlush();
+
+    dinit_flag = 0;
+    tp = Buffers;
+    for (i = 0; i < nbuffers; i += NPB, tp += NPB) {
+       afs_osi_Free(tp->data, NPB * AFS_BUFFER_PAGESIZE);
+    }
+    afs_osi_Free(Buffers, nbuffers * sizeof(struct buffer));
+    Buffers = NULL;
+    nbuffers = 0;
+    timecounter = 1;
+    for (i = 0; i < PHSIZE; i++)
+       phTable[i] = NULL;
+
     if (afs_cold_shutdown) {
-       dinit_flag = 0;
-       tp = Buffers;
-       for (i = 0; i < nbuffers; i += NPB, tp += NPB) {
-           afs_osi_Free(tp->data, NPB * AFS_BUFFER_PAGESIZE);
-       }
-       afs_osi_Free(Buffers, nbuffers * sizeof(struct buffer));
-       nbuffers = 0;
-       timecounter = 1;
-       for (i = 0; i < PHSIZE; i++)
-           phTable[i] = 0;
        memset(&afs_bufferLock, 0, sizeof(afs_lock_t));
     }
 }
index 29cf64f..ac5d75c 100644 (file)
@@ -1097,7 +1097,9 @@ shutdown_cell(void)
        afs_osi_FreeStr(afs_cellname_inode.ufs);
     }
 #endif
-    AFS_RWLOCK_INIT(&afs_xcell, "afs_xcell");
+    if (afs_cold_shutdown) {
+       AFS_RWLOCK_INIT(&afs_xcell, "afs_xcell");
+    }
 
     for (cq = CellLRU.next; cq != &CellLRU; cq = tq) {
        tc = QTOC(cq);
index 9a6c5b8..fe30973 100644 (file)
@@ -820,62 +820,65 @@ 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();
 }
index f2e5d4b..78254d6 100644 (file)
@@ -181,26 +181,29 @@ osi_AllocSmallSpace(size_t size)
 void
 shutdown_osinet(void)
 {
-    AFS_STATCNT(shutdown_osinet);
 #ifndef AFS_PRIVATE_OSI_ALLOCSPACES
-    if (afs_cold_shutdown) {
-       struct osi_packet *tp;
+    struct osi_packet *tp;
+#endif
+
+    AFS_STATCNT(shutdown_osinet);
 
-       while ((tp = freePacketList)) {
-           freePacketList = tp->next;
-           afs_osi_Free(tp, AFS_LRALLOCSIZ);
+#ifndef AFS_PRIVATE_OSI_ALLOCSPACES
+    while ((tp = freePacketList)) {
+       freePacketList = tp->next;
+       afs_osi_Free(tp, AFS_LRALLOCSIZ);
 #ifdef  KERNEL_HAVE_PIN
-           unpin(tp, AFS_LRALLOCSIZ);
+       unpin(tp, AFS_LRALLOCSIZ);
 #endif
-       }
+    }
 
-       while ((tp = freeSmallList)) {
-           freeSmallList = tp->next;
-           afs_osi_Free(tp, AFS_SMALLOCSIZ);
+    while ((tp = freeSmallList)) {
+       freeSmallList = tp->next;
+       afs_osi_Free(tp, AFS_SMALLOCSIZ);
 #ifdef  KERNEL_HAVE_PIN
-           unpin(tp, AFS_SMALLOCSIZ);
+       unpin(tp, AFS_SMALLOCSIZ);
 #endif
-       }
+    }
+    if (afs_cold_shutdown) {
        LOCK_INIT(&osi_fsplock, "osi_fsplock");
        LOCK_INIT(&osi_flplock, "osi_flplock");
     }