History

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.

Mikulas Patocka committed 13 years ago

Commit a2606241 parent 02cde502 files · +40 −1Browse files

Unified · Split

2 files
  1. drivers/md/dm-ioctl.c +35 −1
  2. include/uapi/linux/dm-ioctl.h +5 −0
drivers/md/dm-ioctl.c+35−1
@@ -1414,6 +1414,22 @@ static int table_status(struct dm_ioctl *param, size_t param_size) · 1413 unmodified lines
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) · 5 unmodified lines
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) · 17 unmodified lines
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) · 19 unmodified lines
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) · 173 unmodified lines
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+5−0
@@ -336,4 +336,9 @@ enum { · 335 unmodified lines
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 */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t