From patchwork Fri Sep 7 13:45:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 1422541 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 E9FBE3FC85 for ; Fri, 7 Sep 2012 13:45:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754504Ab2IGNpa (ORCPT ); Fri, 7 Sep 2012 09:45:30 -0400 Received: from mail-ie0-f174.google.com ([209.85.223.174]:33631 "EHLO mail-ie0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753283Ab2IGNp3 (ORCPT ); Fri, 7 Sep 2012 09:45:29 -0400 Received: by mail-ie0-f174.google.com with SMTP id e11so5014223iej.19 for ; Fri, 07 Sep 2012 06:45:29 -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=xOFyjvsdCTckUdpAEmrUpEaIurjO9kjbzzFYpbHYOfo=; b=L2COSDIWZT5kTe/l9yRA214cafXbdqarM4hatub35I+IOgEVTHXghc07paIwnU+hgl 4dluwr5m1nt3R68QMa/5mlh6MRtPauP2B6RBSaCKgAJs8+7IeoklDbBszOeI687ivCCH 4y5ARidY+pAp9IdABcS4tPjLREbK5Adfnst1lgYYL0JtAYRG7aZ0isPYxvou7sxl+AmB GIwLiurBwHtwa86JZP2WpC7Pmgq6fMj74C/5AGqUnVHQwPcX388FBeaCFGTPS0AVVYxC 7jSe08Vu7cLe8IHKGDQ/2GvG60utDG+DAuDaUM2SrOgf1N4K0cNdPmkT5nnGuKkCjtra TdxQ== Received: by 10.42.129.83 with SMTP id p19mr7231667ics.9.1347025529043; Fri, 07 Sep 2012 06:45:29 -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 wn5sm8154207igc.7.2012.09.07.06.45.27 (version=SSLv3 cipher=OTHER); Fri, 07 Sep 2012 06:45:28 -0700 (PDT) Message-ID: <5049FA78.9080603@inktank.com> Date: Fri, 07 Sep 2012 08:45:28 -0500 From: Alex Elder User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120827 Thunderbird/15.0 MIME-Version: 1.0 To: ceph-devel@vger.kernel.org Subject: [PATCH 3/7] rbd: return snap name from rbd_add_parse_args() References: <5049F951.2030706@inktank.com> In-Reply-To: <5049F951.2030706@inktank.com> X-Gm-Message-State: ALoCoQn1pQV+/ZxhXbT0F7kRG/bJqSsaznAy17TcNDRtt1IFCaoyX9LwO5TctXsCXN8YhSeGQyec Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org This is the first of two patches aimed at isolating the code that sets the mapping information into a single spot. Signed-off-by: Alex Elder Reviewed-by: Josh Durgin --- drivers/block/rbd.c | 72 ++++++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 35 deletions(-) @@ -2506,9 +2509,9 @@ static int rbd_add_parse_args(struct rbd_device *rbd_dev, len = copy_token(&buf, options, options_size); if (!len || len >= options_size) - return -EINVAL; + return err_ptr; - ret = -ENOMEM; + err_ptr = ERR_PTR(-ENOMEM); rbd_dev->pool_name = dup_token(&buf, NULL); if (!rbd_dev->pool_name) goto out_err; @@ -2526,26 +2529,21 @@ static int rbd_add_parse_args(struct rbd_device *rbd_dev, goto out_err; sprintf(rbd_dev->header_name, "%s%s", rbd_dev->image_name, RBD_SUFFIX); - /* - * The snapshot name is optional. If none is is supplied, - * we use the default value. - */ - rbd_dev->mapping.snap_name = dup_token(&buf, &len); - if (!rbd_dev->mapping.snap_name) - goto out_err; + /* Snapshot name is optional */ + len = next_token(&buf); if (!len) { - /* Replace the empty name with the default */ - kfree(rbd_dev->mapping.snap_name); - rbd_dev->mapping.snap_name - = kmalloc(sizeof (RBD_SNAP_HEAD_NAME), GFP_KERNEL); - if (!rbd_dev->mapping.snap_name) - goto out_err; - - memcpy(rbd_dev->mapping.snap_name, RBD_SNAP_HEAD_NAME, - sizeof (RBD_SNAP_HEAD_NAME)); + buf = RBD_SNAP_HEAD_NAME; /* No snapshot supplied */ + len = sizeof (RBD_SNAP_HEAD_NAME) - 1; } + snap_name = kmalloc(len + 1, GFP_KERNEL); + if (!snap_name) + goto out_err; + memcpy(snap_name, buf, len); + *(snap_name + len) = '\0'; - return 0; +dout(" SNAP_NAME is <%s>, len is %zd\n", snap_name, len); + + return snap_name; out_err: kfree(rbd_dev->header_name); @@ -2556,7 +2554,7 @@ out_err: kfree(rbd_dev->pool_name); rbd_dev->pool_name = NULL; - return ret; + return err_ptr; } static ssize_t rbd_add(struct bus_type *bus, @@ -2569,6 +2567,7 @@ static ssize_t rbd_add(struct bus_type *bus, size_t mon_addrs_size = 0; struct ceph_osd_client *osdc; int rc = -ENOMEM; + char *snap_name; if (!try_module_get(THIS_MODULE)) return -ENODEV; @@ -2595,10 +2594,13 @@ static ssize_t rbd_add(struct bus_type *bus, sprintf(rbd_dev->name, "%s%d", RBD_DRV_NAME, rbd_dev->dev_id); /* parse add command */ - rc = rbd_add_parse_args(rbd_dev, buf, &mon_addrs, &mon_addrs_size, - options, count); - if (rc) + snap_name = rbd_add_parse_args(rbd_dev, buf, + &mon_addrs, &mon_addrs_size, options, count); + if (IS_ERR(snap_name)) { + rc = PTR_ERR(snap_name); goto err_put_id; + } + rbd_dev->mapping.snap_name = snap_name; rc = rbd_get_client(rbd_dev, mon_addrs, mon_addrs_size - 1, options); if (rc < 0) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 4377a83..1a64ba2 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -2477,28 +2477,31 @@ static inline char *dup_token(const char **buf, size_t *lenp) } /* - * This fills in the pool_name, image_name, image_name_len, snap_name, - * rbd_dev, rbd_md_name, and name fields of the given rbd_dev, based - * on the list of monitor addresses and other options provided via - * /sys/bus/rbd/add. + * This fills in the pool_name, image_name, image_name_len, rbd_dev, + * rbd_md_name, and name fields of the given rbd_dev, based on the + * list of monitor addresses and other options provided via + * /sys/bus/rbd/add. Returns a pointer to a dynamically-allocated + * copy of the snapshot name to map if successful, or a + * pointer-coded error otherwise. * * Note: rbd_dev is assumed to have been initially zero-filled. */ -static int rbd_add_parse_args(struct rbd_device *rbd_dev, - const char *buf, - const char **mon_addrs, - size_t *mon_addrs_size, - char *options, - size_t options_size) +static char *rbd_add_parse_args(struct rbd_device *rbd_dev, + const char *buf, + const char **mon_addrs, + size_t *mon_addrs_size, + char *options, + size_t options_size) { size_t len; - int ret; + char *err_ptr = ERR_PTR(-EINVAL); + char *snap_name; /* The first four tokens are required */ len = next_token(&buf); if (!len) - return -EINVAL; + return err_ptr; *mon_addrs_size = len + 1; *mon_addrs = buf;