[sheepdog] [PATCH 2/4] trace: run trace cat as a worker

Liu Yuan namei.unix at gmail.com
Sat Sep 1 17:26:16 CEST 2012


From: Liu Yuan <tailai.ly at taobao.com>

The subtle case is that when tracer is in patching, we should return AGAIN to
buffer reader to ask him to try again until patching is down.

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 collie/debug.c           |  3 +++
 include/sheepdog_proto.h |  1 +
 sheep/ops.c              | 15 +++++++++++----
 sheep/trace/trace.c      |  7 +++++--
 sheep/trace/trace.h      |  4 ++--
 5 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/collie/debug.c b/collie/debug.c
index c40d164..6dbd768 100644
--- a/collie/debug.c
+++ b/collie/debug.c
@@ -110,6 +110,9 @@ read_buffer:
 		return EXIT_SYSFAIL;
 	}
 
+	if (rsp->result == SD_RES_AGAIN)
+		goto read_buffer;
+
 	if (rsp->result != SD_RES_SUCCESS) {
 		fprintf(stderr, "Trace failed: %s\n",
 				sd_strerror(rsp->result));
diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h
index 2859844..75c6126 100644
--- a/include/sheepdog_proto.h
+++ b/include/sheepdog_proto.h
@@ -69,6 +69,7 @@
 #define SD_RES_OBJ_RECOVERING     0x23 /* Object is recovering */
 #define SD_RES_KILLED           0x24 /* Node is killed */
 #define SD_RES_OID_EXIST        0x25 /* Object ID exists already */
+#define SD_RES_AGAIN            0x26 /* Ask to try again */
 
 /* errors above 0x80 are sheepdog-internal */
 
diff --git a/sheep/ops.c b/sheep/ops.c
index b4fa77f..465d73f 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -674,10 +674,17 @@ static int local_trace_ops(const struct sd_req *req, struct sd_rsp *rsp, void *d
 	return ret;
 }
 
-static int local_trace_read_buf(const struct sd_req *req, struct sd_rsp *rsp,
-			       void *data)
+static int local_trace_read_buf(struct request *request)
 {
-	rsp->data_length = trace_buffer_pop(data, req->data_length);
+	struct sd_req *req = &request->rq;
+	struct sd_rsp *rsp = &request->rp;
+	int ret;
+
+	ret = trace_buffer_pop(request->data, req->data_length);
+	if (ret == -1)
+		return SD_RES_AGAIN;
+
+	rsp->data_length = ret;
 	dprintf("%u\n", rsp->data_length);
 	return SD_RES_SUCCESS;
 }
@@ -1090,7 +1097,7 @@ static struct sd_op_template sd_ops[] = {
 		.name = "TRACE_READ_BUF",
 		.type = SD_OP_TYPE_LOCAL,
 		.force = 1,
-		.process_main = local_trace_read_buf,
+		.process_work = local_trace_read_buf,
 	},
 
 	[SD_OP_KILL_NODE] = {
diff --git a/sheep/trace/trace.c b/sheep/trace/trace.c
index a906d6b..79868b7 100644
--- a/sheep/trace/trace.c
+++ b/sheep/trace/trace.c
@@ -299,12 +299,15 @@ int trace_init_signal(void)
 	return 0;
 }
 
-notrace uint32_t trace_buffer_pop(void *buf, uint32_t len)
+notrace int trace_buffer_pop(void *buf, uint32_t len)
 {
-	uint32_t readin, count = 0, requested = len;
+	int readin, count = 0, requested = len;
 	char *buff = (char *)buf;
 	int i;
 
+	if (trace_in_patch)
+		return -1;
+
 	for (i = 0; i < nr_cpu; i++) {
 		readin = strbuf_stripout(&buffer[i], buff, len);
 		count += readin;
diff --git a/sheep/trace/trace.h b/sheep/trace/trace.h
index fa8eb05..cdeb2a1 100644
--- a/sheep/trace/trace.h
+++ b/sheep/trace/trace.h
@@ -55,7 +55,7 @@ extern unsigned long trace_return_call(void);
   extern int trace_enable(void);
   extern int trace_disable(void);
   extern struct caller *trace_lookup_ip(unsigned long ip, int create);
-  extern uint32_t trace_buffer_pop(void *buf, uint32_t len);
+  extern int trace_buffer_pop(void *buf, uint32_t len);
   extern void trace_buffer_push(int cpuid, struct trace_graph_item *item);
   extern void short_thread_begin(void);
   extern void short_thread_end(void);
@@ -64,7 +64,7 @@ extern unsigned long trace_return_call(void);
   static inline int trace_init(void) { return 0; }
   static inline int trace_enable(void) { return 0; }
   static inline int trace_disable(void) { return 0; }
-  static inline uint32_t trace_buffer_pop(void *buf, uint32_t len) { return 0; }
+  static inline int trace_buffer_pop(void *buf, uint32_t len) { return 0; }
   static inline void trace_buffer_push(int cpuid, struct
 				       trace_graph_item *item) { return; }
   static inline void short_thread_begin(void) { return; }
-- 
1.7.12.84.gefa6462




More information about the sheepdog mailing list