summaryrefslogtreecommitdiffstats
path: root/cli/src/cli-cmd-volume-bdevice.c
diff options
context:
space:
mode:
authorM. Mohan Kumar <mohan@in.ibm.com>2012-11-29 21:46:07 +0530
committerVijay Bellur <vbellur@redhat.com>2012-11-29 09:40:14 -0800
commit983d290f7b36fea580ed9337bdc15e8f0f6f5bb3 (patch)
tree7437660f9427ca9fb1bbf5432b38dc35f7351389 /cli/src/cli-cmd-volume-bdevice.c
parent3c72850e8d00f0cf35ae054136be076a394e08e9 (diff)
BD Backend: CLI to create a full/linked clone of a image
A new CLI command added to support cloning/snapshotting of a LV device Syntax is: $ gluster bd clone <volname>:<vg>/<lv> <newlv> $ gluster bd snapshot <volname>:<vg>/<lv> <snap_lv> <size> BUG: 805138 Change-Id: Idc2ac14525a3998329c742bf85a06326cac8cd54 Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com> Reviewed-on: http://review.gluster.org/3719 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'cli/src/cli-cmd-volume-bdevice.c')
-rw-r--r--cli/src/cli-cmd-volume-bdevice.c47
1 files changed, 46 insertions, 1 deletions
diff --git a/cli/src/cli-cmd-volume-bdevice.c b/cli/src/cli-cmd-volume-bdevice.c
index ea7edab6502..19325754fb9 100644
--- a/cli/src/cli-cmd-volume-bdevice.c
+++ b/cli/src/cli-cmd-volume-bdevice.c
@@ -41,6 +41,8 @@ cli_cmd_bd_parse (dict_t *dict, const char **words)
char *size = NULL;
char *eptr = NULL;
gf_xl_bd_op_t bd_op = GF_BD_OP_INVALID;
+ char *dest_lv = NULL;
+
/* volname:/path */
if (!strchr (words[2], ':') || !strchr (words[2], '/')) {
@@ -64,6 +66,10 @@ cli_cmd_bd_parse (dict_t *dict, const char **words)
bd_op = GF_BD_OP_NEW_BD;
else if (!strcasecmp (words[1], "delete"))
bd_op = GF_BD_OP_DELETE_BD;
+ else if (!strcasecmp (words[1], "clone"))
+ bd_op = GF_BD_OP_CLONE_BD;
+ else if (!strcasecmp (words[1], "snapshot"))
+ bd_op = GF_BD_OP_SNAPSHOT_BD;
else
return -1;
@@ -83,6 +89,30 @@ cli_cmd_bd_parse (dict_t *dict, const char **words)
ret = dict_set_dynstr (dict, "size", size);
if (ret)
goto out;
+ } else if (bd_op == GF_BD_OP_SNAPSHOT_BD ||
+ bd_op == GF_BD_OP_CLONE_BD) {
+ /*
+ * dest_lv should be just dest_lv, we don't support
+ * cloning/snapshotting to a different volume or vg
+ */
+ if (strchr (words[3], ':') || strchr (words[3], '/')) {
+ cli_err ("invalid parameter %s, volname/vg not needed",
+ words[3]);
+ ret = -1;
+ goto out;
+ }
+ dest_lv = gf_strdup (words[3]);
+ ret = dict_set_dynstr (dict, "dest_lv", dest_lv);
+ if (ret)
+ goto out;
+
+ /* clone needs size as parameter */
+ if (bd_op == GF_BD_OP_SNAPSHOT_BD) {
+ ret = dict_set_dynstr (dict, "size",
+ gf_strdup (words[4]));
+ if (ret)
+ goto out;
+ }
}
ret = 0;
@@ -94,13 +124,15 @@ out:
/*
* bd create <volname>:/path <size>
* bd delete <volname>:/path
+ * bd clone <volname>:/path <newbd>
+ * bd snapshot <volname>:/<path> <newbd> <size>
*/
int32_t
cli_cmd_bd_validate (const char **words, int wordcount, dict_t **options)
{
dict_t *dict = NULL;
int ret = -1;
- char *op[] = { "create", "delete", NULL };
+ char *op[] = { "create", "delete", "clone", "snapshot", NULL };
int index = 0;
for (index = 0; op[index]; index++)
@@ -120,6 +152,12 @@ cli_cmd_bd_validate (const char **words, int wordcount, dict_t **options)
} else if (!strcasecmp (words[1], "delete")) {
if (wordcount != 3)
goto out;
+ } else if (!strcasecmp (words[1], "clone")) {
+ if (wordcount != 4)
+ goto out;
+ } else if (!strcasecmp (words[1], "snapshot")) {
+ if (wordcount != 5)
+ goto out;
} else {
ret = -1;
goto out;
@@ -193,6 +231,13 @@ struct cli_cmd cli_bd_cmds[] = {
{ "bd delete <volname>:<bd>",
cli_cmd_bd_cbk,
"Delete a block device"},
+ { "bd clone <volname>:<bd> <newbd>",
+ cli_cmd_bd_cbk,
+ "clone device"},
+ { "bd snapshot <volname>:<bd> <newbd> <size>",
+ cli_cmd_bd_cbk,
+ "\n\tsnapshot device where size can be "
+ "suffixed with KB, MB etc. Default size is in MB"},
{ NULL, NULL, NULL }
};