Skip to content

Commit acead00

Browse files
Alex ElderSage Weil
authored andcommitted
libceph: don't build request in ceph_osdc_new_request()
This patch moves the call to ceph_osdc_build_request() out of ceph_osdc_new_request() and into its caller. This is in order to defer formatting osd operation information into the request message until just before request is started. The only unusual (ab)user of ceph_osdc_build_request() is ceph_writepages_start(), where the final length of write request may change (downward) based on the current inode size or the oldest snapshot context with dirty data for the inode. The remaining callers don't change anything in the request after has been built. This means the ops array is now supplied by the caller. It also means there is no need to pass the mtime to ceph_osdc_new_request() (it gets provided to ceph_osdc_build_request()). And rather than passing a do_sync flag, have the number of ops in the ops array supplied imply adding a second STARTSYNC operation after the READ or WRITE requested. This and some of the patches that follow are related to having the messenger (only) be responsible for filling the content of the message header, as described here: http://tracker.ceph.com/issues/4589 Signed-off-by: Alex Elder <elder@inktank.com> Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
1 parent a193080 commit acead00

4 files changed

Lines changed: 63 additions & 45 deletions

File tree

‎fs/ceph/addr.c‎

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,9 @@ static int start_read(struct inode *inode, struct list_head *page_list, int max)
284284
&ceph_inode_to_client(inode)->client->osdc;
285285
struct ceph_inode_info *ci = ceph_inode(inode);
286286
struct page *page = list_entry(page_list->prev, struct page, lru);
287+
struct ceph_vino vino;
287288
struct ceph_osd_request *req;
289+
struct ceph_osd_req_op op;
288290
u64 off;
289291
u64 len;
290292
int i;
@@ -308,16 +310,17 @@ static int start_read(struct inode *inode, struct list_head *page_list, int max)
308310
len = nr_pages << PAGE_CACHE_SHIFT;
309311
dout("start_read %p nr_pages %d is %lld~%lld\n", inode, nr_pages,
310312
off, len);
311-
312-
req = ceph_osdc_new_request(osdc, &ci->i_layout, ceph_vino(inode),
313-
off, &len,
314-
CEPH_OSD_OP_READ, CEPH_OSD_FLAG_READ,
315-
NULL, 0,
313+
vino = ceph_vino(inode);
314+
req = ceph_osdc_new_request(osdc, &ci->i_layout, vino, off, &len,
315+
1, &op, CEPH_OSD_OP_READ,
316+
CEPH_OSD_FLAG_READ, NULL,
316317
ci->i_truncate_seq, ci->i_truncate_size,
317-
NULL, false);
318+
false);
318319
if (IS_ERR(req))
319320
return PTR_ERR(req);
320321

