Commit 43bfe5de authored by Alex Elder's avatar Alex Elder Committed by Sage Weil

libceph: define osd data initialization helpers

Define and use functions that encapsulate the initializion of a
ceph_osd_data structure.
Signed-off-by: default avatarAlex Elder <elder@inktank.com>
Reviewed-by: default avatarJosh Durgin <josh.durgin@inktank.com>
parent 9fc6e064
...@@ -1350,17 +1350,13 @@ static struct ceph_osd_request *rbd_osd_req_create( ...@@ -1350,17 +1350,13 @@ static struct ceph_osd_request *rbd_osd_req_create(
break; /* Nothing to do */ break; /* Nothing to do */
case OBJ_REQUEST_BIO: case OBJ_REQUEST_BIO:
rbd_assert(obj_request->bio_list != NULL); rbd_assert(obj_request->bio_list != NULL);
osd_data->type = CEPH_OSD_DATA_TYPE_BIO; ceph_osd_data_bio_init(osd_data, obj_request->bio_list,
osd_data->bio = obj_request->bio_list; obj_request->length);
osd_data->bio_length = obj_request->length;
break; break;
case OBJ_REQUEST_PAGES: case OBJ_REQUEST_PAGES:
osd_data->type = CEPH_OSD_DATA_TYPE_PAGES; ceph_osd_data_pages_init(osd_data, obj_request->pages,
osd_data->pages = obj_request->pages; obj_request->length, offset & ~PAGE_MASK,
osd_data->length = obj_request->length; false, false);
osd_data->alignment = offset & ~PAGE_MASK;
osd_data->pages_from_pool = false;
osd_data->own_pages = false;
break; break;
} }
......
...@@ -342,10 +342,8 @@ static int start_read(struct inode *inode, struct list_head *page_list, int max) ...@@ -342,10 +342,8 @@ static int start_read(struct inode *inode, struct list_head *page_list, int max)
} }
pages[i] = page; pages[i] = page;
} }
req->r_data_in.type = CEPH_OSD_DATA_TYPE_PAGES; ceph_osd_data_pages_init(&req->r_data_in, pages, len, 0,
req->r_data_in.pages = pages; false, false);
req->r_data_in.length = len;
req->r_data_in.alignment = 0;
req->r_callback = finish_read; req->r_callback = finish_read;
req->r_inode = inode; req->r_inode = inode;
...@@ -917,11 +915,8 @@ static int ceph_writepages_start(struct address_space *mapping, ...@@ -917,11 +915,8 @@ static int ceph_writepages_start(struct address_space *mapping,
dout("writepages got %d pages at %llu~%llu\n", dout("writepages got %d pages at %llu~%llu\n",
locked_pages, offset, len); locked_pages, offset, len);
req->r_data_out.type = CEPH_OSD_DATA_TYPE_PAGES; ceph_osd_data_pages_init(&req->r_data_out, pages, len, 0,
req->r_data_out.pages = pages; !!pool, false);
req->r_data_out.length = len;
req->r_data_out.alignment = 0;
req->r_data_out.pages_from_pool = !!pool;
pages = NULL; /* request message now owns the pages array */ pages = NULL; /* request message now owns the pages array */
pool = NULL; pool = NULL;
......
...@@ -491,6 +491,7 @@ static ssize_t ceph_sync_write(struct file *file, const char __user *data, ...@@ -491,6 +491,7 @@ static ssize_t ceph_sync_write(struct file *file, const char __user *data,
unsigned long buf_align; unsigned long buf_align;
int ret; int ret;
struct timespec mtime = CURRENT_TIME; struct timespec mtime = CURRENT_TIME;
bool own_pages = false;
if (ceph_snap(file_inode(file)) != CEPH_NOSNAP) if (ceph_snap(file_inode(file)) != CEPH_NOSNAP)
return -EROFS; return -EROFS;
...@@ -571,14 +572,11 @@ static ssize_t ceph_sync_write(struct file *file, const char __user *data, ...@@ -571,14 +572,11 @@ static ssize_t ceph_sync_write(struct file *file, const char __user *data,
if ((file->f_flags & O_SYNC) == 0) { if ((file->f_flags & O_SYNC) == 0) {
/* get a second commit callback */ /* get a second commit callback */
req->r_safe_callback = sync_write_commit; req->r_safe_callback = sync_write_commit;
req->r_data_out.own_pages = 1; own_pages = true;
} }
} }
req->r_data_out.type = CEPH_OSD_DATA_TYPE_PAGES; ceph_osd_data_pages_init(&req->r_data_out, pages, len, page_align,
req->r_data_out.pages = pages; false, own_pages);
req->r_data_out.length = len;
req->r_data_out.alignment = page_align;
req->r_inode = inode;
/* BUG_ON(vino.snap != CEPH_NOSNAP); */ /* BUG_ON(vino.snap != CEPH_NOSNAP); */
ceph_osdc_build_request(req, pos, num_ops, ops, ceph_osdc_build_request(req, pos, num_ops, ops,
......
...@@ -280,6 +280,17 @@ static inline void ceph_osdc_put_request(struct ceph_osd_request *req) ...@@ -280,6 +280,17 @@ static inline void ceph_osdc_put_request(struct ceph_osd_request *req)
kref_put(&req->r_kref, ceph_osdc_release_request); kref_put(&req->r_kref, ceph_osdc_release_request);
} }
extern void ceph_osd_data_pages_init(struct ceph_osd_data *osd_data,
struct page **pages, u64 length,
u32 alignment, bool pages_from_pool,
bool own_pages);
extern void ceph_osd_data_pagelist_init(struct ceph_osd_data *osd_data,
struct ceph_pagelist *pagelist);
#ifdef CONFIG_BLOCK
extern void ceph_osd_data_bio_init(struct ceph_osd_data *osd_data,
struct bio *bio, size_t bio_length);
#endif /* CONFIG_BLOCK */
extern int ceph_osdc_start_request(struct ceph_osd_client *osdc, extern int ceph_osdc_start_request(struct ceph_osd_client *osdc,
struct ceph_osd_request *req, struct ceph_osd_request *req,
bool nofail); bool nofail);
......
...@@ -79,6 +79,38 @@ static int calc_layout(struct ceph_file_layout *layout, u64 off, u64 *plen, ...@@ -79,6 +79,38 @@ static int calc_layout(struct ceph_file_layout *layout, u64 off, u64 *plen,
return 0; return 0;
} }
void ceph_osd_data_pages_init(struct ceph_osd_data *osd_data,
struct page **pages, u64 length, u32 alignment,
bool pages_from_pool, bool own_pages)
{
osd_data->type = CEPH_OSD_DATA_TYPE_PAGES;
osd_data->pages = pages;
osd_data->length = length;
osd_data->alignment = alignment;
osd_data->pages_from_pool = pages_from_pool;
osd_data->own_pages = own_pages;
}
EXPORT_SYMBOL(ceph_osd_data_pages_init);
void ceph_osd_data_pagelist_init(struct ceph_osd_data *osd_data,
struct ceph_pagelist *pagelist)
{
osd_data->type = CEPH_OSD_DATA_TYPE_PAGELIST;
osd_data->pagelist = pagelist;
}
EXPORT_SYMBOL(ceph_osd_data_pagelist_init);
#ifdef CONFIG_BLOCK
void ceph_osd_data_bio_init(struct ceph_osd_data *osd_data,
struct bio *bio, size_t bio_length)
{
osd_data->type = CEPH_OSD_DATA_TYPE_BIO;
osd_data->bio = bio;
osd_data->bio_length = bio_length;
}
EXPORT_SYMBOL(ceph_osd_data_bio_init);
#endif /* CONFIG_BLOCK */
/* /*
* requests * requests
*/ */
...@@ -400,8 +432,7 @@ static u64 osd_req_encode_op(struct ceph_osd_request *req, ...@@ -400,8 +432,7 @@ static u64 osd_req_encode_op(struct ceph_osd_request *req,
ceph_pagelist_append(pagelist, src->cls.indata, ceph_pagelist_append(pagelist, src->cls.indata,
src->cls.indata_len); src->cls.indata_len);
req->r_data_out.type = CEPH_OSD_DATA_TYPE_PAGELIST; ceph_osd_data_pagelist_init(&req->r_data_out, pagelist);
req->r_data_out.pagelist = pagelist;
out_data_len = pagelist->length; out_data_len = pagelist->length;
break; break;
case CEPH_OSD_OP_STARTSYNC: case CEPH_OSD_OP_STARTSYNC:
...@@ -2056,7 +2087,6 @@ int ceph_osdc_readpages(struct ceph_osd_client *osdc, ...@@ -2056,7 +2087,6 @@ int ceph_osdc_readpages(struct ceph_osd_client *osdc,
struct page **pages, int num_pages, int page_align) struct page **pages, int num_pages, int page_align)
{ {
struct ceph_osd_request *req; struct ceph_osd_request *req;
struct ceph_osd_data *osd_data;
struct ceph_osd_req_op op; struct ceph_osd_req_op op;
int rc = 0; int rc = 0;
...@@ -2071,14 +2101,11 @@ int ceph_osdc_readpages(struct ceph_osd_client *osdc, ...@@ -2071,14 +2101,11 @@ int ceph_osdc_readpages(struct ceph_osd_client *osdc,
/* it may be a short read due to an object boundary */ /* it may be a short read due to an object boundary */
osd_data = &req->r_data_in; ceph_osd_data_pages_init(&req->r_data_in, pages, *plen, page_align,
osd_data->type = CEPH_OSD_DATA_TYPE_PAGES; false, false);
osd_data->pages = pages;
osd_data->length = *plen;
osd_data->alignment = page_align;
dout("readpages final extent is %llu~%llu (%llu bytes align %d)\n", dout("readpages final extent is %llu~%llu (%llu bytes align %d)\n",
off, *plen, osd_data->length, page_align); off, *plen, *plen, page_align);
ceph_osdc_build_request(req, off, 1, &op, NULL, vino.snap, NULL); ceph_osdc_build_request(req, off, 1, &op, NULL, vino.snap, NULL);
...@@ -2104,7 +2131,6 @@ int ceph_osdc_writepages(struct ceph_osd_client *osdc, struct ceph_vino vino, ...@@ -2104,7 +2131,6 @@ int ceph_osdc_writepages(struct ceph_osd_client *osdc, struct ceph_vino vino,
struct page **pages, int num_pages) struct page **pages, int num_pages)
{ {
struct ceph_osd_request *req; struct ceph_osd_request *req;
struct ceph_osd_data *osd_data;
struct ceph_osd_req_op op; struct ceph_osd_req_op op;
int rc = 0; int rc = 0;
int page_align = off & ~PAGE_MASK; int page_align = off & ~PAGE_MASK;
...@@ -2119,12 +2145,9 @@ int ceph_osdc_writepages(struct ceph_osd_client *osdc, struct ceph_vino vino, ...@@ -2119,12 +2145,9 @@ int ceph_osdc_writepages(struct ceph_osd_client *osdc, struct ceph_vino vino,
return PTR_ERR(req); return PTR_ERR(req);
/* it may be a short write due to an object boundary */ /* it may be a short write due to an object boundary */
osd_data = &req->r_data_out; ceph_osd_data_pages_init(&req->r_data_out, pages, len, page_align,
osd_data->type = CEPH_OSD_DATA_TYPE_PAGES; false, false);
osd_data->pages = pages; dout("writepages %llu~%llu (%llu bytes)\n", off, len, len);
osd_data->length = len;
osd_data->alignment = page_align;
dout("writepages %llu~%llu (%llu bytes)\n", off, len, osd_data->length);
ceph_osdc_build_request(req, off, 1, &op, snapc, CEPH_NOSNAP, mtime); ceph_osdc_build_request(req, off, 1, &op, snapc, CEPH_NOSNAP, mtime);
......
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