"Fossies" - the Fresh Open Source Software Archive

Member "glusterfs-8.2/cli/src/cli-cmd-snapshot.c" (16 Sep 2020, 4161 Bytes) of package /linux/misc/glusterfs-8.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "cli-cmd-snapshot.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2    Copyright (c) 2013-2014 Red Hat, Inc. <http://www.redhat.com>
    3    This file is part of GlusterFS.
    4 
    5    This file is licensed to you under your choice of the GNU Lesser
    6    General Public License, version 3 or any later version (LGPLv3 or
    7    later), or the GNU General Public License, version 2 (GPLv2), in all
    8    cases as published by the Free Software Foundation.
    9 */
   10 #include <stdio.h>
   11 #include <string.h>
   12 #include <stdlib.h>
   13 #include <stdint.h>
   14 #include <pthread.h>
   15 
   16 #include "cli.h"
   17 #include "cli-cmd.h"
   18 #include "cli-mem-types.h"
   19 
   20 extern rpc_clnt_prog_t *cli_rpc_prog;
   21 
   22 int
   23 cli_cmd_snapshot_help_cbk(struct cli_state *state, struct cli_cmd_word *in_word,
   24                           const char **words, int wordcount);
   25 
   26 int
   27 cli_cmd_snapshot_cbk(struct cli_state *state, struct cli_cmd_word *word,
   28                      const char **words, int wordcount)
   29 {
   30     int ret = 0;
   31     int parse_err = 0;
   32     dict_t *options = NULL;
   33     rpc_clnt_procedure_t *proc = NULL;
   34     call_frame_t *frame = NULL;
   35     cli_local_t *local = NULL;
   36 
   37     proc = &cli_rpc_prog->proctable[GLUSTER_CLI_SNAP];
   38 
   39     /* Parses the command entered by the user */
   40     ret = cli_cmd_snapshot_parse(words, wordcount, &options, state);
   41     if (ret) {
   42         if (ret < 0) {
   43             cli_usage_out(word->pattern);
   44             parse_err = 1;
   45         } else {
   46             /* User might have cancelled the snapshot operation */
   47             ret = 0;
   48         }
   49         goto out;
   50     }
   51 
   52     frame = create_frame(THIS, THIS->ctx->pool);
   53     if (frame == NULL) {
   54         ret = -1;
   55         goto out;
   56     }
   57 
   58     CLI_LOCAL_INIT(local, words, frame, options);
   59 
   60     if (proc->fn)
   61         ret = proc->fn(frame, THIS, options);
   62 
   63 out:
   64     if (ret && parse_err == 0)
   65         cli_out("Snapshot command failed");
   66 
   67     CLI_STACK_DESTROY(frame);
   68 
   69     return ret;
   70 }
   71 
   72 struct cli_cmd snapshot_cmds[] = {
   73     {"snapshot help", cli_cmd_snapshot_help_cbk,
   74      "display help for snapshot commands"},
   75     {"snapshot create <snapname> <volname> [no-timestamp] "
   76      "[description <description>] [force]",
   77      cli_cmd_snapshot_cbk, "Snapshot Create."},
   78     {"snapshot clone <clonename> <snapname>", cli_cmd_snapshot_cbk,
   79      "Snapshot Clone."},
   80     {"snapshot restore <snapname>", cli_cmd_snapshot_cbk, "Snapshot Restore."},
   81     {"snapshot status [(snapname | volume <volname>)]", cli_cmd_snapshot_cbk,
   82      "Snapshot Status."},
   83     {"snapshot info [(snapname | volume <volname>)]", cli_cmd_snapshot_cbk,
   84      "Snapshot Info."},
   85     {"snapshot list [volname]", cli_cmd_snapshot_cbk, "Snapshot List."},
   86     {"snapshot config [volname] ([snap-max-hard-limit <count>] "
   87      "[snap-max-soft-limit <percent>]) "
   88      "| ([auto-delete <enable|disable>])"
   89      "| ([activate-on-create <enable|disable>])",
   90      cli_cmd_snapshot_cbk, "Snapshot Config."},
   91     {"snapshot delete (all | snapname | volume <volname>)",
   92      cli_cmd_snapshot_cbk, "Snapshot Delete."},
   93     {"snapshot activate <snapname> [force]", cli_cmd_snapshot_cbk,
   94      "Activate snapshot volume."},
   95     {"snapshot deactivate <snapname>", cli_cmd_snapshot_cbk,
   96      "Deactivate snapshot volume."},
   97     {NULL, NULL, NULL}};
   98 
   99 int
  100 cli_cmd_snapshot_help_cbk(struct cli_state *state, struct cli_cmd_word *in_word,
  101                           const char **words, int wordcount)
  102 {
  103     struct cli_cmd *cmd = NULL;
  104     struct cli_cmd *snap_cmd = NULL;
  105     int count = 0;
  106 
  107     cmd = GF_MALLOC(sizeof(snapshot_cmds), cli_mt_cli_cmd);
  108     memcpy(cmd, snapshot_cmds, sizeof(snapshot_cmds));
  109     count = (sizeof(snapshot_cmds) / sizeof(struct cli_cmd));
  110     cli_cmd_sort(cmd, count);
  111 
  112     cli_out("\ngluster snapshot commands");
  113     cli_out("=========================\n");
  114 
  115     for (snap_cmd = cmd; snap_cmd->pattern; snap_cmd++)
  116         if (_gf_false == snap_cmd->disable)
  117             cli_out("%s - %s", snap_cmd->pattern, snap_cmd->desc);
  118     cli_out("\n");
  119 
  120     GF_FREE(cmd);
  121     return 0;
  122 }
  123 
  124 int
  125 cli_cmd_snapshot_register(struct cli_state *state)
  126 {
  127     int ret = 0;
  128     struct cli_cmd *cmd = NULL;
  129 
  130     for (cmd = snapshot_cmds; cmd->pattern; cmd++) {
  131         ret = cli_cmd_register(&state->tree, cmd);
  132         if (ret)
  133             goto out;
  134     }
  135 out:
  136     return ret;
  137 }