[sheepdog] [PATCH v3 02/10] collie: add -c for 'collie vdi create' to specify redundancy level for per-vdi
levin li
levin108 at gmail.com
Tue Aug 7 13:20:49 CEST 2012
From: levin li <xingke.lwp at taobao.com>
Signed-off-by: levin li <xingke.lwp at taobao.com>
---
collie/vdi.c | 27 ++++++++++++++++++++-------
sheep/ops.c | 9 ++++++---
2 files changed, 26 insertions(+), 10 deletions(-)
diff --git a/collie/vdi.c b/collie/vdi.c
index e4f4f65..4c793c9 100644
--- a/collie/vdi.c
+++ b/collie/vdi.c
@@ -23,6 +23,7 @@ struct vdi_cmd_data {
int exclusive;
int delete;
int prealloc;
+ int nr_copies;
} vdi_cmd_data = { ~0, };
struct get_vdi_info {
@@ -399,7 +400,7 @@ out:
}
static int do_vdi_create(char *vdiname, int64_t vdi_size, uint32_t base_vid,
- uint32_t *vdi_id, int snapshot)
+ uint32_t *vdi_id, int snapshot, int nr_copies)
{
struct sd_req hdr;
struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
@@ -425,6 +426,7 @@ static int do_vdi_create(char *vdiname, int64_t vdi_size, uint32_t base_vid,
hdr.vdi.base_vdi_id = base_vid;
hdr.vdi.snapid = snapshot;
hdr.vdi.vdi_size = roundup(vdi_size, 512);
+ hdr.vdi.copies = nr_copies;
ret = exec_req(fd, &hdr, buf, &wlen, &rlen);
@@ -469,7 +471,7 @@ static int vdi_create(int argc, char **argv)
return EXIT_USAGE;
}
- ret = do_vdi_create(vdiname, size, 0, &vid, 0);
+ ret = do_vdi_create(vdiname, size, 0, &vid, 0, vdi_cmd_data.nr_copies);
if (ret != EXIT_SUCCESS || !vdi_cmd_data.prealloc)
goto out;
@@ -548,7 +550,8 @@ static int vdi_snapshot(int argc, char **argv)
0, inode->nr_copies, 0);
}
- return do_vdi_create(vdiname, inode->vdi_size, vid, NULL, 1);
+ return do_vdi_create(vdiname, inode->vdi_size, vid, NULL, 1,
+ vdi_cmd_data.nr_copies);
}
static int vdi_clone(int argc, char **argv)
@@ -595,7 +598,8 @@ static int vdi_clone(int argc, char **argv)
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, 0,
+ vdi_cmd_data.nr_copies);
if (ret != EXIT_SUCCESS || !vdi_cmd_data.prealloc)
goto out;
@@ -1479,11 +1483,11 @@ out:
static struct subcommand vdi_cmd[] = {
{"check", "<vdiname>", "saph", "check and repair image's consistency",
NULL, SUBCMD_FLAG_NEED_NODELIST|SUBCMD_FLAG_NEED_THIRD_ARG, vdi_check},
- {"create", "<vdiname> <size>", "Paph", "create an image",
+ {"create", "<vdiname> <size>", "Pcaph", "create an image",
NULL, SUBCMD_FLAG_NEED_NODELIST|SUBCMD_FLAG_NEED_THIRD_ARG, vdi_create},
- {"snapshot", "<vdiname>", "saph", "create a snapshot",
+ {"snapshot", "<vdiname>", "scaph", "create a snapshot",
NULL, SUBCMD_FLAG_NEED_NODELIST|SUBCMD_FLAG_NEED_THIRD_ARG, vdi_snapshot},
- {"clone", "<src vdi> <dst vdi>", "sPaph", "clone an image",
+ {"clone", "<src vdi> <dst vdi>", "sPcaph", "clone an image",
NULL, SUBCMD_FLAG_NEED_NODELIST|SUBCMD_FLAG_NEED_THIRD_ARG, vdi_clone},
{"delete", "<vdiname>", "saph", "delete an image",
NULL, SUBCMD_FLAG_NEED_NODELIST|SUBCMD_FLAG_NEED_THIRD_ARG, vdi_delete},
@@ -1513,6 +1517,7 @@ static struct subcommand vdi_cmd[] = {
static int vdi_parser(int ch, char *opt)
{
char *p;
+ int nr_copies;
switch (ch) {
case 'P':
@@ -1539,6 +1544,14 @@ static int vdi_parser(int ch, char *opt)
case 'd':
vdi_cmd_data.delete = 1;
break;
+ case 'c':
+ nr_copies = strtol(opt, &p, 10);
+ if (opt == p || nr_copies < 0 || nr_copies > SD_MAX_COPIES) {
+ fprintf(stderr, "Invalid copies number, must be "
+ "an integer between 0 and %d\n", SD_MAX_COPIES);
+ exit(EXIT_FAILURE);
+ }
+ vdi_cmd_data.nr_copies = nr_copies;
}
return 0;
diff --git a/sheep/ops.c b/sheep/ops.c
index 8793c8d..062a7b4 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -112,7 +112,7 @@ static int cluster_new_vdi(struct request *req)
{
const struct sd_req *hdr = &req->rq;
struct sd_rsp *rsp = &req->rp;
- uint32_t vid = 0, nr_copies = sys->nr_copies;
+ uint32_t vid = 0;
struct vdi_iocb iocb;
int ret;
@@ -121,12 +121,15 @@ static int cluster_new_vdi(struct request *req)
iocb.size = hdr->vdi.vdi_size;
iocb.base_vid = hdr->vdi.base_vdi_id;
iocb.is_snapshot = hdr->vdi.snapid;
- iocb.nr_copies = sys->nr_copies;
+ iocb.nr_copies = hdr->vdi.copies;
+
+ if (!iocb.nr_copies)
+ iocb.nr_copies = SD_DEFAULT_COPIES;
ret = add_vdi(&iocb, &vid);
rsp->vdi.vdi_id = vid;
- rsp->vdi.copies = nr_copies;
+ rsp->vdi.copies = iocb.nr_copies;
return ret;
}
--
1.7.1
More information about the sheepdog
mailing list