From patchwork Sat Jun 1 01:20:26 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 2646371 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 B1CD0DFB79 for ; Sat, 1 Jun 2013 01:20:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755323Ab3FABU3 (ORCPT ); Fri, 31 May 2013 21:20:29 -0400 Received: from mail-ie0-f171.google.com ([209.85.223.171]:50027 "EHLO mail-ie0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755098Ab3FABU2 (ORCPT ); Fri, 31 May 2013 21:20:28 -0400 Received: by mail-ie0-f171.google.com with SMTP id s9so5770988iec.16 for ; Fri, 31 May 2013 18:20:28 -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=U4Odqhs8kZfBry8FPifpDuQ7+AiDsB+eqRzS4oOdKpo=; b=VOAPAbX8+du2SWVjNIVHwk8bUsuNCIpDklSQD8AaIlB6d7sCNe11dWKFo/5hxUbiQ8 ID93cBCKTIGOv8dELIQKIAbKH8piDxxQChVxkrO4WaEFcWKx3Wh1SgXBsCcJZ2C7AXS8 ufI5PVBzBeVdLhpcWI8v0pC512ZEj69UJwY1GTEKHwRhfyzL7U73qCuO0ef6EGgz5uWn i1t4nyN/38T16pEiX5I+XBmen5r6fYVgarKIoD084baM/sv8+jxZUzI1wEudpvaERp1O Ts7E8UtxXUO5m3ZXHu7Q/GKcOT0bSvlkuG30IGQXsmtDT18o84ZBh3vlLpaXekPEFurt kgSg== X-Received: by 10.50.33.19 with SMTP id n19mr2871900igi.44.1370049628192; Fri, 31 May 2013 18:20:28 -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 ji5sm6490138igb.0.2013.05.31.18.20.27 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 31 May 2013 18:20:27 -0700 (PDT) Message-ID: <51A94C5A.20807@inktank.com> Date: Fri, 31 May 2013 20:20:26 -0500 From: Alex Elder User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6 MIME-Version: 1.0 To: ceph-devel Subject: [PATCH 2/5] rbd: protect against concurrent unmaps References: <51A94BC0.4080703@inktank.com> In-Reply-To: <51A94BC0.4080703@inktank.com> X-Gm-Message-State: ALoCoQkz4rmJK6lgfFTMXPBXf7fT0uZyi6Wx1x3yQF+v65Nh/lqbwOnuPffoT9N1R1zkFLx5CXOl Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org Make sure two concurrent unmap operations on the same rbd device won't collide, by only proceeding with the removal and cleanup of a device if is not already underway. Signed-off-by: Alex Elder Reviewed-by: Josh Durgin --- drivers/block/rbd.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 716ef1f..380940d 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -5153,6 +5153,7 @@ static ssize_t rbd_remove(struct bus_type *bus, struct list_head *tmp; int dev_id; unsigned long ul; + bool already = false; int ret; ret = strict_strtoul(buf, 10, &ul); @@ -5180,11 +5181,12 @@ static ssize_t rbd_remove(struct bus_type *bus, if (rbd_dev->open_count) ret = -EBUSY; else - set_bit(RBD_DEV_FLAG_REMOVING, &rbd_dev->flags); + already = test_and_set_bit(RBD_DEV_FLAG_REMOVING, + &rbd_dev->flags); spin_unlock_irq(&rbd_dev->lock); } spin_unlock(&rbd_dev_list_lock); - if (ret < 0) + if (ret < 0 || already) goto done; rbd_bus_del_dev(rbd_dev);