From patchwork Mon Jan 28 22:09:15 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 2058601 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 83AFEDF2A1 for ; Mon, 28 Jan 2013 22:09:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755049Ab3A1WJR (ORCPT ); Mon, 28 Jan 2013 17:09:17 -0500 Received: from mail-ia0-f172.google.com ([209.85.210.172]:54913 "EHLO mail-ia0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754704Ab3A1WJQ (ORCPT ); Mon, 28 Jan 2013 17:09:16 -0500 Received: by mail-ia0-f172.google.com with SMTP id u8so5060360iag.31 for ; Mon, 28 Jan 2013 14:09:15 -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=uJh+Eb/4zK9wsgB1/xn0Inygb1Qjpf2f+Asw6Y6keRg=; b=PsfjXk40dkc0soOoa4l2AyEpgu9PP6RBdDiz1RxBDmuzF06QmvPscIZWp4jKikgUKl miEKzlfOh+EwAjOvkXyIgPI0n1PKs0a4+6aIw83VC8sVOIlnuCDgqXl4nPa/OK8JwjzI HKv3SShq3qeqpQKYtnw81oAsDLaGSChLCZonXDzTggIt45BlTilL46mnDop8WlxrTHnC sj1vUzp/0kSWQrgrBgMruT/fAMmhv1UgDeHGCFp9vhiA2uH/L+H6WeytuwmToxXOic27 PUMaf+zORyZcL7HgGxgyXzslpbCYia7n7WvhK7H3sCWrwCly9UWcU6Q6ulN29v1RJDjU Dpjw== X-Received: by 10.50.214.39 with SMTP id nx7mr5988529igc.101.1359410955696; Mon, 28 Jan 2013 14:09:15 -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 hi2sm100792igc.16.2013.01.28.14.09.12 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 28 Jan 2013 14:09:14 -0800 (PST) Message-ID: <5106F70B.2090502@inktank.com> Date: Mon, 28 Jan 2013 16:09:15 -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: <5106F6D2.7040805@inktank.com> In-Reply-To: <5106F6D2.7040805@inktank.com> X-Gm-Message-State: ALoCoQnznnhvf/+CcZuhQw29zVmH6fvdaT19YS6pneCP2PKrCKnpKhEAURZ4aeZyUlaClnw3AF1v 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 bit operations. Replace the use of the current "exists" flag with a bit in this new "flags" field. Add a little commentary about the "exists" flag, which does not need to be manipulated atomically. Signed-off-by: Alex Elder Reviewed-by: Josh Durgin --- drivers/block/rbd.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) } @@ -1886,9 +1893,14 @@ static void rbd_request_fn(struct request_queue *q) rbd_assert(rbd_dev->spec->snap_id == CEPH_NOSNAP); } - /* Quit early if the snapshot has disappeared */ - - if (!atomic_read(&rbd_dev->exists)) { + /* + * Quit early if the mapped snapshot no longer + * exists. It's still possible the snapshot will + * have disappeared by the time our request arrives + * at the osd, but there's no sense in sending it if + * we already know. + */ + if (!test_bit(rbd_dev_flag_exists, &rbd_dev->flags)) { dout("request for non-existent snapshot"); rbd_assert(rbd_dev->spec->snap_id != CEPH_NOSNAP); result = -ENXIO; @@ -2578,7 +2590,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); @@ -3207,10 +3219,17 @@ static int rbd_dev_snaps_update(struct rbd_device *rbd_dev) if (snap_id == CEPH_NOSNAP || (snap && snap->id > snap_id)) { struct list_head *next = links->next; - /* Existing snapshot not in the new snap context */ - + /* + * A previously-existing snapshot is not in + * the new snap context. + * + * If the now missing snapshot is the one the + * image is mapped to, clear its exists flag + * so we can avoid sending any more requests + * to it. + */ if (rbd_dev->spec->snap_id == snap->id) - atomic_set(&rbd_dev->exists, 0); + clear_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 177ba0c..107df40 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -262,7 +262,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; @@ -291,6 +291,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 */ @@ -790,7 +796,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;