"support" vop_poll enough for testing purposes. In short, yield every

poll request for a few seconds before returning.
This commit is contained in:
pooka 2007-05-18 13:55:21 +00:00
parent 75bb6c40b0
commit 48d5a49e1f
4 changed files with 76 additions and 10 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: dtfs.c,v 1.24 2007/05/17 14:10:13 pooka Exp $ */
/* $NetBSD: dtfs.c,v 1.25 2007/05/18 13:55:21 pooka Exp $ */
/*
* Copyright (c) 2006 Antti Kantee. All Rights Reserved.
@ -53,7 +53,8 @@
#define FSNAME "dt"
#endif
static struct puffs_usermount *pu;
static struct puffs_usermount *gpu;
static struct dtfs_mount gdtm;
int dynamicfh;
static void usage(void);
@ -74,8 +75,32 @@ static void
dosuspend(int v)
{
puffs_fs_suspend(pu);
puffs_fs_suspend(pu);
puffs_fs_suspend(gpu);
puffs_fs_suspend(gpu);
}
static void
wipe_the_sleep_out_of_my_eyes(int v)
{
gdtm.dtm_needwakeup++;
}
static void
loopfun(struct puffs_usermount *pu)
{
struct dtfs_mount *dtm = puffs_getspecific(pu);
struct dtfs_poll *dp;
while (dtm->dtm_needwakeup) {
dtm->dtm_needwakeup--;
dp = LIST_FIRST(&dtm->dtm_pollent);
if (dp == NULL)
return;
LIST_REMOVE(dp, dp_entries);
puffs_cc_continue(dp->dp_pcc);
}
}
int
@ -83,9 +108,10 @@ main(int argc, char *argv[])
{
extern char *optarg;
extern int optind;
struct dtfs_mount dtm;
struct puffs_usermount *pu;
struct puffs_pathobj *po_root;
struct puffs_ops *pops;
struct timespec ts;
char *rtstr;
mntoptparse_t mp;
int pflags, lflags, mntflags;
@ -156,6 +182,7 @@ main(int argc, char *argv[])
PUFFSOP_SET(pops, dtfs, node, create);
PUFFSOP_SET(pops, dtfs, node, remove);
PUFFSOP_SET(pops, dtfs, node, readdir);
PUFFSOP_SET(pops, dtfs, node, poll);
PUFFSOP_SET(pops, dtfs, node, mkdir);
PUFFSOP_SET(pops, dtfs, node, rmdir);
PUFFSOP_SET(pops, dtfs, node, rename);
@ -170,9 +197,10 @@ main(int argc, char *argv[])
srandom(time(NULL)); /* for random generation numbers */
pu = puffs_init(pops, FSNAME, &dtm, pflags);
pu = puffs_init(pops, FSNAME, &gdtm, pflags);
if (pu == NULL)
err(1, "init");
gpu = pu;
puffs_setfhsize(pu, sizeof(struct dtfs_fid),
PUFFS_FHFLAG_NFSV2 | PUFFS_FHFLAG_NFSV3
@ -181,6 +209,8 @@ main(int argc, char *argv[])
if (signal(SIGUSR1, dosuspend) == SIG_ERR)
warn("cannot set suspend sighandler");
if (signal(SIGALRM, wipe_the_sleep_out_of_my_eyes) == SIG_ERR)
warn("cannot set alarm sighandler");
/* init */
if (dtfs_domount(pu, rtstr) != 0)
@ -190,6 +220,12 @@ main(int argc, char *argv[])
po_root->po_path = argv[0];
po_root->po_len = strlen(argv[0]);
/* often enough for testing poll */
ts.tv_sec = 1;
ts.tv_nsec = 0;
puffs_ml_setloopfn(pu, loopfun);
puffs_ml_settimeout(pu, &ts);
if (puffs_mount(pu, argv[0], mntflags, puffs_getroot(pu)) == -1)
err(1, "mount");
if (puffs_mainloop(pu, lflags) == -1)

View File

@ -1,4 +1,4 @@
/* $NetBSD: dtfs.h,v 1.15 2007/05/17 14:10:13 pooka Exp $ */
/* $NetBSD: dtfs.h,v 1.16 2007/05/18 13:55:21 pooka Exp $ */
/*
* Copyright (c) 2006 Antti Kantee. All Rights Reserved.
@ -50,6 +50,9 @@ struct dtfs_mount {
size_t dtm_fsizes; /* sum of file sizes in bytes */
fsfilcnt_t dtm_nfiles; /* number of files */
LIST_HEAD(, dtfs_poll) dtm_pollent;
int dtm_needwakeup;
};
struct dtfs_file {
@ -92,6 +95,11 @@ struct dtfs_fid {
};
#define DTFS_FIDSIZE (sizeof(struct dtfs_fid))
struct dtfs_poll {
struct puffs_cc *dp_pcc;
LIST_ENTRY(dtfs_poll) dp_entries;
};
struct puffs_node * dtfs_genfile(struct puffs_node *,
const struct puffs_cn *, enum vtype);
struct dtfs_file * dtfs_newdir(void);

View File

@ -1,4 +1,4 @@
/* $NetBSD: dtfs_vfsops.c,v 1.17 2007/05/17 14:10:13 pooka Exp $ */
/* $NetBSD: dtfs_vfsops.c,v 1.18 2007/05/18 13:55:21 pooka Exp $ */
/*
* Copyright (c) 2006 Antti Kantee. All Rights Reserved.
@ -133,6 +133,7 @@ dtfs_domount(struct puffs_usermount *pu, const char *typestr)
dtm->dtm_nextfileid = 3;
dtm->dtm_nfiles = 1;
dtm->dtm_fsizes = 0;
LIST_INIT(&dtm->dtm_pollent);
/*
* create root directory, do it "by hand" to avoid special-casing

View File

@ -1,4 +1,4 @@
/* $NetBSD: dtfs_vnops.c,v 1.25 2007/05/07 17:18:50 pooka Exp $ */
/* $NetBSD: dtfs_vnops.c,v 1.26 2007/05/18 13:55:21 pooka Exp $ */
/*
* Copyright (c) 2006 Antti Kantee. All Rights Reserved.
@ -29,6 +29,7 @@
*/
#include <sys/types.h>
#include <sys/poll.h>
#include <assert.h>
#include <errno.h>
@ -36,7 +37,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ucontext.h>
#include <unistd.h>
#include <util.h>
#include "dtfs.h"
@ -272,6 +273,26 @@ dtfs_node_readdir(struct puffs_cc *pcc, void *opc,
return 0;
}
int
dtfs_node_poll(struct puffs_cc *pcc, void *opc, int *events, pid_t pid)
{
struct dtfs_mount *dtm = puffs_cc_getspecific(pcc);
struct dtfs_poll dp;
struct itimerval it;
memset(&it, 0, sizeof(struct itimerval));
it.it_value.tv_sec = 4;
if (setitimer(ITIMER_REAL, &it, NULL) == -1)
return errno;
dp.dp_pcc = pcc;
LIST_INSERT_HEAD(&dtm->dtm_pollent, &dp, dp_entries);
puffs_cc_yield(pcc);
*events = *events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM);
return 0;
}
int
dtfs_node_rename(struct puffs_cc *pcc, void *opc, void *src,
const struct puffs_cn *pcn_src, void *targ_dir, void *targ,