From patchwork Thu Jul 19 21:08:59 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 1218611 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 692E03FD48 for ; Thu, 19 Jul 2012 21:09:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751874Ab2GSVJC (ORCPT ); Thu, 19 Jul 2012 17:09:02 -0400 Received: from mail-yw0-f46.google.com ([209.85.213.46]:52993 "EHLO mail-yw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751739Ab2GSVJC (ORCPT ); Thu, 19 Jul 2012 17:09:02 -0400 Received: by mail-yw0-f46.google.com with SMTP id m54so3293293yhm.19 for ; Thu, 19 Jul 2012 14:09:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding :x-gm-message-state; bh=x8NltMRXwPSMqrkfnxYqLtxLslSd3B9gdBU0qefYTIQ=; b=Sbwnslron/zQURwMPPwc5Lw4wZwddda4cahtH6erXoevh47FEk5LSv2laymUECxTo6 FeFONWSn3YhErFoITv5rTOJd8IkLlySG30QQ1bHU4tPtnZ0iCAnILBWCA9EJIXZb7uT3 A/JyLBxiQUfrTj8RklI0QmLoOsKYK3NgtVJI6bxCOBEPmsrSyno2MLfXXMimH1GwCz3U oHO/t6RafH+z2RYbCPLxJy/nz+vBvHNw+FKvndYqQxTk2I0up7dX4WFII21MUbyRP6yT 4R+fliXD8lSQC3usbnLojZ4RgkoUE+1UXC/NnP4856jxtoLMicQVkTg5fo4ezZefxkBC BWGw== Received: by 10.50.181.232 with SMTP id dz8mr6684146igc.72.1342732141448; Thu, 19 Jul 2012 14:09:01 -0700 (PDT) Received: from [172.22.22.4] (c-71-195-31-37.hsd1.mn.comcast.net. [71.195.31.37]) by mx.google.com with ESMTPS id ai6sm5491117igc.0.2012.07.19.14.09.00 (version=SSLv3 cipher=OTHER); Thu, 19 Jul 2012 14:09:00 -0700 (PDT) Message-ID: <5008776B.7030500@inktank.com> Date: Thu, 19 Jul 2012 16:08:59 -0500 From: Alex Elder User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 MIME-Version: 1.0 To: ceph-devel@vger.kernel.org Subject: [PATCH 10/12] rbd: make rbd_create_rw_ops() return a pointer References: <500874F5.4090205@inktank.com> In-Reply-To: <500874F5.4090205@inktank.com> X-Gm-Message-State: ALoCoQk8tF9z0+m9lrReNjNt/dKr6lZVZiy6mf+816iRFI8w+dZftJpxbJMmfUW3GywXAZFkDk5R Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org 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 --- drivers/block/rbd.c | 68 ++++++++++++++++++++++++++++---------------------- 1 files changed, 38 insertions(+), 30 deletions(-) ops[0].watch.cookie = notify_id; @@ -1236,10 +1240,11 @@ static int rbd_req_sync_watch(struct rbd_device *rbd_dev, { struct ceph_osd_req_op *ops; struct ceph_osd_client *osdc = &rbd_dev->rbd_client->client->osdc; + int ret; - int ret = rbd_create_rw_ops(&ops, 1, CEPH_OSD_OP_WATCH, 0); - if (ret < 0) - return ret; + ops = rbd_create_rw_ops(1, CEPH_OSD_OP_WATCH, 0); + if (!ops) + return -ENOMEM; ret = ceph_osdc_create_event(osdc, rbd_watch_cb, 0, (void *)rbd_dev, &rbd_dev->watch_event); @@ -1279,10 +1284,11 @@ static int rbd_req_sync_unwatch(struct rbd_device *rbd_dev, const char *object_name) { struct ceph_osd_req_op *ops; + int ret; - int ret = rbd_create_rw_ops(&ops, 1, CEPH_OSD_OP_WATCH, 0); - if (ret < 0) - return ret; + ops = rbd_create_rw_ops(1, CEPH_OSD_OP_WATCH, 0); + if (!ops) + return -ENOMEM; ops[0].watch.ver = 0; ops[0].watch.cookie = cpu_to_le64(rbd_dev->watch_event->cookie); @@ -1328,9 +1334,9 @@ static int rbd_req_sync_notify(struct rbd_device *rbd_dev, int payload_len = sizeof(u32) + sizeof(u32); int ret; - ret = rbd_create_rw_ops(&ops, 1, CEPH_OSD_OP_NOTIFY, payload_len); - if (ret < 0) - return ret; + ops = rbd_create_rw_ops(1, CEPH_OSD_OP_NOTIFY, payload_len); + if (!ops) + return -ENOMEM; info.rbd_dev = rbd_dev; @@ -1379,10 +1385,12 @@ static int rbd_req_sync_exec(struct rbd_device *rbd_dev, struct ceph_osd_req_op *ops; int class_name_len = strlen(class_name); int method_name_len = strlen(method_name); - int ret = rbd_create_rw_ops(&ops, 1, CEPH_OSD_OP_CALL, + int ret; + + ops = rbd_create_rw_ops(1, CEPH_OSD_OP_CALL, class_name_len + method_name_len + len); - if (ret < 0) - return ret; + if (!ops) + return -ENOMEM; ops[0].cls.class_name = class_name; ops[0].cls.class_len = (__u8) class_name_len; diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 79b0762..0535612 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -783,22 +783,24 @@ err_out: /* * helpers for osd request op vectors. */ -static int rbd_create_rw_ops(struct ceph_osd_req_op **ops, - int num_ops, - int opcode, - u32 payload_len) -{ - *ops = kzalloc(sizeof(struct ceph_osd_req_op) * (num_ops + 1), - GFP_NOIO); - if (!*ops) - return -ENOMEM; - (*ops)[0].op = opcode; +static struct ceph_osd_req_op *rbd_create_rw_ops(int num_ops, + int opcode, u32 payload_len) +{ + struct ceph_osd_req_op *ops; + + ops = kzalloc(sizeof (*ops) * (num_ops + 1), GFP_NOIO); + if (!ops) + return NULL; + + ops[0].op = opcode; + /* * op extent offset and length will be set later on * in calc_raw_layout() */ - (*ops)[0].payload_len = payload_len; - return 0; + ops[0].payload_len = payload_len; + + return ops; } static void rbd_destroy_ops(struct ceph_osd_req_op *ops) @@ -1033,8 +1035,9 @@ static int rbd_req_sync_op(struct rbd_device *rbd_dev, if (!orig_ops) { payload_len = (flags & CEPH_OSD_FLAG_WRITE ? len : 0); - ret = rbd_create_rw_ops(&ops, 1, opcode, payload_len); - if (ret < 0) + ret = -ENOMEM; + ops = rbd_create_rw_ops(1, opcode, payload_len); + if (!ops) goto done; if ((flags & CEPH_OSD_FLAG_WRITE) && buf) { @@ -1097,8 +1100,9 @@ static int rbd_do_op(struct request *rq, payload_len = (flags & CEPH_OSD_FLAG_WRITE ? seg_len : 0); - ret = rbd_create_rw_ops(&ops, 1, opcode, payload_len); - if (ret < 0) + ret = -ENOMEM; + ops = rbd_create_rw_ops(1, opcode, payload_len); + if (!ops) goto done; /* we've taken care of segment sizes earlier when we @@ -1185,9 +1189,9 @@ static int rbd_req_sync_notify_ack(struct rbd_device *rbd_dev, struct ceph_osd_req_op *ops; int ret; - ret = rbd_create_rw_ops(&ops, 1, CEPH_OSD_OP_NOTIFY_ACK, 0); - if (ret < 0) - return ret; + ops = rbd_create_rw_ops(1, CEPH_OSD_OP_NOTIFY_ACK, 0); + if (!ops) + return -ENOMEM; ops[0].watch.ver = cpu_to_le64(ver);