From patchwork Sat Apr 27 12:36:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 2497111 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 A466ADF23A for ; Sat, 27 Apr 2013 12:36:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755188Ab3D0Mgt (ORCPT ); Sat, 27 Apr 2013 08:36:49 -0400 Received: from mail-ia0-f170.google.com ([209.85.210.170]:35089 "EHLO mail-ia0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752440Ab3D0Mgs (ORCPT ); Sat, 27 Apr 2013 08:36:48 -0400 Received: by mail-ia0-f170.google.com with SMTP id k20so1360143iak.1 for ; Sat, 27 Apr 2013 05:36: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=JBKNBoncZtUp4G1WsMSL3SU8B4eXCWbOjbCaWMYN158=; b=QYnNDRL2U/WXd14fLJ1ZdC4OyeLPEb737tj3xFpXZwg3ROPxWIAQ0g75N6gUQwsulW S/6CqEj/gU/SOhNkxAZ7PYw/APkZfLGE+7YxnYFj9Mn3Vz/EBrNHQRVH6HxROoqx9gf6 UZITFezQTbTLr5XgoIKeHZA2mOsJQhuxj3Ci4o2+Sx7aS/TdAKt1LfD03gjZi8phL+du zVl44Wwczv7sYgjhCRPGPbszMIH6yUclhK2dkitI91YFUtnUZYL4XeyznEfG641gVmvk CxsPkOUvpTiE+7MU2M5qWUtTG1UEJ9Mwy929haEPJzppgnjwrRQD8WqEAake+iI2DRSE 8ahw== X-Received: by 10.50.66.162 with SMTP id g2mr4026403igt.84.1367066208423; Sat, 27 Apr 2013 05:36: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 d4sm7770553igc.3.2013.04.27.05.36.47 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 27 Apr 2013 05:36:47 -0700 (PDT) Message-ID: <517BC65F.90300@inktank.com> Date: Sat, 27 Apr 2013 07:36:47 -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/6] rbd: encapsulate removing parent devices References: <517BC608.5030008@inktank.com> In-Reply-To: <517BC608.5030008@inktank.com> X-Gm-Message-State: ALoCoQnXODri0eE9ElgHEMSAZY4n7D12E66lQ/X/eXb6lZfQ8AhfeZjlGsxRai+0td6ymnGjta0o Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org Encapsulate the code that removes an rbd device's parent images into a new function, rbd_dev_remove_parent(). Signed-off-by: Alex Elder --- drivers/block/rbd.c | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) static int rbd_dev_v2_refresh(struct rbd_device *rbd_dev, u64 *hver); @@ -4987,6 +4988,29 @@ static void __rbd_remove(struct rbd_device *rbd_dev) rbd_bus_del_dev(rbd_dev); } +static void rbd_dev_remove_parent(struct rbd_device *rbd_dev) +{ + while (rbd_dev->parent_spec) { + struct rbd_device *first = rbd_dev; + struct rbd_device *second = first->parent; + struct rbd_device *third; + + /* + * Follow to the parent with no grandparent and + * remove it. + */ + while (second && (third = second->parent)) { + first = second; + second = third; + } + __rbd_remove(second); + rbd_spec_put(first->parent_spec); + first->parent_spec = NULL; + first->parent_overlap = 0; + first->parent = NULL; + } +} + static ssize_t rbd_remove(struct bus_type *bus, const char *buf, size_t count) @@ -5022,25 +5046,9 @@ static ssize_t rbd_remove(struct bus_type *bus, if (ret < 0) goto done; - while (rbd_dev->parent_spec) { - struct rbd_device *first = rbd_dev; - struct rbd_device *second = first->parent; - struct rbd_device *third; + if (rbd_dev->parent) + rbd_dev_remove_parent(rbd_dev); - /* - * Follow to the parent with no grandparent and - * remove it. - */ - while (second && (third = second->parent)) { - first = second; - second = third; - } - __rbd_remove(second); - rbd_spec_put(first->parent_spec); - first->parent_spec = NULL; - first->parent_overlap = 0; - first->parent = NULL; - } __rbd_remove(rbd_dev); done: diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 88cd5f4..fa703db 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -427,8 +427,9 @@ void rbd_warn(struct rbd_device *rbd_dev, const char *fmt, ...) # define rbd_assert(expr) ((void) 0) #endif /* !RBD_DEBUG */ -static void rbd_img_parent_read(struct rbd_obj_request *obj_request); static int rbd_img_obj_request_submit(struct rbd_obj_request *obj_request); +static void rbd_img_parent_read(struct rbd_obj_request *obj_request); +static void rbd_dev_remove_parent(struct rbd_device *rbd_dev); static int rbd_dev_refresh(struct rbd_device *rbd_dev, u64 *hver);