libfuse: Notifying the kernel of deletion.
authorJohn Muir <john@jmuir.com>
Tue, 6 Dec 2011 20:56:34 +0000 (21:56 +0100)
committerMiklos Szeredi <mszeredi@suse.cz>
Wed, 7 Dec 2011 11:23:58 +0000 (12:23 +0100)
libfuse part to allow a FUSE file-system to tell the kernel when a
file or directory is deleted. If the specified dentry has the
specified inode number, the kernel will unhash it.

Signed-off-by: John Muir <john@jmuir.com>
Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
ChangeLog
include/fuse_kernel.h
include/fuse_lowlevel.h
lib/fuse_lowlevel.c
lib/fuse_versionscript

index 636dddcf3b0fb955009117543b2b5849e98e296d..3f6133d9d450e63e606a6614cd6d6882cf385ac3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2011-12-07  Miklos Szeredi <miklos@szeredi.hu>
+
+       * Add fuse_lowlevel_notify_delete() which tells the kernel that a
+       file or directory is deleted.  Patch by John Muir
+
 2011-12-06  Miklos Szeredi <miklos@szeredi.hu>
 
        * Add mmap() and munmap() methods to low level API.  Currently
index 039eb1ffb877381c146c9cf81641a50ca8e9be21..89e941ac778653af041457578fc0a68b10bde6f2 100644 (file)
@@ -79,6 +79,7 @@
  *
  * 7.18
  *  - add FUSE_IOCTL_DIR flag
+ *  - add FUSE_NOTIFY_DELETE
  *  - add FUSE_MMAP and FUSE_MUNMAP
  */
 
@@ -322,6 +323,7 @@ enum fuse_notify_code {
        FUSE_NOTIFY_INVAL_ENTRY = 3,
        FUSE_NOTIFY_STORE = 4,
        FUSE_NOTIFY_RETRIEVE = 5,
+       FUSE_NOTIFY_DELETE = 6,
        FUSE_NOTIFY_CODE_MAX,
 };
 
@@ -667,6 +669,13 @@ struct fuse_notify_inval_entry_out {
        __u32   padding;
 };
 
+struct fuse_notify_delete_out {
+       __u64   parent;
+       __u64   child;
+       __u32   namelen;
+       __u32   padding;
+};
+
 struct fuse_notify_store_out {
        __u64   nodeid;
        __u64   offset;
index 643593740daab596d65b2312b38a36e3821bbad4..8ed555eb629911161ff84d36c43f9e281fb0424e 100644 (file)
@@ -1322,6 +1322,22 @@ int fuse_lowlevel_notify_inval_inode(struct fuse_chan *ch, fuse_ino_t ino,
 int fuse_lowlevel_notify_inval_entry(struct fuse_chan *ch, fuse_ino_t parent,
                                      const char *name, size_t namelen);
 
+/**
+ * Notify to invalidate parent attributes and delete the dentry matching
+ * parent/name if the dentry's inode number matches child (otherwise it
+ * will invalidate the matching dentry).
+ *
+ * @param ch the channel through which to send the notification
+ * @param parent inode number
+ * @param child inode number
+ * @param name file name
+ * @param namelen strlen() of file name
+ * @return zero for success, -errno for failure
+ */
+int fuse_lowlevel_notify_delete(struct fuse_chan *ch,
+                               fuse_ino_t parent, fuse_ino_t child,
+                               const char *name, size_t namelen);
+
 /**
  * Store data to the kernel buffers
  *
index f69b2b122824fee1a6cc8120f59930a5d1fd768e..3bfc9932d652ce20f4be451b6afaa0a75a383f0b 100644 (file)
@@ -2054,6 +2054,34 @@ int fuse_lowlevel_notify_inval_entry(struct fuse_chan *ch, fuse_ino_t parent,
        return send_notify_iov(f, ch, FUSE_NOTIFY_INVAL_ENTRY, iov, 3);
 }
 
+int fuse_lowlevel_notify_delete(struct fuse_chan *ch,
+                               fuse_ino_t parent, fuse_ino_t child,
+                               const char *name, size_t namelen)
+{
+       struct fuse_notify_delete_out outarg;
+       struct fuse_ll *f;
+       struct iovec iov[3];
+
+       if (!ch)
+               return -EINVAL;
+
+       f = (struct fuse_ll *)fuse_session_data(fuse_chan_session(ch));
+       if (!f)
+               return -ENODEV;
+
+       outarg.parent = parent;
+       outarg.child = child;
+       outarg.namelen = namelen;
+       outarg.padding = 0;
+
+       iov[1].iov_base = &outarg;
+       iov[1].iov_len = sizeof(outarg);
+       iov[2].iov_base = (void *)name;
+       iov[2].iov_len = namelen + 1;
+
+       return send_notify_iov(f, ch, FUSE_NOTIFY_DELETE, iov, 3);
+}
+
 int fuse_lowlevel_notify_store(struct fuse_chan *ch, fuse_ino_t ino,
                               off_t offset, struct fuse_bufvec *bufv,
                               enum fuse_buf_copy_flags flags)
index 1ee1c9d9af28b46d56f94b83a0cc62195cbae862..95bc7d9b5fe4c8589938e23be52bbb1139c85d88 100644 (file)
@@ -195,6 +195,7 @@ FUSE_2.9 {
                fuse_stop_cleanup_thread;
                fuse_clean_cache;
                fuse_reply_mmap;
+               fuse_lowlevel_notify_delete;
 
        local:
                *;