Commit f38a5181 authored by Kent Overstreet's avatar Kent Overstreet

ceph: Convert to immutable biovecs

Now that we've got a mechanism for immutable biovecs -
bi_iter.bi_bvec_done - we need to convert drivers to use primitives that
respect it instead of using the bvec array directly.
Signed-off-by: default avatarKent Overstreet <kmo@daterainc.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Sage Weil <sage@inktank.com>
Cc: ceph-devel@vger.kernel.org
parent feb261e2
#ifndef __FS_CEPH_MESSENGER_H #ifndef __FS_CEPH_MESSENGER_H
#define __FS_CEPH_MESSENGER_H #define __FS_CEPH_MESSENGER_H
#include <linux/blk_types.h>
#include <linux/kref.h> #include <linux/kref.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/net.h> #include <linux/net.h>
...@@ -119,8 +120,7 @@ struct ceph_msg_data_cursor { ...@@ -119,8 +120,7 @@ struct ceph_msg_data_cursor {
#ifdef CONFIG_BLOCK #ifdef CONFIG_BLOCK
struct { /* bio */ struct { /* bio */
struct bio *bio; /* bio from list */ struct bio *bio; /* bio from list */
unsigned int vector_index; /* vector from bio */ struct bvec_iter bvec_iter;
unsigned int vector_offset; /* bytes from vector */
}; };
#endif /* CONFIG_BLOCK */ #endif /* CONFIG_BLOCK */
struct { /* pages */ struct { /* pages */
......
...@@ -777,13 +777,12 @@ static void ceph_msg_data_bio_cursor_init(struct ceph_msg_data_cursor *cursor, ...@@ -777,13 +777,12 @@ static void ceph_msg_data_bio_cursor_init(struct ceph_msg_data_cursor *cursor,
bio = data->bio; bio = data->bio;
BUG_ON(!bio); BUG_ON(!bio);
BUG_ON(!bio->bi_vcnt);
cursor->resid = min(length, data->bio_length); cursor->resid = min(length, data->bio_length);
cursor->bio = bio; cursor->bio = bio;
cursor->vector_index = 0; cursor->bvec_iter = bio->bi_iter;
cursor->vector_offset = 0; cursor->last_piece =
cursor->last_piece = length <= bio->bi_io_vec[0].bv_len; cursor->resid <= bio_iter_len(bio, cursor->bvec_iter);
} }
static struct page *ceph_msg_data_bio_next(struct ceph_msg_data_cursor *cursor, static struct page *ceph_msg_data_bio_next(struct ceph_msg_data_cursor *cursor,
...@@ -792,71 +791,63 @@ static struct page *ceph_msg_data_bio_next(struct ceph_msg_data_cursor *cursor, ...@@ -792,71 +791,63 @@ static struct page *ceph_msg_data_bio_next(struct ceph_msg_data_cursor *cursor,
{ {
struct ceph_msg_data *data = cursor->data; struct ceph_msg_data *data = cursor->data;
struct bio *bio; struct bio *bio;
struct bio_vec *bio_vec; struct bio_vec bio_vec;
unsigned int index;
BUG_ON(data->type != CEPH_MSG_DATA_BIO); BUG_ON(data->type != CEPH_MSG_DATA_BIO);
bio = cursor->bio; bio = cursor->bio;
BUG_ON(!bio); BUG_ON(!bio);
index = cursor->vector_index; bio_vec = bio_iter_iovec(bio, cursor->bvec_iter);
BUG_ON(index >= (unsigned int) bio->bi_vcnt);
bio_vec = &bio->bi_io_vec[index]; *page_offset = (size_t) bio_vec.bv_offset;
BUG_ON(cursor->vector_offset >= bio_vec->bv_len);
*page_offset = (size_t) (bio_vec->bv_offset + cursor->vector_offset);
BUG_ON(*page_offset >= PAGE_SIZE); BUG_ON(*page_offset >= PAGE_SIZE);
if (cursor->last_piece) /* pagelist offset is always 0 */ if (cursor->last_piece) /* pagelist offset is always 0 */
*length = cursor->resid; *length = cursor->resid;
else else
*length = (size_t) (bio_vec->bv_len - cursor->vector_offset); *length = (size_t) bio_vec.bv_len;
BUG_ON(*length > cursor->resid); BUG_ON(*length > cursor->resid);
BUG_ON(*page_offset + *length > PAGE_SIZE); BUG_ON(*page_offset + *length > PAGE_SIZE);
return bio_vec->bv_page; return bio_vec.bv_page;
} }
static bool ceph_msg_data_bio_advance(struct ceph_msg_data_cursor *cursor, static bool ceph_msg_data_bio_advance(struct ceph_msg_data_cursor *cursor,
size_t bytes) size_t bytes)
{ {
struct bio *bio; struct bio *bio;
struct bio_vec *bio_vec; struct bio_vec bio_vec;
unsigned int index;
BUG_ON(cursor->data->type != CEPH_MSG_DATA_BIO); BUG_ON(cursor->data->type != CEPH_MSG_DATA_BIO);
bio = cursor->bio; bio = cursor->bio;
BUG_ON(!bio); BUG_ON(!bio);
index = cursor->vector_index; bio_vec = bio_iter_iovec(bio, cursor->bvec_iter);
BUG_ON(index >= (unsigned int) bio->bi_vcnt);
bio_vec = &bio->bi_io_vec[index];
/* Advance the cursor offset */ /* Advance the cursor offset */
BUG_ON(cursor->resid < bytes); BUG_ON(cursor->resid < bytes);
cursor->resid -= bytes; cursor->resid -= bytes;
cursor->vector_offset += bytes;
if (cursor->vector_offset < bio_vec->bv_len) bio_advance_iter(bio, &cursor->bvec_iter, bytes);
if (bytes < bio_vec.bv_len)
return false; /* more bytes to process in this segment */ return false; /* more bytes to process in this segment */
BUG_ON(cursor->vector_offset != bio_vec->bv_len);
/* Move on to the next segment, and possibly the next bio */ /* Move on to the next segment, and possibly the next bio */
if (++index == (unsigned int) bio->bi_vcnt) { if (!cursor->bvec_iter.bi_size) {
bio = bio->bi_next; bio = bio->bi_next;
index = 0; cursor->bvec_iter = bio->bi_iter;
} }
cursor->bio = bio; cursor->bio = bio;
cursor->vector_index = index;
cursor->vector_offset = 0;
if (!cursor->last_piece) { if (!cursor->last_piece) {
BUG_ON(!cursor->resid); BUG_ON(!cursor->resid);
BUG_ON(!bio); BUG_ON(!bio);
/* A short read is OK, so use <= rather than == */ /* A short read is OK, so use <= rather than == */
if (cursor->resid <= bio->bi_io_vec[index].bv_len) if (cursor->resid <= bio_iter_len(bio, cursor->bvec_iter))
cursor->last_piece = true; cursor->last_piece = true;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment