X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=libust%2Fbuffers.c;h=bb5d8c581918c191da90e370dafd00c667dcac08;hb=bc237fab2306223e429c43ff003ac06c3777be99;hp=c27b78877df625c33a23af1ff8f6af2f4277ad1b;hpb=ee4c34673a261a035d224096db82e6b70ba085ca;p=ust.git diff --git a/libust/buffers.c b/libust/buffers.c index c27b788..bb5d8c5 100644 --- a/libust/buffers.c +++ b/libust/buffers.c @@ -70,28 +70,68 @@ static int get_n_cpus(void) return n_cpus; } -/* _ust_buffers_write() +/** + * _ust_buffers_strncpy_fixup - Fix an incomplete string in a ltt_relay buffer. + * @buf : buffer + * @offset : offset within the buffer + * @len : length to write + * @copied: string actually copied + * @terminated: does string end with \0 * - * @buf: destination buffer - * @offset: offset in destination - * @src: source buffer - * @len: length of source - * @cpy: already copied + * Fills string with "X" if incomplete. */ - -void _ust_buffers_write(struct ust_buffer *buf, size_t offset, - const void *src, size_t len, ssize_t cpy) +void _ust_buffers_strncpy_fixup(struct ust_buffer *buf, size_t offset, + size_t len, size_t copied, int terminated) { - do { - len -= cpy; - src += cpy; - offset += cpy; + size_t buf_offset, cpy; + + if (copied == len) { + /* + * Deal with non-terminated string. + */ + assert(!terminated); + offset += copied - 1; + buf_offset = BUFFER_OFFSET(offset, buf->chan); + /* + * Underlying layer should never ask for writes across + * subbuffers. + */ + assert(buf_offset + < buf->chan->subbuf_size*buf->chan->subbuf_cnt); + ust_buffers_do_memset(buf->buf_data + buf_offset, '\0', 1); + return; + } - WARN_ON(offset >= buf->buf_size); + /* + * Deal with incomplete string. + * Overwrite string's \0 with X too. + */ + cpy = copied - 1; + assert(terminated); + len -= cpy; + offset += cpy; + buf_offset = BUFFER_OFFSET(offset, buf->chan); + + /* + * Underlying layer should never ask for writes across subbuffers. + */ + assert(buf_offset + < buf->chan->subbuf_size*buf->chan->subbuf_cnt); - cpy = min_t(size_t, len, buf->buf_size - offset); - ust_buffers_do_copy(buf->buf_data + offset, src, cpy); - } while (unlikely(len != cpy)); + ust_buffers_do_memset(buf->buf_data + buf_offset, + 'X', len); + + /* + * Overwrite last 'X' with '\0'. + */ + offset += len - 1; + buf_offset = BUFFER_OFFSET(offset, buf->chan); + /* + * Underlying layer should never ask for writes across subbuffers. + */ + assert(buf_offset + < buf->chan->subbuf_size*buf->chan->subbuf_cnt); + ust_buffers_do_memset(buf->buf_data + buf_offset, '\0', 1); } static int ust_buffers_init_buffer(struct ust_trace *trace, @@ -163,7 +203,7 @@ int ust_buffers_create_buf(struct ust_channel *channel, int cpu) static void ust_buffers_destroy_channel(struct kref *kref) { - struct ust_channel *chan = container_of(kref, struct ust_channel, kref); + struct ust_channel *chan = _ust_container_of(kref, struct ust_channel, kref); free(chan); } @@ -185,7 +225,7 @@ static void ust_buffers_destroy_buf(struct ust_buffer *buf) /* called from kref_put */ static void ust_buffers_remove_buf(struct kref *kref) { - struct ust_buffer *buf = container_of(kref, struct ust_buffer, kref); + struct ust_buffer *buf = _ust_container_of(kref, struct ust_buffer, kref); ust_buffers_destroy_buf(buf); } @@ -552,7 +592,7 @@ static void ltt_relay_print_buffer_errors(struct ust_channel *channel, int cpu) static void ltt_relay_release_channel(struct kref *kref) { - struct ust_channel *ltt_chan = container_of(kref, + struct ust_channel *ltt_chan = _ust_container_of(kref, struct ust_channel, kref); free(ltt_chan->buf); } @@ -737,11 +777,11 @@ static int ust_buffers_create_channel(const char *trace_name, struct ust_trace * ltt_chan->commit_count_mask = (~0UL >> ltt_chan->n_subbufs_order); ltt_chan->n_cpus = get_n_cpus(); //ust// ltt_chan->buf = percpu_alloc_mask(sizeof(struct ltt_channel_buf_struct), GFP_KERNEL, cpu_possible_map); - ltt_chan->buf = (void *) malloc(ltt_chan->n_cpus * sizeof(void *)); + ltt_chan->buf = (void *) zmalloc(ltt_chan->n_cpus * sizeof(void *)); if(ltt_chan->buf == NULL) { goto error; } - ltt_chan->buf_struct_shmids = (int *) malloc(ltt_chan->n_cpus * sizeof(int)); + ltt_chan->buf_struct_shmids = (int *) zmalloc(ltt_chan->n_cpus * sizeof(int)); if(ltt_chan->buf_struct_shmids == NULL) goto free_buf;