Source-Changes-HG archive

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

[src/netbsd-1-5]: src Pull up LFS userland changes to correspond with the pre...



details:   https://anonhg.NetBSD.org/src/rev/d9cc9e40bbc3
branches:  netbsd-1-5
changeset: 489465:d9cc9e40bbc3
user:      perseant <perseant%NetBSD.org@localhost>
date:      Thu Sep 14 18:53:19 2000 +0000

description:
Pull up LFS userland changes to correspond with the previous commit's
kernel changes (approved by thorpej):

[basesrc/libexec/lfs_cleanerd:]
cleanerd.c, 1.20--1.22           (MIN_FREE_SEG -> lfs_minfreeseg ;
                                 read bfree/avail from CLEANERINFO ;
                                 changes to definition of -n and -b)
lfs_cleanerd.8, 1.7              (update man page to current behavior)
library.c, 1.16                  (fix comment)

[basesrc/sbin/fsck_lfs:]
pass5.c, 1.6                     (calculate/fix lfs_avail and lfs_bfree)

[basesrc/sbin/newfs_lfs:]
config.h, 1.2--1.5               (MINFREE=20, remove FFS cruft ;
                                 add DFL_MIN_FREE_SEGS=8 and MINFREE=10 ;
                                 set DFL_MIN_FREE_SEGS=10 ;
                                 set DFL_MIN_FREE_SEGS=20)
extern.h, 1.2                    (correct function declaration for make_lfs)
newfs.c, 1.4                     (add -M flag)
lfs.c, 1.13--1.14, 1.16--1.18    (change lfs_bfree initialization ;
                                 MIN_FREE_SEG -> lfs_minfreeseg ;
                                 only 10 superblocks and print nicely ;
                                 correct init calculation of
                                   lfs_bfree/lfs_avail to allow fs to
                                                                   fill ;
                                 make -N dtrt)

[basesrc/sbin/mount_lfs:]
mount_lfs.8, 1.7                 (document -N, -b flags)
mount_lfs.c, 1.10                (default cleanerd to -b -n 4; add -N,
                                 -b flags)

[basesrc/usr.sbin/dumplfs:]
dumplfs.c, 1.15                  (print only the SEGUSEs specified with -s)

diffstat:

 libexec/lfs_cleanerd/cleanerd.c     |  342 +++++++++++++++++++++++------------
 libexec/lfs_cleanerd/lfs_cleanerd.8 |   52 +++++-
 libexec/lfs_cleanerd/library.c      |    6 +-
 sbin/fsck_lfs/pass5.c               |   40 ++++-
 sbin/mount_lfs/mount_lfs.8          |   14 +-
 sbin/mount_lfs/mount_lfs.c          |   23 ++-
 sbin/newfs_lfs/config.h             |   64 +------
 sbin/newfs_lfs/extern.h             |    4 +-
 sbin/newfs_lfs/lfs.c                |  121 +++++++----
 sbin/newfs_lfs/newfs.c              |   13 +-
 sbin/newfs_lfs/newfs_lfs.8          |   10 +-
 11 files changed, 440 insertions(+), 249 deletions(-)

diffs (truncated from 1339 to 300 lines):

diff -r 45141c0d4f2b -r d9cc9e40bbc3 libexec/lfs_cleanerd/cleanerd.c
--- a/libexec/lfs_cleanerd/cleanerd.c   Thu Sep 14 18:50:15 2000 +0000
+++ b/libexec/lfs_cleanerd/cleanerd.c   Thu Sep 14 18:53:19 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cleanerd.c,v 1.18.4.1 2000/06/21 05:11:13 perseant Exp $       */
+/*     $NetBSD: cleanerd.c,v 1.18.4.2 2000/09/14 18:53:19 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.18.4.1 2000/06/21 05:11:13 perseant Exp $");
+__RCSID("$NetBSD: cleanerd.c,v 1.18.4.2 2000/09/14 18:53:19 perseant Exp $");
 #endif
 #endif /* not lint */
 
@@ -57,6 +57,7 @@
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <time.h>
 #include <unistd.h>
 
@@ -94,6 +95,14 @@
        int seg;
 };
 
