[ltt-dev] [Patch for ltt-control] lttd try to get trace data with old way if splice faults.

Masahiro Tamori masahiro.tamori at gmail.com
Tue Mar 17 05:53:53 EDT 2009


Hello Mathieu,

This is LTT Control patch.

I use the following version.
LTTV 0.12.12
LTTng 0.110
LTT Control 0.67
Kernles 2.6.29-rc7

The target is ARM RealviewEB.

Best Regards,
Masahiro Tamori


If splice() faults, try to get trace data
with old way.

Signed-off-by: Masahiro.Tamori at gmail.com

---
 lttd/lttd.c |   80 	48 +	32 -	0 !
 1 file changed, 48 insertions(+), 32 deletions(-)

Index: b/lttd/lttd.c
===================================================================
--- a/lttd/lttd.c
+++ b/lttd/lttd.c
@@ -132,6 +132,7 @@ pthread_rwlock_t fd_pairs_lock = PTHREAD

 static char		*trace_name = NULL;
 static char		*channel_name = NULL;
+static int		use_splice = 1;
 static int		daemon_mode = 0;
 static int		append_mode = 0;
 static unsigned long	num_threads = 1;
@@ -450,38 +451,57 @@ int read_subbuffer(struct fd_pair *pair)
 		perror("Reserving sub buffer failed (everything is normal, it is
due to concurrency)");
 		goto get_error;
 	}
-#if 0
-	err = TEMP_FAILURE_RETRY(write(pair->trace,
-				pair->mmap
-					+ (consumed_old & ((pair->n_subbufs * pair->subbuf_size)-1)),
-				pair->subbuf_size));

-	if(err < 0) {
-		ret = errno;
-		perror("Error in writing to file");
-		goto write_error;
-	}
-#endif //0
-	len = pair->subbuf_size;
-	offset = 0;
-	while (len > 0) {
-		printf_verbose("splice chan to pipe offset %lu\n",
-			(unsigned long)offset);
-		ret = splice(pair->channel, &offset, thread_pipe[1], NULL,
-			len, SPLICE_F_MOVE);
-		printf_verbose("splice chan to pipe ret %ld\n", ret);
-		if (ret < 0) {
-			perror("Error in relay splice");
+	if (use_splice == 0) {
+		err = TEMP_FAILURE_RETRY(
+			write(pair->trace, pair->mmap
+			      + (consumed_old & ((pair->n_subbufs * pair->subbuf_size)-1)),
+			      pair->subbuf_size));
+		if(err < 0) {
+			ret = errno;
+			perror("Error in writing to file");
 			goto write_error;
 		}
-		ret = splice(thread_pipe[0], NULL, pair->trace, NULL,
-			ret, SPLICE_F_MOVE);
-		printf_verbose("splice pipe to file %ld\n", ret);
-		if (ret < 0) {
-			perror("Error in file splice");
-			goto write_error;
+	}
+	else {
+		 len = pair->subbuf_size;
+		 offset = 0;
+		while (len > 0) {
+			printf_verbose("splice chan to pipe offset %lu\n",
+				       (unsigned long)offset);
+			ret = splice(pair->channel, &offset, thread_pipe[1], NULL,
+				     len, SPLICE_F_MOVE);
+			printf_verbose("splice chan to pipe ret %ld\n", ret);
+			if (ret < 0) {
+				perror("Error in relay splice");
+				goto write_error;
+			}
+			ret = splice(thread_pipe[0], NULL, pair->trace, NULL,
+				     ret, SPLICE_F_MOVE);
+			printf_verbose("splice pipe to file %ld\n", ret);
+			if (ret < 0) {
+				if (errno == EINVAL) {
+					printf_verbose("splice is not supported\n");
+					use_splice = 0;
+					err = TEMP_FAILURE_RETRY(
+						write(pair->trace, pair->mmap
+						      + (consumed_old & ((pair->n_subbufs * pair->subbuf_size)-1)),
+						      pair->subbuf_size));
+					if(err < 0) {
+						perror("Error in writing to file");
+						goto write_error;
+					}
+					else {
+						break;
+					}
+				}
+				else {
+					perror("Error in file splice");
+					goto write_error;
+				}
+			}
+			len -= ret;
 		}
-		len -= ret;
 	}

 #if 0
@@ -546,7 +566,6 @@ int map_channels(struct channel_trace_fd
 		}
 	}

-#if 0
 	/* Mmap each FD */
 	for(i=idx_begin;i<idx_end;i++) {
 		struct fd_pair *pair = &fd_pairs->pair[i];
@@ -576,7 +595,6 @@ munmap:
 		ret |= err_ret;
 	}

-#endif //0
 end:
 	return ret;
 }
@@ -591,13 +609,11 @@ int unmap_channels(struct channel_trace_
 		struct fd_pair *pair = &fd_pairs->pair[j];
 		int err_ret;

-#if 0
 		err_ret = munmap(pair->mmap, pair->subbuf_size * pair->n_subbufs);
 		if(err_ret != 0) {
 			perror("Error in munmap");
 		}
 		ret |= err_ret;
-#endif //0
 		err_ret = pthread_mutex_destroy(&pair->mutex);
 		if(err_ret != 0) {
 			perror("Error in mutex destroy");




More information about the lttng-dev mailing list