Skip to content

Commit e3290b9

Browse files
committed
dm: simplify target code conditional on CONFIG_BLK_DEV_ZONED
Allow removal of CONFIG_BLK_DEV_ZONED conditionals in target_type definition of various targets. Suggested-by: Eric Biggers <[email protected]> Signed-off-by: Mike Snitzer <[email protected]>
1 parent 3db564b commit e3290b9

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

drivers/md/dm-crypt.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3134,7 +3134,6 @@ static int crypt_ctr_optional(struct dm_target *ti, unsigned int argc, char **ar
31343134
}
31353135

31363136
#ifdef CONFIG_BLK_DEV_ZONED
3137-
31383137
static int crypt_report_zones(struct dm_target *ti,
31393138
struct dm_report_zones_args *args, unsigned int nr_zones)
31403139
{
@@ -3145,7 +3144,8 @@ static int crypt_report_zones(struct dm_target *ti,
31453144
return blkdev_report_zones(cc->dev->bdev, sector, nr_zones,
31463145
dm_report_zones_cb, args);
31473146
}
3148-
3147+
#else
3148+
#define crypt_report_zones NULL
31493149
#endif
31503150

31513151
/*
@@ -3580,10 +3580,8 @@ static struct target_type crypt_target = {
35803580
.module = THIS_MODULE,
35813581
.ctr = crypt_ctr,
35823582
.dtr = crypt_dtr,
3583-
#ifdef CONFIG_BLK_DEV_ZONED
35843583
.features = DM_TARGET_ZONED_HM,
35853584
.report_zones = crypt_report_zones,
3586-
#endif
35873585
.map = crypt_map,
35883586
.status = crypt_status,
35893587
.postsuspend = crypt_postsuspend,

drivers/md/dm-flakey.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,8 @@ static int flakey_report_zones(struct dm_target *ti,
469469
return blkdev_report_zones(fc->dev->bdev, sector, nr_zones,
470470
dm_report_zones_cb, args);
471471
}
472+
#else
473+
#define flakey_report_zones NULL
472474
#endif
473475

474476
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_
481483
static struct target_type flakey_target = {
482484
.name = "flakey",
483485
.version = {1, 5, 0},
484-
#ifdef CONFIG_BLK_DEV_ZONED
485486
.features = DM_TARGET_ZONED_HM | DM_TARGET_PASSES_CRYPTO,
486487
.report_zones = flakey_report_zones,
487-
#else
488-
.features = DM_TARGET_PASSES_CRYPTO,
489-
#endif
490488
.module = THIS_MODULE,
491489
.ctr = flakey_ctr,
492490
.dtr = flakey_dtr,

drivers/md/dm-linear.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ static int linear_report_zones(struct dm_target *ti,
146146
return blkdev_report_zones(lc->dev->bdev, sector, nr_zones,
147147
dm_report_zones_cb, args);
148148
}
149+
#else
150+
#define linear_report_zones NULL
149151
#endif
150152

151153
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,
227229
static struct target_type linear_target = {
228230
.name = "linear",
229231
.version = {1, 4, 0},
230-
#ifdef CONFIG_BLK_DEV_ZONED
231232
.features = DM_TARGET_PASSES_INTEGRITY | DM_TARGET_NOWAIT |
232233
DM_TARGET_ZONED_HM | DM_TARGET_PASSES_CRYPTO,
233234
.report_zones = linear_report_zones,
234-
#else
235-
.features = DM_TARGET_PASSES_INTEGRITY | DM_TARGET_NOWAIT |
236-
DM_TARGET_PASSES_CRYPTO,
237-
#endif
238235
.module = THIS_MODULE,
239236
.ctr = linear_ctr,
240237
.dtr = linear_dtr,

include/linux/device-mapper.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,18 @@ typedef int (*dm_message_fn) (struct dm_target *ti, unsigned argc, char **argv,
9393

9494
typedef int (*dm_prepare_ioctl_fn) (struct dm_target *ti, struct block_device **bdev);
9595

96+
#ifdef CONFIG_BLK_DEV_ZONED
9697
typedef int (*dm_report_zones_fn) (struct dm_target *ti,
9798
struct dm_report_zones_args *args,
9899
unsigned int nr_zones);
100+
#else
101+
/*
102+
* Define dm_report_zones_fn so that targets can assign to NULL if
103+
* CONFIG_BLK_DEV_ZONED disabled. Otherwise each target needs to do
104+
* awkward #ifdefs in their target_type, etc.
105+
*/
106+
typedef int (*dm_report_zones_fn) (struct dm_target *dummy);
107+
#endif
99108

100109
/*
101110
* These iteration functions are typically used to check (and combine)
@@ -187,9 +196,7 @@ struct target_type {
187196
dm_status_fn status;
188197
dm_message_fn message;
189198
dm_prepare_ioctl_fn prepare_ioctl;
190-
#ifdef CONFIG_BLK_DEV_ZONED
191199
dm_report_zones_fn report_zones;
192-
#endif
193200
dm_busy_fn busy;
194201
dm_iterate_devices_fn iterate_devices;
195202
dm_io_hints_fn io_hints;
@@ -248,8 +255,13 @@ struct target_type {
248255
/*
249256
* Indicates that a target supports host-managed zoned block devices.
250257
*/
258+
#ifdef CONFIG_BLK_DEV_ZONED
251259
#define DM_TARGET_ZONED_HM 0x00000040
252260
#define dm_target_supports_zoned_hm(type) ((type)->features & DM_TARGET_ZONED_HM)
261+
#else
262+
#define DM_TARGET_ZONED_HM 0x00000000
263+
#define dm_target_supports_zoned_hm(type) (false)
264+
#endif
253265

254266
/*
255267
* A target handles REQ_NOWAIT

0 commit comments

Comments
 (0)