From patchwork Thu Jan 7 14:05:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yan, Zheng" X-Patchwork-Id: 7977631 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 4F7459F3E6 for ; Thu, 7 Jan 2016 14:06:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6B671200DE for ; Thu, 7 Jan 2016 14:06:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 70B58201BB for ; Thu, 7 Jan 2016 14:06:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752358AbcAGOGD (ORCPT ); Thu, 7 Jan 2016 09:06:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50873 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752293AbcAGOGB (ORCPT ); Thu, 7 Jan 2016 09:06:01 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 995358F227; Thu, 7 Jan 2016 14:06:01 +0000 (UTC) Received: from localhost.localdomain (vpn1-4-93.pek2.redhat.com [10.72.4.93]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u07E5cWl003807; Thu, 7 Jan 2016 09:05:58 -0500 From: "Yan, Zheng" To: ceph-devel@vger.kernel.org Cc: idryomov@gmail.com, "Yan, Zheng" Subject: [PATCH 4/6] libceph: add helper that extends numner of operations in OSD request Date: Thu, 7 Jan 2016 22:05:26 +0800 Message-Id: <1452175528-20751-5-git-send-email-zyan@redhat.com> In-Reply-To: <1452175528-20751-1-git-send-email-zyan@redhat.com> References: <1452175528-20751-1-git-send-email-zyan@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 The helper function resizes the r_ops array and re-allocates request message. Signed-off-by: Yan, Zheng --- include/linux/ceph/osd_client.h | 3 ++ net/ceph/osd_client.c | 61 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/include/linux/ceph/osd_client.h b/include/linux/ceph/osd_client.h index 9802df1..6430766 100644 --- a/include/linux/ceph/osd_client.h +++ b/include/linux/ceph/osd_client.h @@ -322,6 +322,9 @@ extern struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client * unsigned int num_ops, bool use_mempool, gfp_t gfp_flags); +extern int ceph_osdc_extend_request(struct ceph_osd_request *req, + unsigned int num_ops, gfp_t gfp_flags); + extern void ceph_osdc_build_request(struct ceph_osd_request *req, u64 off, struct ceph_snap_context *snapc, diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c index 4a9d4e5..8349681 100644 --- a/net/ceph/osd_client.c +++ b/net/ceph/osd_client.c @@ -361,6 +361,67 @@ void ceph_osdc_put_request(struct ceph_osd_request *req) } EXPORT_SYMBOL(ceph_osdc_put_request); +int ceph_osdc_extend_request(struct ceph_osd_request *req, + unsigned int num_ops, gfp_t gfp_flags) +{ + struct ceph_osd_req_op *new_ops; + struct ceph_msg *request_msg; + struct ceph_msg *reply_msg = NULL; + size_t msg_size; + + if (num_ops > CEPH_OSD_MAX_OP) + return -EINVAL; + + if (num_ops <= req->r_max_ops) + return 0; + + msg_size = req->r_request->front_alloc_len + + (num_ops - req->r_max_ops) * + sizeof(struct ceph_osd_op); + request_msg = ceph_msg_new(CEPH_MSG_OSD_OP, msg_size, gfp_flags, true); + if (!request_msg) + return -ENOMEM; + + if (num_ops > CEPH_OSD_INITIAL_OP && + req->r_max_ops <= CEPH_OSD_INITIAL_OP) { + msg_size = OSD_OPREPLY_FRONT_LEN + + (CEPH_OSD_MAX_OP - CEPH_OSD_INITIAL_OP) * + (sizeof(struct ceph_osd_op) + 4); + reply_msg = ceph_msg_new(CEPH_MSG_OSD_OPREPLY, msg_size, + gfp_flags, true); + if (!reply_msg) + goto out_enomem; + } + + if (num_ops > CEPH_OSD_INITIAL_OP) { + new_ops = ceph_kvmalloc(sizeof(*req->r_ops) * num_ops, + gfp_flags | __GFP_ZERO); + if (!new_ops) + goto out_enomem; + + memcpy(new_ops, req->r_ops, + sizeof(*req->r_ops) * req->r_num_ops); + if (req->r_ops != req->r_inline_ops) + kvfree(req->r_ops); + req->r_ops = new_ops; + } + + ceph_msg_put(req->r_request); + req->r_request = request_msg; + if (reply_msg) { + ceph_msg_put(req->r_reply); + req->r_reply = reply_msg; + } + req->r_max_ops = num_ops; + return 0; +out_enomem: + ceph_msg_put(request_msg); + if (reply_msg) + ceph_msg_put(reply_msg); + return -ENOMEM; +} +EXPORT_SYMBOL(ceph_osdc_extend_request); + struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc, struct ceph_snap_context *snapc, unsigned int num_ops,