From patchwork Thu Sep 7 15:03:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 9942417 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0E03F602CC for ; Thu, 7 Sep 2017 15:11:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 12D9128694 for ; Thu, 7 Sep 2017 15:11:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0783528706; Thu, 7 Sep 2017 15:11:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 63BD328694 for ; Thu, 7 Sep 2017 15:11:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4A221821C1; Thu, 7 Sep 2017 15:11:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4A221821C1 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=dm-devel-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 4A221821C1 Authentication-Results: mx1.redhat.com; dkim=fail reason="signature verification failed" (2048-bit key) header.d=toxicpanda-com.20150623.gappssmtp.com header.i=@toxicpanda-com.20150623.gappssmtp.com header.b="oO0KEl42" Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 75A9C6BF94; Thu, 7 Sep 2017 15:11:22 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 244AD3FAD7; Thu, 7 Sep 2017 15:11:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v87F38Sh024266 for ; Thu, 7 Sep 2017 11:03:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 80E1668245; Thu, 7 Sep 2017 15:03:08 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7AFEE660E0 for ; Thu, 7 Sep 2017 15:03:05 +0000 (UTC) Received: from mail-qt0-f195.google.com (mail-qt0-f195.google.com [209.85.216.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 64F11C049E31 for ; Thu, 7 Sep 2017 15:03:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 64F11C049E31 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=none smtp.mailfrom=josef@toxicpanda.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 64F11C049E31 Received: by mail-qt0-f195.google.com with SMTP id q8so4990450qtb.1 for ; Thu, 07 Sep 2017 08:03:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qINLRO8phrhbnp2S1hhUsltTy9pStFsR5R52b8Do8jw=; b=oO0KEl42b5bE6lfrapbFWdykTjMeC8cWkXBLZEOmfjQGaMm/+Dy5z4lA8Bk895kxwg BmKfPVraPNx5iZtL1NBFCo4hxZp8sFg2XfcDAw+05SaNn0TMQLRfGrIqLgDDJ+EH37tw INs7I79IO3hdUdzRE+gVdqAV+wjpHiR5fkBUm7XIRk9k7xHSJrxldS7Fa8mJ5e84Mcor 4HTMuMI1cFnvbVHglptuXv2b/0ApP/E9/XXbw9ZSMzegwOgfO0UZULGVPNTAcdMCzxgf tTXd+jca7pcQAskCEOdR7lK1S/a3HnOZJYU7X+r079yZ0sxjN/lCzKev3zFTVa4bjXkA 8I5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qINLRO8phrhbnp2S1hhUsltTy9pStFsR5R52b8Do8jw=; b=jhbKCLCkJP99sa/iDuOKYiFkm66xP3XvXXAqOL+MiRhJS9JS7uVtNUnkgWONKAEmuv upr1ShbWJcPmWpAtPbDbZssPLxka8FCseEFiE2NQMa8cn1P037nxVr8Qx8XM5LFhynWM saMdE8bzmAsnDUWHPomkxY/AIkLv84tK/SLtIHDRUqSF675kU9uR+PXiBOUL7xaNKlil 3BpXUwXGwjFWur8S3vlhe+IksdnL01bU2WfE4NCvYKBrXFe3UQFL0XtVAHFL/n1udCmp PtWyXuHxMipt4WMk3s5XswZvSPXQQpmdgLPKncOcsXzQGoMXsFQjusyHKoiGESGy+x6m +erA== X-Gm-Message-State: AHPjjUiU7x4HdLeE/NVpakhwNXEANgZXJp4pPmB1gNmPNYXuPDzWf+p8 KDSDvSBqQv7IxHekNYp1qg== X-Google-Smtp-Source: ADKCNb4gupnRNEU7ojcsk9cIl+PZDhNoIJgpCK5Qe1GnB4bR/P8+eysrYFtirQZ3hvUFZs1l4zqZlw== X-Received: by 10.200.38.98 with SMTP id v31mr4229925qtv.306.1504796583402; Thu, 07 Sep 2017 08:03:03 -0700 (PDT) Received: from localhost ([2606:a000:4381:1201:225:22ff:feb3:e51a]) by smtp.gmail.com with ESMTPSA id n87sm1877923qkh.18.2017.09.07.08.03.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Sep 2017 08:03:02 -0700 (PDT) From: josef@toxicpanda.com X-Google-Original-From: jbacik@fb.com To: dm-devel@redhat.com, snitzer@redhat.com, amir73il@gmail.com Date: Thu, 7 Sep 2017 11:03:00 -0400 Message-Id: <1504796580-18069-2-git-send-email-jbacik@fb.com> In-Reply-To: <1504796580-18069-1-git-send-email-jbacik@fb.com> References: <1504796580-18069-1-git-send-email-jbacik@fb.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 07 Sep 2017 15:03:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 07 Sep 2017 15:03:04 +0000 (UTC) for IP:'209.85.216.195' DOMAIN:'mail-qt0-f195.google.com' HELO:'mail-qt0-f195.google.com' FROM:'josef@toxicpanda.com' RCPT:'' X-RedHat-Spam-Score: 0.47 (DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_SPAM) 209.85.216.195 mail-qt0-f195.google.com 209.85.216.195 mail-qt0-f195.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: dm-devel@redhat.com Cc: Josef Bacik Subject: [dm-devel] [PATCH 2/2][RESEND] dm-log-writes: fix >512b sectorsize support X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 07 Sep 2017 15:11:24 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP From: Josef Bacik I screwed up the initial >512b support, I was storing the bio sectors which are 512b sectors in the log metadata which expects them to be in sectorsize units of sectors. I also was assuming device sectors when assigning the bi_sector for the blocks I was logging in some places. Fix this up by adding two helpers to convert between bio and dev sectors, and use these in the appropriate places to fix the problem and make it clear which units go where. With this patch I could now properly use dm-log-writes with 4k devices. Signed-off-by: Josef Bacik --- drivers/md/dm-log-writes.c | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/drivers/md/dm-log-writes.c b/drivers/md/dm-log-writes.c index 9aab510..6f1b954 100644 --- a/drivers/md/dm-log-writes.c +++ b/drivers/md/dm-log-writes.c @@ -100,6 +100,7 @@ struct log_writes_c { struct dm_dev *logdev; u64 logged_entries; u32 sectorsize; + u32 sectorshift; atomic_t io_blocks; atomic_t pending_blocks; sector_t next_sector; @@ -128,6 +129,18 @@ struct per_bio_data { struct pending_block *block; }; +static inline sector_t bio_to_dev_sectors(struct log_writes_c *lc, + sector_t sectors) +{ + return sectors >> (lc->sectorshift - SECTOR_SHIFT); +} + +static inline sector_t dev_to_bio_sectors(struct log_writes_c *lc, + sector_t sectors) +{ + return sectors << (lc->sectorshift - SECTOR_SHIFT); +} + static void put_pending_block(struct log_writes_c *lc) { if (atomic_dec_and_test(&lc->pending_blocks)) { @@ -253,7 +266,7 @@ static int log_one_block(struct log_writes_c *lc, if (!block->vec_cnt) goto out; - sector++; + sector += dev_to_bio_sectors(lc, 1); atomic_inc(&lc->io_blocks); bio = bio_alloc(GFP_KERNEL, min(block->vec_cnt, BIO_MAX_PAGES)); @@ -354,10 +367,10 @@ static int log_writes_kthread(void *arg) goto next; sector = lc->next_sector; - if (block->flags & LOG_DISCARD_FLAG) - lc->next_sector++; - else - lc->next_sector += block->nr_sectors + 1; + if (!(block->flags & LOG_DISCARD_FLAG)) + lc->next_sector += + dev_to_bio_sectors(lc, block->nr_sectors); + lc->next_sector += dev_to_bio_sectors(lc, 1); /* * Apparently the size of the device may not be known @@ -435,7 +448,6 @@ static int log_writes_ctr(struct dm_target *ti, unsigned int argc, char **argv) INIT_LIST_HEAD(&lc->unflushed_blocks); INIT_LIST_HEAD(&lc->logging_blocks); init_waitqueue_head(&lc->wait); - lc->sectorsize = 1 << SECTOR_SHIFT; atomic_set(&lc->io_blocks, 0); atomic_set(&lc->pending_blocks, 0); @@ -455,6 +467,8 @@ static int log_writes_ctr(struct dm_target *ti, unsigned int argc, char **argv) goto bad; } + lc->sectorsize = bdev_logical_block_size(lc->dev->bdev); + lc->sectorshift = ilog2(lc->sectorsize); lc->log_kthread = kthread_run(log_writes_kthread, lc, "log-write"); if (IS_ERR(lc->log_kthread)) { ret = PTR_ERR(lc->log_kthread); @@ -464,8 +478,12 @@ static int log_writes_ctr(struct dm_target *ti, unsigned int argc, char **argv) goto bad; } - /* We put the super at sector 0, start logging at sector 1 */ - lc->next_sector = 1; + /* + * next_sector is in 512 sectors to correspond to what bi_sector expects + * to be. The super starts at sector 0, and the next_sector is the next + * logical one based on the sectorsize of the device. + */ + lc->next_sector = lc->sectorsize >> SECTOR_SHIFT; lc->logging_enabled = true; lc->end_sector = logdev_last_sector(lc); lc->device_supports_discard = true; @@ -599,8 +617,8 @@ static int log_writes_map(struct dm_target *ti, struct bio *bio) if (discard_bio) block->flags |= LOG_DISCARD_FLAG; - block->sector = bio->bi_iter.bi_sector; - block->nr_sectors = bio_sectors(bio); + block->sector = bio_to_dev_sectors(lc, bio->bi_iter.bi_sector); + block->nr_sectors = bio_to_dev_sectors(lc, bio_sectors(bio)); /* We don't need the data, just submit */ if (discard_bio) { @@ -767,9 +785,12 @@ static void log_writes_io_hints(struct dm_target *ti, struct queue_limits *limit if (!q || !blk_queue_discard(q)) { lc->device_supports_discard = false; - limits->discard_granularity = 1 << SECTOR_SHIFT; + limits->discard_granularity = lc->sectorsize; limits->max_discard_sectors = (UINT_MAX >> SECTOR_SHIFT); } + limits->logical_block_size = bdev_logical_block_size(lc->dev->bdev); + limits->physical_block_size = bdev_physical_block_size(lc->dev->bdev); + limits->io_min = limits->physical_block_size; } static struct target_type log_writes_target = {