summaryrefslogtreecommitdiffstats
path: root/cli/src/cli-cmd-system.c
blob: 25938b8974b948881852e2dc18bf35df4b6ff87c (plain)
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
/*
  Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com>
  This file is part of GlusterFS.

  GlusterFS is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published
  by the Free Software Foundation; either version 3 of the License,
  or (at your option) any later version.

  GlusterFS is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see
  <http://www.gnu.org/licenses/>.
*/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <pthread.h>

#ifndef _CONFIG_H
#define _CONFIG_H
#include "config.h"
#endif

#include "cli.h"
#include "cli-cmd.h"
#include "cli-mem-types.h"
#include "protocol-common.h"


extern struct rpc_clnt *global_rpc;

extern rpc_clnt_prog_t *cli_rpc_prog;

int cli_cmd_system_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word,
                             const char **words, int wordcount);

int
cli_cmd_getspec_cbk (struct cli_state *state, struct cli_cmd_word *word,
                     const char **words, int wordcount)
{
        int                     ret = -1;
        rpc_clnt_procedure_t    *proc = NULL;
        call_frame_t            *frame = NULL;
        dict_t                  *dict = NULL;

        frame = create_frame (THIS, THIS->ctx->pool);
        if (!frame)
                goto out;

        dict = dict_new ();
        if (!dict)
                goto out;

        if (wordcount != 3) {
                cli_usage_out (word->pattern);
                goto out;
        }

        ret = dict_set_str (dict, "volid", (char *)words[2]);
        if (ret)
                goto out;

        proc = &cli_rpc_prog->proctable[GLUSTER_CLI_GETSPEC];
        if (proc->fn) {
                ret = proc->fn (frame, THIS, dict);
        }

out:
        if (!proc && ret) {
                if (dict)
                        dict_destroy (dict);
                if (wordcount > 1)
                        cli_out ("Fetching spec for volume %s failed",
                                 (char *)words[2]);
        }

        return ret;
}

int
cli_cmd_pmap_b2p_cbk (struct cli_state *state, struct cli_cmd_word *word,
                 const char **words, int wordcount)
{
        int                     ret = -1;
        rpc_clnt_procedure_t    *proc = NULL;
        call_frame_t            *frame = NULL;
        dict_t                  *dict = NULL;

        frame = create_frame (THIS, THIS->ctx->pool);
        if (!frame)
                goto out;

        dict = dict_new ();
        if (!dict)
                goto out;

        if (wordcount != 4) {
                cli_usage_out (word->pattern);
                goto out;
        }

        ret = dict_set_str (dict, "brick", (char *)words[3]);
        if (ret)
                goto out;

        proc = &cli_rpc_prog->proctable[GLUSTER_CLI_PMAP_PORTBYBRICK];
        if (proc->fn) {
                ret = proc->fn (frame, THIS, dict);
        }

out:
        if (!proc && ret) {
                if (dict)
                        dict_destroy (dict);
                if (wordcount > 1)
                        cli_out ("Fetching spec for volume %s failed",
                                 (char *)words[3]);
        }

        return ret;
}

int
cli_cmd_fsm_log_cbk (struct cli_state *state, struct cli_cmd_word *word,
                     const char **words, int wordcount)
{
        int                             ret = -1;
        rpc_clnt_procedure_t            *proc = NULL;
        call_frame_t                    *frame = NULL;
        char                            *name = "";

        if ((wordcount != 4) && (wordcount != 3)) {
                cli_usage_out (word->pattern);
                goto out;
        }

        if (wordcount == 4)
                name = (char*)words[3];
        proc = &cli_rpc_prog->proctable[GLUSTER_CLI_FSM_LOG];
        if (proc && proc->fn) {
                frame = create_frame (THIS, THIS->ctx->pool);
                if (!frame)
                        goto out;
                ret = proc->fn (frame, THIS, (void*)name);
        }
out:
        return ret;
}