+typedef struct {
+       int nsegs;      /* number of segments */
+       struct seglist **segs; /* segment numbers, costs, etc */
+       int nb;         /* total number of blocks */
+       BLOCK_INFO *ba; /* accumulated block_infos */
+       caddr_t *buf;   /* segment buffers */
+} SEGS_AND_BLOCKS;
+
 #define        CLEAN_BYTES     0x1
 
 /* function prototypes for system calls; not sure where they should go */
@@ -108,7 +117,8 @@
             unsigned long (*)(FS_INFO *, SEGUSE *)));
 void    clean_fs __P((FS_INFO  *, unsigned long (*)(FS_INFO *, SEGUSE *), int, long));
 int     clean_loop __P((FS_INFO *, int, long));
-int     clean_segment __P((FS_INFO *, struct seglist *));
+int     add_segment __P((FS_INFO *, struct seglist *, SEGS_AND_BLOCKS *));
+int     clean_segments __P((FS_INFO *, SEGS_AND_BLOCKS *));
 unsigned long   cost_benefit __P((FS_INFO *, SEGUSE *));
 int     cost_compare __P((const void *, const void *));
 void    sig_report __P((int));
@@ -144,6 +154,9 @@
        lfsp = &fsp->fi_lfs;
        if (live == 0) { /* No cost, only benefit. */
                return lblkno(lfsp, seg_size(lfsp)) * t.tv_sec;
+       } else if (su->su_flags & SEGUSE_ERROR) {
+               /* No benefit: don't even try */
+               return 0;
        } else {
                /* 
                 * from lfsSegUsage.c (Mendel's code).
@@ -312,17 +325,19 @@
        int nsegs;
        long options;
 {
+       struct lfs *lfsp;
        double loadavg[MAXLOADS];
        time_t  now;
        u_long max_free_segs;
        u_long db_per_seg;
 
+       lfsp = &fsp->fi_lfs;
         /*
         * Compute the maximum possible number of free segments, given the
         * number of free blocks.
         */
-       db_per_seg = fragstodb(&fsp->fi_lfs, fsp->fi_lfs.lfs_ssize);
-       max_free_segs = (fsp->fi_statfsp->f_bfree / fsp->fi_lfs.lfs_ssize) >> fsp->fi_lfs.lfs_fbshift;
+       db_per_seg = fsbtodb(lfsp, lfsp->lfs_ssize);
+       max_free_segs = fsp->fi_cip->bfree / db_per_seg + lfsp->lfs_minfreeseg;
        
        /* 
         * We will clean if there are not enough free blocks or total clean
@@ -331,23 +346,26 @@
        now = time((time_t *)NULL);
 
         if(debug > 1) {
-            syslog(LOG_DEBUG, "db_per_seg = %lu max_free_segs = %lu, bfree = %u avail = %d ",
-                   db_per_seg, max_free_segs, fsp->fi_lfs.lfs_bfree,
-                   fsp->fi_lfs.lfs_avail);
-           syslog(LOG_DEBUG, "clean segs = %d, max_free_segs = %ld",
-                  fsp->fi_cip->clean, max_free_segs);
-            syslog(LOG_DEBUG, "clean = %d", fsp->fi_cip->clean);
+               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_lfs.lfs_bfree - fsp->fi_lfs.lfs_avail > db_per_seg &&
-            fsp->fi_lfs.lfs_avail < db_per_seg) ||
+       if ((fsp->fi_cip->bfree - fsp->fi_cip->avail > db_per_seg &&
+            fsp->fi_cip->avail < (long)db_per_seg &&
+            fsp->fi_cip->bfree > (long)db_per_seg) ||
            (fsp->fi_cip->clean < max_free_segs &&
-            (fsp->fi_cip->clean <= MIN_SEGS(&fsp->fi_lfs) ||
+            (fsp->fi_cip->clean <= lfsp->lfs_minfreeseg ||
              fsp->fi_cip->clean < max_free_segs * BUSY_LIM)))
        {
                 if(debug)
-                       syslog(LOG_DEBUG, "Cleaner Running  at %s (%d of %lu segments available)",
-                              ctime(&now), fsp->fi_cip->clean, max_free_segs);
+                       syslog(LOG_DEBUG, "Cleaner Running  at %s"
+                              " (%d of %lu segments available, avail = %d,"
+                              " bfree = %u)",
+                              ctime(&now), fsp->fi_cip->clean, max_free_segs,
+                              fsp->fi_cip->avail, fsp->fi_cip->bfree);
                clean_fs(fsp, cost_benefit, nsegs, options);
                if(do_quit) {
                        if(debug)
@@ -405,8 +423,20 @@
                        return (1);
                }
        }
-        if(debug > 1)
-            syslog(LOG_DEBUG, "Cleaner Not Running at %s", ctime(&now));
+        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)
+                       syslog(LOG_DEBUG, "condition 2 false");
+               if (fsp->fi_cip->clean >= max_free_segs)
+                       syslog(LOG_DEBUG, "condition 3 false");
+               if (fsp->fi_cip->clean > lfsp->lfs_minfreeseg)
+                       syslog(LOG_DEBUG, "condition 4 false");
+               if (fsp->fi_cip->clean >= max_free_segs * BUSY_LIM)
+                       syslog(LOG_DEBUG, "condition 5 false");
+
+               syslog(LOG_DEBUG, "Cleaner Not Running at %s", ctime(&now));
+       }
        return (0);
 }
 
@@ -419,10 +449,15 @@
        long options;
 {
        struct seglist *segs, *sp;
-       long int to_clean, cleaned_bytes;
+       long int to_clean, cleaned_bytes, seg_size;
        unsigned long i, j, total;
        struct rusage ru;
+       fsid_t *fsidp;
        int error;
+       SEGS_AND_BLOCKS *sbp;
+
+       fsidp = &fsp->fi_statfsp->f_fsid;
+       seg_size = (1 << fsp->fi_lfs.lfs_segshift);
 
        if ((segs =
            malloc(fsp->fi_lfs.lfs_nseg * sizeof(struct seglist))) == NULL) {
@@ -432,11 +467,11 @@
        total = i = choose_segments(fsp, segs, cost_func);
 
        /* If we can get lots of cleaning for free, do it now */
-       sp=segs;
+       sp = segs;
        for(j=0; j < total && sp->sl_bytes == 0; j++) {
                if(debug)
                        syslog(LOG_DEBUG,"Wiping empty segment %ld",sp->sl_id);
-               if(lfs_segclean(&fsp->fi_statfsp->f_fsid, sp->sl_id) < 0)
+               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;
                sp++;
@@ -447,65 +482,79 @@
                return;
        }
 
+#if 0
        /* If we relly need to clean a lot, do it now */
-       if(fsp->fi_cip->clean < 2*MIN_FREE_SEGS)
-               nsegs = MAX(nsegs,MIN_FREE_SEGS);
+       if(fsp->fi_cip->clean < 2 * fsp->fi_lfs.lfs_minfreeseg)
+               nsegs = MAX(nsegs, fsp->fi_lfs.lfs_minfreeseg);
+#endif
        /* But back down if we haven't got that many free to clean into */
        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 file system %s",
+            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));
+               memset(sbp, 0, sizeof(SEGS_AND_BLOCKS));
+
                /* Check which cleaning algorithm to use. */
                if (options & CLEAN_BYTES) {
+                       /* Count bytes */
                        cleaned_bytes = 0;
                        to_clean = nsegs << fsp->fi_lfs.lfs_segshift;
-                       for (; i && cleaned_bytes < to_clean;
-                           i--, ++sp) {
-                               if (clean_segment(fsp, sp) < 0)
-                                       syslog(LOG_NOTICE,"clean_segment failed segment %ld: %m", sp->sl_id);
-                               else if (lfs_segclean(&fsp->fi_statfsp->f_fsid,
-                                                     sp->sl_id) < 0)
-                                       syslog(LOG_NOTICE,"lfs_segclean failed segment %ld: %m", sp->sl_id);
-                               else {
-                                       if(debug) {
-                                               syslog(LOG_DEBUG,
-                                                      "Cleaned segment %ld (%ld->%ld/%ld)",
-                                                      sp->sl_id,
-                                                      (1<<fsp->fi_lfs.lfs_segshift) - sp->sl_bytes,
-                                                      cleaned_bytes + (1<<fsp->fi_lfs.lfs_segshift) - sp->sl_bytes,
-                                                      to_clean);
-                                       }
-                                       cleaned_bytes += (1<<fsp->fi_lfs.lfs_segshift) - sp->sl_bytes;
+                       for (; i && cleaned_bytes < to_clean; i--, ++sp) {
+                               if (add_segment(fsp, sp, sbp) < 0) {
+                                       syslog(LOG_NOTICE,"add_segment failed"
+                                              " segment %ld: %m", sp->sl_id);
+                                       if (sbp->nsegs == 0)
+                                               continue;
+                                       else
+                                               break;
+                               }
+                               cleaned_bytes += sp->sl_bytes;
+                       }
+               } else {
+                       /* Count segments */
+                       for (i = MIN(i, nsegs); i-- ; ++sp) {
+                               total--;
+                               syslog(LOG_DEBUG, "Cleaning segment %ld"
+                                      " (of %ld choices)", sp->sl_id, i + 1);
+                               if (add_segment(fsp, sp, sbp) != 0) {
+                                       syslog(LOG_NOTICE,"add_segment failed"
+                                              " segment %ld: %m", sp->sl_id);
+                                       if (sbp->nsegs == 0)
+                                               continue;
+                                       else
+                                               break;
                                }
                        }
-               } else
-                       for (i = MIN(i, nsegs); i-- ; ++sp) {
-                               total--;
-                               syslog(LOG_DEBUG,"Cleaning segment %ld (of %ld choices)", sp->sl_id, i+1);
-                               if (clean_segment(fsp, sp) < 0) {
-                                       syslog(LOG_NOTICE,"clean_segment failed segment %ld: %m", sp->sl_id);
-                                       if(total)
-                                               i++;
-                               }
-                               else if (lfs_segclean(&fsp->fi_statfsp->f_fsid,
-                                   sp->sl_id) < 0)
-                                       syslog(LOG_NOTICE,"lfs_segclean failed segment %ld: %m", sp->sl_id);
-                               else if(debug)
-                                       syslog(LOG_DEBUG,"Completed cleaning segment %ld (of %ld choices)", sp->sl_id, i+1);
+               }
+               if (clean_segments(fsp, sbp) >= 0) {
+                       for (j = 0; j < sbp->nsegs; j++) {
+                               sp = sbp->segs[j];
+                               if (lfs_segclean(fsidp, sp->sl_id) < 0)
+                                       syslog(LOG_NOTICE,
+                                              "lfs_segclean: segment %ld: %m",
+                                              sp->sl_id);
+                               else
+                                       syslog(LOG_DEBUG,
+                                              "finished segment %ld",
+                                              sp->sl_id);
                        }
+               }
+               free(sbp);
        }
        free(segs);
        if(debug) {
-               error=getrusage(RUSAGE_SELF,&ru);
+               error = getrusage(RUSAGE_SELF, &ru);
                if(error) {
-                       syslog(LOG_INFO,"getrusage returned error: %m");
+                       syslog(LOG_INFO, "getrusage returned error: %m");
                } else {
-                       syslog(LOG_DEBUG,"Current usage: maxrss=%ld, idrss=%ld, isrss=%ld",
-                              ru.ru_maxrss,ru.ru_idrss,ru.ru_isrss);
+                       syslog(LOG_DEBUG, "Current usage: maxrss=%ld,"
+                              " idrss=%ld, isrss=%ld", ru.ru_maxrss,
+                              ru.ru_idrss, ru.ru_isrss);
                }
        }
 }
@@ -547,13 +596,17 @@
        dump_cleaner_info(fsp->fi_cip);
 
        for (sp = seglist, i = 0; i < lfsp->lfs_nseg; ++i) {
+               if (debug > 1) {
+                       printf("%d...", i);
+                       fflush(stdout);



Home | Main Index | Thread Index | Old Index