From patchwork Thu Jan 3 22:54:17 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 1929831 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 BEE7FDF25A for ; Thu, 3 Jan 2013 22:54:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754742Ab3ACWyU (ORCPT ); Thu, 3 Jan 2013 17:54:20 -0500 Received: from mail-ia0-f182.google.com ([209.85.210.182]:37154 "EHLO mail-ia0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754298Ab3ACWyT (ORCPT ); Thu, 3 Jan 2013 17:54:19 -0500 Received: by mail-ia0-f182.google.com with SMTP id x2so13330939iad.13 for ; Thu, 03 Jan 2013 14:54:19 -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=Yvg2LyaaLL6ZYwnSwiZBgDlmfVgQY9ZO64c6cUoV/eM=; b=YCSV44uSWktJnltJ/UTygVdhWGtoG3ZrbtwCtAEVs0hmKePuKZI36DoxrMXpeU4X7g vrzK/R2O1oDd2N8xVwMiz8+qjfMgIcsRxnLMAndGKl6zD+xJqpQJ7r+tNU28R4iHm0Ss AL9I6KQ7XRT/8WTDj7Iq962259Lg8q16jM8pMUZW3fkX8iTAkFDOhuoTPI/h4B4VDBeT GcTtQ6yIbE0lRwV6xHBwM1O5y0umNn82EfzudVpcLZ+2OqTR6wxX7b8Vlrtd8oqSGrgN Imf/GhMbU7z+zVkIbqT5z5ZWpBAFZntX3Vj02pQOL/P+cR8KFMJ+xFm62q0dg6PjwHf6 H6EQ== X-Received: by 10.50.214.68 with SMTP id ny4mr43692367igc.65.1357253659418; Thu, 03 Jan 2013 14:54:19 -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 xn10sm45535227igb.4.2013.01.03.14.54.17 (version=SSLv3 cipher=OTHER); Thu, 03 Jan 2013 14:54:18 -0800 (PST) Message-ID: <50E60C19.9060305@inktank.com> Date: Thu, 03 Jan 2013 16:54:17 -0600 From: Alex Elder User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: "ceph-devel@vger.kernel.org" Subject: [PATCH REPOST 2/2] rbd: only get snap context for write requests References: <50E60BD0.30408@inktank.com> In-Reply-To: <50E60BD0.30408@inktank.com> X-Gm-Message-State: ALoCoQmQbrwUPPyJ2gbN6hDaOYPfqPkAqIhuuDGXnvIOXLYDsHgHL2JdgkqWpV9451fmS3xpEEbs Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org Right now we get the snapshot context for an rbd image (under protection of the header semaphore) for every request processed. There's no need to get the snap context if we're doing a read, so avoid doing so in that case. Note that we no longer need to hold the header semaphore to check the rbd_dev's existence flag. Signed-off-by: Alex Elder Reviewed-by: Josh Durgin --- drivers/block/rbd.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index a3b0d43..fd6a708 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -1331,7 +1331,7 @@ static int rbd_do_op(struct request *rq, } else { opcode = CEPH_OSD_OP_READ; flags = CEPH_OSD_FLAG_READ; - snapc = NULL; + rbd_assert(!snapc); snapid = rbd_dev->spec->snap_id; payload_len = 0; } @@ -1661,22 +1661,25 @@ static void rbd_rq_fn(struct request_queue *q) } spin_unlock_irq(q->queue_lock); - /* Stop writes to a read-only device */ - - result = -EROFS; - if (read_only && rq_data_dir(rq) == WRITE) - goto out_end_request; - - /* Grab a reference to the snapshot context */ - - down_read(&rbd_dev->header_rwsem); - if (atomic_read(&rbd_dev->exists)) { + /* Write requests need a reference to the snapshot context */ + + if (rq_data_dir(rq) == WRITE) { + result = -EROFS; + if (read_only) /* Can't write to a read-only device */ + goto out_end_request; + + /* + * Note that each osd request will take its + * own reference to the snapshot context + * supplied. The reference we take here + * just guarantees the one we provide stays + * valid. + */ + down_read(&rbd_dev->header_rwsem); snapc = ceph_get_snap_context(rbd_dev->header.snapc); + up_read(&rbd_dev->header_rwsem); rbd_assert(snapc != NULL); - } - up_read(&rbd_dev->header_rwsem); - - if (!snapc) { + } else if (!atomic_read(&rbd_dev->exists)) { rbd_assert(rbd_dev->spec->snap_id != CEPH_NOSNAP); dout("request for non-existent snapshot"); result = -ENXIO; @@ -1687,7 +1690,8 @@ static void rbd_rq_fn(struct request_queue *q) blk_rq_pos(rq) * SECTOR_SIZE, blk_rq_bytes(rq), rq->bio); out_end_request: - ceph_put_snap_context(snapc); + if (snapc) + ceph_put_snap_context(snapc); spin_lock_irq(q->queue_lock); if (result < 0) __blk_end_request_all(rq, result);