Skip to content

Commit fe943d5

Browse files
Chengguang Xuidryomov
authored andcommitted
libceph, rbd: add error handling for osd_req_op_cls_init()
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 <cgxu519@gmx.com> Reviewed-by: Ilya Dryomov <idryomov@gmail.com> Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
1 parent 29dcea8 commit fe943d5

3 files changed

Lines changed: 16 additions & 7 deletions

File tree

drivers/block/rbd.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2339,6 +2339,7 @@ static bool is_zero_bvecs(struct bio_vec *bvecs, u32 bytes)
23392339
static int rbd_obj_issue_copyup(struct rbd_obj_request *obj_req, u32 bytes)
23402340
{
23412341
unsigned int num_osd_ops = obj_req->osd_req->r_num_ops;
2342+
int ret;
23422343

23432344
dout("%s obj_req %p bytes %u\n", __func__, obj_req, bytes);
23442345
rbd_assert(obj_req->osd_req->r_ops[0].op == CEPH_OSD_OP_STAT);
@@ -2353,6 +2354,11 @@ static int rbd_obj_issue_copyup(struct rbd_obj_request *obj_req, u32 bytes)
23532354
if (!obj_req->osd_req)
23542355
return -ENOMEM;
23552356

2357+
ret = osd_req_op_cls_init(obj_req->osd_req, 0, CEPH_OSD_OP_CALL, "rbd",
2358+
"copyup");
2359+
if (ret)
2360+
return ret;
2361+
23562362
/*
23572363
* Only send non-zero copyup data to save some I/O and network
23582364
* bandwidth -- zero copyup data is equivalent to the object not
@@ -2362,9 +2368,6 @@ static int rbd_obj_issue_copyup(struct rbd_obj_request *obj_req, u32 bytes)
23622368
dout("%s obj_req %p detected zeroes\n", __func__, obj_req);
23632369
bytes = 0;
23642370
}
2365-
2366-
osd_req_op_cls_init(obj_req->osd_req, 0, CEPH_OSD_OP_CALL, "rbd",
2367-
"copyup");
23682371
osd_req_op_cls_request_data_bvecs(obj_req->osd_req, 0,
23692372
obj_req->copyup_bvecs,
23702373
obj_req->copyup_bvec_count,

include/linux/ceph/osd_client.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ extern void osd_req_op_cls_response_data_pages(struct ceph_osd_request *,
440440
struct page **pages, u64 length,
441441
u32 alignment, bool pages_from_pool,
442442
bool own_pages);
443-
extern void osd_req_op_cls_init(struct ceph_osd_request *osd_req,
443+
extern int osd_req_op_cls_init(struct ceph_osd_request *osd_req,
444444
unsigned int which, u16 opcode,
445445
const char *class, const char *method);
446446
extern int osd_req_op_xattr_init(struct ceph_osd_request *osd_req, unsigned int which,

net/ceph/osd_client.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ void osd_req_op_extent_dup_last(struct ceph_osd_request *osd_req,
767767
}
768768
EXPORT_SYMBOL(osd_req_op_extent_dup_last);
769769

770-
void osd_req_op_cls_init(struct ceph_osd_request *osd_req, unsigned int which,
770+
int osd_req_op_cls_init(struct ceph_osd_request *osd_req, unsigned int which,
771771
u16 opcode, const char *class, const char *method)
772772
{
773773
struct ceph_osd_req_op *op = _osd_req_op_init(osd_req, which,
@@ -779,7 +779,9 @@ void osd_req_op_cls_init(struct ceph_osd_request *osd_req, unsigned int which,
779779
BUG_ON(opcode != CEPH_OSD_OP_CALL);
780780

781781
pagelist = kmalloc(sizeof (*pagelist), GFP_NOFS);
782-
BUG_ON(!pagelist);
782+
if (!pagelist)
783+
return -ENOMEM;
784+
783785
ceph_pagelist_init(pagelist);
784786

785787
op->cls.class_name = class;
@@ -799,6 +801,7 @@ void osd_req_op_cls_init(struct ceph_osd_request *osd_req, unsigned int which,
799801
osd_req_op_cls_request_info_pagelist(osd_req, which, pagelist);
800802

801803
op->indata_len = payload_len;
804+
return 0;
802805
}
803806
EXPORT_SYMBOL(osd_req_op_cls_init);
804807

@@ -4928,7 +4931,10 @@ int ceph_osdc_call(struct ceph_osd_client *osdc,
49284931
if (ret)
49294932
goto out_put_req;
49304933

4931-
osd_req_op_cls_init(req, 0, CEPH_OSD_OP_CALL, class, method);
4934+
ret = osd_req_op_cls_init(req, 0, CEPH_OSD_OP_CALL, class, method);
4935+
if (ret)
4936+
goto out_put_req;
4937+
49324938
if (req_page)
49334939
osd_req_op_cls_request_data_pages(req, 0, &req_page, req_len,
49344940
0, false, false);

0 commit comments

Comments
 (0)