diff mbox series

[10/11] md: make bitmap file support optional

Message ID 20230615064840.629492-11-hch@lst.de (mailing list archive)
State New, archived
Headers show
Series [01/11] md-bitmap: set BITMAP_WRITE_ERROR in write_sb_page | expand

Commit Message

Christoph Hellwig June 15, 2023, 6:48 a.m. UTC
The support for write intent bitmaps in files on an external files in md
is a hot mess that abuses ->bmap to map file offsets into physical device
objects, and also abuses buffer_heads in a creative way.

Make this code optional so that MD can be built into future kernels
without buffer_head support, and so that we can eventually deprecate it.

Note this does not affect the internal bitmap support, which has none of
the problems.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/md/Kconfig     | 10 ++++++++++
 drivers/md/md-bitmap.c | 15 +++++++++++++++
 drivers/md/md.c        |  7 +++++++
 3 files changed, 32 insertions(+)

Comments

Hannes Reinecke June 15, 2023, 8:37 a.m. UTC | #1
On 6/15/23 08:48, Christoph Hellwig wrote:
> The support for write intent bitmaps in files on an external files in md
> is a hot mess that abuses ->bmap to map file offsets into physical device
> objects, and also abuses buffer_heads in a creative way.
> 
> Make this code optional so that MD can be built into future kernels
> without buffer_head support, and so that we can eventually deprecate it.
> 
> Note this does not affect the internal bitmap support, which has none of
> the problems.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>   drivers/md/Kconfig     | 10 ++++++++++
>   drivers/md/md-bitmap.c | 15 +++++++++++++++
>   drivers/md/md.c        |  7 +++++++
>   3 files changed, 32 insertions(+)
> 
Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
Himanshu Madhani June 15, 2023, 7:37 p.m. UTC | #2
> On Jun 14, 2023, at 11:48 PM, Christoph Hellwig <hch@lst.de> wrote:
> 
> The support for write intent bitmaps in files on an external files in md
> is a hot mess that abuses ->bmap to map file offsets into physical device
> objects, and also abuses buffer_heads in a creative way.
> 
> Make this code optional so that MD can be built into future kernels
> without buffer_head support, and so that we can eventually deprecate it.
> 
> Note this does not affect the internal bitmap support, which has none of
> the problems.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> drivers/md/Kconfig     | 10 ++++++++++
> drivers/md/md-bitmap.c | 15 +++++++++++++++
> drivers/md/md.c        |  7 +++++++
> 3 files changed, 32 insertions(+)
> 
> diff --git a/drivers/md/Kconfig b/drivers/md/Kconfig
> index b0a22e99bade37..9712ab9bcba52e 100644
> --- a/drivers/md/Kconfig
> +++ b/drivers/md/Kconfig
> @@ -50,6 +50,16 @@ config MD_AUTODETECT
> 
>  If unsure, say Y.
> 
> +config MD_BITMAP_FILE
> + bool "MD bitmap file support"
> + default y
> + help
> +  If you say Y here, support for write intent bitmaps in files on an
> +  external file system is enabled.  This is an alternative to the internal
> +  bitmaps near the MD superblock, and very problematic code that abuses
> +  various kernel APIs and can only work with files on a file system not
> +  actually sitting on the MD device.
> +
> config MD_LINEAR
> tristate "Linear (append) mode (deprecated)"
> depends on BLK_DEV_MD
> diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
> index ed402f4dad182d..1e29088b1f081a 100644
> --- a/drivers/md/md-bitmap.c
> +++ b/drivers/md/md-bitmap.c
> @@ -295,6 +295,7 @@ static void write_sb_page(struct bitmap *bitmap, unsigned long pg_index,
> 
> static void md_bitmap_file_kick(struct bitmap *bitmap);
> 
> +#ifdef CONFIG_MD_BITMAP_FILE
> static void write_file_page(struct bitmap *bitmap, struct page *page, int wait)
> {
> struct buffer_head *bh = page_buffers(page);
> @@ -408,6 +409,20 @@ static int read_file_page(struct file *file, unsigned long index,
>       ret);
> return ret;
> }
> +#else /* CONFIG_MD_BITMAP_FILE */
> +static void write_file_page(struct bitmap *bitmap, struct page *page, int wait)
> +{
> +}
> +static int read_file_page(struct file *file, unsigned long index,
> + struct bitmap *bitmap, unsigned long count, struct page *page)
> +{
> + return -EIO;
> +}
> +static void free_buffers(struct page *page)
> +{
> + put_page(page);
> +}
> +#endif /* CONFIG_MD_BITMAP_FILE */
> 
> /*
>  * bitmap file superblock operations
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index cf3733c90c47ed..c9fcefaf9c073b 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -7020,6 +7020,13 @@ static int set_bitmap_file(struct mddev *mddev, int fd)
> 
> if (mddev->bitmap || mddev->bitmap_info.file)
> return -EEXIST; /* cannot add when bitmap is present */
> +
> + if (!IS_ENABLED(CONFIG_MD_BITMAP_FILE)) {
> + pr_warn("%s: bitmap files not supported by this kernel\n",
> + mdname(mddev));
> + return -EINVAL;
> + }
> +
> f = fget(fd);
> 
> if (f == NULL) {
> -- 
> 2.39.2
> 

Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
diff mbox series

Patch

diff --git a/drivers/md/Kconfig b/drivers/md/Kconfig
index b0a22e99bade37..9712ab9bcba52e 100644
--- a/drivers/md/Kconfig
+++ b/drivers/md/Kconfig
@@ -50,6 +50,16 @@  config MD_AUTODETECT
 
 	  If unsure, say Y.
 
+config MD_BITMAP_FILE
+	bool "MD bitmap file support"
+	default y
+	help
+	  If you say Y here, support for write intent bitmaps in files on an
+	  external file system is enabled.  This is an alternative to the internal
+	  bitmaps near the MD superblock, and very problematic code that abuses
+	  various kernel APIs and can only work with files on a file system not
+	  actually sitting on the MD device.
+
 config MD_LINEAR
 	tristate "Linear (append) mode (deprecated)"
 	depends on BLK_DEV_MD
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index ed402f4dad182d..1e29088b1f081a 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -295,6 +295,7 @@  static void write_sb_page(struct bitmap *bitmap, unsigned long pg_index,
 
 static void md_bitmap_file_kick(struct bitmap *bitmap);
 
+#ifdef CONFIG_MD_BITMAP_FILE
 static void write_file_page(struct bitmap *bitmap, struct page *page, int wait)
 {
 	struct buffer_head *bh = page_buffers(page);
@@ -408,6 +409,20 @@  static int read_file_page(struct file *file, unsigned long index,
 		       ret);
 	return ret;
 }
+#else /* CONFIG_MD_BITMAP_FILE */
+static void write_file_page(struct bitmap *bitmap, struct page *page, int wait)
+{
+}
+static int read_file_page(struct file *file, unsigned long index,
+		struct bitmap *bitmap, unsigned long count, struct page *page)
+{
+	return -EIO;
+}
+static void free_buffers(struct page *page)
+{
+	put_page(page);
+}
+#endif /* CONFIG_MD_BITMAP_FILE */
 
 /*
  * bitmap file superblock operations
diff --git a/drivers/md/md.c b/drivers/md/md.c
index cf3733c90c47ed..c9fcefaf9c073b 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -7020,6 +7020,13 @@  static int set_bitmap_file(struct mddev *mddev, int fd)
 
 		if (mddev->bitmap || mddev->bitmap_info.file)
 			return -EEXIST; /* cannot add when bitmap is present */
+
+		if (!IS_ENABLED(CONFIG_MD_BITMAP_FILE)) {
+			pr_warn("%s: bitmap files not supported by this kernel\n",
+				mdname(mddev));
+			return -EINVAL;
+		}
+
 		f = fget(fd);
 
 		if (f == NULL) {