Commit 5af1fb4e authored by Filippos Giannakos's avatar Filippos Giannakos

Merge branch 'feature-snapshot' into xseg-refactor

parents d3fd3049 12ca4a56
......@@ -67,7 +67,8 @@ xseg: xseg-tool.c $(BASE)/xseg/xseg.h
$(CC) $(CFLAGS) -o $@ $< $(BASE)/xtypes/xheap.c $(INC) -L$(LIB) -lxseg
mt-sosd: mt-sosd.c peer.c peer.h
$(CC) $(CFLAGS) -o $@ $< peer.c $(INC) -L$(LIB) -lxseg -lrados -lpthread -DMT
$(CC) $(CFLAGS) -o $@ $< peer.c $(INC) -L$(LIB) -lxseg -lrados -lpthread \
-lcrypto -DMT
dummy: dummy.c peer.c peer.h
$(CC) $(CFLAGS) -o $@ $< peer.c $(INC) -L$(LIB) -lxseg -lpthread -DMT
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -98,7 +98,8 @@ struct xseg_config cfg;
xport srcport = NoPort;
xport sport = NoPort;
struct xseg_port *port;
xport mportno;
xport mportno = NoPort;
xport vportno = NoPort;
static void init_local_signal()
{
......@@ -193,7 +194,52 @@ int vlmc_create(char *name, uint64_t size, char *snap)
int vlmc_snapshot(char *name)
{
return -1;
int targetlen = safe_strlen(name);
if (targetlen <= 0) {
fprintf(stderr, "Invalid name\n");
return -1;
}
struct xseg_request *req = xseg_get_request(xseg, srcport, vportno, X_ALLOC);
if (!req) {
fprintf(stderr, "Couldn't allocate xseg request\n");
return -1;
}
int r = xseg_prep_request(xseg, req, targetlen, sizeof(struct xseg_request_snapshot));
if (r < 0){
fprintf(stderr, "Couldn't prep xseg request\n");
xseg_put_request(xseg, req, srcport);
return -1;
}
char *target = xseg_get_target(xseg, req);
strncpy(target, name, targetlen);
struct xseg_request_snapshot *xsnapshot = (struct xseg_request_snapshot *) xseg_get_data(xseg, req);
xsnapshot->target[0] = 0;
xsnapshot->targetlen = 0;
req->offset = 0;
req->size = req->datalen;
req->op = X_SNAPSHOT;
xport p = xseg_submit(xseg, req, srcport, X_ALLOC);
if (p == NoPort){
fprintf(stderr, "couldn't submit req\n");
xseg_put_request(xseg, req, srcport);
return -1;
}
xseg_signal(xseg, p);
r = wait_reply(req);
if (!r){
struct xseg_reply_snapshot *xreply = (struct xseg_reply_snapshot *) xseg_get_data(xseg, req);
char buf[XSEG_MAX_TARGETLEN + 1];
strncpy(buf, xreply->target, xreply->targetlen);
buf[xreply->targetlen] = 0;
fprintf(stdout, "Snapshot name: %s\n", buf);
}
xseg_put_request(xseg, req, srcport);
return r;
}
int vlmc_remove(char *name)
......@@ -356,6 +402,13 @@ int main(int argc, char *argv[])
mportno = atol(argv[i+1]);
i++;
}
} else if (!strcmp(argv[i], "-vp") && i+1 < argc){
if (!validate_numeric(argv[i+1])){
err_in_arg(i, argv[i]);
} else {
vportno = atol(argv[i+1]);
i++;
}
} else if (!strcmp(argv[i], "-p") && i+1 < argc){
if (!validate_alphanumeric(argv[i+1])){
err_in_arg(i, argv[i]);
......@@ -375,7 +428,7 @@ int main(int argc, char *argv[])
}
}
if (srcport > cfg.nr_ports || mportno > cfg.nr_ports) {
if (srcport > cfg.nr_ports || mportno > cfg.nr_ports || vportno > cfg.nr_ports) {
fprintf(stderr, "Invalid port\n");
return -1;
}
......@@ -404,6 +457,8 @@ int main(int argc, char *argv[])
*/
else if (!strcmp(argv[2], "resize"))
ret = vlmc_resize(name, size);
else if (!strcmp(argv[2], "snapshot"))
ret = vlmc_snapshot(name);
else
fprintf(stderr, "unknown action (%s)\n", argv[2]);
......
......@@ -581,6 +581,48 @@ int cmd_clone(char *src, char *dst)
return 0;
}
int cmd_snapshot(char *src, char *dst, long block_size)
{
uint32_t targetlen = strlen(src);
uint32_t parentlen = strlen(dst);
struct xseg_request *req;
struct xseg_request_snapshot *xsnapshot;
xseg_bind_port(xseg, srcport, NULL);
req = xseg_get_request(xseg, srcport, dstport, X_ALLOC);
if (!req) {
fprintf(stderr, "No request\n");
return -1;
}
int r = xseg_prep_request(xseg, req, targetlen, sizeof(struct xseg_request_snapshot));
if (r < 0) {
fprintf(stderr, "Cannot prepare request!\n");
xseg_put_request(xseg, req, srcport);
return -1;
}
char *target = xseg_get_target(xseg, req);
char *data = xseg_get_data(xseg, req);
strncpy(target, src, targetlen);
xsnapshot = (struct xseg_request_snapshot *) data;
strncpy(xsnapshot->target, dst, parentlen);
xsnapshot->targetlen = parentlen;
req->offset = 0;
req->size = (uint64_t) block_size;
req->op = X_SNAPSHOT;
xport p = xseg_submit(xseg, req, srcport, X_ALLOC);
if (p == NoPort){
fprintf(stderr, "Cannot submit request\n");
return -1;
}
xseg_signal(xseg, p);
return 0;
}
void log_req(int logfd, uint32_t portno2, uint32_t portno1, int op, int method,
struct xseg_request *req)
{
......@@ -1626,9 +1668,13 @@ void handle_reply(struct xseg_request *req)
break;
case X_CLOSE:
fprintf(stderr, "Closed %s\n", req_target);
break;
case X_OPEN:
fprintf(stderr, "Opened %s\n", req_target);
break;
case X_SNAPSHOT:
fprintf(stderr, "Snapshotted %s\n", req_target);
break;
default:
break;
}
......@@ -2010,6 +2056,13 @@ int main(int argc, char **argv)
i += 2;
continue;
}
if (!strcmp(argv[i], "snapshot") && (i + 2 < argc)) {
char *src = argv[i+1];
char *dst = argv[i+2];
ret = cmd_snapshot(src, dst, 4096*1024);
i += 2;
continue;
}
if (!strcmp(argv[i], "info") && (i + 1 < argc)) {
char *target = argv[i+1];
......
......@@ -688,6 +688,7 @@ def vlmc_create(args):
if size != None:
cmd.extend(["--size", "%s" % size])
cmd.extend(["-mp", "%s" % MPORT])
cmd.extend(["-vp", "%s" % VPORT_START])
cmd.extend(["-p", "%s" % VTOOL])
try:
......@@ -699,6 +700,22 @@ def vlmc_create(args):
def vlmc_snapshot(args):
# snapshot
name = args.name[0]
if len(name) < 6:
print >> sys.stderr, "Name should have at least len 6"
sys.exit(-1)
cmd = ["vlmc-xseg", "%s" % SPEC, "snapshot", "--name", "%s" % name]
cmd.extend(["-mp", "%s" % MPORT])
cmd.extend(["-vp", "%s" % VPORT_START])
cmd.extend(["-p", "%s" % VTOOL])
try:
check_call(cmd, shell=False, env=os.environ);
except Exception:
sys.stderr.write("vlmc snapshot failed\n")
sys.exit(-1)
return
def vlmc_list(args):
......@@ -737,6 +754,7 @@ def vlmc_remove(args):
cmd = ["vlmc-xseg", "%s" % SPEC, "remove", "--name", "%s" % name]
cmd.extend(["-mp", "%s" % MPORT])
cmd.extend(["-vp", "%s" % VPORT_START])
cmd.extend(["-p", "%s" % VTOOL])
try:
......@@ -883,6 +901,12 @@ def vlmc():
list_parser.set_defaults(func=vlmc_list)
list_parser.add_argument('-p', '--pool', type=str, nargs='?', help='for backwards compatiblity with rbd')
snapshot_parser = subparsers.add_parser('snapshot', help='snapshot volume')
#group = snapshot_parser.add_mutually_exclusive_group(required=True)
snapshot_parser.add_argument('-p', '--pool', type=str, nargs='?', help='for backwards compatiblity with rbd')
snapshot_parser.add_argument('name', type=str, nargs=1, help='volume/device name')
snapshot_parser.set_defaults(func=vlmc_snapshot)
ls_parser = subparsers.add_parser('ls', help='List volumes')
ls_parser.set_defaults(func=vlmc_list)
ls_parser.add_argument('-p', '--pool', type=str, nargs='?', help='for backwards compatiblity with rbd')
......
......@@ -81,5 +81,14 @@ struct xseg_request_copy {
uint32_t targetlen;
};
struct xseg_request_snapshot {
char target[XSEG_MAX_TARGETLEN];
uint32_t targetlen;
};
struct xseg_reply_snapshot {
char target[XSEG_MAX_TARGETLEN];
uint32_t targetlen;
};
#endif
......@@ -224,6 +224,7 @@ struct xseg_task {
#define X_MAPW 13
#define X_OPEN 14
#define X_CLOSE 15
#define X_SNAPSHOT 16
/* FLAGS */
#define XF_NOSYNC (1 << 0)
......
......@@ -449,7 +449,7 @@ xqindex __xq_resize(struct xq *xq, struct xq *newxq)
val = XPTR(&xq->queue)[(head + i) & mask];
XPTR(&newxq->queue)[(tail - i) & mask_new] = val;
}
return nr;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment