Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/libexec/lfs_cleanerd Check for ENOENT return from lfs_{bmapv...



details:   https://anonhg.NetBSD.org/src/rev/b0966bc58cde
branches:  trunk
changeset: 499564:b0966bc58cde
user:      perseant <perseant%NetBSD.org@localhost>
date:      Wed Nov 22 22:17:39 2000 +0000

description:
Check for ENOENT return from lfs_{bmapv,markv} and do the right thing with it,
avoiding needless looping (possibly infinite looping) on certain kinds of
errors.

Get rid of erroneous free() in error return from add_segment.

Patch from Jesse Off <joff%gci-net.com@localhost> (PR #11547).

diffstat:

 libexec/lfs_cleanerd/cleanerd.c |  104 ++++++++++++++++++++--------------------
 1 files changed, 52 insertions(+), 52 deletions(-)

diffs (295 lines):

diff -r b16244084ee5 -r b0966bc58cde libexec/lfs_cleanerd/cleanerd.c
--- a/libexec/lfs_cleanerd/cleanerd.c   Wed Nov 22 22:11:34 2000 +0000
+++ b/libexec/lfs_cleanerd/cleanerd.c   Wed Nov 22 22:17:39 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cleanerd.c,v 1.25 2000/11/13 22:12:50 perseant Exp $   */
+/*     $NetBSD: cleanerd.c,v 1.26 2000/11/22 22:17:39 perseant Exp $   */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -40,7 +40,7 @@
 #if 0
 static char sccsid[] = "@(#)cleanerd.c 8.5 (Berkeley) 6/10/95";
 #else
-__RCSID("$NetBSD: cleanerd.c,v 1.25 2000/11/13 22:12:50 perseant Exp $");
+__RCSID("$NetBSD: cleanerd.c,v 1.26 2000/11/22 22:17:39 perseant Exp $");
 #endif
 #endif /* not lint */
 
@@ -61,6 +61,7 @@
 #include <time.h>
 #include <unistd.h>
 #include <util.h>
+#include <errno.h>
 
 #include <syslog.h>
 
@@ -169,7 +170,7 @@
                 * priority = ((seg_size - live) * age) / (seg_size + live)
                 */
                if (live < 0 || live > seg_size(lfsp)) {
-                        syslog(LOG_NOTICE,"bad segusage count: %ld", live);
+                       syslog(LOG_NOTICE,"bad segusage count: %ld", live);
                        live = 0;
                }
                return (lblkno(lfsp, seg_size(lfsp) - live) * age)
@@ -251,7 +252,7 @@
                err(1, "lfs_cleanerd: filesystem %s isn't an LFS!", fs_name);
        }
 
-        /* should we become a daemon, chdir to / & close fd's */
+       /* should we become a daemon, chdir to / & close fd's */
        if (debug == 0) {
                if (daemon(0, 0) == -1)
                        err(1, "lfs_cleanerd: couldn't become a daemon!");
@@ -298,11 +299,11 @@
                        }
                        goto loop;
                }
-                openlog("lfs_cleanerd", LOG_NDELAY|LOG_PID, LOG_DAEMON);
-        } else {
-                openlog("lfs_cleanerd", LOG_NDELAY|LOG_PID|LOG_PERROR,
-                        LOG_DAEMON);
-        }
+               openlog("lfs_cleanerd", LOG_NDELAY | LOG_PID, LOG_DAEMON);
+       } else {
+               openlog("lfs_cleanerd", LOG_NDELAY|LOG_PID|LOG_PERROR,
+                       LOG_DAEMON);
+       }
 
        signal(SIGINT, sig_report);
        signal(SIGUSR1, sig_report);
@@ -328,12 +329,12 @@
                        continue;
 
                fsid = lstatfsp->f_fsid;
-                if(debug > 1)
-                    syslog(LOG_DEBUG,"Cleaner going to sleep.");
+               if(debug > 1)
+                       syslog(LOG_DEBUG,"Cleaner going to sleep.");
                if (lfs_segwait(&fsid, &timeout) < 0)
                        syslog(LOG_WARNING,"lfs_segwait returned error.");
-                if(debug > 1)
-                    syslog(LOG_DEBUG,"Cleaner waking up.");
+               if(debug > 1)
+                       syslog(LOG_DEBUG,"Cleaner waking up.");
        }
 }
 
@@ -351,7 +352,7 @@
        u_long db_per_seg;
 
        lfsp = &fsp->fi_lfs;
-        /*
+       /*
         * Compute the maximum possible number of free segments, given the
         * number of free blocks.
         */
