From: laijs@cn.fujitsu.com (Lai Jiangshan)
Subject: [ltt-dev] [PATCH take2 04/13] read C-style string from ltt-relay buffer
Date: Thu, 05 Feb 2009 11:31:23 +0800 [thread overview]
Message-ID: <498A5D8B.3080809@cn.fujitsu.com> (raw)
C-style string which is written to ltt-relay buffer is not in
continuous memory region, we implement ltt_relay_read_cstr()
read it.
Signed-off-by: Lai Jiangshan <laijs at cn.fujitsu.com>
---
diff --git a/include/linux/ltt-relay.h b/include/linux/ltt-relay.h
index 1225a6a..437b2d9 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 e15f244..4b8e4c3 100644
--- a/ltt/ltt-relay-alloc.c
+++ b/ltt/ltt-relay-alloc.c
@@ -614,6 +614,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
next reply other threads:[~2009-02-05 3:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-05 3:31 Lai Jiangshan [this message]
2009-02-23 17:46 ` Mathieu Desnoyers
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=498A5D8B.3080809@cn.fujitsu.com \
--to=laijs@cn.fujitsu.com \
/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