From patchwork Fri Sep 7 14:50:34 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 1423101 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 164843FC33 for ; Fri, 7 Sep 2012 14:50:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933261Ab2IGOuh (ORCPT ); Fri, 7 Sep 2012 10:50:37 -0400 Received: from mail-iy0-f174.google.com ([209.85.210.174]:59661 "EHLO mail-iy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932990Ab2IGOug (ORCPT ); Fri, 7 Sep 2012 10:50:36 -0400 Received: by iahk25 with SMTP id k25so3271922iah.19 for ; Fri, 07 Sep 2012 07:50:36 -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=UBRsp2JxHPhDPKJVktI7Rs5PwgpCv+fis3Q+lw6MRdM=; b=izOpa6JiLj+w26flPAJDztn2STnG/cHmwSgpTdO5ejwgrLF5eIiu2ipkKd63HT73nk LrI3VNjFECxre9dEZBcZq+2EQXiaB8JeIVaE+jhUZ4/2OUfrPCBBbgdnr8DZ0uxKleXs Yw6R2vvc+T/ll/Rh0LI5YHac4W/5Dpjy3kiRLYvenQYk44Zme+hsG7I+35YnX4mWWMTV L5AvA3Wty1SYLncp2krBWPhlZk5cvDUcLCNvLRT12UB+8qvACROgR47rwpqsF90xSEqG HJxIx7/a4J+K2TRcgvubJIeOieIErmrJ8uvaDceG4+JDnJ9UeBdNHCY+V1Oy/+GLiQTh jGWA== Received: by 10.50.57.168 with SMTP id j8mr9091465igq.16.1347029436078; Fri, 07 Sep 2012 07:50:36 -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 cu10sm13286755igc.9.2012.09.07.07.50.34 (version=SSLv3 cipher=OTHER); Fri, 07 Sep 2012 07:50:35 -0700 (PDT) Message-ID: <504A09BA.5030203@inktank.com> Date: Fri, 07 Sep 2012 09:50:34 -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 4/4] rbd: use snaps list in rbd_snap_by_name() References: <504A090F.7000706@inktank.com> In-Reply-To: <504A090F.7000706@inktank.com> X-Gm-Message-State: ALoCoQns4R11p/CNoQaVPlgigSVHGXJIQFRWM7pU+3+tVE3Jcwykg6IcSldSnz0o7t1jMSJc4Gpi Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org An rbd_dev structure maintains a list of current snapshots that have already been fully initialized. The entries on the list have type struct rbd_snap, and each entry contains a copy of information that's found in the rbd_dev's snapshot context and header. The only caller of snap_by_name() is rbd_header_set_snap(). In that call site any positive return value (the index in the snapshot array) is ignored. rbd_header_set_snap() also has only one caller--rbd_add()--and that call is made after a call to rbd_dev_snap_devs_update(). Because the rbd_snap structures are initialized in that function, the current snapshot list can be used instead of the snapshot context to look up a snapshot's information by name. Change snap_by_name() so it uses the snapshot list rather than the rbd_dev's snapshot context in looking up snapshot information. Return 0 if it's found rather than the snapshot id. To do this, change rbd_snap_by_name() to take an rbd_dev rather than rbd_image_header structure pointer as its first argument. No caller ever passes a null pointer to snap_by_name() for the snapshot id or the size, so just assign using those pointers unconditionally. Signed-off-by: Alex Elder Reviewed-by: Josh Durgin --- drivers/block/rbd.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index e922989..4dff92f 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -623,23 +623,18 @@ out_err: static int snap_by_name(struct rbd_device *rbd_dev, const char *snap_name) { - int i; - struct rbd_image_header *header = &rbd_dev->header; - char *p = header->snap_names; - - rbd_assert(header->snapc != NULL); - for (i = 0; i < header->snapc->num_snaps; i++) { - if (!strcmp(snap_name, p)) { - /* Found it. Pass back its id and/or size */ + struct rbd_snap *snap; - rbd_dev->mapping.snap_id = header->snapc->snaps[i]; - rbd_dev->mapping.size = header->snap_sizes[i]; + list_for_each_entry(snap, &rbd_dev->snaps, node) { + if (!strcmp(snap_name, snap->name)) { + rbd_dev->mapping.snap_id = snap->id; + rbd_dev->mapping.size = snap->size; - return i; + return 0; } - p += strlen(p) + 1; /* Skip ahead to the next name */ } + return -ENOENT; }