Skip to contentSkip to conversation

cifs: convert "strict" writes to be asynchronous

PATCH In review Jeff Layton 3 participants 24 messages Feb 3, 2012 – Mar 23, 2012 16 messages not in the archive

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

cover cifs: convert "strict" writes to be asynchronous

cifs_iovec_write currently sends writes serially. This patchset changes it to send those writes in parallel instead, and to simply wait for the replies before returning to userspace. With this, I see a performance boost of roughly 20% or so when doing streaming writes without an oplock.

I'd like to see this in linux-next very soon, and then eventually in v3.4.

As a heads up, my goal here is to eventually convert cifs to use strictcache by default since that's what the protocol really mandates. Before we do that though, we need to convert uncached reads and writes to be asynchronous when we don't have an oplock.

Jeff Layton (8):
cifs: add pid field to cifs_writedata
cifs: allow caller to specify completion op when allocating writedata
cifs: rename pTcon to tcon in cifs_iovec_write
cifs: fix allocation in cifs_write_allocate_pages
cifs: make cifsFileInfo_get return the cifsFileInfo pointer
cifs: fix up get_numpages
cifs: abstract out function to marshal up the iovec array for async
writes
cifs: convert cifs_iovec_write to use async writes

 fs/cifs/cifsglob.h  |    4 +-
 fs/cifs/cifsproto.h |    9 ++-
 fs/cifs/cifssmb.c   |   29 +++---
 fs/cifs/file.c      |  239 +++++++++++++++++++++++++++++++++------------------
 4 files changed, 180 insertions(+), 101 deletions(-)
Signature · 1 line
1.7.7.6
#2 lore raw

PATCH 1/8 cifs: add pid field to cifs_writedata

In reply to a message not in the archive

We'll need this to handle rwpidforward option correctly when we use async writes in the aio_write op.

---
 fs/cifs/cifsproto.h |    1 +
 fs/cifs/cifssmb.c   |    4 ++--
 fs/cifs/file.c      |    1 +
 3 files changed, 4 insertions(+), 2 deletions(-)
fs/cifs/cifsproto.h +1 -0
index a81549d..2778605 100644
@@ -477,6 +477,7 @@ struct cifs_writedata {
 	struct work_struct		work;
 	struct cifsFileInfo		*cfile;
 	__u64				offset;
+	pid_t				pid;
 	unsigned int			bytes;
 	int				result;
 	unsigned int			nr_pages;
fs/cifs/cifssmb.c +2 -2
index cf12c0c..9525ae3 100644
@@ -2122,8 +2122,8 @@ cifs_async_writev(struct cifs_writedata *wdata)
 		goto async_writev_out;
 	}
 
-	smb->hdr.Pid = cpu_to_le16((__u16)wdata->cfile->pid);
-	smb->hdr.PidHigh = cpu_to_le16((__u16)(wdata->cfile->pid >> 16));
+	smb->hdr.Pid = cpu_to_le16((__u16)wdata->pid);
+	smb->hdr.PidHigh = cpu_to_le16((__u16)(wdata->pid >> 16));
 
 	smb->AndXCommand = 0xFF;	/* none */
 	smb->Fid = wdata->cfile->netfid;
fs/cifs/file.c +1 -0
index 4dd9283..ffbb2b4 100644
@@ -1758,6 +1758,7 @@ retry:
 				rc = -EBADF;
 				break;
 			}
+			wdata->pid = wdata->cfile->pid;
 			rc = cifs_async_writev(wdata);
 		} while (wbc->sync_mode == WB_SYNC_ALL && rc == -EAGAIN);
 
Signature · 1 line
1.7.7.6
#5 lore raw

PATCH 2/8 cifs: allow caller to specify completion op when allocating writedata

In reply to a message not in the archive

We'll need a different set of write completion ops when not writing out of the pagecache.

---
 fs/cifs/cifsproto.h |    4 +++-
 fs/cifs/cifssmb.c   |    6 +++---
 fs/cifs/file.c      |    3 ++-
 3 files changed, 8 insertions(+), 5 deletions(-)
fs/cifs/cifsproto.h +3 -1
index 2778605..ff528f3 100644
@@ -485,7 +485,9 @@ struct cifs_writedata {
 };
 
 int cifs_async_writev(struct cifs_writedata *wdata);
-struct cifs_writedata *cifs_writedata_alloc(unsigned int nr_pages);
+void cifs_writev_complete(struct work_struct *work);
+struct cifs_writedata *cifs_writedata_alloc(unsigned int nr_pages,
+						work_func_t complete);
 void cifs_writedata_release(struct kref *refcount);
 
 #endif			/* _CIFSPROTO_H */
fs/cifs/cifssmb.c +3 -3
index 9525ae3..e03a650 100644
@@ -1990,7 +1990,7 @@ cifs_writev_requeue(struct cifs_writedata *wdata)
 	kref_put(&wdata->refcount, cifs_writedata_release);
 }
 
