Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/cifs/file.c |
| 3 | * |
| 4 | * vfs operations that deal with files |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 5 | * |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 6 | * Copyright (C) International Business Machines Corp., 2002,2010 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * Author(s): Steve French (sfrench@us.ibm.com) |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 8 | * Jeremy Allison (jra@samba.org) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * |
| 10 | * This library is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU Lesser General Public License as published |
| 12 | * by the Free Software Foundation; either version 2.1 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This library is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 18 | * the GNU Lesser General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU Lesser General Public License |
| 21 | * along with this library; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 | */ |
| 24 | #include <linux/fs.h> |
Steve French | 37c0eb4 | 2005-10-05 14:50:29 -0700 | [diff] [blame] | 25 | #include <linux/backing-dev.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/stat.h> |
| 27 | #include <linux/fcntl.h> |
| 28 | #include <linux/pagemap.h> |
| 29 | #include <linux/pagevec.h> |
Steve French | 37c0eb4 | 2005-10-05 14:50:29 -0700 | [diff] [blame] | 30 | #include <linux/writeback.h> |
Andrew Morton | 6f88cc2 | 2006-12-10 02:19:44 -0800 | [diff] [blame] | 31 | #include <linux/task_io_accounting_ops.h> |
Steve French | 23e7dd7 | 2005-10-20 13:44:56 -0700 | [diff] [blame] | 32 | #include <linux/delay.h> |
Jeff Layton | 3bc303c | 2009-09-21 06:47:50 -0400 | [diff] [blame] | 33 | #include <linux/mount.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 34 | #include <linux/slab.h> |
Jeff Layton | 690c5e3 | 2011-10-19 15:30:16 -0400 | [diff] [blame] | 35 | #include <linux/swap.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <asm/div64.h> |
| 37 | #include "cifsfs.h" |
| 38 | #include "cifspdu.h" |
| 39 | #include "cifsglob.h" |
| 40 | #include "cifsproto.h" |
| 41 | #include "cifs_unicode.h" |
| 42 | #include "cifs_debug.h" |
| 43 | #include "cifs_fs_sb.h" |
Suresh Jayaraman | 9451a9a | 2010-07-05 18:12:45 +0530 | [diff] [blame] | 44 | #include "fscache.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | static inline int cifs_convert_flags(unsigned int flags) |
| 47 | { |
| 48 | if ((flags & O_ACCMODE) == O_RDONLY) |
| 49 | return GENERIC_READ; |
| 50 | else if ((flags & O_ACCMODE) == O_WRONLY) |
| 51 | return GENERIC_WRITE; |
| 52 | else if ((flags & O_ACCMODE) == O_RDWR) { |
| 53 | /* GENERIC_ALL is too much permission to request |
| 54 | can cause unnecessary access denied on create */ |
| 55 | /* return GENERIC_ALL; */ |
| 56 | return (GENERIC_READ | GENERIC_WRITE); |
| 57 | } |
| 58 | |
Jeff Layton | e10f7b5 | 2008-05-14 10:21:33 -0700 | [diff] [blame] | 59 | return (READ_CONTROL | FILE_WRITE_ATTRIBUTES | FILE_READ_ATTRIBUTES | |
| 60 | FILE_WRITE_EA | FILE_APPEND_DATA | FILE_WRITE_DATA | |
| 61 | FILE_READ_DATA); |
Steve French | 7fc8f4e | 2009-02-23 20:43:11 +0000 | [diff] [blame] | 62 | } |
Jeff Layton | e10f7b5 | 2008-05-14 10:21:33 -0700 | [diff] [blame] | 63 | |
Jeff Layton | 608712f | 2010-10-15 15:33:56 -0400 | [diff] [blame] | 64 | static u32 cifs_posix_convert_flags(unsigned int flags) |
Steve French | 7fc8f4e | 2009-02-23 20:43:11 +0000 | [diff] [blame] | 65 | { |
Jeff Layton | 608712f | 2010-10-15 15:33:56 -0400 | [diff] [blame] | 66 | u32 posix_flags = 0; |
Jeff Layton | e10f7b5 | 2008-05-14 10:21:33 -0700 | [diff] [blame] | 67 | |
Steve French | 7fc8f4e | 2009-02-23 20:43:11 +0000 | [diff] [blame] | 68 | if ((flags & O_ACCMODE) == O_RDONLY) |
Jeff Layton | 608712f | 2010-10-15 15:33:56 -0400 | [diff] [blame] | 69 | posix_flags = SMB_O_RDONLY; |
Steve French | 7fc8f4e | 2009-02-23 20:43:11 +0000 | [diff] [blame] | 70 | else if ((flags & O_ACCMODE) == O_WRONLY) |
Jeff Layton | 608712f | 2010-10-15 15:33:56 -0400 | [diff] [blame] | 71 | posix_flags = SMB_O_WRONLY; |
| 72 | else if ((flags & O_ACCMODE) == O_RDWR) |
| 73 | posix_flags = SMB_O_RDWR; |
| 74 | |
| 75 | if (flags & O_CREAT) |
| 76 | posix_flags |= SMB_O_CREAT; |
| 77 | if (flags & O_EXCL) |
| 78 | posix_flags |= SMB_O_EXCL; |
| 79 | if (flags & O_TRUNC) |
| 80 | posix_flags |= SMB_O_TRUNC; |
| 81 | /* be safe and imply O_SYNC for O_DSYNC */ |
Christoph Hellwig | 6b2f3d1 | 2009-10-27 11:05:28 +0100 | [diff] [blame] | 82 | if (flags & O_DSYNC) |
Jeff Layton | 608712f | 2010-10-15 15:33:56 -0400 | [diff] [blame] | 83 | posix_flags |= SMB_O_SYNC; |
Steve French | 7fc8f4e | 2009-02-23 20:43:11 +0000 | [diff] [blame] | 84 | if (flags & O_DIRECTORY) |
Jeff Layton | 608712f | 2010-10-15 15:33:56 -0400 | [diff] [blame] | 85 | posix_flags |= SMB_O_DIRECTORY; |
Steve French | 7fc8f4e | 2009-02-23 20:43:11 +0000 | [diff] [blame] | 86 | if (flags & O_NOFOLLOW) |
Jeff Layton | 608712f | 2010-10-15 15:33:56 -0400 | [diff] [blame] | 87 | posix_flags |= SMB_O_NOFOLLOW; |
Steve French | 7fc8f4e | 2009-02-23 20:43:11 +0000 | [diff] [blame] | 88 | if (flags & O_DIRECT) |
Jeff Layton | 608712f | 2010-10-15 15:33:56 -0400 | [diff] [blame] | 89 | posix_flags |= SMB_O_DIRECT; |
Steve French | 7fc8f4e | 2009-02-23 20:43:11 +0000 | [diff] [blame] | 90 | |
| 91 | return posix_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | static inline int cifs_get_disposition(unsigned int flags) |
| 95 | { |
| 96 | if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) |
| 97 | return FILE_CREATE; |
| 98 | else if ((flags & (O_CREAT | O_TRUNC)) == (O_CREAT | O_TRUNC)) |
| 99 | return FILE_OVERWRITE_IF; |
| 100 | else if ((flags & O_CREAT) == O_CREAT) |
| 101 | return FILE_OPEN_IF; |
Steve French | 55aa2e0 | 2006-05-30 18:09:31 +0000 | [diff] [blame] | 102 | else if ((flags & O_TRUNC) == O_TRUNC) |
| 103 | return FILE_OVERWRITE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | else |
| 105 | return FILE_OPEN; |
| 106 | } |
| 107 | |
Jeff Layton | 608712f | 2010-10-15 15:33:56 -0400 | [diff] [blame] | 108 | int cifs_posix_open(char *full_path, struct inode **pinode, |
| 109 | struct super_block *sb, int mode, unsigned int f_flags, |
| 110 | __u32 *poplock, __u16 *pnetfid, int xid) |
| 111 | { |
| 112 | int rc; |
| 113 | FILE_UNIX_BASIC_INFO *presp_data; |
| 114 | __u32 posix_flags = 0; |
| 115 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); |
| 116 | struct cifs_fattr fattr; |
| 117 | struct tcon_link *tlink; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 118 | struct cifs_tcon *tcon; |
Jeff Layton | 608712f | 2010-10-15 15:33:56 -0400 | [diff] [blame] | 119 | |
| 120 | cFYI(1, "posix open %s", full_path); |
| 121 | |
| 122 | presp_data = kzalloc(sizeof(FILE_UNIX_BASIC_INFO), GFP_KERNEL); |
| 123 | if (presp_data == NULL) |
| 124 | return -ENOMEM; |
| 125 | |
| 126 | tlink = cifs_sb_tlink(cifs_sb); |
| 127 | if (IS_ERR(tlink)) { |
| 128 | rc = PTR_ERR(tlink); |
| 129 | goto posix_open_ret; |
| 130 | } |
| 131 | |
| 132 | tcon = tlink_tcon(tlink); |
| 133 | mode &= ~current_umask(); |
| 134 | |
| 135 | posix_flags = cifs_posix_convert_flags(f_flags); |
| 136 | rc = CIFSPOSIXCreate(xid, tcon, posix_flags, mode, pnetfid, presp_data, |
| 137 | poplock, full_path, cifs_sb->local_nls, |
| 138 | cifs_sb->mnt_cifs_flags & |
| 139 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
| 140 | cifs_put_tlink(tlink); |
| 141 | |
| 142 | if (rc) |
| 143 | goto posix_open_ret; |
| 144 | |
| 145 | if (presp_data->Type == cpu_to_le32(-1)) |
| 146 | goto posix_open_ret; /* open ok, caller does qpathinfo */ |
| 147 | |
| 148 | if (!pinode) |
| 149 | goto posix_open_ret; /* caller does not need info */ |
| 150 | |
| 151 | cifs_unix_basic_to_fattr(&fattr, presp_data, cifs_sb); |
| 152 | |
| 153 | /* get new inode and set it up */ |
| 154 | if (*pinode == NULL) { |
| 155 | cifs_fill_uniqueid(sb, &fattr); |
| 156 | *pinode = cifs_iget(sb, &fattr); |
| 157 | if (!*pinode) { |
| 158 | rc = -ENOMEM; |
| 159 | goto posix_open_ret; |
| 160 | } |
| 161 | } else { |
| 162 | cifs_fattr_to_inode(*pinode, &fattr); |
| 163 | } |
| 164 | |
| 165 | posix_open_ret: |
| 166 | kfree(presp_data); |
| 167 | return rc; |
| 168 | } |
| 169 | |
Pavel Shilovsky | eeb910a | 2010-11-25 15:12:39 +0300 | [diff] [blame] | 170 | static int |
| 171 | cifs_nt_open(char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb, |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 172 | struct cifs_tcon *tcon, unsigned int f_flags, __u32 *poplock, |
Pavel Shilovsky | eeb910a | 2010-11-25 15:12:39 +0300 | [diff] [blame] | 173 | __u16 *pnetfid, int xid) |
| 174 | { |
| 175 | int rc; |
| 176 | int desiredAccess; |
| 177 | int disposition; |
Shirish Pargaonkar | 3d3ea8e | 2011-09-26 09:56:44 -0500 | [diff] [blame] | 178 | int create_options = CREATE_NOT_DIR; |
Pavel Shilovsky | eeb910a | 2010-11-25 15:12:39 +0300 | [diff] [blame] | 179 | FILE_ALL_INFO *buf; |
| 180 | |
| 181 | desiredAccess = cifs_convert_flags(f_flags); |
| 182 | |
| 183 | /********************************************************************* |
| 184 | * open flag mapping table: |
| 185 | * |
| 186 | * POSIX Flag CIFS Disposition |
| 187 | * ---------- ---------------- |
| 188 | * O_CREAT FILE_OPEN_IF |
| 189 | * O_CREAT | O_EXCL FILE_CREATE |
| 190 | * O_CREAT | O_TRUNC FILE_OVERWRITE_IF |
| 191 | * O_TRUNC FILE_OVERWRITE |
| 192 | * none of the above FILE_OPEN |
| 193 | * |
| 194 | * Note that there is not a direct match between disposition |
| 195 | * FILE_SUPERSEDE (ie create whether or not file exists although |
| 196 | * O_CREAT | O_TRUNC is similar but truncates the existing |
| 197 | * file rather than creating a new file as FILE_SUPERSEDE does |
| 198 | * (which uses the attributes / metadata passed in on open call) |
| 199 | *? |
| 200 | *? O_SYNC is a reasonable match to CIFS writethrough flag |
| 201 | *? and the read write flags match reasonably. O_LARGEFILE |
| 202 | *? is irrelevant because largefile support is always used |
| 203 | *? by this client. Flags O_APPEND, O_DIRECT, O_DIRECTORY, |
| 204 | * O_FASYNC, O_NOFOLLOW, O_NONBLOCK need further investigation |
| 205 | *********************************************************************/ |
| 206 | |
| 207 | disposition = cifs_get_disposition(f_flags); |
| 208 | |
| 209 | /* BB pass O_SYNC flag through on file attributes .. BB */ |
| 210 | |
| 211 | buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL); |
| 212 | if (!buf) |
| 213 | return -ENOMEM; |
| 214 | |
Shirish Pargaonkar | 3d3ea8e | 2011-09-26 09:56:44 -0500 | [diff] [blame] | 215 | if (backup_cred(cifs_sb)) |
| 216 | create_options |= CREATE_OPEN_BACKUP_INTENT; |
| 217 | |
Pavel Shilovsky | eeb910a | 2010-11-25 15:12:39 +0300 | [diff] [blame] | 218 | if (tcon->ses->capabilities & CAP_NT_SMBS) |
| 219 | rc = CIFSSMBOpen(xid, tcon, full_path, disposition, |
Shirish Pargaonkar | 3d3ea8e | 2011-09-26 09:56:44 -0500 | [diff] [blame] | 220 | desiredAccess, create_options, pnetfid, poplock, buf, |
Pavel Shilovsky | eeb910a | 2010-11-25 15:12:39 +0300 | [diff] [blame] | 221 | cifs_sb->local_nls, cifs_sb->mnt_cifs_flags |
| 222 | & CIFS_MOUNT_MAP_SPECIAL_CHR); |
| 223 | else |
| 224 | rc = SMBLegacyOpen(xid, tcon, full_path, disposition, |
| 225 | desiredAccess, CREATE_NOT_DIR, pnetfid, poplock, buf, |
| 226 | cifs_sb->local_nls, cifs_sb->mnt_cifs_flags |
| 227 | & CIFS_MOUNT_MAP_SPECIAL_CHR); |
| 228 | |
| 229 | if (rc) |
| 230 | goto out; |
| 231 | |
| 232 | if (tcon->unix_ext) |
| 233 | rc = cifs_get_inode_info_unix(&inode, full_path, inode->i_sb, |
| 234 | xid); |
| 235 | else |
| 236 | rc = cifs_get_inode_info(&inode, full_path, buf, inode->i_sb, |
| 237 | xid, pnetfid); |
| 238 | |
| 239 | out: |
| 240 | kfree(buf); |
| 241 | return rc; |
| 242 | } |
| 243 | |
Jeff Layton | 15ecb43 | 2010-10-15 15:34:02 -0400 | [diff] [blame] | 244 | struct cifsFileInfo * |
| 245 | cifs_new_fileinfo(__u16 fileHandle, struct file *file, |
| 246 | struct tcon_link *tlink, __u32 oplock) |
| 247 | { |
| 248 | struct dentry *dentry = file->f_path.dentry; |
| 249 | struct inode *inode = dentry->d_inode; |
| 250 | struct cifsInodeInfo *pCifsInode = CIFS_I(inode); |
| 251 | struct cifsFileInfo *pCifsFile; |
| 252 | |
| 253 | pCifsFile = kzalloc(sizeof(struct cifsFileInfo), GFP_KERNEL); |
| 254 | if (pCifsFile == NULL) |
| 255 | return pCifsFile; |
| 256 | |
Jeff Layton | 5f6dbc9 | 2010-10-15 15:34:06 -0400 | [diff] [blame] | 257 | pCifsFile->count = 1; |
Jeff Layton | 15ecb43 | 2010-10-15 15:34:02 -0400 | [diff] [blame] | 258 | pCifsFile->netfid = fileHandle; |
| 259 | pCifsFile->pid = current->tgid; |
| 260 | pCifsFile->uid = current_fsuid(); |
| 261 | pCifsFile->dentry = dget(dentry); |
| 262 | pCifsFile->f_flags = file->f_flags; |
| 263 | pCifsFile->invalidHandle = false; |
Jeff Layton | 15ecb43 | 2010-10-15 15:34:02 -0400 | [diff] [blame] | 264 | pCifsFile->tlink = cifs_get_tlink(tlink); |
| 265 | mutex_init(&pCifsFile->fh_mutex); |
Jeff Layton | 15ecb43 | 2010-10-15 15:34:02 -0400 | [diff] [blame] | 266 | INIT_WORK(&pCifsFile->oplock_break, cifs_oplock_break); |
| 267 | |
Jeff Layton | 4477288 | 2010-10-15 15:34:03 -0400 | [diff] [blame] | 268 | spin_lock(&cifs_file_list_lock); |
Jeff Layton | 15ecb43 | 2010-10-15 15:34:02 -0400 | [diff] [blame] | 269 | list_add(&pCifsFile->tlist, &(tlink_tcon(tlink)->openFileList)); |
| 270 | /* if readable file instance put first in list*/ |
| 271 | if (file->f_mode & FMODE_READ) |
| 272 | list_add(&pCifsFile->flist, &pCifsInode->openFileList); |
| 273 | else |
| 274 | list_add_tail(&pCifsFile->flist, &pCifsInode->openFileList); |
Jeff Layton | 4477288 | 2010-10-15 15:34:03 -0400 | [diff] [blame] | 275 | spin_unlock(&cifs_file_list_lock); |
Jeff Layton | 15ecb43 | 2010-10-15 15:34:02 -0400 | [diff] [blame] | 276 | |
Pavel Shilovsky | c672362 | 2010-11-03 10:58:57 +0300 | [diff] [blame] | 277 | cifs_set_oplock_level(pCifsInode, oplock); |
Jeff Layton | 15ecb43 | 2010-10-15 15:34:02 -0400 | [diff] [blame] | 278 | |
| 279 | file->private_data = pCifsFile; |
| 280 | return pCifsFile; |
| 281 | } |
| 282 | |
Steve French | cdff08e | 2010-10-21 22:46:14 +0000 | [diff] [blame] | 283 | /* |
| 284 | * Release a reference on the file private data. This may involve closing |
Jeff Layton | 5f6dbc9 | 2010-10-15 15:34:06 -0400 | [diff] [blame] | 285 | * the filehandle out on the server. Must be called without holding |
| 286 | * cifs_file_list_lock. |
Steve French | cdff08e | 2010-10-21 22:46:14 +0000 | [diff] [blame] | 287 | */ |
Jeff Layton | b33879a | 2010-10-15 15:34:04 -0400 | [diff] [blame] | 288 | void cifsFileInfo_put(struct cifsFileInfo *cifs_file) |
| 289 | { |
Pavel Shilovsky | e66673e | 2010-11-02 12:00:42 +0300 | [diff] [blame] | 290 | struct inode *inode = cifs_file->dentry->d_inode; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 291 | struct cifs_tcon *tcon = tlink_tcon(cifs_file->tlink); |
Pavel Shilovsky | e66673e | 2010-11-02 12:00:42 +0300 | [diff] [blame] | 292 | struct cifsInodeInfo *cifsi = CIFS_I(inode); |
Pavel Shilovsky | 4f8ba8a | 2010-11-21 22:36:12 +0300 | [diff] [blame] | 293 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
Steve French | cdff08e | 2010-10-21 22:46:14 +0000 | [diff] [blame] | 294 | struct cifsLockInfo *li, *tmp; |
| 295 | |
| 296 | spin_lock(&cifs_file_list_lock); |
Jeff Layton | 5f6dbc9 | 2010-10-15 15:34:06 -0400 | [diff] [blame] | 297 | if (--cifs_file->count > 0) { |
Steve French | cdff08e | 2010-10-21 22:46:14 +0000 | [diff] [blame] | 298 | spin_unlock(&cifs_file_list_lock); |
| 299 | return; |
Jeff Layton | b33879a | 2010-10-15 15:34:04 -0400 | [diff] [blame] | 300 | } |
Steve French | cdff08e | 2010-10-21 22:46:14 +0000 | [diff] [blame] | 301 | |
| 302 | /* remove it from the lists */ |
| 303 | list_del(&cifs_file->flist); |
| 304 | list_del(&cifs_file->tlist); |
| 305 | |
| 306 | if (list_empty(&cifsi->openFileList)) { |
| 307 | cFYI(1, "closing last open instance for inode %p", |
| 308 | cifs_file->dentry->d_inode); |
Pavel Shilovsky | 4f8ba8a | 2010-11-21 22:36:12 +0300 | [diff] [blame] | 309 | |
| 310 | /* in strict cache mode we need invalidate mapping on the last |
| 311 | close because it may cause a error when we open this file |
| 312 | again and get at least level II oplock */ |
| 313 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) |
| 314 | CIFS_I(inode)->invalid_mapping = true; |
| 315 | |
Pavel Shilovsky | c672362 | 2010-11-03 10:58:57 +0300 | [diff] [blame] | 316 | cifs_set_oplock_level(cifsi, 0); |
Steve French | cdff08e | 2010-10-21 22:46:14 +0000 | [diff] [blame] | 317 | } |
| 318 | spin_unlock(&cifs_file_list_lock); |
| 319 | |
Jeff Layton | ad63594 | 2011-07-26 12:20:17 -0400 | [diff] [blame] | 320 | cancel_work_sync(&cifs_file->oplock_break); |
| 321 | |
Steve French | cdff08e | 2010-10-21 22:46:14 +0000 | [diff] [blame] | 322 | if (!tcon->need_reconnect && !cifs_file->invalidHandle) { |
| 323 | int xid, rc; |
| 324 | |
| 325 | xid = GetXid(); |
| 326 | rc = CIFSSMBClose(xid, tcon, cifs_file->netfid); |
| 327 | FreeXid(xid); |
| 328 | } |
| 329 | |
| 330 | /* Delete any outstanding lock records. We'll lose them when the file |
| 331 | * is closed anyway. |
| 332 | */ |
Pavel Shilovsky | d59dad2 | 2011-09-22 09:53:59 +0400 | [diff] [blame] | 333 | mutex_lock(&cifsi->lock_mutex); |
| 334 | list_for_each_entry_safe(li, tmp, &cifsi->llist, llist) { |
| 335 | if (li->netfid != cifs_file->netfid) |
| 336 | continue; |
Steve French | cdff08e | 2010-10-21 22:46:14 +0000 | [diff] [blame] | 337 | list_del(&li->llist); |
| 338 | kfree(li); |
| 339 | } |
Pavel Shilovsky | d59dad2 | 2011-09-22 09:53:59 +0400 | [diff] [blame] | 340 | mutex_unlock(&cifsi->lock_mutex); |
Steve French | cdff08e | 2010-10-21 22:46:14 +0000 | [diff] [blame] | 341 | |
| 342 | cifs_put_tlink(cifs_file->tlink); |
| 343 | dput(cifs_file->dentry); |
| 344 | kfree(cifs_file); |
Jeff Layton | b33879a | 2010-10-15 15:34:04 -0400 | [diff] [blame] | 345 | } |
| 346 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | int cifs_open(struct inode *inode, struct file *file) |
| 348 | { |
| 349 | int rc = -EACCES; |
Jeff Layton | 590a3fe | 2009-09-12 11:54:28 -0400 | [diff] [blame] | 350 | int xid; |
| 351 | __u32 oplock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | struct cifs_sb_info *cifs_sb; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 353 | struct cifs_tcon *tcon; |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 354 | struct tcon_link *tlink; |
Jeff Layton | 6ca9f3b | 2010-06-16 13:40:16 -0400 | [diff] [blame] | 355 | struct cifsFileInfo *pCifsFile = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | char *full_path = NULL; |
Pavel Shilovsky | 7e12edd | 2010-11-25 17:20:20 +0300 | [diff] [blame] | 357 | bool posix_open_ok = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | __u16 netfid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | |
| 360 | xid = GetXid(); |
| 361 | |
| 362 | cifs_sb = CIFS_SB(inode->i_sb); |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 363 | tlink = cifs_sb_tlink(cifs_sb); |
| 364 | if (IS_ERR(tlink)) { |
| 365 | FreeXid(xid); |
| 366 | return PTR_ERR(tlink); |
| 367 | } |
| 368 | tcon = tlink_tcon(tlink); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
Josef "Jeff" Sipek | e6a0029 | 2006-12-08 02:36:48 -0800 | [diff] [blame] | 370 | full_path = build_path_from_dentry(file->f_path.dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | if (full_path == NULL) { |
Suresh Jayaraman | 0f3bc09 | 2009-06-25 18:12:34 +0530 | [diff] [blame] | 372 | rc = -ENOMEM; |
Jeff Layton | 232341b | 2010-08-05 13:58:38 -0400 | [diff] [blame] | 373 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | } |
| 375 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 376 | cFYI(1, "inode = 0x%p file flags are 0x%x for %s", |
| 377 | inode, file->f_flags, full_path); |
Steve French | 276a74a | 2009-03-03 18:00:34 +0000 | [diff] [blame] | 378 | |
Steve French | e750473 | 2011-10-12 17:47:03 -0500 | [diff] [blame] | 379 | if (enable_oplocks) |
Steve French | 276a74a | 2009-03-03 18:00:34 +0000 | [diff] [blame] | 380 | oplock = REQ_OPLOCK; |
| 381 | else |
| 382 | oplock = 0; |
| 383 | |
Steve French | 64cc2c6 | 2009-03-04 19:54:08 +0000 | [diff] [blame] | 384 | if (!tcon->broken_posix_open && tcon->unix_ext && |
| 385 | (tcon->ses->capabilities & CAP_UNIX) && |
Steve French | 276a74a | 2009-03-03 18:00:34 +0000 | [diff] [blame] | 386 | (CIFS_UNIX_POSIX_PATH_OPS_CAP & |
| 387 | le64_to_cpu(tcon->fsUnixInfo.Capability))) { |
Steve French | 276a74a | 2009-03-03 18:00:34 +0000 | [diff] [blame] | 388 | /* can not refresh inode info since size could be stale */ |
Jeff Layton | 2422f67 | 2010-06-16 13:40:16 -0400 | [diff] [blame] | 389 | rc = cifs_posix_open(full_path, &inode, inode->i_sb, |
Steve French | fa588e0 | 2010-04-22 19:21:55 +0000 | [diff] [blame] | 390 | cifs_sb->mnt_file_mode /* ignored */, |
Jeff Layton | 608712f | 2010-10-15 15:33:56 -0400 | [diff] [blame] | 391 | file->f_flags, &oplock, &netfid, xid); |
Steve French | 276a74a | 2009-03-03 18:00:34 +0000 | [diff] [blame] | 392 | if (rc == 0) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 393 | cFYI(1, "posix open succeeded"); |
Pavel Shilovsky | 7e12edd | 2010-11-25 17:20:20 +0300 | [diff] [blame] | 394 | posix_open_ok = true; |
Steve French | 64cc2c6 | 2009-03-04 19:54:08 +0000 | [diff] [blame] | 395 | } else if ((rc == -EINVAL) || (rc == -EOPNOTSUPP)) { |
| 396 | if (tcon->ses->serverNOS) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 397 | cERROR(1, "server %s of type %s returned" |
Steve French | 64cc2c6 | 2009-03-04 19:54:08 +0000 | [diff] [blame] | 398 | " unexpected error on SMB posix open" |
| 399 | ", disabling posix open support." |
| 400 | " Check if server update available.", |
| 401 | tcon->ses->serverName, |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 402 | tcon->ses->serverNOS); |
Steve French | 64cc2c6 | 2009-03-04 19:54:08 +0000 | [diff] [blame] | 403 | tcon->broken_posix_open = true; |
Steve French | 276a74a | 2009-03-03 18:00:34 +0000 | [diff] [blame] | 404 | } else if ((rc != -EIO) && (rc != -EREMOTE) && |
| 405 | (rc != -EOPNOTSUPP)) /* path not found or net err */ |
| 406 | goto out; |
Steve French | 64cc2c6 | 2009-03-04 19:54:08 +0000 | [diff] [blame] | 407 | /* else fallthrough to retry open the old way on network i/o |
| 408 | or DFS errors */ |
Steve French | 276a74a | 2009-03-03 18:00:34 +0000 | [diff] [blame] | 409 | } |
| 410 | |
Pavel Shilovsky | 7e12edd | 2010-11-25 17:20:20 +0300 | [diff] [blame] | 411 | if (!posix_open_ok) { |
| 412 | rc = cifs_nt_open(full_path, inode, cifs_sb, tcon, |
| 413 | file->f_flags, &oplock, &netfid, xid); |
| 414 | if (rc) |
| 415 | goto out; |
| 416 | } |
Jeff Layton | 47c78b7 | 2010-06-16 13:40:17 -0400 | [diff] [blame] | 417 | |
Jeff Layton | abfe1ee | 2010-10-15 15:33:58 -0400 | [diff] [blame] | 418 | pCifsFile = cifs_new_fileinfo(netfid, file, tlink, oplock); |
Jeff Layton | 6ca9f3b | 2010-06-16 13:40:16 -0400 | [diff] [blame] | 419 | if (pCifsFile == NULL) { |
Pavel Shilovsky | 7e12edd | 2010-11-25 17:20:20 +0300 | [diff] [blame] | 420 | CIFSSMBClose(xid, tcon, netfid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | rc = -ENOMEM; |
| 422 | goto out; |
| 423 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | |
Suresh Jayaraman | 9451a9a | 2010-07-05 18:12:45 +0530 | [diff] [blame] | 425 | cifs_fscache_set_inode_cookie(inode, file); |
| 426 | |
Pavel Shilovsky | 7e12edd | 2010-11-25 17:20:20 +0300 | [diff] [blame] | 427 | if ((oplock & CIFS_CREATE_ACTION) && !posix_open_ok && tcon->unix_ext) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | /* time to set mode which we can not set earlier due to |
| 429 | problems creating new read-only files */ |
Pavel Shilovsky | 7e12edd | 2010-11-25 17:20:20 +0300 | [diff] [blame] | 430 | struct cifs_unix_set_info_args args = { |
| 431 | .mode = inode->i_mode, |
| 432 | .uid = NO_CHANGE_64, |
| 433 | .gid = NO_CHANGE_64, |
| 434 | .ctime = NO_CHANGE_64, |
| 435 | .atime = NO_CHANGE_64, |
| 436 | .mtime = NO_CHANGE_64, |
| 437 | .device = 0, |
| 438 | }; |
Jeff Layton | d44a9fe | 2011-01-07 11:30:29 -0500 | [diff] [blame] | 439 | CIFSSMBUnixSetFileInfo(xid, tcon, &args, netfid, |
| 440 | pCifsFile->pid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | kfree(full_path); |
| 445 | FreeXid(xid); |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 446 | cifs_put_tlink(tlink); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | return rc; |
| 448 | } |
| 449 | |
Adrian Bunk | 0418726 | 2006-06-30 18:23:04 +0200 | [diff] [blame] | 450 | /* Try to reacquire byte range locks that were released when session */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | /* to server was lost */ |
| 452 | static int cifs_relock_file(struct cifsFileInfo *cifsFile) |
| 453 | { |
| 454 | int rc = 0; |
| 455 | |
| 456 | /* BB list all locks open on this file and relock */ |
| 457 | |
| 458 | return rc; |
| 459 | } |
| 460 | |
Jeff Layton | 1588617 | 2010-10-15 15:33:59 -0400 | [diff] [blame] | 461 | static int cifs_reopen_file(struct cifsFileInfo *pCifsFile, bool can_flush) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | { |
| 463 | int rc = -EACCES; |
Jeff Layton | 590a3fe | 2009-09-12 11:54:28 -0400 | [diff] [blame] | 464 | int xid; |
| 465 | __u32 oplock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | struct cifs_sb_info *cifs_sb; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 467 | struct cifs_tcon *tcon; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | struct cifsInodeInfo *pCifsInode; |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 469 | struct inode *inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | char *full_path = NULL; |
| 471 | int desiredAccess; |
| 472 | int disposition = FILE_OPEN; |
Shirish Pargaonkar | 3d3ea8e | 2011-09-26 09:56:44 -0500 | [diff] [blame] | 473 | int create_options = CREATE_NOT_DIR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | __u16 netfid; |
| 475 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | xid = GetXid(); |
Jeff Layton | f0a71eb | 2009-06-27 07:04:55 -0400 | [diff] [blame] | 477 | mutex_lock(&pCifsFile->fh_mutex); |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 478 | if (!pCifsFile->invalidHandle) { |
Jeff Layton | f0a71eb | 2009-06-27 07:04:55 -0400 | [diff] [blame] | 479 | mutex_unlock(&pCifsFile->fh_mutex); |
Suresh Jayaraman | 0f3bc09 | 2009-06-25 18:12:34 +0530 | [diff] [blame] | 480 | rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | FreeXid(xid); |
Suresh Jayaraman | 0f3bc09 | 2009-06-25 18:12:34 +0530 | [diff] [blame] | 482 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | } |
| 484 | |
Jeff Layton | 1588617 | 2010-10-15 15:33:59 -0400 | [diff] [blame] | 485 | inode = pCifsFile->dentry->d_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | cifs_sb = CIFS_SB(inode->i_sb); |
Jeff Layton | 13cfb73 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 487 | tcon = tlink_tcon(pCifsFile->tlink); |
Steve French | 3a9f462 | 2007-04-04 17:10:24 +0000 | [diff] [blame] | 488 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | /* can not grab rename sem here because various ops, including |
| 490 | those that already have the rename sem can end up causing writepage |
| 491 | to get called and if the server was down that means we end up here, |
| 492 | and we can never tell if the caller already has the rename_sem */ |
Jeff Layton | 1588617 | 2010-10-15 15:33:59 -0400 | [diff] [blame] | 493 | full_path = build_path_from_dentry(pCifsFile->dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | if (full_path == NULL) { |
Steve French | 3a9f462 | 2007-04-04 17:10:24 +0000 | [diff] [blame] | 495 | rc = -ENOMEM; |
Jeff Layton | f0a71eb | 2009-06-27 07:04:55 -0400 | [diff] [blame] | 496 | mutex_unlock(&pCifsFile->fh_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | FreeXid(xid); |
Steve French | 3a9f462 | 2007-04-04 17:10:24 +0000 | [diff] [blame] | 498 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | } |
| 500 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 501 | cFYI(1, "inode = 0x%p file flags 0x%x for %s", |
Jeff Layton | 1588617 | 2010-10-15 15:33:59 -0400 | [diff] [blame] | 502 | inode, pCifsFile->f_flags, full_path); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | |
Steve French | e750473 | 2011-10-12 17:47:03 -0500 | [diff] [blame] | 504 | if (enable_oplocks) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | oplock = REQ_OPLOCK; |
| 506 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 507 | oplock = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | |
Steve French | 7fc8f4e | 2009-02-23 20:43:11 +0000 | [diff] [blame] | 509 | if (tcon->unix_ext && (tcon->ses->capabilities & CAP_UNIX) && |
| 510 | (CIFS_UNIX_POSIX_PATH_OPS_CAP & |
| 511 | le64_to_cpu(tcon->fsUnixInfo.Capability))) { |
Jeff Layton | 608712f | 2010-10-15 15:33:56 -0400 | [diff] [blame] | 512 | |
| 513 | /* |
| 514 | * O_CREAT, O_EXCL and O_TRUNC already had their effect on the |
| 515 | * original open. Must mask them off for a reopen. |
| 516 | */ |
Jeff Layton | 1588617 | 2010-10-15 15:33:59 -0400 | [diff] [blame] | 517 | unsigned int oflags = pCifsFile->f_flags & |
| 518 | ~(O_CREAT | O_EXCL | O_TRUNC); |
Jeff Layton | 608712f | 2010-10-15 15:33:56 -0400 | [diff] [blame] | 519 | |
Jeff Layton | 2422f67 | 2010-06-16 13:40:16 -0400 | [diff] [blame] | 520 | rc = cifs_posix_open(full_path, NULL, inode->i_sb, |
Steve French | fa588e0 | 2010-04-22 19:21:55 +0000 | [diff] [blame] | 521 | cifs_sb->mnt_file_mode /* ignored */, |
| 522 | oflags, &oplock, &netfid, xid); |
Steve French | 7fc8f4e | 2009-02-23 20:43:11 +0000 | [diff] [blame] | 523 | if (rc == 0) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 524 | cFYI(1, "posix reopen succeeded"); |
Steve French | 7fc8f4e | 2009-02-23 20:43:11 +0000 | [diff] [blame] | 525 | goto reopen_success; |
| 526 | } |
| 527 | /* fallthrough to retry open the old way on errors, especially |
| 528 | in the reconnect path it is important to retry hard */ |
| 529 | } |
| 530 | |
Jeff Layton | 1588617 | 2010-10-15 15:33:59 -0400 | [diff] [blame] | 531 | desiredAccess = cifs_convert_flags(pCifsFile->f_flags); |
Steve French | 7fc8f4e | 2009-02-23 20:43:11 +0000 | [diff] [blame] | 532 | |
Shirish Pargaonkar | 3d3ea8e | 2011-09-26 09:56:44 -0500 | [diff] [blame] | 533 | if (backup_cred(cifs_sb)) |
| 534 | create_options |= CREATE_OPEN_BACKUP_INTENT; |
| 535 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | /* Can not refresh inode by passing in file_info buf to be returned |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 537 | by SMBOpen and then calling get_inode_info with returned buf |
| 538 | since file might have write behind data that needs to be flushed |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | and server version of file size can be stale. If we knew for sure |
| 540 | that inode was not dirty locally we could do this */ |
| 541 | |
Steve French | 7fc8f4e | 2009-02-23 20:43:11 +0000 | [diff] [blame] | 542 | rc = CIFSSMBOpen(xid, tcon, full_path, disposition, desiredAccess, |
Shirish Pargaonkar | 3d3ea8e | 2011-09-26 09:56:44 -0500 | [diff] [blame] | 543 | create_options, &netfid, &oplock, NULL, |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 544 | cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 545 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | if (rc) { |
Jeff Layton | f0a71eb | 2009-06-27 07:04:55 -0400 | [diff] [blame] | 547 | mutex_unlock(&pCifsFile->fh_mutex); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 548 | cFYI(1, "cifs_open returned 0x%x", rc); |
| 549 | cFYI(1, "oplock: %d", oplock); |
Jeff Layton | 1588617 | 2010-10-15 15:33:59 -0400 | [diff] [blame] | 550 | goto reopen_error_exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | } |
Jeff Layton | 1588617 | 2010-10-15 15:33:59 -0400 | [diff] [blame] | 552 | |
| 553 | reopen_success: |
| 554 | pCifsFile->netfid = netfid; |
| 555 | pCifsFile->invalidHandle = false; |
| 556 | mutex_unlock(&pCifsFile->fh_mutex); |
| 557 | pCifsInode = CIFS_I(inode); |
| 558 | |
| 559 | if (can_flush) { |
| 560 | rc = filemap_write_and_wait(inode->i_mapping); |
Jeff Layton | eb4b756 | 2010-10-22 14:52:29 -0400 | [diff] [blame] | 561 | mapping_set_error(inode->i_mapping, rc); |
Jeff Layton | 1588617 | 2010-10-15 15:33:59 -0400 | [diff] [blame] | 562 | |
Jeff Layton | 1588617 | 2010-10-15 15:33:59 -0400 | [diff] [blame] | 563 | if (tcon->unix_ext) |
| 564 | rc = cifs_get_inode_info_unix(&inode, |
| 565 | full_path, inode->i_sb, xid); |
| 566 | else |
| 567 | rc = cifs_get_inode_info(&inode, |
| 568 | full_path, NULL, inode->i_sb, |
| 569 | xid, NULL); |
| 570 | } /* else we are writing out data to server already |
| 571 | and could deadlock if we tried to flush data, and |
| 572 | since we do not know if we have data that would |
| 573 | invalidate the current end of file on the server |
| 574 | we can not go to the server to get the new inod |
| 575 | info */ |
Pavel Shilovsky | e66673e | 2010-11-02 12:00:42 +0300 | [diff] [blame] | 576 | |
Pavel Shilovsky | c672362 | 2010-11-03 10:58:57 +0300 | [diff] [blame] | 577 | cifs_set_oplock_level(pCifsInode, oplock); |
Pavel Shilovsky | e66673e | 2010-11-02 12:00:42 +0300 | [diff] [blame] | 578 | |
Jeff Layton | 1588617 | 2010-10-15 15:33:59 -0400 | [diff] [blame] | 579 | cifs_relock_file(pCifsFile); |
| 580 | |
| 581 | reopen_error_exit: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | kfree(full_path); |
| 583 | FreeXid(xid); |
| 584 | return rc; |
| 585 | } |
| 586 | |
| 587 | int cifs_close(struct inode *inode, struct file *file) |
| 588 | { |
Jeff Layton | 7797069 | 2011-04-05 16:23:47 -0700 | [diff] [blame] | 589 | if (file->private_data != NULL) { |
| 590 | cifsFileInfo_put(file->private_data); |
| 591 | file->private_data = NULL; |
| 592 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | |
Steve French | cdff08e | 2010-10-21 22:46:14 +0000 | [diff] [blame] | 594 | /* return code from the ->release op is always ignored */ |
| 595 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | int cifs_closedir(struct inode *inode, struct file *file) |
| 599 | { |
| 600 | int rc = 0; |
| 601 | int xid; |
Joe Perches | c21dfb6 | 2010-07-12 13:50:14 -0700 | [diff] [blame] | 602 | struct cifsFileInfo *pCFileStruct = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | char *ptmp; |
| 604 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 605 | cFYI(1, "Closedir inode = 0x%p", inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | |
| 607 | xid = GetXid(); |
| 608 | |
| 609 | if (pCFileStruct) { |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 610 | struct cifs_tcon *pTcon = tlink_tcon(pCFileStruct->tlink); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 612 | cFYI(1, "Freeing private data in close dir"); |
Jeff Layton | 4477288 | 2010-10-15 15:34:03 -0400 | [diff] [blame] | 613 | spin_lock(&cifs_file_list_lock); |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 614 | if (!pCFileStruct->srch_inf.endOfSearch && |
| 615 | !pCFileStruct->invalidHandle) { |
| 616 | pCFileStruct->invalidHandle = true; |
Jeff Layton | 4477288 | 2010-10-15 15:34:03 -0400 | [diff] [blame] | 617 | spin_unlock(&cifs_file_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | rc = CIFSFindClose(xid, pTcon, pCFileStruct->netfid); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 619 | cFYI(1, "Closing uncompleted readdir with rc %d", |
| 620 | rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | /* not much we can do if it fails anyway, ignore rc */ |
| 622 | rc = 0; |
Steve French | ddb4cbf | 2008-11-20 20:00:44 +0000 | [diff] [blame] | 623 | } else |
Jeff Layton | 4477288 | 2010-10-15 15:34:03 -0400 | [diff] [blame] | 624 | spin_unlock(&cifs_file_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | ptmp = pCFileStruct->srch_inf.ntwrk_buf_start; |
| 626 | if (ptmp) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 627 | cFYI(1, "closedir free smb buf in srch struct"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | pCFileStruct->srch_inf.ntwrk_buf_start = NULL; |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 629 | if (pCFileStruct->srch_inf.smallBuf) |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 630 | cifs_small_buf_release(ptmp); |
| 631 | else |
| 632 | cifs_buf_release(ptmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | } |
Jeff Layton | 13cfb73 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 634 | cifs_put_tlink(pCFileStruct->tlink); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | kfree(file->private_data); |
| 636 | file->private_data = NULL; |
| 637 | } |
| 638 | /* BB can we lock the filestruct while this is going on? */ |
| 639 | FreeXid(xid); |
| 640 | return rc; |
| 641 | } |
| 642 | |
Pavel Shilovsky | d59dad2 | 2011-09-22 09:53:59 +0400 | [diff] [blame] | 643 | static int store_file_lock(struct cifsInodeInfo *cinode, __u64 len, |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 644 | __u64 offset, __u8 type, __u16 netfid) |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 645 | { |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 646 | struct cifsLockInfo *li = |
| 647 | kmalloc(sizeof(struct cifsLockInfo), GFP_KERNEL); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 648 | if (li == NULL) |
| 649 | return -ENOMEM; |
Pavel Shilovsky | d59dad2 | 2011-09-22 09:53:59 +0400 | [diff] [blame] | 650 | li->netfid = netfid; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 651 | li->offset = offset; |
| 652 | li->length = len; |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 653 | li->type = type; |
| 654 | li->pid = current->tgid; |
Pavel Shilovsky | d59dad2 | 2011-09-22 09:53:59 +0400 | [diff] [blame] | 655 | mutex_lock(&cinode->lock_mutex); |
| 656 | list_add_tail(&li->llist, &cinode->llist); |
| 657 | mutex_unlock(&cinode->lock_mutex); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 658 | return 0; |
| 659 | } |
| 660 | |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 661 | static void |
| 662 | cifs_read_flock(struct file_lock *flock, __u8 *type, int *lock, int *unlock, |
| 663 | bool *wait_flag) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | { |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 665 | if (flock->fl_flags & FL_POSIX) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 666 | cFYI(1, "Posix"); |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 667 | if (flock->fl_flags & FL_FLOCK) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 668 | cFYI(1, "Flock"); |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 669 | if (flock->fl_flags & FL_SLEEP) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 670 | cFYI(1, "Blocking lock"); |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 671 | *wait_flag = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | } |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 673 | if (flock->fl_flags & FL_ACCESS) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 674 | cFYI(1, "Process suspended by mandatory locking - " |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 675 | "not implemented yet"); |
| 676 | if (flock->fl_flags & FL_LEASE) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 677 | cFYI(1, "Lease on file - not implemented yet"); |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 678 | if (flock->fl_flags & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | (~(FL_POSIX | FL_FLOCK | FL_SLEEP | FL_ACCESS | FL_LEASE))) |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 680 | cFYI(1, "Unknown lock flags 0x%x", flock->fl_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 682 | *type = LOCKING_ANDX_LARGE_FILES; |
| 683 | if (flock->fl_type == F_WRLCK) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 684 | cFYI(1, "F_WRLCK "); |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 685 | *lock = 1; |
| 686 | } else if (flock->fl_type == F_UNLCK) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 687 | cFYI(1, "F_UNLCK"); |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 688 | *unlock = 1; |
| 689 | /* Check if unlock includes more than one lock range */ |
| 690 | } else if (flock->fl_type == F_RDLCK) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 691 | cFYI(1, "F_RDLCK"); |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 692 | *type |= LOCKING_ANDX_SHARED_LOCK; |
| 693 | *lock = 1; |
| 694 | } else if (flock->fl_type == F_EXLCK) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 695 | cFYI(1, "F_EXLCK"); |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 696 | *lock = 1; |
| 697 | } else if (flock->fl_type == F_SHLCK) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 698 | cFYI(1, "F_SHLCK"); |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 699 | *type |= LOCKING_ANDX_SHARED_LOCK; |
| 700 | *lock = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | } else |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 702 | cFYI(1, "Unknown type of lock"); |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 703 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 705 | static int |
| 706 | cifs_getlk(struct cifsFileInfo *cfile, struct file_lock *flock, __u8 type, |
| 707 | bool wait_flag, bool posix_lck, int xid) |
| 708 | { |
| 709 | int rc = 0; |
| 710 | __u64 length = 1 + flock->fl_end - flock->fl_start; |
| 711 | __u16 netfid = cfile->netfid; |
| 712 | struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 714 | if (posix_lck) { |
| 715 | int posix_lock_type; |
| 716 | if (type & LOCKING_ANDX_SHARED_LOCK) |
| 717 | posix_lock_type = CIFS_RDLCK; |
| 718 | else |
| 719 | posix_lock_type = CIFS_WRLCK; |
| 720 | rc = CIFSSMBPosixLock(xid, tcon, netfid, 1 /* get */, |
| 721 | length, flock, posix_lock_type, |
| 722 | wait_flag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | return rc; |
| 724 | } |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 725 | |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 726 | /* BB we could chain these into one lock request BB */ |
| 727 | rc = CIFSSMBLock(xid, tcon, netfid, current->tgid, length, |
| 728 | flock->fl_start, 0, 1, type, 0, 0); |
| 729 | if (rc == 0) { |
| 730 | rc = CIFSSMBLock(xid, tcon, netfid, current->tgid, |
| 731 | length, flock->fl_start, 1, 0, |
| 732 | type, 0, 0); |
| 733 | flock->fl_type = F_UNLCK; |
| 734 | if (rc != 0) |
| 735 | cERROR(1, "Error unlocking previously locked " |
| 736 | "range %d during test of lock", rc); |
| 737 | rc = 0; |
| 738 | return rc; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 739 | } |
| 740 | |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 741 | if (type & LOCKING_ANDX_SHARED_LOCK) { |
| 742 | flock->fl_type = F_WRLCK; |
| 743 | rc = 0; |
| 744 | return rc; |
| 745 | } |
| 746 | |
| 747 | rc = CIFSSMBLock(xid, tcon, netfid, current->tgid, length, |
| 748 | flock->fl_start, 0, 1, |
| 749 | type | LOCKING_ANDX_SHARED_LOCK, 0, 0); |
| 750 | if (rc == 0) { |
| 751 | rc = CIFSSMBLock(xid, tcon, netfid, current->tgid, |
| 752 | length, flock->fl_start, 1, 0, |
| 753 | type | LOCKING_ANDX_SHARED_LOCK, |
| 754 | 0, 0); |
| 755 | flock->fl_type = F_RDLCK; |
| 756 | if (rc != 0) |
| 757 | cERROR(1, "Error unlocking previously locked " |
| 758 | "range %d during test of lock", rc); |
| 759 | } else |
| 760 | flock->fl_type = F_WRLCK; |
| 761 | |
| 762 | rc = 0; |
| 763 | return rc; |
| 764 | } |
| 765 | |
| 766 | static int |
| 767 | cifs_setlk(struct file *file, struct file_lock *flock, __u8 type, |
| 768 | bool wait_flag, bool posix_lck, int lock, int unlock, int xid) |
| 769 | { |
| 770 | int rc = 0; |
| 771 | __u64 length = 1 + flock->fl_end - flock->fl_start; |
| 772 | struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data; |
| 773 | struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); |
Pavel Shilovsky | d59dad2 | 2011-09-22 09:53:59 +0400 | [diff] [blame] | 774 | struct cifsInodeInfo *cinode = CIFS_I(file->f_path.dentry->d_inode); |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 775 | __u16 netfid = cfile->netfid; |
| 776 | |
| 777 | if (posix_lck) { |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 778 | int posix_lock_type; |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 779 | if (type & LOCKING_ANDX_SHARED_LOCK) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 780 | posix_lock_type = CIFS_RDLCK; |
| 781 | else |
| 782 | posix_lock_type = CIFS_WRLCK; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 783 | |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 784 | if (unlock == 1) |
Steve French | beb84dc | 2006-03-03 23:36:34 +0000 | [diff] [blame] | 785 | posix_lock_type = CIFS_UNLCK; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 786 | |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 787 | rc = CIFSSMBPosixLock(xid, tcon, netfid, 0 /* set */, length, |
| 788 | flock, posix_lock_type, wait_flag); |
| 789 | goto out; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 790 | } |
| 791 | |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 792 | if (lock) { |
| 793 | rc = CIFSSMBLock(xid, tcon, netfid, current->tgid, length, |
| 794 | flock->fl_start, 0, lock, type, wait_flag, 0); |
| 795 | if (rc == 0) { |
| 796 | /* For Windows locks we must store them. */ |
Pavel Shilovsky | d59dad2 | 2011-09-22 09:53:59 +0400 | [diff] [blame] | 797 | rc = store_file_lock(cinode, length, flock->fl_start, |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 798 | type, netfid); |
| 799 | } |
| 800 | } else if (unlock) { |
| 801 | /* |
| 802 | * For each stored lock that this unlock overlaps completely, |
| 803 | * unlock it. |
| 804 | */ |
| 805 | int stored_rc = 0; |
| 806 | struct cifsLockInfo *li, *tmp; |
| 807 | |
Pavel Shilovsky | d59dad2 | 2011-09-22 09:53:59 +0400 | [diff] [blame] | 808 | mutex_lock(&cinode->lock_mutex); |
| 809 | list_for_each_entry_safe(li, tmp, &cinode->llist, llist) { |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 810 | if (flock->fl_start > li->offset || |
| 811 | (flock->fl_start + length) < |
| 812 | (li->offset + li->length)) |
| 813 | continue; |
| 814 | if (current->tgid != li->pid) |
| 815 | continue; |
Pavel Shilovsky | d59dad2 | 2011-09-22 09:53:59 +0400 | [diff] [blame] | 816 | if (cfile->netfid != li->netfid) |
| 817 | continue; |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 818 | |
| 819 | stored_rc = CIFSSMBLock(xid, tcon, netfid, |
| 820 | current->tgid, li->length, |
| 821 | li->offset, 1, 0, li->type, |
| 822 | 0, 0); |
| 823 | if (stored_rc) |
| 824 | rc = stored_rc; |
| 825 | else { |
| 826 | list_del(&li->llist); |
| 827 | kfree(li); |
| 828 | } |
| 829 | } |
Pavel Shilovsky | d59dad2 | 2011-09-22 09:53:59 +0400 | [diff] [blame] | 830 | mutex_unlock(&cinode->lock_mutex); |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 831 | } |
| 832 | out: |
| 833 | if (flock->fl_flags & FL_POSIX) |
| 834 | posix_lock_file_wait(file, flock); |
| 835 | return rc; |
| 836 | } |
| 837 | |
| 838 | int cifs_lock(struct file *file, int cmd, struct file_lock *flock) |
| 839 | { |
| 840 | int rc, xid; |
| 841 | int lock = 0, unlock = 0; |
| 842 | bool wait_flag = false; |
| 843 | bool posix_lck = false; |
| 844 | struct cifs_sb_info *cifs_sb; |
| 845 | struct cifs_tcon *tcon; |
| 846 | struct cifsInodeInfo *cinode; |
| 847 | struct cifsFileInfo *cfile; |
| 848 | __u16 netfid; |
| 849 | __u8 type; |
| 850 | |
| 851 | rc = -EACCES; |
| 852 | xid = GetXid(); |
| 853 | |
| 854 | cFYI(1, "Lock parm: 0x%x flockflags: 0x%x flocktype: 0x%x start: %lld " |
| 855 | "end: %lld", cmd, flock->fl_flags, flock->fl_type, |
| 856 | flock->fl_start, flock->fl_end); |
| 857 | |
| 858 | cifs_read_flock(flock, &type, &lock, &unlock, &wait_flag); |
| 859 | |
| 860 | cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); |
| 861 | cfile = (struct cifsFileInfo *)file->private_data; |
| 862 | tcon = tlink_tcon(cfile->tlink); |
| 863 | netfid = cfile->netfid; |
| 864 | cinode = CIFS_I(file->f_path.dentry->d_inode); |
| 865 | |
| 866 | if ((tcon->ses->capabilities & CAP_UNIX) && |
| 867 | (CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability)) && |
| 868 | ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0)) |
| 869 | posix_lck = true; |
| 870 | /* |
| 871 | * BB add code here to normalize offset and length to account for |
| 872 | * negative length which we can not accept over the wire. |
| 873 | */ |
| 874 | if (IS_GETLK(cmd)) { |
| 875 | rc = cifs_getlk(cfile, flock, type, wait_flag, posix_lck, xid); |
| 876 | FreeXid(xid); |
| 877 | return rc; |
| 878 | } |
| 879 | |
| 880 | if (!lock && !unlock) { |
| 881 | /* |
| 882 | * if no lock or unlock then nothing to do since we do not |
| 883 | * know what it is |
| 884 | */ |
| 885 | FreeXid(xid); |
| 886 | return -EOPNOTSUPP; |
| 887 | } |
| 888 | |
| 889 | rc = cifs_setlk(file, flock, type, wait_flag, posix_lck, lock, unlock, |
| 890 | xid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | FreeXid(xid); |
| 892 | return rc; |
| 893 | } |
| 894 | |
Jeff Layton | fbec9ab | 2009-04-03 13:44:00 -0400 | [diff] [blame] | 895 | /* update the file size (if needed) after a write */ |
Pavel Shilovsky | 72432ff | 2011-01-24 14:16:35 -0500 | [diff] [blame] | 896 | void |
Jeff Layton | fbec9ab | 2009-04-03 13:44:00 -0400 | [diff] [blame] | 897 | cifs_update_eof(struct cifsInodeInfo *cifsi, loff_t offset, |
| 898 | unsigned int bytes_written) |
| 899 | { |
| 900 | loff_t end_of_write = offset + bytes_written; |
| 901 | |
| 902 | if (end_of_write > cifsi->server_eof) |
| 903 | cifsi->server_eof = end_of_write; |
| 904 | } |
| 905 | |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 906 | static ssize_t cifs_write(struct cifsFileInfo *open_file, __u32 pid, |
Jeff Layton | 7da4b49 | 2010-10-15 15:34:00 -0400 | [diff] [blame] | 907 | const char *write_data, size_t write_size, |
| 908 | loff_t *poffset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | { |
| 910 | int rc = 0; |
| 911 | unsigned int bytes_written = 0; |
| 912 | unsigned int total_written; |
| 913 | struct cifs_sb_info *cifs_sb; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 914 | struct cifs_tcon *pTcon; |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 915 | int xid; |
Jeff Layton | 7da4b49 | 2010-10-15 15:34:00 -0400 | [diff] [blame] | 916 | struct dentry *dentry = open_file->dentry; |
| 917 | struct cifsInodeInfo *cifsi = CIFS_I(dentry->d_inode); |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 918 | struct cifs_io_parms io_parms; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | |
Jeff Layton | 7da4b49 | 2010-10-15 15:34:00 -0400 | [diff] [blame] | 920 | cifs_sb = CIFS_SB(dentry->d_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 922 | cFYI(1, "write %zd bytes to offset %lld of %s", write_size, |
Jeff Layton | 7da4b49 | 2010-10-15 15:34:00 -0400 | [diff] [blame] | 923 | *poffset, dentry->d_name.name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | |
Jeff Layton | 13cfb73 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 925 | pTcon = tlink_tcon(open_file->tlink); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 926 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | xid = GetXid(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | for (total_written = 0; write_size > total_written; |
| 930 | total_written += bytes_written) { |
| 931 | rc = -EAGAIN; |
| 932 | while (rc == -EAGAIN) { |
Jeff Layton | ca83ce3 | 2011-04-12 09:13:44 -0400 | [diff] [blame] | 933 | struct kvec iov[2]; |
| 934 | unsigned int len; |
| 935 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | if (open_file->invalidHandle) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | /* we could deadlock if we called |
| 938 | filemap_fdatawait from here so tell |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 939 | reopen_file not to flush data to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | server now */ |
Jeff Layton | 1588617 | 2010-10-15 15:33:59 -0400 | [diff] [blame] | 941 | rc = cifs_reopen_file(open_file, false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | if (rc != 0) |
| 943 | break; |
| 944 | } |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 945 | |
Jeff Layton | ca83ce3 | 2011-04-12 09:13:44 -0400 | [diff] [blame] | 946 | len = min((size_t)cifs_sb->wsize, |
| 947 | write_size - total_written); |
| 948 | /* iov[0] is reserved for smb header */ |
| 949 | iov[1].iov_base = (char *)write_data + total_written; |
| 950 | iov[1].iov_len = len; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 951 | io_parms.netfid = open_file->netfid; |
| 952 | io_parms.pid = pid; |
| 953 | io_parms.tcon = pTcon; |
| 954 | io_parms.offset = *poffset; |
| 955 | io_parms.length = len; |
| 956 | rc = CIFSSMBWrite2(xid, &io_parms, &bytes_written, iov, |
| 957 | 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | } |
| 959 | if (rc || (bytes_written == 0)) { |
| 960 | if (total_written) |
| 961 | break; |
| 962 | else { |
| 963 | FreeXid(xid); |
| 964 | return rc; |
| 965 | } |
Jeff Layton | fbec9ab | 2009-04-03 13:44:00 -0400 | [diff] [blame] | 966 | } else { |
| 967 | cifs_update_eof(cifsi, *poffset, bytes_written); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | *poffset += bytes_written; |
Jeff Layton | fbec9ab | 2009-04-03 13:44:00 -0400 | [diff] [blame] | 969 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | } |
| 971 | |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 972 | cifs_stats_bytes_written(pTcon, total_written); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | |
Jeff Layton | 7da4b49 | 2010-10-15 15:34:00 -0400 | [diff] [blame] | 974 | if (total_written > 0) { |
| 975 | spin_lock(&dentry->d_inode->i_lock); |
| 976 | if (*poffset > dentry->d_inode->i_size) |
| 977 | i_size_write(dentry->d_inode, *poffset); |
| 978 | spin_unlock(&dentry->d_inode->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | } |
Jeff Layton | 7da4b49 | 2010-10-15 15:34:00 -0400 | [diff] [blame] | 980 | mark_inode_dirty_sync(dentry->d_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | FreeXid(xid); |
| 982 | return total_written; |
| 983 | } |
| 984 | |
Jeff Layton | 6508d90 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 985 | struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *cifs_inode, |
| 986 | bool fsuid_only) |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 987 | { |
| 988 | struct cifsFileInfo *open_file = NULL; |
Jeff Layton | 6508d90 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 989 | struct cifs_sb_info *cifs_sb = CIFS_SB(cifs_inode->vfs_inode.i_sb); |
| 990 | |
| 991 | /* only filter by fsuid on multiuser mounts */ |
| 992 | if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER)) |
| 993 | fsuid_only = false; |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 994 | |
Jeff Layton | 4477288 | 2010-10-15 15:34:03 -0400 | [diff] [blame] | 995 | spin_lock(&cifs_file_list_lock); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 996 | /* we could simply get the first_list_entry since write-only entries |
| 997 | are always at the end of the list but since the first entry might |
| 998 | have a close pending, we go through the whole list */ |
| 999 | list_for_each_entry(open_file, &cifs_inode->openFileList, flist) { |
Jeff Layton | 6508d90 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 1000 | if (fsuid_only && open_file->uid != current_fsuid()) |
| 1001 | continue; |
Jeff Layton | 2e396b8 | 2010-10-15 15:34:01 -0400 | [diff] [blame] | 1002 | if (OPEN_FMODE(open_file->f_flags) & FMODE_READ) { |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 1003 | if (!open_file->invalidHandle) { |
| 1004 | /* found a good file */ |
| 1005 | /* lock it so it will not be closed on us */ |
Dave Kleikamp | 6ab409b | 2009-08-31 11:07:12 -0400 | [diff] [blame] | 1006 | cifsFileInfo_get(open_file); |
Jeff Layton | 4477288 | 2010-10-15 15:34:03 -0400 | [diff] [blame] | 1007 | spin_unlock(&cifs_file_list_lock); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 1008 | return open_file; |
| 1009 | } /* else might as well continue, and look for |
| 1010 | another, or simply have the caller reopen it |
| 1011 | again rather than trying to fix this handle */ |
| 1012 | } else /* write only file */ |
| 1013 | break; /* write only files are last so must be done */ |
| 1014 | } |
Jeff Layton | 4477288 | 2010-10-15 15:34:03 -0400 | [diff] [blame] | 1015 | spin_unlock(&cifs_file_list_lock); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 1016 | return NULL; |
| 1017 | } |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 1018 | |
Jeff Layton | 6508d90 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 1019 | struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *cifs_inode, |
| 1020 | bool fsuid_only) |
Steve French | 6148a74 | 2005-10-05 12:23:19 -0700 | [diff] [blame] | 1021 | { |
| 1022 | struct cifsFileInfo *open_file; |
Jeff Layton | d389229 | 2010-11-02 16:22:50 -0400 | [diff] [blame] | 1023 | struct cifs_sb_info *cifs_sb; |
Jeff Layton | 2846d38 | 2008-09-22 21:33:33 -0400 | [diff] [blame] | 1024 | bool any_available = false; |
Steve French | dd99cd8 | 2005-10-05 19:32:49 -0700 | [diff] [blame] | 1025 | int rc; |
Steve French | 6148a74 | 2005-10-05 12:23:19 -0700 | [diff] [blame] | 1026 | |
Steve French | 6080823 | 2006-04-22 15:53:05 +0000 | [diff] [blame] | 1027 | /* Having a null inode here (because mapping->host was set to zero by |
| 1028 | the VFS or MM) should not happen but we had reports of on oops (due to |
| 1029 | it being zero) during stress testcases so we need to check for it */ |
| 1030 | |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1031 | if (cifs_inode == NULL) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1032 | cERROR(1, "Null inode passed to cifs_writeable_file"); |
Steve French | 6080823 | 2006-04-22 15:53:05 +0000 | [diff] [blame] | 1033 | dump_stack(); |
| 1034 | return NULL; |
| 1035 | } |
| 1036 | |
Jeff Layton | d389229 | 2010-11-02 16:22:50 -0400 | [diff] [blame] | 1037 | cifs_sb = CIFS_SB(cifs_inode->vfs_inode.i_sb); |
| 1038 | |
Jeff Layton | 6508d90 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 1039 | /* only filter by fsuid on multiuser mounts */ |
| 1040 | if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER)) |
| 1041 | fsuid_only = false; |
| 1042 | |
Jeff Layton | 4477288 | 2010-10-15 15:34:03 -0400 | [diff] [blame] | 1043 | spin_lock(&cifs_file_list_lock); |
Steve French | 9b22b0b | 2007-10-02 01:11:08 +0000 | [diff] [blame] | 1044 | refind_writable: |
Steve French | 6148a74 | 2005-10-05 12:23:19 -0700 | [diff] [blame] | 1045 | list_for_each_entry(open_file, &cifs_inode->openFileList, flist) { |
Jeff Layton | 6508d90 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 1046 | if (!any_available && open_file->pid != current->tgid) |
| 1047 | continue; |
| 1048 | if (fsuid_only && open_file->uid != current_fsuid()) |
| 1049 | continue; |
Jeff Layton | 2e396b8 | 2010-10-15 15:34:01 -0400 | [diff] [blame] | 1050 | if (OPEN_FMODE(open_file->f_flags) & FMODE_WRITE) { |
Dave Kleikamp | 6ab409b | 2009-08-31 11:07:12 -0400 | [diff] [blame] | 1051 | cifsFileInfo_get(open_file); |
Steve French | 9b22b0b | 2007-10-02 01:11:08 +0000 | [diff] [blame] | 1052 | |
| 1053 | if (!open_file->invalidHandle) { |
| 1054 | /* found a good writable file */ |
Jeff Layton | 4477288 | 2010-10-15 15:34:03 -0400 | [diff] [blame] | 1055 | spin_unlock(&cifs_file_list_lock); |
Steve French | 9b22b0b | 2007-10-02 01:11:08 +0000 | [diff] [blame] | 1056 | return open_file; |
| 1057 | } |
Steve French | 8840dee | 2007-11-16 23:05:52 +0000 | [diff] [blame] | 1058 | |
Jeff Layton | 4477288 | 2010-10-15 15:34:03 -0400 | [diff] [blame] | 1059 | spin_unlock(&cifs_file_list_lock); |
Steve French | cdff08e | 2010-10-21 22:46:14 +0000 | [diff] [blame] | 1060 | |
Steve French | 9b22b0b | 2007-10-02 01:11:08 +0000 | [diff] [blame] | 1061 | /* Had to unlock since following call can block */ |
Jeff Layton | 1588617 | 2010-10-15 15:33:59 -0400 | [diff] [blame] | 1062 | rc = cifs_reopen_file(open_file, false); |
Steve French | cdff08e | 2010-10-21 22:46:14 +0000 | [diff] [blame] | 1063 | if (!rc) |
| 1064 | return open_file; |
Steve French | 9b22b0b | 2007-10-02 01:11:08 +0000 | [diff] [blame] | 1065 | |
Steve French | cdff08e | 2010-10-21 22:46:14 +0000 | [diff] [blame] | 1066 | /* if it fails, try another handle if possible */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1067 | cFYI(1, "wp failed on reopen file"); |
Dave Kleikamp | 6ab409b | 2009-08-31 11:07:12 -0400 | [diff] [blame] | 1068 | cifsFileInfo_put(open_file); |
Steve French | 8840dee | 2007-11-16 23:05:52 +0000 | [diff] [blame] | 1069 | |
Steve French | cdff08e | 2010-10-21 22:46:14 +0000 | [diff] [blame] | 1070 | spin_lock(&cifs_file_list_lock); |
| 1071 | |
Steve French | 9b22b0b | 2007-10-02 01:11:08 +0000 | [diff] [blame] | 1072 | /* else we simply continue to the next entry. Thus |
| 1073 | we do not loop on reopen errors. If we |
| 1074 | can not reopen the file, for example if we |
| 1075 | reconnected to a server with another client |
| 1076 | racing to delete or lock the file we would not |
| 1077 | make progress if we restarted before the beginning |
| 1078 | of the loop here. */ |
Steve French | 6148a74 | 2005-10-05 12:23:19 -0700 | [diff] [blame] | 1079 | } |
| 1080 | } |
Jeff Layton | 2846d38 | 2008-09-22 21:33:33 -0400 | [diff] [blame] | 1081 | /* couldn't find useable FH with same pid, try any available */ |
| 1082 | if (!any_available) { |
| 1083 | any_available = true; |
| 1084 | goto refind_writable; |
| 1085 | } |
Jeff Layton | 4477288 | 2010-10-15 15:34:03 -0400 | [diff] [blame] | 1086 | spin_unlock(&cifs_file_list_lock); |
Steve French | 6148a74 | 2005-10-05 12:23:19 -0700 | [diff] [blame] | 1087 | return NULL; |
| 1088 | } |
| 1089 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | static int cifs_partialpagewrite(struct page *page, unsigned from, unsigned to) |
| 1091 | { |
| 1092 | struct address_space *mapping = page->mapping; |
| 1093 | loff_t offset = (loff_t)page->index << PAGE_CACHE_SHIFT; |
| 1094 | char *write_data; |
| 1095 | int rc = -EFAULT; |
| 1096 | int bytes_written = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | struct inode *inode; |
Steve French | 6148a74 | 2005-10-05 12:23:19 -0700 | [diff] [blame] | 1098 | struct cifsFileInfo *open_file; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | |
| 1100 | if (!mapping || !mapping->host) |
| 1101 | return -EFAULT; |
| 1102 | |
| 1103 | inode = page->mapping->host; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | |
| 1105 | offset += (loff_t)from; |
| 1106 | write_data = kmap(page); |
| 1107 | write_data += from; |
| 1108 | |
| 1109 | if ((to > PAGE_CACHE_SIZE) || (from > to)) { |
| 1110 | kunmap(page); |
| 1111 | return -EIO; |
| 1112 | } |
| 1113 | |
| 1114 | /* racing with truncate? */ |
| 1115 | if (offset > mapping->host->i_size) { |
| 1116 | kunmap(page); |
| 1117 | return 0; /* don't care */ |
| 1118 | } |
| 1119 | |
| 1120 | /* check to make sure that we are not extending the file */ |
| 1121 | if (mapping->host->i_size - offset < (loff_t)to) |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1122 | to = (unsigned)(mapping->host->i_size - offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | |
Jeff Layton | 6508d90 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 1124 | open_file = find_writable_file(CIFS_I(mapping->host), false); |
Steve French | 6148a74 | 2005-10-05 12:23:19 -0700 | [diff] [blame] | 1125 | if (open_file) { |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1126 | bytes_written = cifs_write(open_file, open_file->pid, |
| 1127 | write_data, to - from, &offset); |
Dave Kleikamp | 6ab409b | 2009-08-31 11:07:12 -0400 | [diff] [blame] | 1128 | cifsFileInfo_put(open_file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | /* Does mm or vfs already set times? */ |
Steve French | 6148a74 | 2005-10-05 12:23:19 -0700 | [diff] [blame] | 1130 | inode->i_atime = inode->i_mtime = current_fs_time(inode->i_sb); |
Steve French | bb5a9a0 | 2007-12-31 04:21:29 +0000 | [diff] [blame] | 1131 | if ((bytes_written > 0) && (offset)) |
Steve French | 6148a74 | 2005-10-05 12:23:19 -0700 | [diff] [blame] | 1132 | rc = 0; |
Steve French | bb5a9a0 | 2007-12-31 04:21:29 +0000 | [diff] [blame] | 1133 | else if (bytes_written < 0) |
| 1134 | rc = bytes_written; |
Steve French | 6148a74 | 2005-10-05 12:23:19 -0700 | [diff] [blame] | 1135 | } else { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1136 | cFYI(1, "No writeable filehandles for inode"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | rc = -EIO; |
| 1138 | } |
| 1139 | |
| 1140 | kunmap(page); |
| 1141 | return rc; |
| 1142 | } |
| 1143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1144 | static int cifs_writepages(struct address_space *mapping, |
Steve French | 37c0eb4 | 2005-10-05 14:50:29 -0700 | [diff] [blame] | 1145 | struct writeback_control *wbc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | { |
Jeff Layton | c3d17b6 | 2011-05-19 16:22:57 -0400 | [diff] [blame] | 1147 | struct cifs_sb_info *cifs_sb = CIFS_SB(mapping->host->i_sb); |
| 1148 | bool done = false, scanned = false, range_whole = false; |
| 1149 | pgoff_t end, index; |
| 1150 | struct cifs_writedata *wdata; |
Steve French | 37c0eb4 | 2005-10-05 14:50:29 -0700 | [diff] [blame] | 1151 | struct page *page; |
Steve French | 37c0eb4 | 2005-10-05 14:50:29 -0700 | [diff] [blame] | 1152 | int rc = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1153 | |
Steve French | 37c0eb4 | 2005-10-05 14:50:29 -0700 | [diff] [blame] | 1154 | /* |
Jeff Layton | c3d17b6 | 2011-05-19 16:22:57 -0400 | [diff] [blame] | 1155 | * If wsize is smaller than the page cache size, default to writing |
Steve French | 37c0eb4 | 2005-10-05 14:50:29 -0700 | [diff] [blame] | 1156 | * one page at a time via cifs_writepage |
| 1157 | */ |
| 1158 | if (cifs_sb->wsize < PAGE_CACHE_SIZE) |
| 1159 | return generic_writepages(mapping, wbc); |
| 1160 | |
OGAWA Hirofumi | 111ebb6 | 2006-06-23 02:03:26 -0700 | [diff] [blame] | 1161 | if (wbc->range_cyclic) { |
Steve French | 37c0eb4 | 2005-10-05 14:50:29 -0700 | [diff] [blame] | 1162 | index = mapping->writeback_index; /* Start from prev offset */ |
OGAWA Hirofumi | 111ebb6 | 2006-06-23 02:03:26 -0700 | [diff] [blame] | 1163 | end = -1; |
| 1164 | } else { |
| 1165 | index = wbc->range_start >> PAGE_CACHE_SHIFT; |
| 1166 | end = wbc->range_end >> PAGE_CACHE_SHIFT; |
| 1167 | if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) |
Jeff Layton | c3d17b6 | 2011-05-19 16:22:57 -0400 | [diff] [blame] | 1168 | range_whole = true; |
| 1169 | scanned = true; |
Steve French | 37c0eb4 | 2005-10-05 14:50:29 -0700 | [diff] [blame] | 1170 | } |
| 1171 | retry: |
Jeff Layton | c3d17b6 | 2011-05-19 16:22:57 -0400 | [diff] [blame] | 1172 | while (!done && index <= end) { |
| 1173 | unsigned int i, nr_pages, found_pages; |
| 1174 | pgoff_t next = 0, tofind; |
| 1175 | struct page **pages; |
Steve French | 37c0eb4 | 2005-10-05 14:50:29 -0700 | [diff] [blame] | 1176 | |
Jeff Layton | c3d17b6 | 2011-05-19 16:22:57 -0400 | [diff] [blame] | 1177 | tofind = min((cifs_sb->wsize / PAGE_CACHE_SIZE) - 1, |
| 1178 | end - index) + 1; |
Steve French | 37c0eb4 | 2005-10-05 14:50:29 -0700 | [diff] [blame] | 1179 | |
Jeff Layton | c3d17b6 | 2011-05-19 16:22:57 -0400 | [diff] [blame] | 1180 | wdata = cifs_writedata_alloc((unsigned int)tofind); |
| 1181 | if (!wdata) { |
| 1182 | rc = -ENOMEM; |
| 1183 | break; |
| 1184 | } |
| 1185 | |
| 1186 | /* |
| 1187 | * find_get_pages_tag seems to return a max of 256 on each |
| 1188 | * iteration, so we must call it several times in order to |
| 1189 | * fill the array or the wsize is effectively limited to |
| 1190 | * 256 * PAGE_CACHE_SIZE. |
| 1191 | */ |
| 1192 | found_pages = 0; |
| 1193 | pages = wdata->pages; |
| 1194 | do { |
| 1195 | nr_pages = find_get_pages_tag(mapping, &index, |
| 1196 | PAGECACHE_TAG_DIRTY, |
| 1197 | tofind, pages); |
| 1198 | found_pages += nr_pages; |
| 1199 | tofind -= nr_pages; |
| 1200 | pages += nr_pages; |
| 1201 | } while (nr_pages && tofind && index <= end); |
| 1202 | |
| 1203 | if (found_pages == 0) { |
| 1204 | kref_put(&wdata->refcount, cifs_writedata_release); |
| 1205 | break; |
| 1206 | } |
| 1207 | |
| 1208 | nr_pages = 0; |
| 1209 | for (i = 0; i < found_pages; i++) { |
| 1210 | page = wdata->pages[i]; |
Steve French | 37c0eb4 | 2005-10-05 14:50:29 -0700 | [diff] [blame] | 1211 | /* |
| 1212 | * At this point we hold neither mapping->tree_lock nor |
| 1213 | * lock on the page itself: the page may be truncated or |
| 1214 | * invalidated (changing page->mapping to NULL), or even |
| 1215 | * swizzled back from swapper_space to tmpfs file |
| 1216 | * mapping |
| 1217 | */ |
| 1218 | |
Jeff Layton | c3d17b6 | 2011-05-19 16:22:57 -0400 | [diff] [blame] | 1219 | if (nr_pages == 0) |
Steve French | 37c0eb4 | 2005-10-05 14:50:29 -0700 | [diff] [blame] | 1220 | lock_page(page); |
Nick Piggin | 529ae9a | 2008-08-02 12:01:03 +0200 | [diff] [blame] | 1221 | else if (!trylock_page(page)) |
Steve French | 37c0eb4 | 2005-10-05 14:50:29 -0700 | [diff] [blame] | 1222 | break; |
| 1223 | |
| 1224 | if (unlikely(page->mapping != mapping)) { |
| 1225 | unlock_page(page); |
| 1226 | break; |
| 1227 | } |
| 1228 | |
OGAWA Hirofumi | 111ebb6 | 2006-06-23 02:03:26 -0700 | [diff] [blame] | 1229 | if (!wbc->range_cyclic && page->index > end) { |
Jeff Layton | c3d17b6 | 2011-05-19 16:22:57 -0400 | [diff] [blame] | 1230 | done = true; |
Steve French | 37c0eb4 | 2005-10-05 14:50:29 -0700 | [diff] [blame] | 1231 | unlock_page(page); |
| 1232 | break; |
| 1233 | } |
| 1234 | |
| 1235 | if (next && (page->index != next)) { |
| 1236 | /* Not next consecutive page */ |
| 1237 | unlock_page(page); |
| 1238 | break; |
| 1239 | } |
| 1240 | |
| 1241 | if (wbc->sync_mode != WB_SYNC_NONE) |
| 1242 | wait_on_page_writeback(page); |
| 1243 | |
| 1244 | if (PageWriteback(page) || |
Linus Torvalds | cb876f4 | 2006-12-23 16:19:07 -0800 | [diff] [blame] | 1245 | !clear_page_dirty_for_io(page)) { |
Steve French | 37c0eb4 | 2005-10-05 14:50:29 -0700 | [diff] [blame] | 1246 | unlock_page(page); |
| 1247 | break; |
| 1248 | } |
Steve French | 84d2f07 | 2005-10-12 15:32:05 -0700 | [diff] [blame] | 1249 | |
Linus Torvalds | cb876f4 | 2006-12-23 16:19:07 -0800 | [diff] [blame] | 1250 | /* |
| 1251 | * This actually clears the dirty bit in the radix tree. |
| 1252 | * See cifs_writepage() for more commentary. |
| 1253 | */ |
| 1254 | set_page_writeback(page); |
| 1255 | |
Steve French | 84d2f07 | 2005-10-12 15:32:05 -0700 | [diff] [blame] | 1256 | if (page_offset(page) >= mapping->host->i_size) { |
Jeff Layton | c3d17b6 | 2011-05-19 16:22:57 -0400 | [diff] [blame] | 1257 | done = true; |
Steve French | 84d2f07 | 2005-10-12 15:32:05 -0700 | [diff] [blame] | 1258 | unlock_page(page); |
Linus Torvalds | cb876f4 | 2006-12-23 16:19:07 -0800 | [diff] [blame] | 1259 | end_page_writeback(page); |
Steve French | 84d2f07 | 2005-10-12 15:32:05 -0700 | [diff] [blame] | 1260 | break; |
| 1261 | } |
| 1262 | |
Jeff Layton | c3d17b6 | 2011-05-19 16:22:57 -0400 | [diff] [blame] | 1263 | wdata->pages[i] = page; |
Steve French | 37c0eb4 | 2005-10-05 14:50:29 -0700 | [diff] [blame] | 1264 | next = page->index + 1; |
Jeff Layton | c3d17b6 | 2011-05-19 16:22:57 -0400 | [diff] [blame] | 1265 | ++nr_pages; |
Steve French | 37c0eb4 | 2005-10-05 14:50:29 -0700 | [diff] [blame] | 1266 | } |
Jeff Layton | c3d17b6 | 2011-05-19 16:22:57 -0400 | [diff] [blame] | 1267 | |
| 1268 | /* reset index to refind any pages skipped */ |
| 1269 | if (nr_pages == 0) |
| 1270 | index = wdata->pages[0]->index + 1; |
| 1271 | |
| 1272 | /* put any pages we aren't going to use */ |
| 1273 | for (i = nr_pages; i < found_pages; i++) { |
| 1274 | page_cache_release(wdata->pages[i]); |
| 1275 | wdata->pages[i] = NULL; |
| 1276 | } |
| 1277 | |
| 1278 | /* nothing to write? */ |
| 1279 | if (nr_pages == 0) { |
| 1280 | kref_put(&wdata->refcount, cifs_writedata_release); |
| 1281 | continue; |
| 1282 | } |
| 1283 | |
| 1284 | wdata->sync_mode = wbc->sync_mode; |
| 1285 | wdata->nr_pages = nr_pages; |
| 1286 | wdata->offset = page_offset(wdata->pages[0]); |
| 1287 | |
| 1288 | do { |
| 1289 | if (wdata->cfile != NULL) |
| 1290 | cifsFileInfo_put(wdata->cfile); |
| 1291 | wdata->cfile = find_writable_file(CIFS_I(mapping->host), |
| 1292 | false); |
| 1293 | if (!wdata->cfile) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1294 | cERROR(1, "No writable handles for inode"); |
Steve French | 23e7dd7 | 2005-10-20 13:44:56 -0700 | [diff] [blame] | 1295 | rc = -EBADF; |
Jeff Layton | c3d17b6 | 2011-05-19 16:22:57 -0400 | [diff] [blame] | 1296 | break; |
Steve French | 37c0eb4 | 2005-10-05 14:50:29 -0700 | [diff] [blame] | 1297 | } |
Jeff Layton | c3d17b6 | 2011-05-19 16:22:57 -0400 | [diff] [blame] | 1298 | rc = cifs_async_writev(wdata); |
| 1299 | } while (wbc->sync_mode == WB_SYNC_ALL && rc == -EAGAIN); |
Jeff Layton | f3983c2 | 2010-09-22 16:17:40 -0700 | [diff] [blame] | 1300 | |
Jeff Layton | c3d17b6 | 2011-05-19 16:22:57 -0400 | [diff] [blame] | 1301 | for (i = 0; i < nr_pages; ++i) |
| 1302 | unlock_page(wdata->pages[i]); |
Jeff Layton | 941b853 | 2011-01-11 07:24:01 -0500 | [diff] [blame] | 1303 | |
Jeff Layton | c3d17b6 | 2011-05-19 16:22:57 -0400 | [diff] [blame] | 1304 | /* send failure -- clean up the mess */ |
| 1305 | if (rc != 0) { |
| 1306 | for (i = 0; i < nr_pages; ++i) { |
Jeff Layton | 941b853 | 2011-01-11 07:24:01 -0500 | [diff] [blame] | 1307 | if (rc == -EAGAIN) |
Jeff Layton | c3d17b6 | 2011-05-19 16:22:57 -0400 | [diff] [blame] | 1308 | redirty_page_for_writepage(wbc, |
| 1309 | wdata->pages[i]); |
| 1310 | else |
| 1311 | SetPageError(wdata->pages[i]); |
| 1312 | end_page_writeback(wdata->pages[i]); |
| 1313 | page_cache_release(wdata->pages[i]); |
Steve French | 37c0eb4 | 2005-10-05 14:50:29 -0700 | [diff] [blame] | 1314 | } |
Jeff Layton | 941b853 | 2011-01-11 07:24:01 -0500 | [diff] [blame] | 1315 | if (rc != -EAGAIN) |
| 1316 | mapping_set_error(mapping, rc); |
Jeff Layton | c3d17b6 | 2011-05-19 16:22:57 -0400 | [diff] [blame] | 1317 | } |
| 1318 | kref_put(&wdata->refcount, cifs_writedata_release); |
Jeff Layton | 941b853 | 2011-01-11 07:24:01 -0500 | [diff] [blame] | 1319 | |
Jeff Layton | c3d17b6 | 2011-05-19 16:22:57 -0400 | [diff] [blame] | 1320 | wbc->nr_to_write -= nr_pages; |
| 1321 | if (wbc->nr_to_write <= 0) |
| 1322 | done = true; |
Dave Kleikamp | b066a48 | 2008-11-18 03:49:05 +0000 | [diff] [blame] | 1323 | |
Jeff Layton | c3d17b6 | 2011-05-19 16:22:57 -0400 | [diff] [blame] | 1324 | index = next; |
Steve French | 37c0eb4 | 2005-10-05 14:50:29 -0700 | [diff] [blame] | 1325 | } |
Jeff Layton | c3d17b6 | 2011-05-19 16:22:57 -0400 | [diff] [blame] | 1326 | |
Steve French | 37c0eb4 | 2005-10-05 14:50:29 -0700 | [diff] [blame] | 1327 | if (!scanned && !done) { |
| 1328 | /* |
| 1329 | * We hit the last page and there is more work to be done: wrap |
| 1330 | * back to the start of the file |
| 1331 | */ |
Jeff Layton | c3d17b6 | 2011-05-19 16:22:57 -0400 | [diff] [blame] | 1332 | scanned = true; |
Steve French | 37c0eb4 | 2005-10-05 14:50:29 -0700 | [diff] [blame] | 1333 | index = 0; |
| 1334 | goto retry; |
| 1335 | } |
Jeff Layton | c3d17b6 | 2011-05-19 16:22:57 -0400 | [diff] [blame] | 1336 | |
OGAWA Hirofumi | 111ebb6 | 2006-06-23 02:03:26 -0700 | [diff] [blame] | 1337 | if (wbc->range_cyclic || (range_whole && wbc->nr_to_write > 0)) |
Steve French | 37c0eb4 | 2005-10-05 14:50:29 -0700 | [diff] [blame] | 1338 | mapping->writeback_index = index; |
| 1339 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1340 | return rc; |
| 1341 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | |
Pavel Shilovsky | 9ad1506 | 2011-04-08 05:29:10 +0400 | [diff] [blame] | 1343 | static int |
| 1344 | cifs_writepage_locked(struct page *page, struct writeback_control *wbc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | { |
Pavel Shilovsky | 9ad1506 | 2011-04-08 05:29:10 +0400 | [diff] [blame] | 1346 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | int xid; |
| 1348 | |
| 1349 | xid = GetXid(); |
| 1350 | /* BB add check for wbc flags */ |
| 1351 | page_cache_get(page); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1352 | if (!PageUptodate(page)) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1353 | cFYI(1, "ppw - page not up to date"); |
Linus Torvalds | cb876f4 | 2006-12-23 16:19:07 -0800 | [diff] [blame] | 1354 | |
| 1355 | /* |
| 1356 | * Set the "writeback" flag, and clear "dirty" in the radix tree. |
| 1357 | * |
| 1358 | * A writepage() implementation always needs to do either this, |
| 1359 | * or re-dirty the page with "redirty_page_for_writepage()" in |
| 1360 | * the case of a failure. |
| 1361 | * |
| 1362 | * Just unlocking the page will cause the radix tree tag-bits |
| 1363 | * to fail to update with the state of the page correctly. |
| 1364 | */ |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1365 | set_page_writeback(page); |
Pavel Shilovsky | 9ad1506 | 2011-04-08 05:29:10 +0400 | [diff] [blame] | 1366 | retry_write: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | rc = cifs_partialpagewrite(page, 0, PAGE_CACHE_SIZE); |
Pavel Shilovsky | 9ad1506 | 2011-04-08 05:29:10 +0400 | [diff] [blame] | 1368 | if (rc == -EAGAIN && wbc->sync_mode == WB_SYNC_ALL) |
| 1369 | goto retry_write; |
| 1370 | else if (rc == -EAGAIN) |
| 1371 | redirty_page_for_writepage(wbc, page); |
| 1372 | else if (rc != 0) |
| 1373 | SetPageError(page); |
| 1374 | else |
| 1375 | SetPageUptodate(page); |
Linus Torvalds | cb876f4 | 2006-12-23 16:19:07 -0800 | [diff] [blame] | 1376 | end_page_writeback(page); |
| 1377 | page_cache_release(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | FreeXid(xid); |
| 1379 | return rc; |
| 1380 | } |
| 1381 | |
Pavel Shilovsky | 9ad1506 | 2011-04-08 05:29:10 +0400 | [diff] [blame] | 1382 | static int cifs_writepage(struct page *page, struct writeback_control *wbc) |
| 1383 | { |
| 1384 | int rc = cifs_writepage_locked(page, wbc); |
| 1385 | unlock_page(page); |
| 1386 | return rc; |
| 1387 | } |
| 1388 | |
Nick Piggin | d941477 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 1389 | static int cifs_write_end(struct file *file, struct address_space *mapping, |
| 1390 | loff_t pos, unsigned len, unsigned copied, |
| 1391 | struct page *page, void *fsdata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | { |
Nick Piggin | d941477 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 1393 | int rc; |
| 1394 | struct inode *inode = mapping->host; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1395 | struct cifsFileInfo *cfile = file->private_data; |
| 1396 | struct cifs_sb_info *cifs_sb = CIFS_SB(cfile->dentry->d_sb); |
| 1397 | __u32 pid; |
| 1398 | |
| 1399 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD) |
| 1400 | pid = cfile->pid; |
| 1401 | else |
| 1402 | pid = current->tgid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1404 | cFYI(1, "write_end for page %p from pos %lld with %d bytes", |
| 1405 | page, pos, copied); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1406 | |
Jeff Layton | a98ee8c | 2008-11-26 19:32:33 +0000 | [diff] [blame] | 1407 | if (PageChecked(page)) { |
| 1408 | if (copied == len) |
| 1409 | SetPageUptodate(page); |
| 1410 | ClearPageChecked(page); |
| 1411 | } else if (!PageUptodate(page) && copied == PAGE_CACHE_SIZE) |
Nick Piggin | d941477 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 1412 | SetPageUptodate(page); |
| 1413 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | if (!PageUptodate(page)) { |
Nick Piggin | d941477 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 1415 | char *page_data; |
| 1416 | unsigned offset = pos & (PAGE_CACHE_SIZE - 1); |
| 1417 | int xid; |
| 1418 | |
| 1419 | xid = GetXid(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | /* this is probably better than directly calling |
| 1421 | partialpage_write since in this function the file handle is |
| 1422 | known which we might as well leverage */ |
| 1423 | /* BB check if anything else missing out of ppw |
| 1424 | such as updating last write time */ |
| 1425 | page_data = kmap(page); |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1426 | rc = cifs_write(cfile, pid, page_data + offset, copied, &pos); |
Nick Piggin | d941477 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 1427 | /* if (rc < 0) should we set writebehind rc? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1428 | kunmap(page); |
Nick Piggin | d941477 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 1429 | |
| 1430 | FreeXid(xid); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1431 | } else { |
Nick Piggin | d941477 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 1432 | rc = copied; |
| 1433 | pos += copied; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1434 | set_page_dirty(page); |
| 1435 | } |
| 1436 | |
Nick Piggin | d941477 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 1437 | if (rc > 0) { |
| 1438 | spin_lock(&inode->i_lock); |
| 1439 | if (pos > inode->i_size) |
| 1440 | i_size_write(inode, pos); |
| 1441 | spin_unlock(&inode->i_lock); |
| 1442 | } |
| 1443 | |
| 1444 | unlock_page(page); |
| 1445 | page_cache_release(page); |
| 1446 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | return rc; |
| 1448 | } |
| 1449 | |
Josef Bacik | 02c24a8 | 2011-07-16 20:44:56 -0400 | [diff] [blame] | 1450 | int cifs_strict_fsync(struct file *file, loff_t start, loff_t end, |
| 1451 | int datasync) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | { |
| 1453 | int xid; |
| 1454 | int rc = 0; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1455 | struct cifs_tcon *tcon; |
Joe Perches | c21dfb6 | 2010-07-12 13:50:14 -0700 | [diff] [blame] | 1456 | struct cifsFileInfo *smbfile = file->private_data; |
Josef "Jeff" Sipek | e6a0029 | 2006-12-08 02:36:48 -0800 | [diff] [blame] | 1457 | struct inode *inode = file->f_path.dentry->d_inode; |
Pavel Shilovsky | 8be7e6b | 2010-12-12 13:11:13 +0300 | [diff] [blame] | 1458 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1459 | |
Josef Bacik | 02c24a8 | 2011-07-16 20:44:56 -0400 | [diff] [blame] | 1460 | rc = filemap_write_and_wait_range(inode->i_mapping, start, end); |
| 1461 | if (rc) |
| 1462 | return rc; |
| 1463 | mutex_lock(&inode->i_mutex); |
| 1464 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1465 | xid = GetXid(); |
| 1466 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1467 | cFYI(1, "Sync file - name: %s datasync: 0x%x", |
Christoph Hellwig | 7ea8085 | 2010-05-26 17:53:25 +0200 | [diff] [blame] | 1468 | file->f_path.dentry->d_name.name, datasync); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1469 | |
Pavel Shilovsky | 6feb989 | 2011-04-07 18:18:11 +0400 | [diff] [blame] | 1470 | if (!CIFS_I(inode)->clientCanCacheRead) { |
| 1471 | rc = cifs_invalidate_mapping(inode); |
| 1472 | if (rc) { |
| 1473 | cFYI(1, "rc: %d during invalidate phase", rc); |
| 1474 | rc = 0; /* don't care about it in fsync */ |
| 1475 | } |
| 1476 | } |
Jeff Layton | eb4b756 | 2010-10-22 14:52:29 -0400 | [diff] [blame] | 1477 | |
Pavel Shilovsky | 8be7e6b | 2010-12-12 13:11:13 +0300 | [diff] [blame] | 1478 | tcon = tlink_tcon(smbfile->tlink); |
| 1479 | if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC)) |
| 1480 | rc = CIFSSMBFlush(xid, tcon, smbfile->netfid); |
| 1481 | |
| 1482 | FreeXid(xid); |
Josef Bacik | 02c24a8 | 2011-07-16 20:44:56 -0400 | [diff] [blame] | 1483 | mutex_unlock(&inode->i_mutex); |
Pavel Shilovsky | 8be7e6b | 2010-12-12 13:11:13 +0300 | [diff] [blame] | 1484 | return rc; |
| 1485 | } |
| 1486 | |
Josef Bacik | 02c24a8 | 2011-07-16 20:44:56 -0400 | [diff] [blame] | 1487 | int cifs_fsync(struct file *file, loff_t start, loff_t end, int datasync) |
Pavel Shilovsky | 8be7e6b | 2010-12-12 13:11:13 +0300 | [diff] [blame] | 1488 | { |
| 1489 | int xid; |
| 1490 | int rc = 0; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1491 | struct cifs_tcon *tcon; |
Pavel Shilovsky | 8be7e6b | 2010-12-12 13:11:13 +0300 | [diff] [blame] | 1492 | struct cifsFileInfo *smbfile = file->private_data; |
| 1493 | struct cifs_sb_info *cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); |
Josef Bacik | 02c24a8 | 2011-07-16 20:44:56 -0400 | [diff] [blame] | 1494 | struct inode *inode = file->f_mapping->host; |
| 1495 | |
| 1496 | rc = filemap_write_and_wait_range(inode->i_mapping, start, end); |
| 1497 | if (rc) |
| 1498 | return rc; |
| 1499 | mutex_lock(&inode->i_mutex); |
Pavel Shilovsky | 8be7e6b | 2010-12-12 13:11:13 +0300 | [diff] [blame] | 1500 | |
| 1501 | xid = GetXid(); |
| 1502 | |
| 1503 | cFYI(1, "Sync file - name: %s datasync: 0x%x", |
| 1504 | file->f_path.dentry->d_name.name, datasync); |
| 1505 | |
| 1506 | tcon = tlink_tcon(smbfile->tlink); |
| 1507 | if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC)) |
| 1508 | rc = CIFSSMBFlush(xid, tcon, smbfile->netfid); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 1509 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | FreeXid(xid); |
Josef Bacik | 02c24a8 | 2011-07-16 20:44:56 -0400 | [diff] [blame] | 1511 | mutex_unlock(&inode->i_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1512 | return rc; |
| 1513 | } |
| 1514 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1515 | /* |
| 1516 | * As file closes, flush all cached write data for this inode checking |
| 1517 | * for write behind errors. |
| 1518 | */ |
Miklos Szeredi | 75e1fcc | 2006-06-23 02:05:12 -0700 | [diff] [blame] | 1519 | int cifs_flush(struct file *file, fl_owner_t id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | { |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1521 | struct inode *inode = file->f_path.dentry->d_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1522 | int rc = 0; |
| 1523 | |
Jeff Layton | eb4b756 | 2010-10-22 14:52:29 -0400 | [diff] [blame] | 1524 | if (file->f_mode & FMODE_WRITE) |
Jeff Layton | d3f1322 | 2010-10-15 15:34:07 -0400 | [diff] [blame] | 1525 | rc = filemap_write_and_wait(inode->i_mapping); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1526 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1527 | cFYI(1, "Flush inode %p file %p rc %d", inode, file, rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1528 | |
| 1529 | return rc; |
| 1530 | } |
| 1531 | |
Pavel Shilovsky | 72432ff | 2011-01-24 14:16:35 -0500 | [diff] [blame] | 1532 | static int |
| 1533 | cifs_write_allocate_pages(struct page **pages, unsigned long num_pages) |
| 1534 | { |
| 1535 | int rc = 0; |
| 1536 | unsigned long i; |
| 1537 | |
| 1538 | for (i = 0; i < num_pages; i++) { |
| 1539 | pages[i] = alloc_page(__GFP_HIGHMEM); |
| 1540 | if (!pages[i]) { |
| 1541 | /* |
| 1542 | * save number of pages we have already allocated and |
| 1543 | * return with ENOMEM error |
| 1544 | */ |
| 1545 | num_pages = i; |
| 1546 | rc = -ENOMEM; |
| 1547 | goto error; |
| 1548 | } |
| 1549 | } |
| 1550 | |
| 1551 | return rc; |
| 1552 | |
| 1553 | error: |
| 1554 | for (i = 0; i < num_pages; i++) |
| 1555 | put_page(pages[i]); |
| 1556 | return rc; |
| 1557 | } |
| 1558 | |
| 1559 | static inline |
| 1560 | size_t get_numpages(const size_t wsize, const size_t len, size_t *cur_len) |
| 1561 | { |
| 1562 | size_t num_pages; |
| 1563 | size_t clen; |
| 1564 | |
| 1565 | clen = min_t(const size_t, len, wsize); |
| 1566 | num_pages = clen / PAGE_CACHE_SIZE; |
| 1567 | if (clen % PAGE_CACHE_SIZE) |
| 1568 | num_pages++; |
| 1569 | |
| 1570 | if (cur_len) |
| 1571 | *cur_len = clen; |
| 1572 | |
| 1573 | return num_pages; |
| 1574 | } |
| 1575 | |
| 1576 | static ssize_t |
| 1577 | cifs_iovec_write(struct file *file, const struct iovec *iov, |
| 1578 | unsigned long nr_segs, loff_t *poffset) |
| 1579 | { |
Pavel Shilovsky | 76429c1 | 2011-01-31 16:03:08 +0300 | [diff] [blame] | 1580 | unsigned int written; |
| 1581 | unsigned long num_pages, npages, i; |
| 1582 | size_t copied, len, cur_len; |
| 1583 | ssize_t total_written = 0; |
Pavel Shilovsky | 72432ff | 2011-01-24 14:16:35 -0500 | [diff] [blame] | 1584 | struct kvec *to_send; |
| 1585 | struct page **pages; |
| 1586 | struct iov_iter it; |
| 1587 | struct inode *inode; |
| 1588 | struct cifsFileInfo *open_file; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1589 | struct cifs_tcon *pTcon; |
Pavel Shilovsky | 72432ff | 2011-01-24 14:16:35 -0500 | [diff] [blame] | 1590 | struct cifs_sb_info *cifs_sb; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1591 | struct cifs_io_parms io_parms; |
Pavel Shilovsky | 72432ff | 2011-01-24 14:16:35 -0500 | [diff] [blame] | 1592 | int xid, rc; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1593 | __u32 pid; |
Pavel Shilovsky | 72432ff | 2011-01-24 14:16:35 -0500 | [diff] [blame] | 1594 | |
| 1595 | len = iov_length(iov, nr_segs); |
| 1596 | if (!len) |
| 1597 | return 0; |
| 1598 | |
| 1599 | rc = generic_write_checks(file, poffset, &len, 0); |
| 1600 | if (rc) |
| 1601 | return rc; |
| 1602 | |
| 1603 | cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); |
| 1604 | num_pages = get_numpages(cifs_sb->wsize, len, &cur_len); |
| 1605 | |
| 1606 | pages = kmalloc(sizeof(struct pages *)*num_pages, GFP_KERNEL); |
| 1607 | if (!pages) |
| 1608 | return -ENOMEM; |
| 1609 | |
| 1610 | to_send = kmalloc(sizeof(struct kvec)*(num_pages + 1), GFP_KERNEL); |
| 1611 | if (!to_send) { |
| 1612 | kfree(pages); |
| 1613 | return -ENOMEM; |
| 1614 | } |
| 1615 | |
| 1616 | rc = cifs_write_allocate_pages(pages, num_pages); |
| 1617 | if (rc) { |
| 1618 | kfree(pages); |
| 1619 | kfree(to_send); |
| 1620 | return rc; |
| 1621 | } |
| 1622 | |
| 1623 | xid = GetXid(); |
| 1624 | open_file = file->private_data; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1625 | |
| 1626 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD) |
| 1627 | pid = open_file->pid; |
| 1628 | else |
| 1629 | pid = current->tgid; |
| 1630 | |
Pavel Shilovsky | 72432ff | 2011-01-24 14:16:35 -0500 | [diff] [blame] | 1631 | pTcon = tlink_tcon(open_file->tlink); |
| 1632 | inode = file->f_path.dentry->d_inode; |
| 1633 | |
| 1634 | iov_iter_init(&it, iov, nr_segs, len, 0); |
| 1635 | npages = num_pages; |
| 1636 | |
| 1637 | do { |
| 1638 | size_t save_len = cur_len; |
| 1639 | for (i = 0; i < npages; i++) { |
| 1640 | copied = min_t(const size_t, cur_len, PAGE_CACHE_SIZE); |
| 1641 | copied = iov_iter_copy_from_user(pages[i], &it, 0, |
| 1642 | copied); |
| 1643 | cur_len -= copied; |
| 1644 | iov_iter_advance(&it, copied); |
| 1645 | to_send[i+1].iov_base = kmap(pages[i]); |
| 1646 | to_send[i+1].iov_len = copied; |
| 1647 | } |
| 1648 | |
| 1649 | cur_len = save_len - cur_len; |
| 1650 | |
| 1651 | do { |
| 1652 | if (open_file->invalidHandle) { |
| 1653 | rc = cifs_reopen_file(open_file, false); |
| 1654 | if (rc != 0) |
| 1655 | break; |
| 1656 | } |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1657 | io_parms.netfid = open_file->netfid; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1658 | io_parms.pid = pid; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1659 | io_parms.tcon = pTcon; |
| 1660 | io_parms.offset = *poffset; |
| 1661 | io_parms.length = cur_len; |
| 1662 | rc = CIFSSMBWrite2(xid, &io_parms, &written, to_send, |
| 1663 | npages, 0); |
Pavel Shilovsky | 72432ff | 2011-01-24 14:16:35 -0500 | [diff] [blame] | 1664 | } while (rc == -EAGAIN); |
| 1665 | |
| 1666 | for (i = 0; i < npages; i++) |
| 1667 | kunmap(pages[i]); |
| 1668 | |
| 1669 | if (written) { |
| 1670 | len -= written; |
| 1671 | total_written += written; |
| 1672 | cifs_update_eof(CIFS_I(inode), *poffset, written); |
| 1673 | *poffset += written; |
| 1674 | } else if (rc < 0) { |
| 1675 | if (!total_written) |
| 1676 | total_written = rc; |
| 1677 | break; |
| 1678 | } |
| 1679 | |
| 1680 | /* get length and number of kvecs of the next write */ |
| 1681 | npages = get_numpages(cifs_sb->wsize, len, &cur_len); |
| 1682 | } while (len > 0); |
| 1683 | |
| 1684 | if (total_written > 0) { |
| 1685 | spin_lock(&inode->i_lock); |
| 1686 | if (*poffset > inode->i_size) |
| 1687 | i_size_write(inode, *poffset); |
| 1688 | spin_unlock(&inode->i_lock); |
| 1689 | } |
| 1690 | |
| 1691 | cifs_stats_bytes_written(pTcon, total_written); |
| 1692 | mark_inode_dirty_sync(inode); |
| 1693 | |
| 1694 | for (i = 0; i < num_pages; i++) |
| 1695 | put_page(pages[i]); |
| 1696 | kfree(to_send); |
| 1697 | kfree(pages); |
| 1698 | FreeXid(xid); |
| 1699 | return total_written; |
| 1700 | } |
| 1701 | |
Pavel Shilovsky | 0b81c1c | 2011-03-10 10:11:05 +0300 | [diff] [blame] | 1702 | ssize_t cifs_user_writev(struct kiocb *iocb, const struct iovec *iov, |
Pavel Shilovsky | 72432ff | 2011-01-24 14:16:35 -0500 | [diff] [blame] | 1703 | unsigned long nr_segs, loff_t pos) |
| 1704 | { |
| 1705 | ssize_t written; |
| 1706 | struct inode *inode; |
| 1707 | |
| 1708 | inode = iocb->ki_filp->f_path.dentry->d_inode; |
| 1709 | |
| 1710 | /* |
| 1711 | * BB - optimize the way when signing is disabled. We can drop this |
| 1712 | * extra memory-to-memory copying and use iovec buffers for constructing |
| 1713 | * write request. |
| 1714 | */ |
| 1715 | |
| 1716 | written = cifs_iovec_write(iocb->ki_filp, iov, nr_segs, &pos); |
| 1717 | if (written > 0) { |
| 1718 | CIFS_I(inode)->invalid_mapping = true; |
| 1719 | iocb->ki_pos = pos; |
| 1720 | } |
| 1721 | |
| 1722 | return written; |
| 1723 | } |
| 1724 | |
| 1725 | ssize_t cifs_strict_writev(struct kiocb *iocb, const struct iovec *iov, |
| 1726 | unsigned long nr_segs, loff_t pos) |
| 1727 | { |
| 1728 | struct inode *inode; |
| 1729 | |
| 1730 | inode = iocb->ki_filp->f_path.dentry->d_inode; |
| 1731 | |
| 1732 | if (CIFS_I(inode)->clientCanCacheAll) |
| 1733 | return generic_file_aio_write(iocb, iov, nr_segs, pos); |
| 1734 | |
| 1735 | /* |
| 1736 | * In strict cache mode we need to write the data to the server exactly |
| 1737 | * from the pos to pos+len-1 rather than flush all affected pages |
| 1738 | * because it may cause a error with mandatory locks on these pages but |
| 1739 | * not on the region from pos to ppos+len-1. |
| 1740 | */ |
| 1741 | |
| 1742 | return cifs_user_writev(iocb, iov, nr_segs, pos); |
| 1743 | } |
| 1744 | |
Pavel Shilovsky | a70307e | 2010-12-14 11:50:41 +0300 | [diff] [blame] | 1745 | static ssize_t |
| 1746 | cifs_iovec_read(struct file *file, const struct iovec *iov, |
| 1747 | unsigned long nr_segs, loff_t *poffset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | { |
Pavel Shilovsky | a70307e | 2010-12-14 11:50:41 +0300 | [diff] [blame] | 1749 | int rc; |
| 1750 | int xid; |
Pavel Shilovsky | 76429c1 | 2011-01-31 16:03:08 +0300 | [diff] [blame] | 1751 | ssize_t total_read; |
| 1752 | unsigned int bytes_read = 0; |
Pavel Shilovsky | a70307e | 2010-12-14 11:50:41 +0300 | [diff] [blame] | 1753 | size_t len, cur_len; |
| 1754 | int iov_offset = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1755 | struct cifs_sb_info *cifs_sb; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1756 | struct cifs_tcon *pTcon; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1757 | struct cifsFileInfo *open_file; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1758 | struct smb_com_read_rsp *pSMBr; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1759 | struct cifs_io_parms io_parms; |
Pavel Shilovsky | a70307e | 2010-12-14 11:50:41 +0300 | [diff] [blame] | 1760 | char *read_data; |
Jeff Layton | 5eba8ab | 2011-10-19 15:30:26 -0400 | [diff] [blame] | 1761 | unsigned int rsize; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1762 | __u32 pid; |
Pavel Shilovsky | a70307e | 2010-12-14 11:50:41 +0300 | [diff] [blame] | 1763 | |
| 1764 | if (!nr_segs) |
| 1765 | return 0; |
| 1766 | |
| 1767 | len = iov_length(iov, nr_segs); |
| 1768 | if (!len) |
| 1769 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | |
| 1771 | xid = GetXid(); |
Josef "Jeff" Sipek | e6a0029 | 2006-12-08 02:36:48 -0800 | [diff] [blame] | 1772 | cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | |
Jeff Layton | 5eba8ab | 2011-10-19 15:30:26 -0400 | [diff] [blame] | 1774 | /* FIXME: set up handlers for larger reads and/or convert to async */ |
| 1775 | rsize = min_t(unsigned int, cifs_sb->rsize, CIFSMaxBufSize); |
| 1776 | |
Joe Perches | c21dfb6 | 2010-07-12 13:50:14 -0700 | [diff] [blame] | 1777 | open_file = file->private_data; |
Jeff Layton | 13cfb73 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 1778 | pTcon = tlink_tcon(open_file->tlink); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1779 | |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1780 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD) |
| 1781 | pid = open_file->pid; |
| 1782 | else |
| 1783 | pid = current->tgid; |
| 1784 | |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1785 | if ((file->f_flags & O_ACCMODE) == O_WRONLY) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1786 | cFYI(1, "attempting read on write only file instance"); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1787 | |
Pavel Shilovsky | a70307e | 2010-12-14 11:50:41 +0300 | [diff] [blame] | 1788 | for (total_read = 0; total_read < len; total_read += bytes_read) { |
Jeff Layton | 5eba8ab | 2011-10-19 15:30:26 -0400 | [diff] [blame] | 1789 | cur_len = min_t(const size_t, len - total_read, rsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1790 | rc = -EAGAIN; |
Pavel Shilovsky | a70307e | 2010-12-14 11:50:41 +0300 | [diff] [blame] | 1791 | read_data = NULL; |
| 1792 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1793 | while (rc == -EAGAIN) { |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1794 | int buf_type = CIFS_NO_BUFFER; |
Steve French | cdff08e | 2010-10-21 22:46:14 +0000 | [diff] [blame] | 1795 | if (open_file->invalidHandle) { |
Jeff Layton | 1588617 | 2010-10-15 15:33:59 -0400 | [diff] [blame] | 1796 | rc = cifs_reopen_file(open_file, true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1797 | if (rc != 0) |
| 1798 | break; |
| 1799 | } |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1800 | io_parms.netfid = open_file->netfid; |
| 1801 | io_parms.pid = pid; |
| 1802 | io_parms.tcon = pTcon; |
| 1803 | io_parms.offset = *poffset; |
Pavel Shilovsky | 2cebaa5 | 2011-07-20 18:24:09 +0400 | [diff] [blame] | 1804 | io_parms.length = cur_len; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1805 | rc = CIFSSMBRead(xid, &io_parms, &bytes_read, |
Pavel Shilovsky | a70307e | 2010-12-14 11:50:41 +0300 | [diff] [blame] | 1806 | &read_data, &buf_type); |
| 1807 | pSMBr = (struct smb_com_read_rsp *)read_data; |
| 1808 | if (read_data) { |
| 1809 | char *data_offset = read_data + 4 + |
| 1810 | le16_to_cpu(pSMBr->DataOffset); |
| 1811 | if (memcpy_toiovecend(iov, data_offset, |
| 1812 | iov_offset, bytes_read)) |
Steve French | 93544cc | 2006-02-14 22:30:52 -0600 | [diff] [blame] | 1813 | rc = -EFAULT; |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1814 | if (buf_type == CIFS_SMALL_BUFFER) |
Pavel Shilovsky | a70307e | 2010-12-14 11:50:41 +0300 | [diff] [blame] | 1815 | cifs_small_buf_release(read_data); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1816 | else if (buf_type == CIFS_LARGE_BUFFER) |
Pavel Shilovsky | a70307e | 2010-12-14 11:50:41 +0300 | [diff] [blame] | 1817 | cifs_buf_release(read_data); |
| 1818 | read_data = NULL; |
| 1819 | iov_offset += bytes_read; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1820 | } |
| 1821 | } |
Pavel Shilovsky | a70307e | 2010-12-14 11:50:41 +0300 | [diff] [blame] | 1822 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | if (rc || (bytes_read == 0)) { |
| 1824 | if (total_read) { |
| 1825 | break; |
| 1826 | } else { |
| 1827 | FreeXid(xid); |
| 1828 | return rc; |
| 1829 | } |
| 1830 | } else { |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1831 | cifs_stats_bytes_read(pTcon, bytes_read); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | *poffset += bytes_read; |
| 1833 | } |
| 1834 | } |
Pavel Shilovsky | a70307e | 2010-12-14 11:50:41 +0300 | [diff] [blame] | 1835 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | FreeXid(xid); |
| 1837 | return total_read; |
| 1838 | } |
| 1839 | |
Pavel Shilovsky | 0b81c1c | 2011-03-10 10:11:05 +0300 | [diff] [blame] | 1840 | ssize_t cifs_user_readv(struct kiocb *iocb, const struct iovec *iov, |
Pavel Shilovsky | a70307e | 2010-12-14 11:50:41 +0300 | [diff] [blame] | 1841 | unsigned long nr_segs, loff_t pos) |
| 1842 | { |
| 1843 | ssize_t read; |
| 1844 | |
| 1845 | read = cifs_iovec_read(iocb->ki_filp, iov, nr_segs, &pos); |
| 1846 | if (read > 0) |
| 1847 | iocb->ki_pos = pos; |
| 1848 | |
| 1849 | return read; |
| 1850 | } |
| 1851 | |
| 1852 | ssize_t cifs_strict_readv(struct kiocb *iocb, const struct iovec *iov, |
| 1853 | unsigned long nr_segs, loff_t pos) |
| 1854 | { |
| 1855 | struct inode *inode; |
| 1856 | |
| 1857 | inode = iocb->ki_filp->f_path.dentry->d_inode; |
| 1858 | |
| 1859 | if (CIFS_I(inode)->clientCanCacheRead) |
| 1860 | return generic_file_aio_read(iocb, iov, nr_segs, pos); |
| 1861 | |
| 1862 | /* |
| 1863 | * In strict cache mode we need to read from the server all the time |
| 1864 | * if we don't have level II oplock because the server can delay mtime |
| 1865 | * change - so we can't make a decision about inode invalidating. |
| 1866 | * And we can also fail with pagereading if there are mandatory locks |
| 1867 | * on pages affected by this read but not on the region from pos to |
| 1868 | * pos+len-1. |
| 1869 | */ |
| 1870 | |
| 1871 | return cifs_user_readv(iocb, iov, nr_segs, pos); |
| 1872 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1873 | |
| 1874 | static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size, |
Pavel Shilovsky | a70307e | 2010-12-14 11:50:41 +0300 | [diff] [blame] | 1875 | loff_t *poffset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | { |
| 1877 | int rc = -EACCES; |
| 1878 | unsigned int bytes_read = 0; |
| 1879 | unsigned int total_read; |
| 1880 | unsigned int current_read_size; |
Jeff Layton | 5eba8ab | 2011-10-19 15:30:26 -0400 | [diff] [blame] | 1881 | unsigned int rsize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1882 | struct cifs_sb_info *cifs_sb; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1883 | struct cifs_tcon *pTcon; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1884 | int xid; |
| 1885 | char *current_offset; |
| 1886 | struct cifsFileInfo *open_file; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1887 | struct cifs_io_parms io_parms; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1888 | int buf_type = CIFS_NO_BUFFER; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1889 | __u32 pid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1890 | |
| 1891 | xid = GetXid(); |
Josef "Jeff" Sipek | e6a0029 | 2006-12-08 02:36:48 -0800 | [diff] [blame] | 1892 | cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1893 | |
Jeff Layton | 5eba8ab | 2011-10-19 15:30:26 -0400 | [diff] [blame] | 1894 | /* FIXME: set up handlers for larger reads and/or convert to async */ |
| 1895 | rsize = min_t(unsigned int, cifs_sb->rsize, CIFSMaxBufSize); |
| 1896 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1897 | if (file->private_data == NULL) { |
Suresh Jayaraman | 0f3bc09 | 2009-06-25 18:12:34 +0530 | [diff] [blame] | 1898 | rc = -EBADF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | FreeXid(xid); |
Suresh Jayaraman | 0f3bc09 | 2009-06-25 18:12:34 +0530 | [diff] [blame] | 1900 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1901 | } |
Joe Perches | c21dfb6 | 2010-07-12 13:50:14 -0700 | [diff] [blame] | 1902 | open_file = file->private_data; |
Jeff Layton | 13cfb73 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 1903 | pTcon = tlink_tcon(open_file->tlink); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1904 | |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1905 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD) |
| 1906 | pid = open_file->pid; |
| 1907 | else |
| 1908 | pid = current->tgid; |
| 1909 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | if ((file->f_flags & O_ACCMODE) == O_WRONLY) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1911 | cFYI(1, "attempting read on write only file instance"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1912 | |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1913 | for (total_read = 0, current_offset = read_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1914 | read_size > total_read; |
| 1915 | total_read += bytes_read, current_offset += bytes_read) { |
Jeff Layton | 5eba8ab | 2011-10-19 15:30:26 -0400 | [diff] [blame] | 1916 | current_read_size = min_t(uint, read_size - total_read, rsize); |
| 1917 | |
Steve French | f9f5c817 | 2005-09-15 23:06:38 -0700 | [diff] [blame] | 1918 | /* For windows me and 9x we do not want to request more |
| 1919 | than it negotiated since it will refuse the read then */ |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1920 | if ((pTcon->ses) && |
Steve French | f9f5c817 | 2005-09-15 23:06:38 -0700 | [diff] [blame] | 1921 | !(pTcon->ses->capabilities & CAP_LARGE_FILES)) { |
Dan Carpenter | 7748dd6 | 2011-10-18 12:41:35 +0300 | [diff] [blame] | 1922 | current_read_size = min_t(uint, current_read_size, |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 1923 | CIFSMaxBufSize); |
Steve French | f9f5c817 | 2005-09-15 23:06:38 -0700 | [diff] [blame] | 1924 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1925 | rc = -EAGAIN; |
| 1926 | while (rc == -EAGAIN) { |
Steve French | cdff08e | 2010-10-21 22:46:14 +0000 | [diff] [blame] | 1927 | if (open_file->invalidHandle) { |
Jeff Layton | 1588617 | 2010-10-15 15:33:59 -0400 | [diff] [blame] | 1928 | rc = cifs_reopen_file(open_file, true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | if (rc != 0) |
| 1930 | break; |
| 1931 | } |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1932 | io_parms.netfid = open_file->netfid; |
| 1933 | io_parms.pid = pid; |
| 1934 | io_parms.tcon = pTcon; |
| 1935 | io_parms.offset = *poffset; |
| 1936 | io_parms.length = current_read_size; |
| 1937 | rc = CIFSSMBRead(xid, &io_parms, &bytes_read, |
| 1938 | ¤t_offset, &buf_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1939 | } |
| 1940 | if (rc || (bytes_read == 0)) { |
| 1941 | if (total_read) { |
| 1942 | break; |
| 1943 | } else { |
| 1944 | FreeXid(xid); |
| 1945 | return rc; |
| 1946 | } |
| 1947 | } else { |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1948 | cifs_stats_bytes_read(pTcon, total_read); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1949 | *poffset += bytes_read; |
| 1950 | } |
| 1951 | } |
| 1952 | FreeXid(xid); |
| 1953 | return total_read; |
| 1954 | } |
| 1955 | |
Jeff Layton | ca83ce3 | 2011-04-12 09:13:44 -0400 | [diff] [blame] | 1956 | /* |
| 1957 | * If the page is mmap'ed into a process' page tables, then we need to make |
| 1958 | * sure that it doesn't change while being written back. |
| 1959 | */ |
| 1960 | static int |
| 1961 | cifs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) |
| 1962 | { |
| 1963 | struct page *page = vmf->page; |
| 1964 | |
| 1965 | lock_page(page); |
| 1966 | return VM_FAULT_LOCKED; |
| 1967 | } |
| 1968 | |
| 1969 | static struct vm_operations_struct cifs_file_vm_ops = { |
| 1970 | .fault = filemap_fault, |
| 1971 | .page_mkwrite = cifs_page_mkwrite, |
| 1972 | }; |
| 1973 | |
Pavel Shilovsky | 7a6a19b | 2010-12-14 11:29:51 +0300 | [diff] [blame] | 1974 | int cifs_file_strict_mmap(struct file *file, struct vm_area_struct *vma) |
| 1975 | { |
| 1976 | int rc, xid; |
| 1977 | struct inode *inode = file->f_path.dentry->d_inode; |
| 1978 | |
| 1979 | xid = GetXid(); |
| 1980 | |
Pavel Shilovsky | 6feb989 | 2011-04-07 18:18:11 +0400 | [diff] [blame] | 1981 | if (!CIFS_I(inode)->clientCanCacheRead) { |
| 1982 | rc = cifs_invalidate_mapping(inode); |
| 1983 | if (rc) |
| 1984 | return rc; |
| 1985 | } |
Pavel Shilovsky | 7a6a19b | 2010-12-14 11:29:51 +0300 | [diff] [blame] | 1986 | |
| 1987 | rc = generic_file_mmap(file, vma); |
Jeff Layton | ca83ce3 | 2011-04-12 09:13:44 -0400 | [diff] [blame] | 1988 | if (rc == 0) |
| 1989 | vma->vm_ops = &cifs_file_vm_ops; |
Pavel Shilovsky | 7a6a19b | 2010-12-14 11:29:51 +0300 | [diff] [blame] | 1990 | FreeXid(xid); |
| 1991 | return rc; |
| 1992 | } |
| 1993 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1994 | int cifs_file_mmap(struct file *file, struct vm_area_struct *vma) |
| 1995 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1996 | int rc, xid; |
| 1997 | |
| 1998 | xid = GetXid(); |
Jeff Layton | abab095 | 2010-02-12 07:44:18 -0500 | [diff] [blame] | 1999 | rc = cifs_revalidate_file(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2000 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2001 | cFYI(1, "Validation prior to mmap failed, error=%d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | FreeXid(xid); |
| 2003 | return rc; |
| 2004 | } |
| 2005 | rc = generic_file_mmap(file, vma); |
Jeff Layton | ca83ce3 | 2011-04-12 09:13:44 -0400 | [diff] [blame] | 2006 | if (rc == 0) |
| 2007 | vma->vm_ops = &cifs_file_vm_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2008 | FreeXid(xid); |
| 2009 | return rc; |
| 2010 | } |
| 2011 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2012 | static int cifs_readpages(struct file *file, struct address_space *mapping, |
| 2013 | struct list_head *page_list, unsigned num_pages) |
| 2014 | { |
Jeff Layton | 690c5e3 | 2011-10-19 15:30:16 -0400 | [diff] [blame] | 2015 | int rc; |
| 2016 | struct list_head tmplist; |
| 2017 | struct cifsFileInfo *open_file = file->private_data; |
| 2018 | struct cifs_sb_info *cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); |
| 2019 | unsigned int rsize = cifs_sb->rsize; |
| 2020 | pid_t pid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2021 | |
Jeff Layton | 690c5e3 | 2011-10-19 15:30:16 -0400 | [diff] [blame] | 2022 | /* |
| 2023 | * Give up immediately if rsize is too small to read an entire page. |
| 2024 | * The VFS will fall back to readpage. We should never reach this |
| 2025 | * point however since we set ra_pages to 0 when the rsize is smaller |
| 2026 | * than a cache page. |
| 2027 | */ |
| 2028 | if (unlikely(rsize < PAGE_CACHE_SIZE)) |
| 2029 | return 0; |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 2030 | |
Suresh Jayaraman | 5669823 | 2010-07-05 18:13:25 +0530 | [diff] [blame] | 2031 | /* |
| 2032 | * Reads as many pages as possible from fscache. Returns -ENOBUFS |
| 2033 | * immediately if the cookie is negative |
| 2034 | */ |
| 2035 | rc = cifs_readpages_from_fscache(mapping->host, mapping, page_list, |
| 2036 | &num_pages); |
| 2037 | if (rc == 0) |
Jeff Layton | 690c5e3 | 2011-10-19 15:30:16 -0400 | [diff] [blame] | 2038 | return rc; |
Suresh Jayaraman | 5669823 | 2010-07-05 18:13:25 +0530 | [diff] [blame] | 2039 | |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 2040 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD) |
| 2041 | pid = open_file->pid; |
| 2042 | else |
| 2043 | pid = current->tgid; |
| 2044 | |
Jeff Layton | 690c5e3 | 2011-10-19 15:30:16 -0400 | [diff] [blame] | 2045 | rc = 0; |
| 2046 | INIT_LIST_HEAD(&tmplist); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2047 | |
Jeff Layton | 690c5e3 | 2011-10-19 15:30:16 -0400 | [diff] [blame] | 2048 | cFYI(1, "%s: file=%p mapping=%p num_pages=%u", __func__, file, |
| 2049 | mapping, num_pages); |
| 2050 | |
| 2051 | /* |
| 2052 | * Start with the page at end of list and move it to private |
| 2053 | * list. Do the same with any following pages until we hit |
| 2054 | * the rsize limit, hit an index discontinuity, or run out of |
| 2055 | * pages. Issue the async read and then start the loop again |
| 2056 | * until the list is empty. |
| 2057 | * |
| 2058 | * Note that list order is important. The page_list is in |
| 2059 | * the order of declining indexes. When we put the pages in |
| 2060 | * the rdata->pages, then we want them in increasing order. |
| 2061 | */ |
| 2062 | while (!list_empty(page_list)) { |
| 2063 | unsigned int bytes = PAGE_CACHE_SIZE; |
| 2064 | unsigned int expected_index; |
| 2065 | unsigned int nr_pages = 1; |
| 2066 | loff_t offset; |
| 2067 | struct page *page, *tpage; |
| 2068 | struct cifs_readdata *rdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2069 | |
| 2070 | page = list_entry(page_list->prev, struct page, lru); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2071 | |
Jeff Layton | 690c5e3 | 2011-10-19 15:30:16 -0400 | [diff] [blame] | 2072 | /* |
| 2073 | * Lock the page and put it in the cache. Since no one else |
| 2074 | * should have access to this page, we're safe to simply set |
| 2075 | * PG_locked without checking it first. |
| 2076 | */ |
| 2077 | __set_page_locked(page); |
| 2078 | rc = add_to_page_cache_locked(page, mapping, |
| 2079 | page->index, GFP_KERNEL); |
| 2080 | |
| 2081 | /* give up if we can't stick it in the cache */ |
| 2082 | if (rc) { |
| 2083 | __clear_page_locked(page); |
| 2084 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2085 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2086 | |
Jeff Layton | 690c5e3 | 2011-10-19 15:30:16 -0400 | [diff] [blame] | 2087 | /* move first page to the tmplist */ |
| 2088 | offset = (loff_t)page->index << PAGE_CACHE_SHIFT; |
| 2089 | list_move_tail(&page->lru, &tmplist); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2090 | |
Jeff Layton | 690c5e3 | 2011-10-19 15:30:16 -0400 | [diff] [blame] | 2091 | /* now try and add more pages onto the request */ |
| 2092 | expected_index = page->index + 1; |
| 2093 | list_for_each_entry_safe_reverse(page, tpage, page_list, lru) { |
| 2094 | /* discontinuity ? */ |
| 2095 | if (page->index != expected_index) |
| 2096 | break; |
| 2097 | |
| 2098 | /* would this page push the read over the rsize? */ |
| 2099 | if (bytes + PAGE_CACHE_SIZE > rsize) |
| 2100 | break; |
| 2101 | |
| 2102 | __set_page_locked(page); |
| 2103 | if (add_to_page_cache_locked(page, mapping, |
| 2104 | page->index, GFP_KERNEL)) { |
| 2105 | __clear_page_locked(page); |
| 2106 | break; |
| 2107 | } |
| 2108 | list_move_tail(&page->lru, &tmplist); |
| 2109 | bytes += PAGE_CACHE_SIZE; |
| 2110 | expected_index++; |
| 2111 | nr_pages++; |
| 2112 | } |
| 2113 | |
| 2114 | rdata = cifs_readdata_alloc(nr_pages); |
| 2115 | if (!rdata) { |
| 2116 | /* best to give up if we're out of mem */ |
| 2117 | list_for_each_entry_safe(page, tpage, &tmplist, lru) { |
| 2118 | list_del(&page->lru); |
| 2119 | lru_cache_add_file(page); |
| 2120 | unlock_page(page); |
| 2121 | page_cache_release(page); |
| 2122 | } |
| 2123 | rc = -ENOMEM; |
| 2124 | break; |
| 2125 | } |
| 2126 | |
| 2127 | spin_lock(&cifs_file_list_lock); |
| 2128 | cifsFileInfo_get(open_file); |
| 2129 | spin_unlock(&cifs_file_list_lock); |
| 2130 | rdata->cfile = open_file; |
| 2131 | rdata->mapping = mapping; |
| 2132 | rdata->offset = offset; |
| 2133 | rdata->bytes = bytes; |
| 2134 | rdata->pid = pid; |
| 2135 | list_splice_init(&tmplist, &rdata->pages); |
| 2136 | |
| 2137 | do { |
Steve French | cdff08e | 2010-10-21 22:46:14 +0000 | [diff] [blame] | 2138 | if (open_file->invalidHandle) { |
Jeff Layton | 1588617 | 2010-10-15 15:33:59 -0400 | [diff] [blame] | 2139 | rc = cifs_reopen_file(open_file, true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2140 | if (rc != 0) |
Jeff Layton | 690c5e3 | 2011-10-19 15:30:16 -0400 | [diff] [blame] | 2141 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2142 | } |
Jeff Layton | 690c5e3 | 2011-10-19 15:30:16 -0400 | [diff] [blame] | 2143 | rc = cifs_async_readv(rdata); |
| 2144 | } while (rc == -EAGAIN); |
| 2145 | |
| 2146 | if (rc != 0) { |
| 2147 | list_for_each_entry_safe(page, tpage, &rdata->pages, |
| 2148 | lru) { |
| 2149 | list_del(&page->lru); |
| 2150 | lru_cache_add_file(page); |
| 2151 | unlock_page(page); |
| 2152 | page_cache_release(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2153 | } |
Jeff Layton | 690c5e3 | 2011-10-19 15:30:16 -0400 | [diff] [blame] | 2154 | cifs_readdata_free(rdata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2155 | break; |
| 2156 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2157 | } |
| 2158 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2159 | return rc; |
| 2160 | } |
| 2161 | |
| 2162 | static int cifs_readpage_worker(struct file *file, struct page *page, |
| 2163 | loff_t *poffset) |
| 2164 | { |
| 2165 | char *read_data; |
| 2166 | int rc; |
| 2167 | |
Suresh Jayaraman | 5669823 | 2010-07-05 18:13:25 +0530 | [diff] [blame] | 2168 | /* Is the page cached? */ |
| 2169 | rc = cifs_readpage_from_fscache(file->f_path.dentry->d_inode, page); |
| 2170 | if (rc == 0) |
| 2171 | goto read_complete; |
| 2172 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2173 | page_cache_get(page); |
| 2174 | read_data = kmap(page); |
| 2175 | /* for reads over a certain size could initiate async read ahead */ |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 2176 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2177 | rc = cifs_read(file, read_data, PAGE_CACHE_SIZE, poffset); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 2178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2179 | if (rc < 0) |
| 2180 | goto io_error; |
| 2181 | else |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2182 | cFYI(1, "Bytes read %d", rc); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 2183 | |
Josef "Jeff" Sipek | e6a0029 | 2006-12-08 02:36:48 -0800 | [diff] [blame] | 2184 | file->f_path.dentry->d_inode->i_atime = |
| 2185 | current_fs_time(file->f_path.dentry->d_inode->i_sb); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 2186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2187 | if (PAGE_CACHE_SIZE > rc) |
| 2188 | memset(read_data + rc, 0, PAGE_CACHE_SIZE - rc); |
| 2189 | |
| 2190 | flush_dcache_page(page); |
| 2191 | SetPageUptodate(page); |
Suresh Jayaraman | 9dc0655 | 2010-07-05 18:13:11 +0530 | [diff] [blame] | 2192 | |
| 2193 | /* send this page to the cache */ |
| 2194 | cifs_readpage_to_fscache(file->f_path.dentry->d_inode, page); |
| 2195 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2196 | rc = 0; |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 2197 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2198 | io_error: |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 2199 | kunmap(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2200 | page_cache_release(page); |
Suresh Jayaraman | 5669823 | 2010-07-05 18:13:25 +0530 | [diff] [blame] | 2201 | |
| 2202 | read_complete: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2203 | return rc; |
| 2204 | } |
| 2205 | |
| 2206 | static int cifs_readpage(struct file *file, struct page *page) |
| 2207 | { |
| 2208 | loff_t offset = (loff_t)page->index << PAGE_CACHE_SHIFT; |
| 2209 | int rc = -EACCES; |
| 2210 | int xid; |
| 2211 | |
| 2212 | xid = GetXid(); |
| 2213 | |
| 2214 | if (file->private_data == NULL) { |
Suresh Jayaraman | 0f3bc09 | 2009-06-25 18:12:34 +0530 | [diff] [blame] | 2215 | rc = -EBADF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2216 | FreeXid(xid); |
Suresh Jayaraman | 0f3bc09 | 2009-06-25 18:12:34 +0530 | [diff] [blame] | 2217 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2218 | } |
| 2219 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2220 | cFYI(1, "readpage %p at offset %d 0x%x\n", |
| 2221 | page, (int)offset, (int)offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2222 | |
| 2223 | rc = cifs_readpage_worker(file, page, &offset); |
| 2224 | |
| 2225 | unlock_page(page); |
| 2226 | |
| 2227 | FreeXid(xid); |
| 2228 | return rc; |
| 2229 | } |
| 2230 | |
Steve French | a403a0a | 2007-07-26 15:54:16 +0000 | [diff] [blame] | 2231 | static int is_inode_writable(struct cifsInodeInfo *cifs_inode) |
| 2232 | { |
| 2233 | struct cifsFileInfo *open_file; |
| 2234 | |
Jeff Layton | 4477288 | 2010-10-15 15:34:03 -0400 | [diff] [blame] | 2235 | spin_lock(&cifs_file_list_lock); |
Steve French | a403a0a | 2007-07-26 15:54:16 +0000 | [diff] [blame] | 2236 | list_for_each_entry(open_file, &cifs_inode->openFileList, flist) { |
Jeff Layton | 2e396b8 | 2010-10-15 15:34:01 -0400 | [diff] [blame] | 2237 | if (OPEN_FMODE(open_file->f_flags) & FMODE_WRITE) { |
Jeff Layton | 4477288 | 2010-10-15 15:34:03 -0400 | [diff] [blame] | 2238 | spin_unlock(&cifs_file_list_lock); |
Steve French | a403a0a | 2007-07-26 15:54:16 +0000 | [diff] [blame] | 2239 | return 1; |
| 2240 | } |
| 2241 | } |
Jeff Layton | 4477288 | 2010-10-15 15:34:03 -0400 | [diff] [blame] | 2242 | spin_unlock(&cifs_file_list_lock); |
Steve French | a403a0a | 2007-07-26 15:54:16 +0000 | [diff] [blame] | 2243 | return 0; |
| 2244 | } |
| 2245 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2246 | /* We do not want to update the file size from server for inodes |
| 2247 | open for write - to avoid races with writepage extending |
| 2248 | the file - in the future we could consider allowing |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 2249 | refreshing the inode only on increases in the file size |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2250 | but this is tricky to do without racing with writebehind |
| 2251 | page caching in the current Linux kernel design */ |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 2252 | bool is_size_safe_to_change(struct cifsInodeInfo *cifsInode, __u64 end_of_file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2253 | { |
Steve French | a403a0a | 2007-07-26 15:54:16 +0000 | [diff] [blame] | 2254 | if (!cifsInode) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 2255 | return true; |
Steve French | 23e7dd7 | 2005-10-20 13:44:56 -0700 | [diff] [blame] | 2256 | |
Steve French | a403a0a | 2007-07-26 15:54:16 +0000 | [diff] [blame] | 2257 | if (is_inode_writable(cifsInode)) { |
| 2258 | /* This inode is open for write at least once */ |
Steve French | c32a0b6 | 2006-01-12 14:41:28 -0800 | [diff] [blame] | 2259 | struct cifs_sb_info *cifs_sb; |
| 2260 | |
Steve French | c32a0b6 | 2006-01-12 14:41:28 -0800 | [diff] [blame] | 2261 | cifs_sb = CIFS_SB(cifsInode->vfs_inode.i_sb); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2262 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO) { |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 2263 | /* since no page cache to corrupt on directio |
Steve French | c32a0b6 | 2006-01-12 14:41:28 -0800 | [diff] [blame] | 2264 | we can change size safely */ |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 2265 | return true; |
Steve French | c32a0b6 | 2006-01-12 14:41:28 -0800 | [diff] [blame] | 2266 | } |
| 2267 | |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 2268 | if (i_size_read(&cifsInode->vfs_inode) < end_of_file) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 2269 | return true; |
Steve French | 7ba5263 | 2007-02-08 18:14:13 +0000 | [diff] [blame] | 2270 | |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 2271 | return false; |
Steve French | 23e7dd7 | 2005-10-20 13:44:56 -0700 | [diff] [blame] | 2272 | } else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 2273 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2274 | } |
| 2275 | |
Nick Piggin | d941477 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2276 | static int cifs_write_begin(struct file *file, struct address_space *mapping, |
| 2277 | loff_t pos, unsigned len, unsigned flags, |
| 2278 | struct page **pagep, void **fsdata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 | { |
Nick Piggin | d941477 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2280 | pgoff_t index = pos >> PAGE_CACHE_SHIFT; |
| 2281 | loff_t offset = pos & (PAGE_CACHE_SIZE - 1); |
Jeff Layton | a98ee8c | 2008-11-26 19:32:33 +0000 | [diff] [blame] | 2282 | loff_t page_start = pos & PAGE_MASK; |
| 2283 | loff_t i_size; |
| 2284 | struct page *page; |
| 2285 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2287 | cFYI(1, "write_begin from %lld len %d", (long long)pos, len); |
Nick Piggin | d941477 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2288 | |
Nick Piggin | 54566b2 | 2009-01-04 12:00:53 -0800 | [diff] [blame] | 2289 | page = grab_cache_page_write_begin(mapping, index, flags); |
Jeff Layton | a98ee8c | 2008-11-26 19:32:33 +0000 | [diff] [blame] | 2290 | if (!page) { |
| 2291 | rc = -ENOMEM; |
| 2292 | goto out; |
| 2293 | } |
Nick Piggin | d941477 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2294 | |
Jeff Layton | a98ee8c | 2008-11-26 19:32:33 +0000 | [diff] [blame] | 2295 | if (PageUptodate(page)) |
| 2296 | goto out; |
Steve French | 8a23626 | 2007-03-06 00:31:00 +0000 | [diff] [blame] | 2297 | |
Jeff Layton | a98ee8c | 2008-11-26 19:32:33 +0000 | [diff] [blame] | 2298 | /* |
| 2299 | * If we write a full page it will be up to date, no need to read from |
| 2300 | * the server. If the write is short, we'll end up doing a sync write |
| 2301 | * instead. |
| 2302 | */ |
| 2303 | if (len == PAGE_CACHE_SIZE) |
| 2304 | goto out; |
| 2305 | |
| 2306 | /* |
| 2307 | * optimize away the read when we have an oplock, and we're not |
| 2308 | * expecting to use any of the data we'd be reading in. That |
| 2309 | * is, when the page lies beyond the EOF, or straddles the EOF |
| 2310 | * and the write will cover all of the existing data. |
| 2311 | */ |
| 2312 | if (CIFS_I(mapping->host)->clientCanCacheRead) { |
| 2313 | i_size = i_size_read(mapping->host); |
| 2314 | if (page_start >= i_size || |
| 2315 | (offset == 0 && (pos + len) >= i_size)) { |
| 2316 | zero_user_segments(page, 0, offset, |
| 2317 | offset + len, |
| 2318 | PAGE_CACHE_SIZE); |
| 2319 | /* |
| 2320 | * PageChecked means that the parts of the page |
| 2321 | * to which we're not writing are considered up |
| 2322 | * to date. Once the data is copied to the |
| 2323 | * page, it can be set uptodate. |
| 2324 | */ |
| 2325 | SetPageChecked(page); |
| 2326 | goto out; |
| 2327 | } |
| 2328 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2329 | |
Nick Piggin | d941477 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2330 | if ((file->f_flags & O_ACCMODE) != O_WRONLY) { |
Jeff Layton | a98ee8c | 2008-11-26 19:32:33 +0000 | [diff] [blame] | 2331 | /* |
| 2332 | * might as well read a page, it is fast enough. If we get |
| 2333 | * an error, we don't need to return it. cifs_write_end will |
| 2334 | * do a sync write instead since PG_uptodate isn't set. |
| 2335 | */ |
| 2336 | cifs_readpage_worker(file, page, &page_start); |
Steve French | 8a23626 | 2007-03-06 00:31:00 +0000 | [diff] [blame] | 2337 | } else { |
| 2338 | /* we could try using another file handle if there is one - |
| 2339 | but how would we lock it to prevent close of that handle |
| 2340 | racing with this read? In any case |
Nick Piggin | d941477 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2341 | this will be written out by write_end so is fine */ |
Steve French | 8a23626 | 2007-03-06 00:31:00 +0000 | [diff] [blame] | 2342 | } |
Jeff Layton | a98ee8c | 2008-11-26 19:32:33 +0000 | [diff] [blame] | 2343 | out: |
| 2344 | *pagep = page; |
| 2345 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2346 | } |
| 2347 | |
Suresh Jayaraman | 85f2d6b | 2010-07-05 18:13:00 +0530 | [diff] [blame] | 2348 | static int cifs_release_page(struct page *page, gfp_t gfp) |
| 2349 | { |
| 2350 | if (PagePrivate(page)) |
| 2351 | return 0; |
| 2352 | |
| 2353 | return cifs_fscache_release_page(page, gfp); |
| 2354 | } |
| 2355 | |
| 2356 | static void cifs_invalidate_page(struct page *page, unsigned long offset) |
| 2357 | { |
| 2358 | struct cifsInodeInfo *cifsi = CIFS_I(page->mapping->host); |
| 2359 | |
| 2360 | if (offset == 0) |
| 2361 | cifs_fscache_invalidate_page(page, &cifsi->vfs_inode); |
| 2362 | } |
| 2363 | |
Pavel Shilovsky | 9ad1506 | 2011-04-08 05:29:10 +0400 | [diff] [blame] | 2364 | static int cifs_launder_page(struct page *page) |
| 2365 | { |
| 2366 | int rc = 0; |
| 2367 | loff_t range_start = page_offset(page); |
| 2368 | loff_t range_end = range_start + (loff_t)(PAGE_CACHE_SIZE - 1); |
| 2369 | struct writeback_control wbc = { |
| 2370 | .sync_mode = WB_SYNC_ALL, |
| 2371 | .nr_to_write = 0, |
| 2372 | .range_start = range_start, |
| 2373 | .range_end = range_end, |
| 2374 | }; |
| 2375 | |
| 2376 | cFYI(1, "Launder page: %p", page); |
| 2377 | |
| 2378 | if (clear_page_dirty_for_io(page)) |
| 2379 | rc = cifs_writepage_locked(page, &wbc); |
| 2380 | |
| 2381 | cifs_fscache_invalidate_page(page, page->mapping->host); |
| 2382 | return rc; |
| 2383 | } |
| 2384 | |
Tejun Heo | 9b64697 | 2010-07-20 22:09:02 +0200 | [diff] [blame] | 2385 | void cifs_oplock_break(struct work_struct *work) |
Jeff Layton | 3bc303c | 2009-09-21 06:47:50 -0400 | [diff] [blame] | 2386 | { |
| 2387 | struct cifsFileInfo *cfile = container_of(work, struct cifsFileInfo, |
| 2388 | oplock_break); |
Jeff Layton | a5e18bc | 2010-10-11 15:07:18 -0400 | [diff] [blame] | 2389 | struct inode *inode = cfile->dentry->d_inode; |
Jeff Layton | 3bc303c | 2009-09-21 06:47:50 -0400 | [diff] [blame] | 2390 | struct cifsInodeInfo *cinode = CIFS_I(inode); |
Jeff Layton | eb4b756 | 2010-10-22 14:52:29 -0400 | [diff] [blame] | 2391 | int rc = 0; |
Jeff Layton | 3bc303c | 2009-09-21 06:47:50 -0400 | [diff] [blame] | 2392 | |
| 2393 | if (inode && S_ISREG(inode->i_mode)) { |
Steve French | d54ff73 | 2010-04-27 04:38:15 +0000 | [diff] [blame] | 2394 | if (cinode->clientCanCacheRead) |
Al Viro | 8737c93 | 2009-12-24 06:47:55 -0500 | [diff] [blame] | 2395 | break_lease(inode, O_RDONLY); |
Steve French | d54ff73 | 2010-04-27 04:38:15 +0000 | [diff] [blame] | 2396 | else |
Al Viro | 8737c93 | 2009-12-24 06:47:55 -0500 | [diff] [blame] | 2397 | break_lease(inode, O_WRONLY); |
Jeff Layton | 3bc303c | 2009-09-21 06:47:50 -0400 | [diff] [blame] | 2398 | rc = filemap_fdatawrite(inode->i_mapping); |
| 2399 | if (cinode->clientCanCacheRead == 0) { |
Jeff Layton | eb4b756 | 2010-10-22 14:52:29 -0400 | [diff] [blame] | 2400 | rc = filemap_fdatawait(inode->i_mapping); |
| 2401 | mapping_set_error(inode->i_mapping, rc); |
Jeff Layton | 3bc303c | 2009-09-21 06:47:50 -0400 | [diff] [blame] | 2402 | invalidate_remote_inode(inode); |
| 2403 | } |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2404 | cFYI(1, "Oplock flush inode %p rc %d", inode, rc); |
Jeff Layton | 3bc303c | 2009-09-21 06:47:50 -0400 | [diff] [blame] | 2405 | } |
| 2406 | |
| 2407 | /* |
| 2408 | * releasing stale oplock after recent reconnect of smb session using |
| 2409 | * a now incorrect file handle is not a data integrity issue but do |
| 2410 | * not bother sending an oplock release if session to server still is |
| 2411 | * disconnected since oplock already released by the server |
| 2412 | */ |
Steve French | cdff08e | 2010-10-21 22:46:14 +0000 | [diff] [blame] | 2413 | if (!cfile->oplock_break_cancelled) { |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 2414 | rc = CIFSSMBLock(0, tlink_tcon(cfile->tlink), cfile->netfid, |
| 2415 | current->tgid, 0, 0, 0, 0, |
| 2416 | LOCKING_ANDX_OPLOCK_RELEASE, false, |
Pavel Shilovsky | 12fed00 | 2011-01-17 20:15:44 +0300 | [diff] [blame] | 2417 | cinode->clientCanCacheRead ? 1 : 0); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2418 | cFYI(1, "Oplock release rc = %d", rc); |
Jeff Layton | 3bc303c | 2009-09-21 06:47:50 -0400 | [diff] [blame] | 2419 | } |
Jeff Layton | 3bc303c | 2009-09-21 06:47:50 -0400 | [diff] [blame] | 2420 | } |
| 2421 | |
Christoph Hellwig | f5e54d6 | 2006-06-28 04:26:44 -0700 | [diff] [blame] | 2422 | const struct address_space_operations cifs_addr_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2423 | .readpage = cifs_readpage, |
| 2424 | .readpages = cifs_readpages, |
| 2425 | .writepage = cifs_writepage, |
Steve French | 37c0eb4 | 2005-10-05 14:50:29 -0700 | [diff] [blame] | 2426 | .writepages = cifs_writepages, |
Nick Piggin | d941477 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2427 | .write_begin = cifs_write_begin, |
| 2428 | .write_end = cifs_write_end, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2429 | .set_page_dirty = __set_page_dirty_nobuffers, |
Suresh Jayaraman | 85f2d6b | 2010-07-05 18:13:00 +0530 | [diff] [blame] | 2430 | .releasepage = cifs_release_page, |
| 2431 | .invalidatepage = cifs_invalidate_page, |
Pavel Shilovsky | 9ad1506 | 2011-04-08 05:29:10 +0400 | [diff] [blame] | 2432 | .launder_page = cifs_launder_page, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2433 | }; |
Dave Kleikamp | 273d81d | 2006-06-01 19:41:23 +0000 | [diff] [blame] | 2434 | |
| 2435 | /* |
| 2436 | * cifs_readpages requires the server to support a buffer large enough to |
| 2437 | * contain the header plus one complete page of data. Otherwise, we need |
| 2438 | * to leave cifs_readpages out of the address space operations. |
| 2439 | */ |
Christoph Hellwig | f5e54d6 | 2006-06-28 04:26:44 -0700 | [diff] [blame] | 2440 | const struct address_space_operations cifs_addr_ops_smallbuf = { |
Dave Kleikamp | 273d81d | 2006-06-01 19:41:23 +0000 | [diff] [blame] | 2441 | .readpage = cifs_readpage, |
| 2442 | .writepage = cifs_writepage, |
| 2443 | .writepages = cifs_writepages, |
Nick Piggin | d941477 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2444 | .write_begin = cifs_write_begin, |
| 2445 | .write_end = cifs_write_end, |
Dave Kleikamp | 273d81d | 2006-06-01 19:41:23 +0000 | [diff] [blame] | 2446 | .set_page_dirty = __set_page_dirty_nobuffers, |
Suresh Jayaraman | 85f2d6b | 2010-07-05 18:13:00 +0530 | [diff] [blame] | 2447 | .releasepage = cifs_release_page, |
| 2448 | .invalidatepage = cifs_invalidate_page, |
Pavel Shilovsky | 9ad1506 | 2011-04-08 05:29:10 +0400 | [diff] [blame] | 2449 | .launder_page = cifs_launder_page, |
Dave Kleikamp | 273d81d | 2006-06-01 19:41:23 +0000 | [diff] [blame] | 2450 | }; |