From patchwork Thu Apr 12 04:04:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengguang Xu X-Patchwork-Id: 10337873 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 3D3B0604D4 for ; Thu, 12 Apr 2018 04:05:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 30A0728569 for ; Thu, 12 Apr 2018 04:05:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 241C8285B0; Thu, 12 Apr 2018 04:05:42 +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=-7.9 required=2.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 6A29F28569 for ; Thu, 12 Apr 2018 04:05:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751029AbeDLEFi (ORCPT ); Thu, 12 Apr 2018 00:05:38 -0400 Received: from mout.gmx.net ([212.227.17.22]:49647 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750959AbeDLEFh (ORCPT ); Thu, 12 Apr 2018 00:05:37 -0400 Received: from juanniu018037.ss.mogujie.org ([122.225.81.134]) by mail.gmx.com (mrgmx102 [212.227.17.174]) with ESMTPSA (Nemesis) id 0M96Jd-1fCHJv29bZ-00CR9a; Thu, 12 Apr 2018 06:05:31 +0200 From: Chengguang Xu To: idryomov@gmail.com, zyan@redhat.com Cc: ceph-devel@vger.kernel.org, Chengguang Xu Subject: [PATCH] libceph: add error handling for osd_req_op_cls_init Date: Thu, 12 Apr 2018 12:04:55 +0800 Message-Id: <1523505895-99462-1-git-send-email-cgxu519@gmx.com> X-Mailer: git-send-email 1.8.3.1 X-Provags-ID: V03:K1:iVbVckZ6uf7TNNIK4AxIIqgKFA2pBSiXJPRGHaCr8z6WvofsNA4 tByRbr/T5YJ8wXNz+jLrx+kcv/TQGe4nAsEM9t525EBiFrcAxuSjlq6+n7SBXAbFslEJYJn FELqcKtdOs/xY8gBecuvTaiR7fL36akL/whACgTf7nu0AQemT+i4GW4Lk/IpEKQhq+4xghP jt9/aIl4UGr4jsqfNLlAA== X-UI-Out-Filterresults: notjunk:1; V01:K0:kw0V62QKnmk=:bEyefclW22PykSDi+yFEVs EjATJT+EAmTsxOR/Y4PQsw+IhWVe1HXvjW6g4h3aDb3zeChu00cLkFgZF1mj9MhrpuCiAlU9Z vdvbELVZxYkFbkcWZouhLeBSrnWF3W+PwZE7IHbvYHfOLfgHKNggeo5nWGB01cBW9pGU+3nz1 7ci6tNrhFhXGD+JFPNC6vzVGphY2cTC/81sZr9kc4I2mZvvWrSfqv0KGQE2SBIx9G6CmbnHjT zJXkwzWmJnc291So3ABBunMfnEBsPEkwfkfXsYcX7EEg9yG+KvBzJ5OMXzs2L3F/h+CBvK6yQ OraIdsaCi1c7RxXE/zQOzA0DK+sr890CGAfA7RZj/lMH4s1rwLjqLiKy/xewgXpyUujBwl4NO +oO4a3Qk95WfbUt1eCQrNVwgUVs4hVQ4xO224GbiIj11RfRnc9ii+/K/E0qD3SbjyMzawVTKI v3jAw0F2jXRpe+izbGidHN18BCkKBlYzdxPZujgNBhcMpdDmnJgj/9U3ZFoUTk59yGf9vbhl5 oyUtYdVGgOmmDCjxTO6YJphZHvEWh3cUeGqrou4a+72pOQqq6eKtXG7Wbzp7cc95XyXYz5G9M yQPo2dKsauNEk5w9pjSkJSm80Bwf1rqB2c6OxKDy1XUAe8dbRGRXPv1TZ8gs20KRk1n7Lf/pK jV/SKn2mEdrXH2gZWWGnC4irzzJc8PW88aeRm/AcNwS8HaB7dmNdIiVOAT56jIRfBpFtFFVGj csvOmrFkiW3niuAskFt0L4EM91p51/PnMaix9WbQfk4/NECZ5HY4EI9S5n+msCyWLoWb5KfER sRQSAz5S5+0glqSngWvG4cGhtBN2g== Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add proper error handling for osd_req_op_cls_init() to replace BUG_ON statement when failing from memory allocation. Signed-off-by: Chengguang Xu --- drivers/block/rbd.c | 8 ++++++-- include/linux/ceph/osd_client.h | 2 +- net/ceph/osd_client.c | 12 +++++++++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 7320466..ebd1d79 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -2348,6 +2348,7 @@ static bool is_zero_bvecs(struct bio_vec *bvecs, u32 bytes) static int rbd_obj_issue_copyup(struct rbd_obj_request *obj_req, u32 bytes) { unsigned int num_osd_ops = obj_req->osd_req->r_num_ops; + int err; dout("%s obj_req %p bytes %u\n", __func__, obj_req, bytes); rbd_assert(obj_req->osd_req->r_ops[0].op == CEPH_OSD_OP_STAT); @@ -2362,6 +2363,11 @@ static int rbd_obj_issue_copyup(struct rbd_obj_request *obj_req, u32 bytes) if (!obj_req->osd_req) return -ENOMEM; + err = osd_req_op_cls_init(obj_req->osd_req, 0, CEPH_OSD_OP_CALL, "rbd", + "copyup"); + if (err) + return err; + /* * Only send non-zero copyup data to save some I/O and network * bandwidth -- zero copyup data is equivalent to the object not @@ -2372,8 +2378,6 @@ static int rbd_obj_issue_copyup(struct rbd_obj_request *obj_req, u32 bytes) bytes = 0; } - osd_req_op_cls_init(obj_req->osd_req, 0, CEPH_OSD_OP_CALL, "rbd", - "copyup"); osd_req_op_cls_request_data_bvecs(obj_req->osd_req, 0, obj_req->copyup_bvecs, bytes); diff --git a/include/linux/ceph/osd_client.h b/include/linux/ceph/osd_client.h index 528ccc9..ba3d8c2 100644 --- a/include/linux/ceph/osd_client.h +++ b/include/linux/ceph/osd_client.h @@ -432,7 +432,7 @@ extern void osd_req_op_cls_response_data_pages(struct ceph_osd_request *, struct page **pages, u64 length, u32 alignment, bool pages_from_pool, bool own_pages); -extern void osd_req_op_cls_init(struct ceph_osd_request *osd_req, +extern int osd_req_op_cls_init(struct ceph_osd_request *osd_req, unsigned int which, u16 opcode, const char *class, const char *method); extern int osd_req_op_xattr_init(struct ceph_osd_request *osd_req, unsigned int which, diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c index ea2a6c9f..a2e2c36 100644 --- a/net/ceph/osd_client.c +++ b/net/ceph/osd_client.c @@ -748,7 +748,7 @@ void osd_req_op_extent_dup_last(struct ceph_osd_request *osd_req, } EXPORT_SYMBOL(osd_req_op_extent_dup_last); -void osd_req_op_cls_init(struct ceph_osd_request *osd_req, unsigned int which, +int osd_req_op_cls_init(struct ceph_osd_request *osd_req, unsigned int which, u16 opcode, const char *class, const char *method) { struct ceph_osd_req_op *op = _osd_req_op_init(osd_req, which, @@ -760,7 +760,9 @@ void osd_req_op_cls_init(struct ceph_osd_request *osd_req, unsigned int which, BUG_ON(opcode != CEPH_OSD_OP_CALL); pagelist = kmalloc(sizeof (*pagelist), GFP_NOFS); - BUG_ON(!pagelist); + if (!pagelist) + return -ENOMEM; + ceph_pagelist_init(pagelist); op->cls.class_name = class; @@ -780,6 +782,7 @@ void osd_req_op_cls_init(struct ceph_osd_request *osd_req, unsigned int which, osd_req_op_cls_request_info_pagelist(osd_req, which, pagelist); op->indata_len = payload_len; + return 0; } EXPORT_SYMBOL(osd_req_op_cls_init); @@ -4909,7 +4912,10 @@ int ceph_osdc_call(struct ceph_osd_client *osdc, if (ret) goto out_put_req; - osd_req_op_cls_init(req, 0, CEPH_OSD_OP_CALL, class, method); + ret = osd_req_op_cls_init(req, 0, CEPH_OSD_OP_CALL, class, method); + if (ret) + goto out_put_req; + if (req_page) osd_req_op_cls_request_data_pages(req, 0, &req_page, req_len, 0, false, false);