From patchwork Sun May 7 04:59:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Butterfield X-Patchwork-Id: 9715661 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AE8876020F for ; Sun, 7 May 2017 23:58:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9534A24603 for ; Sun, 7 May 2017 23:58:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 89F9C265B9; Sun, 7 May 2017 23:58:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 54FF124603 for ; Sun, 7 May 2017 23:58:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751516AbdEGX6s (ORCPT ); Sun, 7 May 2017 19:58:48 -0400 Received: from mail-io0-f194.google.com ([209.85.223.194]:35801 "EHLO mail-io0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751412AbdEGX6r (ORCPT ); Sun, 7 May 2017 19:58:47 -0400 Received: by mail-io0-f194.google.com with SMTP id o12so143634iod.2 for ; Sun, 07 May 2017 16:58:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=Y4KqbKWiKT5682pj7Ng5eDwUqot03VaL6FaC1mmWpPg=; b=eQalMHAFOTBTH7UN3MLfGYwfEMNkBD1ZX5TpgLiGOrYH7ZWLZoh3ROa3iGRKhxwICh 6+qFPo0r79jhCWv6WOPd183CXFeiF+BVRHGBLjaYol0BLebNEhEME+6tzdCDxUpVntgM s6Nz5+qZj+stl1FMC5e1IpO7q3UER5PwnL+hfnFBa2DEtdR3HWJbjrDp6sjBsAqoIaed /p1RTrFZ03tA8ZvGVyWVBYQF/TxJhrWldXjdKd+9T8qJnY0c4el/wnQaz4o4DXIOWQCD PUv1N9uRtgKERy9B1UOL5vSq8E06vg4pKBJcR2aDJWHa0NIv7lBvmVeZocj7kv/pB8pW iaeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Y4KqbKWiKT5682pj7Ng5eDwUqot03VaL6FaC1mmWpPg=; b=HExyFrGl4oP0+mCcUit0cZGmPtDgdERG8yQTdq701Yg/qAEn7OgtuMCxAWgh53byp5 AYzAZGY937TkGiOK+1TIyO/vZ68fs0PnWjp5yxDTo0FGpS6W6dJXMFOTh79BIw30xN/k LQ2mPu9po9K5BVSStsmNinAzcfkL4mcSKtKxyrIuOfaAzKFavMmrxogtELqn1H5l9S6P BSvgBphPckcYaSMro+3l3yie1ZQ3AOPUb/LnTMiwHP/uEbV6MNMhGjcO+UYNj1S//S2d oWJcmU3jXyP7Y0JD2hLyGsresB2XyzsyyLghamx6zUyFMl/c5v4P7qEM8R1vHghrEj18 kMOQ== X-Gm-Message-State: AN3rC/6cq8LWCm3RfVtdPiOtUT2i3RX7LbCkQR1VXFvTmhCxM3PxVdF6 4uLI+robhPvEtXXz X-Received: by 10.107.10.223 with SMTP id 92mr19161221iok.108.1494133165838; Sat, 06 May 2017 21:59:25 -0700 (PDT) Received: from localhost.localdomain (c-73-181-28-74.hsd1.co.comcast.net. [73.181.28.74]) by smtp.gmail.com with ESMTPSA id 2sm8787574iof.47.2017.05.06.21.59.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 06 May 2017 21:59:25 -0700 (PDT) From: David Butterfield To: target-devel@vger.kernel.org Cc: David Butterfield Subject: [PATCH] use rbd_aio_readv/_writev instead of bounce_buffer Date: Sat, 6 May 2017 22:59:08 -0600 Message-Id: <20170507045908.19579-1-dab21774@gmail.com> X-Mailer: git-send-email 2.12.2.575.gb14f27f Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This change may need adjustment for local style conventions; but it's what I did in my copy to use the rbd iovec functions instead of copying through a bounce_buffer. Note all the extra conditional checks are done at compile-time. Signed-off-by: David Butterfield --- rbd.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 19 deletions(-) diff --git a/rbd.c b/rbd.c index c8019b5..1b80d14 100644 --- a/rbd.c +++ b/rbd.c @@ -37,6 +37,17 @@ #include +/* Use gcc -DCONFIG_TCMU_NO_IOV=0 to enable use of RBD iovec calls */ +/* Use gcc -DCONFIG_TCMU_NO_IOV=1 to disable use of RBD iovec calls */ +#ifndef CONFIG_TCMU_NO_IOV +#define CONFIG_TCMU_NO_IOV true /* default for now is to assume older library */ +#endif + +#if CONFIG_TCMU_NO_IOV +#define rbd_aio_readv(image, iov, iov_cnt, offset, completion) -EIO +#define rbd_aio_writev(image, iov, iov_cnt, offset, completion) -EIO +#endif + enum { TCMU_RBD_OPENING, TCMU_RBD_OPENED, @@ -516,15 +527,18 @@ static void rbd_finish_aio_read(rbd_completion_t completion, } else if (ret < 0) { tcmu_r = tcmu_set_sense_data(tcmulib_cmd->sense_buf, MEDIUM_ERROR, ASC_READ_ERROR, NULL); - } else { + } else if (CONFIG_TCMU_NO_IOV) { tcmu_r = SAM_STAT_GOOD; tcmu_memcpy_into_iovec(iovec, iov_cnt, aio_cb->bounce_buffer, aio_cb->length); - } + } else + tcmu_r = SAM_STAT_GOOD; tcmulib_cmd->done(dev, tcmulib_cmd, tcmu_r); - free(aio_cb->bounce_buffer); + if (CONFIG_TCMU_NO_IOV) + free(aio_cb->bounce_buffer); + free(aio_cb); } @@ -547,10 +561,12 @@ static int tcmu_rbd_read(struct tcmu_device *dev, struct tcmulib_cmd *cmd, aio_cb->length = length; aio_cb->tcmulib_cmd = cmd; - aio_cb->bounce_buffer = malloc(length); - if (!aio_cb->bounce_buffer) { - tcmu_dev_err(dev, "Could not allocate bounce buffer.\n"); - goto out_free_aio_cb; + if (CONFIG_TCMU_NO_IOV) { + aio_cb->bounce_buffer = malloc(length); + if (!aio_cb->bounce_buffer) { + tcmu_dev_err(dev, "Could not allocate bounce buffer.\n"); + goto out_free_aio_cb; + } } ret = rbd_aio_create_completion @@ -559,8 +575,12 @@ static int tcmu_rbd_read(struct tcmu_device *dev, struct tcmulib_cmd *cmd, goto out_free_bounce_buffer; } - ret = rbd_aio_read(state->image, offset, length, aio_cb->bounce_buffer, - completion); + if (CONFIG_TCMU_NO_IOV) + ret = rbd_aio_read(state->image, offset, length, + aio_cb->bounce_buffer, completion); + else + ret = rbd_aio_readv(state->image, iov, iov_cnt, offset, completion); + if (ret < 0) { goto out_remove_tracked_aio; } @@ -570,7 +590,8 @@ static int tcmu_rbd_read(struct tcmu_device *dev, struct tcmulib_cmd *cmd, out_remove_tracked_aio: rbd_aio_release(completion); out_free_bounce_buffer: - free(aio_cb->bounce_buffer); + if (CONFIG_TCMU_NO_IOV) + free(aio_cb->bounce_buffer); out_free_aio_cb: free(aio_cb); out: @@ -628,22 +649,27 @@ static int tcmu_rbd_write(struct tcmu_device *dev, struct tcmulib_cmd *cmd, aio_cb->length = length; aio_cb->tcmulib_cmd = cmd; - aio_cb->bounce_buffer = malloc(length); - if (!aio_cb->bounce_buffer) { - tcmu_dev_err(dev, "Failed to allocate bounce buffer.\n"); - goto out_free_aio_cb; + if (CONFIG_TCMU_NO_IOV) { + aio_cb->bounce_buffer = malloc(length); + if (!aio_cb->bounce_buffer) { + tcmu_dev_err(dev, "Failed to allocate bounce buffer.\n"); + goto out_free_aio_cb; + } + tcmu_memcpy_from_iovec(aio_cb->bounce_buffer, length, iov, iov_cnt); } - tcmu_memcpy_from_iovec(aio_cb->bounce_buffer, length, iov, iov_cnt); - ret = rbd_aio_create_completion (aio_cb, (rbd_callback_t) rbd_finish_aio_generic, &completion); if (ret < 0) { goto out_free_bounce_buffer; } - ret = rbd_aio_write(state->image, offset, - length, aio_cb->bounce_buffer, completion); + if (CONFIG_TCMU_NO_IOV) + ret = rbd_aio_write(state->image, offset, + length, aio_cb->bounce_buffer, completion); + else + ret = rbd_aio_writev(state->image, iov, iov_cnt, offset, completion); + if (ret < 0) { goto out_remove_tracked_aio; } @@ -653,7 +679,8 @@ static int tcmu_rbd_write(struct tcmu_device *dev, struct tcmulib_cmd *cmd, out_remove_tracked_aio: rbd_aio_release(completion); out_free_bounce_buffer: - free(aio_cb->bounce_buffer); + if (CONFIG_TCMU_NO_IOV) + free(aio_cb->bounce_buffer); out_free_aio_cb: free(aio_cb); out: @@ -733,5 +760,8 @@ struct tcmur_handler tcmu_rbd_handler = { int handler_init(void) { + if (!CONFIG_TCMU_NO_IOV) + tcmu_info("tcmu/rbd using iovec calls"); + return tcmur_register_handler(&tcmu_rbd_handler); }