From: Liu Yuan <tailai.ly at taobao.com> Signed-off-by: Liu Yuan <tailai.ly at taobao.com> --- collie/Makefile.am | 6 ++++ collie/collie.c | 5 ++++ collie/collie.h | 1 + collie/debug.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ include/sheep.h | 1 + sheep/ops.c | 19 ++++++++++++++ 6 files changed, 99 insertions(+), 0 deletions(-) create mode 100644 collie/debug.c diff --git a/collie/Makefile.am b/collie/Makefile.am index 477b150..d98b709 100644 --- a/collie/Makefile.am +++ b/collie/Makefile.am @@ -24,6 +24,12 @@ INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include sbin_PROGRAMS = collie collie_SOURCES = collie.c common.c treeview.c vdi.c node.c cluster.c + +if BUILD_TRACE +collie_SOURCES += debug.c +override CFLAGS := $(subst -pg -gstabs,,$(CFLAGS)) +endif + collie_LDADD = ../lib/libsheepdog.a collie_DEPENDENCIES = ../lib/libsheepdog.a diff --git a/collie/collie.c b/collie/collie.c index 7989bb2..6215349 100644 --- a/collie/collie.c +++ b/collie/collie.c @@ -48,6 +48,10 @@ static const struct sd_option collie_options[] = { {'R', "restore", 1, "restore the cluster"}, {'l', "list", 0, "list the user epoch information"}, + /* debug options */ + {'e', "begin", 0, "begin tracing"}, + {'t', "stop", 0, "stop tracing"}, + { 0, NULL, 0, NULL }, }; @@ -287,6 +291,7 @@ int main(int argc, char **argv) vdi_command, node_command, cluster_command, + debug_command, {NULL,} }; diff --git a/collie/collie.h b/collie/collie.h index 85a1289..53cc48d 100644 --- a/collie/collie.h +++ b/collie/collie.h @@ -73,5 +73,6 @@ int sd_write_object(uint64_t oid, uint64_t cow_oid, void *data, unsigned int dat extern struct command vdi_command; extern struct command node_command; extern struct command cluster_command; +extern struct command debug_command; #endif diff --git a/collie/debug.c b/collie/debug.c new file mode 100644 index 0000000..2fbda2d --- /dev/null +++ b/collie/debug.c @@ -0,0 +1,67 @@ +#include "collie.h" + +struct debug_cmd_data { + int t_enable; +} debug_cmd_data; + +static int debug_trace(int argc, char **argv) +{ + int fd, ret; + struct sd_req hdr; + struct sd_rsp *rsp = (struct sd_rsp *)&hdr; + unsigned rlen, wlen; + + fd = connect_to(sdhost, sdport); + if (fd < 0) + return EXIT_SYSFAIL; + + memset(&hdr, 0, sizeof(hdr)); + + hdr.opcode = SD_OP_TRACE; + hdr.epoch = node_list_version; + hdr.data_length = debug_cmd_data.t_enable; + + rlen = 0; + wlen = 0; + ret = exec_req(fd, &hdr, NULL, &wlen, &rlen); + close(fd); + + if (ret) { + fprintf(stderr, "Failed to connect\n"); + return EXIT_SYSFAIL; + } + + if (rsp->result != SD_RES_SUCCESS) { + fprintf(stderr, "Trace failed: %s\n", + sd_strerror(rsp->result)); + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} + +static int debug_parser(int ch, char *opt) +{ + switch (ch) { + case 'e': + debug_cmd_data.t_enable = 1; + break; + case 't': + debug_cmd_data.t_enable = 0; + break; + } + + return 0; +} + +static struct subcommand debug_cmd[] = { + {"trace", NULL, "etaprh", "debug the cluster", + 0, debug_trace}, + {NULL,}, +}; + +struct command debug_command = { + "debug", + debug_cmd, + debug_parser +}; diff --git a/include/sheep.h b/include/sheep.h index fc86c25..a3de178 100644 --- a/include/sheep.h +++ b/include/sheep.h @@ -42,6 +42,7 @@ #define SD_OP_SNAPSHOT 0x91 #define SD_OP_RESTORE 0x92 #define SD_OP_GET_SNAP_FILE 0x93 +#define SD_OP_TRACE 0x94 #define SD_FLAG_CMD_IO_LOCAL 0x0010 #define SD_FLAG_CMD_RECOVERY 0x0020 diff --git a/sheep/ops.c b/sheep/ops.c index 4a672be..b41962c 100644 --- a/sheep/ops.c +++ b/sheep/ops.c @@ -13,6 +13,7 @@ #include "sheep_priv.h" #include "strbuf.h" +#include "trace/trace.h" extern char *obj_path; extern struct store_driver *sd_store; @@ -454,6 +455,18 @@ static int local_get_snap_file(const struct sd_req *req, struct sd_rsp *rsp, return ret; } +static int local_trace_ops(const struct sd_req *req, struct sd_rsp *rsp, void *data) +{ + int enable = req->data_length, ret; + + if (enable) + ret = trace_enable(); + else + ret = trace_disable(); + + return ret; +} + static struct sd_op_template sd_ops[] = { /* cluster operations */ @@ -568,6 +581,12 @@ static struct sd_op_template sd_ops[] = { .process_work = local_get_snap_file, }, + [SD_OP_TRACE] = { + .type = SD_OP_TYPE_LOCAL, + .force = 1, + .process_main = local_trace_ops, + }, + /* I/O operations */ [SD_OP_CREATE_AND_WRITE_OBJ] = { .type = SD_OP_TYPE_IO, -- 1.7.8.2 |