From patchwork Mon Jan 14 18:50:51 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 1973291 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 A08543FE33 for ; Mon, 14 Jan 2013 18:50:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757194Ab3ANSuy (ORCPT ); Mon, 14 Jan 2013 13:50:54 -0500 Received: from mail-ie0-f171.google.com ([209.85.223.171]:42194 "EHLO mail-ie0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756871Ab3ANSuy (ORCPT ); Mon, 14 Jan 2013 13:50:54 -0500 Received: by mail-ie0-f171.google.com with SMTP id 17so5557047iea.2 for ; Mon, 14 Jan 2013 10:50:54 -0800 (PST) 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=0uBLXXfW0viqw4UWuyn7qF7TqtEMgrkJJHgNEAnAOmM=; b=obuC7B71/0Z8SzHK7C7JMu6DQR5251zBudwPId2p/Zi/nhH5x9hG7QFYmiZBTz2kbQ QffVJx+MZlr6h0I+72COym4cMyttOdsMO09MaJ1EMyW0d76Hg2dZc5qIQIPgSOCnfYRs lkKSk0A/fB5leTod2w6JNAsWKCcw99P3ARUi2eh/kYs+uv+89zyTXj+J2NuEkFbpYCBO vVuBrQVYl8sUQU/boW06y+uHBAl5uxNGWxsD1V0gIbSeZq0HMnj+0V3J5rZMYQ6f7qAP xfYP7/+64LimFbJMj9UkyEbrUtF7MH0DXSYpfPsLgod9b1Bn3IE0ABJH9ebTUEouF8eC UiLQ== X-Received: by 10.50.104.228 with SMTP id gh4mr7627527igb.22.1358189453854; Mon, 14 Jan 2013 10:50:53 -0800 (PST) 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 qn10sm6998094igc.15.2013.01.14.10.50.51 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 14 Jan 2013 10:50:52 -0800 (PST) Message-ID: <50F4538B.4010106@inktank.com> Date: Mon, 14 Jan 2013 12:50:51 -0600 From: Alex Elder User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2 MIME-Version: 1.0 To: "ceph-devel@vger.kernel.org" Subject: [PATCH 1/2] rbd: define flags field, use it for exists flag References: <50F4535A.6030601@inktank.com> In-Reply-To: <50F4535A.6030601@inktank.com> X-Gm-Message-State: ALoCoQkEfpnzLyc5P292eQlwcLdJkyxsUwfsBJxrJWcXQmsyUFFSwdUzqxtQKIO1m8a/lHglZtLV Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org Define a new rbd device flags field, manipulated using atomic bit operations. Replace the use of the current "exists" flag with a bit in this new "flags" field. Signed-off-by: Alex Elder Reviewed-by: Dan Mick --- drivers/block/rbd.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) } @@ -1654,7 +1661,7 @@ static void rbd_rq_fn(struct request_queue *q) snapc = ceph_get_snap_context(rbd_dev->header.snapc); up_read(&rbd_dev->header_rwsem); rbd_assert(snapc != NULL); - } else if (!atomic_read(&rbd_dev->exists)) { + } else if (!test_bit(rbd_dev_flag_exists, &rbd_dev->flags)) { rbd_assert(rbd_dev->spec->snap_id != CEPH_NOSNAP); dout("request for non-existent snapshot"); result = -ENXIO; @@ -2270,7 +2277,7 @@ struct rbd_device *rbd_dev_create(struct rbd_client *rbdc, return NULL; spin_lock_init(&rbd_dev->lock); - atomic_set(&rbd_dev->exists, 0); + rbd_dev->flags = 0; INIT_LIST_HEAD(&rbd_dev->node); INIT_LIST_HEAD(&rbd_dev->snaps); init_rwsem(&rbd_dev->header_rwsem); @@ -2902,7 +2909,7 @@ static int rbd_dev_snaps_update(struct rbd_device *rbd_dev) /* Existing snapshot not in the new snap context */ if (rbd_dev->spec->snap_id == snap->id) - atomic_set(&rbd_dev->exists, 0); + set_bit(rbd_dev_flag_exists, &rbd_dev->flags); rbd_remove_snap_dev(snap); dout("%ssnap id %llu has been removed\n", rbd_dev->spec->snap_id == snap->id ? diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 02002b1..9eb1631 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -232,7 +232,7 @@ struct rbd_device { spinlock_t lock; /* queue lock */ struct rbd_image_header header; - atomic_t exists; + unsigned long flags; struct rbd_spec *spec; char *header_name; @@ -260,6 +260,12 @@ struct rbd_device { unsigned long open_count; }; +/* Flag bits for rbd_dev->flags */ + +enum rbd_dev_flags { + rbd_dev_flag_exists, /* mapped snapshot has not been deleted */ +}; + static DEFINE_MUTEX(ctl_mutex); /* Serialize open/close/setup/teardown */ static LIST_HEAD(rbd_dev_list); /* devices */ @@ -756,7 +762,8 @@ static int rbd_dev_set_mapping(struct rbd_device *rbd_dev) goto done; rbd_dev->mapping.read_only = true; } - atomic_set(&rbd_dev->exists, 1); + set_bit(rbd_dev_flag_exists, &rbd_dev->flags); + done: return ret;