From patchwork Fri Apr 12 02:17:40 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 2433881 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 1D2CFDF230 for ; Fri, 12 Apr 2013 02:17:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752282Ab3DLCRl (ORCPT ); Thu, 11 Apr 2013 22:17:41 -0400 Received: from mail-ie0-f174.google.com ([209.85.223.174]:41872 "EHLO mail-ie0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751003Ab3DLCRl (ORCPT ); Thu, 11 Apr 2013 22:17:41 -0400 Received: by mail-ie0-f174.google.com with SMTP id aq17so2803167iec.19 for ; Thu, 11 Apr 2013 19:17:40 -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=xglkmCYlV76MxKoTm2IXt0rP76nkZqM4bGU9TSioSbM=; b=jaivCzInORR5aGJlibj2ePE8ABttlHEtD26BXRfU11Ah+43vU35/Ipe6F/01wI3421 FmQJq0JEwLc0z5/1NUIk8p20bzjKBAG4pd3eFFvTkE0AN0yMa7EWn7nvmUjvSqUJ37FO x02vaAYJWXguUeRQHGawZUzrH82csi+LIEtx+o/ZJC8X9T/XfPmG87Ma9Hx0xCqwWtTj DZK8gI9xbkzChn0hvfCaPKzu+px1zmtIT8zmWJwFUp/S8O5TWqaIfGCacWdIK28Dh3Qa 4RBpOr3DShPF+/WzuKids2veNeZxA7uNQepBYw8mUTIlY1HJu+Q1c9wCC9pi76qkaeBi h1/A== X-Received: by 10.50.57.168 with SMTP id j8mr549501igq.51.1365733060518; Thu, 11 Apr 2013 19:17:40 -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 ESMTPS id ip2sm994490igc.5.2013.04.11.19.17.39 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 11 Apr 2013 19:17:39 -0700 (PDT) Message-ID: <51676EC4.1070601@inktank.com> Date: Thu, 11 Apr 2013 21:17:40 -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 04/11] rbd: define image request flags References: <51676E0F.2010504@inktank.com> In-Reply-To: <51676E0F.2010504@inktank.com> X-Gm-Message-State: ALoCoQnyLg5B/9E03q5kWZtbtd8q07uZt2h/HVXrEzYsOUeClcrSm2VoKtqzg91HaT8OLFchEQpz Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org There are several Boolean values we'll be maintaining for image requests. Switch from the single write_request field to a general-purpose flags field, and use one if its bits to represent the direction of I/O for the image request. Define helper functions for setting and testing that flag. Signed-off-by: Alex Elder --- drivers/block/rbd.c | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) { @@ -1369,8 +1390,9 @@ static struct ceph_osd_request *rbd_osd_req_create( struct ceph_osd_request *osd_req; if (img_request) { - rbd_assert(img_request->write_request == write_request); - if (img_request->write_request) + rbd_assert(write_request == + img_request_write_test(img_request)); + if (write_request) snapc = img_request->snapc; } @@ -1494,17 +1516,20 @@ static struct rbd_img_request *rbd_img_request_create( kfree(img_request); return NULL; /* Shouldn't happen */ } + } img_request->rq = NULL; img_request->rbd_dev = rbd_dev; img_request->offset = offset; img_request->length = length; - img_request->write_request = write_request; - if (write_request) + img_request->flags = 0; + if (write_request) { + img_request_write_set(img_request); img_request->snapc = snapc; - else + } else { img_request->snap_id = rbd_dev->spec->snap_id; + } spin_lock_init(&img_request->completion_lock); img_request->next_completion = 0; img_request->callback = NULL; @@ -1537,7 +1562,7 @@ static void rbd_img_request_destroy(struct kref *kref) rbd_img_obj_request_del(img_request, obj_request); rbd_assert(img_request->obj_request_count == 0); - if (img_request->write_request) + if (img_request_write_test(img_request)) ceph_put_snap_context(img_request->snapc); kfree(img_request); @@ -1580,7 +1605,8 @@ static void rbd_img_obj_callback(struct rbd_obj_request *obj_request) struct rbd_device *rbd_dev = img_request->rbd_dev; rbd_warn(rbd_dev, "%s %llx at %llx (%llx)\n", - img_request->write_request ? "write" : "read", + img_request_write_test(img_request) ? "write" + : "read", obj_request->length, obj_request->img_offset, obj_request->offset); rbd_warn(rbd_dev, " result %d xferred %x\n", @@ -1608,7 +1634,7 @@ static int rbd_img_request_fill_bio(struct rbd_img_request *img_request, struct rbd_device *rbd_dev = img_request->rbd_dev; struct rbd_obj_request *obj_request = NULL; struct rbd_obj_request *next_obj_request; - bool write_request = img_request->write_request; + bool write_request = img_request_write_test(img_request); unsigned int bio_offset; u64 img_offset; u64 resid; diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index f0124c5..5ea2e36 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -202,12 +202,16 @@ struct rbd_obj_request { struct kref kref; }; +enum img_req_flags { + IMG_REQ_WRITE, /* read = 0, write = 1 */ +}; + struct rbd_img_request { struct request *rq; struct rbd_device *rbd_dev; u64 offset; /* starting image byte offset */ u64 length; /* byte count from offset */ - bool write_request; /* false for read */ + unsigned long flags; union { struct ceph_snap_context *snapc; /* for writes */ u64 snap_id; /* for reads */ @@ -1210,6 +1214,23 @@ static bool obj_request_done_test(struct rbd_obj_request *obj_request) return atomic_read(&obj_request->done) != 0; } +/* + * The default/initial value for all image request flags is 0. Each + * is conditionally set to 1 at image request initialization time + * and currently never change thereafter. + */ +static void img_request_write_set(struct rbd_img_request *img_request) +{ + set_bit(IMG_REQ_WRITE, &img_request->flags); + smp_mb(); +} + +static bool img_request_write_test(struct rbd_img_request *img_request) +{ + smp_mb(); + return test_bit(IMG_REQ_WRITE, &img_request->flags) != 0; +} + static void rbd_img_obj_request_read_callback(struct rbd_obj_request *obj_request)