From patchwork Mon Jun 23 14:58:34 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 4403641 Return-Path: X-Original-To: patchwork-cifs-client@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7432A9F390 for ; Mon, 23 Jun 2014 14:59:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8194520225 for ; Mon, 23 Jun 2014 14:59:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 419E92017E for ; Mon, 23 Jun 2014 14:59:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755850AbaFWO7F (ORCPT ); Mon, 23 Jun 2014 10:59:05 -0400 Received: from mail-lb0-f174.google.com ([209.85.217.174]:63562 "EHLO mail-lb0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755817AbaFWO7B (ORCPT ); Mon, 23 Jun 2014 10:59:01 -0400 Received: by mail-lb0-f174.google.com with SMTP id u10so4689541lbd.19 for ; Mon, 23 Jun 2014 07:58:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=O56xHRFCFJKEp8T3DM+e1oRciAuh92JPcTYIrrowopg=; b=U/iMiAobGgS2JRw4V+mvLbswjyNYNsEJ2L63zNQNjVNKMV90mY579v+IyrwU5YQVBy p2urXcRARuArlvoDrRf0HDI59mY3sp3FnsjmHVQhqNs6WiPuZ/55OEyRvo108PP+tTVP nszsXsrbGKT1SdZZrvzaks9seQZXHFOKloOqvlEhlxfeVsOjvVjtJU28VgTSUc9TqZqH stLtmUsUBHuuzQj6COp3kFq+AwIvGODLHiXBuDlygBvJUitqPJ0H09MOL/iMnwI3vPbb 90XMgFz6+mYXOd0PD2MWMCHaP0cYPC1WMYjdK80ZtK811L5CG+g/+bNXR2ORfTOAuLXu l54w== X-Received: by 10.152.207.11 with SMTP id ls11mr2397432lac.62.1403535539395; Mon, 23 Jun 2014 07:58:59 -0700 (PDT) Received: from localhost.localdomain ([92.43.3.32]) by mx.google.com with ESMTPSA id fb6sm7964060lac.40.2014.06.23.07.58.57 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 23 Jun 2014 07:58:58 -0700 (PDT) From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 6/9] CIFS: Separate filling pages from iovec write Date: Mon, 23 Jun 2014 18:58:34 +0400 Message-Id: <1403535517-8301-7-git-send-email-pshilovsky@samba.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1403535517-8301-1-git-send-email-pshilovsky@samba.org> References: <1403535517-8301-1-git-send-email-pshilovsky@samba.org> Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Pavel Shilovsky --- fs/cifs/file.c | 88 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 50 insertions(+), 38 deletions(-) diff --git a/fs/cifs/file.c b/fs/cifs/file.c index e9dc57a..89d647b 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -2423,12 +2423,59 @@ cifs_uncached_retry_writev(struct cifs_writedata *wdata) return rc; } +static int +wdata_fill_from_iovec(struct cifs_writedata *wdata, struct iov_iter *it, + size_t *len, unsigned long nr_pages) +{ + int rc = 0; + size_t save_len, copied, bytes, cur_len = *len; + unsigned long i; + + save_len = cur_len; + for (i = 0; i < nr_pages; i++) { + bytes = min_t(const size_t, cur_len, PAGE_SIZE); + copied = iov_iter_copy_from_user(wdata->pages[i], it, + 0, bytes); + cur_len -= copied; + iov_iter_advance(it, copied); + /* + * If we didn't copy as much as we expected, then that + * may mean we trod into an unmapped area. Stop copying + * at that point. On the next pass through the big + * loop, we'll likely end up getting a zero-length + * write and bailing out of it. + */ + if (copied < bytes) + break; + } + cur_len = save_len - cur_len; + *len = cur_len; + + /* + * If we have no data to send, then that probably means that + * the copy above failed altogether. That's most likely because + * the address in the iovec was bogus. Return -EFAULT and let + * the caller free anything we allocated and bail out. + */ + if (!cur_len) + return -EFAULT; + + /* + * i + 1 now represents the number of pages we actually used in + * the copy phase above. Bring nr_pages down to that, and free + * any pages that we didn't use. + */ + for ( ; nr_pages > i + 1; nr_pages--) + put_page(wdata->pages[nr_pages - 1]); + return rc; +} + static ssize_t cifs_iovec_write(struct file *file, const struct iovec *iov, unsigned long nr_segs, loff_t *poffset) { unsigned long nr_pages, i; - size_t bytes, copied, len, cur_len; + size_t len, cur_len; ssize_t total_written = 0; loff_t offset; struct iov_iter it; @@ -2465,8 +2512,6 @@ cifs_iovec_write(struct file *file, const struct iovec *iov, iov_iter_init(&it, iov, nr_segs, len, 0); do { - size_t save_len; - nr_pages = get_numpages(cifs_sb->wsize, len, &cur_len); wdata = cifs_writedata_alloc(nr_pages, cifs_uncached_writev_complete); @@ -2481,47 +2526,14 @@ cifs_iovec_write(struct file *file, const struct iovec *iov, break; } - save_len = cur_len; - for (i = 0; i < nr_pages; i++) { - bytes = min_t(const size_t, cur_len, PAGE_SIZE); - copied = iov_iter_copy_from_user(wdata->pages[i], &it, - 0, bytes); - cur_len -= copied; - iov_iter_advance(&it, copied); - /* - * If we didn't copy as much as we expected, then that - * may mean we trod into an unmapped area. Stop copying - * at that point. On the next pass through the big - * loop, we'll likely end up getting a zero-length - * write and bailing out of it. - */ - if (copied < bytes) - break; - } - cur_len = save_len - cur_len; - - /* - * If we have no data to send, then that probably means that - * the copy above failed altogether. That's most likely because - * the address in the iovec was bogus. Set the rc to -EFAULT, - * free anything we allocated and bail out. - */ - if (!cur_len) { + rc = wdata_fill_from_iovec(wdata, &it, &cur_len, nr_pages); + if (rc) { for (i = 0; i < nr_pages; i++) put_page(wdata->pages[i]); kfree(wdata); - rc = -EFAULT; break; } - /* - * i + 1 now represents the number of pages we actually used in - * the copy phase above. Bring nr_pages down to that, and free - * any pages that we didn't use. - */ - for ( ; nr_pages > i + 1; nr_pages--) - put_page(wdata->pages[nr_pages - 1]); - wdata->sync_mode = WB_SYNC_ALL; wdata->nr_pages = nr_pages; wdata->offset = (__u64)offset;