From patchwork Fri Mar 22 20:11:51 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 2322321 Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com [209.132.183.25]) by patchwork1.kernel.org (Postfix) with ESMTP id 1FFF7400E6 for ; Fri, 22 Mar 2013 20:15:06 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r2MKC3jG015318; Fri, 22 Mar 2013 16:12:04 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r2MKC2rW029371 for ; Fri, 22 Mar 2013 16:12:02 -0400 Received: from mx1.redhat.com (ext-mx12.extmail.prod.ext.phx2.redhat.com [10.5.110.17]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r2MKC2dp012920; Fri, 22 Mar 2013 16:12:02 -0400 Received: from userp1040.oracle.com (userp1040.oracle.com [156.151.31.81]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r2MKC14O019863; Fri, 22 Mar 2013 16:12:01 -0400 Received: from ucsinet22.oracle.com (ucsinet22.oracle.com [156.151.31.94]) by userp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r2MKBs48002138 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 22 Mar 2013 20:11:55 GMT Received: from acsmt357.oracle.com (acsmt357.oracle.com [141.146.40.157]) by ucsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r2MKBraO006694 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 22 Mar 2013 20:11:54 GMT Received: from abhmt109.oracle.com (abhmt109.oracle.com [141.146.116.61]) by acsmt357.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id r2MKBrde019685; Fri, 22 Mar 2013 15:11:53 -0500 Received: from localhost (/67.171.138.228) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 22 Mar 2013 13:11:52 -0700 Date: Fri, 22 Mar 2013 13:11:51 -0700 From: "Darrick J. Wong" To: Linus Torvalds , dm-devel@redhat.com, linux-kernel@vger.kernel.org, Heinz Mauelshagen , Joe Thornber , Mike Snitzer , Mikulas Patocka , Paul Taysom , Randy Dunlap , stable@vger.kernel.org Message-ID: <20130322201151.GB5357@blackbox.djwong.org> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Source-IP: ucsinet22.oracle.com [156.151.31.94] X-RedHat-Spam-Score: -106.796 (BAYES_00, DCC_REPUT_13_19, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, SPF_PASS, UNPARSEABLE_RELAY, URIBL_BLOCKED, USER_IN_WHITELIST) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Scanned-By: MIMEDefang 2.68 on 10.5.110.17 X-loop: dm-devel@redhat.com Subject: [dm-devel] [PATCH] dm: dm-cache fails to write the cache device in writethrough mode X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com The new writethrough strategy for dm-cache issues a bio to the origin device, remaps the bio to the cache device, and issues the bio to the cache device. However, the block layer modifies bi_sector and bi_size, so we need to preserve these or else nothing gets written to the cache (bi_size == 0). This fixes the problem where someone writes a block through the cache, but a subsequent reread (from the cache) returns old contents. Signed-off-by: Darrick J. Wong Nacked-by: Mike Snitzer --- drivers/md/dm-cache-target.c | 10 ++++++++++ 1 file changed, 10 insertions(+) -- dm-devel mailing list dm-devel@redhat.com https://www.redhat.com/mailman/listinfo/dm-devel diff --git a/drivers/md/dm-cache-target.c b/drivers/md/dm-cache-target.c index 66120bd..0db0ad2 100644 --- a/drivers/md/dm-cache-target.c +++ b/drivers/md/dm-cache-target.c @@ -205,6 +205,8 @@ struct per_bio_data { struct cache *cache; dm_cblock_t cblock; bio_end_io_t *saved_bi_end_io; + unsigned int bi_size; + sector_t bi_sector; }; struct dm_cache_migration { @@ -643,6 +645,8 @@ static void writethrough_endio(struct bio *bio, int err) return; } + bio->bi_sector = pb->bi_sector; + bio->bi_size = pb->bi_size; remap_to_cache(pb->cache, bio, pb->cblock); /* @@ -667,6 +671,12 @@ static void remap_to_origin_then_cache(struct cache *cache, struct bio *bio, pb->cache = cache; pb->cblock = cblock; pb->saved_bi_end_io = bio->bi_end_io; + /* + * The block layer modifies bi_size and bi_sector, so we must save + * them for when we re-issue the bio against the cache device. + */ + pb->bi_size = bio->bi_size; + pb->bi_sector = bio->bi_sector; bio->bi_end_io = writethrough_endio; remap_to_origin_clear_discard(pb->cache, bio, oblock);