Skip to content

Commit a260624

Browse files
Mikulas Patockakergon
authored andcommitted
dm ioctl: allow message to return data
This patch introduces enhanced message support that allows the device-mapper core to recognise messages that are common to all devices, and for messages to return data to userspace. Core messages are processed by the function "message_for_md". If the device mapper doesn't support the message, it is passed to the target driver. If the message returns data, the kernel sets the flag DM_MESSAGE_OUT_FLAG. Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> Signed-off-by: Alasdair G Kergon <agk@redhat.com>
1 parent 02cde50 commit a260624

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

‎drivers/md/dm-ioctl.c‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1414,6 +1414,22 @@ static int table_status(struct dm_ioctl *param, size_t param_size)
14141414
return 0;
14151415
}
14161416

1417+
static bool buffer_test_overflow(char *result, unsigned maxlen)
1418+
{
1419+
return !maxlen || strlen(result) + 1 >= maxlen;
1420+
}
1421+
1422+
/*
1423+
* Process device-mapper dependent messages.
1424+
* Returns a number <= 1 if message was processed by device mapper.
1425+
* Returns 2 if message should be delivered to the target.
1426+
*/
1427+
static int message_for_md(struct mapped_device *md, unsigned argc, char **argv,
1428+
char *result, unsigned maxlen)
1429+
{
1430+
return 2;
1431+
}
1432+
14171433
/*
14181434
* Pass a message to the target that's at the supplied device offset.
14191435
*/
@@ -1425,6 +1441,8 @@ static int target_message(struct dm_ioctl *param, size_t param_size)
14251441
struct dm_table *table;
14261442
struct dm_target *ti;
14271443
struct dm_target_msg *tmsg = (void *) param + param->data_start;
1444+
size_t maxlen;
1445+
char *result = get_result_buffer(param, param_size, &maxlen);
14281446

14291447
md = find_device(param);
14301448
if (!md)
@@ -1448,6 +1466,10 @@ static int target_message(struct dm_ioctl *param, size_t param_size)
14481466
goto out_argv;
14491467
}
14501468

1469+
r = message_for_md(md, argc, argv, result, maxlen);
1470+
if (r <= 1)
1471+
goto out_argv;
1472+
14511473
table = dm_get_live_table(md);
14521474
if (!table)
14531475
goto out_argv;
@@ -1473,7 +1495,18 @@ static int target_message(struct dm_ioctl *param, size_t param_size)
14731495
out_argv:
14741496
kfree(argv);
14751497
out:
1476-
param->data_size = 0;
1498+
if (r >= 0)
1499+
__dev_status(md, param);
1500+
1501+
if (r == 1) {
1502+
param->flags |= DM_DATA_OUT_FLAG;
1503+
if (buffer_test_overflow(result, maxlen))
1504+
param->flags |= DM_BUFFER_FULL_FLAG;
1505+
else
1506+
param->data_size = param->data_start + strlen(result) + 1;
1507+
r = 0;
1508+
}
1509+
14771510
dm_put(md);
14781511
return r;
14791512
}
@@ -1653,6 +1686,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
16531686
param->flags &= ~DM_BUFFER_FULL_FLAG;
16541687
param->flags &= ~DM_UEVENT_GENERATED_FLAG;
16551688
param->flags &= ~DM_SECURE_DATA_FLAG;
1689+
param->flags &= ~DM_DATA_OUT_FLAG;
16561690

16571691
/* Ignores parameters */
16581692
if (cmd == DM_REMOVE_ALL_CMD ||

‎include/uapi/linux/dm-ioctl.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,4 +336,9 @@ enum {
336336
*/
337337
#define DM_SECURE_DATA_FLAG (1 << 15) /* In */
338338

339+
/*
340+
* If set, a message generated output data.
341+
*/
342+
#define DM_DATA_OUT_FLAG (1 << 16) /* Out */
343+
339344
#endif /* _LINUX_DM_IOCTL_H */

0 commit comments

Comments
 (0)