From patchwork Wed Feb 6 15:19:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 2105031 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 C5F0240106 for ; Wed, 6 Feb 2013 15:19:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757299Ab3BFPTM (ORCPT ); Wed, 6 Feb 2013 10:19:12 -0500 Received: from mail-ie0-f169.google.com ([209.85.223.169]:54686 "EHLO mail-ie0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756633Ab3BFPTI (ORCPT ); Wed, 6 Feb 2013 10:19:08 -0500 Received: by mail-ie0-f169.google.com with SMTP id 13so2105219iea.0 for ; Wed, 06 Feb 2013 07:19:08 -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 :content-type:content-transfer-encoding:x-gm-message-state; bh=gV2/d9pWKIyxWiWSas8D/FriChhdem8NQrRoAFjojJI=; b=C8WKzHWwHBp/YELnpyp0tmsV2yva3POYGFUokNZ5J93FDPrWXRClr3WOT8+s4VXa9S uh7vb/S3Fxe7kbRTbtf6mVTUL3hj161KGdX/scsPai1J/KMb4LtraWcsWJYKnmPuhWN9 88Jqiv/il7Km1yFdDlJoqXCaMuPyf/Qt7i2N0pD4hNjw0qTTeiVYHbEYJj2F8CI5FxBL 3qXItqSzlRcS1on3UqzGFQGsvYpQ07X8/Tz8RaJHig3sENogU/AFWySSSf7gNGYTsr9c cjgkTlrwPrK64cSctj/WGNmXCOo8UUMUQ9bNX6PhCxoVYfSixwGKBnDVRIjIrRMHB4Wo AE1g== X-Received: by 10.50.150.167 with SMTP id uj7mr6805163igb.1.1360163948222; Wed, 06 Feb 2013 07:19:08 -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 uj6sm3926986igb.4.2013.02.06.07.19.06 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 06 Feb 2013 07:19:07 -0800 (PST) Message-ID: <51127469.1070903@inktank.com> Date: Wed, 06 Feb 2013 09:19:05 -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] rbd: add barriers near done flag operations X-Gm-Message-State: ALoCoQmvRt9bNiknp9SusuPCTDh0myGnc0EkI7HjiiSJ7ZnZIPgDOPO5pKFyEgS66ANUcMARXGNu Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org Somehow, I missed this little item in Documentation/atomic_ops.txt: *** WARNING: atomic_read() and atomic_set() DO NOT IMPLY BARRIERS! *** Create and use some helper functions that include the proper memory barriers for manipulating the done field. Signed-off-by: Alex Elder Reviewed-by: Josh Durgin --- drivers/block/rbd.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) static void rbd_obj_request_complete(struct rbd_obj_request *obj_request) @@ -1249,14 +1267,14 @@ static void rbd_osd_read_callback(struct rbd_obj_request *obj_request, xferred = obj_request->length; } obj_request->xferred = xferred; - atomic_set(&obj_request->done, 1); + obj_request_done_set(obj_request); } static void rbd_osd_write_callback(struct rbd_obj_request *obj_request, struct ceph_osd_op *op) { obj_request->xferred = le64_to_cpu(op->extent.length); - atomic_set(&obj_request->done, 1); + obj_request_done_set(obj_request); } static void rbd_osd_req_callback(struct ceph_osd_request *osd_req, @@ -1300,7 +1318,7 @@ static void rbd_osd_req_callback(struct ceph_osd_request *osd_req, break; } - if (atomic_read(&obj_request->done)) + if (obj_request_done_test(obj_request)) rbd_obj_request_complete(obj_request); } @@ -1407,7 +1425,7 @@ static struct rbd_obj_request *rbd_obj_request_create(const char *object_name, obj_request->which = BAD_WHICH; obj_request->type = type; INIT_LIST_HEAD(&obj_request->links); - atomic_set(&obj_request->done, 0); + obj_request_done_init(obj_request); init_completion(&obj_request->completion); kref_init(&obj_request->kref); @@ -1611,7 +1629,7 @@ static void rbd_img_obj_callback(struct rbd_obj_request *obj_request) rbd_assert(more); rbd_assert(which < img_request->obj_request_count); - if (!atomic_read(&obj_request->done)) + if (!obj_request_done_test(obj_request)) break; rbd_assert(obj_request->xferred <= (u64) UINT_MAX); diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 91983a60..982963e 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -1216,10 +1216,28 @@ static int rbd_obj_request_wait(struct rbd_obj_request *obj_request) return wait_for_completion_interruptible(&obj_request->completion); } +static void obj_request_done_init(struct rbd_obj_request *obj_request) +{ + atomic_set(&obj_request->done, 0); + smp_wmb(); +} + +static void obj_request_done_set(struct rbd_obj_request *obj_request) +{ + atomic_set(&obj_request->done, 1); + smp_wmb(); +} + +static bool obj_request_done_test(struct rbd_obj_request *obj_request) +{ + smp_rmb(); + return atomic_read(&obj_request->done) != 0; +} + static void rbd_osd_trivial_callback(struct rbd_obj_request *obj_request, struct ceph_osd_op *op) { - atomic_set(&obj_request->done, 1); + obj_request_done_set(obj_request); }