From: Goswin v. B. <gos...@we...> - 2010-03-17 08:16:32
|
Stef Bon <st...@gm...> writes: > 2010/3/11 Goswin von Brederlow <gos...@we...>: > >> >> You need to replace the >> >> Â int fuse_session_loop(struct fuse_session *se); >> >> You can cut&paste most of it >> from the fuse source and modify it to select/poll as needed though. My >> loop looks something like this: >> >> while(true) { >> Â select(nfds, readfds, writefds, exceptfds, timeout); >> Â if (FD_ISSET(fuse_fd, readfds)) { >> Â Â if (fuse_session_exited(fs->se) != 0) { >> Â Â Â Â umount_common(fs); >> Â Â Â Â free(buffer); >> Â Â Â Â buffer = NULL; >> Â Â Â Â break; >> Â Â } >> Â Â struct fuse_chan *tmpch = fs->ch; >> Â Â res = fuse_chan_recv(&tmpch, buf, size); >> Â Â if (res > 0) { >> Â Â Â Â fuse_session_process(fs->se, buf, res, tmpch); >> Â Â } else if (fuse_session_exited(fs->se) != 0) { >> Â Â Â Â umount_common(fs); >> Â Â Â Â free(buffer); >> Â Â Â Â buffer = NULL; >> Â Â Â Â break; >> Â Â } >> Â } else { >> Â Â // handle aio >> Â } >> } > > Well thank you very much for your idea. I'm not into fd/poll/select > programming, so I had to do a lot of reading before I got a clue how > this select/poll/fd works. > > Now when I reread your email again, I see what you mean, at least I hope I do. > > So please correct me when I write things here that do not make any sense. > > In stead of the original fuse_session_loop, which is a loop, exiting > when fuse_session_exited is true, > it is a loop around select, which waits for any activity on the fd's. > The fuse module itself is a > fd (fuse_fd), and select will note there action there. It will perform > the right action (by calling fuse_session_process). > > If there is no action there, there is action on the other fd's, which > are handled apart. Yes, that is the idea. In my case I have exactly 2 FDs so a simple "if/else" construct works fine. With more FDs in the mix you might want to use a different mechanism than "if". > Now this should work when there are no other fd's. If there are no other FDs then the FDSet will only have one bit set, the one for fuse. It is a bit pointless to select on one FD (unless you want to use a timeout as well) but perfectly OK. > I do like your setup very much, by making the fuse module act as a fd. > > I have still some questions. > Where does this fuse_fd come from? Did you forget to define it, or is > this just not defined yet because this is just an idea which is not > complete yet? /** * Query the file descriptor of the channel * * @param ch the channel * @return the file descriptor passed to fuse_chan_new() */ int fuse_chan_fd(struct fuse_chan *ch); > Futher, select makes use of nfds, readfds, writefds, exceptfds, > timeout, they have to be defined first right? yes. Read the manpages for select, poll and epoll. > In the case of the overlay filesystem, this means that the readfds are > those inotify fd set on the underlying fs. > > Apart from how fuse finds out about inotify requests and how to pass > them to the underlying fs, is this correct? Yes. It might be better to use epoll instead of select and set callbacks to handle the fd with activity better. With many FDs select becomes increasingly inefficient and I think epoll is just easier to use for you in the first place. But that might just be a matter of taste with the number of FDs you probably have to handle. > Stef MfG Goswin |