From patchwork Fri Apr 26 14:52:48 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 2494061 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 3B4D13FC64 for ; Fri, 26 Apr 2013 14:52:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756083Ab3DZOwv (ORCPT ); Fri, 26 Apr 2013 10:52:51 -0400 Received: from mail-ia0-f170.google.com ([209.85.210.170]:56550 "EHLO mail-ia0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753642Ab3DZOwv (ORCPT ); Fri, 26 Apr 2013 10:52:51 -0400 Received: by mail-ia0-f170.google.com with SMTP id k20so694178iak.15 for ; Fri, 26 Apr 2013 07:52:50 -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=wG217H+Sm9+H9LuSkZi1hy6WDviryK02UidxxaJEH3I=; b=nAzr1eRGaJyd3Lp6/VnPgIF11F76OXQ1kgW3JncvijB24Pp9uNGjrbXFk8RLkw0Rlt MFUp2raMDGvfrBRWbyAJzcif44b0WwncVzD6ZHhiHHx+VLKPNIkYgRFPvnH5hCWFWZyq r5Wa9O3ypg5+AEggh/m712xtaT99pPnfTv+xbPqcab8ay54XJWkOybpAj/8+8ua+mOnX 8/S/QYQOR56FS/tADFHG8UBx0kXRgfWhOrsLK871kCJkFlbuLETzSidv0MkfKoJ7fbni aaxmM4nwhNr+f5TznKme1Zx3u3iTrthSXxRADbVDlbxyau5rja1N3njroqruWc/O+SNW MGtg== X-Received: by 10.42.203.68 with SMTP id fh4mr10035639icb.36.1366987970373; Fri, 26 Apr 2013 07:52:50 -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 s16sm3234605ign.4.2013.04.26.07.52.49 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 26 Apr 2013 07:52:49 -0700 (PDT) Message-ID: <517A94C0.3000006@inktank.com> Date: Fri, 26 Apr 2013 09:52:48 -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 3/4] rbd: have snap_by_name() return a snapshot References: <517A945B.9040304@inktank.com> In-Reply-To: <517A945B.9040304@inktank.com> X-Gm-Message-State: ALoCoQk4gVPI6XM0Q8qeCkUZyyhuAtlVXMp1Z6DM/sSP2Q8R8fifORvSvUwSGPGBoeqnsksH+GGQ Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org A function called snap_by_name() ought to just look up a snapshot by name. It does that, but then it assigns some stuff to the rbd device structure as well. Change the function to do just the lookup, and have the caller do the assignments that follow. Signed-off-by: Alex Elder Reviewed-by: Josh Durgin --- drivers/block/rbd.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) static void rbd_header_free(struct rbd_image_header *header) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index e79dfe2..5f97137 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -830,44 +830,39 @@ static const char *rbd_snap_name(struct rbd_device *rbd_dev, u64 snap_id) return NULL; } -static int snap_by_name(struct rbd_device *rbd_dev, const char *snap_name) +static struct rbd_snap *snap_by_name(struct rbd_device *rbd_dev, + const char *snap_name) { - struct rbd_snap *snap; - list_for_each_entry(snap, &rbd_dev->snaps, node) { - if (!strcmp(snap_name, snap->name)) { - rbd_dev->spec->snap_id = snap->id; - rbd_dev->mapping.size = snap->size; - rbd_dev->mapping.features = snap->features; - - return 0; - } - } + list_for_each_entry(snap, &rbd_dev->snaps, node) + if (!strcmp(snap_name, snap->name)) + return snap; - return -ENOENT; + return NULL; } static int rbd_dev_set_mapping(struct rbd_device *rbd_dev) { - int ret; - 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; - ret = 0; } else { - ret = snap_by_name(rbd_dev, rbd_dev->spec->snap_name); - if (ret < 0) - goto done; + 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; + rbd_dev->mapping.size = snap->size; + rbd_dev->mapping.features = snap->features; rbd_dev->mapping.read_only = true; } set_bit(RBD_DEV_FLAG_EXISTS, &rbd_dev->flags); -done: - return ret; + return 0; }