SUMMARY: "fastfs" for Solaris 2.[34]

From: Ted Nolan SRI Ft Gordon (ted@ags.ga.erg.sri.com)
Date: Thu Feb 02 1995 - 07:40:21 CST


Thanks folks!

Once again, the list comes through!

You may remember that I sent the message yesterday:

------------
Hello folks,

There's a program called "fastfs" which turns on restore mode for
a filesystem so that writes work much faster than normal (though less
safely).

I have a binary version that works for SunOS 4.1.3+. I'm almost positive
that someone posted the source code for this, with patches to add support
for Solaris also. I'm also almost positive that I saved it, but it seems
not..

Could anybody send me a copy of the source version with the Solaris support?
I remember it as being pretty short, if I get it, I'll post it as the summary.

                                Thanks!

                                Ted Nolan

----------

Well, I got the answer(s) almost immediately. The first to come
through was Casper Dik (casper@fwi.uva.nl -- Mr. Solaris!), and I'll
put his response at the first at the bottom. Rick Pluta
(pluta@eda.mke.ab.co) also sent Solarisized code, with a Makefile and
slightly more verbose messages, I'll put that second. (One day, I have
to figure out attachments...)

Thanks also to : frode@read-well.no (Frode Stromsvag)
                 mikem@centerline.com (Mike Maciolek)

                                Ted Nolan

-------------------------CUT HERE FOR SOLUTION 1-----------------------------
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of shell archive."
# Contents: fastfs.c
# Wrapped by casper@mail on Wed Feb 1 09:59:17 1995
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'fastfs.c' -a "${1}" != "-c" ; then
  echo shar: Will not clobber existing file \"'fastfs.c'\"
