Merge git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi-rc-fixes-2.6
[safe/jmp/linux-2.6] / include / linux / fsnotify_backend.h
index 13d2dd5..4d6f47b 100644 (file)
@@ -9,6 +9,7 @@
 
 #ifdef __KERNEL__
 
+#include <linux/idr.h> /* inotify uses this */
 #include <linux/fs.h> /* struct inode */
 #include <linux/list.h>
 #include <linux/path.h> /* struct path */
                                   FS_MOVED_FROM | FS_MOVED_TO | FS_CREATE |\
                                   FS_DELETE)
 
+/* listeners that hard code group numbers near the top */
+#define DNOTIFY_GROUP_NUM      UINT_MAX
+#define INOTIFY_GROUP_NUM      (DNOTIFY_GROUP_NUM-1)
+
 struct fsnotify_group;
 struct fsnotify_event;
 struct fsnotify_mark_entry;
+struct fsnotify_event_private_data;
 
 /*
  * Each group much define these ops.  The fsnotify infrastructure will call
@@ -78,6 +84,7 @@ struct fsnotify_ops {
        int (*handle_event)(struct fsnotify_group *group, struct fsnotify_event *event);
        void (*free_group_priv)(struct fsnotify_group *group);
        void (*freeing_mark)(struct fsnotify_mark_entry *entry, struct fsnotify_group *group);
+       void (*free_event_priv)(struct fsnotify_event_private_data *priv);
 };
 
 /*
@@ -116,6 +123,13 @@ struct fsnotify_group {
 
        const struct fsnotify_ops *ops; /* how this group handles things */
 
+       /* needed to send notification to userspace */
+       struct mutex notification_mutex;        /* protect the notification_list */
+       struct list_head notification_list;     /* list of event_holder this group needs to send to userspace */
+       wait_queue_head_t notification_waitq;   /* read() on the notification file blocks on this waitq */
+       unsigned int q_len;                     /* events on the queue */
+       unsigned int max_events;                /* maximum events allowed on the list */
+
        /* stores all fastapth entries assoc with this group so they can be cleaned on unregister */
        spinlock_t mark_lock;           /* protect mark_entries list */
        atomic_t num_marks;             /* 1 for each mark entry and 1 for not being
@@ -129,15 +143,54 @@ struct fsnotify_group {
        /* groups can define private fields here or use the void *private */
        union {
                void *private;
+#ifdef CONFIG_INOTIFY_USER
+               struct inotify_group_private_data {
+                       spinlock_t      idr_lock;
+                       struct idr      idr;
+                       u32             last_wd;
+                       struct fasync_struct    *fa;    /* async notification */
+                       struct user_struct      *user;
+               } inotify_data;
+#endif
        };
 };
 
 /*
+ * A single event can be queued in multiple group->notification_lists.
+ *
+ * each group->notification_list will point to an event_holder which in turns points
+ * to the actual event that needs to be sent to userspace.
+ *
+ * Seemed cheaper to create a refcnt'd event and a small holder for every group
+ * than create a different event for every group
+ *
+ */
+struct fsnotify_event_holder {
+       struct fsnotify_event *event;
+       struct list_head event_list;
+};
+
+/*
+ * Inotify needs to tack data onto an event.  This struct lets us later find the
+ * correct private data of the correct group.
+ */
+struct fsnotify_event_private_data {
+       struct fsnotify_group *group;
+       struct list_head event_list;
+};
+
+/*
  * all of the information about the original object we want to now send to
  * a group.  If you want to carry more info from the accessing task to the
  * listener this structure is where you need to be adding fields.
  */
 struct fsnotify_event {
+       /*
+        * If we create an event we are also likely going to need a holder
+        * to link to a group.  So embed one holder in the event.  Means only
+        * one allocation for the common case where we only have one group
+        */
+       struct fsnotify_event_holder holder;
        spinlock_t lock;        /* protection for the associated event_holder and private_list */
        /* to_tell may ONLY be dereferenced during handle_event(). */
        struct inode *to_tell;  /* either the inode the event happened to or its parent */
@@ -161,6 +214,12 @@ struct fsnotify_event {
        int data_type;          /* which of the above union we have */
        atomic_t refcnt;        /* how many groups still are using/need to send this event */
        __u32 mask;             /* the type of access, bitwise OR for FS_* event types */
+
+       u32 sync_cookie;        /* used to corrolate events, namely inotify mv events */
+       char *file_name;
+       size_t name_len;
+
+       struct list_head private_data_list;     /* groups can store private data here */
 };
 
 /*
@@ -193,9 +252,11 @@ struct fsnotify_mark_entry {
 /* called from the vfs helpers */
 
 /* main fsnotify call to send events */
-extern void fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is);
+extern void fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is,
+                    const char *name, u32 cookie);
 extern void __fsnotify_parent(struct dentry *dentry, __u32 mask);
 extern void __fsnotify_inode_delete(struct inode *inode);
