API changes
authorMiklos Szeredi <miklos@szeredi.hu>
Sat, 30 Sep 2006 20:03:52 +0000 (20:03 +0000)
committerMiklos Szeredi <miklos@szeredi.hu>
Sat, 30 Sep 2006 20:03:52 +0000 (20:03 +0000)
ChangeLog
example/fusexmp_fh.c
include/fuse.h
include/fuse_common.h
include/fuse_lowlevel.h
kernel/fuse_kernel.h
lib/fuse.c
lib/fuse_lowlevel.c

index 9846bf4f9e431d9d91177741dfb6e1e6fbbc56d6..c5858a0c6934c88f1d171a7d065968f1a315c77f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2006-09-30  Miklos Szeredi <miklos@szeredi.hu>
 
+       * API changes:
+
+       * Move lock_owner from a separate argument into fuse_file_info
+
+       * Add a flag to fuse_file_info indicating (1) a highlevel lock
+       operation (unlock all) was initiated by a flush, (2) a lowlevel
+       release operation should perform a flush as well.
+
        * fusermount: revert modprobe change (2006-08-18) since it
        doesn't work reliably with udev
 
index 9bf0d25a7040865dfb3c0470ffd10e983821e806..2ad1a509a631fedcd059a8ce62435d758b32f5eb 100644 (file)
@@ -402,11 +402,12 @@ static int xmp_removexattr(const char *path, const char *name)
 #endif /* HAVE_SETXATTR */
 
 static int xmp_lock(const char *path, struct fuse_file_info *fi, int cmd,
-                    struct flock *lock, uint64_t owner)
+                    struct flock *lock)
 {
     (void) path;
 
-    return ulockmgr_op(fi->fh, cmd, lock, &owner, sizeof(owner));
+    return ulockmgr_op(fi->fh, cmd, lock, &fi->lock_owner,
+                       sizeof(fi->lock_owner));
 }
 
 static struct fuse_operations xmp_oper = {
index 797f225370e58e4b47bb405998fa7b55a0fcb869..37aec282af6b6899a2990d18d95738b9c3be7f64 100644 (file)
@@ -376,7 +376,8 @@ struct fuse_operations {
      * for fcntl(2).  The l_whence field will always be set to
      * SEEK_SET.
      *
-     * For checking lock ownership, the 'owner' argument must be used.
+     * For checking lock ownership, the 'fuse_file_info->owner'
+     * argument must be used.
      *
      * For F_GETLK operation, the library will first check currently
      * held locks, and if a conflicting lock is found it will return
@@ -399,7 +400,7 @@ struct fuse_operations {
      * Introduced in version 2.6
      */
     int (*lock) (const char *, struct fuse_file_info *, int cmd,
-                 struct flock *, uint64_t owner);
+                 struct flock *);
 
     /**
      * Change the access and modification times of a file with
index 73cc0df8e0c97eab892025a36d2a97a4653cc337..b687043e5ff38f285903b479dcfe776b72217654 100644 (file)
@@ -58,12 +58,20 @@ struct fuse_file_info {
         need not be invalidated.  Introduced in version 2.4 */
     unsigned int keep_cache : 1;
 
+    /** Indicates a flush operation.  Set in flush operation, also
+        maybe set in highlevel lock operation and lowlevel release
+        operation.  Introduced in version 2.6 */
+    unsigned int flush : 1;
+
     /** Padding.  Do not use*/
-    unsigned int padding : 30;
+    unsigned int padding : 29;
 
     /** File handle.  May be filled in by filesystem in open().
         Available in all other file operations */
     uint64_t fh;
+
+    /** Lock owner id.  Available in locking operations and flush */
+    uint64_t lock_owner;
 };
 
 struct fuse_conn_info {
index 83e9739b909119547dde0f85418a2374afaed486..47bdeb1fe9714ad38dc87936f1f60d40d7040f18 100644 (file)
@@ -449,7 +449,7 @@ struct fuse_lowlevel_ops {
      * write errors.
      *
      * If the filesystem supports file locking operations (setlk,
-     * getlk) it should remove all locks belonging to 'owner'.
+     * getlk) it should remove all locks belonging to 'fi->owner'.
      *
      * Valid replies:
      *   fuse_reply_err
@@ -457,10 +457,8 @@ struct fuse_lowlevel_ops {
      * @param req request handle
      * @param ino the inode number
      * @param fi file information
-     * @param owner lock owner id
      */
-    void (*flush) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi,
-                   uint64_t owner);
+    void (*flush) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi);
 
     /**
      * Release an open file
@@ -743,17 +741,16 @@ struct fuse_lowlevel_ops {
      * @param ino the inode number
      * @param fi file information
      * @param lock the region/type to test
-     * @param owner lock owner id of caller
      */
     void (*getlk) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi,
-                   struct flock *lock, uint64_t owner);
+                   struct flock *lock);
 
     /**
      * Acquire, modify or release a POSIX file lock
      *
      * For POSIX threads (NPTL) there's a 1-1 relation between pid and
      * owner, but otherwise this is not always the case.  For checking
-     * lock ownership, 'owner' must be used.  The l_pid field in
+     * lock ownership, 'fi->owner' must be used.  The l_pid field in
      * 'struct flock' should only be used to fill in this field in
      * getlk().
      *
@@ -770,11 +767,10 @@ struct fuse_lowlevel_ops {
      * @param ino the inode number
      * @param fi file information
      * @param lock the region/type to test
-     * @param owner lock owner id of caller
      * @param sleep locking operation may sleep
      */
     void (*setlk) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi,
