From: Goswin v. B. <gos...@we...> - 2008-08-27 11:29:16
|
Miklos Szeredi <mi...@sz...> writes: > On Thu, 07 Aug 2008, Goswin von Brederlow wrote: >> > Linux's default is to flush data from the cache that is older than 30 >> > seconds, and do such a run every 5 seconds. It also has limits for >> > the size of the data that can be buffered this way. >> > >> > Miklos >> >> Does fuse have any hook for such a 5-second-tick? > > No. > >> Actually I can think of 2 tick() modes: >> >> 1) call every 5 seconds no matter what (unless old tick is still >> running) >> 2) call after 5 seconds without request >> >> Obviously the second can be more or less implemented with the first >> but it might be worth having a flag when registering such a tick() >> callback. >> >> >> Alternatively how would you imlement this, esspecially for a single >> threaded FS? I don't want the tick() to run in parallel with other >> operations. > > You'd have to implement your own event loop in that case. Not that > difficult: basically just poll() followed by fuse_chan_recv() and > fuse_session_process(). > > Miklos I tried this with select instead of poll: --- fuse-2.7.3.orig/lib/fuse_kern_chan.c +++ fuse-2.7.3/lib/fuse_kern_chan.c @@ -14,6 +14,7 @@ #include <errno.h> #include <unistd.h> #include <assert.h> +#include <sys/select.h> static int fuse_kern_chan_receive(struct fuse_chan **chp, char *buf, size_t size) @@ -22,9 +23,21 @@ int err; ssize_t res; struct fuse_session *se = fuse_chan_session(ch); + fd_set rfds; + struct timeval timeout; assert(se != NULL); - + FD_ZERO(&rfds); + FD_SET(fuse_chan_fd(ch), &rfds); restart: + timeout.tv_sec = 1; + timeout.tv_usec = 0; + res = select(fuse_chan_fd(ch), &rfds, NULL, NULL, &timeout); + if (res == -1) { + perror("fuse: select"); + } else if (res == 0) { + printf("fuse: --tick--\n"); + goto restart; + } res = read(fuse_chan_fd(ch), buf, size); err = errno; Problem there is that select will always wait 1 second and always returns 0 and goes into an endless loop. The fuse FD does not seem to support select(). Any chance poll would work? MfG Goswin |