home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / sys / sun / admin / 8585 < prev    next >
Encoding:
Text File  |  1992-11-22  |  3.0 KB  |  129 lines

  1. Newsgroups: comp.sys.sun.admin
  2. Path: sparky!uunet!munnari.oz.au!metro!cs.uow.edu.au!pdg
  3. From: pdg@cs.uow.edu.au (Peter Gray)
  4. Subject: fast restores
  5. Message-ID: <1992Nov23.043712.2792@cs.uow.edu.au>
  6. Summary: turning on delayed I/O
  7. Keywords: restore, speedup
  8. Organization: Dept of Computer Science, Wollongong University, Australia
  9. Date: Mon, 23 Nov 1992 04:37:12 GMT
  10. Lines: 117
  11.  
  12.  
  13. Below is a program I wrote to turn on delayed
  14. I/O while doing restores. It improves the speed
  15. of restores by about 500% on my machines.
  16.  
  17. I also use it for /tmp rather than running tmpfs.
  18.  
  19. Let me know if you find any bugs.
  20. I have only tried this on SUN's running 4.1.2.
  21. It will work under Solaris 2 I think but
  22. the name of the ioctl has changed slightly.
  23.  
  24. Does anybody know of any reason why you should
  25. not do this???
  26.  
  27.  
  28. pdg
  29.  
  30. Peter Gray                    Internet: pdg@cs.uow.EDU.AU
  31. Professional Officer          UUCP:     ...!munnari!cs.uow.EDU.AU!pdg  
  32. Dept of Computer Science      MHSnet:   pdg@cs.uow.oz.au
  33. University of Wollongong      Phone: +61 42 213770                       
  34. N.S.W.  2500  Australia       Fax :  +61 42 213262                       
  35.  
  36.  
  37.  
  38. /* 
  39.  * This programs turns on/off delayed I/O on a filesystem.
  40.  * 
  41.  * Usage:    fastfs filesystem fast|slow|status
  42.  *
  43.  * Note that it is intended for use with restore(8)
  44.  * to speed up full filesystem restores. Remember
  45.  * that if a filesystem is running with delayed I/O
  46.  * enabled when the system crashes it can result in
  47.  * fsck being unable to "fix" the filesystem on reboot
  48.  * without manual intervention.
  49.  *
  50.  * Typical use is
  51.  *
  52.  * fastfs /home    fast
  53.  * cd /home; restore rf /dev/rst5
  54.  * fastfs /home slow
  55.  *
  56.  * The above gives about a 500% increase in the speed of
  57.  * the restore (your milage may vary).
  58.  *
  59.  * Its also good for /tmp giving most of the benifits of tmpfs
  60.  * without the problems.
  61.  *
  62.  * In rc.local
  63.  *
  64.  * fastfs /tmp fast
  65.  *
  66.  * but you may need to add fsck -y /tmp into /etc/rc.boot
  67.  * before the real fsck to ensure the machine always boots
  68.  * (I have not done this yet).
  69. */
  70.  
  71. #include <stdio.h> 
  72. #include <sys/ioctl.h>
  73. #include <fcntl.h>
  74. #include <errno.h>
  75.  
  76. extern char    *sys_errlist[];
  77.  
  78.  
  79. int
  80. main(argc, argv)
  81. int    argc;
  82. char    **argv;
  83. {
  84.     int    fd;
  85.     int    flag;
  86.     
  87.     if (geteuid() != 0)
  88.     {
  89.         fprintf(stderr,"%s: Must run as root.\n", argv[0]);
  90.         exit(1);
  91.     }
  92.  
  93.     if (argc != 3)
  94.     {
  95.         fprintf(stderr,"Usage: %s path {fast|slow|status}\n",argv[0]);
  96.         exit(2);
  97.     }
  98.     
  99.     if ((fd = open(argv[1], O_RDONLY)) < 0)
  100.     {
  101.         fprintf(stderr,"%s: Unable to open \"%s\"\n%s\n", argv[0], argv[1], sys_errlist[errno]);
  102.         exit(3);
  103.     }
  104.     
  105.     if (!strcasecmp(argv[2], "status"))
  106.     {
  107.         if (ioctl(fd, FIODIOS, &flag) != 0)
  108.         {
  109.             fprintf(stderr,"%s: ioctl failed%s\n", argv[0], sys_errlist[errno]);
  110.             exit(4);
  111.         }
  112.         if (flag == 0) printf("%s is slow.\n", argv[1]);
  113.         else printf("%s is fast\n", argv[1]);
  114.         exit(0);
  115.     }
  116.     
  117.     flag = (strcasecmp(argv[2], "fast") == 0) ? 1 : 0;
  118.     
  119.     if (ioctl(fd, FIODIO, &flag) != 0)
  120.     {
  121.         fprintf(stderr,"%s: ioctl failed\n%s\n", argv[0], sys_errlist[errno]);
  122.         exit(5);
  123.     }
  124.     
  125.     printf("%s is now %s\n",argv[1], flag ? "fast" : "slow");
  126.     exit(0);
  127.  
  128. }
  129.