linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / fs / fuse / fuse_i.h
index 69c7750..4a83adf 100644 (file)
@@ -1,6 +1,6 @@
 /*
   FUSE: Filesystem in Userspace
-  Copyright (C) 2001-2006  Miklos Szeredi <miklos@szeredi.hu>
+  Copyright (C) 2001-2005  Miklos Szeredi <miklos@szeredi.hu>
 
   This program can be distributed under the terms of the GNU GPL.
   See the file COPYING.
@@ -8,26 +8,22 @@
 
 #include <linux/fuse.h>
 #include <linux/fs.h>
-#include <linux/mount.h>
 #include <linux/wait.h>
 #include <linux/list.h>
 #include <linux/spinlock.h>
 #include <linux/mm.h>
 #include <linux/backing-dev.h>
-#include <linux/mutex.h>
+#include <asm/semaphore.h>
 
 /** Max number of pages that can be used in a single read request */
 #define FUSE_MAX_PAGES_PER_REQ 32
 
-/** Maximum number of outstanding background requests */
-#define FUSE_MAX_BACKGROUND 10
+/** 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
 
-/** Number of dentries for each connection in the control filesystem */
-#define FUSE_CTL_NUM_DENTRIES 3
-
 /** If the FUSE_DEFAULT_PERMISSIONS flag is given, the filesystem
     module will check permissions based on the file mode.  Otherwise no
     permission checking is done in the kernel */
     doing the mount will be allowed to access the filesystem */
 #define FUSE_ALLOW_OTHER         (1 << 1)
 
