[sheepdog] [PATCH v2] collie: print VIDs in various vdi operations
Hitoshi Mitake
mitake.hitoshi at lab.ntt.co.jp
Tue Jul 2 11:02:55 CEST 2013
Priting VIDs after various operations by "collie vdi" is useful for
frontend software which wraps collie. Because detecting changed VIDs
with an output of "collie vdi list" is costly, printing changed VIDs
when the change happens is an effective way.
Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
v2: Add a new option -v to collie for verbose output. If this option
isn't passed, VIDs are not printed.
collie/collie.c | 5 +++++
collie/collie.h | 1 +
collie/vdi.c | 47 ++++++++++++++++++++++++++++++++++++++++-------
3 files changed, 46 insertions(+), 7 deletions(-)
diff --git a/collie/collie.c b/collie/collie.c
index 7975b47..2f8e9d0 100644
--- a/collie/collie.c
+++ b/collie/collie.c
@@ -25,6 +25,7 @@ const char *sdhost = "127.0.0.1";
int sdport = SD_LISTEN_PORT;
bool highlight = true;
bool raw_output;
+bool verbose;
static const struct sd_option collie_options[] = {
@@ -33,6 +34,7 @@ static const struct sd_option collie_options[] = {
{'p', "port", true, "specify the daemon port"},
{'r', "raw", false, "raw output mode: omit headers, separate fields with\n"
" single spaces and print all sizes in decimal bytes"},
+ {'v', "verbose", false, "print more information than default"},
{'h', "help", false, "display this help and exit"},
{ 0, NULL, false, NULL },
@@ -376,6 +378,9 @@ int main(int argc, char **argv)
case 'r':
raw_output = true;
break;
+ case 'v':
+ verbose = true;
+ break;
case 'h':
subcommand_usage(argv[1], argv[2], EXIT_SUCCESS);
break;
diff --git a/collie/collie.h b/collie/collie.h
index 18b9c08..0e8cb3b 100644
--- a/collie/collie.h
+++ b/collie/collie.h
@@ -51,6 +51,7 @@ extern const char *sdhost;
extern int sdport;
extern bool highlight;
extern bool raw_output;
+extern bool verbose;
extern uint32_t sd_epoch;
extern struct sd_node sd_nodes[SD_MAX_NODES];
diff --git a/collie/vdi.c b/collie/vdi.c
index 987be29..8707b1f 100644
--- a/collie/vdi.c
+++ b/collie/vdi.c
@@ -609,6 +609,14 @@ static int vdi_create(int argc, char **argv)
}
show_progress(idx * SD_DATA_OBJ_SIZE, inode->vdi_size);
ret = EXIT_SUCCESS;
+
+ if (verbose) {
+ if (raw_output)
+ printf("%x\n", vid);
+ else
+ printf("VDI ID of newly created VDI: %x\n", vid);
+ }
+
out:
free(inode);
return ret;
@@ -639,8 +647,17 @@ static int vdi_snapshot(int argc, char **argv)
0, inode->nr_copies, false, true);
}
- return do_vdi_create(vdiname, inode->vdi_size, vid, NULL, true,
+ ret = do_vdi_create(vdiname, inode->vdi_size, vid, NULL, true,
inode->nr_copies);
+
+ if (ret == EXIT_SUCCESS && verbose) {
+ if (raw_output)
+ printf("%x\n", vid);
+ else
+ printf("VDI ID of newly created snapshot: %x\n", vid);
+ }
+
+ return ret;
}
static int vdi_clone(int argc, char **argv)
@@ -712,6 +729,13 @@ static int vdi_clone(int argc, char **argv)
}
show_progress(idx * SD_DATA_OBJ_SIZE, inode->vdi_size);
ret = EXIT_SUCCESS;
+
+ if (verbose) {
+ if (raw_output)
+ printf("%x\n", new_vid);
+ else
+ printf("VDI ID of newly created clone: %x\n", new_vid);
+ }
out:
free(inode);
free(buf);
@@ -818,7 +842,7 @@ static int vdi_delete(int argc, char **argv)
static int vdi_rollback(int argc, char **argv)
{
const char *vdiname = argv[optind++];
- uint32_t base_vid;
+ uint32_t base_vid, new_vid;
int ret;
char buf[SD_INODE_HEADER_SIZE];
struct sd_inode *inode = (struct sd_inode *)buf;
@@ -844,8 +868,17 @@ static int vdi_rollback(int argc, char **argv)
return EXIT_FAILURE;
}
- return do_vdi_create(vdiname, inode->vdi_size, base_vid, NULL,
+ ret = do_vdi_create(vdiname, inode->vdi_size, base_vid, &new_vid,
false, vdi_cmd_data.nr_copies);
+
+ if (ret == EXIT_SUCCESS && verbose) {
+ if (raw_output)
+ printf("%x\n", new_vid);
+ else
+ printf("New VDI ID of rollbacked VDI: %x\n", new_vid);
+ }
+
+ return ret;
}
static int vdi_object(int argc, char **argv)
@@ -2025,19 +2058,19 @@ static struct subcommand vdi_cmd[] = {
{"check", "<vdiname>", "saph", "check and repair image's consistency",
NULL, SUBCMD_FLAG_NEED_NODELIST|SUBCMD_FLAG_NEED_ARG,
vdi_check, vdi_options},
- {"create", "<vdiname> <size>", "Pcaph", "create an image",
+ {"create", "<vdiname> <size>", "Pcaphrv", "create an image",
NULL, SUBCMD_FLAG_NEED_NODELIST|SUBCMD_FLAG_NEED_ARG,
vdi_create, vdi_options},
- {"snapshot", "<vdiname>", "saph", "create a snapshot",
+ {"snapshot", "<vdiname>", "saphrv", "create a snapshot",
NULL, SUBCMD_FLAG_NEED_ARG,
vdi_snapshot, vdi_options},
- {"clone", "<src vdi> <dst vdi>", "sPcaph", "clone an image",
+ {"clone", "<src vdi> <dst vdi>", "sPcaphrv", "clone an image",
NULL, SUBCMD_FLAG_NEED_ARG,
vdi_clone, vdi_options},
{"delete", "<vdiname>", "saph", "delete an image",
NULL, SUBCMD_FLAG_NEED_ARG,
vdi_delete, vdi_options},
- {"rollback", "<vdiname>", "saphf", "rollback to a snapshot",
+ {"rollback", "<vdiname>", "saphfrv", "rollback to a snapshot",
NULL, SUBCMD_FLAG_NEED_ARG,
vdi_rollback, vdi_options},
{"list", "[vdiname]", "aprh", "list images",
--
1.7.10.4
More information about the sheepdog
mailing list