Subject: Portalfs corner case
To: None <current-users@netbsd.org>
From: Rhialto <rhialto@azenomei.knuffel.net>
List: current-users
Date: 06/07/2004 16:30:36
I am trying to get dump(8) to dump to a portal-fs file. The idea is to
dump to a dvd-writing program, so I can do multi-volume dvd dumps.

From /etc/portal.conf:

dvdw            wfilter dvdw    /usr/local/sbin/dvdw %s

There is however a difficulty.

After the real dump is complete, the tape is re-opened, presumably to
see that the tape drive is really done. This is done requesting READ nor
WRITE access:

src/sbin/dump/tape.c:407

        (void) close(tapefd);
        while ((f = open(tape, 0)) < 0) {
                msg("sleeping after open failure of %s\n", tape);
                sleep (10);
        }
        if (eflag && eject) {
                struct mtop offl;

                msg("Ejecting %s\n", tape);
                offl.mt_op = MTOFFL;
                offl.mt_count = 0;
                (void) ioctl(f, MTIOCTOP, &offl);
        }
        (void) close(f);
}


This however seems to run afoul of the following check in the portal
file system:

portal_vnops.c:

        /*
         * Check that the mode the file is being opened for is a subset 
         * of the mode of the existing descriptor.
         */
        fp = p->p_fd->fd_ofiles[fd];
        if (((ap->a_mode & (FREAD|FWRITE)) | fp->f_flag) != fp->f_flag) {
                portal_closefd(curlwp, fd); /* XXXNJWLWP */
                error = EACCES;
                goto bad;
        }


ap->a_mode, the requested access mode, == FREAD - apparently something has
translated this in the mean time.

fp->f_flag, the mode for the created file by the portal deamon, == FWRITE,
as would be expected for a wfilter.

The condition is therefore triggered, the file is not opened (although
the portal script dvdw is run!), and dump keeps trying again every 10
seconds without ever succeeding.

The result, however, is that It Won't Work(tm).

The problem is that a wfilter should never be matched when a file is
opened just for reading. I'll look into some patches to fix this.

-Olaf.
-- 
___ Olaf 'Rhialto' Seibert
\X/ rhialto/at/xs4all.nl        -- Cetero censeo "authored" delendum esse.