Re: [RFC PATCH] dm: add deviceless messages
Mikulas Patocka <[email protected]>
| Newsgroups | dev.linux.lists.dm-devel |
|---|---|
| Message-ID | <[email protected]> |
On Tue, 12 May 2026, Mikulas Patocka wrote: > The VDO code needs to perform some calculations before creating a device. > The calculations should be performed in the kernel, so that the same logic > is not duplicated in the kernel and in the userspace. > > However, currently it is not possible to call a device mapper target > when no device exists. > > This commit solves the problem by adding "deviceless" messages. If the > message starts with '%', the name is a name of a target, not a name of a > device. The message will be directed to the target by calling the > "deviceless_message" method. The target can perform the requested > calculations in this method and return the result back to userspace. > > Signed-off-by: Mikulas Patocka <[email protected]> This is example code how to use deviceless messages. You can call it with "dmsetup message linear 0 %Hello" Mikulas --- drivers/md/dm-linear.c | 10 ++++++++++ 1 file changed, 10 insertions(+) Index: linux-2.6/drivers/md/dm-linear.c =================================================================== --- linux-2.6.orig/drivers/md/dm-linear.c 2026-05-11 13:00:08.000000000 +0200 +++ linux-2.6/drivers/md/dm-linear.c 2026-05-11 13:00:14.000000000 +0200 @@ -199,6 +199,15 @@ static size_t linear_dax_recovery_write( #define linear_dax_recovery_write NULL #endif +static int linear_deviceless_message(unsigned int argc, char **argv, char *result, unsigned int maxlen) +{ + if (argc == 1 && !strcasecmp(argv[0], "%Hello")) { + snprintf(result, maxlen, "World!"); + return 1; + } + return -EINVAL; +} + static struct target_type linear_target = { .name = "linear", .version = {1, 5, 0}, @@ -211,6 +220,7 @@ static struct target_type linear_target .dtr = linear_dtr, .map = linear_map, .status = linear_status, + .deviceless_message = linear_deviceless_message, .prepare_ioctl = linear_prepare_ioctl, .iterate_devices = linear_iterate_devices, .direct_access = linear_dax_direct_access,