Skip to contentSkip to conversation

Inotify: preliminary nested attributes support.

take1 Evgeniy Polyakov 1 participant 1 message Nov 24, 2008

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

Hi.

Attached patch (untested yet, created to show the idea) implementes scalable nested attributes which are transferred on behalf the inotify mechanism. It uses inotify_init1() to show that new event format should be returned when reading from inotify file descriptor.

Attributes are attached to given inotify instance via TIOCSETD ioctl, where ID of the attribute is transferred. If entry with given ID exists, it is removed and -EEXIST is returned.

There is a set of callbacks indexed by ID (currently 4 attributes are
supported: pid, tid, io details (start/size of the written block) and name), which are attached to given inotify device.
When new event is created, each callback is executed and may queue some data into event structure, based on its internal details. When event is read from the userspace, first its header is transferred (old inotify_event structure) and then all attributes data in the order of its registration via above ioctl. Nested attributes have following structure:

struct inotify_attribute

{
	unsigned int		id;
	unsigned int		size;
	unsigned char		data[0];
};

where size is nuber of attached bytes for given attribute. inotify_event.len contains number of bytes used to store all attached attributes and data.

Attribute callback can check if mask contains its bits and do some steps based on that information, for example io details attribute does not add own data (and header) if event mask does not contain IN_MODIFY bit.

It is possible to infinitely extend number of attributes processed, so we will be no longer limited by inotify API and ABI.

I will cook up userspace example tomorrow and fix possible bugs if find them during testing and would like to get a feedback on idea and implementation. I added all involved in discussion people into copy list, drop me a note if you want to be removed.

fs/inotify.c +11 -12
index 7bbed1b..b56cefc 100644
@@ -24,6 +24,7 @@
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/spinlock.h>
+#include <linux/fsnotify.h>
 #include <linux/idr.h>
 #include <linux/slab.h>
 #include <linux/fs.h>
@@ -251,8 +252,9 @@ static void remove_watch_no_event(struct inotify_watch *watch,
 void inotify_remove_watch_locked(struct inotify_handle *ih,
 				 struct inotify_watch *watch)
 {
+	INOTIFY_DETAILS(det, IN_IGNORED, 0, NULL);
 	remove_watch_no_event(watch, ih);
-	ih->in_ops->handle_event(watch, watch->wd, IN_IGNORED, 0, NULL, NULL);
+	ih->in_ops->handle_event(watch, watch->wd, &det, NULL);
 }
 EXPORT_SYMBOL_GPL(inotify_remove_watch_locked);
 
@@ -297,8 +299,8 @@ void inotify_d_move(struct dentry *entry)
  * @name: filename, if any
  * @n_inode: inode associated with name
  */
-void inotify_inode_queue_event(struct inode *inode, u32 mask, u32 cookie,
-			       const char *name, struct inode *n_inode)
+void inotify_inode_queue_event(struct inode *inode, struct inotify_details *det,
+		struct inode *n_inode)
 {
 	struct inotify_watch *watch, *next;
 
@@ -308,13 +310,12 @@ void inotify_inode_queue_event(struct inode *inode, u32 mask, u32 cookie,
 	mutex_lock(&inode->inotify_mutex);
 	list_for_each_entry_safe(watch, next, &inode->inotify_watches, i_list) {
 		u32 watch_mask = watch->mask;
-		if (watch_mask & mask) {
+		if (watch_mask & det->mask) {
 			struct inotify_handle *ih= watch->ih;
 			mutex_lock(&ih->mutex);
 			if (watch_mask & IN_ONESHOT)
 				remove_watch_no_event(watch, ih);
-			ih->in_ops->handle_event(watch, watch->wd, mask, cookie,
-						 name, n_inode);
+			ih->in_ops->handle_event(watch, watch->wd, det, n_inode);
 			mutex_unlock(&ih->mutex);
 		}
 	}
@@ -329,8 +330,7 @@ EXPORT_SYMBOL_GPL(inotify_inode_queue_event);
  * @cookie: cookie for synchronization, or zero
  * @name: filename, if any
  */
-void inotify_dentry_parent_queue_event(struct dentry *dentry, u32 mask,
-				       u32 cookie, const char *name)
+void inotify_dentry_parent_queue_event(struct dentry *dentry, struct inotify_details *det)
 {
 	struct dentry *parent;
 	struct inode *inode;
@@ -345,8 +345,7 @@ void inotify_dentry_parent_queue_event(struct dentry *dentry, u32 mask,
 	if (inotify_inode_watched(inode)) {
 		dget(parent);
 		spin_unlock(&dentry->d_lock);
-		inotify_inode_queue_event(inode, mask, cookie, name,
-					  dentry->d_inode);
+		inotify_inode_queue_event(inode, det, dentry->d_inode);
 		dput(parent);
 	} else
 		spin_unlock(&dentry->d_lock);
@@ -428,9 +427,9 @@ void inotify_unmount_inodes(struct list_head *list)
 		watches = &inode->inotify_watches;
 		list_for_each_entry_safe(watch, next_w, watches, i_list) {
 			struct inotify_handle *ih= watch->ih;
+			INOTIFY_DETAILS(det, IN_UNMOUNT, 0, NULL);
 			mutex_lock(&ih->mutex);
-			ih->in_ops->handle_event(watch, watch->wd, IN_UNMOUNT, 0,
-						 NULL, NULL);
+			ih->in_ops->handle_event(watch, watch->wd, &det, NULL);
 			inotify_remove_watch_locked(ih, watch);
 			mutex_unlock(&ih->mutex);
 		}
fs/inotify_user.c +260 -38

445 lines not on this page · raw message

fs/read_write.c +2 -2
index 969a6d9..5c521c2 100644
@@ -335,7 +335,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
 		else
 			ret = do_sync_write(file, buf, count, pos);
 		if (ret > 0) {
-			fsnotify_modify(file->f_path.dentry);
+			fsnotify_modify(file->f_path.dentry, *pos - ret, ret);
 			add_wchar(current, ret);
 		}
 		inc_syscw(current);
@@ -628,7 +628,7 @@ out:
 		if (type == READ)
 			fsnotify_access(file->f_path.dentry);
 		else
-			fsnotify_modify(file->f_path.dentry);
+			fsnotify_modify(file->f_path.dentry, *pos - ret, ret);
 	}
 	return ret;
 }
include/linux/fsnotify.h +62 -43

226 lines not on this page · raw message

include/linux/inotify.h +43 -7

75 lines not on this page · raw message

Signature · 5 lines
	Evgeniy Polyakov
--
To unsubscribe from this list: send the line "unsubscribe linux-api" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html