[sheepdog] [PATCH 1/3] use req->vdi.snapid to specify whether snapshot is created or not
MORITA Kazutaka
morita.kazutaka at lab.ntt.co.jp
Tue Oct 16 20:04:25 CEST 2012
SD_OP_NEW_VDI operation uses req->vdi.snapid only to check whether
sheep should create a snapshot or not, so setting req->vdi.snapid to
snapshot id is wrong. This patch uses a boolean variable for it
instead.
Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
collie/vdi.c | 20 ++++++++++----------
sheep/ops.c | 2 +-
sheep/sheep_priv.h | 2 +-
sheep/vdi.c | 10 +++++-----
4 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/collie/vdi.c b/collie/vdi.c
index e0581b8..9dc15e1 100644
--- a/collie/vdi.c
+++ b/collie/vdi.c
@@ -453,7 +453,7 @@ static int read_vdi_obj(char *vdiname, int snapid, const char *tag,
}
static int do_vdi_create(char *vdiname, int64_t vdi_size, uint32_t base_vid,
- uint32_t *vdi_id, int snapshot, int nr_copies)
+ uint32_t *vdi_id, bool snapshot, int nr_copies)
{
struct sd_req hdr;
struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
@@ -477,7 +477,7 @@ static int do_vdi_create(char *vdiname, int64_t vdi_size, uint32_t base_vid,
hdr.data_length = wlen;
hdr.vdi.base_vdi_id = base_vid;
- hdr.vdi.snapid = snapshot;
+ hdr.vdi.snapid = snapshot ? 1 : 0;
hdr.vdi.vdi_size = roundup(vdi_size, 512);
hdr.vdi.copies = nr_copies;
@@ -524,7 +524,8 @@ static int vdi_create(int argc, char **argv)
return EXIT_USAGE;
}
- ret = do_vdi_create(vdiname, size, 0, &vid, 0, vdi_cmd_data.nr_copies);
+ ret = do_vdi_create(vdiname, size, 0, &vid, false,
+ vdi_cmd_data.nr_copies);
if (ret != EXIT_SUCCESS || !vdi_cmd_data.prealloc)
goto out;
@@ -595,7 +596,7 @@ static int vdi_snapshot(int argc, char **argv)
0, inode->nr_copies, false, true);
}
- return do_vdi_create(vdiname, inode->vdi_size, vid, NULL, 1,
+ return do_vdi_create(vdiname, inode->vdi_size, vid, NULL, true,
inode->nr_copies);
}
@@ -635,7 +636,7 @@ static int vdi_clone(int argc, char **argv)
if (ret != EXIT_SUCCESS)
goto out;
- ret = do_vdi_create(dst_vdi, inode->vdi_size, base_vid, &new_vid, 0,
+ ret = do_vdi_create(dst_vdi, inode->vdi_size, base_vid, &new_vid, false,
vdi_cmd_data.nr_copies);
if (ret != EXIT_SUCCESS || !vdi_cmd_data.prealloc)
goto out;
@@ -802,7 +803,7 @@ static int vdi_rollback(int argc, char **argv)
}
return do_vdi_create(vdiname, inode->vdi_size, base_vid, NULL,
- inode->snap_id, vdi_cmd_data.nr_copies);
+ true, vdi_cmd_data.nr_copies);
}
static int vdi_object(int argc, char **argv)
@@ -1752,8 +1753,8 @@ static uint32_t do_restore(char *vdiname, int snapid, const char *tag)
if (ret != EXIT_SUCCESS)
goto out;
- ret = do_vdi_create(vdiname, inode->vdi_size, inode->vdi_id, &vid, 1,
- inode->nr_copies);
+ ret = do_vdi_create(vdiname, inode->vdi_size, inode->vdi_id, &vid,
+ true, inode->nr_copies);
if (ret != EXIT_SUCCESS) {
fprintf(stderr, "Failed to read VDI\n");
goto out;
@@ -1843,8 +1844,7 @@ out:
/* recreate the current vdi object */
recovery_ret = do_vdi_create(vdiname, current_inode->vdi_size,
current_inode->parent_vdi_id, NULL,
- parent_inode->snap_id,
- current_inode->nr_copies);
+ true, current_inode->nr_copies);
if (recovery_ret != EXIT_SUCCESS) {
fprintf(stderr, "failed to resume the current vdi\n");
ret = recovery_ret;
diff --git a/sheep/ops.c b/sheep/ops.c
index df4831b..1e2539c 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -116,7 +116,7 @@ static int cluster_new_vdi(struct request *req)
iocb.data_len = hdr->data_length;
iocb.size = hdr->vdi.vdi_size;
iocb.base_vid = hdr->vdi.base_vdi_id;
- iocb.snapid = hdr->vdi.snapid;
+ iocb.create_snapshot = !!hdr->vdi.snapid;
iocb.nr_copies = hdr->vdi.copies;
if (!iocb.nr_copies)
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 7ed5130..d308751 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -140,7 +140,7 @@ struct vdi_iocb {
uint32_t data_len;
uint64_t size;
uint32_t base_vid;
- int snapid;
+ bool create_snapshot;
int nr_copies;
};
diff --git a/sheep/vdi.c b/sheep/vdi.c
index 2177b24..3ac0f12 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -217,7 +217,7 @@ static int create_vdi_obj(struct vdi_iocb *iocb, uint32_t new_vid,
}
}
- if (iocb->snapid && cur_vid != iocb->base_vid) {
+ if (iocb->create_snapshot && cur_vid != iocb->base_vid) {
cur = zalloc(SD_INODE_HEADER_SIZE);
if (!cur) {
eprintf("failed to allocate memory\n");
@@ -236,7 +236,7 @@ static int create_vdi_obj(struct vdi_iocb *iocb, uint32_t new_vid,
gettimeofday(&tv, NULL);
- if (iocb->snapid) {
+ if (iocb->create_snapshot) {
if (cur_vid != iocb->base_vid) {
vprintf(SDOG_INFO, "tree snapshot %s %" PRIx32 " %" PRIx32 "\n",
name, cur_vid, iocb->base_vid);
@@ -282,7 +282,7 @@ static int create_vdi_obj(struct vdi_iocb *iocb, uint32_t new_vid,
}
}
- if (iocb->snapid && cur_vid != iocb->base_vid) {
+ if (iocb->create_snapshot && cur_vid != iocb->base_vid) {
ret = write_object(vid_to_vdi_oid(cur_vid), (char *)cur,
SD_INODE_HEADER_SIZE, 0, 0, false, 0);
if (ret != 0) {
@@ -453,7 +453,7 @@ int add_vdi(struct vdi_iocb *iocb, uint32_t *new_vid)
NULL, 0, &next_snapid, &right_nr, &deleted_nr,
&dummy, NULL);
- if (iocb->snapid) {
+ if (iocb->create_snapshot) {
if (ret != SD_RES_SUCCESS) {
if (ret == SD_RES_NO_VDI)
vprintf(SDOG_CRIT, "VDI %s does not exist\n", name);
@@ -480,7 +480,7 @@ int add_vdi(struct vdi_iocb *iocb, uint32_t *new_vid)
vprintf(SDOG_INFO, "creating new %s %s: size %" PRIu64 ", vid %"
PRIx32 ", base %" PRIx32 ", cur %" PRIx32 ", copies %d\n",
- iocb->snapid ? "snapshot" : "vdi", name, iocb->size,
+ iocb->create_snapshot ? "snapshot" : "vdi", name, iocb->size,
*new_vid, iocb->base_vid, cur_vid, iocb->nr_copies);
return create_vdi_obj(iocb, *new_vid, cur_vid, next_snapid);
--
1.7.2.5
More information about the sheepdog
mailing list