[sheepdog] [PATCH v2 3/6] change method of updating vid in ionde
Robin Dong
robin.k.dong at gmail.com
Tue Oct 15 08:45:37 CEST 2013
Because the 'data_vdi_id' is not array anymore, we can't write each 'vid' into
inode but writing whole inode object.
Signed-off-by: Robin Dong <sanbai at taobao.com>
---
dog/vdi.c | 35 +++++++++++++++++++++++++----------
sheep/ops.c | 17 +++++++++++++++--
sheepfs/volume.c | 8 +++++---
3 files changed, 45 insertions(+), 15 deletions(-)
diff --git a/dog/vdi.c b/dog/vdi.c
index 02267ab..d01e175 100644
--- a/dog/vdi.c
+++ b/dog/vdi.c
@@ -1319,11 +1319,12 @@ static int vdi_write(int argc, char **argv)
}
if (create) {
- ret = sd_write_object(vid_to_vdi_oid(vid), 0, &vid,
- sizeof(vid),
- SD_INODE_HEADER_SIZE + sizeof(vid) * idx,
- flags, inode->nr_copies,
- inode->copy_policy, false, false);
+ ret = sd_write_object(vid_to_vdi_oid(vid), 0,
+ (char *)inode + SD_INODE_HEADER_SIZE,
+ sizeof(uint32_t) * MAX_DATA_OBJS,
+ SD_INODE_HEADER_SIZE,
+ flags, inode->nr_copies,
+ inode->copy_policy, false, false);
if (ret) {
ret = EXIT_FAILURE;
goto out;
@@ -1785,6 +1786,7 @@ static int restore_obj(struct obj_backup *backup, uint32_t vid,
int ret;
uint32_t parent_vid = sd_inode_get_vdi(parent_inode, backup->idx);
uint64_t parent_oid = 0;
+ struct sd_inode *inode = NULL;
if (parent_vid)
parent_oid = vid_to_data_oid(parent_vid, backup->idx);
@@ -1795,12 +1797,25 @@ static int restore_obj(struct obj_backup *backup, uint32_t vid,
0, parent_inode->nr_copies,
parent_inode->copy_policy, true, true);
if (ret != SD_RES_SUCCESS)
- return ret;
+ goto out;
+
+ inode = xmalloc(sizeof(*inode));
+ ret = sd_read_object(vid_to_vdi_oid(vid), inode, sizeof(*inode),
+ 0, true);
+ if (ret != SD_RES_SUCCESS)
+ goto out;
- return sd_write_object(vid_to_vdi_oid(vid), 0, &vid, sizeof(vid),
- SD_INODE_HEADER_SIZE + sizeof(vid) * backup->idx,
- 0, parent_inode->nr_copies,
- parent_inode->copy_policy, false, true);
+ sd_inode_set_vdi(inode, backup->idx, vid);
+ ret = sd_write_object(vid_to_vdi_oid(vid), 0,
+ (char *)inode + SD_INODE_HEADER_SIZE,
+ sizeof(uint32_t) * MAX_DATA_OBJS,
+ SD_INODE_HEADER_SIZE,
+ 0, parent_inode->nr_copies,
+ parent_inode->copy_policy, false, true);
+out:
+ if (inode)
+ free(inode);
+ return ret;
}
static uint32_t do_restore(const char *vdiname, int snapid, const char *tag)
diff --git a/sheep/ops.c b/sheep/ops.c
index 5206faf..0f43e55 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -806,10 +806,23 @@ static int local_discard_obj(struct request *req)
uint64_t oid = req->rq.obj.oid;
uint32_t vid = oid_to_vid(oid), zero = 0;
int ret, idx = data_oid_to_idx(oid);
+ struct sd_inode *inode;
+
+ inode = xmalloc(sizeof(*inode));
sd_debug("%"PRIx64, oid);
- ret = write_object(vid_to_vdi_oid(vid), (char *)&zero, sizeof(zero),
- SD_INODE_HEADER_SIZE + sizeof(vid) * idx, false);
+ ret = read_object(vid_to_vdi_oid(vid), (char *)inode,
+ sizeof(*inode), 0);
+ if (ret != SD_RES_SUCCESS)
+ return ret;
+ sd_inode_set_vdi(inode, idx, zero);
+
+ ret = write_object(vid_to_vdi_oid(vid),
+ (char *)inode + SD_INODE_HEADER_SIZE,
+ sizeof(uint32_t) * MAX_DATA_OBJS,
+ SD_INODE_HEADER_SIZE, false);
+ if (inode)
+ free(inode);
if (ret != SD_RES_SUCCESS)
return ret;
if (remove_object(oid) != SD_RES_SUCCESS)
diff --git a/sheepfs/volume.c b/sheepfs/volume.c
index ab16ada..54e5ad3 100644
--- a/sheepfs/volume.c
+++ b/sheepfs/volume.c
@@ -178,9 +178,11 @@ static int volume_rw_object(char *buf, uint64_t oid, size_t size,
if (create) {
sd_inode_set_vdi(vdi->inode, idx, vid);
/* writeback inode update */
- if (volume_rw_object((char *)&vid, vid_to_vdi_oid(vid),
- sizeof(vid),
- SD_INODE_HEADER_SIZE + sizeof(vid) * idx,
+ if (volume_rw_object((char *)(vdi->inode)
+ + SD_INODE_HEADER_SIZE,
+ vid_to_vdi_oid(vid),
+ sizeof(uint32_t) * MAX_DATA_OBJS,
+ SD_INODE_HEADER_SIZE,
VOLUME_WRITE) < 0)
return -1;
}
--
1.7.1
More information about the sheepdog
mailing list