Skip to contentSkip to conversation

CIFS: Implement cifs_file_strict_mmap (try #2)

PATCH In review Pavel Shilovsky 2 participants 5 messages Dec 16, 2010 – Dec 22, 2010 3 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 3/6 CIFS: Implement cifs_file_strict_mmap (try #2)

From: Pavel Shilovsky <[email protected]>

Invalidate inode mapping if we don't have at least Level II oplock.

---
 fs/cifs/cifsfs.c |    4 ++--
 fs/cifs/cifsfs.h |    1 +
 fs/cifs/file.c   |   15 +++++++++++++++
 3 files changed, 18 insertions(+), 2 deletions(-)
fs/cifs/cifsfs.c +2 -2
index 7660133..a218afe 100644
@@ -720,7 +720,7 @@ const struct file_operations cifs_file_strict_ops = {
 	.lock = cifs_lock,
 	.fsync = cifs_strict_fsync,
 	.flush = cifs_flush,
-	.mmap = cifs_file_mmap,
+	.mmap = cifs_file_strict_mmap,
 	.splice_read = generic_file_splice_read,
 	.llseek = cifs_llseek,
 #ifdef CONFIG_CIFS_POSIX
@@ -775,7 +775,7 @@ const struct file_operations cifs_file_strict_nobrl_ops = {
 	.release = cifs_close,
 	.fsync = cifs_strict_fsync,
 	.flush = cifs_flush,
-	.mmap = cifs_file_mmap,
+	.mmap = cifs_file_strict_mmap,
 	.splice_read = generic_file_splice_read,
 	.llseek = cifs_llseek,
 #ifdef CONFIG_CIFS_POSIX
fs/cifs/cifsfs.h +1 -0
index 8584829..657738f 100644
@@ -89,6 +89,7 @@ extern int cifs_fsync(struct file *, int);
 extern int cifs_strict_fsync(struct file *, int);
 extern int cifs_flush(struct file *, fl_owner_t id);
 extern int cifs_file_mmap(struct file * , struct vm_area_struct *);
+extern int cifs_file_strict_mmap(struct file * , struct vm_area_struct *);
 extern const struct file_operations cifs_dir_ops;
 extern int cifs_dir_open(struct inode *inode, struct file *file);
 extern int cifs_readdir(struct file *file, void *direntry, filldir_t filldir);
fs/cifs/file.c +15 -0
index 4e37cb8..d48723c 100644
@@ -1827,6 +1827,21 @@ static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size,
 	return total_read;
 }
 
+int cifs_file_strict_mmap(struct file *file, struct vm_area_struct *vma)
+{
+	int rc, xid;
+	struct inode *inode = file->f_path.dentry->d_inode;
+
+	xid = GetXid();
+
+	if (!CIFS_I(inode)->clientCanCacheRead)
+		cifs_invalidate_mapping(inode);
+
+	rc = generic_file_mmap(file, vma);
+	FreeXid(xid);
+	return rc;
+}
+
 int cifs_file_mmap(struct file *file, struct vm_area_struct *vma)
 {
 	int rc, xid;
Signature · 1 line
1.7.3.2

A message that is not in the archive (sent off-list or not yet received): 1292521052-5388-1-git-send-email-piastry-7qunaywFIewox3rIn2DAYQ@public.gmane.org

#2 lore raw

PATCH 4/6 CIFS: Implement cifs_strict_read (try #2)

From: Pavel Shilovsky <[email protected]>

Read from the cache if we have at least Level II oplock - otherwise read from the server. Add cifs_user_readv to let the client read into several buffers.

---
 fs/cifs/cifsfs.c |   38 ++++++++++++++++++-
 fs/cifs/cifsfs.h |    4 +-
 fs/cifs/file.c   |  108 +++++++++++++++++++++++++++++++++++++++---------------
 3 files changed, 117 insertions(+), 33 deletions(-)
fs/cifs/cifsfs.c +36 -2
index a218afe..bcb4d2c 100644
@@ -572,6 +572,40 @@ cifs_do_mount(struct file_system_type *fs_type,
 	return dget(sb->s_root);
 }
 
+static ssize_t cifs_strict_read(struct kiocb *iocb, const struct iovec *iov,
+				unsigned long nr_segs, loff_t pos)
+{
+	struct inode *inode;
+	struct cifs_sb_info *cifs_sb;
+	ssize_t read = 0;
+
+	if (!nr_segs)
+		return read;
+
+	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.
+	 */
+
+	read = cifs_user_readv(iocb->ki_filp, iov, nr_segs, &pos);
+	if (read < 0)
+		return read;
+
+	iocb->ki_pos = pos;
+
+	return read;
+}
+
 static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
 				   unsigned long nr_segs, loff_t pos)
 {
@@ -713,7 +747,7 @@ const struct file_operations cifs_file_ops = {
 const struct file_operations cifs_file_strict_ops = {
 	.read = do_sync_read,
 	.write = do_sync_write,
-	.aio_read = generic_file_aio_read,
+	.aio_read = cifs_strict_read,
 	.aio_write = cifs_file_aio_write,
 	.open = cifs_open,
 	.release = cifs_close,
@@ -769,7 +803,7 @@ const struct file_operations cifs_file_nobrl_ops = {
 const struct file_operations cifs_file_strict_nobrl_ops = {
 	.read = do_sync_read,
 	.write = do_sync_write,
-	.aio_read = generic_file_aio_read,
+	.aio_read = cifs_strict_read,
 	.aio_write = cifs_file_aio_write,
 	.open = cifs_open,
 	.release = cifs_close,
fs/cifs/cifsfs.h +3 -1
index 657738f..f690d1c 100644
@@ -81,7 +81,9 @@ extern int cifs_open(struct inode *inode, struct file *file);
 extern int cifs_close(struct inode *inode, struct file *file);
 extern int cifs_closedir(struct inode *inode, struct file *file);
 extern ssize_t cifs_user_read(struct file *file, char __user *read_data,
-			 size_t read_size, loff_t *poffset);
+			      size_t read_size, loff_t *poffset);
+extern ssize_t cifs_user_readv(struct file *file, const struct iovec *iov,
+			       unsigned long nr_segs, loff_t *poffset);
 extern ssize_t cifs_user_write(struct file *file, const char __user *write_data,
 			 size_t write_size, loff_t *poffset);
 extern int cifs_lock(struct file *, int, struct file_lock *);
fs/cifs/file.c +78 -30

156 lines not on this page · raw message

Signature · 1 line
1.7.3.2

A message that is not in the archive (sent off-list or not yet received): 1292521052-5388-2-git-send-email-piastry-7qunaywFIewox3rIn2DAYQ@public.gmane.org

Reviewed-by
#4 lore raw

Re: [PATCH 4/6] CIFS: Implement cifs_strict_read (try #2)

Quoted 96 lines · On Thu, 16 Dec 2010 20:37:32 +0300 Pavel Shilovsky…

From: Pavel Shilovsky <[email protected]>

Read from the cache if we have at least Level II oplock - otherwise read from the server. Add cifs_user_readv to let the client read into several buffers.

---
 fs/cifs/cifsfs.c |   38 ++++++++++++++++++-
 fs/cifs/cifsfs.h |    4 +-
 fs/cifs/file.c   |  108 +++++++++++++++++++++++++++++++++++++++---------------
 3 files changed, 117 insertions(+), 33 deletions(-)
fs/cifs/cifsfs.c +36 -2
index a218afe..bcb4d2c 100644
@@ -572,6 +572,40 @@ cifs_do_mount(struct file_system_type *fs_type,
 	return dget(sb->s_root);
 }
 
+static ssize_t cifs_strict_read(struct kiocb *iocb, const struct iovec *iov,
+				unsigned long nr_segs, loff_t pos)
+{
+	struct inode *inode;
+	struct cifs_sb_info *cifs_sb;
+	ssize_t read = 0;
+
+	if (!nr_segs)
+		return read;
+
+	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.
+	 */
+
+	read = cifs_user_readv(iocb->ki_filp, iov, nr_segs, &pos);
+	if (read < 0)
+		return read;
+
+	iocb->ki_pos = pos;
+
+	return read;
+}
+
 static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
 				   unsigned long nr_segs, loff_t pos)
 {
@@ -713,7 +747,7 @@ const struct file_operations cifs_file_ops = {
 const struct file_operations cifs_file_strict_ops = {
 	.read = do_sync_read,
 	.write = do_sync_write,
-	.aio_read = generic_file_aio_read,
+	.aio_read = cifs_strict_read,
 	.aio_write = cifs_file_aio_write,
 	.open = cifs_open,
 	.release = cifs_close,
@@ -769,7 +803,7 @@ const struct file_operations cifs_file_nobrl_ops = {
 const struct file_operations cifs_file_strict_nobrl_ops = {
 	.read = do_sync_read,
 	.write = do_sync_write,
-	.aio_read = generic_file_aio_read,
+	.aio_read = cifs_strict_read,
 	.aio_write = cifs_file_aio_write,
 	.open = cifs_open,
 	.release = cifs_close,
fs/cifs/cifsfs.h +3 -1
index 657738f..f690d1c 100644
@@ -81,7 +81,9 @@ extern int cifs_open(struct inode *inode, struct file *file);
 extern int cifs_close(struct inode *inode, struct file *file);
 extern int cifs_closedir(struct inode *inode, struct file *file);
 extern ssize_t cifs_user_read(struct file *file, char __user *read_data,
-			 size_t read_size, loff_t *poffset);
+			      size_t read_size, loff_t *poffset);
+extern ssize_t cifs_user_readv(struct file *file, const struct iovec *iov,
+			       unsigned long nr_segs, loff_t *poffset);
 extern ssize_t cifs_user_write(struct file *file, const char __user *write_data,
 			 size_t write_size, loff_t *poffset);
 extern int cifs_lock(struct file *, int, struct file_lock *);
fs/cifs/file.c +0 -0
index d48723c..bc53e9e 100644

fs/cifs/file.c int cifs_flush(struct file *file, fl_owner_t id) · line 1684

Quoted 10 lines
fs/cifs/file.c +4 -2
@@ -1677,20 +1677,60 @@ int cifs_flush(struct file *file, fl_owner_t id)
 	return rc;
 }
 
-ssize_t cifs_user_read(struct file *file, char __user *read_data,
-	size_t read_size, loff_t *poffset)
+static int
+cifs_fill_iov(const struct iovec *iov, unsigned long nr_segs,
+	      unsigned long *last_len, unsigned long *last_ind, char *data,
+	      size_t datalen)
 {

I have to wonder if we already have generic helpers for this sort of thing?

fs/cifs/file.c int cifs_flush(struct file *file, fl_owner_t id) · line 1690

Quoted 10 lines
fs/cifs/file.c +6 -4
-	int rc = -EACCES;
-	unsigned int bytes_read = 0;
-	unsigned int total_read = 0;
-	unsigned int current_read_size;
+	const struct iovec *ciov;
+	unsigned long cur_len;
+
+	while (datalen) {
+		cur_len = min_t(unsigned long, datalen,
+					      *last_len);
		^^^^^
		This can be on a single line...
Quoted 89 lines
fs/cifs/file.c +44 -19
+		ciov = &iov[*last_ind];
+
+		if (copy_to_user(ciov->iov_base + (ciov->iov_len - *last_len),
+				 data, cur_len))
+			return -EFAULT;
+
+		datalen -= cur_len;
+		data += cur_len;
+
+		*last_len -= cur_len;
+		if (*last_len == 0) {
+			(*last_ind)++;
+			*last_len = iov[*last_ind].iov_len;
+		}
+	}
+
+	return 0;
+}
+
+ssize_t cifs_user_readv(struct file *file, const struct iovec *iov,
+			unsigned long nr_segs, loff_t *poffset)
+{
+	int rc;
+	int xid;
+	unsigned int bytes_read = 0, total_read = 0;
+	unsigned long last_len = 0, len = 0, last_ind = 0;
+	unsigned long cur_len, i;
 	struct cifs_sb_info *cifs_sb;
 	struct cifsTconInfo *pTcon;
-	int xid;
 	struct cifsFileInfo *open_file;
-	char *smb_read_data;
-	char __user *current_offset;
 	struct smb_com_read_rsp *pSMBr;
+	char *read_data;
+
+	if (!nr_segs)
+		return 0;
+
+	last_len = iov->iov_len;
+
+	for (i = 0; i < nr_segs; i++)
+		len += iov[i].iov_len;
+
+	if (!len)
+		return 0;
 
 	xid = GetXid();
 	cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
@@ -1700,19 +1740,19 @@ ssize_t cifs_user_read(struct file *file, char __user *read_data,
 		FreeXid(xid);
 		return rc;
 	}
+
 	open_file = file->private_data;
 	pTcon = tlink_tcon(open_file->tlink);
 
 	if ((file->f_flags & O_ACCMODE) == O_WRONLY)
 		cFYI(1, "attempting read on write only file instance");
 
-	for (total_read = 0, current_offset = read_data;
-	     read_size > total_read;
-	     total_read += bytes_read, current_offset += bytes_read) {
-		current_read_size = min_t(const int, read_size - total_read,
+	for (total_read = 0; total_read < len; total_read += bytes_read) {
+		cur_len = min_t(const int, len - total_read,
 					  cifs_sb->rsize);
 		rc = -EAGAIN;
-		smb_read_data = NULL;
+		read_data = NULL;
+
 		while (rc == -EAGAIN) {
 			int buf_type = CIFS_NO_BUFFER;
 			if (open_file->invalidHandle) {
@@ -1721,26 +1761,24 @@ ssize_t cifs_user_read(struct file *file, char __user *read_data,
 					break;
 			}
 			rc = CIFSSMBRead(xid, pTcon,
-					 open_file->netfid,
-					 current_read_size, *poffset,
-					 &bytes_read, &smb_read_data,
-					 &buf_type);
-			pSMBr = (struct smb_com_read_rsp *)smb_read_data;
-			if (smb_read_data) {
-				if (copy_to_user(current_offset,
-						smb_read_data +
-						4 /* RFC1001 length field */ +
-						le16_to_cpu(pSMBr->DataOffset),
-						bytes_read))

fs/cifs/file.c ssize_t cifs_user_read(struct file *file, char __user *read_data, · line 1773

Quoted 10 lines
fs/cifs/file.c +9 -0
+					 open_file->netfid, cur_len, *poffset,
+					 &bytes_read, &read_data, &buf_type);
+			pSMBr = (struct smb_com_read_rsp *)read_data;
+			if (read_data) {
+				char *data_offset = read_data + 4 +
+						le16_to_cpu(pSMBr->DataOffset);
+				if (cifs_fill_iov(iov, nr_segs,
+					&last_len, &last_ind,
+					data_offset, bytes_read))
 					rc = -EFAULT;
					^^^^^^^^^^^^^
			nit: it's generally better not to indent the inside of a block along with the conditions.
Quoted 30 lines
fs/cifs/file.c +11 -4
-
 				if (buf_type == CIFS_SMALL_BUFFER)
-					cifs_small_buf_release(smb_read_data);
+					cifs_small_buf_release(read_data);
 				else if (buf_type == CIFS_LARGE_BUFFER)
-					cifs_buf_release(smb_read_data);
-				smb_read_data = NULL;
+					cifs_buf_release(read_data);
+				read_data = NULL;
 			}
 		}
+
 		if (rc || (bytes_read == 0)) {
 			if (total_read) {
 				break;
@@ -1753,13 +1791,23 @@ ssize_t cifs_user_read(struct file *file, char __user *read_data,
 			*poffset += bytes_read;
 		}
 	}
+
 	FreeXid(xid);
 	return total_read;
 }
 
+ssize_t cifs_user_read(struct file *file, char __user *read_data,
+		       size_t read_size, loff_t *poffset)
+{
+	struct iovec iov;
+	iov.iov_base = read_data;
+	iov.iov_len = read_size;

fs/cifs/file.c ssize_t cifs_user_read(struct file *file, char __user *read_data, · line 1813

Quoted 10 lines
fs/cifs/file.c +4 -1
+
+	return cifs_user_readv(file, &iov, 1, poffset);
+}
 
 static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size,
-	loff_t *poffset)
+			 loff_t *poffset)
 {
 	int rc = -EACCES;
 	unsigned int bytes_read = 0;

Other than the minor nits above, it looks good to me.

A message that is not in the archive (sent off-list or not yet received): 20101221132931.2e2e2a6f-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org

#6 lore raw

Re: [PATCH 4/6] CIFS: Implement cifs_strict_read (try #2)

2010/12/21 Jeff Layton <[email protected]>:

Quoted 102 lines
Quoted 99 lines · On Thu, 16 Dec 2010 20:37:32 +0300 Pavel Shilovsky…

From: Pavel Shilovsky <[email protected]>

Read from the cache if we have at least Level II oplock - otherwise read from the server. Add cifs_user_readv to let the client read into several buffers.

---
 fs/cifs/cifsfs.c |   38 ++++++++++++++++++-
 fs/cifs/cifsfs.h |    4 +-
 fs/cifs/file.c   |  108 +++++++++++++++++++++++++++++++++++++++---------------

 3 files changed, 117 insertions(+), 33 deletions(-)
fs/cifs/cifsfs.c +36 -2
index a218afe..bcb4d2c 100644
@@ -572,6 +572,40 @@ cifs_do_mount(struct file_system_type *fs_type,
       return dget(sb->s_root);
  }
 
+static ssize_t cifs_strict_read(struct kiocb *iocb, const struct iovec *iov,
+                             unsigned long nr_segs, loff_t pos)
+{
+     struct inode *inode;
+     struct cifs_sb_info *cifs_sb;
+     ssize_t read = 0;
+
+     if (!nr_segs)
+             return read;
+
+     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.
+      */
+
+     read = cifs_user_readv(iocb->ki_filp, iov, nr_segs, &pos);
+     if (read < 0)
+             return read;
+
+     iocb->ki_pos = pos;
+
+     return read;
+}
+
  static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
                                  unsigned long nr_segs, loff_t pos)
  {
@@ -713,7 +747,7 @@ const struct file_operations cifs_file_ops = {
  const struct file_operations cifs_file_strict_ops = {
       .read = do_sync_read,
       .write = do_sync_write,
-     .aio_read = generic_file_aio_read,
+     .aio_read = cifs_strict_read,
       .aio_write = cifs_file_aio_write,
       .open = cifs_open,
       .release = cifs_close,
@@ -769,7 +803,7 @@ const struct file_operations cifs_file_nobrl_ops = {
  const struct file_operations cifs_file_strict_nobrl_ops = {
       .read = do_sync_read,
       .write = do_sync_write,
-     .aio_read = generic_file_aio_read,
+     .aio_read = cifs_strict_read,
       .aio_write = cifs_file_aio_write,
       .open = cifs_open,
       .release = cifs_close,
fs/cifs/cifsfs.h +3 -1
index 657738f..f690d1c 100644
@@ -81,7 +81,9 @@ extern int cifs_open(struct inode *inode, struct file *file);
  extern int cifs_close(struct inode *inode, struct file *file);
  extern int cifs_closedir(struct inode *inode, struct file *file);
  extern ssize_t cifs_user_read(struct file *file, char __user *read_data,
-                      size_t read_size, loff_t *poffset);
+                           size_t read_size, loff_t *poffset);
+extern ssize_t cifs_user_readv(struct file *file, const struct iovec *iov,
+                            unsigned long nr_segs, loff_t *poffset);
  extern ssize_t cifs_user_write(struct file *file, const char __user *write_data,
                        size_t write_size, loff_t *poffset);
  extern int cifs_lock(struct file *, int, struct file_lock *);
fs/cifs/file.c +0 -0
index d48723c..bc53e9e 100644
@@ -1677,20 +1677,60 @@ int cifs_flush(struct file *file, fl_owner_t id)
       return rc;
  }
 
Quoted 9 lines

fs/cifs/file.c int cifs_flush(struct file *file, fl_owner_t id) · line 1684

Quoted 7 lines
fs/cifs/file.c +4 -2
-ssize_t cifs_user_read(struct file *file, char __user *read_data,
-     size_t read_size, loff_t *poffset)
+static int
+cifs_fill_iov(const struct iovec *iov, unsigned long nr_segs,
+           unsigned long *last_len, unsigned long *last_ind, char *data,
+           size_t datalen)
  {

I have to wonder if we already have generic helpers for this sort of thing?

Thanks, good idea. I've just found memcpy_toiovecend call that does the same things. I think I should replace this try with variant that uses memcpy_toiovecend.

Quoted 165 lines

fs/cifs/file.c int cifs_flush(struct file *file, fl_owner_t id) · line 1690

Quoted 11 lines
fs/cifs/file.c +6 -4
-     int rc = -EACCES;
-     unsigned int bytes_read = 0;
-     unsigned int total_read = 0;
-     unsigned int current_read_size;
+     const struct iovec *ciov;
+     unsigned long cur_len;
+
+     while (datalen) {
+             cur_len = min_t(unsigned long, datalen,
+                                           *last_len);

               ^^^^^
               This can be on a single line...

Quoted 89 lines
fs/cifs/file.c +44 -19
+             ciov = &iov[*last_ind];
+
+             if (copy_to_user(ciov->iov_base + (ciov->iov_len - *last_len),
+                              data, cur_len))
+                     return -EFAULT;
+
+             datalen -= cur_len;
+             data += cur_len;
+
+             *last_len -= cur_len;
+             if (*last_len == 0) {
+                     (*last_ind)++;
+                     *last_len = iov[*last_ind].iov_len;
+             }
+     }
+
+     return 0;
+}
+
+ssize_t cifs_user_readv(struct file *file, const struct iovec *iov,
+                     unsigned long nr_segs, loff_t *poffset)
+{
+     int rc;
+     int xid;
+     unsigned int bytes_read = 0, total_read = 0;
+     unsigned long last_len = 0, len = 0, last_ind = 0;
+     unsigned long cur_len, i;
       struct cifs_sb_info *cifs_sb;
       struct cifsTconInfo *pTcon;
-     int xid;
       struct cifsFileInfo *open_file;
-     char *smb_read_data;
-     char __user *current_offset;
       struct smb_com_read_rsp *pSMBr;
+     char *read_data;
+
+     if (!nr_segs)
+             return 0;
+
+     last_len = iov->iov_len;
+
+     for (i = 0; i < nr_segs; i++)
+             len += iov[i].iov_len;
+
+     if (!len)
+             return 0;
 
       xid = GetXid();
       cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
@@ -1700,19 +1740,19 @@ ssize_t cifs_user_read(struct file *file, char __user *read_data,
               FreeXid(xid);
               return rc;
       }
+
       open_file = file->private_data;
       pTcon = tlink_tcon(open_file->tlink);
 
       if ((file->f_flags & O_ACCMODE) == O_WRONLY)
               cFYI(1, "attempting read on write only file instance");
 
-     for (total_read = 0, current_offset = read_data;
-          read_size > total_read;
-          total_read += bytes_read, current_offset += bytes_read) {
-             current_read_size = min_t(const int, read_size - total_read,
+     for (total_read = 0; total_read < len; total_read += bytes_read) {
+             cur_len = min_t(const int, len - total_read,
                                         cifs_sb->rsize);
               rc = -EAGAIN;
-             smb_read_data = NULL;
+             read_data = NULL;
+
               while (rc == -EAGAIN) {
                       int buf_type = CIFS_NO_BUFFER;
                       if (open_file->invalidHandle) {
@@ -1721,26 +1761,24 @@ ssize_t cifs_user_read(struct file *file, char __user *read_data,
                                       break;
                       }
                       rc = CIFSSMBRead(xid, pTcon,
-                                      open_file->netfid,
-                                      current_read_size, *poffset,
-                                      &bytes_read, &smb_read_data,
-                                      &buf_type);
-                     pSMBr = (struct smb_com_read_rsp *)smb_read_data;
-                     if (smb_read_data) {
-                             if (copy_to_user(current_offset,
-                                             smb_read_data +
-                                             4 /* RFC1001 length field */ +
-                                             le16_to_cpu(pSMBr->DataOffset),
-                                             bytes_read))

fs/cifs/file.c ssize_t cifs_user_read(struct file *file, char __user *read_data, · line 1773

Quoted 10 lines
fs/cifs/file.c +9 -0
+                                      open_file->netfid, cur_len, *poffset,
+                                      &bytes_read, &read_data, &buf_type);
+                     pSMBr = (struct smb_com_read_rsp *)read_data;
+                     if (read_data) {
+                             char *data_offset = read_data + 4 +
+                                             le16_to_cpu(pSMBr->DataOffset);
+                             if (cifs_fill_iov(iov, nr_segs,
+                                     &last_len, &last_ind,
+                                     data_offset, bytes_read))
                                       rc = -EFAULT;

                                       ^^^^^^^^^^^^^
                       nit: it's generally better not to indent the inside of a block along with the conditions.

Quoted 30 lines
fs/cifs/file.c +11 -4
-
                               if (buf_type == CIFS_SMALL_BUFFER)
-                                     cifs_small_buf_release(smb_read_data);
+                                     cifs_small_buf_release(read_data);
                               else if (buf_type == CIFS_LARGE_BUFFER)
-                                     cifs_buf_release(smb_read_data);
-                             smb_read_data = NULL;
+                                     cifs_buf_release(read_data);
+                             read_data = NULL;
                       }
               }
+
               if (rc || (bytes_read == 0)) {
                       if (total_read) {
                               break;
@@ -1753,13 +1791,23 @@ ssize_t cifs_user_read(struct file *file, char __user *read_data,
                       *poffset += bytes_read;
               }
       }
+
       FreeXid(xid);
       return total_read;
  }
 
+ssize_t cifs_user_read(struct file *file, char __user *read_data,
+                    size_t read_size, loff_t *poffset)
+{
+     struct iovec iov;
+     iov.iov_base = read_data;
+     iov.iov_len = read_size;

fs/cifs/file.c ssize_t cifs_user_read(struct file *file, char __user *read_data, · line 1813

Quoted 10 lines
fs/cifs/file.c +4 -1
+
+     return cifs_user_readv(file, &iov, 1, poffset);
+}
 
  static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size,
-     loff_t *poffset)
+                      loff_t *poffset)
  {
       int rc = -EACCES;
       unsigned int bytes_read = 0;

Other than the minor nits above, it looks good to me.

--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in the body of a message to [email protected] More majordomo info at  http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Best regards,
Pavel Shilovsky.
Reviewed-by
#7 lore raw
In reply to a message not in the archive
Quoted 61 lines · On Thu, 16 Dec 2010 20:37:31 +0300 Pavel Shilovsky…

From: Pavel Shilovsky <[email protected]>

Invalidate inode mapping if we don't have at least Level II oplock.

---
 fs/cifs/cifsfs.c |    4 ++--
 fs/cifs/cifsfs.h |    1 +
 fs/cifs/file.c   |   15 +++++++++++++++
 3 files changed, 18 insertions(+), 2 deletions(-)
fs/cifs/cifsfs.c +2 -2
index 7660133..a218afe 100644
@@ -720,7 +720,7 @@ const struct file_operations cifs_file_strict_ops = {
 	.lock = cifs_lock,
 	.fsync = cifs_strict_fsync,
 	.flush = cifs_flush,
-	.mmap = cifs_file_mmap,
+	.mmap = cifs_file_strict_mmap,
 	.splice_read = generic_file_splice_read,
 	.llseek = cifs_llseek,
 #ifdef CONFIG_CIFS_POSIX
@@ -775,7 +775,7 @@ const struct file_operations cifs_file_strict_nobrl_ops = {
 	.release = cifs_close,
 	.fsync = cifs_strict_fsync,
 	.flush = cifs_flush,
-	.mmap = cifs_file_mmap,
+	.mmap = cifs_file_strict_mmap,
 	.splice_read = generic_file_splice_read,
 	.llseek = cifs_llseek,
 #ifdef CONFIG_CIFS_POSIX
fs/cifs/cifsfs.h +1 -0
index 8584829..657738f 100644
@@ -89,6 +89,7 @@ extern int cifs_fsync(struct file *, int);
 extern int cifs_strict_fsync(struct file *, int);
 extern int cifs_flush(struct file *, fl_owner_t id);
 extern int cifs_file_mmap(struct file * , struct vm_area_struct *);
+extern int cifs_file_strict_mmap(struct file * , struct vm_area_struct *);
 extern const struct file_operations cifs_dir_ops;
 extern int cifs_dir_open(struct inode *inode, struct file *file);
 extern int cifs_readdir(struct file *file, void *direntry, filldir_t filldir);
fs/cifs/file.c +8 -0
index 4e37cb8..d48723c 100644
@@ -1827,6 +1827,21 @@ static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size,
 	return total_read;
 }
 
+int cifs_file_strict_mmap(struct file *file, struct vm_area_struct *vma)
+{
+	int rc, xid;
+	struct inode *inode = file->f_path.dentry->d_inode;
+
+	xid = GetXid();
+
+	if (!CIFS_I(inode)->clientCanCacheRead)

fs/cifs/file.c static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size, · line 1847

Quoted 10 lines
fs/cifs/file.c +7 -0
+		cifs_invalidate_mapping(inode);
+
+	rc = generic_file_mmap(file, vma);
+	FreeXid(xid);
+	return rc;
+}
+
 int cifs_file_mmap(struct file *file, struct vm_area_struct *vma)
 {
 	int rc, xid;