Module Name: src Committed By: pooka Date: Fri Jul 30 16:15:06 UTC 2010
Modified Files: src/tests/fs/common: fstest_ext2fs.c fstest_ffs.c fstest_lfs.c fstest_msdosfs.c fstest_nfs.c fstest_puffs.c fstest_sysvbfs.c fstest_tmpfs.c h_fsmacros.h src/tests/fs/ffs: t_mount.c src/tests/fs/nfs/nfsservice: rumpnfsd.c src/tests/fs/puffs: Makefile t_basic.c Log Message: Fold the puffs private and vfs tests mount/unmount routines together. To achieve this, add a file system private parameter to the newfs method (which will obviously not be used by vfs tests). njoly ok To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/fs/common/fstest_ext2fs.c \ src/tests/fs/common/fstest_ffs.c src/tests/fs/common/fstest_msdosfs.c \ src/tests/fs/common/fstest_puffs.c src/tests/fs/common/fstest_sysvbfs.c \ src/tests/fs/common/fstest_tmpfs.c cvs rdiff -u -r1.3 -r1.4 src/tests/fs/common/fstest_lfs.c cvs rdiff -u -r1.2 -r1.3 src/tests/fs/common/fstest_nfs.c cvs rdiff -u -r1.16 -r1.17 src/tests/fs/common/h_fsmacros.h cvs rdiff -u -r1.6 -r1.7 src/tests/fs/ffs/t_mount.c cvs rdiff -u -r1.1 -r1.2 src/tests/fs/nfs/nfsservice/rumpnfsd.c cvs rdiff -u -r1.9 -r1.10 src/tests/fs/puffs/Makefile cvs rdiff -u -r1.6 -r1.7 src/tests/fs/puffs/t_basic.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/fs/common/fstest_ext2fs.c diff -u src/tests/fs/common/fstest_ext2fs.c:1.1 src/tests/fs/common/fstest_ext2fs.c:1.2 --- src/tests/fs/common/fstest_ext2fs.c:1.1 Thu Jul 29 14:15:46 2010 +++ src/tests/fs/common/fstest_ext2fs.c Fri Jul 30 16:15:05 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: fstest_ext2fs.c,v 1.1 2010/07/29 14:15:46 pooka Exp $ */ +/* $NetBSD: fstest_ext2fs.c,v 1.2 2010/07/30 16:15:05 pooka Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -53,7 +53,7 @@ int ext2fs_fstest_newfs(const atf_tc_t *tc, void **buf, const char *image, - off_t size) + off_t size, void *fspriv) { char cmd[1024]; int res; Index: src/tests/fs/common/fstest_ffs.c diff -u src/tests/fs/common/fstest_ffs.c:1.1 src/tests/fs/common/fstest_ffs.c:1.2 --- src/tests/fs/common/fstest_ffs.c:1.1 Thu Jul 29 14:15:46 2010 +++ src/tests/fs/common/fstest_ffs.c Fri Jul 30 16:15:05 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: fstest_ffs.c,v 1.1 2010/07/29 14:15:46 pooka Exp $ */ +/* $NetBSD: fstest_ffs.c,v 1.2 2010/07/30 16:15:05 pooka Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -52,7 +52,8 @@ }; int -ffs_fstest_newfs(const atf_tc_t *tc, void **buf, const char *image, off_t size) +ffs_fstest_newfs(const atf_tc_t *tc, void **buf, const char *image, off_t size, + void *fspriv) { char cmd[1024]; int res; Index: src/tests/fs/common/fstest_msdosfs.c diff -u src/tests/fs/common/fstest_msdosfs.c:1.1 src/tests/fs/common/fstest_msdosfs.c:1.2 --- src/tests/fs/common/fstest_msdosfs.c:1.1 Thu Jul 29 14:15:46 2010 +++ src/tests/fs/common/fstest_msdosfs.c Fri Jul 30 16:15:05 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: fstest_msdosfs.c,v 1.1 2010/07/29 14:15:46 pooka Exp $ */ +/* $NetBSD: fstest_msdosfs.c,v 1.2 2010/07/30 16:15:05 pooka Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -53,7 +53,7 @@ int msdosfs_fstest_newfs(const atf_tc_t *tc, void **buf, const char *image, - off_t size) + off_t size, void *fspriv) { char cmd[1024]; int res; Index: src/tests/fs/common/fstest_puffs.c diff -u src/tests/fs/common/fstest_puffs.c:1.1 src/tests/fs/common/fstest_puffs.c:1.2 --- src/tests/fs/common/fstest_puffs.c:1.1 Thu Jul 29 14:15:47 2010 +++ src/tests/fs/common/fstest_puffs.c Fri Jul 30 16:15:05 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: fstest_puffs.c,v 1.1 2010/07/29 14:15:47 pooka Exp $ */ +/* $NetBSD: fstest_puffs.c,v 1.2 2010/07/30 16:15:05 pooka Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -50,51 +50,9 @@ #include "h_fsmacros.h" -struct puffstestargs { - uint8_t *pta_pargs; - size_t pta_pargslen; - - int pta_pflags; - int pta_servfd; - pid_t pta_childpid; - - char pta_dev[MAXPATHLEN]; - char pta_dir[MAXPATHLEN]; - - int pta_mntflags; -}; - #define BUFSIZE (128*1024) #define DTFS_DUMP "-o","dump" -struct thefds { - int rumpfd; - int servfd; -}; - -int vfs_toserv_ops[PUFFS_VFS_MAX]; -int vn_toserv_ops[PUFFS_VN_MAX]; - -#ifdef PUFFSDUMP -static void __unused -dumpopcount(void) -{ - size_t i; - - printf("VFS OPS:\n"); - for (i = 0; i < MIN(puffsdump_vfsop_count, PUFFS_VFS_MAX); i++) { - printf("\t%s: %d\n", - puffsdump_vfsop_revmap[i], vfs_toserv_ops[i]); - } - - printf("VN OPS:\n"); - for (i = 0; i < MIN(puffsdump_vnop_count, PUFFS_VN_MAX); i++) { - printf("\t%s: %d\n", - puffsdump_vnop_revmap[i], vn_toserv_ops[i]); - } -} -#endif - /* * Threads which shovel data between comfd and /dev/puffs. * (cannot use polling since fd's are in different namespaces) @@ -104,12 +62,12 @@ { struct putter_hdr *phdr; struct puffs_req *preq; - struct thefds *fds = arg; + struct puffstestargs *args = arg; char buf[BUFSIZE]; int comfd, puffsfd; - comfd = fds->servfd; - puffsfd = fds->rumpfd; + comfd = args->pta_servfd; + puffsfd = args->pta_rumpfd; phdr = (void *)buf; preq = (void *)buf; @@ -133,10 +91,10 @@ /* Analyze request */ if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_VFS) { assert(preq->preq_optype < PUFFS_VFS_MAX); - vfs_toserv_ops[preq->preq_optype]++; + args->pta_vfs_toserv_ops[preq->preq_optype]++; } else if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_VN) { assert(preq->preq_optype < PUFFS_VN_MAX); - vn_toserv_ops[preq->preq_optype]++; + args->pta_vn_toserv_ops[preq->preq_optype]++; } n = phdr->pth_framelen; @@ -150,7 +108,7 @@ static void * writeshovel(void *arg) { - struct thefds *fds = arg; + struct puffstestargs *args = arg; struct putter_hdr *phdr; char buf[BUFSIZE]; size_t toread; @@ -159,8 +117,8 @@ /* use static thread id */ rump_pub_lwp_alloc_and_switch(0, 11); - comfd = fds->servfd; - puffsfd = fds->rumpfd; + comfd = args->pta_servfd; + puffsfd = args->pta_rumpfd; phdr = (struct putter_hdr *)buf; @@ -196,22 +154,19 @@ } static void -rumpshovels(int rumpfd, int servfd) +rumpshovels(struct puffstestargs *args) { - struct thefds *fds; pthread_t pt; int rv; if ((rv = rump_init()) == -1) err(1, "rump_init"); - fds = malloc(sizeof(*fds)); - fds->rumpfd = rumpfd; - fds->servfd = servfd; - if (pthread_create(&pt, NULL, readshovel, fds) == -1) + if (pthread_create(&pt, NULL, readshovel, args) == -1) err(1, "read shovel"); pthread_detach(pt); - if (pthread_create(&pt, NULL, writeshovel, fds) == -1) + + if (pthread_create(&pt, NULL, writeshovel, args) == -1) err(1, "write shovel"); pthread_detach(pt); } @@ -223,14 +178,17 @@ atf_tc_fail("child died"); /* almost signal-safe */ } +struct puffstestargs *theargs; /* XXX */ + /* XXX: we don't support size */ int puffs_fstest_newfs(const atf_tc_t *tc, void **argp, - const char *image, off_t size) + const char *image, off_t size, void *fspriv) { struct puffstestargs *args; char dtfs_path[MAXPATHLEN]; char *dtfsargv[6]; + char **theargv; pid_t childpid; int *pflags; char comfd[16]; @@ -250,12 +208,20 @@ /* build dtfs exec path from atf test dir */ sprintf(dtfs_path, "%s/../puffs/h_dtfs/h_dtfs", atf_tc_get_config_var(tc, "srcdir")); - dtfsargv[0] = dtfs_path; - dtfsargv[1] = __UNCONST("-i"); - dtfsargv[2] = __UNCONST("-s"); - dtfsargv[3] = __UNCONST("dtfs"); - dtfsargv[4] = __UNCONST("fictional"); - dtfsargv[5] = NULL; + + if (fspriv) { + theargv = fspriv; + theargv[0] = dtfs_path; + } else { + dtfsargv[0] = dtfs_path; + dtfsargv[1] = __UNCONST("-i"); + dtfsargv[2] = __UNCONST("-s"); + dtfsargv[3] = __UNCONST("dtfs"); + dtfsargv[4] = __UNCONST("fictional"); + dtfsargv[5] = NULL; + + theargv = dtfsargv; + } /* Create sucketpair for communication with the real file server */ if (socketpair(PF_LOCAL, SOCK_STREAM, 0, sv) == -1) @@ -270,7 +236,7 @@ if (setenv("PUFFS_COMFD", comfd, 1) == -1) return errno; - if (execvp(dtfsargv[0], dtfsargv) == -1) + if (execvp(theargv[0], theargv) == -1) return errno; case -1: return errno; @@ -294,12 +260,14 @@ err(1, "fn 2"); if (read(sv[1], &mntflags, sizeof(mntflags)) != sizeof(mntflags)) err(1, "mntflags"); - if (read(sv[1], &args->pta_pargslen, sizeof(args->pta_pargslen)) != sizeof(args->pta_pargslen)) + if (read(sv[1], &args->pta_pargslen, sizeof(args->pta_pargslen)) + != sizeof(args->pta_pargslen)) err(1, "puffstest_args len"); args->pta_pargs = malloc(args->pta_pargslen); if (args->pta_pargs == NULL) err(1, "malloc"); - if (read(sv[1], args->pta_pargs, args->pta_pargslen) != (ssize_t)args->pta_pargslen) + if (read(sv[1], args->pta_pargs, args->pta_pargslen) + != (ssize_t)args->pta_pargslen) err(1, "puffstest_args"); if (read(sv[1], pflags, sizeof(*pflags)) != sizeof(*pflags)) err(1, "pflags"); @@ -308,7 +276,7 @@ args->pta_servfd = sv[1]; strlcpy(args->pta_dev, image, sizeof(args->pta_dev)); - *argp = args; + *argp = theargs = args; return 0; } @@ -340,7 +308,8 @@ return -1; } - rumpshovels(fd, pargs->pta_servfd); + pargs->pta_rumpfd = fd; + rumpshovels(pargs); return 0; } @@ -348,25 +317,16 @@ int puffs_fstest_delfs(const atf_tc_t *tc, void *arg) { - struct puffstestargs *pargs = arg; - int status; - if (waitpid(pargs->pta_childpid, &status, WNOHANG) > 0) - return 0; - kill(pargs->pta_childpid, SIGTERM); - usleep(10); - if (waitpid(pargs->pta_childpid, &status, WNOHANG) > 0) - return 0; - kill(pargs->pta_childpid, SIGKILL); - usleep(500); - if (waitpid(pargs->pta_childpid, &status, 0) == -1) - return errno; + /* useless ... */ return 0; } int puffs_fstest_unmount(const atf_tc_t *tc, const char *path, int flags) { + struct puffstestargs *pargs = theargs; + int status; int rv; /* ok, child might exit here */ @@ -376,5 +336,18 @@ if (rv) return rv; - return rump_sys_rmdir(path); + if ((rv = rump_sys_rmdir(path)) != 0) + return rv; + + if (waitpid(pargs->pta_childpid, &status, WNOHANG) > 0) + return 0; + kill(pargs->pta_childpid, SIGTERM); + usleep(10); + if (waitpid(pargs->pta_childpid, &status, WNOHANG) > 0) + return 0; + kill(pargs->pta_childpid, SIGKILL); + usleep(500); + wait(&status); + + return 0; } Index: src/tests/fs/common/fstest_sysvbfs.c diff -u src/tests/fs/common/fstest_sysvbfs.c:1.1 src/tests/fs/common/fstest_sysvbfs.c:1.2 --- src/tests/fs/common/fstest_sysvbfs.c:1.1 Thu Jul 29 14:15:47 2010 +++ src/tests/fs/common/fstest_sysvbfs.c Fri Jul 30 16:15:05 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: fstest_sysvbfs.c,v 1.1 2010/07/29 14:15:47 pooka Exp $ */ +/* $NetBSD: fstest_sysvbfs.c,v 1.2 2010/07/30 16:15:05 pooka Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -53,7 +53,7 @@ int sysvbfs_fstest_newfs(const atf_tc_t *tc, void **buf, const char *image, - off_t size) + off_t size, void *fspriv) { char cmd[1024]; int res; Index: src/tests/fs/common/fstest_tmpfs.c diff -u src/tests/fs/common/fstest_tmpfs.c:1.1 src/tests/fs/common/fstest_tmpfs.c:1.2 --- src/tests/fs/common/fstest_tmpfs.c:1.1 Thu Jul 29 14:15:47 2010 +++ src/tests/fs/common/fstest_tmpfs.c Fri Jul 30 16:15:05 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: fstest_tmpfs.c,v 1.1 2010/07/29 14:15:47 pooka Exp $ */ +/* $NetBSD: fstest_tmpfs.c,v 1.2 2010/07/30 16:15:05 pooka Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -51,7 +51,7 @@ int tmpfs_fstest_newfs(const atf_tc_t *tc, void **buf, const char *image, - off_t size) + off_t size, void *fspriv) { int res; struct tmpfstestargs *args; Index: src/tests/fs/common/fstest_lfs.c diff -u src/tests/fs/common/fstest_lfs.c:1.3 src/tests/fs/common/fstest_lfs.c:1.4 --- src/tests/fs/common/fstest_lfs.c:1.3 Thu Jul 29 14:50:32 2010 +++ src/tests/fs/common/fstest_lfs.c Fri Jul 30 16:15:05 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: fstest_lfs.c,v 1.3 2010/07/29 14:50:32 pooka Exp $ */ +/* $NetBSD: fstest_lfs.c,v 1.4 2010/07/30 16:15:05 pooka Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -61,7 +61,8 @@ }; int -lfs_fstest_newfs(const atf_tc_t *tc, void **buf, const char *image, off_t size) +lfs_fstest_newfs(const atf_tc_t *tc, void **buf, const char *image, off_t size, + void *fspriv) { char cmd[1024]; int res; Index: src/tests/fs/common/fstest_nfs.c diff -u src/tests/fs/common/fstest_nfs.c:1.2 src/tests/fs/common/fstest_nfs.c:1.3 --- src/tests/fs/common/fstest_nfs.c:1.2 Fri Jul 30 10:23:26 2010 +++ src/tests/fs/common/fstest_nfs.c Fri Jul 30 16:15:05 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: fstest_nfs.c,v 1.2 2010/07/30 10:23:26 pooka Exp $ */ +/* $NetBSD: fstest_nfs.c,v 1.3 2010/07/30 16:15:05 pooka Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -69,7 +69,7 @@ /* fork rump nfsd, configure interface */ int nfs_fstest_newfs(const atf_tc_t *tc, void **argp, - const char *image, off_t size) + const char *image, off_t size, void *fspriv) { const char *srcdir; char *nfsdargv[7]; Index: src/tests/fs/common/h_fsmacros.h diff -u src/tests/fs/common/h_fsmacros.h:1.16 src/tests/fs/common/h_fsmacros.h:1.17 --- src/tests/fs/common/h_fsmacros.h:1.16 Wed Jul 28 15:16:50 2010 +++ src/tests/fs/common/h_fsmacros.h Fri Jul 30 16:15:05 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: h_fsmacros.h,v 1.16 2010/07/28 15:16:50 pooka Exp $ */ +/* $NetBSD: h_fsmacros.h,v 1.17 2010/07/30 16:15:05 pooka Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -35,10 +35,12 @@ #include <sys/mount.h> #include <atf-c.h> +#include <puffsdump.h> #include <string.h> #define FSPROTOS(_fs_) \ -int _fs_##_fstest_newfs(const atf_tc_t *, void **, const char *, off_t);\ +int _fs_##_fstest_newfs(const atf_tc_t *, void **, const char *, \ + off_t, void *); \ int _fs_##_fstest_delfs(const atf_tc_t *, void *); \ int _fs_##_fstest_mount(const atf_tc_t *, void *, const char *, int); \ int _fs_##_fstest_unmount(const atf_tc_t *, const char *, int); @@ -59,7 +61,16 @@ #define FSTEST_CONSTRUCTOR(_tc_, _fs_, _args_) \ do { \ if (_fs_##_fstest_newfs(_tc_, &_args_, \ - FSTEST_IMGNAME, FSTEST_IMGSIZE) != 0) \ + FSTEST_IMGNAME, FSTEST_IMGSIZE, NULL) != 0) \ + atf_tc_fail("newfs failed"); \ + if (_fs_##_fstest_mount(_tc_, _args_, FSTEST_MNTNAME, 0) != 0) \ + atf_tc_fail("mount failed"); \ +} while (/*CONSTCOND*/0); + +#define FSTEST_CONSTRUCTOR_FSPRIV(_tc_, _fs_, _args_, _privargs_) \ +do { \ + if (_fs_##_fstest_newfs(_tc_, &_args_, \ + FSTEST_IMGNAME, FSTEST_IMGSIZE, _privargs_) != 0) \ atf_tc_fail("newfs failed"); \ if (_fs_##_fstest_mount(_tc_, _args_, FSTEST_MNTNAME, 0) != 0) \ atf_tc_fail("mount failed"); \ @@ -160,11 +171,39 @@ #define FSTYPE_TMPFS(tc)\ (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_TMPFS) == 0) +#define FSTEST_ENTER() \ + if (rump_sys_chdir(FSTEST_MNTNAME) == -1) \ + atf_tc_fail_errno("failed to cd into test mount") +#define FSTEST_EXIT() \ + if (rump_sys_chdir("/") == -1) \ + atf_tc_fail_errno("failed to cd out of test mount") + +/* + * file system args structures + */ -/* file system args structures */ struct nfstestargs { pid_t ta_childpid; char ta_ethername[MAXPATHLEN]; }; +struct puffstestargs { + uint8_t *pta_pargs; + size_t pta_pargslen; + + int pta_pflags; + pid_t pta_childpid; + + int pta_rumpfd; + int pta_servfd; + + char pta_dev[MAXPATHLEN]; + char pta_dir[MAXPATHLEN]; + + int pta_mntflags; + + int pta_vfs_toserv_ops[PUFFS_VFS_MAX]; + int pta_vn_toserv_ops[PUFFS_VN_MAX]; +}; + #endif /* __H_FSMACROS_H_ */ Index: src/tests/fs/ffs/t_mount.c diff -u src/tests/fs/ffs/t_mount.c:1.6 src/tests/fs/ffs/t_mount.c:1.7 --- src/tests/fs/ffs/t_mount.c:1.6 Mon Jul 19 16:22:05 2010 +++ src/tests/fs/ffs/t_mount.c Fri Jul 30 16:15:05 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: t_mount.c,v 1.6 2010/07/19 16:22:05 pooka Exp $ */ +/* $NetBSD: t_mount.c,v 1.7 2010/07/30 16:15:05 pooka Exp $ */ /* * Adapted for rump and atf from a testcase supplied @@ -25,7 +25,7 @@ { void *tmp; - if (ffs_fstest_newfs(tc, &tmp, IMGNAME, IMGSIZE) != 0) + if (ffs_fstest_newfs(tc, &tmp, IMGNAME, IMGSIZE, NULL) != 0) atf_tc_fail("newfs failed"); atf_tc_expect_fail("PR kern/43573"); Index: src/tests/fs/nfs/nfsservice/rumpnfsd.c diff -u src/tests/fs/nfs/nfsservice/rumpnfsd.c:1.1 src/tests/fs/nfs/nfsservice/rumpnfsd.c:1.2 --- src/tests/fs/nfs/nfsservice/rumpnfsd.c:1.1 Mon Jul 26 15:53:00 2010 +++ src/tests/fs/nfs/nfsservice/rumpnfsd.c Fri Jul 30 16:15:06 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: rumpnfsd.c,v 1.1 2010/07/26 15:53:00 pooka Exp $ */ +/* $NetBSD: rumpnfsd.c,v 1.2 2010/07/30 16:15:06 pooka Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -93,10 +93,7 @@ rump_sys_mkdir("/var/db", 0777); fprintf(stderr, "imagename %s\n", imagename); - if (ffs_fstest_newfs(NULL, &fsarg, imagename, 10000 * 512)) - errx(1, "newfs ffs"); - if ((rv = ffs_fstest_mount(NULL, fsarg, exportpath, 0)) != 0) - errx(1, "mount ffs %d", rv); + FSTEST_CONSTRUCTOR(NULL, ffs, fsarg); #if 0 /* Index: src/tests/fs/puffs/Makefile diff -u src/tests/fs/puffs/Makefile:1.9 src/tests/fs/puffs/Makefile:1.10 --- src/tests/fs/puffs/Makefile:1.9 Tue Jul 13 21:13:23 2010 +++ src/tests/fs/puffs/Makefile Fri Jul 30 16:15:06 2010 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.9 2010/07/13 21:13:23 jmmv Exp $ +# $NetBSD: Makefile,v 1.10 2010/07/30 16:15:06 pooka Exp $ # .include <bsd.own.mk> @@ -9,6 +9,9 @@ TESTS_C= t_basic +VFSTESTDIR != cd ${.CURDIR}/../common && ${PRINTOBJDIR} +LDADD+=-L${VFSTESTDIR} -lvfstest + LDADD+= -lrumpdev_putter -lrumpdev LDADD+= -lrumpfs_syspuffs -lrumpvfs_fifofs LDADD+= -lrumpnet_local -lrumpnet_net -lrumpnet Index: src/tests/fs/puffs/t_basic.c diff -u src/tests/fs/puffs/t_basic.c:1.6 src/tests/fs/puffs/t_basic.c:1.7 --- src/tests/fs/puffs/t_basic.c:1.6 Mon Jul 12 13:09:19 2010 +++ src/tests/fs/puffs/t_basic.c Fri Jul 30 16:15:06 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: t_basic.c,v 1.6 2010/07/12 13:09:19 pooka Exp $ */ +/* $NetBSD: t_basic.c,v 1.7 2010/07/30 16:15:06 pooka Exp $ */ #include <sys/types.h> #include <sys/mount.h> @@ -21,26 +21,7 @@ #include <rump/rump_syscalls.h> #include "../../h_macros.h" - -struct puffs_args { - uint8_t *us_pargs; - size_t us_pargslen; - - int us_pflags; - int us_servfd; - pid_t us_childpid; -}; - -#define BUFSIZE (64*1024) -#define DTFS_DUMP "-o","dump" - -struct thefds { - int rumpfd; - int servfd; -}; - -int vfs_toserv_ops[PUFFS_VFS_MAX]; -int vn_toserv_ops[PUFFS_VN_MAX]; +#include "../common/h_fsmacros.h" /* * Do a synchronous operation. When this returns, all FAF operations @@ -54,266 +35,26 @@ { struct statvfs svb; - rump_sys_statvfs1(fs, &svb, ST_WAIT); + if (rump_sys_statvfs1(fs, &svb, ST_WAIT) == -1) + atf_tc_fail_errno("statvfs"); } -#ifdef PUFFSDUMP static void __unused -dumpopcount(void) +dumpopcount(struct puffstestargs *args) { size_t i; printf("VFS OPS:\n"); for (i = 0; i < MIN(puffsdump_vfsop_count, PUFFS_VFS_MAX); i++) { printf("\t%s: %d\n", - puffsdump_vfsop_revmap[i], vfs_toserv_ops[i]); + puffsdump_vfsop_revmap[i], args->pta_vfs_toserv_ops[i]); } printf("VN OPS:\n"); for (i = 0; i < MIN(puffsdump_vnop_count, PUFFS_VN_MAX); i++) { printf("\t%s: %d\n", - puffsdump_vnop_revmap[i], vn_toserv_ops[i]); - } -} -#endif - -/* - * Threads which shovel data between comfd and /dev/puffs. - * (cannot use polling since fd's are in different namespaces) - */ -static void * -readshovel(void *arg) -{ - struct putter_hdr *phdr; - struct puffs_req *preq; - struct thefds *fds = arg; - char buf[BUFSIZE]; - int comfd, puffsfd; - - comfd = fds->servfd; - puffsfd = fds->rumpfd; - - phdr = (void *)buf; - preq = (void *)buf; - - /* use static thread id */ - rump_pub_lwp_alloc_and_switch(0, 10); - - for (;;) { - ssize_t n; - - n = rump_sys_read(puffsfd, buf, sizeof(*phdr)); - if (n <= 0) - break; - - assert(phdr->pth_framelen < BUFSIZE); - n = rump_sys_read(puffsfd, buf+sizeof(*phdr), - phdr->pth_framelen - sizeof(*phdr)); - if (n <= 0) - break; - - /* Analyze request */ - if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_VFS) { - assert(preq->preq_optype < PUFFS_VFS_MAX); - vfs_toserv_ops[preq->preq_optype]++; - } else if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_VN) { - assert(preq->preq_optype < PUFFS_VN_MAX); - vn_toserv_ops[preq->preq_optype]++; - } - - n = phdr->pth_framelen; - if (write(comfd, buf, n) != n) - break; + puffsdump_vnop_revmap[i], args->pta_vn_toserv_ops[i]); } - - return NULL; -} - -static void * -writeshovel(void *arg) -{ - struct thefds *fds = arg; - struct putter_hdr *phdr; - char buf[BUFSIZE]; - size_t toread; - int comfd, puffsfd; - - /* use static thread id */ - rump_pub_lwp_alloc_and_switch(0, 11); - - comfd = fds->servfd; - puffsfd = fds->rumpfd; - - phdr = (struct putter_hdr *)buf; - - for (;;) { - off_t off; - ssize_t n; - - /* - * Need to write everything to the "kernel" in one chunk, - * so make sure we have it here. - */ - off = 0; - toread = sizeof(struct putter_hdr); - assert(toread < BUFSIZE); - do { - n = read(comfd, buf+off, toread); - if (n <= 0) { - break; - } - off += n; - if (off >= sizeof(struct putter_hdr)) - toread = phdr->pth_framelen - off; - else - toread = off - sizeof(struct putter_hdr); - } while (toread); - - n = rump_sys_write(puffsfd, buf, phdr->pth_framelen); - if (n != phdr->pth_framelen) - break; - } - - return NULL; -} - -static void -rumpshovels(int rumpfd, int servfd) -{ - struct thefds *fds; - pthread_t pt; - int rv; - - if ((rv = rump_init()) == -1) - err(1, "rump_init"); - - fds = malloc(sizeof(*fds)); - fds->rumpfd = rumpfd; - fds->servfd = servfd; - if (pthread_create(&pt, NULL, readshovel, fds) == -1) - err(1, "read shovel"); - pthread_detach(pt); - if (pthread_create(&pt, NULL, writeshovel, fds) == -1) - err(1, "write shovel"); - pthread_detach(pt); -} - -static int -parseargs(int argc, char *argv[], - struct puffs_args *args, int *mntflags, - char *canon_dev, char *canon_dir) -{ - pid_t childpid; - int *pflags = &args->us_pflags; - char comfd[16]; - int sv[2]; - size_t len; - ssize_t n; - - /* Create sucketpair for communication with the real file server */ - if (socketpair(PF_LOCAL, SOCK_STREAM, 0, sv) == -1) - err(1, "socketpair"); - - switch ((childpid = fork())) { - case 0: - close(sv[1]); - snprintf(comfd, sizeof(sv[0]), "%d", sv[0]); - if (setenv("PUFFS_COMFD", comfd, 1) == -1) - atf_tc_fail_errno("setenv"); - - if (execvp(argv[0], argv) == -1) - atf_tc_fail_errno("execvp"); - /*NOTREACHED*/ - case -1: - atf_tc_fail_errno("fork"); - /*NOTREACHED*/ - default: - close(sv[0]); - break; - } - - /* read args */ - if ((n = read(sv[1], &len, sizeof(len))) != sizeof(len)) - err(1, "mp 1 %zd", n); - if (len > MAXPATHLEN) - err(1, "mntpath > MAXPATHLEN"); - if ((size_t)read(sv[1], canon_dir, len) != len) - err(1, "mp 2"); - if (read(sv[1], &len, sizeof(len)) != sizeof(len)) - err(1, "fn 1"); - if (len > MAXPATHLEN) - err(1, "devpath > MAXPATHLEN"); - if ((size_t)read(sv[1], canon_dev, len) != len) - err(1, "fn 2"); - if (read(sv[1], mntflags, sizeof(*mntflags)) != sizeof(*mntflags)) - err(1, "mntflags"); - if (read(sv[1], &args->us_pargslen, sizeof(args->us_pargslen)) != sizeof(args->us_pargslen)) - err(1, "puffs_args len"); - args->us_pargs = malloc(args->us_pargslen); - if (args->us_pargs == NULL) - err(1, "malloc"); - if (read(sv[1], args->us_pargs, args->us_pargslen) != args->us_pargslen) - err(1, "puffs_args"); - if (read(sv[1], pflags, sizeof(*pflags)) != sizeof(*pflags)) - err(1, "pflags"); - - args->us_childpid = childpid; - args->us_servfd = sv[1]; - - return 0; -} - -#define dtfsmountv(a, b) \ - struct puffs_args pa; \ - dtfsmount1(a, __arraycount(b), b, atf_tc_get_config_var(tc, "srcdir"), &pa) -static void -dtfsmount1(const char *mp, int optcount, char *opts[], const char *srcdir, - struct puffs_args *pa) -{ - char canon_dev[MAXPATHLEN], canon_dir[MAXPATHLEN]; - char dtfs_path[MAXPATHLEN], mountpath[MAXPATHLEN]; - char **dtfsargv; - int mntflag; - int rv, i; - int fd; - - dtfsargv = malloc(sizeof(char *) * (optcount+3)); - - /* build dtfs exec path for atf */ - sprintf(dtfs_path, "%s/h_dtfs/h_dtfs", srcdir); - dtfsargv[0] = dtfs_path; - - for (i = 0; i < optcount; i++) { - dtfsargv[i+1] = opts[i]; - } - - strlcpy(mountpath, mp, sizeof(mountpath)); - dtfsargv[optcount+1] = mountpath; - dtfsargv[optcount+2] = NULL; - - rv = parseargs(optcount+3, dtfsargv, - pa, &mntflag, canon_dev, canon_dir); - if (rv) - atf_tc_fail("comfd parseargs"); - - rump_init(); - fd = rump_sys_open("/dev/puffs", O_RDWR); - if (fd == -1) - atf_tc_fail_errno("open puffs fd"); -#if 0 - pa->pa_fd = fd; -#else - assert(fd == 0); /* XXX: FIXME */ -#endif - - if (rump_sys_mkdir(mp, 0777) == -1) - atf_tc_fail_errno("mkdir mountpoint"); - - if (rump_sys_mount(MOUNT_PUFFS, mp, 0, - pa->us_pargs, pa->us_pargslen) == -1) - atf_tc_fail_errno("mount"); - - rumpshovels(fd, pa->us_servfd); } ATF_TC(mount); @@ -325,13 +66,10 @@ ATF_TC_BODY(mount, tc) { - char *myopts[] = { - "dtfs", - }; + void *args; - dtfsmountv("/mp", myopts); - if (rump_sys_unmount("/mp", 0) == -1) - atf_tc_fail_errno("unmount"); + FSTEST_CONSTRUCTOR(tc, puffs, args); + FSTEST_DESTRUCTOR(tc, puffs, args); } ATF_TC(root_reg); @@ -340,28 +78,28 @@ atf_tc_set_md_var(tc, "descr", "root is a regular file"); } +#define MAKEOPTS(...) \ + char *theopts[] = {NULL, "-s", __VA_ARGS__, "dtfs", "n/a", NULL} + ATF_TC_BODY(root_reg, tc) { - char *myopts[] = { - "-r","reg", - "dtfs", - }; + MAKEOPTS("-r", "reg"); + void *args; int fd, rv; - dtfsmountv("/mp", myopts); + FSTEST_CONSTRUCTOR_FSPRIV(tc, puffs, args, theopts); - fd = rump_sys_open("/mp", O_RDWR); + fd = rump_sys_open(FSTEST_MNTNAME, O_RDWR); if (fd == -1) atf_tc_fail_errno("open root"); if (rump_sys_write(fd, &fd, sizeof(fd)) != sizeof(fd)) atf_tc_fail_errno("write to root"); - rv = rump_sys_mkdir("/mp/test", 0777); + rv = rump_sys_mkdir(FSTEST_MNTNAME "/test", 0777); ATF_REQUIRE(errno == ENOTDIR); ATF_REQUIRE(rv == -1); rump_sys_close(fd); - if (rump_sys_unmount("/mp", 0) == -1) - atf_tc_fail_errno("unmount"); + FSTEST_DESTRUCTOR(tc, puffs, args); } ATF_TC(root_lnk); @@ -374,17 +112,16 @@ #define LINKSTR "/path/to/nowhere" ATF_TC_BODY(root_lnk, tc) { - char *myopts[] = { - "-r", "lnk " LINKSTR, - "-s", - "dtfs", - }; + MAKEOPTS("-r", "lnk " LINKSTR); + struct puffstestargs *pargs; + void *args; char buf[PATH_MAX]; ssize_t len; - dtfsmountv("/mp", myopts); + FSTEST_CONSTRUCTOR_FSPRIV(tc, puffs, args, theopts); + pargs = args; - if ((len = rump_sys_readlink("/mp", buf, sizeof(buf)-1)) == -1) + if ((len = rump_sys_readlink(FSTEST_MNTNAME, buf, sizeof(buf)-1)) == -1) atf_tc_fail_errno("readlink"); buf[len] = '\0'; @@ -399,8 +136,9 @@ * XXX2: due to atf issue #53, we must make sure the child dies * before we exit. */ - if (kill(pa.us_childpid, SIGTERM) == -1) - err(1, "kill"); + signal(SIGCHLD, SIG_IGN); + if (kill(pargs->pta_childpid, SIGTERM) == -1) + atf_tc_fail_errno("kill"); } ATF_TC(root_fifo); @@ -427,31 +165,28 @@ ATF_TC_BODY(root_fifo, tc) { - char *myopts[] = { - "-r", "fifo", - "dtfs", - }; + MAKEOPTS("-r", "fifo"); + void *args; pthread_t pt; char buf[512]; int fd; - dtfsmountv("/mp", myopts); - fd = rump_sys_open("/mp", O_RDWR); + FSTEST_CONSTRUCTOR_FSPRIV(tc, puffs, args, theopts); + + fd = rump_sys_open(FSTEST_MNTNAME, O_RDWR); if (fd == -1) atf_tc_fail_errno("open fifo"); pthread_create(&pt, NULL, dofifow, (void *)(uintptr_t)fd); - printf("reading\n"); memset(buf, 0, sizeof(buf)); if (rump_sys_read(fd, buf, sizeof(buf)) == -1) atf_tc_fail_errno("read fifo"); ATF_REQUIRE_STREQ(buf, MAGICSTR); - rump_sys_close(fd); - if (rump_sys_unmount("/mp", 0) == -1) - atf_tc_fail_errno("unmount"); + + FSTEST_DESTRUCTOR(tc, puffs, args); } ATF_TC(root_chrdev); @@ -463,16 +198,15 @@ ATF_TC_BODY(root_chrdev, tc) { - char *myopts[] = { - "-r", "chr 2 0", - "dtfs", - }; + MAKEOPTS("-r", "chr 2 0"); + void *args; ssize_t rv; char buf[512]; int fd; - dtfsmountv("/mp", myopts); - fd = rump_sys_open("/mp", O_RDWR); + FSTEST_CONSTRUCTOR_FSPRIV(tc, puffs, args, theopts); + + fd = rump_sys_open(FSTEST_MNTNAME, O_RDWR); if (fd == -1) atf_tc_fail_errno("open null"); @@ -483,8 +217,8 @@ ATF_REQUIRE(rv == 0); rump_sys_close(fd); - if (rump_sys_unmount("/mp", 0) == -1) - atf_tc_fail_errno("unmount"); + + FSTEST_DESTRUCTOR(tc, puffs, args); } /* @@ -500,30 +234,32 @@ ATF_TC_BODY(inactive_basic, tc) { - char *myopts[] = { - "-i", - "dtfs", - }; + struct puffstestargs *pargs; + void *args; int fd; - dtfsmountv("/mp", myopts); - fd = rump_sys_open("/mp/file", O_CREAT | O_RDWR, 0777); + FSTEST_CONSTRUCTOR(tc, puffs, args); + FSTEST_ENTER(); + pargs = args; + + fd = rump_sys_open("file", O_CREAT | O_RDWR, 0777); if (fd == -1) atf_tc_fail_errno("create"); - /* one for /mp */ - ATF_REQUIRE_EQ(vn_toserv_ops[PUFFS_VN_INACTIVE], 1); + /* none yet */ + ATF_REQUIRE_EQ(pargs->pta_vn_toserv_ops[PUFFS_VN_INACTIVE], 0); rump_sys_close(fd); - /* one for /mp/file */ - ATF_REQUIRE_EQ(vn_toserv_ops[PUFFS_VN_INACTIVE], 2); + /* one for file */ + ATF_REQUIRE_EQ(pargs->pta_vn_toserv_ops[PUFFS_VN_INACTIVE], 1); - if (rump_sys_unmount("/mp", 0) == -1) - atf_tc_fail_errno("unmount"); + FSTEST_EXIT(); - /* one for /mp again */ - ATF_REQUIRE_EQ(vn_toserv_ops[PUFFS_VN_INACTIVE], 3); + /* another for the mountpoint */ + ATF_REQUIRE_EQ(pargs->pta_vn_toserv_ops[PUFFS_VN_INACTIVE], 2); + + FSTEST_DESTRUCTOR(tc, puffs, args); } ATF_TC(inactive_reclaim); @@ -535,33 +271,34 @@ ATF_TC_BODY(inactive_reclaim, tc) { - char *myopts[] = { - "-i", - "dtfs", - }; + struct puffstestargs *pargs; + void *args; int fd; - dtfsmountv("/mp", myopts); - fd = rump_sys_open("/mp/file", O_CREAT | O_RDWR, 0777); + FSTEST_CONSTRUCTOR(tc, puffs, args); + FSTEST_ENTER(); + pargs = args; + + fd = rump_sys_open("file", O_CREAT | O_RDWR, 0777); if (fd == -1) atf_tc_fail_errno("create"); - ATF_REQUIRE_EQ(vn_toserv_ops[PUFFS_VN_INACTIVE], 1); + ATF_REQUIRE_EQ(pargs->pta_vn_toserv_ops[PUFFS_VN_INACTIVE], 0); - if (rump_sys_unlink("/mp/file") == -1) + if (rump_sys_unlink("file") == -1) atf_tc_fail_errno("remove"); - ATF_REQUIRE_EQ(vn_toserv_ops[PUFFS_VN_INACTIVE], 2); - ATF_REQUIRE_EQ(vn_toserv_ops[PUFFS_VN_RECLAIM], 0); + ATF_REQUIRE_EQ(pargs->pta_vn_toserv_ops[PUFFS_VN_INACTIVE], 0); + ATF_REQUIRE_EQ(pargs->pta_vn_toserv_ops[PUFFS_VN_RECLAIM], 0); rump_sys_close(fd); - syncbar("/mp"); + syncbar(FSTEST_MNTNAME); - ATF_REQUIRE_EQ(vn_toserv_ops[PUFFS_VN_INACTIVE], 4); - ATF_REQUIRE_EQ(vn_toserv_ops[PUFFS_VN_RECLAIM], 1); + ATF_REQUIRE_EQ(pargs->pta_vn_toserv_ops[PUFFS_VN_INACTIVE], 1); + ATF_REQUIRE_EQ(pargs->pta_vn_toserv_ops[PUFFS_VN_RECLAIM], 1); - if (rump_sys_unmount("/mp", 0) == -1) - atf_tc_fail_errno("unmount"); + FSTEST_EXIT(); + FSTEST_DESTRUCTOR(tc, puffs, args); } ATF_TC(reclaim_hardlink); @@ -574,42 +311,43 @@ ATF_TC_BODY(reclaim_hardlink, tc) { - char *myopts[] = { - "-i", - "dtfs", - }; + struct puffstestargs *pargs; + void *args; int fd; int ianow; - dtfsmountv("/mp", myopts); - fd = rump_sys_open("/mp/file", O_CREAT | O_RDWR, 0777); + FSTEST_CONSTRUCTOR(tc, puffs, args); + FSTEST_ENTER(); + pargs = args; + + fd = rump_sys_open("file", O_CREAT | O_RDWR, 0777); if (fd == -1) atf_tc_fail_errno("create"); - if (rump_sys_link("/mp/file", "/mp/anotherfile") == -1) + if (rump_sys_link("file", "anotherfile") == -1) atf_tc_fail_errno("create link"); rump_sys_close(fd); - ATF_REQUIRE_EQ(vn_toserv_ops[PUFFS_VN_RECLAIM], 0); + ATF_REQUIRE_EQ(pargs->pta_vn_toserv_ops[PUFFS_VN_RECLAIM], 0); /* unlink first hardlink */ - if (rump_sys_unlink("/mp/file") == -1) + if (rump_sys_unlink("file") == -1) atf_tc_fail_errno("unlink 1"); - ATF_REQUIRE_EQ(vn_toserv_ops[PUFFS_VN_RECLAIM], 0); - ianow = vn_toserv_ops[PUFFS_VN_INACTIVE]; + ATF_REQUIRE_EQ(pargs->pta_vn_toserv_ops[PUFFS_VN_RECLAIM], 0); + ianow = pargs->pta_vn_toserv_ops[PUFFS_VN_INACTIVE]; /* unlink second hardlink */ - if (rump_sys_unlink("/mp/anotherfile") == -1) + if (rump_sys_unlink("anotherfile") == -1) atf_tc_fail_errno("unlink 2"); - syncbar("/mp"); + syncbar(FSTEST_MNTNAME); - ATF_REQUIRE(ianow < vn_toserv_ops[PUFFS_VN_INACTIVE]); - ATF_REQUIRE_EQ(vn_toserv_ops[PUFFS_VN_RECLAIM], 1); + ATF_REQUIRE(ianow < pargs->pta_vn_toserv_ops[PUFFS_VN_INACTIVE]); + ATF_REQUIRE_EQ(pargs->pta_vn_toserv_ops[PUFFS_VN_RECLAIM], 1); - if (rump_sys_unmount("/mp", 0) == -1) - atf_tc_fail_errno("unmount"); + FSTEST_EXIT(); + FSTEST_DESTRUCTOR(tc, puffs, args); } ATF_TC(unlink_accessible); @@ -622,42 +360,43 @@ ATF_TC_BODY(unlink_accessible, tc) { - char *myopts[] = { - "-i", - "-o","nopagecache", - "dtfs", - }; + MAKEOPTS("-i", "-o", "nopagecache"); + struct puffstestargs *pargs; + void *args; char buf[512]; int fd, ianow; assert(sizeof(buf) > sizeof(MAGICSTR)); - dtfsmountv("/mp", myopts); - fd = rump_sys_open("/mp/file", O_CREAT | O_RDWR, 0777); + FSTEST_CONSTRUCTOR_FSPRIV(tc, puffs, args, theopts); + FSTEST_ENTER(); + pargs = args; + + fd = rump_sys_open("file", O_CREAT | O_RDWR, 0777); if (fd == -1) atf_tc_fail_errno("create"); if (rump_sys_write(fd, MAGICSTR, sizeof(MAGICSTR)) != sizeof(MAGICSTR)) atf_tc_fail_errno("write"); - if (rump_sys_unlink("/mp/file") == -1) + if (rump_sys_unlink("file") == -1) atf_tc_fail_errno("unlink"); - ATF_REQUIRE_EQ(vn_toserv_ops[PUFFS_VN_RECLAIM], 0); - ianow = vn_toserv_ops[PUFFS_VN_INACTIVE]; + ATF_REQUIRE_EQ(pargs->pta_vn_toserv_ops[PUFFS_VN_RECLAIM], 0); + ianow = pargs->pta_vn_toserv_ops[PUFFS_VN_INACTIVE]; if (rump_sys_pread(fd, buf, sizeof(buf), 0) == -1) atf_tc_fail_errno("read"); rump_sys_close(fd); - syncbar("/mp"); + syncbar(FSTEST_MNTNAME); - ATF_REQUIRE_EQ(vn_toserv_ops[PUFFS_VN_RECLAIM], 1); - ATF_REQUIRE_EQ(vn_toserv_ops[PUFFS_VN_INACTIVE], ianow+2); + ATF_REQUIRE_EQ(pargs->pta_vn_toserv_ops[PUFFS_VN_RECLAIM], 1); + ATF_REQUIRE_EQ(pargs->pta_vn_toserv_ops[PUFFS_VN_INACTIVE], ianow+1); ATF_REQUIRE_STREQ(buf, MAGICSTR); - if (rump_sys_unmount("/mp", 0) == -1) - atf_tc_fail_errno("unmount"); + FSTEST_EXIT(); + FSTEST_DESTRUCTOR(tc, puffs, args); } ATF_TP_ADD_TCS(tp)