[Sheepdog] [PATCH 3/3] support deleting a snapshot vdi with a tag name
MORITA Kazutaka
morita.kazutaka at lab.ntt.co.jp
Sat Feb 5 14:14:38 CET 2011
This enable us to specify a tag name in snapshot deletion.
$ qemu-img snapshot -c tag sheepdog:vdi # create snapshot
$ collie vdi delete vdi -s tag # delete snapshot with tag
Deleting a snapshot with a snapshot id is also still supported.
Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
collie/collie.c | 52 ++++++++++++++++++++++++++++++++++------------------
sheep/vdi.c | 10 +++++++---
2 files changed, 41 insertions(+), 21 deletions(-)
diff --git a/collie/collie.c b/collie/collie.c
index 169f3d2..5ed6bcd 100644
--- a/collie/collie.c
+++ b/collie/collie.c
@@ -165,7 +165,8 @@ struct cluster_cmd_data {
struct vdi_cmd_data {
unsigned int index;
- int snapshot;
+ int snapshot_id;
+ char snapshot_tag[SD_MAX_VDI_TAG_LEN];
} vdi_cmd_data = { ~0, };
static int cluster_format(int argc, char **argv)
@@ -241,7 +242,8 @@ static int shutdown_sheepdog(void)
return 0;
}
-typedef void (*vdi_parser_func_t)(uint32_t vid, char *name, uint32_t tag, uint32_t flags,
+typedef void (*vdi_parser_func_t)(uint32_t vid, char *name, char *tag,
+ uint32_t snapid, uint32_t flags,
struct sheepdog_inode *i, void *data);
static int parse_vdi(vdi_parser_func_t func, size_t size, void *data)
@@ -340,7 +342,7 @@ static int parse_vdi(vdi_parser_func_t func, size_t size, void *data)
}
}
- func(i.vdi_id, i.name, i.snap_id, 0, &i, data);
+ func(i.vdi_id, i.name, i.tag, i.snap_id, 0, &i, data);
next:
close(fd);
}
@@ -348,7 +350,7 @@ static int parse_vdi(vdi_parser_func_t func, size_t size, void *data)
return 0;
}
-static void print_vdi_list(uint32_t vid, char *name, uint32_t tag,
+static void print_vdi_list(uint32_t vid, char *name, char *tag, uint32_t snapid,
uint32_t flags, struct sheepdog_inode *i, void *data)
{
int idx;
@@ -381,12 +383,12 @@ static void print_vdi_list(uint32_t vid, char *name, uint32_t tag,
if (!data || strcmp(name, data) == 0) {
printf("%c %-8s %5d %7s %7s %7s %s %7" PRIx32 "\n",
- is_current(i) ? ' ' : 's', name, tag,
+ is_current(i) ? ' ' : 's', name, snapid,
vdi_size_str, my_objs_str, cow_objs_str, dbuf, vid);
}
}
-static void print_vdi_tree(uint32_t vid, char *name, uint32_t tag,
+static void print_vdi_tree(uint32_t vid, char *name, char * tag, uint32_t snapid,
uint32_t flags, struct sheepdog_inode *i, void *data)
{
time_t ti;
@@ -406,7 +408,7 @@ static void print_vdi_tree(uint32_t vid, char *name, uint32_t tag,
add_vdi_tree(name, buf, vid, i->parent_vdi_id, highlight && is_current(i));
}
-static void print_vdi_graph(uint32_t vid, char *name, uint32_t tag,
+static void print_vdi_graph(uint32_t vid, char *name, char * tag, uint32_t snapid,
uint32_t flags, struct sheepdog_inode *i, void *data)
{
time_t ti;
@@ -430,7 +432,7 @@ static void print_vdi_graph(uint32_t vid, char *name, uint32_t tag,
"size: %10s\\n"
"date: %10s\\n"
"time: %10s",
- name, tag, size_str, dbuf, tbuf);
+ name, snapid, size_str, dbuf, tbuf);
if (is_current(i))
printf("\",\n color=\"red\"\n ];\n\n");
@@ -439,8 +441,9 @@ static void print_vdi_graph(uint32_t vid, char *name, uint32_t tag,
}
-static void cal_total_vdi_size(uint32_t vid, char *name, uint32_t tag,
- uint32_t flags, struct sheepdog_inode *i, void *data)
+static void cal_total_vdi_size(uint32_t vid, char *name, char * tag,
+ uint32_t snapid, uint32_t flags,
+ struct sheepdog_inode *i, void *data)
{
uint64_t *size = data;
@@ -450,18 +453,22 @@ static void cal_total_vdi_size(uint32_t vid, char *name, uint32_t tag,
struct get_vid_info {
char *name;
+ char *tag;
uint32_t vid;
+ uint32_t snapid;
};
-static void get_oid(uint32_t vid, char *name, uint32_t tag,
+static void get_oid(uint32_t vid, char *name, char *tag, uint32_t snapid,
uint32_t flags, struct sheepdog_inode *i, void *data)
{
struct get_vid_info *info = data;
- int snapshot_id = vdi_cmd_data.snapshot;
if (info->name) {
- if (snapshot_id) {
- if (!strcmp(name, info->name) && tag == snapshot_id)
+ if (info->tag) {
+ if (!strcmp(name, info->name) && !strcmp(tag, info->tag))
+ info->vid = vid;
+ } else if (info->snapid) {
+ if (!strcmp(name, info->name) && snapid == info->snapid)
info->vid = vid;
} else {
if (!strcmp(name, info->name))
@@ -717,7 +724,7 @@ static int vdi_delete(int argc, char **argv)
struct sd_vdi_req hdr;
struct sd_vdi_rsp *rsp = (struct sd_vdi_rsp *)&hdr;
unsigned rlen, wlen;
- char vdiname[SD_MAX_VDI_LEN];
+ char vdiname[SD_MAX_VDI_LEN + SD_MAX_VDI_TAG_LEN];
fd = connect_to(sdhost, sdport);
if (fd < 0)
@@ -729,11 +736,14 @@ static int vdi_delete(int argc, char **argv)
wlen = sizeof(vdiname);
hdr.opcode = SD_OP_DEL_VDI;
- hdr.snapid = vdi_cmd_data.snapshot;
+ hdr.snapid = vdi_cmd_data.snapshot_id;
hdr.epoch = node_list_version;
hdr.flags = SD_FLAG_CMD_WRITE;
hdr.data_length = wlen;
- strncpy(vdiname, data, sizeof(vdiname));
+ memset(vdiname, 0, sizeof(vdiname));
+ strncpy(vdiname, data, SD_MAX_VDI_LEN);
+ strncpy(vdiname + SD_MAX_VDI_LEN, vdi_cmd_data.snapshot_tag,
+ SD_MAX_VDI_TAG_LEN);
ret = exec_req(fd, (struct sd_req *)&hdr, vdiname, &wlen, &rlen);
close(fd);
@@ -759,8 +769,11 @@ static int vdi_object(int argc, char **argv)
struct get_vid_info info;
uint32_t vid;
+ memset(&info, 0, sizeof(info));
info.name = vdiname;
+ info.tag = vdi_cmd_data.snapshot_tag;
info.vid = 0;
+ info.snapid = vdi_cmd_data.snapshot_id;
ret = parse_vdi(get_oid, SD_INODE_HEADER_SIZE, &info);
@@ -828,7 +841,10 @@ static int vdi_parser(int ch, char *opt)
vdi_cmd_data.index = atoi(opt);
break;
case 's':
- vdi_cmd_data.snapshot = atoi(opt);
+ vdi_cmd_data.snapshot_id = atoi(opt);
+ if (vdi_cmd_data.snapshot_id == 0)
+ strncpy(vdi_cmd_data.snapshot_tag, opt,
+ sizeof(vdi_cmd_data.snapshot_tag));
break;
}
diff --git a/sheep/vdi.c b/sheep/vdi.c
index 58ce0d3..1490968 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -287,7 +287,7 @@ int start_deletion(uint32_t vid, uint32_t epoch);
int del_vdi(uint32_t epoch, char *data, int data_len, uint32_t *vid, uint32_t snapid)
{
- char *name = data;
+ char *name = data, *tag;
uint32_t dummy0;
unsigned long dummy1, dummy2;
int ret;
@@ -295,10 +295,14 @@ int del_vdi(uint32_t epoch, char *data, int data_len, uint32_t *vid, uint32_t sn
int nr_nodes, nr_reqs;
static struct sheepdog_inode inode;
- if (data_len != SD_MAX_VDI_LEN)
+ if (data_len == SD_MAX_VDI_LEN + SD_MAX_VDI_TAG_LEN)
+ tag = data + SD_MAX_VDI_LEN;
+ else if (data_len == SD_MAX_VDI_LEN)
+ tag = NULL;
+ else
return SD_RES_INVALID_PARMS;
- ret = do_lookup_vdi(epoch, name, strlen(name), vid, NULL, snapid,
+ ret = do_lookup_vdi(epoch, name, strlen(name), vid, tag, snapid,
&dummy0, &dummy1, &dummy2);
if (ret != SD_RES_SUCCESS)
return ret;
--
1.5.6.5
More information about the sheepdog
mailing list