-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdevice-mapper-dmsetup-export.patch
136 lines (134 loc) · 3.48 KB
/
device-mapper-dmsetup-export.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
---
man/dmsetup.8.in | 7 ++++
libdm/dm-tools/dmsetup.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 95 insertions(+)
--- LVM2.2.02.149/man/dmsetup.8_main.orig 2016-04-05 22:16:49.848604442 +0200
+++ LVM2.2.02.149/man/dmsetup.8_main 2016-04-06 15:59:35.582595117 +0200
@@ -48,6 +48,14 @@
.
.HP
.B dmsetup
+.de CMD_EXPORT
+. B export
+. RI [ device_name ]
+..
+.CMD_EXPORT
+.
+.HP
+.B dmsetup
.de CMD_HELP
. B help
. RB [ -c | -C | --columns ]
@@ -629,6 +637,9 @@
\fBdevname\fP (map name for device-mapper devices, equal to blkdevname otherwise).
.
.HP
+.CMD_EXPORT
+Outputs information in key/value format to be imported by other programs.
+.HP
.CMD_HELP
.br
Outputs a summary of the commands available, optionally including
--- LVM2.2.02.181/libdm/dm-tools/dmsetup.c.orig 2018-09-07 20:22:51.648299609 +0200
+++ LVM2.2.02.181/libdm/dm-tools/dmsetup.c 2018-09-07 20:26:20.021630562 +0200
@@ -2570,6 +2570,93 @@
return r;
}
+static int _export(CMD_ARGS)
+{
+ int r = 0;
+ struct dm_task *dmt = NULL;
+ void *next = NULL;
+ uint64_t start, length;
+ char *target_type = NULL;
+ char *params;
+ const char *name = NULL;
+ const char *uuid = NULL;
+ struct dm_info info;
+
+ if (names)
+ name = names->name;
+ else if (argc == 2)
+ name = argv[1];
+
+ if (!(dmt = dm_task_create(DM_DEVICE_STATUS)))
+ goto out;
+
+ if (!_set_task_device(dmt, name, 0))
+ goto out;
+
+ if (!dm_task_run(dmt))
+ goto out;
+
+ if (!dm_task_get_info(dmt, &info) || !info.exists)
+ goto out;
+
+ if (!name)
+ name = dm_task_get_name(dmt);
+
+ uuid = dm_task_get_uuid(dmt);
+ printf("DM_NAME=%s\n", name);
+
+ if ((uuid = dm_task_get_uuid(dmt)) && *uuid)
+ printf("DM_UUID=%s\n", uuid);
+
+ if (!info.exists) {
+ printf("DM_STATE=NOTPRESENT\n");
+ goto out;
+ }
+
+ printf("DM_STATE=%s\n",
+ info.suspended ? "SUSPENDED" :
+ (info.read_only ? "READONLY" : "ACTIVE"));
+
+ if (!info.live_table && !info.inactive_table)
+ printf("DM_TABLE_STATE=NONE\n");
+ else
+ printf("DM_TABLE_STATE=%s%s%s\n",
+ info.live_table ? "LIVE" : "",
+ info.live_table && info.inactive_table ? "/" : "",
+ info.inactive_table ? "INACTIVE" : "");
+
+ if (info.open_count != -1)
+ printf("DM_OPENCOUNT=%d\n", info.open_count);
+
+ printf("DM_LAST_EVENT_NR=%" PRIu32 "\n", info.event_nr);
+
+ printf("DM_MAJOR=%d\n", info.major);
+ printf("DM_MINOR=%d\n", info.minor);
+
+ if (info.target_count != -1)
+ printf("DM_TARGET_COUNT=%d\n", info.target_count);
+
+ /* export all table types */
+ next = dm_get_next_target(dmt, next, &start, &length,
+ &target_type, ¶ms);
+ if (target_type) {
+ printf("DM_TARGET_TYPES=%s", target_type);
+ while (next) {
+ next = dm_get_next_target(dmt, next, &start, &length,
+ &target_type, ¶ms);
+ if (target_type)
+ printf(",%s", target_type);
+ }
+ printf("\n");
+ }
+
+ r = 1;
+ out:
+ if (dmt)
+ dm_task_destroy(dmt);
+ return r;
+}
+
/* Show target names and their version numbers */
static int _targets(CMD_ARGS)
{
@@ -6245,6 +6332,7 @@
{"stats", "<command> [<options>] [<device>...]", 1, -1, 1, 1, _stats},
{"status", "[<device>...] [--noflush] [--target <target_type>]", 0, -1, 2, 0, _status},
{"table", "[<device>...] [--concise] [--target <target_type>] [--showkeys]", 0, -1, 2, 0, _status},
+ {"export", "[<device>]", 0, 1, 1, 0, _export},
{"wait", "<device> [<event_nr>] [--noflush]", 0, 2, 0, 0, _wait},
{"mknodes", "[<device>...]", 0, -1, 1, 0, _mknodes},
{"mangle", "[<device>...]", 0, -1, 1, 0, _mangle},