int
cli_cmd_getwd_cbk (struct cli_state *state, struct cli_cmd_word *word,
                   const char **words, int wordcount)
{
        int                             ret = -1;
        rpc_clnt_procedure_t            *proc = NULL;
        call_frame_t                    *frame = NULL;

        if (wordcount != 2) {
                cli_usage_out (word->pattern);
                goto out;
        }

        proc = &cli_rpc_prog->proctable[GLUSTER_CLI_GETWD];
        if (proc && proc->fn) {
                frame = create_frame (THIS, THIS->ctx->pool);
                if (!frame)
                        goto out;
                ret = proc->fn (frame, THIS, NULL);
        }
out:
        return ret;
}

static dict_t *
make_seq_dict (int argc, char **argv)
{
        char index[] = "4294967296"; // 1<<32
        int i        = 0;
        int ret      = 0;
        dict_t *dict = dict_new ();

        if (!dict)
                return NULL;

        for (i = 0; i < argc; i++) {
                snprintf(index, sizeof(index), "%d", i);
                ret = dict_set_str (dict, index, argv[i]);
                if (ret == -1)
                        break;
        }

        if (ret) {
                dict_destroy (dict);
                dict = NULL;
        }

        return dict;
}

int
cli_cmd_mount_cbk (struct cli_state *state, struct cli_cmd_word *word,
                   const char **words, int wordcount)
{
        rpc_clnt_procedure_t *proc = NULL;
        call_frame_t *frame        = NULL;
        int ret                    = -1;
        dict_t *dict               = NULL;
        void *dataa[]              = {NULL, NULL};

        if (wordcount < 4) {
                cli_usage_out (word->pattern);
                goto out;
        }

        dict = make_seq_dict (wordcount - 3, (char **)words + 3);
        if (!dict)
                goto out;

        dataa[0] = (void *)words[2];
        dataa[1] = dict;

        proc = &cli_rpc_prog->proctable[GLUSTER_CLI_MOUNT];
        if (proc && proc->fn) {
                frame = create_frame (THIS, THIS->ctx->pool);
                if (!frame)
                        goto out;
                ret = proc->fn (frame, THIS, dataa);
        }

 out:
        if (dict)
                dict_unref (dict);

        if (!proc && ret)
                cli_out ("Mount command failed");

        return ret;
}

int
cli_cmd_umount_cbk (struct cli_state *state, struct cli_cmd_word *word,
                   const char **words, int wordcount)
{
        rpc_clnt_procedure_t *proc = NULL;
        call_frame_t *frame        = NULL;
        int ret                    = -1;
        dict_t *dict               = NULL;

        if (!(wordcount == 3 ||
              (wordcount == 4 && strcmp (words[3], "lazy") == 0))) {
                cli_usage_out (word->pattern);
                goto out;
        }

        dict = dict_new ();
        if (!dict)
                goto out;

        ret = dict_set_str (dict, "path", (char *)words[2]);
        if (ret != 0)
                goto out;
        ret = dict_set_int32 (dict, "lazy", wordcount == 4);
        if (ret != 0)
                goto out;

        proc = &cli_rpc_prog->proctable[GLUSTER_CLI_UMOUNT];
        if (proc && proc->fn) {
                frame = create_frame (THIS, THIS->ctx->pool);
                if (!frame)
                        goto out;
                ret = proc->fn (frame, THIS, dict);
        }

 out:
        if (dict)
                dict_unref (dict);

        if (!proc && ret)
                cli_out ("Umount command failed");

        return ret;
}

struct cli_cmd cli_system_cmds[] = {
        { "system:: getspec <VOLID>",
          cli_cmd_getspec_cbk,
          "fetch spec for volume <VOLID>"},

        { "system:: portmap brick2port <BRICK>",
          cli_cmd_pmap_b2p_cbk,
          "query which port <BRICK> listens on"},

        { "system:: fsm log [<peer-name>]",
          cli_cmd_fsm_log_cbk,
          "display fsm transitions"},

        { "system:: getwd",
          cli_cmd_getwd_cbk,
          "query glusterd work directory"},

        { "system:: mount <label> <args...>",
          cli_cmd_mount_cbk,
          "request a mount"},

        { "system:: umount <path> [lazy]",
          cli_cmd_umount_cbk,
          "request an umount"},

        { "system:: help",
           cli_cmd_system_help_cbk,
           "display help for system commands"},

        { NULL, NULL, NULL }
};