else
echo shar: Extracting \"'fastfs.c'\" \(4628 characters\)
sed "s/^X//" >'fastfs.c' <<'END_OF_FILE'
X/*
X * This programs turns on/off delayed I/O on a filesystem.
X *
X * Usage: fastfs filesystem fast|slow|status
X *
X * Note that it is intended for use with restore(8)
X * to speed up full filesystem restores. Remember
X * that if a filesystem is running with delayed I/O
X * enabled when the system crashes it can result in
X * fsck being unable to "fix" the filesystem on reboot
X * without manual intervention.
X *
X * Typical use is
X *
X * fastfs /home fast
X * cd /home; restore rf /dev/rst5
X * fastfs /home slow
X *
X * The above gives about a 500% increase in the speed of
X * the restore (your milage may vary).
X *
X * Its also good for /tmp giving most of the benifits of tmpfs
X * without the problems.
X *
X * In rc.local
X *
X * fastfs /tmp fast
X *
X * but you may need to add fsck -y /tmp into /etc/rc.boot
X * before the real fsck to ensure the machine always boots
X *
X * Changed usage considerably.
X *
X * Casper Dik
X*/
X
X#include <stdio.h>
X#include <string.h>
X#include <sys/ioctl.h>
X#include <sys/filio.h>
X#include <fcntl.h>
X#include <errno.h>
X#ifndef FIODIO
X#define SOLARIS
X#define FIODIO _FIOSDIO
X#define FIODIOS _FIOGDIO
X#include <sys/mnttab.h>
X#define MTAB "/etc/mnttab"
X#else
X#include <mntent.h>
X#define MTAB "/etc/mtab"
X#endif
X
X#ifndef SOLARIS
Xextern char *sys_errlist[];
Xextern int sys_nerr;
X#define strerror(x) ((x > sys_nerr || x < 0) ? "Uknown error" : sys_errlist[x])
X#endif
X
Xint errors;
X
Xchar *cmds[] = { "slow", "fast", "status" };
X
X#define CMD_SLOW 0
X#define CMD_FAST 1
X#define CMD_STATUS 2
X#define CMD_ERROR -1
X#define CMD_AMBIGUOUS -2
X
Xint
Xstr2cmd(str)
Xchar *str;
X{
X int i,len = strlen(str), hits = 0, res = CMD_ERROR;
X for (i = 0; i < sizeof(cmds)/sizeof(char*); i++) {
X if (strncmp(str, cmds[i], len) == 0) {
X res = i;
X hits++;
X }
X }
X if (hits <= 1)
X return res;
X else
X return CMD_AMBIGUOUS;
X}
X
Xvoid
Xfastfs(path, cmd)
Xchar *path;
Xint cmd;
X{
X int fd = open(path, O_RDONLY);
X int flag, newflag, oldflag, nochange = 0;
X char *how;
X
X if (fd < 0) {
X perror(path);
X errors ++;
X return;
X }
X if (ioctl(fd, FIODIOS, &oldflag) == -1) {
X perror("status ioctl");
X errors ++;
X return;
X }
X switch (cmd) {
X case CMD_SLOW:
X flag = 0;
X if (oldflag == flag)
X nochange = 1;
X else
X if (ioctl(fd, FIODIO, &flag) == -1) {
X perror("slow ioctl");
X errors ++;
X return;
X }
X break;
X case CMD_FAST:
X flag = 1;
X if (oldflag == flag)
X nochange = 1;
X else
X if (ioctl(fd, FIODIO, &flag) == -1) {
X perror("fast ioctl");
X errors ++;
X return;
X }
X break;
X case CMD_STATUS:
X how = "";
X break;
X default:
X fprintf(stderr,"Internal error: unexpected command\n");
X exit(1);
X /*NOTREACHED*/
X }
X if (ioctl(fd, FIODIOS, &newflag) == -1) {
X perror("status ioctl");
X errors ++;
X } else {
X if (cmd != CMD_STATUS && flag != newflag)
X printf("FAILED: ");
X if (cmd != CMD_STATUS)
X how = nochange ? "already " : "now ";
X printf("%s\tis %s%s\n", path, how, cmds[newflag]);
X }
X close(fd);
X}
X
Xvoid usage()
X{
X fprintf(stderr,"Usage: fastfs -a [slow|status|fast]\n");
X fprintf(stderr,"Usage: fastfs path1 .. pathN [slow|status|fast]\n");
X exit(1);
X}
X
Xint
Xmain(argc, argv)
Xint argc;
Xchar **argv;
X{
X int opstat = 0;
X int i;
X char *cmd;
X int icmd;
X
X#if 0 /* Allow status reporting for normal users */
X if (geteuid() != 0)
X {
X fprintf(stderr,"%s: Must run as root.\n", argv[0]);
X exit(1);
X }
X#endif
X
X /*
X * New usage:
X * fastfs -a [ report status on all ufs filesystems ]
X * fastfs -a status|slow|fast
X * fastfs path1 ... pathN status|slow|fast
X */
X
X if (argc < 2) usage();
X
X if (argc > 2) {
X if (str2cmd(argv[argc-1]) == CMD_ERROR)
X opstat = 1;
X } else
X opstat = 1;
X
X if (opstat)
X cmd = "status";
X else
X cmd = argv[argc-1];
X
X if ((icmd = str2cmd(cmd)) < 0)
X usage();
X
X if (strcmp(argv[1],"-a") == 0) {
X FILE *fp = fopen(MTAB,"r");
X#ifdef SOLARIS
X struct mnttab mp, mtemplate;
X#else
X struct mntent *mnt;
X#endif
X
X if (fp == NULL) {
X fprintf(stderr,"Can't open %s\n", MTAB);
X exit(1);
X }
X if (argc + opstat != 3)
X usage();
X#ifdef SOLARIS
X mtemplate.mnt_fstype = "ufs";
X mtemplate.mnt_special = 0;
X mtemplate.mnt_mntopts = 0;
X mtemplate.mnt_mountp = 0;
X mtemplate.mnt_time = 0;
X while (getmntany(fp, &mp, &mtemplate) == 0)
X fastfs(mp.mnt_mountp, icmd);
X#else
X while (mnt = getmntent(fp)) {
X if (strcmp(mnt->mnt_type,"4.2") != 0)
X continue;
X fastfs(mnt->mnt_dir, icmd);
X }
X#endif
X fclose(fp);
X } else {
X for (i = 1; i < argc + opstat - 1; i++)
X fastfs(argv[i], icmd);
X }
X
X exit(errors ? 1 : 0);
X}
END_OF_FILE
if test 4628 -ne `wc -c <'fastfs.c'`; then
    echo shar: \"'fastfs.c'\" unpacked with wrong size!
fi
# end of 'fastfs.c'
fi
echo shar: End of shell archive.
exit 0
-------------------------END SOLUTION 1--------------------------------------

-------------------------CUT HERE FOR SOLUTION 2-----------------------------
Ted,

I am attaching the version of fastfs source code we use to generate binaries
for SunOS 4.X and SunOS 5.X.

The original code was written by Peter Gray, University of Wollongong
pdg@cs.uow.edu.au.

Hope this helps

Rick Pluta
Systems Analyst, CAE/CAD Services Voice: (414)382-3799
Allen-Bradley Co. Fax: (414)382-4444
Milwaukee, Wi. USA Email: pluta@eda.mke.ab.com

----------
X-Sun-Data-Type: c-file
X-Sun-Data-Name: main.c
X-Sun-Charset: us-ascii
X-Sun-Content-Lines: 143