-static void
+void
 cifs_writev_complete(struct work_struct *work)
 {
 	struct cifs_writedata *wdata = container_of(work,
@@ -2020,7 +2020,7 @@ cifs_writev_complete(struct work_struct *work)
 }
 
 struct cifs_writedata *
-cifs_writedata_alloc(unsigned int nr_pages)
+cifs_writedata_alloc(unsigned int nr_pages, work_func_t complete)
 {
 	struct cifs_writedata *wdata;
 
@@ -2034,7 +2034,7 @@ cifs_writedata_alloc(unsigned int nr_pages)
 	wdata = kzalloc(sizeof(*wdata) +
 			sizeof(struct page *) * (nr_pages - 1), GFP_NOFS);
 	if (wdata != NULL) {
-		INIT_WORK(&wdata->work, cifs_writev_complete);
+		INIT_WORK(&wdata->work, complete);
 		kref_init(&wdata->refcount);
 	}
 	return wdata;
fs/cifs/file.c +2 -1
index ffbb2b4..5e758d8 100644
@@ -1640,7 +1640,8 @@ retry:
 		tofind = min((cifs_sb->wsize / PAGE_CACHE_SIZE) - 1,
 				end - index) + 1;
 
-		wdata = cifs_writedata_alloc((unsigned int)tofind);
+		wdata = cifs_writedata_alloc((unsigned int)tofind,
+					     cifs_writev_complete);
 		if (!wdata) {
 			rc = -ENOMEM;
 			break;
Signature · 1 line
1.7.7.6
#8 lore raw

PATCH 3/8 cifs: rename pTcon to tcon in cifs_iovec_write

In reply to a message not in the archive
---
 fs/cifs/file.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)
fs/cifs/file.c +4 -5
index 5e758d8..febf32e 100644
@@ -2051,9 +2051,8 @@ cifs_iovec_write(struct file *file, const struct iovec *iov,
 	struct iov_iter it;
 	struct inode *inode;
 	struct cifsFileInfo *open_file;
-	struct cifs_tcon *pTcon;
+	struct cifs_tcon *tcon;
 	struct cifs_sb_info *cifs_sb;
-	struct cifs_io_parms io_parms;
 	int xid, rc;
 	__u32 pid;
 
@@ -2093,7 +2092,7 @@ cifs_iovec_write(struct file *file, const struct iovec *iov,
 	else
 		pid = current->tgid;
 
-	pTcon = tlink_tcon(open_file->tlink);
+	tcon = tlink_tcon(open_file->tlink);
 	inode = file->f_path.dentry->d_inode;
 
 	iov_iter_init(&it, iov, nr_segs, len, 0);
@@ -2121,7 +2120,7 @@ cifs_iovec_write(struct file *file, const struct iovec *iov,
 			}
 			io_parms.netfid = open_file->netfid;
 			io_parms.pid = pid;
-			io_parms.tcon = pTcon;
+			io_parms.tcon = tcon;
 			io_parms.offset = *poffset;
 			io_parms.length = cur_len;
 			rc = CIFSSMBWrite2(xid, &io_parms, &written, to_send,
@@ -2153,7 +2152,7 @@ cifs_iovec_write(struct file *file, const struct iovec *iov,
 		spin_unlock(&inode->i_lock);
 	}
 
-	cifs_stats_bytes_written(pTcon, total_written);
+	cifs_stats_bytes_written(tcon, total_written);
 	mark_inode_dirty_sync(inode);
 
 	for (i = 0; i < num_pages; i++)
Signature · 1 line
1.7.7.6
#11 lore raw

PATCH 4/8 cifs: fix allocation in cifs_write_allocate_pages

In reply to a message not in the archive

The gfp flags are currently set to __GPF_HIGHMEM, which doesn't allow for any reclaim. Make this more resilient by or'ing that with GFP_KERNEL. Also, get rid of the goto and unify the exit codepath.

---
 fs/cifs/file.c |   13 ++++++-------
 1 files changed, 6 insertions(+), 7 deletions(-)
fs/cifs/file.c +6 -7
index febf32e..6afa40f 100644
@@ -2001,7 +2001,7 @@ cifs_write_allocate_pages(struct page **pages, unsigned long num_pages)
 	unsigned long i;
 
 	for (i = 0; i < num_pages; i++) {
-		pages[i] = alloc_page(__GFP_HIGHMEM);
+		pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
 		if (!pages[i]) {
 			/*
 			 * save number of pages we have already allocated and
@@ -2009,15 +2009,14 @@ cifs_write_allocate_pages(struct page **pages, unsigned long num_pages)
 			 */
 			num_pages = i;
 			rc = -ENOMEM;
-			goto error;
+			break;
 		}
 	}
 
-	return rc;
-
-error:
-	for (i = 0; i < num_pages; i++)
-		put_page(pages[i]);
+	if (rc) {
+		for (i = 0; i < num_pages; i++)
+			put_page(pages[i]);
+	}
 	return rc;
 }
 
Signature · 1 line
1.7.7.6
#14 lore raw

PATCH 5/8 cifs: make cifsFileInfo_get return the cifsFileInfo pointer

In reply to a message not in the archive
---
 fs/cifs/cifsglob.h |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
fs/cifs/cifsglob.h +3 -1
index 0e56b1e..4adad0a 100644
@@ -555,9 +555,11 @@ struct cifs_io_parms {
  * Take a reference on the file private data. Must be called with
  * cifs_file_list_lock held.
  */
-static inline void cifsFileInfo_get(struct cifsFileInfo *cifs_file)
+static inline
+struct cifsFileInfo *cifsFileInfo_get(struct cifsFileInfo *cifs_file)
 {
 	++cifs_file->count;
+	return cifs_file;
 }
 
 void cifsFileInfo_put(struct cifsFileInfo *cifs_file);
Signature · 1 line
1.7.7.6
#17 lore raw

PATCH 6/8 cifs: fix up get_numpages

In reply to a message not in the archive

Use DIV_ROUND_UP. Also, PAGE_SIZE is more appropriate here since these aren't pagecache pages.

---
 fs/cifs/file.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
fs/cifs/file.c +1 -3
index 6afa40f..264e99c 100644
@@ -2027,9 +2027,7 @@ size_t get_numpages(const size_t wsize, const size_t len, size_t *cur_len)
 	size_t clen;
 
 	clen = min_t(const size_t, len, wsize);
-	num_pages = clen / PAGE_CACHE_SIZE;
-	if (clen % PAGE_CACHE_SIZE)
-		num_pages++;
+	num_pages = DIV_ROUND_UP(clen, PAGE_SIZE);
 
 	if (cur_len)
 		*cur_len = clen;
Signature · 1 line
1.7.7.6
#20 lore raw

PATCH 7/8 cifs: abstract out function to marshal up the iovec array for async writes

In reply to a message not in the archive

We'll need to do something a bit different depending on the caller. Abstract the code that marshals the page array into an iovec.

---
 fs/cifs/cifsproto.h |    2 ++
 fs/cifs/cifssmb.c   |   17 +++++++----------
 fs/cifs/file.c      |   22 ++++++++++++++++++++++
 3 files changed, 31 insertions(+), 10 deletions(-)
fs/cifs/cifsproto.h +2 -0
index ff528f3..bceadc5 100644
@@ -480,6 +480,8 @@ struct cifs_writedata {
 	pid_t				pid;
 	unsigned int			bytes;
 	int				result;
+	void (*marshal_iov) (struct kvec *iov,
+			     struct cifs_writedata *wdata);
 	unsigned int			nr_pages;
 	struct page			*pages[1];
 };
fs/cifs/cifssmb.c +7 -10
index e03a650..113b5af 100644
@@ -2098,7 +2098,6 @@ cifs_async_writev(struct cifs_writedata *wdata)
 	WRITE_REQ *smb = NULL;
 	int wct;
 	struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink);
-	struct inode *inode = wdata->cfile->dentry->d_inode;
 	struct kvec *iov = NULL;
 
 	if (tcon->ses->capabilities & CAP_LARGE_FILES) {
@@ -2141,15 +2140,13 @@ cifs_async_writev(struct cifs_writedata *wdata)
 	iov[0].iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4 + 1;
 	iov[0].iov_base = smb;
 
-	/* marshal up the pages into iov array */
-	wdata->bytes = 0;
-	for (i = 0; i < wdata->nr_pages; i++) {
-		iov[i + 1].iov_len = min(inode->i_size -
-				      page_offset(wdata->pages[i]),
-					(loff_t)PAGE_CACHE_SIZE);
-		iov[i + 1].iov_base = kmap(wdata->pages[i]);
-		wdata->bytes += iov[i + 1].iov_len;
-	}
+	/*
+	 * This function should marshal up the page array into the kvec
+	 * array, reserving [0] for the header. It should kmap the pages
+	 * and set the iov_len properly for each one. It may also set
+	 * wdata->bytes too.
+	 */
+	wdata->marshal_iov(iov, wdata);
 
 	cFYI(1, "async write at %llu %u bytes", wdata->offset, wdata->bytes);
 
fs/cifs/file.c +22 -0
index 264e99c..c7e47a2 100644
@@ -1604,6 +1604,27 @@ static int cifs_partialpagewrite(struct page *page, unsigned from, unsigned to)
 	return rc;
 }
 
+/*
+ * Marshal up the iov array, reserving the first one for the header. Also,
+ * set wdata->bytes.
+ */
+static void
+cifs_writepages_marshal_iov(struct kvec *iov, struct cifs_writedata *wdata)
+{
+	int i;
+	struct inode *inode = wdata->cfile->dentry->d_inode;
+	loff_t size = i_size_read(inode);
+
+	/* marshal up the pages into iov array */
+	wdata->bytes = 0;
+	for (i = 0; i < wdata->nr_pages; i++) {
+		iov[i + 1].iov_len = min(size - page_offset(wdata->pages[i]),
+					(loff_t)PAGE_CACHE_SIZE);
+		iov[i + 1].iov_base = kmap(wdata->pages[i]);
+		wdata->bytes += iov[i + 1].iov_len;
+	}
+}
+
 static int cifs_writepages(struct address_space *mapping,
 			   struct writeback_control *wbc)
 {
@@ -1748,6 +1769,7 @@ retry:
 		wdata->sync_mode = wbc->sync_mode;
 		wdata->nr_pages = nr_pages;
 		wdata->offset = page_offset(wdata->pages[0]);
+		wdata->marshal_iov = cifs_writepages_marshal_iov;
 
 		do {
 			if (wdata->cfile != NULL)
Signature · 1 line
1.7.7.6
#23 lore raw

PATCH 8/8 cifs: convert cifs_iovec_write to use async writes

In reply to a message not in the archive
---
 fs/cifs/cifsproto.h |    2 +
 fs/cifs/cifssmb.c   |    4 +-
 fs/cifs/file.c      |  191 ++++++++++++++++++++++++++++++++-------------------
 3 files changed, 126 insertions(+), 71 deletions(-)
fs/cifs/cifsproto.h +2 -0
index bceadc5..a131ded 100644
@@ -473,6 +473,8 @@ int cifs_async_readv(struct cifs_readdata *rdata);
 /* asynchronous write support */
 struct cifs_writedata {
 	struct kref			refcount;
+	struct list_head		list;
+	struct completion		done;
 	enum writeback_sync_modes	sync_mode;
 	struct work_struct		work;
 	struct cifsFileInfo		*cfile;
fs/cifs/cifssmb.c +3 -1
index 113b5af..6e93c9e 100644
@@ -2034,8 +2034,10 @@ cifs_writedata_alloc(unsigned int nr_pages, work_func_t complete)
 	wdata = kzalloc(sizeof(*wdata) +
 			sizeof(struct page *) * (nr_pages - 1), GFP_NOFS);
 	if (wdata != NULL) {
-		INIT_WORK(&wdata->work, complete);
 		kref_init(&wdata->refcount);
+		INIT_LIST_HEAD(&wdata->list);
+		init_completion(&wdata->done);
+		INIT_WORK(&wdata->work, complete);
 	}
 	return wdata;
 }
fs/cifs/file.c +121 -70

247 lines not on this page · raw message

Signature · 1 line
1.7.7.6
Reviewed-by
#4 lore raw

Re: [PATCH v1 1/8] cifs: add pid field to cifs_writedata

In reply to a message not in the archive

2012/2/3 Jeff Layton <[email protected]>:

Quoted 50 lines

We'll need this to handle rwpidforward option correctly when we use async writes in the aio_write op.

---
 fs/cifs/cifsproto.h |    1 +
 fs/cifs/cifssmb.c   |    4 ++--
 fs/cifs/file.c      |    1 +

 3 files changed, 4 insertions(+), 2 deletions(-)
fs/cifs/cifsproto.h +1 -0
index a81549d..2778605 100644
@@ -477,6 +477,7 @@ struct cifs_writedata {
        struct work_struct              work;
        struct cifsFileInfo             *cfile;
        __u64                           offset;
+       pid_t                           pid;
        unsigned int                    bytes;
        int                             result;
        unsigned int                    nr_pages;
fs/cifs/cifssmb.c +2 -2
index cf12c0c..9525ae3 100644
@@ -2122,8 +2122,8 @@ cifs_async_writev(struct cifs_writedata *wdata)
                goto async_writev_out;
        }
 
-       smb->hdr.Pid = cpu_to_le16((__u16)wdata->cfile->pid);
-       smb->hdr.PidHigh = cpu_to_le16((__u16)(wdata->cfile->pid >> 16));
+       smb->hdr.Pid = cpu_to_le16((__u16)wdata->pid);
+       smb->hdr.PidHigh = cpu_to_le16((__u16)(wdata->pid >> 16));
 

       smb->AndXCommand = 0xFF;        /* none */
       smb->Fid = wdata->cfile->netfid;

fs/cifs/file.c +1 -1
index 4dd9283..ffbb2b4 100644
@@ -1758,6 +1758,7 @@ retry:
                                rc = -EBADF;
                                break;
                        }
+                       wdata->pid = wdata->cfile->pid;
                        rc = cifs_async_writev(wdata);
                } while (wbc->sync_mode == WB_SYNC_ALL && rc == -EAGAIN);
 
--
Quoted 2 lines

1.7.7.6

Looks good.

Signature · 2 lines
Best regards,
Pavel Shilovsky.
Reviewed-by
#7 lore raw

Re: [PATCH v1 2/8] cifs: allow caller to specify completion op when allocating writedata

In reply to a message not in the archive

2012/2/3 Jeff Layton <[email protected]>:

Quoted 71 lines

We'll need a different set of write completion ops when not writing out of the pagecache.

---
 fs/cifs/cifsproto.h |    4 +++-
 fs/cifs/cifssmb.c   |    6 +++---
 fs/cifs/file.c      |    3 ++-

 3 files changed, 8 insertions(+), 5 deletions(-)
fs/cifs/cifsproto.h +3 -1
index 2778605..ff528f3 100644
@@ -485,7 +485,9 @@ struct cifs_writedata {
  };
 
  int cifs_async_writev(struct cifs_writedata *wdata);
-struct cifs_writedata *cifs_writedata_alloc(unsigned int nr_pages);
+void cifs_writev_complete(struct work_struct *work);
+struct cifs_writedata *cifs_writedata_alloc(unsigned int nr_pages,
+                                               work_func_t complete);
  void cifs_writedata_release(struct kref *refcount);
 
  #endif                 /* _CIFSPROTO_H */
fs/cifs/cifssmb.c +1 -1
index 9525ae3..e03a650 100644
@@ -1990,7 +1990,7 @@ cifs_writev_requeue(struct cifs_writedata *wdata)
        kref_put(&wdata->refcount, cifs_writedata_release);
  }
 
-static void
+void
  cifs_writev_complete(struct work_struct *work)
  {
        struct cifs_writedata *wdata = container_of(work,
@@ -2020,7 +2020,7 @@ cifs_writev_complete(struct work_struct *work)
  }
 

 struct cifs_writedata *

fs/cifs/cifssmb.c +1 -1
-cifs_writedata_alloc(unsigned int nr_pages)
+cifs_writedata_alloc(unsigned int nr_pages, work_func_t complete)

 {
       struct cifs_writedata *wdata;

fs/cifs/cifssmb.c +0 -0
@@ -2034,7 +2034,7 @@ cifs_writedata_alloc(unsigned int nr_pages)

       wdata = kzalloc(sizeof(*wdata) +
                       sizeof(struct page *) * (nr_pages - 1), GFP_NOFS); if (wdata != NULL) {
-               INIT_WORK(&wdata->work, cifs_writev_complete);
+               INIT_WORK(&wdata->work, complete); kref_init(&wdata->refcount);
       }
       return wdata;

fs/cifs/file.c +2 -2
index ffbb2b4..5e758d8 100644
@@ -1640,7 +1640,8 @@ retry:
                tofind = min((cifs_sb->wsize / PAGE_CACHE_SIZE) - 1,
                                end - index) + 1;
 
-               wdata = cifs_writedata_alloc((unsigned int)tofind);
+               wdata = cifs_writedata_alloc((unsigned int)tofind,
+                                            cifs_writev_complete);
                if (!wdata) {
                        rc = -ENOMEM;
                        break;
--
Quoted 2 lines

1.7.7.6

Looks good.

Signature · 2 lines
Best regards,
Pavel Shilovsky.
Reviewed-by
#10 lore raw

Re: [PATCH v1 3/8] cifs: rename pTcon to tcon in cifs_iovec_write

In reply to a message not in the archive

2012/2/3 Jeff Layton <[email protected]>:

Quoted 48 lines

---
 fs/cifs/file.c |    9 ++++-----

 1 files changed, 4 insertions(+), 5 deletions(-)
fs/cifs/file.c +1 -2
index 5e758d8..febf32e 100644
@@ -2051,9 +2051,8 @@ cifs_iovec_write(struct file *file, const struct iovec *iov,
        struct iov_iter it;
        struct inode *inode;
        struct cifsFileInfo *open_file;
-       struct cifs_tcon *pTcon;
+       struct cifs_tcon *tcon;
        struct cifs_sb_info *cifs_sb;
-       struct cifs_io_parms io_parms;
        int xid, rc;
        __u32 pid;
 
@@ -2093,7 +2092,7 @@ cifs_iovec_write(struct file *file, const struct iovec *iov,

       else
               pid = current->tgid;

-       pTcon = tlink_tcon(open_file->tlink);
+       tcon = tlink_tcon(open_file->tlink);
       inode = file->f_path.dentry->d_inode;

       iov_iter_init(&it, iov, nr_segs, len, 0);

fs/cifs/file.c +2 -3
@@ -2121,7 +2120,7 @@ cifs_iovec_write(struct file *file, const struct iovec *iov,
                        }
                        io_parms.netfid = open_file->netfid;
                        io_parms.pid = pid;
-                       io_parms.tcon = pTcon;
+                       io_parms.tcon = tcon;
                        io_parms.offset = *poffset;
                        io_parms.length = cur_len;
                        rc = CIFSSMBWrite2(xid, &io_parms, &written, to_send,
@@ -2153,7 +2152,7 @@ cifs_iovec_write(struct file *file, const struct iovec *iov,
                spin_unlock(&inode->i_lock);
        }
 
-       cifs_stats_bytes_written(pTcon, total_written);
+       cifs_stats_bytes_written(tcon, total_written);
        mark_inode_dirty_sync(inode);
 
        for (i = 0; i < num_pages; i++)
--
Quoted 2 lines

1.7.7.6

Signature · 2 lines
Best regards,
Pavel Shilovsky.
#13 lore raw

Re: [PATCH v1 4/8] cifs: fix allocation in cifs_write_allocate_pages

In reply to a message not in the archive

2012/2/3 Jeff Layton <[email protected]>:

Quoted 44 lines

The gfp flags are currently set to __GPF_HIGHMEM, which doesn't allow for any reclaim. Make this more resilient by or'ing that with GFP_KERNEL. Also, get rid of the goto and unify the exit codepath.

---
 fs/cifs/file.c |   13 ++++++-------

 1 files changed, 6 insertions(+), 7 deletions(-)
fs/cifs/file.c +6 -8
index febf32e..6afa40f 100644
@@ -2001,7 +2001,7 @@ cifs_write_allocate_pages(struct page **pages, unsigned long num_pages)
        unsigned long i;
 
        for (i = 0; i < num_pages; i++) {
-               pages[i] = alloc_page(__GFP_HIGHMEM);
+               pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
                if (!pages[i]) {
                        /*
                         * save number of pages we have already allocated and
@@ -2009,15 +2009,14 @@ cifs_write_allocate_pages(struct page **pages, unsigned long num_pages)
                         */
                        num_pages = i;
                        rc = -ENOMEM;
-                       goto error;
+                       break;
                }
        }
 
-       return rc;
-
-error:
-       for (i = 0; i < num_pages; i++)
-               put_page(pages[i]);
+       if (rc) {
+               for (i = 0; i < num_pages; i++)
+                       put_page(pages[i]);
+       }
        return rc;
  }
 
--
Quoted 2 lines

1.7.7.6

Signature · 2 lines
Best regards,
Pavel Shilovsky.
Reviewed-by
#16 lore raw

Re: [PATCH v1 5/8] cifs: make cifsFileInfo_get return the cifsFileInfo pointer

In reply to a message not in the archive

2012/2/3 Jeff Layton <[email protected]>:

Quoted 23 lines

---
 fs/cifs/cifsglob.h |    4 +++-

 1 files changed, 3 insertions(+), 1 deletions(-)
fs/cifs/cifsglob.h +3 -2
index 0e56b1e..4adad0a 100644
@@ -555,9 +555,11 @@ struct cifs_io_parms {
  * Take a reference on the file private data. Must be called with
  * cifs_file_list_lock held.
  */
-static inline void cifsFileInfo_get(struct cifsFileInfo *cifs_file)
+static inline
+struct cifsFileInfo *cifsFileInfo_get(struct cifsFileInfo *cifs_file)
  {
        ++cifs_file->count;
+       return cifs_file;
  }
 
  void cifsFileInfo_put(struct cifsFileInfo *cifs_file);
--
Quoted 2 lines

1.7.7.6

Signature · 2 lines
Best regards,
Pavel Shilovsky.
Reviewed-by
#19 lore raw

Re: [PATCH v1 6/8] cifs: fix up get_numpages

In reply to a message not in the archive

2012/2/3 Jeff Layton <[email protected]>:

Quoted 24 lines

Use DIV_ROUND_UP. Also, PAGE_SIZE is more appropriate here since these aren't pagecache pages.

---
 fs/cifs/file.c |    4 +---

 1 files changed, 1 insertions(+), 3 deletions(-)
fs/cifs/file.c +1 -4
index 6afa40f..264e99c 100644
@@ -2027,9 +2027,7 @@ size_t get_numpages(const size_t wsize, const size_t len, size_t *cur_len)
        size_t clen;
 
        clen = min_t(const size_t, len, wsize);
-       num_pages = clen / PAGE_CACHE_SIZE;
-       if (clen % PAGE_CACHE_SIZE)
-               num_pages++;
+       num_pages = DIV_ROUND_UP(clen, PAGE_SIZE);
 
        if (cur_len)
                *cur_len = clen;
--
Quoted 2 lines

1.7.7.6

Signature · 2 lines
Best regards,
Pavel Shilovsky.
Reviewed-by
#22 lore raw

Re: [PATCH v1 7/8] cifs: abstract out function to marshal up the iovec array for async writes

In reply to a message not in the archive

2012/2/3 Jeff Layton <[email protected]>:

Quoted 99 lines

We'll need to do something a bit different depending on the caller. Abstract the code that marshals the page array into an iovec.

---
 fs/cifs/cifsproto.h |    2 ++ fs/cifs/cifssmb.c   |   17 +++++++---------- fs/cifs/file.c      |   22 ++++++++++++++++++++++

 3 files changed, 31 insertions(+), 10 deletions(-)
fs/cifs/cifsproto.h +2 -0
index ff528f3..bceadc5 100644
@@ -480,6 +480,8 @@ struct cifs_writedata {
        pid_t                           pid;
        unsigned int                    bytes;
        int                             result;
+       void (*marshal_iov) (struct kvec *iov,
+                            struct cifs_writedata *wdata);
        unsigned int                    nr_pages;
        struct page                     *pages[1];
  };
fs/cifs/cifssmb.c +7 -10
index e03a650..113b5af 100644
@@ -2098,7 +2098,6 @@ cifs_async_writev(struct cifs_writedata *wdata)
        WRITE_REQ *smb = NULL;
        int wct;
        struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink);
-       struct inode *inode = wdata->cfile->dentry->d_inode;
        struct kvec *iov = NULL;
 
        if (tcon->ses->capabilities & CAP_LARGE_FILES) {
@@ -2141,15 +2140,13 @@ cifs_async_writev(struct cifs_writedata *wdata)
        iov[0].iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4 + 1;
        iov[0].iov_base = smb;
 
-       /* marshal up the pages into iov array */
-       wdata->bytes = 0;
-       for (i = 0; i < wdata->nr_pages; i++) {
-               iov[i + 1].iov_len = min(inode->i_size -
-                                     page_offset(wdata->pages[i]),
-                                       (loff_t)PAGE_CACHE_SIZE);
-               iov[i + 1].iov_base = kmap(wdata->pages[i]);
-               wdata->bytes += iov[i + 1].iov_len;
-       }
+       /*
+        * This function should marshal up the page array into the kvec
+        * array, reserving [0] for the header. It should kmap the pages
+        * and set the iov_len properly for each one. It may also set
+        * wdata->bytes too.
+        */
+       wdata->marshal_iov(iov, wdata);
 
        cFYI(1, "async write at %llu %u bytes", wdata->offset, wdata->bytes);
 
fs/cifs/file.c +22 -1
index 264e99c..c7e47a2 100644
@@ -1604,6 +1604,27 @@ static int cifs_partialpagewrite(struct page *page, unsigned from, unsigned to)
        return rc;
  }
 
+/*
+ * Marshal up the iov array, reserving the first one for the header. Also,
+ * set wdata->bytes.
+ */
+static void
+cifs_writepages_marshal_iov(struct kvec *iov, struct cifs_writedata *wdata)
+{
+       int i;
+       struct inode *inode = wdata->cfile->dentry->d_inode;
+       loff_t size = i_size_read(inode);
+
+       /* marshal up the pages into iov array */
+       wdata->bytes = 0;
+       for (i = 0; i < wdata->nr_pages; i++) {
+               iov[i + 1].iov_len = min(size - page_offset(wdata->pages[i]),
+                                       (loff_t)PAGE_CACHE_SIZE);
+               iov[i + 1].iov_base = kmap(wdata->pages[i]);
+               wdata->bytes += iov[i + 1].iov_len;
+       }
+}
+
  static int cifs_writepages(struct address_space *mapping,
                           struct writeback_control *wbc)
  {
@@ -1748,6 +1769,7 @@ retry:
                wdata->sync_mode = wbc->sync_mode;
                wdata->nr_pages = nr_pages;
                wdata->offset = page_offset(wdata->pages[0]);
+               wdata->marshal_iov = cifs_writepages_marshal_iov;
 
                do {
                        if (wdata->cfile != NULL)
--
Quoted 2 lines

1.7.7.6

Looks good.

Signature · 2 lines
Best regards,
Pavel Shilovsky.
Reviewed-by
#25 lore raw

Re: [PATCH v1 8/8] cifs: convert cifs_iovec_write to use async writes

In reply to a message not in the archive

2012/2/3 Jeff Layton <[email protected]>:

Quoted 178 lines

---
 fs/cifs/cifsproto.h |    2 +
 fs/cifs/cifssmb.c   |    4 +-
 fs/cifs/file.c      |  191 ++++++++++++++++++++++++++++++++-------------------

 3 files changed, 126 insertions(+), 71 deletions(-)
fs/cifs/cifsproto.h +2 -0
index bceadc5..a131ded 100644
@@ -473,6 +473,8 @@ int cifs_async_readv(struct cifs_readdata *rdata);
  /* asynchronous write support */
  struct cifs_writedata {
        struct kref                     refcount;
+       struct list_head                list;
+       struct completion               done;
        enum writeback_sync_modes       sync_mode;
        struct work_struct              work;
        struct cifsFileInfo             *cfile;
fs/cifs/cifssmb.c +0 -0
index 113b5af..6e93c9e 100644
@@ -2034,8 +2034,10 @@ cifs_writedata_alloc(unsigned int nr_pages, work_func_t complete)

       wdata = kzalloc(sizeof(*wdata) +
                       sizeof(struct page *) * (nr_pages - 1), GFP_NOFS); if (wdata != NULL) {
-               INIT_WORK(&wdata->work, complete); kref_init(&wdata->refcount);
+               INIT_LIST_HEAD(&wdata->list);
+               init_completion(&wdata->done);
+               INIT_WORK(&wdata->work, complete);
       }
       return wdata;
 }

fs/cifs/file.c +31 -0
index c7e47a2..ef25fc5 100644
@@ -2057,23 +2057,55 @@ size_t get_numpages(const size_t wsize, const size_t len, size_t *cur_len)
        return num_pages;
  }
 
+static void
+cifs_uncached_marshal_iov(struct kvec *iov, struct cifs_writedata *wdata)
+{
+       int i;
+       size_t bytes = wdata->bytes;
+
+       /* marshal up the pages into iov array */
+       for (i = 0; i < wdata->nr_pages; i++) {
+               iov[i + 1].iov_len = min(bytes, PAGE_SIZE);
+               iov[i + 1].iov_base = kmap(wdata->pages[i]);
+               bytes -= iov[i + 1].iov_len;
+       }
+}
+
+static void
+cifs_uncached_writev_complete(struct work_struct *work)
+{
+       int i;
+       struct cifs_writedata *wdata = container_of(work,
+                                       struct cifs_writedata, work);
+
+       complete(&wdata->done);
+
+       if (wdata->result != -EAGAIN) {
+               for (i = 0; i < wdata->nr_pages; i++)
+                       put_page(wdata->pages[i]);
+       }
+
+       kref_put(&wdata->refcount, cifs_writedata_release);
+}
+

 static ssize_t
 cifs_iovec_write(struct file *file, const struct iovec *iov, unsigned long nr_segs, loff_t *poffset) {
-       unsigned int written;
-       unsigned long num_pages, npages, i;
+       unsigned long nr_pages, i;
       size_t copied, len, cur_len;
       ssize_t total_written = 0;
-       struct kvec *to_send;
-       struct page **pages;
+       loff_t offset = *poffset;
       struct iov_iter it;
-       struct inode *inode;
+       struct inode *inode = file->f_path.dentry->d_inode;
+       struct cifsInodeInfo *cifsi = CIFS_I(inode); struct cifsFileInfo *open_file;
       struct cifs_tcon *tcon;
       struct cifs_sb_info *cifs_sb;
-       int xid, rc;
-       __u32 pid;
+       struct cifs_writedata *wdata, *tmp;
+       struct list_head wdata_list;
+       int rc;
+       pid_t pid;

       len = iov_length(iov, nr_segs);
       if (!len)

fs/cifs/file.c +2 -20
@@ -2083,103 +2115,122 @@ cifs_iovec_write(struct file *file, const struct iovec *iov,
        if (rc)
                return rc;
 
+       INIT_LIST_HEAD(&wdata_list);
        cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
-       num_pages = get_numpages(cifs_sb->wsize, len, &cur_len);
-
-       pages = kmalloc(sizeof(struct pages *)*num_pages, GFP_KERNEL);
-       if (!pages)
-               return -ENOMEM;
-
-       to_send = kmalloc(sizeof(struct kvec)*(num_pages + 1), GFP_KERNEL);
-       if (!to_send) {
-               kfree(pages);
-               return -ENOMEM;
-       }
-
-       rc = cifs_write_allocate_pages(pages, num_pages);
-       if (rc) {
-               kfree(pages);
-               kfree(to_send);
-               return rc;
-       }
-
-       xid = GetXid();
        open_file = file->private_data;
+       tcon = tlink_tcon(open_file->tlink);
 
        if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD)
                pid = open_file->pid;

       else
               pid = current->tgid;

-       tcon = tlink_tcon(open_file->tlink);
-       inode = file->f_path.dentry->d_inode;
-
       iov_iter_init(&it, iov, nr_segs, len, 0);
-       npages = num_pages;
-
       do {
-               size_t save_len = cur_len;
-               for (i = 0; i < npages; i++) {
-                       copied = min_t(const size_t, cur_len, PAGE_CACHE_SIZE);
-                       copied = iov_iter_copy_from_user(pages[i], &it, 0,
-                                                        copied);
+               size_t save_len;

fs/cifs/file.c +20 -0
+
+               nr_pages = get_numpages(cifs_sb->wsize, len, &cur_len);
+               wdata = cifs_writedata_alloc(nr_pages,
+                                            cifs_uncached_writev_complete);
+               if (!wdata) {
+                       rc = -ENOMEM;
+                       break;
+               }
+
+               rc = cifs_write_allocate_pages(wdata->pages, nr_pages);
+               if (rc) {
+                       kfree(wdata);
+                       break;
+               }
+
+               save_len = cur_len;
+               for (i = 0; i < nr_pages; i++) {
+                       copied = min_t(const size_t, cur_len, PAGE_SIZE);
+                       copied = iov_iter_copy_from_user(wdata->pages[i], &it,
+                                                        0, copied);

                       cur_len -= copied; iov_iter_advance(&it, copied);
-                       to_send[i+1].iov_base = kmap(pages[i]);
-                       to_send[i+1].iov_len = copied; }
-
               cur_len = save_len - cur_len;

Quoted 13 lines

+               wdata->sync_mode = WB_SYNC_ALL;
+               wdata->nr_pages = nr_pages;
+               wdata->offset = (__u64)offset;
+               wdata->cfile = cifsFileInfo_get(open_file);
+               wdata->pid = pid;
+               wdata->bytes = cur_len;
+               wdata->marshal_iov = cifs_uncached_marshal_iov; do {
                       if (open_file->invalidHandle) {
                               rc = cifs_reopen_file(open_file, false); if (rc != 0)
                                       break;
                       }

When we reopen a file, we do it with the current pid, but in cfile->pid leaves with the old value (and pid variable too).Should we do reopen with cfile->pid to save the original state of the file (now we don't restore locks, if we do it - it will be the problem)?

Quoted 97 lines

-                       io_parms.netfid = open_file->netfid;
-                       io_parms.pid = pid;
-                       io_parms.tcon = tcon;
-                       io_parms.offset = *poffset;
-                       io_parms.length = cur_len;
-                       rc = CIFSSMBWrite2(xid, &io_parms, &written, to_send,
-                                          npages, 0);
+                       rc = cifs_async_writev(wdata);
               } while (rc == -EAGAIN);

-               for (i = 0; i < npages; i++)
-                       kunmap(pages[i]);
-
-               if (written) {
-                       len -= written;
-                       total_written += written;
-                       cifs_update_eof(CIFS_I(inode), *poffset, written);
-                       *poffset += written;
-               } else if (rc < 0) {
-                       if (!total_written)
-                               total_written = rc;
+               if (rc) {
+                       kref_put(&wdata->refcount, cifs_writedata_release); break;
               }

-               /* get length and number of kvecs of the next write */
-               npages = get_numpages(cifs_sb->wsize, len, &cur_len);
+               list_add_tail(&wdata->list, &wdata_list);
+               offset += cur_len;
+               len -= cur_len;
       } while (len > 0);

+       /*
+        * If at least one write was successfully sent, then discard any rc
+        * value from the later writes. If the other write succeeds, then
+        * we'll end up returning whatever was written. If it fails, then
+        * we'll get a new rc value from that.
+        */
+       if (!list_empty(&wdata_list))
+               rc = 0;

fs/cifs/file.c +33 -0
+
+       /*
+        * Wait for and collect replies for any successful sends in order of
+        * increasing offset. Once an error is hit or we get a fatal signal
+        * while waiting, then return without waiting for any more replies.
+        */
+restart_loop:
+       list_for_each_entry_safe(wdata, tmp, &wdata_list, list) {
+               if (!rc) {
+                       /* FIXME: freezable too? */
+                       rc = wait_for_completion_killable(&wdata->done);
+                       if (!rc) {
+                               if (wdata->result)
+                                       rc = wdata->result;
+                               else
+                                       total_written += wdata->bytes;
+                       } else if (rc == -EAGAIN) {
+                               do {
+                                       if (open_file->invalidHandle) {
+                                               rc = cifs_reopen_file(open_file,
+                                                                       false);
+                                               if (rc != 0)
+                                                       break;
+                                       }
+                                       rc = cifs_async_writev(wdata);
+                               } while (rc == -EAGAIN);
+                               goto restart_loop;
+                       }
+               }
+               list_del_init(&wdata->list);
+               kref_put(&wdata->refcount, cifs_writedata_release);
+       }
+

       if (total_written > 0) {
+               cifs_update_eof(cifsi, *poffset, total_written);
+               *poffset += total_written; spin_lock(&inode->i_lock);
-               if (*poffset > inode->i_size)
-                       i_size_write(inode, *poffset);
+               if (offset > inode->i_size)
+                       i_size_write(inode, cifsi->server_eof); spin_unlock(&inode->i_lock);
       }

       cifs_stats_bytes_written(tcon, total_written);
-       mark_inode_dirty_sync(inode);
-
-       for (i = 0; i < num_pages; i++)
-               put_page(pages[i]);
-       kfree(to_send);
-       kfree(pages);
-       FreeXid(xid);
-       return total_written;
+       return total_written ? total_written : (ssize_t)rc; }

Quoted 4 lines

 ssize_t cifs_user_writev(struct kiocb *iocb, const struct iovec *iov, --
1.7.7.6

The patch itself looks correct.

Signature · 2 lines
Best regards,
Pavel Shilovsky.
#27 lore raw

Re: [PATCH v1 8/8] cifs: convert cifs_iovec_write to use async writes

In reply to a message not in the archive
Quoted 189 lines · On Tue, 21 Feb 2012 12:06:49 +0400 Pavel Shilovsky…

2012/2/3 Jeff Layton <[email protected]>:

Quoted 188 lines

---
 fs/cifs/cifsproto.h |    2 +
 fs/cifs/cifssmb.c   |    4 +-
 fs/cifs/file.c      |  191 ++++++++++++++++++++++++++++++++-------------------

 3 files changed, 126 insertions(+), 71 deletions(-)
fs/cifs/cifsproto.h +2 -0
index bceadc5..a131ded 100644
@@ -473,6 +473,8 @@ int cifs_async_readv(struct cifs_readdata *rdata);
  /* asynchronous write support */
  struct cifs_writedata {
        struct kref                     refcount;
+       struct list_head                list;
+       struct completion               done;
        enum writeback_sync_modes       sync_mode;
        struct work_struct              work;
        struct cifsFileInfo             *cfile;
fs/cifs/cifssmb.c +0 -0
index 113b5af..6e93c9e 100644
@@ -2034,8 +2034,10 @@ cifs_writedata_alloc(unsigned int nr_pages, work_func_t complete)

       wdata = kzalloc(sizeof(*wdata) +
                       sizeof(struct page *) * (nr_pages - 1), GFP_NOFS); if (wdata != NULL) {
-               INIT_WORK(&wdata->work, complete); kref_init(&wdata->refcount);
+               INIT_LIST_HEAD(&wdata->list);
+               init_completion(&wdata->done);
+               INIT_WORK(&wdata->work, complete);
       }
       return wdata;
 }

fs/cifs/file.c +31 -0
index c7e47a2..ef25fc5 100644
@@ -2057,23 +2057,55 @@ size_t get_numpages(const size_t wsize, const size_t len, size_t *cur_len)
        return num_pages;
  }
 
+static void
+cifs_uncached_marshal_iov(struct kvec *iov, struct cifs_writedata *wdata)
+{
+       int i;
+       size_t bytes = wdata->bytes;
+
+       /* marshal up the pages into iov array */
+       for (i = 0; i < wdata->nr_pages; i++) {
+               iov[i + 1].iov_len = min(bytes, PAGE_SIZE);
+               iov[i + 1].iov_base = kmap(wdata->pages[i]);
+               bytes -= iov[i + 1].iov_len;
+       }
+}
+
+static void
+cifs_uncached_writev_complete(struct work_struct *work)
+{
+       int i;
+       struct cifs_writedata *wdata = container_of(work,
+                                       struct cifs_writedata, work);
+
+       complete(&wdata->done);
+
+       if (wdata->result != -EAGAIN) {
+               for (i = 0; i < wdata->nr_pages; i++)
+                       put_page(wdata->pages[i]);
+       }
+
+       kref_put(&wdata->refcount, cifs_writedata_release);
+}
+

 static ssize_t
 cifs_iovec_write(struct file *file, const struct iovec *iov, unsigned long nr_segs, loff_t *poffset) {
-       unsigned int written;
-       unsigned long num_pages, npages, i;
+       unsigned long nr_pages, i;
       size_t copied, len, cur_len;
       ssize_t total_written = 0;
-       struct kvec *to_send;
-       struct page **pages;
+       loff_t offset = *poffset;
       struct iov_iter it;
-       struct inode *inode;
+       struct inode *inode = file->f_path.dentry->d_inode;
+       struct cifsInodeInfo *cifsi = CIFS_I(inode); struct cifsFileInfo *open_file;
       struct cifs_tcon *tcon;
       struct cifs_sb_info *cifs_sb;
-       int xid, rc;
-       __u32 pid;
+       struct cifs_writedata *wdata, *tmp;
+       struct list_head wdata_list;
+       int rc;
+       pid_t pid;

       len = iov_length(iov, nr_segs);
       if (!len)

fs/cifs/file.c +2 -20
@@ -2083,103 +2115,122 @@ cifs_iovec_write(struct file *file, const struct iovec *iov,
        if (rc)
                return rc;
 
+       INIT_LIST_HEAD(&wdata_list);
        cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
-       num_pages = get_numpages(cifs_sb->wsize, len, &cur_len);
-
-       pages = kmalloc(sizeof(struct pages *)*num_pages, GFP_KERNEL);
-       if (!pages)
-               return -ENOMEM;
-
-       to_send = kmalloc(sizeof(struct kvec)*(num_pages + 1), GFP_KERNEL);
-       if (!to_send) {
-               kfree(pages);
-               return -ENOMEM;
-       }
-
-       rc = cifs_write_allocate_pages(pages, num_pages);
-       if (rc) {
-               kfree(pages);
-               kfree(to_send);
-               return rc;
-       }
-
-       xid = GetXid();
        open_file = file->private_data;
+       tcon = tlink_tcon(open_file->tlink);
 
        if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD)
                pid = open_file->pid;

       else
               pid = current->tgid;

-       tcon = tlink_tcon(open_file->tlink);
-       inode = file->f_path.dentry->d_inode;
-
       iov_iter_init(&it, iov, nr_segs, len, 0);
-       npages = num_pages;
-
       do {
-               size_t save_len = cur_len;
-               for (i = 0; i < npages; i++) {
-                       copied = min_t(const size_t, cur_len, PAGE_CACHE_SIZE);
-                       copied = iov_iter_copy_from_user(pages[i], &it, 0,
-                                                        copied);
+               size_t save_len;

fs/cifs/file.c +20 -0
+
+               nr_pages = get_numpages(cifs_sb->wsize, len, &cur_len);
+               wdata = cifs_writedata_alloc(nr_pages,
+                                            cifs_uncached_writev_complete);
+               if (!wdata) {
+                       rc = -ENOMEM;
+                       break;
+               }
+
+               rc = cifs_write_allocate_pages(wdata->pages, nr_pages);
+               if (rc) {
+                       kfree(wdata);
+                       break;
+               }
+
+               save_len = cur_len;
+               for (i = 0; i < nr_pages; i++) {
+                       copied = min_t(const size_t, cur_len, PAGE_SIZE);
+                       copied = iov_iter_copy_from_user(wdata->pages[i], &it,
+                                                        0, copied);

                       cur_len -= copied; iov_iter_advance(&it, copied);
-                       to_send[i+1].iov_base = kmap(pages[i]);
-                       to_send[i+1].iov_len = copied; }
-
               cur_len = save_len - cur_len;

+               wdata->sync_mode = WB_SYNC_ALL;
+               wdata->nr_pages = nr_pages;
+               wdata->offset = (__u64)offset;
+               wdata->cfile = cifsFileInfo_get(open_file);
+               wdata->pid = pid;
+               wdata->bytes = cur_len;
+               wdata->marshal_iov = cifs_uncached_marshal_iov; do {
                       if (open_file->invalidHandle) {
                               rc = cifs_reopen_file(open_file, false);

Quoted 9 lines
Quoted 3 lines

                               if (rc != 0)
                                       break;
                       }

When we reopen a file, we do it with the current pid, but in cfile->pid leaves with the old value (and pid variable too).Should we do reopen with cfile->pid to save the original state of the file (now we don't restore locks, if we do it - it will be the problem)?

Yes, that does sound like something that should be fixed. That said, we have a lot of problems in the code that handles open files, and that's just one of them. At this point, I'm not going to fix that in this patchset since it's an existing bug and unrelated to what I'm changing here. It certainly wouldn't hurt to fix that at some point though.

Quoted 106 lines
Quoted 97 lines

-                       io_parms.netfid = open_file->netfid;
-                       io_parms.pid = pid;
-                       io_parms.tcon = tcon;
-                       io_parms.offset = *poffset;
-                       io_parms.length = cur_len;
-                       rc = CIFSSMBWrite2(xid, &io_parms, &written, to_send,
-                                          npages, 0);
+                       rc = cifs_async_writev(wdata);
               } while (rc == -EAGAIN);

-               for (i = 0; i < npages; i++)
-                       kunmap(pages[i]);
-
-               if (written) {
-                       len -= written;
-                       total_written += written;
-                       cifs_update_eof(CIFS_I(inode), *poffset, written);
-                       *poffset += written;
-               } else if (rc < 0) {
-                       if (!total_written)
-                               total_written = rc;
+               if (rc) {
+                       kref_put(&wdata->refcount, cifs_writedata_release); break;
               }

-               /* get length and number of kvecs of the next write */
-               npages = get_numpages(cifs_sb->wsize, len, &cur_len);
+               list_add_tail(&wdata->list, &wdata_list);
+               offset += cur_len;
+               len -= cur_len;
       } while (len > 0);

+       /*
+        * If at least one write was successfully sent, then discard any rc
+        * value from the later writes. If the other write succeeds, then
+        * we'll end up returning whatever was written. If it fails, then
+        * we'll get a new rc value from that.
+        */
+       if (!list_empty(&wdata_list))
+               rc = 0;

fs/cifs/file.c +33 -0
+
+       /*
+        * Wait for and collect replies for any successful sends in order of
+        * increasing offset. Once an error is hit or we get a fatal signal
+        * while waiting, then return without waiting for any more replies.
+        */
+restart_loop:
+       list_for_each_entry_safe(wdata, tmp, &wdata_list, list) {
+               if (!rc) {
+                       /* FIXME: freezable too? */
+                       rc = wait_for_completion_killable(&wdata->done);
+                       if (!rc) {
+                               if (wdata->result)
+                                       rc = wdata->result;
+                               else
+                                       total_written += wdata->bytes;
+                       } else if (rc == -EAGAIN) {
+                               do {
+                                       if (open_file->invalidHandle) {
+                                               rc = cifs_reopen_file(open_file,
+                                                                       false);
+                                               if (rc != 0)
+                                                       break;
+                                       }
+                                       rc = cifs_async_writev(wdata);
+                               } while (rc == -EAGAIN);
+                               goto restart_loop;
+                       }
+               }
+               list_del_init(&wdata->list);
+               kref_put(&wdata->refcount, cifs_writedata_release);
+       }
+

       if (total_written > 0) {
+               cifs_update_eof(cifsi, *poffset, total_written);
+               *poffset += total_written; spin_lock(&inode->i_lock);
-               if (*poffset > inode->i_size)
-                       i_size_write(inode, *poffset);
+               if (offset > inode->i_size)
+                       i_size_write(inode, cifsi->server_eof); spin_unlock(&inode->i_lock);
       }

       cifs_stats_bytes_written(tcon, total_written);
-       mark_inode_dirty_sync(inode);
-
-       for (i = 0; i < num_pages; i++)
-               put_page(pages[i]);
-       kfree(to_send);
-       kfree(pages);
-       FreeXid(xid);
-       return total_written;
+       return total_written ? total_written : (ssize_t)rc; }

Quoted 4 lines

 ssize_t cifs_user_writev(struct kiocb *iocb, const struct iovec *iov, --
1.7.7.6

The patch itself looks correct.

Signature · 1 line
Jeff Layton <[email protected]>
#29 lore raw

Re: [PATCH v1 8/8] cifs: convert cifs_iovec_write to use async writes

In reply to a message not in the archive

2012/2/21 Jeff Layton <[email protected]>:

Quoted 202 lines
Quoted 189 lines · On Tue, 21 Feb 2012 12:06:49 +0400 Pavel Shilovsky…

2012/2/3 Jeff Layton <[email protected]>:

Quoted 188 lines

---
 fs/cifs/cifsproto.h |    2 +
 fs/cifs/cifssmb.c   |    4 +-
 fs/cifs/file.c      |  191 ++++++++++++++++++++++++++++++++-------------------

 3 files changed, 126 insertions(+), 71 deletions(-)
fs/cifs/cifsproto.h +2 -0
index bceadc5..a131ded 100644
@@ -473,6 +473,8 @@ int cifs_async_readv(struct cifs_readdata *rdata);
  /* asynchronous write support */
  struct cifs_writedata {
        struct kref                     refcount;
+       struct list_head                list;
+       struct completion               done;
        enum writeback_sync_modes       sync_mode;
        struct work_struct              work;
        struct cifsFileInfo             *cfile;
fs/cifs/cifssmb.c +0 -0
index 113b5af..6e93c9e 100644
@@ -2034,8 +2034,10 @@ cifs_writedata_alloc(unsigned int nr_pages, work_func_t complete)

       wdata = kzalloc(sizeof(*wdata) +
                       sizeof(struct page *) * (nr_pages - 1), GFP_NOFS); if (wdata != NULL) {
-               INIT_WORK(&wdata->work, complete); kref_init(&wdata->refcount);
+               INIT_LIST_HEAD(&wdata->list);
+               init_completion(&wdata->done);
+               INIT_WORK(&wdata->work, complete);
       }
       return wdata;
 }

fs/cifs/file.c +31 -0
index c7e47a2..ef25fc5 100644
@@ -2057,23 +2057,55 @@ size_t get_numpages(const size_t wsize, const size_t len, size_t *cur_len)
        return num_pages;
  }
 
+static void
+cifs_uncached_marshal_iov(struct kvec *iov, struct cifs_writedata *wdata)
+{
+       int i;
+       size_t bytes = wdata->bytes;
+
+       /* marshal up the pages into iov array */
+       for (i = 0; i < wdata->nr_pages; i++) {
+               iov[i + 1].iov_len = min(bytes, PAGE_SIZE);
+               iov[i + 1].iov_base = kmap(wdata->pages[i]);
+               bytes -= iov[i + 1].iov_len;
+       }
+}
+
+static void
+cifs_uncached_writev_complete(struct work_struct *work)
+{
+       int i;
+       struct cifs_writedata *wdata = container_of(work,
+                                       struct cifs_writedata, work);
+
+       complete(&wdata->done);
+
+       if (wdata->result != -EAGAIN) {
+               for (i = 0; i < wdata->nr_pages; i++)
+                       put_page(wdata->pages[i]);
+       }
+
+       kref_put(&wdata->refcount, cifs_writedata_release);
+}
+

 static ssize_t
 cifs_iovec_write(struct file *file, const struct iovec *iov, unsigned long nr_segs, loff_t *poffset) {
-       unsigned int written;
-       unsigned long num_pages, npages, i;
+       unsigned long nr_pages, i;
       size_t copied, len, cur_len;
       ssize_t total_written = 0;
-       struct kvec *to_send;
-       struct page **pages;
+       loff_t offset = *poffset;
       struct iov_iter it;
-       struct inode *inode;
+       struct inode *inode = file->f_path.dentry->d_inode;
+       struct cifsInodeInfo *cifsi = CIFS_I(inode); struct cifsFileInfo *open_file;
       struct cifs_tcon *tcon;
       struct cifs_sb_info *cifs_sb;
-       int xid, rc;
-       __u32 pid;
+       struct cifs_writedata *wdata, *tmp;
+       struct list_head wdata_list;
+       int rc;
+       pid_t pid;

       len = iov_length(iov, nr_segs);
       if (!len)

fs/cifs/file.c +2 -20
@@ -2083,103 +2115,122 @@ cifs_iovec_write(struct file *file, const struct iovec *iov,
        if (rc)
                return rc;
 
+       INIT_LIST_HEAD(&wdata_list);
        cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
-       num_pages = get_numpages(cifs_sb->wsize, len, &cur_len);
-
-       pages = kmalloc(sizeof(struct pages *)*num_pages, GFP_KERNEL);
-       if (!pages)
-               return -ENOMEM;
-
-       to_send = kmalloc(sizeof(struct kvec)*(num_pages + 1), GFP_KERNEL);
-       if (!to_send) {
-               kfree(pages);
-               return -ENOMEM;
-       }
-
-       rc = cifs_write_allocate_pages(pages, num_pages);
-       if (rc) {
-               kfree(pages);
-               kfree(to_send);
-               return rc;
-       }
-
-       xid = GetXid();
        open_file = file->private_data;
+       tcon = tlink_tcon(open_file->tlink);
 
        if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD)
                pid = open_file->pid;

       else
               pid = current->tgid;

-       tcon = tlink_tcon(open_file->tlink);
-       inode = file->f_path.dentry->d_inode;
-
       iov_iter_init(&it, iov, nr_segs, len, 0);
-       npages = num_pages;
-
       do {
-               size_t save_len = cur_len;
-               for (i = 0; i < npages; i++) {
-                       copied = min_t(const size_t, cur_len, PAGE_CACHE_SIZE);
-                       copied = iov_iter_copy_from_user(pages[i], &it, 0,
-                                                        copied);
+               size_t save_len;

fs/cifs/file.c +20 -0
+
+               nr_pages = get_numpages(cifs_sb->wsize, len, &cur_len);
+               wdata = cifs_writedata_alloc(nr_pages,
+                                            cifs_uncached_writev_complete);
+               if (!wdata) {
+                       rc = -ENOMEM;
+                       break;
+               }
+
+               rc = cifs_write_allocate_pages(wdata->pages, nr_pages);
+               if (rc) {
+                       kfree(wdata);
+                       break;
+               }
+
+               save_len = cur_len;
+               for (i = 0; i < nr_pages; i++) {
+                       copied = min_t(const size_t, cur_len, PAGE_SIZE);
+                       copied = iov_iter_copy_from_user(wdata->pages[i], &it,
+                                                        0, copied);

                       cur_len -= copied; iov_iter_advance(&it, copied);
-                       to_send[i+1].iov_base = kmap(pages[i]);
-                       to_send[i+1].iov_len = copied; }
-
               cur_len = save_len - cur_len;

+               wdata->sync_mode = WB_SYNC_ALL;
+               wdata->nr_pages = nr_pages;
+               wdata->offset = (__u64)offset;
+               wdata->cfile = cifsFileInfo_get(open_file);
+               wdata->pid = pid;
+               wdata->bytes = cur_len;
+               wdata->marshal_iov = cifs_uncached_marshal_iov; do {
                       if (open_file->invalidHandle) {
                               rc = cifs_reopen_file(open_file, false);

Quoted 9 lines
Quoted 3 lines

                               if (rc != 0)
                                       break;
                       }

When we reopen a file, we do it with the current pid, but in cfile->pid leaves with the old value (and pid variable too).Should we do reopen with cfile->pid to save the original state of the file (now we don't restore locks, if we do it - it will be the problem)?

Quoted 6 lines

Yes, that does sound like something that should be fixed. That said, we have a lot of problems in the code that handles open files, and that's just one of them. At this point, I'm not going to fix that in this patchset since it's an existing bug and unrelated to what I'm changing here. It certainly wouldn't hurt to fix that at some point though.

I agree - this doesn't related to the patch, it simply pointed me to this existing problem.

Signature · 2 lines
Best regards,
Pavel Shilovsky.
#31 lore raw

Re: [PATCH v1 8/8] cifs: convert cifs_iovec_write to use async writes

In reply to a message not in the archive

Jeff,
We should cleanup compile warning - was planning to add a tiny patch to fix if no objection.

Look correct?

fs/cifs/file.c +0 -0
index daaaca8..460d87b 100644
@@ -2114,7 +2114,7 @@ cifs_uncached_marshal_iov(struct kvec *iov,

struct cifs_writedata *wdata)

        /* marshal up the pages into iov array */
        for (i = 0; i < wdata->nr_pages; i++) {
-               iov[i + 1].iov_len = min(bytes, PAGE_SIZE);
+               iov[i + 1].iov_len = min_t(size_t, bytes, PAGE_SIZE);
                iov[i + 1].iov_base = kmap(wdata->pages[i]);
                bytes -= iov[i + 1].iov_len;
        }
Quoted 216 lines · Pavel Shilovsky

2012/2/21 Jeff Layton <[email protected]>:

Quoted 202 lines
Quoted 189 lines · On Tue, 21 Feb 2012 12:06:49 +0400 Pavel Shilovsky…

2012/2/3 Jeff Layton <[email protected]>:

Quoted 188 lines

---
 fs/cifs/cifsproto.h |    2 +
 fs/cifs/cifssmb.c   |    4 +-
 fs/cifs/file.c      |  191 ++++++++++++++++++++++++++++++++-------------------

 3 files changed, 126 insertions(+), 71 deletions(-)
fs/cifs/cifsproto.h +2 -0
index bceadc5..a131ded 100644
@@ -473,6 +473,8 @@ int cifs_async_readv(struct cifs_readdata *rdata);
  /* asynchronous write support */
  struct cifs_writedata {
        struct kref                     refcount;
+       struct list_head                list;
+       struct completion               done;
        enum writeback_sync_modes       sync_mode;
        struct work_struct              work;
        struct cifsFileInfo             *cfile;
fs/cifs/cifssmb.c +0 -0
index 113b5af..6e93c9e 100644
@@ -2034,8 +2034,10 @@ cifs_writedata_alloc(unsigned int nr_pages, work_func_t complete)

       wdata = kzalloc(sizeof(*wdata) +
                       sizeof(struct page *) * (nr_pages - 1), GFP_NOFS); if (wdata != NULL) {
-               INIT_WORK(&wdata->work, complete); kref_init(&wdata->refcount);
+               INIT_LIST_HEAD(&wdata->list);
+               init_completion(&wdata->done);
+               INIT_WORK(&wdata->work, complete);
       }
       return wdata;
 }

fs/cifs/file.c +31 -0
index c7e47a2..ef25fc5 100644
@@ -2057,23 +2057,55 @@ size_t get_numpages(const size_t wsize, const size_t len, size_t *cur_len)
        return num_pages;
  }
 
+static void
+cifs_uncached_marshal_iov(struct kvec *iov, struct cifs_writedata *wdata)
+{
+       int i;
+       size_t bytes = wdata->bytes;
+
+       /* marshal up the pages into iov array */
+       for (i = 0; i < wdata->nr_pages; i++) {
+               iov[i + 1].iov_len = min(bytes, PAGE_SIZE);
+               iov[i + 1].iov_base = kmap(wdata->pages[i]);
+               bytes -= iov[i + 1].iov_len;
+       }
+}
+
+static void
+cifs_uncached_writev_complete(struct work_struct *work)
+{
+       int i;
+       struct cifs_writedata *wdata = container_of(work,
+                                       struct cifs_writedata, work);
+
+       complete(&wdata->done);
+
+       if (wdata->result != -EAGAIN) {
+               for (i = 0; i < wdata->nr_pages; i++)
+                       put_page(wdata->pages[i]);
+       }
+
+       kref_put(&wdata->refcount, cifs_writedata_release);
+}
+

 static ssize_t
 cifs_iovec_write(struct file *file, const struct iovec *iov, unsigned long nr_segs, loff_t *poffset) {
-       unsigned int written;
-       unsigned long num_pages, npages, i;
+       unsigned long nr_pages, i;
       size_t copied, len, cur_len;
       ssize_t total_written = 0;
-       struct kvec *to_send;
-       struct page **pages;
+       loff_t offset = *poffset;
       struct iov_iter it;
-       struct inode *inode;
+       struct inode *inode = file->f_path.dentry->d_inode;
+       struct cifsInodeInfo *cifsi = CIFS_I(inode); struct cifsFileInfo *open_file;
       struct cifs_tcon *tcon;
       struct cifs_sb_info *cifs_sb;
-       int xid, rc;
-       __u32 pid;
+       struct cifs_writedata *wdata, *tmp;
+       struct list_head wdata_list;
+       int rc;
+       pid_t pid;

       len = iov_length(iov, nr_segs);
       if (!len)

fs/cifs/file.c +2 -20
@@ -2083,103 +2115,122 @@ cifs_iovec_write(struct file *file, const struct iovec *iov,
        if (rc)
                return rc;
 
+       INIT_LIST_HEAD(&wdata_list);
        cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
-       num_pages = get_numpages(cifs_sb->wsize, len, &cur_len);
-
-       pages = kmalloc(sizeof(struct pages *)*num_pages, GFP_KERNEL);
-       if (!pages)
-               return -ENOMEM;
-
-       to_send = kmalloc(sizeof(struct kvec)*(num_pages + 1), GFP_KERNEL);
-       if (!to_send) {
-               kfree(pages);
-               return -ENOMEM;
-       }
-
-       rc = cifs_write_allocate_pages(pages, num_pages);
-       if (rc) {
-               kfree(pages);
-               kfree(to_send);
-               return rc;
-       }
-
-       xid = GetXid();
        open_file = file->private_data;
+       tcon = tlink_tcon(open_file->tlink);
 
        if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD)
                pid = open_file->pid;

       else
               pid = current->tgid;

-       tcon = tlink_tcon(open_file->tlink);
-       inode = file->f_path.dentry->d_inode;
-
       iov_iter_init(&it, iov, nr_segs, len, 0);
-       npages = num_pages;
-
       do {
-               size_t save_len = cur_len;
-               for (i = 0; i < npages; i++) {
-                       copied = min_t(const size_t, cur_len, PAGE_CACHE_SIZE);
-                       copied = iov_iter_copy_from_user(pages[i], &it, 0,
-                                                        copied);
+               size_t save_len;

fs/cifs/file.c +20 -0
+
+               nr_pages = get_numpages(cifs_sb->wsize, len, &cur_len);
+               wdata = cifs_writedata_alloc(nr_pages,
+                                            cifs_uncached_writev_complete);
+               if (!wdata) {
+                       rc = -ENOMEM;
+                       break;
+               }
+
+               rc = cifs_write_allocate_pages(wdata->pages, nr_pages);
+               if (rc) {
+                       kfree(wdata);
+                       break;
+               }
+
+               save_len = cur_len;
+               for (i = 0; i < nr_pages; i++) {
+                       copied = min_t(const size_t, cur_len, PAGE_SIZE);
+                       copied = iov_iter_copy_from_user(wdata->pages[i], &it,
+                                                        0, copied);

                       cur_len -= copied; iov_iter_advance(&it, copied);
-                       to_send[i+1].iov_base = kmap(pages[i]);
-                       to_send[i+1].iov_len = copied; }
-
               cur_len = save_len - cur_len;

+               wdata->sync_mode = WB_SYNC_ALL;
+               wdata->nr_pages = nr_pages;
+               wdata->offset = (__u64)offset;
+               wdata->cfile = cifsFileInfo_get(open_file);
+               wdata->pid = pid;
+               wdata->bytes = cur_len;
+               wdata->marshal_iov = cifs_uncached_marshal_iov; do {
                       if (open_file->invalidHandle) {
                               rc = cifs_reopen_file(open_file, false);

Quoted 9 lines
Quoted 3 lines

                               if (rc != 0)
                                       break;
                       }

When we reopen a file, we do it with the current pid, but in cfile->pid leaves with the old value (and pid variable too).Should we do reopen with cfile->pid to save the original state of the file (now we don't restore locks, if we do it - it will be the problem)?

Quoted 6 lines

Yes, that does sound like something that should be fixed. That said, we have a lot of problems in the code that handles open files, and that's just one of them. At this point, I'm not going to fix that in this patchset since it's an existing bug and unrelated to what I'm changing here. It certainly wouldn't hurt to fix that at some point though.

I agree - this doesn't related to the patch, it simply pointed me to this existing problem.

--
Best regards,
Pavel Shilovsky.

Signature · 3 lines
Thanks,

Steve
#33 lore raw

Re: [PATCH v1 8/8] cifs: convert cifs_iovec_write to use async writes

In reply to a message not in the archive
Quoted 19 lines · On Fri, 23 Mar 2012 15:55:14 -0500 Steve French…

Jeff,
We should cleanup compile warning - was planning to add a tiny patch to fix if no objection.

Look correct?

fs/cifs/file.c +1 -1
index daaaca8..460d87b 100644
@@ -2114,7 +2114,7 @@ cifs_uncached_marshal_iov(struct kvec *iov,
 struct cifs_writedata *wdata)
 
        /* marshal up the pages into iov array */
        for (i = 0; i < wdata->nr_pages; i++) {
-               iov[i + 1].iov_len = min(bytes, PAGE_SIZE);
+               iov[i + 1].iov_len = min_t(size_t, bytes, PAGE_SIZE);
                iov[i + 1].iov_base = kmap(wdata->pages[i]);
                bytes -= iov[i + 1].iov_len;
Quoted 2 lines
        }

That patch looks harmless, but I don't seem to be able to reproduce any warnings. Can you elaborate on how you're getting a warning from that?

Signature · 1 line
Jeff Layton <[email protected]>
#35 lore raw

Re: [PATCH v1 8/8] cifs: convert cifs_iovec_write to use async writes

In reply to a message not in the archive
Quoted 16 lines · Jeff Layton
Quoted 13 lines · On Fri, 23 Mar 2012 15:55:14 -0500 Steve French…

Jeff,
We should cleanup compile warning - was planning to add a tiny patch to fix if no objection.

Look correct?

fs/cifs/file.c +0 -0
index daaaca8..460d87b 100644
@@ -2114,7 +2114,7 @@ cifs_uncached_marshal_iov(struct kvec *iov,
 struct cifs_writedata *wdata)
 
Quoted 11 lines
Quoted 8 lines
fs/cifs/file.c +1 -1
         /* marshal up the pages into iov array */
         for (i = 0; i < wdata->nr_pages; i++) {
-               iov[i + 1].iov_len = min(bytes, PAGE_SIZE);
+               iov[i + 1].iov_len = min_t(size_t, bytes, PAGE_SIZE);
                 iov[i + 1].iov_base = kmap(wdata->pages[i]);
                 bytes -= iov[i + 1].iov_len;

        }

That patch looks harmless, but I don't seem to be able to reproduce any warnings. Can you elaborate on how you're getting a warning from that?

make modules C=1 M=fs/cifs CF=-D__CHECK_ENDIAN__

FC16

[stevef@smf-gateway cifs-2.6]$ gcc --version
gcc (GCC) 4.6.2 20111027 (Red Hat 4.6.2-1)
Copyright (C) 2011 Free Software Foundation, Inc.

Signature · 3 lines
Thanks,

Steve
#37 lore raw

Re: [PATCH v1 8/8] cifs: convert cifs_iovec_write to use async writes

In reply to a message not in the archive
Quoted 29 lines · On Fri, 23 Mar 2012 16:05:20 -0500 Steve French…
Quoted 16 lines · Jeff Layton
Quoted 13 lines · On Fri, 23 Mar 2012 15:55:14 -0500 Steve French…

Jeff,
We should cleanup compile warning - was planning to add a tiny patch to fix if no objection.

Look correct?

fs/cifs/file.c +0 -0
index daaaca8..460d87b 100644
@@ -2114,7 +2114,7 @@ cifs_uncached_marshal_iov(struct kvec *iov,
 struct cifs_writedata *wdata)
 
Quoted 11 lines
Quoted 8 lines
fs/cifs/file.c +1 -1
         /* marshal up the pages into iov array */
         for (i = 0; i < wdata->nr_pages; i++) {
-               iov[i + 1].iov_len = min(bytes, PAGE_SIZE);
+               iov[i + 1].iov_len = min_t(size_t, bytes, PAGE_SIZE);
                 iov[i + 1].iov_base = kmap(wdata->pages[i]);
                 bytes -= iov[i + 1].iov_len;

        }

That patch looks harmless, but I don't seem to be able to reproduce any warnings. Can you elaborate on how you're getting a warning from that?

Quoted 9 lines

make modules C=1 M=fs/cifs CF=-D__CHECK_ENDIAN__

FC16

[stevef@smf-gateway cifs-2.6]$ gcc --version
gcc (GCC) 4.6.2 20111027 (Red Hat 4.6.2-1)
Copyright (C) 2011 Free Software Foundation, Inc.

Hrm...I don't see it on my F16 box. Are you on 32 bit arch? If so, that might be why. In any case, that patch is fine if it silences the warning for you.

Signature · 1 line
Jeff Layton <[email protected]>
#39 lore raw

Re: [PATCH v1 8/8] cifs: convert cifs_iovec_write to use async writes

In reply to a message not in the archive
Quoted 42 lines · Jeff Layton
Quoted 29 lines · On Fri, 23 Mar 2012 16:05:20 -0500 Steve French…
Quoted 16 lines · Jeff Layton
Quoted 13 lines · On Fri, 23 Mar 2012 15:55:14 -0500 Steve French…

Jeff,
We should cleanup compile warning - was planning to add a tiny patch to fix if no objection.

Look correct?

fs/cifs/file.c +0 -0
index daaaca8..460d87b 100644
@@ -2114,7 +2114,7 @@ cifs_uncached_marshal_iov(struct kvec *iov,
 struct cifs_writedata *wdata)
 
Quoted 11 lines
Quoted 8 lines
fs/cifs/file.c +1 -1
         /* marshal up the pages into iov array */
         for (i = 0; i < wdata->nr_pages; i++) {
-               iov[i + 1].iov_len = min(bytes, PAGE_SIZE);
+               iov[i + 1].iov_len = min_t(size_t, bytes, PAGE_SIZE);
                 iov[i + 1].iov_base = kmap(wdata->pages[i]);
                 bytes -= iov[i + 1].iov_len;

        }

That patch looks harmless, but I don't seem to be able to reproduce any warnings. Can you elaborate on how you're getting a warning from that?

Quoted 9 lines

make modules C=1 M=fs/cifs CF=-D__CHECK_ENDIAN__

FC16

[stevef@smf-gateway cifs-2.6]$ gcc --version
gcc (GCC) 4.6.2 20111027 (Red Hat 4.6.2-1)
Copyright (C) 2011 Free Software Foundation, Inc.

Quoted 3 lines

Hrm...I don't see it on my F16 box. Are you on 32 bit arch? If so, that might be why. In any case, that patch is fine if it silences the warning for you.

yes - 32 bit arch on this system.

Signature · 3 lines
Thanks,

Steve