-/** List of active connections */
-extern struct list_head fuse_conn_list;
-
-/** Global mutex protecting fuse_conn_list and the control filesystem */
-extern struct mutex fuse_mutex;
 
 /** FUSE inode */
 struct fuse_inode {
@@ -59,13 +50,13 @@ struct fuse_inode {
        struct fuse_req *forget_req;
 
        /** Time in jiffies until the file attributes are valid */
-       u64 i_time;
+       unsigned long i_time;
 };
 
 /** FUSE specific file data */
 struct fuse_file {
        /** Request reserved for flush and release */
-       struct fuse_req *reserved_req;
+       struct fuse_req *release_req;
 
        /** File handle used by userspace */
        u64 fh;
@@ -131,7 +122,6 @@ enum fuse_req_state {
        FUSE_REQ_PENDING,
        FUSE_REQ_READING,
        FUSE_REQ_SENT,
-       FUSE_REQ_WRITING,
        FUSE_REQ_FINISHED
 };
 
@@ -141,46 +131,37 @@ struct fuse_conn;
  * A request to the client
  */
 struct fuse_req {
-       /** This can be on either pending processing or io lists in
-           fuse_conn */
+       /** This can be on either unused_list, pending processing or
+           io lists in fuse_conn */
        struct list_head list;
 
-       /** Entry on the interrupts list  */
-       struct list_head intr_entry;
+       /** Entry on the background list */
+       struct list_head bg_entry;
 
        /** refcount */
        atomic_t count;
 
-       /** Unique ID for the interrupt request */
-       u64 intr_unique;
-
        /*
         * The following bitfields are either set once before the
         * request is queued or setting/clearing them is protected by
-        * fuse_conn->lock
+        * fuse_lock
         */
 
        /** True if the request has reply */
        unsigned isreply:1;
 
-       /** Force sending of the request even if interrupted */
-       unsigned force:1;
+       /** The request is preallocated */
+       unsigned preallocated:1;
 
-       /** The request was aborted */
-       unsigned aborted:1;
+       /** The request was interrupted */
+       unsigned interrupted:1;
 
        /** Request is sent in the background */
        unsigned background:1;
 
-       /** The request has been interrupted */
-       unsigned interrupted:1;
-
        /** Data is being copied to/from the request */
        unsigned locked:1;
 
-       /** Request is counted as "waiting" */
-       unsigned waiting:1;
-
        /** State of the request */
        enum fuse_req_state state;
 
@@ -200,7 +181,6 @@ struct fuse_req {
                struct fuse_init_in init_in;
                struct fuse_init_out init_out;
                struct fuse_read_in read_in;
-               struct fuse_lk_in lk_in;
        } misc;
 
        /** page vector */
@@ -212,20 +192,17 @@ struct fuse_req {
        /** offset of data on first page */
        unsigned page_offset;
 
-       /** File used in the request (or NULL) */
-       struct file *file;
+       /** Inode used in the request */
+       struct inode *inode;
 
-       /** vfsmount used in release */
-       struct vfsmount *vfsmount;
+       /** Second inode used in the request (or NULL) */
+       struct inode *inode2;
 
-       /** dentry used in release */
-       struct dentry *dentry;
+       /** File used in the request (or NULL) */
+       struct file *file;
 
        /** Request completion callback */
        void (*end)(struct fuse_conn *, struct fuse_req *);
-
-       /** Request is stolen from fuse_file->reserved_req */
-       struct file *stolen_file;
 };
 
 /**
@@ -236,12 +213,6 @@ struct fuse_req {
  * unmounted.
  */
 struct fuse_conn {
-       /** Lock protecting accessess to  members of this structure */
-       spinlock_t lock;
-
-       /** Refcount */
-       atomic_t count;
-
        /** The user id for this mount */
        uid_t user_id;
 
@@ -269,23 +240,29 @@ struct fuse_conn {
        /** The list of requests under I/O */
        struct list_head io;
 
-       /** Number of requests currently in the background */
-       unsigned num_background;
+       /** Requests put in the background (RELEASE or any other
+           interrupted request) */
+       struct list_head background;
 
-       /** Pending interrupts */
-       struct list_head interrupts;
+       /** Controls the maximum number of outstanding requests */
+       struct semaphore outstanding_sem;
 
-       /** Flag indicating if connection is blocked.  This will be
-           the case before the INIT reply is received, and if there
-           are too many outstading backgrounds requests */
-       int blocked;
+       /** This counts the number of outstanding requests if
+           outstanding_sem would go negative */
+       unsigned outstanding_debt;
 
-       /** waitq for blocked connection */
-       wait_queue_head_t blocked_waitq;
+       /** 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 */
+       unsigned mounted;
+
        /** Connection established, cleared on umount, connection
            abort and device release */
        unsigned connected;
@@ -324,18 +301,12 @@ struct fuse_conn {
        /** Is removexattr not implemented by fs? */
        unsigned no_removexattr : 1;
 
-       /** Are file locking primitives not implemented by fs? */
-       unsigned no_lock : 1;
-
        /** Is access not implemented by fs? */
        unsigned no_access : 1;
 
        /** Is create not implemented by fs? */
        unsigned no_create : 1;
 
-       /** Is interrupt not implemented by fs? */
-       unsigned no_interrupt : 1;
-
        /** The number of requests waiting for completion */
        atomic_t num_waiting;
 
@@ -345,23 +316,8 @@ struct fuse_conn {
        /** Backing dev info */
        struct backing_dev_info bdi;
 
-       /** Entry on the fuse_conn_list */
-       struct list_head entry;
-
-       /** Unique ID */
-       u64 id;
-
-       /** Dentries in the control filesystem */
-       struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES];
-
-       /** number of dentries used in the above array */
-       int ctl_ndents;
-
-       /** O_ASYNC requests */
-       struct fasync_struct *fasync;
-
-       /** Key for lock owner ID scrambling */
-       u32 scramble_key[4];
+       /** kobject */
+       struct kobject kobj;
 };
 
 static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
@@ -374,6 +330,11 @@ static inline struct fuse_conn *get_fuse_conn(struct inode *inode)
        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);
@@ -385,7 +346,22 @@ static inline u64 get_node_id(struct inode *inode)
 }
 
 /** Device operations */
-extern const struct file_operations fuse_dev_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;
 
 /**
  * Get a filled in inode
@@ -415,9 +391,12 @@ void fuse_file_free(struct fuse_file *ff);
 void fuse_finish_open(struct inode *inode, struct file *file,
                      struct fuse_file *ff, struct fuse_open_out *outarg);
 
-/** */
-struct fuse_req *fuse_release_fill(struct fuse_file *ff, u64 nodeid, int flags,
-                                  int opcode);
+/**
+ * Send a RELEASE request
+ */
+void fuse_send_release(struct fuse_conn *fc, struct fuse_file *ff,
+                      u64 nodeid, struct inode *inode, int flags, int isdir);
+
 /**
  * Send RELEASE or RELEASEDIR request
  */
@@ -464,9 +443,6 @@ int fuse_dev_init(void);
  */
 void fuse_dev_cleanup(void);
 
-int fuse_ctl_init(void);
-void fuse_ctl_cleanup(void);
-
 /**
  * Allocate a request
  */
@@ -478,18 +454,18 @@ struct fuse_req *fuse_request_alloc(void);
 void fuse_request_free(struct fuse_req *req);
 
 /**
- * Get a request, may fail with -ENOMEM
+ * Reinitialize a request, the preallocated flag is left unmodified
  */
-struct fuse_req *fuse_get_req(struct fuse_conn *fc);
+void fuse_reset_request(struct fuse_req *req);
 
 /**
- * Gets a requests for a file operation, always succeeds
+ * Reserve a preallocated request
  */
-struct fuse_req *fuse_get_req_nofail(struct fuse_conn *fc, struct file *file);
+struct fuse_req *fuse_get_request(struct fuse_conn *fc);
 
 /**
- * Decrement reference count of a request.  If count goes to zero free
- * the request.
+ * Decrement reference count of a request.  If count goes to zero put
+ * on unused list (preallocated) or free request (not preallocated).
  */
 void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req);
 
@@ -508,6 +484,11 @@ void request_send_noreply(struct fuse_conn *fc, struct fuse_req *req);
  */
 void request_send_background(struct fuse_conn *fc, struct fuse_req *req);
 
+/**
+ * Release inodes and file associated with background request
+ */
+void fuse_release_background(struct fuse_req *req);
+
 /* Abort all requests */
 void fuse_abort_conn(struct fuse_conn *fc);
 
@@ -520,23 +501,3 @@ int fuse_do_getattr(struct inode *inode);
  * Invalidate inode attributes
  */
 void fuse_invalidate_attr(struct inode *inode);
-
-/**
- * Acquire reference to fuse_conn
- */
-struct fuse_conn *fuse_conn_get(struct fuse_conn *fc);
-
-/**
- * Release reference to fuse_conn
- */
-void fuse_conn_put(struct fuse_conn *fc);
-
-/**
- * Add connection to control filesystem
- */
-int fuse_ctl_add_conn(struct fuse_conn *fc);
-
-/**
- * Remove connection from control filesystem
- */
-void fuse_ctl_remove_conn(struct fuse_conn *fc);