/*****************************************************************************

Syntax:
fastfs filesystem {status|fast|slow}

Purpose:
Turns on/off or reports on delayed io mode for a specified filesystem.

Input:

Output:

Return values:
exit status- 0 - sucess
                                        1 - failure

Libraries:

Method:

Error indications:

Restrictions/Notes:
1. Most of this program came from Peter Gray, University of Wollongong.
        The following is the documentation from Peter Gray's source:
                * Written by Peter Gray, University of Wollongong
                * pdg@cs.uow.edu.au
                *
                * This programs turns on/off delayed I/O on a filesystem.
                *
                * Usage: fastfs filesystem fast|slow|status
                *
                * Note that it is intended for use with restore(8)
                * to speed up full filesystem restores. Remember
                * that if a filesystem is running with delayed I/O
                * enabled when the system crashes it can result in
                * the fsck being unable to "fix" the filesystem on reboot
                * without manual intervention.
                *
                * Typical use is
                *
                * fastfs /home fast
                * cd /home; restore rf /dev/rst5
                * fastfs /home slow
                *
                * The above gives about a 500% increase in the speed of
                * the restore.
                *
                * Its also good for /tmp giving most of the benefits of tmpfs
                * without the problems.
                *
                * In rc.local
                *
                * fastfs /tmp fast
                *
                * but you may need to add fsck -y /tmp into /etc/rc.boot
                * before the real fsck to ensure the machine always boots
                * (I have not done this yet).

        I have found that the actual increase in the speed of restore under
        SunOS 4.1.3 and 5.3 is 200% and that is for a filesystem with many
        small files. For a filesystem with fewer but larger files, the speed
        increase is even smaller. - RSP

*******************************************************************************
29-jun-94 rsp; Created with support for svr4
******************************************************************************/

#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/filio.h>

#ifdef SVR4
#define GETDIO _FIOGDIO
#define SETDIO _FIOSDIO
#else
#define GETDIO FIODIOS
#define SETDIO FIODIO
#endif

main(argc, argv)

int argc;
char *argv[];

{

        char *command;
        int fd;
        int dioflag;

        command = argv[0];

        if (geteuid()) {
                fprintf(stderr, "you must be root to run this command");
                exit(1);
        }

        if (argc != 3) {
                fprintf(stderr, "Usage: %s filesys {fast|slow|status}\n", command);
                exit(1);
        }

        if ((fd = open(argv[1], O_RDONLY, 0)) < 0) {
                perror("failed to open device");
                exit(1);
        }

        if (strcasecmp(argv[2], "status") == 0) {
                if (ioctl(fd, GETDIO, &dioflag)) {
                        perror("error in ioctl(GETDIO) call");
                        exit(1);
                }
                if (dioflag) {
                        printf("%s has delayed io turned on (fast mode)\n", argv[1]);
                } else {
                        printf("%s has delayed io turned off (slow/normal mode)\n", argv[1]);
                }
        } else if (!strcasecmp(argv[2], "fast")) {
                dioflag = 1;
                if (ioctl(fd, SETDIO, &dioflag)) {
                        perror("error in ioctl(SETDIO) call");
                        exit(1);
                }
                printf("turned on delayed io (fast mode) for %s\n", argv[1]);
        } else if (!strcasecmp(argv[2], "slow")) {
                        dioflag = 0;
                if (ioctl(fd, SETDIO, &dioflag)) {
                        perror("error in ioctl(SETDIO) call");
                        exit(1);
                }
                printf("turned off delayed io (slow/normal mode) for %s\n", argv[1]);
        } else {
                fprintf(stderr, "Usage: %s filesys {fast|slow|status}\n", command);
                exit(1);
        }

        exit(0);

}
----------
X-Sun-Data-Type: Makefile
X-Sun-Data-Name: Makefile_4.X
X-Sun-Charset: us-ascii
X-Sun-Content-Lines: 5

fastfs_4.X: main_4.X.o
        cc -g -o fastfs_4.X main_4.X.o
 
main_4.X.o: main.c
        cc -c -g -o main_4.X.o main.c
----------
X-Sun-Data-Type: Makefile
X-Sun-Data-Name: Makefile_svr4
X-Sun-Charset: us-ascii
X-Sun-Content-Lines: 5

fastfs_svr4: main_svr4.o
        cc -g -o fastfs_svr4 main_svr4.o

main_svr4.o: main.c
        cc -c -g -DSVR4 -o main_svr4.o main.c
-----------------------------END SOLUTION 2-----------------------------------



This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:10:15 CDT