提交 9ff53a0e 编写于 作者: M MORITA Kazutaka 提交者: Stefan Hajnoczi

sheepdog: add helper function to reload inode

This adds a helper function to update the current inode state with the
specified vdi object.
Signed-off-by: NMORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
上级 6a0b5490
...@@ -1150,6 +1150,42 @@ static int write_object(int fd, char *buf, uint64_t oid, int copies, ...@@ -1150,6 +1150,42 @@ static int write_object(int fd, char *buf, uint64_t oid, int copies,
create, cache_flags); create, cache_flags);
} }
/* update inode with the latest state */
static int reload_inode(BDRVSheepdogState *s, uint32_t snapid, const char *tag)
{
SheepdogInode *inode;
int ret = 0, fd;
uint32_t vid = 0;
fd = connect_to_sdog(s);
if (fd < 0) {
return -EIO;
}
inode = g_malloc(sizeof(s->inode));
ret = find_vdi_name(s, s->name, snapid, tag, &vid, false);
if (ret) {
goto out;
}
ret = read_object(fd, (char *)inode, vid_to_vdi_oid(vid),
s->inode.nr_copies, sizeof(*inode), 0, s->cache_flags);
if (ret < 0) {
goto out;
}
if (inode->vdi_id != s->inode.vdi_id) {
memcpy(&s->inode, inode, sizeof(s->inode));
}
out:
g_free(inode);
closesocket(fd);
return ret;
}
/* TODO Convert to fine grained options */ /* TODO Convert to fine grained options */
static QemuOptsList runtime_opts = { static QemuOptsList runtime_opts = {
.name = "sheepdog", .name = "sheepdog",
...@@ -1905,18 +1941,14 @@ static int sd_snapshot_goto(BlockDriverState *bs, const char *snapshot_id) ...@@ -1905,18 +1941,14 @@ static int sd_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
{ {
BDRVSheepdogState *s = bs->opaque; BDRVSheepdogState *s = bs->opaque;
BDRVSheepdogState *old_s; BDRVSheepdogState *old_s;
char vdi[SD_MAX_VDI_LEN], tag[SD_MAX_VDI_TAG_LEN]; char tag[SD_MAX_VDI_TAG_LEN];
char *buf = NULL;
uint32_t vid;
uint32_t snapid = 0; uint32_t snapid = 0;
int ret = 0, fd; int ret = 0;
old_s = g_malloc(sizeof(BDRVSheepdogState)); old_s = g_malloc(sizeof(BDRVSheepdogState));
memcpy(old_s, s, sizeof(BDRVSheepdogState)); memcpy(old_s, s, sizeof(BDRVSheepdogState));
pstrcpy(vdi, sizeof(vdi), s->name);
snapid = strtoul(snapshot_id, NULL, 10); snapid = strtoul(snapshot_id, NULL, 10);
if (snapid) { if (snapid) {
tag[0] = 0; tag[0] = 0;
...@@ -1924,30 +1956,11 @@ static int sd_snapshot_goto(BlockDriverState *bs, const char *snapshot_id) ...@@ -1924,30 +1956,11 @@ static int sd_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
pstrcpy(tag, sizeof(tag), s->name); pstrcpy(tag, sizeof(tag), s->name);
} }
ret = find_vdi_name(s, vdi, snapid, tag, &vid, false); ret = reload_inode(s, snapid, tag);
if (ret) { if (ret) {
error_report("Failed to find_vdi_name");
goto out; goto out;
} }
fd = connect_to_sdog(s);
if (fd < 0) {
ret = fd;
goto out;
}
buf = g_malloc(SD_INODE_SIZE);
ret = read_object(fd, buf, vid_to_vdi_oid(vid), s->inode.nr_copies,
SD_INODE_SIZE, 0, s->cache_flags);
closesocket(fd);
if (ret) {
goto out;
}
memcpy(&s->inode, buf, sizeof(s->inode));
if (!s->inode.vm_state_size) { if (!s->inode.vm_state_size) {
error_report("Invalid snapshot"); error_report("Invalid snapshot");
ret = -ENOENT; ret = -ENOENT;
...@@ -1956,14 +1969,12 @@ static int sd_snapshot_goto(BlockDriverState *bs, const char *snapshot_id) ...@@ -1956,14 +1969,12 @@ static int sd_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
s->is_snapshot = true; s->is_snapshot = true;
g_free(buf);
g_free(old_s); g_free(old_s);
return 0; return 0;
out: out:
/* recover bdrv_sd_state */ /* recover bdrv_sd_state */
memcpy(s, old_s, sizeof(BDRVSheepdogState)); memcpy(s, old_s, sizeof(BDRVSheepdogState));
g_free(buf);
g_free(old_s); g_free(old_s);
error_report("failed to open. recover old bdrv_sd_state."); error_report("failed to open. recover old bdrv_sd_state.");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册