]> git.baikalelectronics.ru Git - kernel.git/commitdiff
dm: simplify target code conditional on CONFIG_BLK_DEV_ZONED
authorMike Snitzer <snitzer@redhat.com>
Wed, 10 Feb 2021 22:38:30 +0000 (17:38 -0500)
committerMike Snitzer <snitzer@redhat.com>
Thu, 11 Feb 2021 14:45:27 +0000 (09:45 -0500)
Allow removal of CONFIG_BLK_DEV_ZONED conditionals in target_type
definition of various targets.

Suggested-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
drivers/md/dm-crypt.c
drivers/md/dm-flakey.c
drivers/md/dm-linear.c
include/linux/device-mapper.h

index ee20b586f5267f3fc44de9071315abfe349631c7..ae0f0a4e3689115b330e8c30aff59be312b6f206 100644 (file)
@@ -3134,7 +3134,6 @@ static int crypt_ctr_optional(struct dm_target *ti, unsigned int argc, char **ar
 }
 
 #ifdef CONFIG_BLK_DEV_ZONED
-
 static int crypt_report_zones(struct dm_target *ti,
                struct dm_report_zones_args *args, unsigned int nr_zones)
 {
@@ -3145,7 +3144,8 @@ static int crypt_report_zones(struct dm_target *ti,
        return blkdev_report_zones(cc->dev->bdev, sector, nr_zones,
                                   dm_report_zones_cb, args);
 }
-
+#else
+#define crypt_report_zones NULL
 #endif
 
 /*
@@ -3580,10 +3580,8 @@ static struct target_type crypt_target = {
        .module = THIS_MODULE,
        .ctr    = crypt_ctr,
        .dtr    = crypt_dtr,
-#ifdef CONFIG_BLK_DEV_ZONED
        .features = DM_TARGET_ZONED_HM,
        .report_zones = crypt_report_zones,
-#endif
        .map    = crypt_map,
        .status = crypt_status,
        .postsuspend = crypt_postsuspend,
index 30c6bc1512137b12cdd0a9ff8e7a2d5d33be372a..b7fee9936f050017ff4efaf6048ab6bb3b02be8e 100644 (file)
@@ -469,6 +469,8 @@ static int flakey_report_zones(struct dm_target *ti,
        return blkdev_report_zones(fc->dev->bdev, sector, nr_zones,
                                   dm_report_zones_cb, args);
 }
+#else
+#define flakey_report_zones NULL
 #endif
 
 static int flakey_iterate_devices(struct dm_target *ti, iterate_devices_callout_fn fn, void *data)
@@ -481,12 +483,8 @@ static int flakey_iterate_devices(struct dm_target *ti, iterate_devices_callout_
 static struct target_type flakey_target = {
        .name   = "flakey",
        .version = {1, 5, 0},
-#ifdef CONFIG_BLK_DEV_ZONED
        .features = DM_TARGET_ZONED_HM | DM_TARGET_PASSES_CRYPTO,
        .report_zones = flakey_report_zones,
-#else
-       .features = DM_TARGET_PASSES_CRYPTO,
-#endif
        .module = THIS_MODULE,
        .ctr    = flakey_ctr,
        .dtr    = flakey_dtr,
index fc9c4272c10dbac2b5a76ab59379bbf1e00f26e0..92db0f5e7f28c49907988d09a8b0e8920cc24861 100644 (file)
@@ -146,6 +146,8 @@ static int linear_report_zones(struct dm_target *ti,
        return blkdev_report_zones(lc->dev->bdev, sector, nr_zones,
                                   dm_report_zones_cb, args);
 }
+#else
+#define linear_report_zones NULL
 #endif
 
 static int linear_iterate_devices(struct dm_target *ti,
@@ -227,14 +229,9 @@ static int linear_dax_zero_page_range(struct dm_target *ti, pgoff_t pgoff,
 static struct target_type linear_target = {
        .name   = "linear",
        .version = {1, 4, 0},
-#ifdef CONFIG_BLK_DEV_ZONED
        .features = DM_TARGET_PASSES_INTEGRITY | DM_TARGET_NOWAIT |
                    DM_TARGET_ZONED_HM | DM_TARGET_PASSES_CRYPTO,
        .report_zones = linear_report_zones,
-#else
-       .features = DM_TARGET_PASSES_INTEGRITY | DM_TARGET_NOWAIT |
-                   DM_TARGET_PASSES_CRYPTO,
-#endif
        .module = THIS_MODULE,
        .ctr    = linear_ctr,
        .dtr    = linear_dtr,
index 47588130ef5e27e15d870c432429a1622af9066c..c98d847b0f0b8ed8f070c613a0abddd8909ee1f0 100644 (file)
@@ -93,9 +93,18 @@ typedef int (*dm_message_fn) (struct dm_target *ti, unsigned argc, char **argv,
 
 typedef int (*dm_prepare_ioctl_fn) (struct dm_target *ti, struct block_device **bdev);
 
+#ifdef CONFIG_BLK_DEV_ZONED
 typedef int (*dm_report_zones_fn) (struct dm_target *ti,
                                   struct dm_report_zones_args *args,
                                   unsigned int nr_zones);
+#else
+/*
+ * Define dm_report_zones_fn so that targets can assign to NULL if
+ * CONFIG_BLK_DEV_ZONED disabled. Otherwise each target needs to do
+ * awkward #ifdefs in their target_type, etc.
+ */
+typedef int (*dm_report_zones_fn) (struct dm_target *dummy);
+#endif
 
 /*
  * These iteration functions are typically used to check (and combine)
@@ -187,9 +196,7 @@ struct target_type {
        dm_status_fn status;
        dm_message_fn message;
        dm_prepare_ioctl_fn prepare_ioctl;
-#ifdef CONFIG_BLK_DEV_ZONED
        dm_report_zones_fn report_zones;
-#endif
        dm_busy_fn busy;
        dm_iterate_devices_fn iterate_devices;
        dm_io_hints_fn io_hints;
@@ -248,8 +255,13 @@ struct target_type {
 /*
  * Indicates that a target supports host-managed zoned block devices.
  */
+#ifdef CONFIG_BLK_DEV_ZONED
 #define DM_TARGET_ZONED_HM             0x00000040
 #define dm_target_supports_zoned_hm(type) ((type)->features & DM_TARGET_ZONED_HM)
+#else
+#define DM_TARGET_ZONED_HM             0x00000000
+#define dm_target_supports_zoned_hm(type) (false)
+#endif
 
 /*
  * A target handles REQ_NOWAIT