@@ -575,8 +575,54 @@ cifs_do_mount(struct file_system_type *fs_type,
static ssize_t cifs_strict_read(struct kiocb *iocb, const struct iovec *iov,
unsigned long nr_segs, loff_t pos)
{
- ssize_t read = 0;
- /* BB */
+ struct inode *inode;
+ struct cifs_sb_info *cifs_sb;
+ ssize_t read;
+ unsigned long i, len = 0;
+ char *buf, *offset;
+
+ inode = iocb->ki_filp->f_path.dentry->d_inode;
+ cifs_sb = CIFS_SB(iocb->ki_filp->f_path.dentry->d_sb);
+
+ if (CIFS_I(inode)->clientCanCacheRead)
+ return generic_file_aio_read(iocb, iov, nr_segs, pos);
+
+ /*
+ * In strict cache mode we need to read from the server all the time
+ * if we don't have level II oplock because the server can delay mtime
+ * change - so we can't make a decision about inode invalidating.
+ * And we can also fail with pagereading if there are mandatory locks
+ * on pages affected by this read but not on the region from pos to
+ * pos+len-1.
+ */
+
+ for (i = 0; i < nr_segs; i++)
+ len += iov[i].iov_len;
+
+ buf = kmalloc(len, GFP_KERNEL);
+
+ read = cifs_read(iocb->ki_filp, buf, len, &pos);
+ if (read < 0) {
+ kfree(buf);
+ return read;
+ }
+
+ for (i = 0, offset = buf, len = read; i < nr_segs && len; i++) {
+ unsigned long cur_len = min_t(unsigned long, len,
+ iov[i].iov_len);
+
+ if (copy_to_user(iov[i].iov_base, offset, cur_len)) {
+ kfree(buf);
+ return -EFAULT;
+ }
+
+ len -= cur_len;
+ offset += cur_len;
+ }
+
+ iocb->ki_pos = pos;
+
+ kfree(buf);
return read;
}
@@ -79,6 +79,8 @@ extern int checkSMB(struct smb_hdr *smb, __u16 mid, unsigned int length);
extern bool is_valid_oplock_break(struct smb_hdr *smb,
struct TCP_Server_Info *);
extern bool is_size_safe_to_change(struct cifsInodeInfo *, __u64 eof);
+extern ssize_t cifs_read(struct file *file, char *read_data, size_t read_size,
+ loff_t *poffset);
extern struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *, bool);
extern struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *, bool);
extern unsigned int smbCalcSize(struct smb_hdr *ptr);
@@ -1758,8 +1758,8 @@ ssize_t cifs_user_read(struct file *file, char __user *read_data,
}
-static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size,
- loff_t *poffset)
+ssize_t cifs_read(struct file *file, char *read_data, size_t read_size,
+ loff_t *poffset)
{
int rc = -EACCES;
unsigned int bytes_read = 0;