support for multiplexing fuse fd
authorMiklos Szeredi <miklos@szeredi.hu>
Wed, 30 Jun 2004 11:34:56 +0000 (11:34 +0000)
committerMiklos Szeredi <miklos@szeredi.hu>
Wed, 30 Jun 2004 11:34:56 +0000 (11:34 +0000)
ChangeLog
include/fuse.h
lib/fuse.c
lib/fuse_mt.c

index 6786d2eea613802f6d9834a5dc500a8be1a0e0d0..5448cc90d1f350b7b690d7828582d43163d53395 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,12 @@
        * Acquire inode->i_sem before open and release methods to prevent
        concurrent rename or unlink operations.
 
+       * Make __fuse_read_cmd() read only one command.  This allows
+       multiplexing the fuse file descriptor with other event sources
+       using select() or poll() (patch by Jeff Harris)
+
+       * Export 'exited' flag with __fuse_exited() (patch by Jeff Harris)
+
 2004-06-27  Miklos Szeredi <mszeredi@inf.bme.hu>
 
        * Fix file offset wrap around at 4G when doing large reads
index d298cb3cb8347a08ea6d4b1754b51681b8955837..aeeb204d753c3503989217829d293bef0c0a16b8 100644 (file)
@@ -273,6 +273,7 @@ typedef void (*fuse_processor_t)(struct fuse *, struct fuse_cmd *, void *);
 struct fuse_cmd *__fuse_read_cmd(struct fuse *f);
 void __fuse_process_cmd(struct fuse *f, struct fuse_cmd *cmd);
 void __fuse_loop_mt(struct fuse *f, fuse_processor_t proc, void *data);
+int __fuse_exited(struct fuse* f);
 
 #ifdef __cplusplus
 }
index d4e95f29d0e54f619524af5e5d393968a1718c1e..4cd89157abda6826b6cd69652290c9309bf6a6a6 100644 (file)
@@ -1432,6 +1432,11 @@ void __fuse_process_cmd(struct fuse *f, struct fuse_cmd *cmd)
     free_cmd(cmd);
 }
 
+int __fuse_exited(struct fuse* f)
+{
+    return f->exited;
+}
+
 struct fuse_cmd *__fuse_read_cmd(struct fuse *f)
 {
     ssize_t res;
@@ -1444,36 +1449,36 @@ struct fuse_cmd *__fuse_read_cmd(struct fuse *f)
     in = (struct fuse_in_header *) cmd->buf;
     inarg = cmd->buf + sizeof(struct fuse_in_header);
 
-    do {
-        res = read(f->fd, cmd->buf, FUSE_MAX_IN);
-        if (res == -1) {
-            free_cmd(cmd);
-            if (f->exited || errno == EINTR)
-                return NULL;
-
-            /* ENODEV means we got unmounted, so we silenty return failure */
-            if (errno != ENODEV) {
-                /* BAD... This will happen again */
-                perror("fuse: reading device");
-            }
-
-            fuse_exit(f);
-            return NULL;
-        }
-        if ((size_t) res < sizeof(struct fuse_in_header)) {
-            free_cmd(cmd);
-            /* Cannot happen */
-            fprintf(stderr, "short read on fuse device\n");
-            fuse_exit(f);
+    res = read(f->fd, cmd->buf, FUSE_MAX_IN);
+    if (res == -1) {
+        free_cmd(cmd);
+        if (__fuse_exited(f) || errno == EINTR)
             return NULL;
+        
+        /* ENODEV means we got unmounted, so we silenty return failure */
+        if (errno != ENODEV) {
+            /* BAD... This will happen again */
+            perror("fuse: reading device");
         }
-        cmd->buflen = res;
         
-        /* Forget is special, it can be done without messing with threads. */
-        if (in->opcode == FUSE_FORGET)
-            do_forget(f, in, (struct fuse_forget_in *) inarg);
-
-    } while (in->opcode == FUSE_FORGET);
+        fuse_exit(f);
+        return NULL;
+    }
+    if ((size_t) res < sizeof(struct fuse_in_header)) {
+        free_cmd(cmd);
+        /* Cannot happen */
+        fprintf(stderr, "short read on fuse device\n");
+        fuse_exit(f);
+        return NULL;
+    }
+    cmd->buflen = res;
+    
+    /* Forget is special, it can be done without messing with threads. */
+    if (in->opcode == FUSE_FORGET) {
+        do_forget(f, in, (struct fuse_forget_in *) inarg);
+        free_cmd(cmd);
+        return NULL;
+    }
 
     return cmd;
 }
@@ -1486,7 +1491,7 @@ void fuse_loop(struct fuse *f)
     while (1) {
         struct fuse_cmd *cmd;
 
-        if (f->exited)
+        if (__fuse_exited(f))
             return;
 
         cmd = __fuse_read_cmd(f);
index afc70d424712dc71659b23cd15f2f2be404b1fc1..597ce1a16093aae0322609b5bff5d8e38d9d41a8 100644 (file)
@@ -38,7 +38,7 @@ static void *do_work(void *data)
     while (1) {
         struct fuse_cmd *cmd;
 
-        if (f->exited)
+        if (__fuse_exited(f))
             break;
 
         cmd = __fuse_read_cmd(w->f);