Mirror of the lttng-dev mailing list
 help / color / mirror / Atom feed
From: compudj@krystal.dyndns.org (Mathieu Desnoyers)
Subject: [ltt-dev] [PATCH 04/13] read C-style string from ltt-relay	buffer
Date: Thu, 15 Jan 2009 13:42:54 -0500	[thread overview]
Message-ID: <20090115184254.GD32620@Krystal> (raw)
In-Reply-To: <496C5A28.8080609@cn.fujitsu.com>

* Lai Jiangshan (laijs at cn.fujitsu.com) wrote:
> 
> C-style string which is written to ltt-relay buffer is not in
> continuous memory region, we implement ltt_relay_read_cstr()
> read it.
> 

This patch looks good. (please resubmit with the rest of the patchset in
your next round)

Acked-by: Mathieu Desnoyers <mathieu.desnoyers at polymtl.ca>

> Signed-off-by: Lai Jiangshan <laijs at cn.fujitsu.com>
> ---
>  b/ltt/ltt-relay-alloc.c   |   44 ++++++++++++++++++++++++++++++++++++++++++++
>  include/linux/ltt-relay.h |    3 +++
>  2 files changed, 47 insertions(+)
> diff --git a/include/linux/ltt-relay.h b/include/linux/ltt-relay.h
> index 1225a6a..173b557 100644
> --- a/include/linux/ltt-relay.h
> +++ b/include/linux/ltt-relay.h
> @@ -146,6 +146,9 @@ extern int ltt_relay_write(struct rchan_buf *buf, size_t offset,
>  extern int ltt_relay_read(struct rchan_buf *buf, size_t offset,
>  	void *dest, size_t len);
>  
> +extern int ltt_relay_read_cstr(struct rchan_buf *buf, size_t offset,
> +	void *dest, size_t len);
> +
>  extern struct buf_page *ltt_relay_read_get_page(struct rchan_buf *buf,
>  	size_t offset);
>  
> diff --git a/ltt/ltt-relay-alloc.c b/ltt/ltt-relay-alloc.c
> index 80e856c..4d9489d 100644
> --- a/ltt/ltt-relay-alloc.c
> +++ b/ltt/ltt-relay-alloc.c
> @@ -614,6 +626,50 @@ int ltt_relay_read(struct rchan_buf *buf, size_t offset,
>  EXPORT_SYMBOL_GPL(ltt_relay_read);
>  
>  /**
> + * ltt_relay_read_cstr : read a C-style string from ltt_relay_buffer.
> + * @buf : buffer
> + * @offset : offset within the buffer
> + * @dest : destination address
> + * @len : destination's length
> + *
> + * return string's length
> + */
> +int ltt_relay_read_cstr(struct rchan_buf *buf, size_t offset,
> +		void *dest, size_t len)
> +{
> +	struct buf_page *page;
> +	ssize_t pagecpy, pagelen, strpagelen, orig_offset = offset;
> +	char *str;
> +
> +	offset &= buf->chan->alloc_size - 1;
> +	page = buf->rpage;
> +	for (;;) {
> +		page = ltt_relay_cache_page(buf, &buf->rpage, page, offset);
> +		str = (char *)page_address(page->page) + (offset & ~PAGE_MASK);
> +		pagelen = PAGE_SIZE - (offset & ~PAGE_MASK);
> +		strpagelen = strnlen(str, pagelen);
> +		if (len) {
> +			pagecpy = min_t(size_t, len, strpagelen);
> +			memcpy(dest, str, pagecpy);
> +			len -= pagecpy;
> +			dest += pagecpy;
> +		}
> +		offset += strpagelen;
> +		if (strpagelen < pagelen)
> +			break;
> +		/*
> +		 * Underlying layer should never ask for reads across
> +		 * subbuffers.
> +		 */
> +		WARN_ON(offset >= buf->chan->alloc_size);
> +	}
> +	if (len)
> +		((char *)dest)[0] = 0;
> +	return offset - orig_offset;
> +}
> +EXPORT_SYMBOL_GPL(ltt_relay_read_cstr);
> +
> +/**
>   * ltt_relay_read_get_page : Get a whole page to read from
>   * @buf : buffer
>   * @offset : offset within the buffer
> 
> 
> 
> 
> _______________________________________________
> ltt-dev mailing list
> ltt-dev at lists.casi.polymtl.ca
> http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev
> 

-- 
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68




      reply	other threads:[~2009-01-15 18:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-13  9:08 Lai Jiangshan
2009-01-15 18:42 ` Mathieu Desnoyers [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090115184254.GD32620@Krystal \
    --to=compudj@krystal.dyndns.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox