Skip to content

Commit 3194e36

Browse files
johnpgarryMikulas Patocka
authored andcommitted
dm-table: atomic writes support
Support stacking atomic write limits for DM devices. All the pre-existing code in blk_stack_atomic_writes_limits() already takes care of finding the aggregrate limits from the bottom devices. Feature flag DM_TARGET_ATOMIC_WRITES is introduced so that atomic writes can be enabled on personalities selectively. This is to ensure that atomic writes are only enabled when verified to be working properly (for a specific personality). In addition, it just may not make sense to enable atomic writes on some personalities (so this flag also helps there). Signed-off-by: John Garry <[email protected]> Reviewed-by: Mike Snitzer <[email protected]> Signed-off-by: Mikulas Patocka <[email protected]>
1 parent a384259 commit 3194e36

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

drivers/md/dm-table.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,6 +1806,32 @@ static bool dm_table_supports_secure_erase(struct dm_table *t)
18061806
return true;
18071807
}
18081808

1809+
static int device_not_atomic_write_capable(struct dm_target *ti,
1810+
struct dm_dev *dev, sector_t start,
1811+
sector_t len, void *data)
1812+
{
1813+
return !bdev_can_atomic_write(dev->bdev);
1814+
}
1815+
1816+
static bool dm_table_supports_atomic_writes(struct dm_table *t)
1817+
{
1818+
for (unsigned int i = 0; i < t->num_targets; i++) {
1819+
struct dm_target *ti = dm_table_get_target(t, i);
1820+
1821+
if (!dm_target_supports_atomic_writes(ti->type))
1822+
return false;
1823+
1824+
if (!ti->type->iterate_devices)
1825+
return false;
1826+
1827+
if (ti->type->iterate_devices(ti,
1828+
device_not_atomic_write_capable, NULL)) {
1829+
return false;
1830+
}
1831+
}
1832+
return true;
1833+
}
1834+
18091835
int dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
18101836
struct queue_limits *limits)
18111837
{
@@ -1854,6 +1880,9 @@ int dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
18541880
return r;
18551881
}
18561882

1883+
if (dm_table_supports_atomic_writes(t))
1884+
limits->features |= BLK_FEAT_ATOMIC_WRITES;
1885+
18571886
r = queue_limits_set(q, limits);
18581887
if (r)
18591888
return r;

include/linux/device-mapper.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,9 @@ struct target_type {
299299
#define dm_target_supports_mixed_zoned_model(type) (false)
300300
#endif
301301

302+
#define DM_TARGET_ATOMIC_WRITES 0x00000400
303+
#define dm_target_supports_atomic_writes(type) ((type)->features & DM_TARGET_ATOMIC_WRITES)
304+
302305
struct dm_target {
303306
struct dm_table *table;
304307
struct target_type *type;

include/uapi/linux/dm-ioctl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,9 @@ enum {
286286
#define DM_DEV_SET_GEOMETRY _IOWR(DM_IOCTL, DM_DEV_SET_GEOMETRY_CMD, struct dm_ioctl)
287287

288288
#define DM_VERSION_MAJOR 4
289-
#define DM_VERSION_MINOR 48
289+
#define DM_VERSION_MINOR 49
290290
#define DM_VERSION_PATCHLEVEL 0
291-
#define DM_VERSION_EXTRA "-ioctl (2023-03-01)"
291+
#define DM_VERSION_EXTRA "-ioctl (2025-01-17)"
292292

293293
/* Status bits */
294294
#define DM_READONLY_FLAG (1 << 0) /* In/Out */

0 commit comments

Comments
 (0)