X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=lttd%2Flttd.c;h=773cb234108350df3ac15ef1b5f1e4e7e5f97c22;hb=572db7d9168063ea3301de2e996cf329ff5d147f;hp=f21c411eb8940de479fb62980917c6880fae7e99;hpb=5e1fd42a8d1bbbe1e1283e4c652994ff738dd6a7;p=ltt-control.git diff --git a/lttd/lttd.c b/lttd/lttd.c index f21c411..773cb23 100644 --- a/lttd/lttd.c +++ b/lttd/lttd.c @@ -42,13 +42,16 @@ #include /* Get the next sub buffer that can be read. */ -#define RELAY_GET_SUBBUF _IOR(0xF5, 0x00,__u32) +#define RELAY_GET_SB _IOR(0xF5, 0x00,__u32) /* Release the oldest reserved (by "get") sub buffer. */ -#define RELAY_PUT_SUBBUF _IOW(0xF5, 0x01,__u32) +#define RELAY_PUT_SB _IOW(0xF5, 0x01,__u32) /* returns the number of sub buffers in the per cpu channel. */ -#define RELAY_GET_N_SUBBUFS _IOR(0xF5, 0x02,__u32) -/* returns the size of the sub buffers. */ -#define RELAY_GET_SUBBUF_SIZE _IOR(0xF5, 0x03,__u32) +#define RELAY_GET_N_SB _IOR(0xF5, 0x02,__u32) +/* returns the size of the current sub buffer. */ +#define RELAY_GET_SB_SIZE _IOR(0xF5, 0x03, __u32) +/* returns the size of data to consume in the current sub-buffer. */ +#define RELAY_GET_MAX_SB_SIZE _IOR(0xF5, 0x04, __u32) + #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14) #include @@ -88,18 +91,11 @@ static inline int inotify_rm_watch (int fd, __u32 wd) #undef HAS_INOTIFY #endif -enum { - GET_SUBBUF, - PUT_SUBBUF, - GET_N_BUBBUFS, - GET_SUBBUF_SIZE -}; - struct fd_pair { int channel; int trace; - unsigned int n_subbufs; - unsigned int subbuf_size; + unsigned int n_sb; + unsigned int max_sb_size; void *mmap; pthread_mutex_t mutex; }; @@ -320,15 +316,26 @@ int open_buffer_file(char *filename, char *path_channel, char *path_trace, S_IRWXU|S_IRWXG|S_IRWXO); if(fd_pairs->pair[fd_pairs->num_pairs-1].trace == -1) { perror(path_trace); + open_ret = -1; + close(fd_pairs->pair[fd_pairs->num_pairs-1].channel); + fd_pairs->num_pairs--; + goto end; } ret = lseek(fd_pairs->pair[fd_pairs->num_pairs-1].trace, 0, SEEK_END); if (ret < 0) { perror(path_trace); + open_ret = -1; + close(fd_pairs->pair[fd_pairs->num_pairs-1].channel); + close(fd_pairs->pair[fd_pairs->num_pairs-1].trace); + fd_pairs->num_pairs--; + goto end; } } else { printf("File %s exists, cannot open. Try append mode.\n", path_trace); open_ret = -1; + close(fd_pairs->pair[fd_pairs->num_pairs-1].channel); + fd_pairs->num_pairs--; goto end; } } else { @@ -338,6 +345,10 @@ int open_buffer_file(char *filename, char *path_channel, char *path_trace, S_IRWXU|S_IRWXG|S_IRWXO); if(fd_pairs->pair[fd_pairs->num_pairs-1].trace == -1) { perror(path_trace); + open_ret = -1; + close(fd_pairs->pair[fd_pairs->num_pairs-1].channel); + fd_pairs->num_pairs--; + goto end; } } } @@ -440,14 +451,13 @@ end: int read_subbuffer(struct fd_pair *pair) { - unsigned int consumed_old; + unsigned int consumed_old, len; int err; long ret; - unsigned long len; off_t offset; - err = ioctl(pair->channel, RELAY_GET_SUBBUF, &consumed_old); + err = ioctl(pair->channel, RELAY_GET_SB, &consumed_old); printf_verbose("cookie : %u\n", consumed_old); if(err != 0) { ret = errno; @@ -466,20 +476,26 @@ int read_subbuffer(struct fd_pair *pair) goto write_error; } #endif //0 - len = pair->subbuf_size; + err = ioctl(pair->channel, RELAY_GET_SB_SIZE, &len); + if(err != 0) { + ret = errno; + perror("Getting sub-buffer len failed."); + goto get_error; + } + 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); + len, SPLICE_F_MOVE | SPLICE_F_MORE); 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); + ret, SPLICE_F_MOVE | SPLICE_F_MORE); printf_verbose("splice pipe to file %ld\n", ret); if (ret < 0) { perror("Error in file splice"); @@ -498,14 +514,14 @@ int read_subbuffer(struct fd_pair *pair) #endif //0 write_error: ret = 0; - err = ioctl(pair->channel, RELAY_PUT_SUBBUF, &consumed_old); + err = ioctl(pair->channel, RELAY_PUT_SB, &consumed_old); if(err != 0) { ret = errno; if(errno == EFAULT) { perror("Error in unreserving sub buffer\n"); } else if(errno == EIO) { - perror("Reader has been pushed by the writer, last subbuffer corrupted."); - /* FIXME : we may delete the last written buffer if we wish. */ + /* Should never happen with newer LTTng versions */ + perror("Reader has been pushed by the writer, last sub-buffer corrupted."); } goto get_error; } @@ -531,16 +547,15 @@ int map_channels(struct channel_trace_fd *fd_pairs, for(i=idx_begin;ipair[i]; - ret = ioctl(pair->channel, RELAY_GET_N_SUBBUFS, - &pair->n_subbufs); + ret = ioctl(pair->channel, RELAY_GET_N_SB, &pair->n_sb); if(ret != 0) { - perror("Error in getting the number of subbuffers"); + perror("Error in getting the number of sub-buffers"); goto end; } - ret = ioctl(pair->channel, RELAY_GET_SUBBUF_SIZE, - &pair->subbuf_size); + ret = ioctl(pair->channel, RELAY_GET_MAX_SB_SIZE, + &pair->max_sb_size); if(ret != 0) { - perror("Error in getting the size of the subbuffers"); + perror("Error in getting the max sub-buffer size"); goto end; } ret = pthread_mutex_init(&pair->mutex, NULL); /* Fast mutex */ @@ -809,7 +824,7 @@ int read_channels(unsigned long thread_num, struct channel_trace_fd *fd_pairs, pollfd[i].fd); /* Take care of high priority channels first. */ high_prio = 1; - /* it's ok to have an unavailable subbuffer */ + /* it's ok to have an unavailable sub-buffer */ ret = read_subbuffer(&fd_pairs->pair[i-inotify_fds]); if(ret == EAGAIN) ret = 0;