[PATCH] fuse: clean up request accounting
[deliverable/linux.git] / fs / fuse / fuse_i.h
index 74c8d098a14a2b9ced4faca1c940f804d39cd19f..242e69cb12517c017975fea7489b9736277172b4 100644 (file)
@@ -1,6 +1,6 @@
 /*
   FUSE: Filesystem in Userspace
 /*
   FUSE: Filesystem in Userspace
-  Copyright (C) 2001-2005  Miklos Szeredi <miklos@szeredi.hu>
+  Copyright (C) 2001-2006  Miklos Szeredi <miklos@szeredi.hu>
 
   This program can be distributed under the terms of the GNU GPL.
   See the file COPYING.
 
   This program can be distributed under the terms of the GNU GPL.
   See the file COPYING.
@@ -18,9 +18,6 @@
 /** Max number of pages that can be used in a single read request */
 #define FUSE_MAX_PAGES_PER_REQ 32
 
 /** Max number of pages that can be used in a single read request */
 #define FUSE_MAX_PAGES_PER_REQ 32
 
-/** If more requests are outstanding, then the operation will block */
-#define FUSE_MAX_OUTSTANDING 10
-
 /** It could be as large as PATH_MAX, but would that have any uses? */
 #define FUSE_NAME_MAX 1024
 
 /** It could be as large as PATH_MAX, but would that have any uses? */
 #define FUSE_NAME_MAX 1024
 
@@ -94,6 +91,11 @@ struct fuse_out {
        /** Header returned from userspace */
        struct fuse_out_header h;
 
        /** Header returned from userspace */
        struct fuse_out_header h;
 
+       /*
+        * The following bitfields are not changed during the request
+        * processing
+        */
+
        /** Last argument is variable length (can be shorter than
            arg->size) */
        unsigned argvar:1;
        /** Last argument is variable length (can be shorter than
            arg->size) */
        unsigned argvar:1;
@@ -111,12 +113,23 @@ struct fuse_out {
        struct fuse_arg args[3];
 };
 
        struct fuse_arg args[3];
 };
 