@@ -364,13 +365,13 @@
         */
        now = time((time_t *)NULL);
 
-        if(debug > 1) {
+       if(debug > 1) {
                syslog(LOG_DEBUG, "db_per_seg = %lu bfree = %u avail = %d,"
                       " bfree = %u, ", db_per_seg, fsp->fi_cip->bfree,
                       fsp->fi_cip->avail, fsp->fi_cip->bfree);
                syslog(LOG_DEBUG, "clean segs = %d, max_free_segs = %ld",
                       fsp->fi_cip->clean, max_free_segs);
-        }
+       }
 
        if ((fsp->fi_cip->bfree - fsp->fi_cip->avail > db_per_seg &&
             fsp->fi_cip->avail < (long)db_per_seg &&
@@ -379,7 +380,7 @@
             (fsp->fi_cip->clean <= lfsp->lfs_minfreeseg ||
              fsp->fi_cip->clean < max_free_segs * BUSY_LIM)))
        {
-                if(debug)
+               if(debug)
                        syslog(LOG_DEBUG, "Cleaner Running  at %s"
                               " (%d of %lu segments available, avail = %d,"
                               " bfree = %u)",
@@ -428,13 +429,13 @@
                if (loadavg[ONE_MIN] < load_threshold
                    && fsp->fi_cip->clean < max_free_segs * IDLE_LIM)
                {
-                        if(debug)
+                       if (debug)
                                syslog(LOG_DEBUG, "Cleaner Running  at %s "
                                       "(system load %.1f, %d of %lu segments available)",
                                        ctime(&now), loadavg[ONE_MIN],
                                        fsp->fi_cip->clean, max_free_segs);
                        clean_fs(fsp, cost_benefit, nsegs, options);
-                       if(do_quit) {
+                       if (do_quit) {
                                if(debug)
                                        syslog(LOG_INFO,"Cleaner shutting down");
                                exit(0);
@@ -442,7 +443,7 @@
                        return (1);
                }
        }
-        if(debug > 1) {
+       if (debug > 1) {
                if (fsp->fi_cip->bfree - fsp->fi_cip->avail <= db_per_seg)
                        syslog(LOG_DEBUG, "condition 1 false");
                if (fsp->fi_cip->avail >= (long)db_per_seg)
@@ -492,7 +493,7 @@
                        syslog(LOG_DEBUG,"Wiping empty segment %ld",sp->sl_id);
                if(lfs_segclean(fsidp, sp->sl_id) < 0)
                        syslog(LOG_NOTICE,"lfs_segclean failed empty segment %ld: %m", sp->sl_id);
-                ++cleaner_stats.segs_empty;
+               ++cleaner_stats.segs_empty;
                sp++;
                i--;
        }
@@ -510,9 +511,9 @@
        if(fsp->fi_cip->clean < nsegs)
                nsegs = fsp->fi_cip->clean;
 
-        if(debug > 1)
-            syslog(LOG_DEBUG, "clean_fs: found %ld segments to clean in %s",
-                   i, fsp->fi_statfsp->f_mntonname);
+       if (debug > 1)
+               syslog(LOG_DEBUG, "clean_fs: found %ld segments to clean in %s",
+                       i, fsp->fi_statfsp->f_mntonname);
 
        if (i) {
                sbp = (SEGS_AND_BLOCKS *)malloc(sizeof(SEGS_AND_BLOCKS));
@@ -527,7 +528,7 @@
                                if (add_segment(fsp, sp, sbp) < 0) {
                                        syslog(LOG_NOTICE,"add_segment failed"
                                               " segment %ld: %m", sp->sl_id);
-                                       if (sbp->nsegs == 0)
+                                       if (sbp->nsegs == 0 && errno != ENOENT)
                                                continue;
                                        else
                                                break;
@@ -543,7 +544,7 @@
                                if (add_segment(fsp, sp, sbp) != 0) {
                                        syslog(LOG_NOTICE,"add_segment failed"
                                               " segment %ld: %m", sp->sl_id);
-                                       if (sbp->nsegs == 0)
+                                       if (sbp->nsegs == 0 && errno != ENOENT)
                                                continue;
                                        else
                                                break;
@@ -613,8 +614,8 @@
 
        lfsp = &fsp->fi_lfs;
 
-        if(debug > 1)
-            syslog(LOG_DEBUG,"Entering choose_segments");
+       if (debug > 1)
+               syslog(LOG_DEBUG,"Entering choose_segments");
        dump_super(lfsp);
        dump_cleaner_info(fsp->fi_cip);
 
@@ -624,13 +625,13 @@
                        fflush(stdout);
                }
                sup = SEGUSE_ENTRY(lfsp, fsp->fi_segusep, i);
-                if(debug > 2)
-                    PRINT_SEGUSE(sup, i);
+               if (debug > 2)
+                       PRINT_SEGUSE(sup, i);
                if (!(sup->su_flags & SEGUSE_DIRTY) ||
                    sup->su_flags & SEGUSE_ACTIVE)
                        continue;
-                if(debug > 2)
-                    syslog(LOG_DEBUG, "\tchoosing segment %d", i);
+               if (debug > 2)
+                       syslog(LOG_DEBUG, "\tchoosing segment %d", i);
                sp->sl_cost = (*cost_func)(fsp, sup);
                sp->sl_id = i;
                sp->sl_bytes = sup->su_nbytes;
@@ -651,8 +652,8 @@
                               seglist[i].sl_bytes, seglist[i].sl_cost);
                }
 
-        if(debug > 1)
-            syslog(LOG_DEBUG,"Returning %d segments", nsegs);
+       if (debug > 1)
+               syslog(LOG_DEBUG,"Returning %d segments", nsegs);
 
        return (nsegs);
 }
@@ -679,7 +680,7 @@
        daddr_t seg_addr;
        int num_blocks, i, j, error;
        int seg_isempty=0;
-        unsigned long *lp;
+       unsigned long *lp;
 
        lfsp = &fsp->fi_lfs;
        sp = SEGUSE_ENTRY(lfsp, fsp->fi_segusep, id);
@@ -687,8 +688,8 @@
        error = 0;
        tba = NULL;
 
-        syslog(LOG_DEBUG, "adding segment %d: contains %lu bytes", id,
-                   (unsigned long)sp->su_nbytes);
+       syslog(LOG_DEBUG, "adding segment %d: contains %lu bytes", id,
+               (unsigned long)sp->su_nbytes);
 
        /* XXX could add debugging to verify that segment is really empty */
        if (sp->su_nbytes == 0) {
@@ -718,8 +719,8 @@
        }
        cleaner_stats.blocks_read += fsp->fi_lfs.lfs_ssize;
 
-        if(debug > 1)
-            syslog(LOG_DEBUG, "lfs_segmapv returned %d blocks", num_blocks);
+       if (debug > 1)
+               syslog(LOG_DEBUG, "lfs_segmapv returned %d blocks", num_blocks);
 
        /* get the current disk address of blocks contained by the segment */
        if ((error = lfs_bmapv(&fsp->fi_statfsp->f_fsid, tba,
@@ -798,15 +799,16 @@
                else
                        slp->sl_bytes += tba[i].bi_size;
 
-        if(debug > 1) {
-            syslog(LOG_DEBUG, "after bmapv still have %d blocks", num_blocks);
-            if (num_blocks)
-                syslog(LOG_DEBUG, "BLOCK INFOS");
-            for (_bip = tba, i=0; i < num_blocks; ++_bip, ++i) {
-                PRINT_BINFO(_bip);
-                lp = (u_long *)_bip->bi_bp;
-            }
-        }
+       if(debug > 1) {
+               syslog(LOG_DEBUG, "after bmapv still have %d blocks",
+                       num_blocks);
+               if (num_blocks)
+                       syslog(LOG_DEBUG, "BLOCK INFOS");
+               for (_bip = tba, i=0; i < num_blocks; ++_bip, ++i) {
+                       PRINT_BINFO(_bip);
+                       lp = (u_long *)_bip->bi_bp;
+               }
+       }
 
        /* Compress segment buffer, if necessary */
        if (slp->sl_bytes < seg_size(lfsp) / 2) {
@@ -846,8 +848,6 @@
        --sbp->nsegs;
        if (tba)
                free(tba);
-       if (sbp->ba)
-               free(sbp->ba);
        if (error) {
                sp->su_flags |= SEGUSE_ERROR;
                ++cleaner_stats.segs_error;
@@ -887,9 +887,9 @@
                                       bp, clean_blocks)) < 0) {
                        syslog(LOG_WARNING,"clean_segment: lfs_markv failed: %m");
                        ++cleaner_stats.segs_error;
+                       if (errno == ENOENT) break;
                }
-               else
-                       sbp->nb -= clean_blocks;
+               sbp->nb -= clean_blocks;
        }
 
        /* Clean up */



Home | Main Index | Thread Index | Old Index