From patchwork Mon Aug 6 11:31:02 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 1278421 Return-Path: X-Original-To: patchwork-cifs-client@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id B8054DF215 for ; Mon, 6 Aug 2012 11:31:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756003Ab2HFLb1 (ORCPT ); Mon, 6 Aug 2012 07:31:27 -0400 Received: from mail-yx0-f174.google.com ([209.85.213.174]:44654 "EHLO mail-yx0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755995Ab2HFLb1 (ORCPT ); Mon, 6 Aug 2012 07:31:27 -0400 Received: by yenl2 with SMTP id l2so2334016yen.19 for ; Mon, 06 Aug 2012 04:31:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=RX1VnnoKxbhTjIX3hNjkjoFZx0Jmv4hZ2IS9Rl2+hGY=; b=GTVXnpz32wYFwN5B17ohZDbu7jGTzymqhZLXqfRC8IDoCqSdSc/8rDk/OhBzVWigfB FdRMq0fO3betevQk/LO+mUhGEFHHMeZ/D7IBxMa/n16yu1QKvzHOygBPLiXcX0fI1yaF deFmVKBAobpU3BZkt5V2qR7iy3ey89rNSJG2PJiNi3n0ev63eZqTO5i8ZCkKoWQs/+k2 SoqliQRGlbhNeFAK9mlkgiZLRWzXhI/SQ67T6cBhJccKVqCZ/oViDgRGeYBRMabh0uOU xGMDlN8O9FUGrJU3+GpNV1Y+KuRbj2xnAuUGuNsI4ArmxOBH6mqwGqFOlJAJTTTEmyNu pXXg== Received: by 10.236.91.48 with SMTP id g36mr9530107yhf.53.1344252686504; Mon, 06 Aug 2012 04:31:26 -0700 (PDT) Received: from salusa.poochiereds.net (cpe-069-134-145-027.nc.res.rr.com. [69.134.145.27]) by mx.google.com with ESMTPS id r25sm31198420yhi.13.2012.08.06.04.31.25 (version=SSLv3 cipher=OTHER); Mon, 06 Aug 2012 04:31:25 -0700 (PDT) From: Jeff Layton To: smfrench@gmail.com Cc: linux-cifs@vger.kernel.org, piastryyy@gmail.com Subject: [PATCH v3 05/15] cifs: teach smb_send_rqst how to handle arrays of pages Date: Mon, 6 Aug 2012 07:31:02 -0400 Message-Id: <1344252672-15244-6-git-send-email-jlayton@redhat.com> X-Mailer: git-send-email 1.7.11.2 In-Reply-To: <1344252672-15244-1-git-send-email-jlayton@redhat.com> References: <1344252672-15244-1-git-send-email-jlayton@redhat.com> X-Gm-Message-State: ALoCoQmeeCZbNDcn13+xGni9t7vWmXBPsc+6HlMzAaNoKNrYLSinTt7Dovk8YfORO9BN1miADxtg Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org Add code that allows smb_send_rqst to send an array of pages after the initial kvec array has been sent. For now, we simply kmap the page array and send it using the standard smb_send_kvec function. Eventually, we may want to convert this code to use kernel_sendpage under the hood and avoid the kmap altogether for the page data. Reviewed-by: Pavel Shilovsky Signed-off-by: Jeff Layton --- fs/cifs/transport.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c index 8ff4c5f..381dbb7 100644 --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -240,6 +241,38 @@ smb_send_kvec(struct TCP_Server_Info *server, struct kvec *iov, size_t n_vec, return rc; } +/** + * rqst_page_to_kvec - Turn a slot in the smb_rqst page array into a kvec + * @rqst: pointer to smb_rqst + * @idx: index into the array of the page + * @iov: pointer to struct kvec that will hold the result + * + * Helper function to convert a slot in the rqst->rq_pages array into a kvec. + * The page will be kmapped and the address placed into iov_base. The length + * will then be adjusted according to the ptailoff. + */ +static void +cifs_rqst_page_to_kvec(struct smb_rqst *rqst, unsigned int idx, + struct kvec *iov) +{ + /* + * FIXME: We could avoid this kmap altogether if we used + * kernel_sendpage instead of kernel_sendmsg. That will only + * work if signing is disabled though as sendpage inlines the + * page directly into the fraglist. If userspace modifies the + * page after we calculate the signature, then the server will + * reject it and may break the connection. kernel_sendmsg does + * an extra copy of the data and avoids that issue. + */ + iov->iov_base = kmap(rqst->rq_pages[idx]); + + /* if last page, don't send beyond this offset into page */ + if (idx == (rqst->rq_npages - 1)) + iov->iov_len = rqst->rq_tailsz; + else + iov->iov_len = rqst->rq_pagesz; +} + static int smb_send_rqst(struct TCP_Server_Info *server, struct smb_rqst *rqst) { @@ -247,7 +280,8 @@ smb_send_rqst(struct TCP_Server_Info *server, struct smb_rqst *rqst) struct kvec *iov = rqst->rq_iov; int n_vec = rqst->rq_nvec; unsigned int smb_buf_length = get_rfc1002_length(iov[0].iov_base); - size_t total_len; + unsigned int i; + size_t total_len = 0, sent; struct socket *ssocket = server->ssocket; int val = 1; @@ -258,8 +292,26 @@ smb_send_rqst(struct TCP_Server_Info *server, struct smb_rqst *rqst) kernel_setsockopt(ssocket, SOL_TCP, TCP_CORK, (char *)&val, sizeof(val)); - rc = smb_send_kvec(server, iov, n_vec, &total_len); + rc = smb_send_kvec(server, iov, n_vec, &sent); + if (rc < 0) + goto uncork; + + total_len += sent; + + /* now walk the page array and send each page in it */ + for (i = 0; i < rqst->rq_npages; i++) { + struct kvec p_iov; + + cifs_rqst_page_to_kvec(rqst, i, &p_iov); + rc = smb_send_kvec(server, &p_iov, 1, &sent); + kunmap(rqst->rq_pages[i]); + if (rc < 0) + break; + + total_len += sent; + } +uncork: /* uncork it */ val = 0; kernel_setsockopt(ssocket, SOL_TCP, TCP_CORK,