[Sheepdog] [PATCH] sheep: add snapshot tag support
MORITA Kazutaka
morita.kazutaka at lab.ntt.co.jp
Sun Jun 20 21:54:07 CEST 2010
This patch enables us to add a snapshot name when creating a snapshot.
This is mutually depends on the client patch I'll send later to the
qemu-devel. You can also get these from the latest git tree:
server:
git://sheepdog.git.sourceforge.net/gitroot/sheepdog/sheepdog next
client:
git://sheepdog.git.sourceforge.net/gitroot/sheepdog/qemu for-block
usage:
$ qemu-img snapshot -c tagname sheepdog:linux
$ ./collie/collie vdi list
name id size used shared creation time vdi id
------------------------------------------------------------------
s linux 1 2.0 GB 48 MB 0.0 MB 2010-06-18 20:40 a5d05d
linux 2 2.0 GB 0.0 MB 48 MB 2010-06-18 21:23 a5d05e
$ qemu-img snapshot -l sheepdog:linux
Snapshot list:
ID TAG VM SIZE DATE VM CLOCK
1 tagname 0 2010-06-18 21:23:32 00:00:00.000
Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
include/sheepdog_proto.h | 2 ++
sheep/vdi.c | 32 ++++++++++++++++++++++----------
2 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h
index 5a16982..1e321a8 100644
--- a/include/sheepdog_proto.h
+++ b/include/sheepdog_proto.h
@@ -74,6 +74,7 @@
#define MAX_DATA_OBJS (1ULL << 20)
#define MAX_CHILDREN 1024
#define SD_MAX_VDI_LEN 256
+#define SD_MAX_VDI_TAG_LEN 256
#define SD_NR_VDIS (1U << 24)
#define SD_DATA_OBJ_SIZE (UINT64_C(1) << 22)
@@ -156,6 +157,7 @@ struct sd_vdi_rsp {
struct sheepdog_inode {
char name[SD_MAX_VDI_LEN];
+ char tag[SD_MAX_VDI_TAG_LEN];
uint64_t ctime;
uint64_t snap_ctime;
uint64_t vm_clock_nsec;
diff --git a/sheep/vdi.c b/sheep/vdi.c
index 7a894a3..102d956 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -117,14 +117,14 @@ static int create_vdi_obj(uint32_t epoch, char *name, uint32_t new_vid, uint64_t
}
static int find_first_vdi(uint32_t epoch, unsigned long start, unsigned long end,
- char *name, int namelen, uint32_t snapid, uint32_t *vid,
+ char *name, char *tag, uint32_t snapid, uint32_t *vid,
unsigned long *deleted_nr, uint32_t *next_snap)
{
struct sheepdog_node_list_entry entries[SD_MAX_NODES];
static struct sheepdog_inode inode;
unsigned long i;
int nr_nodes, nr_reqs;
- int ret;
+ int ret, vdi_found = 0;
nr_nodes = get_ordered_sd_node_list(entries);
@@ -145,6 +145,10 @@ static int find_first_vdi(uint32_t epoch, unsigned long start, unsigned long end
}
if (!strncmp(inode.name, name, strlen(inode.name))) {
+ vdi_found = 1;
+ if (tag && tag[0] &&
+ strncmp(inode.tag, tag, sizeof(inode.tag)) != 0)
+ continue;
if (snapid && snapid != inode.snap_id)
continue;
@@ -153,12 +157,16 @@ static int find_first_vdi(uint32_t epoch, unsigned long start, unsigned long end
return SD_RES_SUCCESS;
}
}
+
+ if (vdi_found)
+ return SD_RES_NO_TAG;
+
return SD_RES_NO_VDI;
}
static int do_lookup_vdi(uint32_t epoch, char *name, int namelen, uint32_t *vid,
- uint32_t snapid, uint32_t *next_snapid,
+ char *tag, uint32_t snapid, uint32_t *next_snapid,
unsigned long *right_nr, unsigned long *deleted_nr)
{
int ret;
@@ -176,7 +184,7 @@ static int do_lookup_vdi(uint32_t epoch, char *name, int namelen, uint32_t *vid,
} else if (nr < SD_NR_VDIS) {
right_side:
/* look up on the right side of the hash point */
- ret = find_first_vdi(epoch, nr - 1, start_nr, name, namelen, snapid, vid,
+ ret = find_first_vdi(epoch, nr - 1, start_nr, name, tag, snapid, vid,
deleted_nr, next_snapid);
return ret;
} else {
@@ -187,7 +195,7 @@ static int do_lookup_vdi(uint32_t epoch, char *name, int namelen, uint32_t *vid,
return SD_RES_FULL_VDI;
else if (nr) {
/* look up on the left side of the hash point */
- ret = find_first_vdi(epoch, nr - 1, 0, name, namelen, snapid, vid,
+ ret = find_first_vdi(epoch, nr - 1, 0, name, tag, snapid, vid,
deleted_nr, next_snapid);
if (ret == SD_RES_NO_VDI)
; /* we need to go to the right side */
@@ -202,14 +210,18 @@ static int do_lookup_vdi(uint32_t epoch, char *name, int namelen, uint32_t *vid,
int lookup_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;
- 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;
- return do_lookup_vdi(epoch, name, strlen(name), vid, snapid,
+ return do_lookup_vdi(epoch, name, strlen(name), vid, tag, snapid,
&dummy0, &dummy1, &dummy2);
}
@@ -227,7 +239,7 @@ int add_vdi(uint32_t epoch, char *data, int data_len, uint64_t size,
name = data;
- ret = do_lookup_vdi(epoch, name, strlen(name), &cur_vid, 0, &next_snapid,
+ ret = do_lookup_vdi(epoch, name, strlen(name), &cur_vid, NULL, 0, &next_snapid,
&right_nr, &deleted_nr);
if (is_snapshot) {
@@ -287,7 +299,7 @@ int del_vdi(uint32_t epoch, char *data, int data_len, uint32_t snapid)
if (data_len != SD_MAX_VDI_LEN)
return SD_RES_INVALID_PARMS;
- ret = do_lookup_vdi(epoch, name, strlen(name), &vid, snapid,
+ ret = do_lookup_vdi(epoch, name, strlen(name), &vid, NULL, snapid,
&dummy0, &dummy1, &dummy2);
if (ret != SD_RES_SUCCESS)
return ret;
--
1.5.6.5
More information about the sheepdog
mailing list