+/** The request state */
+enum fuse_req_state {
+       FUSE_REQ_INIT = 0,
+       FUSE_REQ_PENDING,
+       FUSE_REQ_READING,
+       FUSE_REQ_SENT,
+       FUSE_REQ_FINISHED
+};
+
+struct fuse_conn;
+
 /**
  * A request to the client
  */
 struct fuse_req {
 /**
  * A request to the client
  */
 struct fuse_req {
-       /** This can be on either unused_list, pending or processing
-           lists in fuse_conn */
+       /** This can be on either pending processing or io lists in
+           fuse_conn */
        struct list_head list;
 
        /** Entry on the background list */
        struct list_head list;
 
        /** Entry on the background list */
@@ -125,12 +138,15 @@ struct fuse_req {
        /** refcount */
        atomic_t count;
 
        /** refcount */
        atomic_t count;
 
+       /*
+        * The following bitfields are either set once before the
+        * request is queued or setting/clearing them is protected by
+        * fuse_conn->lock
+        */
+
        /** True if the request has reply */
        unsigned isreply:1;
 
        /** True if the request has reply */
        unsigned isreply:1;
 
-       /** The request is preallocated */
-       unsigned preallocated:1;
-
        /** The request was interrupted */
        unsigned interrupted:1;
 
        /** The request was interrupted */
        unsigned interrupted:1;
 
@@ -140,11 +156,8 @@ struct fuse_req {
        /** Data is being copied to/from the request */
        unsigned locked:1;
 
        /** Data is being copied to/from the request */
        unsigned locked:1;
 
-       /** Request has been sent to userspace */
-       unsigned sent:1;
-
-       /** The request is finished */
-       unsigned finished:1;
+       /** State of the request */
+       enum fuse_req_state state;
 
        /** The request input */
        struct fuse_in in;
 
        /** The request input */
        struct fuse_in in;
@@ -161,6 +174,7 @@ struct fuse_req {
                struct fuse_release_in release_in;
                struct fuse_init_in init_in;
                struct fuse_init_out init_out;
                struct fuse_release_in release_in;
                struct fuse_init_in init_in;
                struct fuse_init_out init_out;
+               struct fuse_read_in read_in;
        } misc;
 
        /** page vector */
        } misc;
 
        /** page vector */
@@ -180,6 +194,9 @@ struct fuse_req {
 
        /** File used in the request (or NULL) */
        struct file *file;
 
        /** File used in the request (or NULL) */
        struct file *file;
+
+       /** Request completion callback */
+       void (*end)(struct fuse_conn *, struct fuse_req *);
 };
 
 /**
 };
 
 /**
@@ -190,8 +207,8 @@ struct fuse_req {
  * unmounted.
  */
 struct fuse_conn {
  * unmounted.
  */
 struct fuse_conn {
-       /** Reference count */
-       int count;
+       /** Lock protecting accessess to  members of this structure */
+       spinlock_t lock;
 
        /** The user id for this mount */
        uid_t user_id;
 
        /** The user id for this mount */
        uid_t user_id;
@@ -217,35 +234,39 @@ struct fuse_conn {
        /** The list of requests being processed */
        struct list_head processing;
 
        /** The list of requests being processed */
        struct list_head processing;
 
+       /** The list of requests under I/O */
+       struct list_head io;
+
        /** Requests put in the background (RELEASE or any other
            interrupted request) */
        struct list_head background;
 
        /** Requests put in the background (RELEASE or any other
            interrupted request) */
        struct list_head background;
 
-       /** Controls the maximum number of outstanding requests */
-       struct semaphore outstanding_sem;
-
-       /** This counts the number of outstanding requests if
-           outstanding_sem would go negative */
-       unsigned outstanding_debt;
-
        /** RW semaphore for exclusion with fuse_put_super() */
        struct rw_semaphore sbput_sem;
 
        /** RW semaphore for exclusion with fuse_put_super() */
        struct rw_semaphore sbput_sem;
 
-       /** The list of unused requests */
-       struct list_head unused_list;
-
        /** The next unique request id */
        u64 reqctr;
 
        /** Mount is active */
        /** The next unique request id */
        u64 reqctr;
 
        /** Mount is active */
-       unsigned mounted : 1;
+       unsigned mounted;
 
 
-       /** Connection established */
-       unsigned connected : 1;
+       /** Connection established, cleared on umount, connection
+           abort and device release */
+       unsigned connected;
 
 
-       /** Connection failed (version mismatch) */
+       /** Connection failed (version mismatch).  Cannot race with
+           setting other bitfields since it is only set once in INIT
+           reply, before any other request, and never cleared */
        unsigned conn_error : 1;
 
        unsigned conn_error : 1;
 
+       /** Do readpages asynchronously?  Only set in INIT */
+       unsigned async_read : 1;
+
+       /*
+        * The following bitfields are only for optimization purposes
+        * and hence races in setting them will not cause malfunction
+        */
+
        /** Is fsync not implemented by fs? */
        unsigned no_fsync : 1;
 
        /** Is fsync not implemented by fs? */
        unsigned no_fsync : 1;
 
@@ -273,21 +294,25 @@ struct fuse_conn {
        /** Is create not implemented by fs? */
        unsigned no_create : 1;
 
        /** Is create not implemented by fs? */
        unsigned no_create : 1;
 
+       /** The number of requests waiting for completion */
+       atomic_t num_waiting;
+
        /** Negotiated minor version */
        unsigned minor;
 
        /** Backing dev info */
        struct backing_dev_info bdi;
        /** Negotiated minor version */
        unsigned minor;
 
        /** Backing dev info */
        struct backing_dev_info bdi;
-};
 
 
-static inline struct fuse_conn **get_fuse_conn_super_p(struct super_block *sb)
-{
-       return (struct fuse_conn **) &sb->s_fs_info;
-}
+       /** kobject */
+       struct kobject kobj;
+
+       /** O_ASYNC requests */
+       struct fasync_struct *fasync;
+};
 
 static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
 {
 
 static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
 {
-       return *get_fuse_conn_super_p(sb);
+       return sb->s_fs_info;
 }
 
 static inline struct fuse_conn *get_fuse_conn(struct inode *inode)
 }
 
 static inline struct fuse_conn *get_fuse_conn(struct inode *inode)
@@ -295,6 +320,11 @@ static inline struct fuse_conn *get_fuse_conn(struct inode *inode)
        return get_fuse_conn_super(inode->i_sb);
 }
 
        return get_fuse_conn_super(inode->i_sb);
 }
 
+static inline struct fuse_conn *get_fuse_conn_kobj(struct kobject *obj)
+{
+       return container_of(obj, struct fuse_conn, kobj);
+}
+
 static inline struct fuse_inode *get_fuse_inode(struct inode *inode)
 {
        return container_of(inode, struct fuse_inode, inode);
 static inline struct fuse_inode *get_fuse_inode(struct inode *inode)
 {
        return container_of(inode, struct fuse_inode, inode);
@@ -306,22 +336,7 @@ static inline u64 get_node_id(struct inode *inode)
 }
 
 /** Device operations */
 }
 
 /** Device operations */
-extern struct file_operations fuse_dev_operations;
-
-/**
- * This is the single global spinlock which protects FUSE's structures
- *
- * The following data is protected by this lock:
- *
- *  - the private_data field of the device file
- *  - the s_fs_info field of the super block
- *  - unused_list, pending, processing lists in fuse_conn
- *  - background list in fuse_conn
- *  - the unique request ID counter reqctr in fuse_conn
- *  - the sb (super_block) field in fuse_conn
- *  - the file (device file) field in fuse_conn
- */
-extern spinlock_t fuse_lock;
+extern const struct file_operations fuse_dev_operations;
 
 /**
  * Get a filled in inode
 
 /**
  * Get a filled in inode
@@ -336,11 +351,10 @@ void fuse_send_forget(struct fuse_conn *fc, struct fuse_req *req,
                      unsigned long nodeid, u64 nlookup);
 
 /**
                      unsigned long nodeid, u64 nlookup);
 
 /**
- * Send READ or READDIR request
+ * Initialize READ or READDIR request
  */
  */
-size_t fuse_send_read_common(struct fuse_req *req, struct file *file,
-                            struct inode *inode, loff_t pos, size_t count,
-                            int isdir);
+void fuse_read_fill(struct fuse_req *req, struct file *file,
+                   struct inode *inode, loff_t pos, size_t count, int opcode);
 
 /**
  * Send OPEN or OPENDIR request
 
 /**
  * Send OPEN or OPENDIR request
@@ -394,12 +408,6 @@ void fuse_init_symlink(struct inode *inode);
  */
 void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr);
 
  */
 void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr);
 
-/**
- * Check if the connection can be released, and if yes, then free the
- * connection structure
- */
-void fuse_release_conn(struct fuse_conn *fc);
-
 /**
  * Initialize the client device
  */
 /**
  * Initialize the client device
  */
@@ -428,11 +436,11 @@ void fuse_reset_request(struct fuse_req *req);
 /**
  * Reserve a preallocated request
  */
 /**
  * Reserve a preallocated request
  */
-struct fuse_req *fuse_get_request(struct fuse_conn *fc);
+struct fuse_req *fuse_get_req(struct fuse_conn *fc);
 
 /**
 
 /**
- * Decrement reference count of a request.  If count goes to zero put
- * on unused list (preallocated) or free request (not preallocated).
+ * Decrement reference count of a request.  If count goes to zero free
+ * the request.
  */
 void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req);
 
  */
 void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req);
 
@@ -454,7 +462,10 @@ void request_send_background(struct fuse_conn *fc, struct fuse_req *req);
 /**
  * Release inodes and file associated with background request
  */
 /**
  * Release inodes and file associated with background request
  */
-void fuse_release_background(struct fuse_req *req);
+void fuse_release_background(struct fuse_conn *fc, struct fuse_req *req);
+
+/* Abort all requests */
+void fuse_abort_conn(struct fuse_conn *fc);
 
 /**
  * Get the attributes of a file
 
 /**
  * Get the attributes of a file
@@ -465,8 +476,3 @@ int fuse_do_getattr(struct inode *inode);
  * Invalidate inode attributes
  */
 void fuse_invalidate_attr(struct inode *inode);
  * Invalidate inode attributes
  */
 void fuse_invalidate_attr(struct inode *inode);
-
-/**
- * Send the INIT message
- */
-void fuse_send_init(struct fuse_conn *fc);
This page took 0.03094 seconds and 5 git commands to generate.