Merge branch 'fixes-davem' of master.kernel.org:/pub/scm/linux/kernel/git/linville...
[powerpc.git] / fs / fuse / dir.c
index 8c5d156..3763757 100644 (file)
@@ -116,13 +116,19 @@ static void fuse_lookup_init(struct fuse_req *req, struct inode *dir,
                             struct dentry *entry,
                             struct fuse_entry_out *outarg)
 {
+       struct fuse_conn *fc = get_fuse_conn(dir);
+
+       memset(outarg, 0, sizeof(struct fuse_entry_out));
        req->in.h.opcode = FUSE_LOOKUP;
        req->in.h.nodeid = get_node_id(dir);
        req->in.numargs = 1;
        req->in.args[0].size = entry->d_name.len + 1;
        req->in.args[0].value = entry->d_name.name;
        req->out.numargs = 1;
-       req->out.args[0].size = sizeof(struct fuse_entry_out);
+       if (fc->minor < 9)
+               req->out.args[0].size = FUSE_COMPAT_ENTRY_OUT_SIZE;
+       else
+               req->out.args[0].size = sizeof(struct fuse_entry_out);
        req->out.args[0].value = outarg;
 }
 
@@ -356,6 +362,7 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry, int mode,
 
        flags &= ~O_NOCTTY;
        memset(&inarg, 0, sizeof(inarg));
+       memset(&outentry, 0, sizeof(outentry));
        inarg.flags = flags;
        inarg.mode = mode;
        req->in.h.opcode = FUSE_CREATE;
@@ -366,7 +373,10 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry, int mode,
        req->in.args[1].size = entry->d_name.len + 1;
        req->in.args[1].value = entry->d_name.name;
        req->out.numargs = 2;
-       req->out.args[0].size = sizeof(outentry);
+       if (fc->minor < 9)
+               req->out.args[0].size = FUSE_COMPAT_ENTRY_OUT_SIZE;
+       else
+               req->out.args[0].size = sizeof(outentry);
        req->out.args[0].value = &outentry;
        req->out.args[1].size = sizeof(outopen);
        req->out.args[1].value = &outopen;
@@ -431,9 +441,13 @@ static int create_new_entry(struct fuse_conn *fc, struct fuse_req *req,
                return PTR_ERR(forget_req);
        }
 
+       memset(&outarg, 0, sizeof(outarg));
        req->in.h.nodeid = get_node_id(dir);
        req->out.numargs = 1;
-       req->out.args[0].size = sizeof(outarg);
+       if (fc->minor < 9)
+               req->out.args[0].size = FUSE_COMPAT_ENTRY_OUT_SIZE;
+       else
+               req->out.args[0].size = sizeof(outarg);
        req->out.args[0].value = &outarg;
        request_send(fc, req);
        err = req->out.h.error;
