From patchwork Thu Jul 19 12:34:36 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 1216391 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 81A8EE006E for ; Thu, 19 Jul 2012 12:34:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750867Ab2GSMej (ORCPT ); Thu, 19 Jul 2012 08:34:39 -0400 Received: from mail-gh0-f174.google.com ([209.85.160.174]:39184 "EHLO mail-gh0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750748Ab2GSMei (ORCPT ); Thu, 19 Jul 2012 08:34:38 -0400 Received: by ghrr11 with SMTP id r11so2682359ghr.19 for ; Thu, 19 Jul 2012 05:34:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding :x-gm-message-state; bh=a3LUz3wYVqbGp1DbWZ5ob3dxb9o+eBukrMMhZdNbcMc=; b=T1mQgVPh9PCYyIoUX6zj7TrCinFc9QHLGPuhbgZ7P4UDj8KimD+NJN7hxXBDnT1ass oY9pafsEiYpKQJShj5BJyT8PcbZAx7C3ab90/wiZ8JTpVJjbWhTiwsYxs9mPUcp1UGuF s30abxLo3hsbjE+4Uk1D2NnwLzFwPWElcoBfPXU8VXOW5WjAC85lmtsKHfthf2M7S2Ai sFLyCRyYJV2xjG6GeibUkZt9QUAx5955ztWYYKi0+eo9xTRsHVQ2CK3RK45ET5/NGR/d FsMAxVMDv+WcWngv+jTA3efqbnSW1mune4+FQFmURbVQpGcuBw7esLWiZ+MwQVsF5uf5 PDTw== Received: by 10.50.17.230 with SMTP id r6mr1194733igd.63.1342701277672; Thu, 19 Jul 2012 05:34:37 -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 gl1sm3526003igc.1.2012.07.19.05.34.36 (version=SSLv3 cipher=OTHER); Thu, 19 Jul 2012 05:34:37 -0700 (PDT) Message-ID: <5007FEDC.8070602@inktank.com> Date: Thu, 19 Jul 2012 07:34:36 -0500 From: Alex Elder User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1 MIME-Version: 1.0 To: "ceph-devel@vger.kernel.org" Subject: [PATCH 1/6] rbd: return errors for mapped but deleted snapshot References: <5007FDEA.9010605@inktank.com> In-Reply-To: <5007FDEA.9010605@inktank.com> X-Gm-Message-State: ALoCoQl8cZy5b2txAr2MlCRyfgpvjzkeLDwBMn16hdlzevSUNslBNQbGS5qRRn+MfXiqM7r15dwE Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org When a snapshot is deleted, the OSD will return ENOENT when reading from it. This is normally interpreted as a hole by rbd, which will return zeroes. To minimize the time in which this can happen, stop requests early when we are notified that our snapshot no longer exists. [elder@inktank.com: updated __rbd_init_snaps_header() logic] Signed-off-by: Josh Durgin Reviewed-by: Alex Elder --- drivers/block/rbd.c | 32 ++++++++++++++++++++++++++++++-- 1 files changed, 30 insertions(+), 2 deletions(-) *size = header->image_size; @@ -606,6 +611,7 @@ static int rbd_header_set_snap(struct rbd_device *rbd_dev, u64 *size) if (ret < 0) goto done; rbd_dev->snap_id = snapc->seq; + rbd_dev->snap_exists = true; rbd_dev->read_only = 1; } @@ -1468,6 +1474,21 @@ static void rbd_rq_fn(struct request_queue *q) spin_unlock_irq(q->queue_lock); + if (rbd_dev->snap_id != CEPH_NOSNAP) { + bool snap_exists; + + down_read(&rbd_dev->header_rwsem); + snap_exists = rbd_dev->snap_exists; + up_read(&rbd_dev->header_rwsem); + + if (!snap_exists) { + dout("request for non-existent snapshot"); + spin_lock_irq(q->queue_lock); + __blk_end_request_all(rq, -ENXIO); + continue; + } + } + dout("%s 0x%x bytes at 0x%llx\n", do_write ? "write" : "read", size, blk_rq_pos(rq) * SECTOR_SIZE); @@ -2088,7 +2109,14 @@ static int __rbd_init_snaps_header(struct rbd_device *rbd_dev) cur_id = rbd_dev->header.snapc->snaps[i - 1]; if (!i || old_snap->id < cur_id) { - /* old_snap->id was skipped, thus was removed */ + /* + * old_snap->id was skipped, thus was + * removed. If this rbd_dev is mapped to + * the removed snapshot, record that it no + * longer exists, to prevent further I/O. + */ + if (rbd_dev->snap_id == old_snap->id) + rbd_dev->snap_exists = false; __rbd_remove_snap_dev(rbd_dev, old_snap); continue; } diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index b124442..730d0ce 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -172,9 +172,13 @@ struct rbd_device { /* protects updating the header */ struct rw_semaphore header_rwsem; + /* name of the snapshot this device reads from */ char *snap_name; + /* id of the snapshot this device reads from */ u64 snap_id; /* current snapshot id */ - int read_only; + /* whether the snap_id this device reads from still exists */ + bool snap_exists; + int read_only; struct list_head node; @@ -597,6 +601,7 @@ static int rbd_header_set_snap(struct rbd_device *rbd_dev, u64 *size) else snapc->seq = 0; rbd_dev->snap_id = CEPH_NOSNAP; + rbd_dev->snap_exists = false; rbd_dev->read_only = 0; if (size)