]> git.pld-linux.org Git - packages/device-mapper.git/blob - device-mapper-dmsetup-export.patch
- lvm2 up to 2.02.43; device-mapper is now part of lvm2 package
[packages/device-mapper.git] / device-mapper-dmsetup-export.patch
1 diff --git a/dmsetup/dmsetup.c b/dmsetup/dmsetup.c
2 index 25f14a6..b693008 100644
3 --- a/dmsetup/dmsetup.c
4 +++ b/dmsetup/dmsetup.c
5 @@ -995,6 +995,94 @@ static int _status(int argc, char **argv
6         return r;
7  }
8  
9 +static int _export(int argc, char **argv, void *data)
10 +{
11 +       int r = 0;
12 +       struct dm_task *dmt = NULL;
13 +       void *next = NULL;
14 +       uint64_t start, length;
15 +       char *target_type = NULL;
16 +       char *params;
17 +       struct dm_names *names = (struct dm_names *) data;
18 +       const char *name = NULL;
19 +       const char *uuid = NULL;
20 +       struct dm_info info;
21 +
22 +       if (data)
23 +               name = names->name;
24 +       else if (argc == 2)
25 +               name = argv[1];
26 +
27 +       if (!(dmt = dm_task_create(DM_DEVICE_STATUS)))
28 +               goto out;
29 +
30 +       if (!_set_task_device(dmt, name, 0))
31 +               goto out;
32 +
33 +       if (!dm_task_run(dmt))
34 +               goto out;
35 +
36 +       if (!dm_task_get_info(dmt, &info) || !info.exists)
37 +               goto out;
38 +
39 +       if (!name)
40 +               name = dm_task_get_name(dmt);
41 +
42 +       uuid = dm_task_get_uuid(dmt);
43 +       printf("DM_NAME=%s\n", name);
44 +
45 +       if ((uuid = dm_task_get_uuid(dmt)) && *uuid)
46 +               printf("DM_UUID=%s\n", uuid);
47 +
48 +       if (!info.exists) {
49 +               printf("DM_STATE=NOTPRESENT\n");
50 +               goto out;
51 +       }
52 +
53 +       printf("DM_STATE=%s\n",
54 +              info.suspended ? "SUSPENDED" :
55 +              (info.read_only ? " READONLY" : "ACTIVE"));
56 +
57 +       if (!info.live_table && !info.inactive_table)
58 +               printf("DM_TABLE_STATE=NONE\n");
59 +       else
60 +               printf("DM_TABLE_STATE=%s%s%s\n",
61 +                      info.live_table ? "LIVE" : "",
62 +                      info.live_table && info.inactive_table ? "/" : "",
63 +                      info.inactive_table ? "INACTIVE" : "");
64 +
65 +       if (info.open_count != -1)
66 +               printf("DM_OPENCOUNT=%d\n", info.open_count);
67 +
68 +       printf("DM_LAST_EVENT_NR=%" PRIu32 "\n", info.event_nr);
69 +
70 +       printf("DM_MAJOR=%d\n", info.major);
71 +       printf("DM_MINOR=%d\n", info.minor);
72 +
73 +       if (info.target_count != -1)
74 +               printf("DM_TARGET_COUNT=%d\n", info.target_count);
75 +
76 +       /* export all table types */
77 +       next = dm_get_next_target(dmt, next, &start, &length,
78 +                                 &target_type, &params);
79 +       if (target_type) {
80 +               printf("DM_TARGET_TYPES=%s", target_type);
81 +               while (next) {
82 +                       next = dm_get_next_target(dmt, next, &start, &length,
83 +                                                 &target_type, &params);
84 +                       if (target_type)
85 +                               printf(",%s", target_type);
86 +               }
87 +               printf("\n");
88 +       }
89 +
90 +       r = 1;
91 +      out:
92 +       if (dmt)
93 +               dm_task_destroy(dmt);
94 +       return r;
95 +}
96 +
97  /* Show target names and their version numbers */
98  static int _targets(int argc __attribute((unused)), char **argv __attribute((unused)), void *data __attribute((unused)))
99  {
100 @@ -1699,6 +1787,7 @@ static struct command _commands[] = {
101         {"info", "[<device>]", 0, 1, _info},
102         {"deps", "[<device>]", 0, 1, _deps},
103         {"status", "[<device>] [--target <target_type>]", 0, 1, _status},
104 +       {"export", "[<device>]", 0, 1, _export},
105         {"table", "[<device>] [--target <target_type>] [--showkeys]", 0, 1, _status},
106         {"wait", "<device> [<event_nr>]", 0, 2, _wait},
107         {"mknodes", "[<device>]", 0, 1, _mknodes},
108 diff --git a/man/dmsetup.8 b/man/dmsetup.8
109 index 5b2ed9f..c4524aa 100644
110 --- a/man/dmsetup.8
111 +++ b/man/dmsetup.8
112 @@ -39,13 +39,16 @@ dmsetup \- low level logical volume mana
113  .B dmsetup ls
114  .I [--target target_type] [--exec command] [--tree [-o options]]
115  .br
116 -.B dmsetup info 
117 +.B dmsetup info
118  .I [device_name]
119  .br
120  .B dmsetup info -c|-C|--columns
121  .I [--noheadings] [--separator separator] [-o fields] [-O|--sort sort_fields]
122  .I [device_name]
123  .br
124 +.B dmsetup export
125 +.I [device_name]
126 +.br
127  .B dmsetup deps
128  .I [device_name]
129  .br
130 @@ -138,6 +141,10 @@ device_name in subsequent dmsetup comman
131  If successful a device will appear as
132  /dev/device-mapper/<device-name>.  
133  See below for information on the table format.
134 +.IP \fBexport
135 +.I [device_name]
136 +.br
137 +Outputs information in key/value format to be imported by other programs.
138  .IP \fBdeps
139  .I [device_name]
140  .br
This page took 0.093836 seconds and 3 git commands to generate.