322+
ceph_osdc_build_request(req, off, 1, &op, NULL, vino.snap, NULL);
323+
321324
/* build page vector */
322325
nr_pages = calc_pages_for(0, len);
323326
pages = kmalloc(sizeof(*pages) * nr_pages, GFP_NOFS);
@@ -736,6 +739,7 @@ static int ceph_writepages_start(struct address_space *mapping,
736739
last_snapc = snapc;
737740

738741
while (!done && index <= end) {
742+
struct ceph_osd_req_op ops[2];
739743
unsigned i;
740744
int first;
741745
pgoff_t next;
@@ -825,27 +829,33 @@ static int ceph_writepages_start(struct address_space *mapping,
825829

826830
/* ok */
827831
if (locked_pages == 0) {
832+
struct ceph_vino vino;
833+
int num_ops = do_sync ? 2 : 1;
834+
828835
/* prepare async write request */
829836
offset = (u64) page_offset(page);
830837
len = wsize;
838+
vino = ceph_vino(inode);
839+
/* BUG_ON(vino.snap != CEPH_NOSNAP); */
831840
req = ceph_osdc_new_request(&fsc->client->osdc,
832-
&ci->i_layout,
833-
ceph_vino(inode),
834-
offset, &len,
841+
&ci->i_layout, vino, offset, &len,
842+
num_ops, ops,
835843
CEPH_OSD_OP_WRITE,
836844
CEPH_OSD_FLAG_WRITE |
837845
CEPH_OSD_FLAG_ONDISK,
838-
snapc, do_sync,
839-
ci->i_truncate_seq,
840-
ci->i_truncate_size,
841-
&inode->i_mtime, true);
846+
snapc, ci->i_truncate_seq,
847+
ci->i_truncate_size, true);
842848

843849
if (IS_ERR(req)) {
844850
rc = PTR_ERR(req);
845851
unlock_page(page);
846852
break;
847853
}
848854

855+
ceph_osdc_build_request(req, offset,
856+
num_ops, ops, snapc, vino.snap,
857+
&inode->i_mtime);
858+
849859
req->r_data_out.type = CEPH_OSD_DATA_TYPE_PAGES;
850860
req->r_data_out.length = len;
851861
req->r_data_out.alignment = 0;

‎fs/ceph/file.c‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -475,14 +475,17 @@ static ssize_t ceph_sync_write(struct file *file, const char __user *data,
475475
struct inode *inode = file_inode(file);
476476
struct ceph_inode_info *ci = ceph_inode(inode);
477477
struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
478+
struct ceph_snap_context *snapc;
479+
struct ceph_vino vino;
478480
struct ceph_osd_request *req;
481+
struct ceph_osd_req_op ops[2];
482+
int num_ops = 1;
479483
struct page **pages;
480484
int num_pages;
481485
long long unsigned pos;
482486
u64 len;
483487
int written = 0;
484488
int flags;
485-
int do_sync = 0;
486489
int check_caps = 0;
487490
int page_align, io_align;
488491
unsigned long buf_align;
@@ -516,7 +519,7 @@ static ssize_t ceph_sync_write(struct file *file, const char __user *data,
516519
if ((file->f_flags & (O_SYNC|O_DIRECT)) == 0)
517520
flags |= CEPH_OSD_FLAG_ACK;
518521
else
519-
do_sync = 1;
522+
num_ops++; /* Also include a 'startsync' command. */
520523

521524
/*
522525
* we may need to do multiple writes here if we span an object
@@ -527,16 +530,19 @@ static ssize_t ceph_sync_write(struct file *file, const char __user *data,
527530
buf_align = (unsigned long)data & ~PAGE_MASK;
528531
len = left;
529532

533+
snapc = ci->i_snap_realm->cached_context;
534+
vino = ceph_vino(inode);
530535
req = ceph_osdc_new_request(&fsc->client->osdc, &ci->i_layout,
531-
ceph_vino(inode), pos, &len,
532-
CEPH_OSD_OP_WRITE, flags,
533-
ci->i_snap_realm->cached_context,
534-
do_sync,
536+
vino, pos, &len, num_ops, ops,
537+
CEPH_OSD_OP_WRITE, flags, snapc,
535538
ci->i_truncate_seq, ci->i_truncate_size,
536-
&mtime, false);
539+
false);
537540
if (IS_ERR(req))
538541
return PTR_ERR(req);
539542

543+
ceph_osdc_build_request(req, pos, num_ops, ops,
544+
snapc, vino.snap, &mtime);
545+
540546
/* write from beginning of first page, regardless of io alignment */
541547
page_align = file->f_flags & O_DIRECT ? buf_align : io_align;
542548
num_pages = calc_pages_for(page_align, len);

‎include/linux/ceph/osd_client.h‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,12 @@ extern void osd_req_op_watch_init(struct ceph_osd_req_op *op, u16 opcode,
243243

244244
extern struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
245245
struct ceph_snap_context *snapc,
246-
unsigned int num_op,
246+
unsigned int num_ops,
247247
bool use_mempool,
248248
gfp_t gfp_flags);
249249

250250
extern void ceph_osdc_build_request(struct ceph_osd_request *req, u64 off,
251-
unsigned int num_op,
251+
unsigned int num_ops,
252252
struct ceph_osd_req_op *src_ops,
253253
struct ceph_snap_context *snapc,
254254
u64 snap_id,
@@ -257,11 +257,11 @@ extern void ceph_osdc_build_request(struct ceph_osd_request *req, u64 off,
257257
extern struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *,
258258
struct ceph_file_layout *layout,
259259
struct ceph_vino vino,
260-
u64 offset, u64 *len, int op, int flags,
260+
u64 offset, u64 *len,
261+
int num_ops, struct ceph_osd_req_op *ops,
262+
int opcode, int flags,
261263
struct ceph_snap_context *snapc,
262-
int do_sync, u32 truncate_seq,
263-
u64 truncate_size,
264-
struct timespec *mtime,
264+
u32 truncate_seq, u64 truncate_size,
265265
bool use_mempool);
266266

267267
extern void ceph_osdc_set_request_linger(struct ceph_osd_client *osdc,

‎net/ceph/osd_client.c‎

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -512,9 +512,7 @@ void ceph_osdc_build_request(struct ceph_osd_request *req,
512512
msg->front.iov_len = msg_size;
513513
msg->hdr.front_len = cpu_to_le32(msg_size);
514514

515-
dout("build_request msg_size was %d num_ops %d\n", (int)msg_size,
516-
num_ops);
517-
return;
515+
dout("build_request msg_size was %d\n", (int)msg_size);
518516
}
519517
EXPORT_SYMBOL(ceph_osdc_build_request);
520518

@@ -532,18 +530,15 @@ EXPORT_SYMBOL(ceph_osdc_build_request);
532530
struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
533531
struct ceph_file_layout *layout,
534532
struct ceph_vino vino,
535-
u64 off, u64 *plen,
533+
u64 off, u64 *plen, int num_ops,
534+
struct ceph_osd_req_op *ops,
536535
int opcode, int flags,
537536
struct ceph_snap_context *snapc,
538-
int do_sync,
539537
u32 truncate_seq,
540538
u64 truncate_size,
541-
struct timespec *mtime,
542539
bool use_mempool)
543540
{
544-
struct ceph_osd_req_op ops[2];
545541
struct ceph_osd_request *req;
546-
unsigned int num_op = do_sync ? 2 : 1;
547542
u64 objnum = 0;
548543
u64 objoff = 0;
549544
u64 objlen = 0;
@@ -553,7 +548,7 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
553548

554549
BUG_ON(opcode != CEPH_OSD_OP_READ && opcode != CEPH_OSD_OP_WRITE);
555550

556-
req = ceph_osdc_alloc_request(osdc, snapc, num_op, use_mempool,
551+
req = ceph_osdc_alloc_request(osdc, snapc, num_ops, use_mempool,
557552
GFP_NOFS);
558553
if (!req)
559554
return ERR_PTR(-ENOMEM);
@@ -578,7 +573,12 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
578573

579574
osd_req_op_extent_init(&ops[0], opcode, objoff, objlen,
580575
truncate_size, truncate_seq);
581-
if (do_sync)
576+
/*
577+
* A second op in the ops array means the caller wants to
578+
* also issue a include a 'startsync' command so that the
579+
* osd will flush data quickly.
580+
*/
581+
if (num_ops > 1)
582582
osd_req_op_init(&ops[1], CEPH_OSD_OP_STARTSYNC);
583583

584584
req->r_file_layout = *layout; /* keep a copy */
@@ -587,9 +587,6 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
587587
vino.ino, objnum);
588588
req->r_oid_len = strlen(req->r_oid);
589589

590-
ceph_osdc_build_request(req, off, num_op, ops,
591-
snapc, vino.snap, mtime);
592-
593590
return req;
594591
}
595592
EXPORT_SYMBOL(ceph_osdc_new_request);
@@ -2047,17 +2044,20 @@ int ceph_osdc_readpages(struct ceph_osd_client *osdc,
20472044
{
20482045
struct ceph_osd_request *req;
20492046
struct ceph_osd_data *osd_data;
2047+
struct ceph_osd_req_op op;
20502048
int rc = 0;
20512049

20522050
dout("readpages on ino %llx.%llx on %llu~%llu\n", vino.ino,
20532051
vino.snap, off, *plen);
2054-
req = ceph_osdc_new_request(osdc, layout, vino, off, plen,
2052+
req = ceph_osdc_new_request(osdc, layout, vino, off, plen, 1, &op,
20552053
CEPH_OSD_OP_READ, CEPH_OSD_FLAG_READ,
2056-
NULL, 0, truncate_seq, truncate_size, NULL,
2054+
NULL, truncate_seq, truncate_size,
20572055
false);
20582056
if (IS_ERR(req))
20592057
return PTR_ERR(req);
20602058

2059+
ceph_osdc_build_request(req, off, 1, &op, NULL, vino.snap, NULL);
2060+
20612061
/* it may be a short read due to an object boundary */
20622062

20632063
osd_data = &req->r_data_in;
@@ -2092,19 +2092,21 @@ int ceph_osdc_writepages(struct ceph_osd_client *osdc, struct ceph_vino vino,
20922092
{
20932093
struct ceph_osd_request *req;
20942094
struct ceph_osd_data *osd_data;
2095+
struct ceph_osd_req_op op;
20952096
int rc = 0;
20962097
int page_align = off & ~PAGE_MASK;
20972098

2098-
BUG_ON(vino.snap != CEPH_NOSNAP);
2099-
req = ceph_osdc_new_request(osdc, layout, vino, off, &len,
2099+
BUG_ON(vino.snap != CEPH_NOSNAP); /* snapshots aren't writeable */
2100+
req = ceph_osdc_new_request(osdc, layout, vino, off, &len, 1, &op,
21002101
CEPH_OSD_OP_WRITE,
21012102
CEPH_OSD_FLAG_ONDISK | CEPH_OSD_FLAG_WRITE,
2102-
snapc, 0,
2103-
truncate_seq, truncate_size, mtime,
2103+
snapc, truncate_seq, truncate_size,
21042104
true);
21052105
if (IS_ERR(req))
21062106
return PTR_ERR(req);
21072107

2108+
ceph_osdc_build_request(req, off, 1, &op, snapc, CEPH_NOSNAP, mtime);
2109+
21082110
/* it may be a short write due to an object boundary */
21092111
osd_data = &req->r_data_out;
21102112
osd_data->type = CEPH_OSD_DATA_TYPE_PAGES;

0 commit comments

Comments
 (0)