aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block/rbd.c
diff options
context:
space:
mode:
authorAlex Elder <elder@inktank.com>2012-06-26 15:57:03 -0400
committerSage Weil <sage@inktank.com>2012-07-30 21:21:46 -0400
commit57cfc1060f35ac2345cb37ea474f9644ac5cfd75 (patch)
tree5a9d18fe47badf7002172cb2af6375d34e5159a6 /drivers/block/rbd.c
parent4e891e0af0f0011c90067373c46d7228568ec079 (diff)
rbd: make rbd_create_rw_ops() return a pointer
Either rbd_create_rw_ops() will succeed, or it will fail because a memory allocation failed. Have it just return a valid pointer or null rather than stuffing a pointer into a provided address and returning an errno. Signed-off-by: Alex Elder <elder@inktank.com> Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
Diffstat (limited to 'drivers/block/rbd.c')
-rw-r--r--drivers/block/rbd.c70
1 files changed, 39 insertions, 31 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index aba0d71a0345..28670c0c68d5 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -788,22 +788,24 @@ err_out:
788/* 788/*
789 * helpers for osd request op vectors. 789 * helpers for osd request op vectors.
790 */ 790 */
791static int rbd_create_rw_ops(struct ceph_osd_req_op **ops, 791static struct ceph_osd_req_op *rbd_create_rw_ops(int num_ops,
792 int num_ops, 792 int opcode, u32 payload_len)
793 int opcode, 793{
794 u32 payload_len) 794 struct ceph_osd_req_op *ops;
795{ 795
796 *ops = kzalloc(sizeof(struct ceph_osd_req_op) * (num_ops + 1), 796 ops = kzalloc(sizeof (*ops) * (num_ops + 1), GFP_NOIO);
797 GFP_NOIO); 797 if (!ops)
798 if (!*ops) 798 return NULL;
799 return -ENOMEM; 799
800 (*ops)[0].op = opcode; 800 ops[0].op = opcode;
801
801 /* 802 /*
802 * op extent offset and length will be set later on 803 * op extent offset and length will be set later on
803 * in calc_raw_layout() 804 * in calc_raw_layout()
804 */ 805 */
805 (*ops)[0].payload_len = payload_len; 806 ops[0].payload_len = payload_len;
806 return 0; 807
808 return ops;
807} 809}
808 810
809static void rbd_destroy_ops(struct ceph_osd_req_op *ops) 811static void rbd_destroy_ops(struct ceph_osd_req_op *ops)
@@ -1040,8 +1042,9 @@ static int rbd_req_sync_op(struct rbd_device *rbd_dev,
1040 1042
1041 if (!orig_ops) { 1043 if (!orig_ops) {
1042 payload_len = (flags & CEPH_OSD_FLAG_WRITE ? len : 0); 1044 payload_len = (flags & CEPH_OSD_FLAG_WRITE ? len : 0);
1043 ret = rbd_create_rw_ops(&ops, 1, opcode, payload_len); 1045 ret = -ENOMEM;
1044 if (ret < 0) 1046 ops = rbd_create_rw_ops(1, opcode, payload_len);
1047 if (!ops)
1045 goto done; 1048 goto done;
1046 1049
1047 if ((flags & CEPH_OSD_FLAG_WRITE) && buf) { 1050 if ((flags & CEPH_OSD_FLAG_WRITE) && buf) {
@@ -1104,8 +1107,9 @@ static int rbd_do_op(struct request *rq,
1104 1107
1105 payload_len = (flags & CEPH_OSD_FLAG_WRITE ? seg_len : 0); 1108 payload_len = (flags & CEPH_OSD_FLAG_WRITE ? seg_len : 0);
1106 1109
1107 ret = rbd_create_rw_ops(&ops, 1, opcode, payload_len); 1110 ret = -ENOMEM;
1108 if (ret < 0) 1111 ops = rbd_create_rw_ops(1, opcode, payload_len);
1112 if (!ops)
1109 goto done; 1113 goto done;
1110 1114
1111 /* we've taken care of segment sizes earlier when we 1115 /* we've taken care of segment sizes earlier when we
@@ -1191,9 +1195,9 @@ static int rbd_req_sync_notify_ack(struct rbd_device *rbd_dev,
1191 struct ceph_osd_req_op *ops; 1195 struct ceph_osd_req_op *ops;
1192 int ret; 1196 int ret;
1193 1197
1194 ret = rbd_create_rw_ops(&ops, 1, CEPH_OSD_OP_NOTIFY_ACK, 0); 1198 ops = rbd_create_rw_ops(1, CEPH_OSD_OP_NOTIFY_ACK, 0);
1195 if (ret < 0) 1199 if (!ops)
1196 return ret; 1200 return -ENOMEM;
1197 1201
1198 ops[0].watch.ver = cpu_to_le64(ver); 1202 ops[0].watch.ver = cpu_to_le64(ver);
1199 ops[0].watch.cookie = notify_id; 1203 ops[0].watch.cookie = notify_id;
@@ -1241,10 +1245,11 @@ static int rbd_req_sync_watch(struct rbd_device *rbd_dev)
1241{ 1245{
1242 struct ceph_osd_req_op *ops; 1246 struct ceph_osd_req_op *ops;
1243 struct ceph_osd_client *osdc = &rbd_dev->rbd_client->client->osdc; 1247 struct ceph_osd_client *osdc = &rbd_dev->rbd_client->client->osdc;
1248 int ret;
1244 1249
1245 int ret = rbd_create_rw_ops(&ops, 1, CEPH_OSD_OP_WATCH, 0); 1250 ops = rbd_create_rw_ops(1, CEPH_OSD_OP_WATCH, 0);
1246 if (ret < 0) 1251 if (!ops)
1247 return ret; 1252 return -ENOMEM;
1248 1253
1249 ret = ceph_osdc_create_event(osdc, rbd_watch_cb, 0, 1254 ret = ceph_osdc_create_event(osdc, rbd_watch_cb, 0,
1250 (void *)rbd_dev, &rbd_dev->watch_event); 1255 (void *)rbd_dev, &rbd_dev->watch_event);
@@ -1284,10 +1289,11 @@ fail:
1284static int rbd_req_sync_unwatch(struct rbd_device *rbd_dev) 1289static int rbd_req_sync_unwatch(struct rbd_device *rbd_dev)
1285{ 1290{
1286 struct ceph_osd_req_op *ops; 1291 struct ceph_osd_req_op *ops;
1292 int ret;
1287 1293
1288 int ret = rbd_create_rw_ops(&ops, 1, CEPH_OSD_OP_WATCH, 0); 1294 ops = rbd_create_rw_ops(1, CEPH_OSD_OP_WATCH, 0);
1289 if (ret < 0) 1295 if (!ops)
1290 return ret; 1296 return -ENOMEM;
1291 1297
1292 ops[0].watch.ver = 0; 1298 ops[0].watch.ver = 0;
1293 ops[0].watch.cookie = cpu_to_le64(rbd_dev->watch_event->cookie); 1299 ops[0].watch.cookie = cpu_to_le64(rbd_dev->watch_event->cookie);
@@ -1335,9 +1341,9 @@ static int rbd_req_sync_notify(struct rbd_device *rbd_dev)
1335 int payload_len = sizeof(u32) + sizeof(u32); 1341 int payload_len = sizeof(u32) + sizeof(u32);
1336 int ret; 1342 int ret;
1337 1343
1338 ret = rbd_create_rw_ops(&ops, 1, CEPH_OSD_OP_NOTIFY, payload_len); 1344 ops = rbd_create_rw_ops(1, CEPH_OSD_OP_NOTIFY, payload_len);
1339 if (ret < 0) 1345 if (!ops)
1340 return ret; 1346 return -ENOMEM;
1341 1347
1342 info.rbd_dev = rbd_dev; 1348 info.rbd_dev = rbd_dev;
1343 1349
@@ -1388,10 +1394,12 @@ static int rbd_req_sync_exec(struct rbd_device *rbd_dev,
1388 struct ceph_osd_req_op *ops; 1394 struct ceph_osd_req_op *ops;
1389 int class_name_len = strlen(class_name); 1395 int class_name_len = strlen(class_name);
1390 int method_name_len = strlen(method_name); 1396 int method_name_len = strlen(method_name);
1391 int ret = rbd_create_rw_ops(&ops, 1, CEPH_OSD_OP_CALL, 1397 int ret;
1398
1399 ops = rbd_create_rw_ops(1, CEPH_OSD_OP_CALL,
1392 class_name_len + method_name_len + len); 1400 class_name_len + method_name_len + len);
1393 if (ret < 0) 1401 if (!ops)
1394 return ret; 1402 return -ENOMEM;
1395 1403
1396 ops[0].cls.class_name = class_name; 1404 ops[0].cls.class_name = class_name;
1397 ops[0].cls.class_len = (__u8) class_name_len; 1405 ops[0].cls.class_len = (__u8) class_name_len;