home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1687 < prev    next >
Internet Message Format  |  1990-12-28  |  7KB

  1. From: mark@zok.UUCP (Mark W. Snitily)
  2. Newsgroups: news.software.b,comp.bugs.sys5,comp.sources.bugs,alt.sources,comp.unix.i386
  3. Subject: Multiple filesystems patch for Bnews 2.11.19
  4. Message-ID: <486@zok.UUCP>
  5. Date: 19 Aug 90 21:57:47 GMT
  6.  
  7.  
  8. News inherently spools all articles on one filesystem.  This poses a problem
  9. when one is running System V since a filesystem is limited to approximately
  10. 64K inodes.  You might have hundreds of MB's but only 64K inodes.  In other
  11. words, when running System V you have a max of 64K spooled articles regardless
  12. of the amount of your disk space.
  13.  
  14. What follows is a patch to inews.c [B News, patchlevel 19] which allows news
  15. articles to be placed on two separate filesystems.  The concept is general but
  16. the following code has only been tested with two filesystems.  Bottom line
  17. result is that by patching inews.c you can doubled the number of news articles
  18. that can be spooled.
  19.  
  20. What I've done is to create two filesystem and mount them on /usr/spool/news
  21. and /usr/spool/news/comp.  The filesystems are about 130MB's and were created
  22. with the maximum number of inodes, (65488 to be exact).  This works out
  23. nicely for spooling about 3 weeks worth of news.  (Actually, the
  24. /usr/spool/news/comp articles are saved for 3 weeks with typically 50MB's
  25. of free space on the filesystem.  Most articles on /usr/spool/news are expired
  26. before 21 days -- 3 weeks of everything except comp articles would easily
  27. overflow 130MB's.)
  28.  
  29. Here's a df of my current news filesystems:
  30.  
  31. Filesystem    kbytes   used avail %used iused ifree %iused Mounted on
  32. /dev/dsk/0s4  130560 119190 11370   91% 45446 20042   69%  /usr/spool/news
  33. /dev/dsk/0s5  130560  70622 59938   54% 20781 44707   31%  /usr/spool/news/comp
  34.  
  35. As you can see, the % of inodes used is actually less than the % of disk used.
  36. :-) :-) :-)
  37.  
  38. Here's the basic concept of the patch:
  39.  
  40.    When hard linking an unbatched news article, if the error returned was
  41.    "cross-device link" (EXDEV), then this article needs to be placed on the
  42.    other filesystem. So...
  43.  
  44.       1) If we have not created a file on the other filesystem, create it.
  45.       2) Otherwise we've already created a file, so hard link to it.
  46.  
  47.    After all hard links have been created for the article, if we created
  48.    a file on the other filesystem, copy the article from the first filesystem
  49.    to the second filesystem.
  50.  
  51. The result is that at most two copies of the article are created, one for
  52. each filesystem; each copy may have multiple hard links.  On the down side,
  53. news unbatches a little slower because of the extra copy.
  54.  
  55. Though I haven't switched over to C news, I've heard that C news unbatches
  56. articles in a similar way (using hard links), so the above concept should
  57. work in C news also.
  58.  
  59. In case it's important, this has been tested under System V R3.2.
  60.  
  61. The patch is only invoked if MULTI_FILESYSTEMS is defined.  I just threw the
  62. define into inews.c since it's the only file that's modified.  In general
  63. though, it should be placed into defs.h and localize.sh.
  64.  
  65. I've been running B news patchlevel 17 with this patch for about 6 months
  66. now without any apparent side effects.  Have just recently upgraded to
  67. patchlevel 19.
  68.  
  69. I'd appreciate hearing from any news gurus out there if you see a fundamental
  70. (or even minor) flaw with the patch.
  71.  
  72. Finally, here's the patch:
  73.  
  74. *** inews.c.org    Sun Aug  5 09:58:43 1990
  75. --- inews.c    Sun Aug 19 13:02:49 1990
  76. ***************
  77. *** 40,45 ****
  78. --- 40,48 ----
  79.   #endif /* !BSD4_2 */
  80.   /* local defines for inews */
  81.   
  82. + #define MULTI_FILESYSTEMS /* Spool news over two separate filesystems.   */
  83. +                           /* Mark W. Snitily  mark@zok.uucp  19-Aug-1990 */
  84.   #define OPTION    0    /* pick up an option string */
  85.   #define STRING    1    /* pick up a string of arguments */
  86.   
  87. ***************
  88. *** 812,817 ****
  89. --- 815,825 ----
  90.   
  91.   char firstbufname[BUFLEN];
  92.   
  93. + #ifdef MULTI_FILESYSTEMS
  94. + static char *cdlinkfn;   /* cross-device link filename */
  95. + static FILE *cdfp;       /* cross-device file pointer  */
  96. + #endif /* MULTI_FILESYSTEMS */
  97.   /*
  98.    *    Link ARTICLE into dir for ngname and update active file.
  99.    */
  100. ***************
  101. *** 878,883 ****
  102. --- 886,917 ----
  103.   #else /* !VMS */
  104.           if (link(ARTICLE, bfr) == 0)
  105.               break;
  106. + #ifdef MULTI_FILESYSTEMS
  107. +    /* If error was a "cross-device link", then this article needs to be
  108. +       placed on the other filesystem.
  109. +       If we have not created the file on the other filesystem, create it.
  110. +       Otherwise, the file already exists on the other filesystem so link to it.
  111. +       For either case, if the create or link was successful, break out of
  112. +       the loop, otherwise an error occurred so continue execution following
  113. +       this code.
  114. +    */
  115. +    if (errno == EXDEV) { /* cross-device link error */
  116. +       if (cdfp == NULL) { /* file on other filesystem doesn't exist */
  117. +          if ((cdfp = xfopen(bfr, "w")) != NULL) { /* create file */
  118. +             cdlinkfn = malloc(strlen(bfr)+1);
  119. +             (void) strcpy(cdlinkfn, bfr);
  120. +             break;
  121. +          }
  122. +       }
  123. +       else { /* already have file on other filesystem, link to it */
  124. +          if (link(cdlinkfn, bfr) == 0)
  125. +             break;
  126. +       }
  127. +    }
  128. + #endif /* MULTI_FILESYSTEMS */
  129.   #endif /* !VMS */
  130.           e = errno;    /* keep log from clobbering it */
  131.           log("Cannot install article as %s: %s", bfr, errmsg(errno));
  132. ***************
  133. *** 979,984 ****
  134. --- 1013,1023 ----
  135.       MKTEMP(ARTICLE);
  136.       tfp = xfopen(ARTICLE, "w");
  137.       linkcount = 0;
  138. + #ifdef MULTI_FILESYSTEMS
  139. +         /* Init cross-device file pointer and cross-device link filename. */
  140. +         cdfp = NULL;
  141. +         cdlinkfn = (char *) 0;
  142. + #endif /* MULTI_FILESYSTEMS */
  143.   
  144.   #ifndef NFSCLIENT
  145.       if (is_invalid) {
  146. ***************
  147. *** 1186,1194 ****
  148. --- 1225,1253 ----
  149.       {
  150.           for (c = 0; c < linkcount; c++)
  151.               free(artlinks[c]);
  152. + #ifdef MULTI_FILESYSTEMS
  153. +         /* If cross-device link, copy temp file to file on other
  154. +            filesystem.  Opening ARTICLE from scratch because I
  155. +            couldn't get "r+" to work with tfp. */
  156. +         if (cdfp != NULL) {
  157. +            FILE *ttfp = xfopen(ARTICLE, "r");
  158. +            rewind(ttfp);
  159. +            while (fgets(bfr, BUFLEN, ttfp) != NULL)
  160. +             fputs(bfr, cdfp);
  161. +            (void) fclose(ttfp);
  162. +         }
  163. + #endif /* MULTI_FILESYSTEMS */
  164.       }
  165.       (void) fclose(tfp);
  166.       (void) fclose(infp);
  167. + #ifdef MULTI_FILESYSTEMS
  168. +     if (cdfp != NULL) { /* perform cleanup */
  169. +        (void) fclose(cdfp);  /* close file on other filesystem */
  170. +        cdfp = NULL;
  171. +        free(cdlinkfn);       /* free filename string */
  172. +        cdlinkfn = (char *) 0;
  173. +     }
  174. + #endif /* MULTI_FILESYSTEMS */
  175.       if (infpbuf) {
  176.           (void) free(infpbuf);
  177.           infpbuf = NULL;
  178.  
  179. -- Mark
  180.  
  181. Mark W. Snitily                 Consulting Services:
  182. 894 Brookgrove Lane             Graphics, Operating Systems, Compilers
  183. Cupertino, CA 95014             (408) 252-0456
  184. mark@zok.uucp                   West Coast UUCP X11 archive site
  185.