From: Mike Snitzer <snitzer@redhat.com>
To: Mikulas Patocka <mpatocka@redhat.com>
Cc: dm-devel@redhat.com, David Teigland <teigland@redhat.com>,
Zdenek Kabelac <zkabelac@redhat.com>
Subject: Re: [dm-devel] dm-writecache: allow the underlying device to be shrunk
Date: Tue, 9 Feb 2021 16:51:59 -0500 [thread overview]
Message-ID: <20210209215159.GA2637@redhat.com> (raw)
In-Reply-To: <alpine.LRH.2.02.2102091053450.5801@file01.intranet.prod.int.rdu2.redhat.com>
On Tue, Feb 09 2021 at 10:56am -0500,
Mikulas Patocka <mpatocka@redhat.com> wrote:
> Allow shrinking the underlying data device (dm-writecache must be
> suspended when the device is shrunk).
>
> This patch modifies dm-writecache, so that it doesn't attempt to write any
> data beyond the end of the data device.
>
> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
> Cc: stable@vger.kernel.org
>
> ---
> drivers/md/dm-writecache.c | 18 ++++++++++++++++++
> 1 file changed, 18 insertions(+)
>
> Index: linux-2.6/drivers/md/dm-writecache.c
> ===================================================================
> --- linux-2.6.orig/drivers/md/dm-writecache.c 2021-02-05 20:30:35.000000000 +0100
> +++ linux-2.6/drivers/md/dm-writecache.c 2021-02-09 16:50:36.000000000 +0100
> @@ -148,6 +148,7 @@ struct dm_writecache {
> size_t metadata_sectors;
> size_t n_blocks;
> uint64_t seq_count;
> + uint64_t data_device_sectors;
> void *block_start;
> struct wc_entry *entries;
> unsigned block_size;
> @@ -969,6 +970,8 @@ static void writecache_resume(struct dm_
>
> wc_lock(wc);
>
> + wc->data_device_sectors = i_size_read(wc->dev->bdev->bd_inode) >> SECTOR_SHIFT;
> +
I switched it to using bdev_nr_sectors() (and sector_t instead of uint64_t) instead.
> if (WC_MODE_PMEM(wc)) {
> persistent_memory_invalidate_cache(wc->memory_map, wc->memory_map_size);
> } else {
> @@ -1638,6 +1641,10 @@ static bool wc_add_block(struct writebac
> void *address = memory_data(wc, e);
>
> persistent_memory_flush_cache(address, block_size);
> +
> + if (unlikely(wb->bio.bi_iter.bi_sector + bio_sectors(&wb->bio) >= wc->data_device_sectors))
> + return true;
> +
I updated it to use bio_end_sector()
Otherwise looks good.
diff --git a/drivers/md/dm-writecache.c b/drivers/md/dm-writecache.c
index d9c0d41e29f3..844c4be11768 100644
--- a/drivers/md/dm-writecache.c
+++ b/drivers/md/dm-writecache.c
@@ -148,7 +148,7 @@ struct dm_writecache {
size_t metadata_sectors;
size_t n_blocks;
uint64_t seq_count;
- uint64_t data_device_sectors;
+ sector_t data_device_sectors;
void *block_start;
struct wc_entry *entries;
unsigned block_size;
@@ -978,7 +978,7 @@ static void writecache_resume(struct dm_target *ti)
wc_lock(wc);
- wc->data_device_sectors = i_size_read(wc->dev->bdev->bd_inode) >> SECTOR_SHIFT;
+ wc->data_device_sectors = bdev_nr_sectors(wc->dev->bdev);
if (WC_MODE_PMEM(wc)) {
persistent_memory_invalidate_cache(wc->memory_map, wc->memory_map_size);
@@ -1650,7 +1650,7 @@ static bool wc_add_block(struct writeback_struct *wb, struct wc_entry *e, gfp_t
persistent_memory_flush_cache(address, block_size);
- if (unlikely(wb->bio.bi_iter.bi_sector + bio_sectors(&wb->bio) >= wc->data_device_sectors))
+ if (unlikely(bio_end_sector(&wb->bio) >= wc->data_device_sectors))
return true;
return bio_add_page(&wb->bio, persistent_memory_page(address),
BUT, it should be noted bdev_nr_sectors is pretty recent, introduced
with commit a782483cc1f8 ("block: remove the nr_sects field in struct
hd_struct"). SO using bdev_nr_sectors creates problems with stable@...
given that I'll revert back to open-coding it in the tsable@ patch and
then apply a quick change to use bdev_nr_sectors().
Mike
--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
prev parent reply other threads:[~2021-02-09 21:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-09 15:56 [dm-devel] [PATCH] dm-writecache: allow the underlying device to be shrunk Mikulas Patocka
2021-02-09 21:51 ` Mike Snitzer [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210209215159.GA2637@redhat.com \
--to=snitzer@redhat.com \
--cc=dm-devel@redhat.com \
--cc=mpatocka@redhat.com \
--cc=teigland@redhat.com \
--cc=zkabelac@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.