From: Zach Brown <zach.brown@oracle.com>
To: linux-fsdevel@vger.kernel.org
Cc: Christoph Hellwig <hch@infradead.org>, David Chinner <dgc@sgi.com>
Subject: [PATCH 3/4] add rwmem type backed by pages
Date: Tue, 6 Nov 2007 17:43:30 -0800 [thread overview]
Message-ID: <1194399811773-git-send-email-zach.brown@oracle.com> (raw)
In-Reply-To: <1194399811507-git-send-email-zach.brown@oracle.com>
This lets callers specify a region of memory to read from or write to with
an array of page/offset/len tuples. There have been specific requests to
do this from servers which want to do O_DIRECT from the kernel. (knfsd?)
This could also be used by places which currently hold a kmap() and call
fop->write. ecryptfs_write_lower_page_segment() is one such caller.
---
fs/rwmem.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++
include/linux/rwmem.h | 16 ++++++++++++
2 files changed, 82 insertions(+), 0 deletions(-)
diff --git a/fs/rwmem.c b/fs/rwmem.c
index 0433ba4..c87e8a4 100644
--- a/fs/rwmem.c
+++ b/fs/rwmem.c
@@ -90,3 +90,69 @@ struct rwmem_ops rwmem_iovec_ops = {
.seg_bytes = rwmem_iovec_seg_bytes,
.get_seg_pages = rwmem_iovec_get_seg_pages,
};
+
+void rwmem_pages_init(struct rwmem *rwm)
+{
+ struct rwmem_pages *rwp = container_of(rwm, struct rwmem_pages, rwmem);
+ struct pgol *pgol;
+ unsigned long i;
+
+ rwm->total_bytes = 0;
+ rwm->nr_pages = rwm->nr_segs;
+ rwm->boundary_bits = 0;
+
+ for (i = 0; i < rwm->nr_segs; i++) {
+ pgol = &rwp->pgol[i];
+
+ rwm->total_bytes += pgol->len;
+ rwm->boundary_bits |= pgol->offset | pgol->len;
+ }
+}
+
+/*
+ * Returns the offset of the start of a segment within its first page.
+ */
+unsigned long rwmem_pages_seg_page_offset(struct rwmem *rwm, unsigned long i)
+{
+ struct rwmem_pages *rwp = container_of(rwm, struct rwmem_pages, rwmem);
+ BUG_ON(i >= rwm->nr_segs);
+ return rwp->pgol[i].offset;
+}
+
+/*
+ * Returns the total bytes in the given segment.
+ */
+unsigned long rwmem_pages_seg_bytes(struct rwmem *rwm, unsigned long i)
+{
+ struct rwmem_pages *rwp = container_of(rwm, struct rwmem_pages, rwmem);
+ BUG_ON(i >= rwm->nr_segs);
+ return rwp->pgol[i].len;
+}
+
+/*
+ * For now each page is its own seg.
+ */
+int rwmem_pages_get_seg_pages(struct rwmem *rwm, unsigned long i,
+ unsigned long *cursor, struct page **pages,
+ unsigned long max_pages, int write)
+{
+ struct rwmem_pages *rwp = container_of(rwm, struct rwmem_pages, rwmem);
+ int ret = 0;
+
+ BUG_ON(i >= rwm->nr_segs);
+ BUG_ON(*cursor != 0);
+
+ if (max_pages) {
+ pages[0] = rwp->pgol[i].page;
+ get_page(pages[0]);
+ ret = 1;
+ }
+ return ret;
+}
+
+struct rwmem_ops rwmem_pages_ops = {
+ .init = rwmem_pages_init,
+ .seg_page_offset = rwmem_pages_seg_page_offset,
+ .seg_bytes = rwmem_pages_seg_bytes,
+ .get_seg_pages = rwmem_pages_get_seg_pages,
+};
diff --git a/include/linux/rwmem.h b/include/linux/rwmem.h
index 666f9f4..47019f0 100644
--- a/include/linux/rwmem.h
+++ b/include/linux/rwmem.h
@@ -26,4 +26,20 @@ struct rwmem_iovec {
};
struct rwmem_ops rwmem_iovec_ops;
+/*
+ * How many times do we need this in subsystems before we make a universal
+ * struct? (bio_vec, skb_frag_struct, pipe_buffer)
+ */
+struct pgol {
+ struct page *page;
+ unsigned int offset;
+ unsigned int len;
+};
+
+struct rwmem_pages {
+ struct rwmem rwmem;
+ struct pgol *pgol;
+};
+struct rwmem_ops rwmem_pages_ops;
+
#endif
--
1.5.2.2
next prev parent reply other threads:[~2007-11-07 1:43 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-07 1:43 [RFC] fs io with struct page instead of iovecs Zach Brown
2007-11-07 1:43 ` [PATCH 1/4] struct rwmem: an abstraction of the memory argument to read/write Zach Brown
2007-11-07 1:43 ` [PATCH 2/4] dio: use rwmem to work with r/w memory arguments Zach Brown
2007-11-07 1:43 ` Zach Brown [this message]
2007-11-07 1:43 ` [PATCH 4/4] add dio interface for page/offset/len tuples Zach Brown
2007-11-07 16:50 ` [RFC] fs io with struct page instead of iovecs Badari Pulavarty
2007-11-07 17:02 ` Zach Brown
2007-11-07 20:44 ` David Chinner
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=1194399811773-git-send-email-zach.brown@oracle.com \
--to=zach.brown@oracle.com \
--cc=dgc@sgi.com \
--cc=hch@infradead.org \
--cc=linux-fsdevel@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).