[Sheepdog] [PATCH v4 11/12] trace: add a new interface for trace utility
Liu Yuan
namei.unix at gmail.com
Tue Apr 10 09:02:06 CEST 2012
From: Liu Yuan <tailai.ly at taobao.com>
usage:
collie/collie debug trace start #start tracing sheep
collie/collie debug trace stop #stop tracing sheep
Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
collie/Makefile.am | 6 ++++
collie/collie.c | 1 +
collie/collie.h | 1 +
collie/debug.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++
include/sheep.h | 1 +
sheep/ops.c | 19 +++++++++++++
6 files changed, 101 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..5a2dc82 100644
--- a/collie/collie.c
+++ b/collie/collie.c
@@ -287,6 +287,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..1c6ce9d
--- /dev/null
+++ b/collie/debug.c
@@ -0,0 +1,73 @@
+#include <ctype.h>
+
+#include "collie.h"
+
+static int debug_trace(int argc, char **argv)
+{
+ int fd, ret, i, l;
+ struct sd_req hdr;
+ struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
+ unsigned rlen, wlen;
+ char *cmd = argv[optind];
+ int enabled;
+
+ l = strlen(cmd);
+ for (i = 0; i < l; i++)
+ cmd[i] = tolower(cmd[i]);
+
+ if (strcmp(cmd, "start") == 0) {
+ enabled = 1;
+ printf("start the tracing\n");
+ } else if (strcmp(cmd, "stop") == 0) {
+ enabled = 0;
+ printf("stop the tracing\n");
+ } else {
+ printf("unsupported operation\n");
+ return EXIT_FAILURE;
+ }
+
+ 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 = enabled;
+
+ 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)
+{
+ return 0;
+}
+
+static struct subcommand debug_cmd[] = {
+ {"trace", "{start, stop, cat}", "aph", "trace the node",
+ 0, debug_trace},
+ {NULL,},
+};
+
+struct command debug_command = {
+ "debug",
+ debug_cmd,
+ debug_parser
+};
diff --git a/include/sheep.h b/include/sheep.h
index 7fdb532..3362759 100644
--- a/include/sheep.h
+++ b/include/sheep.h
@@ -43,6 +43,7 @@
#define SD_OP_RESTORE 0x92
#define SD_OP_GET_SNAP_FILE 0x93
#define SD_OP_CLEANUP 0x94
+#define SD_OP_TRACE 0x95
#define SD_FLAG_CMD_IO_LOCAL 0x0010
#define SD_FLAG_CMD_RECOVERY 0x0020
diff --git a/sheep/ops.c b/sheep/ops.c
index 9107a27..20d114c 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;
@@ -517,6 +518,18 @@ static int local_flush_vdi(const struct sd_req *req, struct sd_rsp *rsp, void *d
return SD_RES_SUCCESS;
}
+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 */
@@ -642,6 +655,12 @@ static struct sd_op_template sd_ops[] = {
.process_work = local_flush_vdi,
},
+ [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
More information about the sheepdog
mailing list