From patchwork Tue Apr 30 12:42:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 2504481 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id F286CDF2F2 for ; Tue, 30 Apr 2013 12:42:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760555Ab3D3Mmt (ORCPT ); Tue, 30 Apr 2013 08:42:49 -0400 Received: from mail-ia0-f178.google.com ([209.85.210.178]:37873 "EHLO mail-ia0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760119Ab3D3Mms (ORCPT ); Tue, 30 Apr 2013 08:42:48 -0400 Received: by mail-ia0-f178.google.com with SMTP id j38so390034iad.23 for ; Tue, 30 Apr 2013 05:42:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:message-id:date:from:user-agent:mime-version:to:subject :references:in-reply-to:content-type:content-transfer-encoding :x-gm-message-state; bh=h9pojMuKYiErXCA9BFpope2eYwAlydr4Uz9/lto+G1I=; b=bP34nEX2YLB3OTC2kFRAYnnVz5AHP/Vg836iM8t0EaN0zS0b759oTG+B/8XS4TWdX9 xJ6eAXgpLgjEEL15vCG3kO9ItQiiKG8eFKLUAZUcPIv7vjYuNS8JQP5Og9gVvYKeeWWf MVeMQ9Irt8ifZ6Adg8xJGXd23dWb8CgcIwaSRuLwVAfLnmW1QtnStVgUUccNGfBUunlG 0fvTPA/W0/uuRvP6Pt++kOsB0Dn9SkyF+q2NG5uH7LdELK4MB6QdxRbATQczI+m0mCTt qoKtyUe5+X/XyKCdWpxl7/FhyNS8pDGtCEKJ4WiijPpzwbBuPQa84lFMfMD3fEW80NVD f24g== X-Received: by 10.50.1.69 with SMTP id 5mr4077502igk.100.1367325768027; Tue, 30 Apr 2013 05:42:48 -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 ESMTPSA id p10sm19595131igj.5.2013.04.30.05.42.46 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 30 Apr 2013 05:42:46 -0700 (PDT) Message-ID: <517FBC46.3010107@inktank.com> Date: Tue, 30 Apr 2013 07:42:46 -0500 From: Alex Elder User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 MIME-Version: 1.0 To: ceph-devel@vger.kernel.org Subject: [PATCH 2/4] rbd: use snap_id not index to look up snap info References: <517FBBF0.9020904@inktank.com> In-Reply-To: <517FBBF0.9020904@inktank.com> X-Gm-Message-State: ALoCoQluIRb9rAzw08segb8QfGUTy3dk0ut6pV5z/vqWyOq+T2TX1aL6B+sE6MHI60c3t8pE6HS5 Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org In order to align with what was needed for format 1 rbd images, rbd_dev_v2_snap_info() was set up to take as argument an index into the array of snapshot ids in a rbd device's snapshot context. This switches that around, so we pass the snapshot id instead. In doing this, rbd_snap_name() now returns a dynamically-allocated string rather than a fixed one, so there's no need to make a duplicate in its caller, rbd_dev_spec_update(). This means the following functions take a snapshot id where they previously used an index value: rbd_dev_snap_info() rbd_dev_v1_snap_info() rbd_dev_v2_snap_info() A new function, rbd_dev_snap_index(), determines the snap index for format 1 images and uses it to look up the name. Signed-off-by: Alex Elder --- drivers/block/rbd.c | 68 ++++++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 31 deletions(-) { @@ -838,18 +840,27 @@ static u32 rbd_dev_snap_index(struct rbd_device *rbd_dev, u64 snap_id) return BAD_SNAP_INDEX; } -static const char *rbd_snap_name(struct rbd_device *rbd_dev, u64 snap_id) +static const char *rbd_dev_v1_snap_name(struct rbd_device *rbd_dev, u64 snap_id) { - struct rbd_snap *snap; + u32 which; + which = rbd_dev_snap_index(rbd_dev, snap_id); + if (which == BAD_SNAP_INDEX) + return NULL; + + return _rbd_dev_v1_snap_name(rbd_dev, which); +} + +static const char *rbd_snap_name(struct rbd_device *rbd_dev, u64 snap_id) +{ if (snap_id == CEPH_NOSNAP) return RBD_SNAP_HEAD_NAME; - list_for_each_entry(snap, &rbd_dev->snaps, node) - if (snap_id == snap->id) - return snap->name; + rbd_assert(rbd_image_format_valid(rbd_dev->image_format)); + if (rbd_dev->image_format == 1) + return rbd_dev_v1_snap_name(rbd_dev, snap_id); - return NULL; + return rbd_dev_v2_snap_name(rbd_dev, snap_id); } static struct rbd_snap *snap_by_name(struct rbd_device *rbd_dev, @@ -3446,11 +3457,15 @@ static struct rbd_snap *rbd_snap_create(struct rbd_device *rbd_dev, * Returns a dynamically-allocated snapshot name if successful, or a * pointer-coded error otherwise. */ -static const char *rbd_dev_v1_snap_info(struct rbd_device *rbd_dev, u32 which, - u64 *snap_size, u64 *snap_features) +static const char *rbd_dev_v1_snap_info(struct rbd_device *rbd_dev, + u64 snap_id, u64 *snap_size, u64 *snap_features) { const char *snap_name; + u32 which; + which = rbd_dev_snap_index(rbd_dev, snap_id); + if (which == BAD_SNAP_INDEX) + return ERR_PTR(-ENOENT); snap_name = _rbd_dev_v1_snap_name(rbd_dev, which); if (!snap_name) return ERR_PTR(-ENOMEM); @@ -3816,12 +3831,6 @@ static int rbd_dev_spec_update(struct rbd_device *rbd_dev) snap_name = rbd_snap_name(rbd_dev, spec->snap_id); if (!snap_name) { - rbd_warn(rbd_dev, "no snapshot with id %llu", spec->snap_id); - ret = -EIO; - goto out_err; - } - snap_name = kstrdup(snap_name, GFP_KERNEL); - if (!snap_name) { ret = -ENOMEM; goto out_err; } @@ -3909,11 +3918,12 @@ out: return ret; } -static const char *rbd_dev_v2_snap_name(struct rbd_device *rbd_dev, u32 which) +static const char *rbd_dev_v2_snap_name(struct rbd_device *rbd_dev, + u64 snap_id) { size_t size; void *reply_buf; - __le64 snap_id; + __le64 snapid; int ret; void *p; void *end; @@ -3924,11 +3934,10 @@ static const char *rbd_dev_v2_snap_name(struct rbd_device *rbd_dev, u32 which) if (!reply_buf) return ERR_PTR(-ENOMEM); - rbd_assert(which < rbd_dev->header.snapc->num_snaps); - snap_id = cpu_to_le64(rbd_dev->header.snapc->snaps[which]); + snapid = cpu_to_le64(snap_id); ret = rbd_obj_method_sync(rbd_dev, rbd_dev->header_name, "rbd", "get_snapshot_name", - &snap_id, sizeof (snap_id), + &snapid, sizeof (snapid), reply_buf, size); dout("%s: rbd_obj_method_sync returned %d\n", __func__, ret); if (ret < 0) { @@ -3943,24 +3952,21 @@ static const char *rbd_dev_v2_snap_name(struct rbd_device *rbd_dev, u32 which) goto out; dout(" snap_id 0x%016llx snap_name = %s\n", - (unsigned long long)le64_to_cpu(snap_id), snap_name); + (unsigned long long)snap_id, snap_name); out: kfree(reply_buf); return snap_name; } -static const char *rbd_dev_v2_snap_info(struct rbd_device *rbd_dev, u32 which, - u64 *snap_size, u64 *snap_features) +static const char *rbd_dev_v2_snap_info(struct rbd_device *rbd_dev, + u64 snap_id, u64 *snap_size, u64 *snap_features) { - u64 snap_id; u64 size; u64 features; const char *snap_name; int ret; - rbd_assert(which < rbd_dev->header.snapc->num_snaps); - snap_id = rbd_dev->header.snapc->snaps[which]; ret = _rbd_dev_v2_snap_size(rbd_dev, snap_id, NULL, &size); if (ret) goto out_err; @@ -3969,7 +3975,7 @@ static const char *rbd_dev_v2_snap_info(struct rbd_device *rbd_dev, u32 which, if (ret) goto out_err; - snap_name = rbd_dev_v2_snap_name(rbd_dev, which); + snap_name = rbd_dev_v2_snap_name(rbd_dev, snap_id); if (!IS_ERR(snap_name)) { *snap_size = size; *snap_features = features; @@ -3980,14 +3986,14 @@ out_err: return ERR_PTR(ret); } -static const char *rbd_dev_snap_info(struct rbd_device *rbd_dev, u32 which, - u64 *snap_size, u64 *snap_features) +static const char *rbd_dev_snap_info(struct rbd_device *rbd_dev, + u64 snap_id, u64 *snap_size, u64 *snap_features) { if (rbd_dev->image_format == 1) - return rbd_dev_v1_snap_info(rbd_dev, which, + return rbd_dev_v1_snap_info(rbd_dev, snap_id, snap_size, snap_features); if (rbd_dev->image_format == 2) - return rbd_dev_v2_snap_info(rbd_dev, which, + return rbd_dev_v2_snap_info(rbd_dev, snap_id, snap_size, snap_features); return ERR_PTR(-EINVAL); } @@ -4085,7 +4091,7 @@ static int rbd_dev_snaps_update(struct rbd_device *rbd_dev) continue; } - snap_name = rbd_dev_snap_info(rbd_dev, index, + snap_name = rbd_dev_snap_info(rbd_dev, snap_id, &snap_size, &snap_features); if (IS_ERR(snap_name)) { ret = PTR_ERR(snap_name); diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 98033e7..b1e1d12 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -433,6 +433,8 @@ static void rbd_dev_remove_parent(struct rbd_device *rbd_dev); static int rbd_dev_refresh(struct rbd_device *rbd_dev); static int rbd_dev_v2_refresh(struct rbd_device *rbd_dev); +static const char *rbd_dev_v2_snap_name(struct rbd_device *rbd_dev, + u64 snap_id); static int rbd_open(struct block_device *bdev, fmode_t mode)