From patchwork Fri Apr 26 14:53:02 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 2494071 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 D8594DF230 for ; Fri, 26 Apr 2013 14:53:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755178Ab3DZOxH (ORCPT ); Fri, 26 Apr 2013 10:53:07 -0400 Received: from mail-ia0-f175.google.com ([209.85.210.175]:44489 "EHLO mail-ia0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753046Ab3DZOxE (ORCPT ); Fri, 26 Apr 2013 10:53:04 -0400 Received: by mail-ia0-f175.google.com with SMTP id i38so3774448iae.34 for ; Fri, 26 Apr 2013 07:53:04 -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=12YwYkd7Y06xogV1QoRxdpEeMUsGHSb++r8iK/Br2mg=; b=VGP3cPc7PqEdDf7hQxLTaXp6h+N1ueTVrtEUErqm3kqhS2urq6JIEWf4+LwwsbrS9m l6e423FQx/Y5UOGxxLDmK8izefeU9ekh8rSS+XnCa6/ioCAWQAG5EdGf8ZTiQO6ccrCq M1AUnsJI6akoYinEQwpvbtvUYnSlfKRSFXei2knk0mu8ay6nlBgmdBua4v3oByvUwMKV TdLg3s2e7mlkGy/1bFvAzm6LM4zxWS3vszlbh46/zcXT7910A2vUQQTl2/2gZxNUyBbg WFPpedyf2g4cdcpd7SrYY/uM3UulSERptggt5P0o3KDKTa7o6i/+5PUDXoQZkHdZFMyT yC6A== X-Received: by 10.50.119.67 with SMTP id ks3mr2001154igb.90.1366987984250; Fri, 26 Apr 2013 07:53:04 -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 b6sm3524819igv.5.2013.04.26.07.53.03 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 26 Apr 2013 07:53:03 -0700 (PDT) Message-ID: <517A94CE.2050408@inktank.com> Date: Fri, 26 Apr 2013 09:53:02 -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 4/4] rbd: set snapshot id in rbd_dev_probe_update_spec() References: <517A945B.9040304@inktank.com> In-Reply-To: <517A945B.9040304@inktank.com> X-Gm-Message-State: ALoCoQnNE5KmNIvJSapjtHpod5DukogD77wo/ZcsodCwoxIkerYyoN8dmefSM7LlH8/UeeqnM39J Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org Set the rbd spec's snapshot id for an image getting mapped in rbd_dev_probe_update_spec() rather than rbd_dev_set_mapping(). This is the more logical place for that to happen (even though it means we might look up the snapshot by name twice). Signed-off-by: Alex Elder Reviewed-by: Josh Durgin --- drivers/block/rbd.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) } else { @@ -855,7 +854,6 @@ static int rbd_dev_set_mapping(struct rbd_device *rbd_dev) snap = snap_by_name(rbd_dev, rbd_dev->spec->snap_name); if (!snap) return -ENOENT; - rbd_dev->spec->snap_id = snap->id; rbd_dev->mapping.size = snap->size; rbd_dev->mapping.features = snap->features; rbd_dev->mapping.read_only = true; @@ -3759,6 +3757,10 @@ out: * rbd_dev_snaps_update() has completed because some of the * information (in particular, snapshot name) is not available * until then. + * + * When an image being mapped (not a parent) is probed, we have the + * pool name and pool id, image name and image id, and the snapshot + * name. The only thing we're missing is the snapshot id. */ static int rbd_dev_probe_update_spec(struct rbd_device *rbd_dev) { @@ -3767,8 +3769,24 @@ static int rbd_dev_probe_update_spec(struct rbd_device *rbd_dev) void *reply_buf = NULL; int ret; - if (rbd_dev->spec->pool_name) - return 0; /* Already have the names */ + /* + * An image being mapped will have the pool name (etc.), but + * we need to look up the snapshot id. + */ + if (rbd_dev->spec->pool_name) { + if (strcmp(rbd_dev->spec->snap_name, RBD_SNAP_HEAD_NAME)) { + struct rbd_snap *snap; + + snap = snap_by_name(rbd_dev, rbd_dev->spec->snap_name); + if (!snap) + return -ENOENT; + rbd_dev->spec->snap_id = snap->id; + } else { + rbd_dev->spec->snap_id = CEPH_NOSNAP; + } + + return 0; + } /* Look up the pool name */ diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 5f97137..5099f44 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -846,7 +846,6 @@ static int rbd_dev_set_mapping(struct rbd_device *rbd_dev) { if (!memcmp(rbd_dev->spec->snap_name, RBD_SNAP_HEAD_NAME, sizeof (RBD_SNAP_HEAD_NAME))) { - rbd_dev->spec->snap_id = CEPH_NOSNAP; rbd_dev->mapping.size = rbd_dev->header.image_size; rbd_dev->mapping.features = rbd_dev->header.features;