cifs: fix writeback race with file that is growing
[linux-3.10.git] / fs / cifs / smb2inode.c
index a6952ba..7064824 100644 (file)
@@ -47,6 +47,7 @@ smb2_open_op_close(const unsigned int xid, struct cifs_tcon *tcon,
        int rc, tmprc = 0;
        u64 persistent_fid, volatile_fid;
        __le16 *utf16_path;
+       __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
 
        utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
        if (!utf16_path)
@@ -54,7 +55,7 @@ smb2_open_op_close(const unsigned int xid, struct cifs_tcon *tcon,
 
        rc = SMB2_open(xid, tcon, utf16_path, &persistent_fid, &volatile_fid,
                       desired_access, create_disposition, file_attributes,
-                      create_options, NULL);
+                      create_options, &oplock, NULL);
        if (rc) {
                kfree(utf16_path);
                return rc;
@@ -78,6 +79,18 @@ smb2_open_op_close(const unsigned int xid, struct cifs_tcon *tcon,
                tmprc = SMB2_rename(xid, tcon, persistent_fid, volatile_fid,
                                    (__le16 *)data);
                break;
+       case SMB2_OP_HARDLINK:
+               tmprc = SMB2_set_hardlink(xid, tcon, persistent_fid,
+                                         volatile_fid, (__le16 *)data);
+               break;
+       case SMB2_OP_SET_EOF:
+               tmprc = SMB2_set_eof(xid, tcon, persistent_fid, volatile_fid,
+                                    current->tgid, (__le64 *)data);
+               break;
+       case SMB2_OP_SET_INFO:
+               tmprc = SMB2_set_info(xid, tcon, persistent_fid, volatile_fid,
+                                     (FILE_BASIC_INFO *)data);
+               break;
        default:
                cERROR(1, "Invalid command");
                break;
@@ -175,10 +188,10 @@ smb2_unlink(const unsigned int xid, struct cifs_tcon *tcon, const char *name,
                                  SMB2_OP_DELETE);
 }
 
-int
-smb2_rename_path(const unsigned int xid, struct cifs_tcon *tcon,
-                const char *from_name, const char *to_name,
-                struct cifs_sb_info *cifs_sb)
+static int
+smb2_set_path_attr(const unsigned int xid, struct cifs_tcon *tcon,
+                  const char *from_name, const char *to_name,
+                  struct cifs_sb_info *cifs_sb, __u32 access, int command)
 {
        __le16 *smb2_to_name = NULL;
        int rc;
@@ -189,9 +202,56 @@ smb2_rename_path(const unsigned int xid, struct cifs_tcon *tcon,
                goto smb2_rename_path;
        }
 
-       rc = smb2_open_op_close(xid, tcon, cifs_sb, from_name, DELETE,
-                               FILE_OPEN, 0, 0, smb2_to_name, SMB2_OP_RENAME);
+       rc = smb2_open_op_close(xid, tcon, cifs_sb, from_name, access,
+                               FILE_OPEN, 0, 0, smb2_to_name, command);
 smb2_rename_path:
        kfree(smb2_to_name);
        return rc;
 }
+
+int
+smb2_rename_path(const unsigned int xid, struct cifs_tcon *tcon,
+                const char *from_name, const char *to_name,
+                struct cifs_sb_info *cifs_sb)
+{
+       return smb2_set_path_attr(xid, tcon, from_name, to_name, cifs_sb,
+                                 DELETE, SMB2_OP_RENAME);
+}
+
+int
+smb2_create_hardlink(const unsigned int xid, struct cifs_tcon *tcon,
+                    const char *from_name, const char *to_name,
+                    struct cifs_sb_info *cifs_sb)
+{
+       return smb2_set_path_attr(xid, tcon, from_name, to_name, cifs_sb,
+                                 FILE_READ_ATTRIBUTES, SMB2_OP_HARDLINK);
+}
+
+int
+smb2_set_path_size(const unsigned int xid, struct cifs_tcon *tcon,
+                  const char *full_path, __u64 size,
+                  struct cifs_sb_info *cifs_sb, bool set_alloc)
+{
+       __le64 eof = cpu_to_le64(size);
+       return smb2_open_op_close(xid, tcon, cifs_sb, full_path,
+                                 FILE_WRITE_DATA, FILE_OPEN, 0, 0, &eof,
+                                 SMB2_OP_SET_EOF);
+}
+
+int
+smb2_set_file_info(struct inode *inode, const char *full_path,
+                  FILE_BASIC_INFO *buf, const unsigned int xid)
+{
+       struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
+       struct tcon_link *tlink;
+       int rc;
+
+       tlink = cifs_sb_tlink(cifs_sb);
+       if (IS_ERR(tlink))
+               return PTR_ERR(tlink);
+       rc = smb2_open_op_close(xid, tlink_tcon(tlink), cifs_sb, full_path,
+                               FILE_WRITE_ATTRIBUTES, FILE_OPEN, 0, 0, buf,
+                               SMB2_OP_SET_INFO);
+       cifs_put_tlink(tlink);
+       return rc;
+}