-                   struct flock *lock, uint64_t owner, int sleep);
+                   struct flock *lock, int sleep);
 
     /**
      * Map block index within file to block index within device
index 936ea95f48c0c3e00c283453f6a4a814c9e932fa..c2243d9e1998d50e860cd207bd03ae403d359fc9 100644 (file)
@@ -246,7 +246,7 @@ struct fuse_release_in {
 
 struct fuse_flush_in {
        __u64   fh;
-       __u32   flush_flags;
+       __u32   unused;
        __u32   padding;
        __u64   lock_owner;
 };
index 0e3e1d14c6442f6fcf7f4f527c5ec58214650a12..c28528eba06a2f05dec149ad47090ac9ba38bb16 100644 (file)
@@ -615,13 +615,12 @@ static int fuse_do_create(struct fuse *f, fuse_req_t req, const char *path,
 }
 
 static int fuse_do_lock(struct fuse *f, fuse_req_t req, const char *path,
-                        struct fuse_file_info *fi, int cmd, struct flock *lock,
-                        uint64_t owner)
+                        struct fuse_file_info *fi, int cmd, struct flock *lock)
 {
     int res;
     struct fuse_intr_data d;
     fuse_prepare_interrupt(f, req, &d);
-    res = f->op.lock(path, fi, cmd, lock, owner);
+    res = f->op.lock(path, fi, cmd, lock);
     fuse_finish_interrupt(f, req, &d);
     return res;
 }
@@ -2263,7 +2262,7 @@ static void lock_to_flock(struct lock *lock, struct flock *flock)
 }
 
 static void fuse_flush(fuse_req_t req, fuse_ino_t ino,
-                       struct fuse_file_info *fi, uint64_t owner)
+                       struct fuse_file_info *fi)
 {
     struct fuse *f = req_fuse_prepare(req);
     char *path;
@@ -2292,9 +2291,9 @@ static void fuse_flush(fuse_req_t req, fuse_ino_t ino,
         memset(&lock, 0, sizeof(lock));
         lock.l_type = F_UNLCK;
         lock.l_whence = SEEK_SET;
-        fuse_do_lock(f, req, path, fi, F_SETLK, &lock, owner);
+        fuse_do_lock(f, req, path, fi, F_SETLK, &lock);
         flock_to_lock(&lock, &l);
-        l.owner = owner;
+        l.owner = fi->lock_owner;
         pthread_mutex_lock(&f->lock);
         locks_insert(get_node(f, ino), &l);
         pthread_mutex_unlock(&f->lock);
@@ -2309,7 +2308,7 @@ static void fuse_flush(fuse_req_t req, fuse_ino_t ino,
 
 static int fuse_lock_common(fuse_req_t req, fuse_ino_t ino,
                             struct fuse_file_info *fi, struct flock *lock,
-                            uint64_t owner, int cmd)
+                            int cmd)
 {
     struct fuse *f = req_fuse_prepare(req);
     char *path;
@@ -2319,7 +2318,7 @@ static int fuse_lock_common(fuse_req_t req, fuse_ino_t ino,
     pthread_rwlock_rdlock(&f->tree_lock);
     path = get_path(f, ino);
     if (path != NULL) {
-        err = fuse_do_lock(f, req, path, fi, cmd, lock, owner);
+        err = fuse_do_lock(f, req, path, fi, cmd, lock);
         free(path);
     }
     pthread_rwlock_unlock(&f->tree_lock);
@@ -2327,8 +2326,7 @@ static int fuse_lock_common(fuse_req_t req, fuse_ino_t ino,
 }
 
 static void fuse_getlk(fuse_req_t req, fuse_ino_t ino,
-                       struct fuse_file_info *fi, struct flock *lock,
-                       uint64_t owner)
+                       struct fuse_file_info *fi, struct flock *lock)
 {
     int err;
     struct lock l;
@@ -2336,14 +2334,14 @@ static void fuse_getlk(fuse_req_t req, fuse_ino_t ino,
     struct fuse *f = req_fuse(req);
 
     flock_to_lock(lock, &l);
-    l.owner = owner;
+    l.owner = fi->lock_owner;
     pthread_mutex_lock(&f->lock);
     conflict = locks_conflict(get_node(f, ino), &l);
     if (conflict)
         lock_to_flock(conflict, lock);
     pthread_mutex_unlock(&f->lock);
     if (!conflict)
-        err = fuse_lock_common(req, ino, fi, lock, owner, F_GETLK);
+        err = fuse_lock_common(req, ino, fi, lock, F_GETLK);
     else
         err = 0;
 
@@ -2355,15 +2353,14 @@ static void fuse_getlk(fuse_req_t req, fuse_ino_t ino,
 
 static void fuse_setlk(fuse_req_t req, fuse_ino_t ino,
                        struct fuse_file_info *fi, struct flock *lock,
-                       uint64_t owner, int sleep)
+                       int sleep)
 {
-    int err = fuse_lock_common(req, ino, fi, lock, owner,
-                               sleep ? F_SETLKW : F_SETLK);
+    int err = fuse_lock_common(req, ino, fi, lock, sleep ? F_SETLKW : F_SETLK);
     if (!err) {
         struct fuse *f = req_fuse(req);
         struct lock l;
         flock_to_lock(lock, &l);
-        l.owner = owner;
+        l.owner = fi->lock_owner;
         pthread_mutex_lock(&f->lock);
         locks_insert(get_node(f, ino), &l);
         pthread_mutex_unlock(&f->lock);
index 8ea6779e5b484e4b9a19265c70d1b85bbf9af10f..4308a262246ae5a17bf4a2c64c0d8e25590ea728 100644 (file)
@@ -620,17 +620,16 @@ static void do_flush(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
 {
     struct fuse_flush_in *arg = (struct fuse_flush_in *) inarg;
     struct fuse_file_info fi;
-    uint64_t lock_owner = 0;
-
-    if (req->f->conn.proto_minor >= 7)
-        lock_owner = arg->lock_owner;
 
     memset(&fi, 0, sizeof(fi));
     fi.fh = arg->fh;
     fi.fh_old = fi.fh;
+    fi.flush = 1;
+    if (req->f->conn.proto_minor >= 7)
+        fi.lock_owner = arg->lock_owner;
 
     if (req->f->op.flush)
-        req->f->op.flush(req, nodeid, &fi, lock_owner);
+        req->f->op.flush(req, nodeid, &fi);
     else
         fuse_reply_err(req, ENOSYS);
 }
@@ -806,10 +805,11 @@ static void do_getlk(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
 
     memset(&fi, 0, sizeof(fi));
     fi.fh = arg->fh;
+    fi.lock_owner = arg->owner;
 
     convert_fuse_file_lock(&arg->lk, &flock);
     if (req->f->op.getlk)
-        req->f->op.getlk(req, nodeid, &fi, &flock, arg->owner);
+        req->f->op.getlk(req, nodeid, &fi, &flock);
     else
         fuse_reply_err(req, ENOSYS);
 }
@@ -823,10 +823,11 @@ static void do_setlk_common(fuse_req_t req, fuse_ino_t nodeid,
 
     memset(&fi, 0, sizeof(fi));
     fi.fh = arg->fh;
+    fi.lock_owner = arg->owner;
 
     convert_fuse_file_lock(&arg->lk, &flock);
     if (req->f->op.setlk)
-        req->f->op.setlk(req, nodeid, &fi, &flock, arg->owner, sleep);
+        req->f->op.setlk(req, nodeid, &fi, &flock, sleep);
     else
         fuse_reply_err(req, ENOSYS);
 }