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