+extern u32 fsnotify_get_cookie(void);
 
 static inline int fsnotify_inode_watches_children(struct inode *inode)
 {
@@ -219,7 +280,7 @@ static inline void __fsnotify_update_dcache_flags(struct dentry *dentry)
        assert_spin_locked(&dentry->d_lock);
 
        parent = dentry->d_parent;
-       if (fsnotify_inode_watches_children(parent->d_inode))
+       if (parent->d_inode && fsnotify_inode_watches_children(parent->d_inode))
                dentry->d_flags |= DCACHE_FSNOTIFY_PARENT_WATCHED;
        else
                dentry->d_flags &= ~DCACHE_FSNOTIFY_PARENT_WATCHED;
@@ -257,9 +318,19 @@ extern void fsnotify_put_group(struct fsnotify_group *group);
 /* take a reference to an event */
 extern void fsnotify_get_event(struct fsnotify_event *event);
 extern void fsnotify_put_event(struct fsnotify_event *event);
-/* find private data previously attached to an event */
-extern struct fsnotify_event_private_data *fsnotify_get_priv_from_event(struct fsnotify_group *group,
-                                                                       struct fsnotify_event *event);
+/* find private data previously attached to an event and unlink it */
+extern struct fsnotify_event_private_data *fsnotify_remove_priv_from_event(struct fsnotify_group *group,
+                                                                          struct fsnotify_event *event);
+
+/* attach the event to the group notification queue */
+extern int fsnotify_add_notify_event(struct fsnotify_group *group, struct fsnotify_event *event,
+                                    struct fsnotify_event_private_data *priv);
+/* true if the group notification queue is empty */
+extern bool fsnotify_notify_queue_is_empty(struct fsnotify_group *group);
+/* return, but do not dequeue the first event on the notification queue */
+extern struct fsnotify_event *fsnotify_peek_notify_event(struct fsnotify_group *group);
+/* return AND dequeue the first event on the notification queue */
+extern struct fsnotify_event *fsnotify_remove_notify_event(struct fsnotify_group *group);
 
 /* functions used to manipulate the marks attached to inodes */
 
@@ -276,13 +347,17 @@ extern void fsnotify_destroy_mark_by_entry(struct fsnotify_mark_entry *entry);
 extern void fsnotify_clear_marks_by_group(struct fsnotify_group *group);
 extern void fsnotify_get_mark(struct fsnotify_mark_entry *entry);
 extern void fsnotify_put_mark(struct fsnotify_mark_entry *entry);
+extern void fsnotify_unmount_inodes(struct list_head *list);
 
 /* put here because inotify does some weird stuff when destroying watches */
 extern struct fsnotify_event *fsnotify_create_event(struct inode *to_tell, __u32 mask,
-                                                   void *data, int data_is);
+                                                   void *data, int data_is, const char *name,
+                                                   u32 cookie, gfp_t gfp);
+
 #else
 
-static inline void fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is)
+static inline void fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is,
+                           const char *name, u32 cookie)
 {}
 
 static inline void __fsnotify_parent(struct dentry *dentry, __u32 mask)
@@ -297,6 +372,14 @@ static inline void __fsnotify_update_dcache_flags(struct dentry *dentry)
 static inline void __fsnotify_d_instantiate(struct dentry *dentry, struct inode *inode)
 {}
 
+static inline u32 fsnotify_get_cookie(void)
+{
+       return 0;
+}
+
+static inline void fsnotify_unmount_inodes(struct list_head *list)
+{}
+
 #endif /* CONFIG_FSNOTIFY */
 
 #endif /* __KERNEL __ */