@@ -724,6 +738,7 @@ static int fuse_do_getattr(struct inode *inode, struct kstat *stat,
        spin_unlock(&fc->lock);
 
        memset(&inarg, 0, sizeof(inarg));
+       memset(&outarg, 0, sizeof(outarg));
        /* Directories have separate file-handle space */
        if (file && S_ISREG(inode->i_mode)) {
                struct fuse_file *ff = file->private_data;
@@ -737,7 +752,10 @@ static int fuse_do_getattr(struct inode *inode, struct kstat *stat,
        req->in.args[0].size = sizeof(inarg);
        req->in.args[0].value = &inarg;
        req->out.numargs = 1;
-       req->out.args[0].size = sizeof(outarg);
+       if (fc->minor < 9)
+               req->out.args[0].size = FUSE_COMPAT_ATTR_OUT_SIZE;
+       else
+               req->out.args[0].size = sizeof(outarg);
        req->out.args[0].value = &outarg;
        request_send(fc, req);
        err = req->out.h.error;
@@ -1014,6 +1032,20 @@ static int fuse_dir_fsync(struct file *file, struct dentry *de, int datasync)
        return file ? fuse_fsync_common(file, de, datasync, 1) : 0;
 }
 
+static bool update_mtime(unsigned ivalid)
+{
+       /* Always update if mtime is explicitly set  */
+       if (ivalid & ATTR_MTIME_SET)
+               return true;
+
+       /* If it's an open(O_TRUNC) or an ftruncate(), don't update */
+       if ((ivalid & ATTR_SIZE) && (ivalid & (ATTR_OPEN | ATTR_FILE)))
+               return false;
+
+       /* In all other cases update */
+       return true;
+}
+
 static void iattr_to_fattr(struct iattr *iattr, struct fuse_setattr_in *arg)
 {
        unsigned ivalid = iattr->ia_valid;
@@ -1026,16 +1058,19 @@ static void iattr_to_fattr(struct iattr *iattr, struct fuse_setattr_in *arg)
                arg->valid |= FATTR_GID,    arg->gid = iattr->ia_gid;
        if (ivalid & ATTR_SIZE)
                arg->valid |= FATTR_SIZE,   arg->size = iattr->ia_size;
-       /* You can only _set_ these together (they may change by themselves) */
-       if ((ivalid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME)) {
-               arg->valid |= FATTR_ATIME | FATTR_MTIME;
+       if (ivalid & ATTR_ATIME) {
+               arg->valid |= FATTR_ATIME;
                arg->atime = iattr->ia_atime.tv_sec;
-               arg->mtime = iattr->ia_mtime.tv_sec;
+               arg->atimensec = iattr->ia_atime.tv_nsec;
+               if (!(ivalid & ATTR_ATIME_SET))
+                       arg->valid |= FATTR_ATIME_NOW;
        }
-       if (ivalid & ATTR_FILE) {
-               struct fuse_file *ff = iattr->ia_file->private_data;
-               arg->valid |= FATTR_FH;
-               arg->fh = ff->fh;
+       if ((ivalid & ATTR_MTIME) && update_mtime(ivalid)) {
+               arg->valid |= FATTR_MTIME;
+               arg->mtime = iattr->ia_mtime.tv_sec;
+               arg->mtimensec = iattr->ia_mtime.tv_nsec;
+               if (!(ivalid & ATTR_MTIME_SET))
+                       arg->valid |= FATTR_MTIME_NOW;
        }
 }
 
@@ -1047,7 +1082,8 @@ static void iattr_to_fattr(struct iattr *iattr, struct fuse_setattr_in *arg)
  * vmtruncate() doesn't allow for this case, so do the rlimit checking
  * and the actual truncation by hand.
  */
-static int fuse_setattr(struct dentry *entry, struct iattr *attr)
+static int fuse_do_setattr(struct dentry *entry, struct iattr *attr,
+                          struct file *file)
 {
        struct inode *inode = entry->d_inode;
        struct fuse_conn *fc = get_fuse_conn(inode);
@@ -1065,6 +1101,9 @@ static int fuse_setattr(struct dentry *entry, struct iattr *attr)
                        return err;
        }
 
+       if ((attr->ia_valid & ATTR_OPEN) && fc->atomic_o_trunc)
+               return 0;
+
        if (attr->ia_valid & ATTR_SIZE) {
                unsigned long limit;
                if (IS_SWAPFILE(inode))
@@ -1081,14 +1120,28 @@ static int fuse_setattr(struct dentry *entry, struct iattr *attr)
                return PTR_ERR(req);
 
        memset(&inarg, 0, sizeof(inarg));
+       memset(&outarg, 0, sizeof(outarg));
        iattr_to_fattr(attr, &inarg);
+       if (file) {
+               struct fuse_file *ff = file->private_data;
+               inarg.valid |= FATTR_FH;
+               inarg.fh = ff->fh;
+       }
+       if (attr->ia_valid & ATTR_SIZE) {
+               /* For mandatory locking in truncate */
+               inarg.valid |= FATTR_LOCKOWNER;
+               inarg.lock_owner = fuse_lock_owner_id(fc, current->files);
+       }
        req->in.h.opcode = FUSE_SETATTR;
        req->in.h.nodeid = get_node_id(inode);
        req->in.numargs = 1;
        req->in.args[0].size = sizeof(inarg);
        req->in.args[0].value = &inarg;
        req->out.numargs = 1;
-       req->out.args[0].size = sizeof(outarg);
+       if (fc->minor < 9)
+               req->out.args[0].size = FUSE_COMPAT_ATTR_OUT_SIZE;
+       else
+               req->out.args[0].size = sizeof(outarg);
        req->out.args[0].value = &outarg;
        request_send(fc, req);
        err = req->out.h.error;
@@ -1108,6 +1161,14 @@ static int fuse_setattr(struct dentry *entry, struct iattr *attr)
        return 0;
 }
 
+static int fuse_setattr(struct dentry *entry, struct iattr *attr)
+{
+       if (attr->ia_valid & ATTR_FILE)
+               return fuse_do_setattr(entry, attr, attr->ia_file);
+       else
+               return fuse_do_setattr(entry, attr, NULL);
+}
+
 static int fuse_getattr(struct vfsmount *mnt, struct dentry *entry,
                        struct kstat *stat)
 {