Commit 9d5004fc authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/sage/ceph-client

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/sage/ceph-client:
  ceph: handle partial result from get_user_pages
  ceph: mark user pages dirty on direct-io reads
  ceph: fix null pointer dereference in ceph_init_dentry for nfs reexport
  ceph: fix direct-io on non-page-aligned buffers
  ceph: fix msgr_init error path
parents 453434cf 361cf405
...@@ -40,7 +40,8 @@ int ceph_init_dentry(struct dentry *dentry) ...@@ -40,7 +40,8 @@ int ceph_init_dentry(struct dentry *dentry)
if (dentry->d_fsdata) if (dentry->d_fsdata)
return 0; return 0;
if (ceph_snap(dentry->d_parent->d_inode) == CEPH_NOSNAP) if (dentry->d_parent == NULL || /* nfs fh_to_dentry */
ceph_snap(dentry->d_parent->d_inode) == CEPH_NOSNAP)
dentry->d_op = &ceph_dentry_ops; dentry->d_op = &ceph_dentry_ops;
else if (ceph_snap(dentry->d_parent->d_inode) == CEPH_SNAPDIR) else if (ceph_snap(dentry->d_parent->d_inode) == CEPH_SNAPDIR)
dentry->d_op = &ceph_snapdir_dentry_ops; dentry->d_op = &ceph_snapdir_dentry_ops;
......
...@@ -282,7 +282,8 @@ int ceph_release(struct inode *inode, struct file *file) ...@@ -282,7 +282,8 @@ int ceph_release(struct inode *inode, struct file *file)
static int striped_read(struct inode *inode, static int striped_read(struct inode *inode,
u64 off, u64 len, u64 off, u64 len,
struct page **pages, int num_pages, struct page **pages, int num_pages,
int *checkeof, bool align_to_pages) int *checkeof, bool align_to_pages,
unsigned long buf_align)
{ {
struct ceph_fs_client *fsc = ceph_inode_to_client(inode); struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
struct ceph_inode_info *ci = ceph_inode(inode); struct ceph_inode_info *ci = ceph_inode(inode);
...@@ -307,7 +308,7 @@ static int striped_read(struct inode *inode, ...@@ -307,7 +308,7 @@ static int striped_read(struct inode *inode,
more: more:
if (align_to_pages) if (align_to_pages)
page_align = (pos - io_align) & ~PAGE_MASK; page_align = (pos - io_align + buf_align) & ~PAGE_MASK;
else else
page_align = pos & ~PAGE_MASK; page_align = pos & ~PAGE_MASK;
this_len = left; this_len = left;
...@@ -376,16 +377,18 @@ static ssize_t ceph_sync_read(struct file *file, char __user *data, ...@@ -376,16 +377,18 @@ static ssize_t ceph_sync_read(struct file *file, char __user *data,
struct inode *inode = file->f_dentry->d_inode; struct inode *inode = file->f_dentry->d_inode;
struct page **pages; struct page **pages;
u64 off = *poff; u64 off = *poff;
int num_pages = calc_pages_for(off, len); int num_pages, ret;
int ret;
dout("sync_read on file %p %llu~%u %s\n", file, off, len, dout("sync_read on file %p %llu~%u %s\n", file, off, len,
(file->f_flags & O_DIRECT) ? "O_DIRECT" : ""); (file->f_flags & O_DIRECT) ? "O_DIRECT" : "");
if (file->f_flags & O_DIRECT) if (file->f_flags & O_DIRECT) {
pages = ceph_get_direct_page_vector(data, num_pages); num_pages = calc_pages_for((unsigned long)data, len);
else pages = ceph_get_direct_page_vector(data, num_pages, true);
} else {
num_pages = calc_pages_for(off, len);
pages = ceph_alloc_page_vector(num_pages, GFP_NOFS); pages = ceph_alloc_page_vector(num_pages, GFP_NOFS);
}
if (IS_ERR(pages)) if (IS_ERR(pages))
return PTR_ERR(pages); return PTR_ERR(pages);
...@@ -400,7 +403,8 @@ static ssize_t ceph_sync_read(struct file *file, char __user *data, ...@@ -400,7 +403,8 @@ static ssize_t ceph_sync_read(struct file *file, char __user *data,
goto done; goto done;
ret = striped_read(inode, off, len, pages, num_pages, checkeof, ret = striped_read(inode, off, len, pages, num_pages, checkeof,
file->f_flags & O_DIRECT); file->f_flags & O_DIRECT,
(unsigned long)data & ~PAGE_MASK);
if (ret >= 0 && (file->f_flags & O_DIRECT) == 0) if (ret >= 0 && (file->f_flags & O_DIRECT) == 0)
ret = ceph_copy_page_vector_to_user(pages, data, off, ret); ret = ceph_copy_page_vector_to_user(pages, data, off, ret);
...@@ -409,7 +413,7 @@ static ssize_t ceph_sync_read(struct file *file, char __user *data, ...@@ -409,7 +413,7 @@ static ssize_t ceph_sync_read(struct file *file, char __user *data,
done: done:
if (file->f_flags & O_DIRECT) if (file->f_flags & O_DIRECT)
ceph_put_page_vector(pages, num_pages); ceph_put_page_vector(pages, num_pages, true);
else else
ceph_release_page_vector(pages, num_pages); ceph_release_page_vector(pages, num_pages);
dout("sync_read result %d\n", ret); dout("sync_read result %d\n", ret);
...@@ -456,6 +460,7 @@ static ssize_t ceph_sync_write(struct file *file, const char __user *data, ...@@ -456,6 +460,7 @@ static ssize_t ceph_sync_write(struct file *file, const char __user *data,
int do_sync = 0; int do_sync = 0;
int check_caps = 0; int check_caps = 0;
int page_align, io_align; int page_align, io_align;
unsigned long buf_align;
int ret; int ret;
struct timespec mtime = CURRENT_TIME; struct timespec mtime = CURRENT_TIME;
...@@ -471,6 +476,7 @@ static ssize_t ceph_sync_write(struct file *file, const char __user *data, ...@@ -471,6 +476,7 @@ static ssize_t ceph_sync_write(struct file *file, const char __user *data,
pos = *offset; pos = *offset;
io_align = pos & ~PAGE_MASK; io_align = pos & ~PAGE_MASK;
buf_align = (unsigned long)data & ~PAGE_MASK;
ret = filemap_write_and_wait_range(inode->i_mapping, pos, pos + left); ret = filemap_write_and_wait_range(inode->i_mapping, pos, pos + left);
if (ret < 0) if (ret < 0)
...@@ -496,12 +502,15 @@ static ssize_t ceph_sync_write(struct file *file, const char __user *data, ...@@ -496,12 +502,15 @@ static ssize_t ceph_sync_write(struct file *file, const char __user *data,
*/ */
more: more:
len = left; len = left;
if (file->f_flags & O_DIRECT) if (file->f_flags & O_DIRECT) {
/* write from beginning of first page, regardless of /* write from beginning of first page, regardless of
io alignment */ io alignment */
page_align = (pos - io_align) & ~PAGE_MASK; page_align = (pos - io_align + buf_align) & ~PAGE_MASK;
else num_pages = calc_pages_for((unsigned long)data, len);
} else {
page_align = pos & ~PAGE_MASK; page_align = pos & ~PAGE_MASK;
num_pages = calc_pages_for(pos, len);
}
req = ceph_osdc_new_request(&fsc->client->osdc, &ci->i_layout, req = ceph_osdc_new_request(&fsc->client->osdc, &ci->i_layout,
ceph_vino(inode), pos, &len, ceph_vino(inode), pos, &len,
CEPH_OSD_OP_WRITE, flags, CEPH_OSD_OP_WRITE, flags,
...@@ -512,10 +521,8 @@ static ssize_t ceph_sync_write(struct file *file, const char __user *data, ...@@ -512,10 +521,8 @@ static ssize_t ceph_sync_write(struct file *file, const char __user *data,
if (!req) if (!req)
return -ENOMEM; return -ENOMEM;
num_pages = calc_pages_for(pos, len);
if (file->f_flags & O_DIRECT) { if (file->f_flags & O_DIRECT) {
pages = ceph_get_direct_page_vector(data, num_pages); pages = ceph_get_direct_page_vector(data, num_pages, false);
if (IS_ERR(pages)) { if (IS_ERR(pages)) {
ret = PTR_ERR(pages); ret = PTR_ERR(pages);
goto out; goto out;
...@@ -565,7 +572,7 @@ static ssize_t ceph_sync_write(struct file *file, const char __user *data, ...@@ -565,7 +572,7 @@ static ssize_t ceph_sync_write(struct file *file, const char __user *data,
} }
if (file->f_flags & O_DIRECT) if (file->f_flags & O_DIRECT)
ceph_put_page_vector(pages, num_pages); ceph_put_page_vector(pages, num_pages, false);
else if (file->f_flags & O_SYNC) else if (file->f_flags & O_SYNC)
ceph_release_page_vector(pages, num_pages); ceph_release_page_vector(pages, num_pages);
......
...@@ -227,8 +227,10 @@ extern int ceph_open_session(struct ceph_client *client); ...@@ -227,8 +227,10 @@ extern int ceph_open_session(struct ceph_client *client);
extern void ceph_release_page_vector(struct page **pages, int num_pages); extern void ceph_release_page_vector(struct page **pages, int num_pages);
extern struct page **ceph_get_direct_page_vector(const char __user *data, extern struct page **ceph_get_direct_page_vector(const char __user *data,
int num_pages); int num_pages,
extern void ceph_put_page_vector(struct page **pages, int num_pages); bool write_page);
extern void ceph_put_page_vector(struct page **pages, int num_pages,
bool dirty);
extern void ceph_release_page_vector(struct page **pages, int num_pages); extern void ceph_release_page_vector(struct page **pages, int num_pages);
extern struct page **ceph_alloc_page_vector(int num_pages, gfp_t flags); extern struct page **ceph_alloc_page_vector(int num_pages, gfp_t flags);
extern int ceph_copy_user_to_page_vector(struct page **pages, extern int ceph_copy_user_to_page_vector(struct page **pages,
......
...@@ -97,11 +97,9 @@ struct workqueue_struct *ceph_msgr_wq; ...@@ -97,11 +97,9 @@ struct workqueue_struct *ceph_msgr_wq;
int ceph_msgr_init(void) int ceph_msgr_init(void)
{ {
ceph_msgr_wq = create_workqueue("ceph-msgr"); ceph_msgr_wq = create_workqueue("ceph-msgr");
if (IS_ERR(ceph_msgr_wq)) { if (!ceph_msgr_wq) {
int ret = PTR_ERR(ceph_msgr_wq); pr_err("msgr_init failed to create workqueue\n");
pr_err("msgr_init failed to create workqueue: %d\n", ret); return -ENOMEM;
ceph_msgr_wq = NULL;
return ret;
} }
return 0; return 0;
} }
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* build a vector of user pages * build a vector of user pages
*/ */
struct page **ceph_get_direct_page_vector(const char __user *data, struct page **ceph_get_direct_page_vector(const char __user *data,
int num_pages) int num_pages, bool write_page)
{ {
struct page **pages; struct page **pages;
int rc; int rc;
...@@ -24,24 +24,27 @@ struct page **ceph_get_direct_page_vector(const char __user *data, ...@@ -24,24 +24,27 @@ struct page **ceph_get_direct_page_vector(const char __user *data,
down_read(&current->mm->mmap_sem); down_read(&current->mm->mmap_sem);
rc = get_user_pages(current, current->mm, (unsigned long)data, rc = get_user_pages(current, current->mm, (unsigned long)data,
num_pages, 0, 0, pages, NULL); num_pages, write_page, 0, pages, NULL);
up_read(&current->mm->mmap_sem); up_read(&current->mm->mmap_sem);
if (rc < 0) if (rc < num_pages)
goto fail; goto fail;
return pages; return pages;
fail: fail:
kfree(pages); ceph_put_page_vector(pages, rc > 0 ? rc : 0, false);
return ERR_PTR(rc); return ERR_PTR(rc);
} }
EXPORT_SYMBOL(ceph_get_direct_page_vector); EXPORT_SYMBOL(ceph_get_direct_page_vector);
void ceph_put_page_vector(struct page **pages, int num_pages) void ceph_put_page_vector(struct page **pages, int num_pages, bool dirty)
{ {
int i; int i;
for (i = 0; i < num_pages; i++) for (i = 0; i < num_pages; i++) {
if (dirty)
set_page_dirty_lock(pages[i]);
put_page(pages[i]); put_page(pages[i]);
}
kfree(pages); kfree(pages);
} }
EXPORT_SYMBOL(ceph_put_page_vector); EXPORT_SYMBOL(ceph_put_page_vector);
......
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