aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ceph
diff options
context:
space:
mode:
authorHenry C Chang <henry_c_chang@tcloudcomputing.com>2010-12-15 23:41:54 -0500
committerSage Weil <sage@newdream.net>2010-12-15 23:46:16 -0500
commitab226e21ad34f6ef52e00d2ab399d2364b4cdfee (patch)
tree95b9683b601a0602d9f813f7e6786e9a0e6da118 /fs/ceph
parentd96c9043d1588f04c7f467167f653c07d83232d5 (diff)
ceph: fix direct-io on non-page-aligned buffers
The user buffer may be 512-byte aligned, not page-aligned. We were assuming the buffer was page-aligned and only accounting for non-page-aligned io offsets. Signed-off-by: Henry C Chang <henry_c_chang@tcloudcomputing.com> Signed-off-by: Sage Weil <sage@newdream.net>
Diffstat (limited to 'fs/ceph')
-rw-r--r--fs/ceph/file.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/fs/ceph/file.c b/fs/ceph/file.c
index 8d79b8912e31..e860d8f1bb45 100644
--- a/fs/ceph/file.c
+++ b/fs/ceph/file.c
@@ -282,7 +282,8 @@ int ceph_release(struct inode *inode, struct file *file)
282static int striped_read(struct inode *inode, 282static int striped_read(struct inode *inode,
283 u64 off, u64 len, 283 u64 off, u64 len,
284 struct page **pages, int num_pages, 284 struct page **pages, int num_pages,
285 int *checkeof, bool align_to_pages) 285 int *checkeof, bool align_to_pages,
286 unsigned long buf_align)
286{ 287{
287 struct ceph_fs_client *fsc = ceph_inode_to_client(inode); 288 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
288 struct ceph_inode_info *ci = ceph_inode(inode); 289 struct ceph_inode_info *ci = ceph_inode(inode);
@@ -307,7 +308,7 @@ static int striped_read(struct inode *inode,
307 308
308more: 309more:
309 if (align_to_pages) 310 if (align_to_pages)
310 page_align = (pos - io_align) & ~PAGE_MASK; 311 page_align = (pos - io_align + buf_align) & ~PAGE_MASK;
311 else 312 else
312 page_align = pos & ~PAGE_MASK; 313 page_align = pos & ~PAGE_MASK;
313 this_len = left; 314 this_len = left;
@@ -376,16 +377,18 @@ static ssize_t ceph_sync_read(struct file *file, char __user *data,
376 struct inode *inode = file->f_dentry->d_inode; 377 struct inode *inode = file->f_dentry->d_inode;
377 struct page **pages; 378 struct page **pages;
378 u64 off = *poff; 379 u64 off = *poff;
379 int num_pages = calc_pages_for(off, len); 380 int num_pages, ret;
380 int ret;
381 381
382 dout("sync_read on file %p %llu~%u %s\n", file, off, len, 382 dout("sync_read on file %p %llu~%u %s\n", file, off, len,
383 (file->f_flags & O_DIRECT) ? "O_DIRECT" : ""); 383 (file->f_flags & O_DIRECT) ? "O_DIRECT" : "");
384 384
385 if (file->f_flags & O_DIRECT) 385 if (file->f_flags & O_DIRECT) {
386 num_pages = calc_pages_for((unsigned long)data, len);
386 pages = ceph_get_direct_page_vector(data, num_pages); 387 pages = ceph_get_direct_page_vector(data, num_pages);
387 else 388 } else {
389 num_pages = calc_pages_for(off, len);
388 pages = ceph_alloc_page_vector(num_pages, GFP_NOFS); 390 pages = ceph_alloc_page_vector(num_pages, GFP_NOFS);
391 }
389 if (IS_ERR(pages)) 392 if (IS_ERR(pages))
390 return PTR_ERR(pages); 393 return PTR_ERR(pages);
391 394
@@ -400,7 +403,8 @@ static ssize_t ceph_sync_read(struct file *file, char __user *data,
400 goto done; 403 goto done;
401 404
402 ret = striped_read(inode, off, len, pages, num_pages, checkeof, 405 ret = striped_read(inode, off, len, pages, num_pages, checkeof,
403 file->f_flags & O_DIRECT); 406 file->f_flags & O_DIRECT,
407 (unsigned long)data & ~PAGE_MASK);
404 408
405 if (ret >= 0 && (file->f_flags & O_DIRECT) == 0) 409 if (ret >= 0 && (file->f_flags & O_DIRECT) == 0)
406 ret = ceph_copy_page_vector_to_user(pages, data, off, ret); 410 ret = ceph_copy_page_vector_to_user(pages, data, off, ret);
@@ -456,6 +460,7 @@ static ssize_t ceph_sync_write(struct file *file, const char __user *data,
456 int do_sync = 0; 460 int do_sync = 0;
457 int check_caps = 0; 461 int check_caps = 0;
458 int page_align, io_align; 462 int page_align, io_align;
463 unsigned long buf_align;
459 int ret; 464 int ret;
460 struct timespec mtime = CURRENT_TIME; 465 struct timespec mtime = CURRENT_TIME;
461 466
@@ -471,6 +476,7 @@ static ssize_t ceph_sync_write(struct file *file, const char __user *data,
471 pos = *offset; 476 pos = *offset;
472 477
473 io_align = pos & ~PAGE_MASK; 478 io_align = pos & ~PAGE_MASK;
479 buf_align = (unsigned long)data & ~PAGE_MASK;
474 480
475 ret = filemap_write_and_wait_range(inode->i_mapping, pos, pos + left); 481 ret = filemap_write_and_wait_range(inode->i_mapping, pos, pos + left);
476 if (ret < 0) 482 if (ret < 0)
@@ -496,12 +502,15 @@ static ssize_t ceph_sync_write(struct file *file, const char __user *data,
496 */ 502 */
497more: 503more:
498 len = left; 504 len = left;
499 if (file->f_flags & O_DIRECT) 505 if (file->f_flags & O_DIRECT) {
500 /* write from beginning of first page, regardless of 506 /* write from beginning of first page, regardless of
501 io alignment */ 507 io alignment */
502 page_align = (pos - io_align) & ~PAGE_MASK; 508 page_align = (pos - io_align + buf_align) & ~PAGE_MASK;
503 else 509 num_pages = calc_pages_for((unsigned long)data, len);
510 } else {
504 page_align = pos & ~PAGE_MASK; 511 page_align = pos & ~PAGE_MASK;
512 num_pages = calc_pages_for(pos, len);
513 }
505 req = ceph_osdc_new_request(&fsc->client->osdc, &ci->i_layout, 514 req = ceph_osdc_new_request(&fsc->client->osdc, &ci->i_layout,
506 ceph_vino(inode), pos, &len, 515 ceph_vino(inode), pos, &len,
507 CEPH_OSD_OP_WRITE, flags, 516 CEPH_OSD_OP_WRITE, flags,
@@ -512,8 +521,6 @@ more:
512 if (!req) 521 if (!req)
513 return -ENOMEM; 522 return -ENOMEM;
514 523
515 num_pages = calc_pages_for(pos, len);
516
517 if (file->f_flags & O_DIRECT) { 524 if (file->f_flags & O_DIRECT) {
518 pages = ceph_get_direct_page_vector(data, num_pages); 525 pages = ceph_get_direct_page_vector(data, num_pages);
519 if (IS_ERR(pages)) { 526 if (IS_ERR(pages)) {