int
cli_cmd_system_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word,
                         const char **words, int wordcount)
{
        struct cli_cmd *cmd = NULL;

        for (cmd = cli_system_cmds; cmd->pattern; cmd++)
                cli_out ("%s - %s", cmd->pattern, cmd->desc);

        return 0;
}

int
cli_cmd_system_register (struct cli_state *state)
{
        int  ret = 0;
        struct cli_cmd *cmd = NULL;

        for (cmd = cli_system_cmds; cmd->pattern; cmd++) {

                ret = cli_cmd_register (&state->tree, cmd);
                if (ret)
                        goto out;
        }
out:
        return ret;
}
-afrv1.git/commit/?h=v3.2.4qa4&id=deea482deff52251f9fe39bc3bda09f58397cb06'>commit deea482def...Vijay Bellur14 years v3.3.0qa34commit 4bb82b2c77...Vijay Bellur14 years v3.3.0qa33commit 1043dedfb5...Vijay Bellur14 years v3.3.0qa32commit af0eb165f6...Vijay Bellur14 years v3.3.0qa31commit c40b9975d0...Vijay Bellur14 years v3.3.0qa30commit d98c3e1934...Vijay Bellur14 years v3.3.0qa29commit 65c6e3706f...Anand Avati14 years v3.3.0qa28commit 212d739886...Vijay Bellur14 years v3.2.6p3commit 410b1092e6...Vijay Bellur14 years v3.2.6p2commit 5ce988633d...Vijay Bellur14 years v3.3.0qa27commit 152a0194e7...Vijay Bellur14 years v3.2.6commit fafd5c17c0...Vijay Bellur14 years v3.2.6qa6commit fafd5c17c0...Vijay Bellur14 years v3.2.6qa5commit e657569da2...Vijay Bellur14 years v3.3.0qa26commit f6a779ffc5...Vijay Bellur14 years v3.2.6qa4commit 8127a6f35e...Vijay Bellur14 years v3.3.0qa25commit 468768d280...Vijay Bellur14 years v3.3.0qa24commit 88c6c11813...Vijay Bellur14 years v3.3.0qa23commit 42cc043875...Vijay Bellur14 years v3.3.0qa22commit c8d47f056e...Vijay Bellur14 years v3.2.6qa3commit cd3ad588f2...Anand Avati14 years v3.2.6qa2commit fa580e9299...Anand Avati14 years v3.3.0qa21commit 83a3daf7c2...Vijay Bellur14 years v3.3.0qa20commit 0694749c3e...Vijay Bellur14 years v3.2.6qa1commit 1020a3dfe9...Anand Avati14 years v3.3.0qa19commit be003fbb3a...Vijay Bellur14 years v3.3.0qa18commit d7d9f3d400...Vijay Bellur14 years v3.3.0qa17commit 0074f20844...Vijay Bellur14 years v3.3.0qa16commit 7235e5b1af...Vijay Bellur14 years v3.3.0qa15commit 289c2902d6...Vijay Bellur14 years v3.2.5commit edf9551b38...Vijay Bellur14 years v3.2.5qa9commit edf9551b38...Vijay Bellur14 years v3.2.5qa8commit 252c9e5cf2...Vijay Bellur14 years v3.2.5qa7commit d2a05724a6...Vijay Bellur14 years v3.2.5qa6commit 51601b2bff...Vijay Bellur14 years v3.2.5qa5commit 8668da9744...Vijay Bellur14 years v3.2.5qa4commit bca358604d...Vijay Bellur14 years v3.2.5qa3commit 3b0eecb53f...Vijay Bellur14 years v3.2.5qa2commit 7dcc94cf1f...Vijay Bellur14 years v3.2.5qa1commit 449f31c8ae...Vijay Bellur14 years v3.3.0qa14commit 4235f7a74e...Vijay Bellur14 years v3.2.4commit da73b31942...Vijay Bellur14 years v3.3.0qa13commit 795c8996c1...Vijay Bellur14 years v3.2.4qa5commit 6c5d3e40a6...Vijay Bellur14 years v3.3.0qa12commit 16b7e3bf20...Vijay Bellur14 years v3.2.4qa4commit edd9461647...Vijay Bellur14 years v3.3.0qa11commit 7658047903...Vijay Bellur14 years v3.3.0qa10commit 4765dd1a1c...Vijay Bellur14 years v3.2.4qa3commit 9564e09e53...Vijay Bellur14 years v3.2.4qa2commit 0f9502d5eb...Vijay Bellur14 years v3.2.4qa1commit 6fe790ee35...Vijay Bellur14 years v3.3.0qa9commit b827cdb230...Vijay Bellur14 years v3.1.7commit a2739b842b...Vijay Bellur14 years v3.1.7qa4commit a2739b842b...Vijay Bellur14 years v3.1.7qa3commit f9fa468090...Vijay Bellur14 years v3.1.7qa2commit d120020fd5...Vijay Bellur14 years v3.1.7qa1commit 561bba7ae4...Vijay Bellur14 years v3.2.3commit 1acef91232...Vijay Bellur14 years v3.3beta2commit b827cdb230...Vijay Bellur14 years v3.3.0qa8commit b827cdb230...Vijay Bellur14 years v3.3.0qa7commit 601f5725a0...Vijay Bellur14 years v3.2.3qa6commit 1acef91232...Vijay Bellur14 years v3.3.0qa6commit b6e3e9c480...Vijay Bellur14 years v3.3.0qa5commit 5ace31ac21...Vijay Bellur15 years v3.2.3qa5commit 10f69943c4...Vijay Bellur15 years v3.3.0qa4commit 350ae611ca...Vijay Bellur15 years v3.2.3qa4commit 0564d1198b...Vijay Bellur15 years v3.2.3qa3commit 2f53b7857c...Vijay Bellur15 years v3.3.0qa3commit 6073fc29bf...Vijay Bellur15 years v3.3.0qa2commit a0071bdf2a...Vijay Bellur15 years v3.1.6commit 98a487f842...Vijay Bellur15 years v3.1.6qa8commit ef517191c5...Vijay Bellur15 years v3.3.0qa1commit 1b5a860f15...Vijay Bellur15 years v3.1.6qa7commit 05e3dcc9b1...Vijay Bellur15 years v3.2.3qa1commit 62adb4d1c2...Vijay Bellur15 years v3.1.6qa6commit c92f45c742...Anand Avati15 years v3.1.6qa5commit 0c01d96a06...Vijay Bellur15 years v3.1.6qa4commit dfc317a77f...Anand Avati15 years v3.1.6qa3commit 967199adb1...Anand Avati15 years v3.1.6qa2commit 7382534ac1...Anand Avati15 years v3.3beta1commit fd60df8798...Anand Avati15 years v3.2.2commit c82a9d438b...Anand Avati15 years v3.2.2qa8commit c82a9d438b...Anand Avati15 years v3.1.6qa1commit 0c9648c1a0...Anand Avati15 years v3.2.2qa7commit 972c4a3c34...Anand Avati15 years v3.2.2qa5commit 7685cec583...Anand Avati15 years v3.2.2qa4commit 817bda650c...Anand Avati15 years v3.2.2qa3commit 1b01b64894...Anand Avati15 years v3.2.2qa2commit 5c20eb3bbf...Vijay Bellur15 years v3.2.2qa1commit 6ca8604204...Anand Avati15 years v3.1.5commit a64d1a8157...Anand Avati15 years v3.1.5qa4commit a64d1a8157...Vijay Bellur15 years v3.1.5qa3commit 5bcb4ddca3...Anand Avati15 years v3.1.5qa2commit 25da481bc5...Anand Avati15 years v3.2.1commit c5321286e5...Anand Avati15 years v3.2.1qa5commit c5321286e5...Anand Avati15 years v3.2.1qa4commit 8dee45b3a7...Anand Avati15 years v3.2.1qa3commit c51b2f7c6c...Anand Avati15 years v3.2.1qa2commit 05c4dced82...Anand Avati15 years v3.2.1qa1commit ef39bf9d23...Anand Avati15 years v3.1.5qa1commit 5f1efbc32d...Vijay Bellur15 years v3.0.8commit ee744e0908...Vijay Bellur15 years v3.0.8qa1commit ee744e0908...Vijay Bellur15 years v3.2.0commit 77f485dc30...Anand Avati15 years branchpoint-3.2commit 1f06da6875...Anand Avati15 years v3.2.0qa16commit 625f779dba...Anand Avati15 years v3.2.0qa15commit b5848ed21b...Anand Avati15 years v3.2.0qa14commit 72b57e311f...Anand Avati15 years v3.2.0qa13commit da66edbe92...Vijay Bellur15 years v3.2.0qa12commit 1c5706c43d...Anand Avati15 years v3.2.0qa11commit 902478bf9e...Anand Avati15 years v3.1.4commit 7b368061ea...Anand Vishweshwaran Avati15 years v3.2.0qa10commit 6db2b422f0...Vijay Bellur15 years v3.1.4qa3commit 7b368061ea...Vijay Bellur15 years v3.2.0qa9commit 56814fefa0...Vijay Bellur15 years v3.2.0qa8commit 35dea20e40...Vijay Bellur15 years v3.1.4qa2commit 2b55a49045...Vijay Bellur15 years v3.2.0qa7commit f338193a70...Vijay Bellur15 years v3.2.0qa6commit 498dbbc506...Vijay Bellur15 years v3.2.0qa5commit 408a2b0298...Vijay Bellur15 years v3.1.3solariscommit 9c0d73d37b...Anand V. Avati15 years v3.2.0qa4commit bd132d8e41...Vijay Bellur15 years v3.1.3commit 1641d8bb4c...Vijay Bellur15 years v3.1.3qa8commit c549807c23...Vijay Bellur15 years v3.1.3qa7commit 5017098718...Vijay Bellur15 years v3.1.3qa6commit 93845ea7cc...Vijay Bellur15 years v3.1.3qa5commit cad088fe3a...Vijay Bellur15 years v3.1.3qa3commit 5b909c83de...Vijay Bellur15 years v3.1.3qa1commit b99e0e0678...Vijay Bellur15 years v3.1.2commit f2a067c4fe...Vijay Bellur15 years v3.0.7commit 6da4cc87ff...Anand V. Avati15 years v3.1.1commit 69a62d2a6d...Anand V. Avati15 years v3.0.6commit 5cbc81a8d3...Vijay Bellur15 years v3.0.6rc1commit ef4005be3a...Vijay Bellur15 years v3.1.0commit 6e6b4b4fd0...Vijay Bellur15 years v3.1.0qa9commit d13ddaf872...Anand V. Avati15 years v3.1.0qa8commit df4a7d7576...Anand V. Avati15 years v3.1.0prealpha4commit 12e997d863...Anand V. Avati16 years v3.1.0prealpha3commit f51252fa0d...Anand V. Avati16 years v3.1.0prealpha2commit 03df087149...Anand V. Avati16 years v3.1.0prealpha1commit 7e6b5454ad...Anand V. Avati16 years v3.1.0qa7commit ab72e06f7b...Anand V. Avati16 years v3.1.0qa6commit 0ec245abd6...Anand V. Avati16 years v3.1.0qa5commit 9349f559dc...Anand V. Avati16 years v3.1.0qa3commit 543f9ef575...Anand V. Avati16 years v3.1.0qa2commit 931a59e2b9...Anand V. Avati16 years v3.0.5commit 002d35bfb1...Anand V. Avati16 years v3.0.4commit aaeddc5084...Anand V. Avati16 years v3.0.3commit 029062c103...Anand V. Avati16 years v3.0.2commit 15043b6d97...Anand V. Avati16 years v3.0.1commit 4c20b5377e...Anand V. Avati16 years v2.0.9commit 7e1ba386dd...Anand V. Avati16 years v3.0.0commit 8379edd978...Anand V. Avati16 years v2.0.8commit 1a53a5a4bf...Anand V. Avati16 years v2.0.7commit 7ba890140f...Anand V. Avati16 years v2.0.6commit 8dfdde57b3...Anand V. Avati17 years v2.0.5commit 683fda4bf0...Anand V. Avati17 years v2.0.4commit 55f476455c...Anand V. Avati17 years v2.0.3commit b470684cbf...Anand V. Avati17 years tag-release-2.0commit 4d4cfc6e45...Anand V. Avati17 years 2.0.0commit 7b2e459db6...Anand V. Avati17 years 2.0.1commit 5c1d9108c1...Anand V. Avati17 years