提交 91f85756 编写于 作者: L Linus Torvalds

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

Pull Ceph changes from Alex Elder:
 "This is a big pull.

  Most of it is culmination of Alex's work to implement RBD image
  layering, which is now complete (yay!).

  There is also some work from Yan to fix i_mutex behavior surrounding
  writes in cephfs, a sync write fix, a fix for RBD images that get
  resized while they are mapped, and a few patches from me that resolve
  annoying auth warnings and fix several bugs in the ceph auth code."

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/sage/ceph-client: (254 commits)
  rbd: fix image request leak on parent read
  libceph: use slab cache for osd client requests
  libceph: allocate ceph message data with a slab allocator
  libceph: allocate ceph messages with a slab allocator
  rbd: allocate image object names with a slab allocator
  rbd: allocate object requests with a slab allocator
  rbd: allocate name separate from obj_request
  rbd: allocate image requests with a slab allocator
  rbd: use binary search for snapshot lookup
  rbd: clear EXISTS flag if mapped snapshot disappears
  rbd: kill off the snapshot list
  rbd: define rbd_snap_size() and rbd_snap_features()
  rbd: use snap_id not index to look up snap info
  rbd: look up snapshot name in names buffer
  rbd: drop obj_request->version
  rbd: drop rbd_obj_method_sync() version parameter
  rbd: more version parameter removal
  rbd: get rid of some version parameters
  rbd: stop tracking header object version
  rbd: snap names are pointer to constant data
  ...
...@@ -66,27 +66,7 @@ current_snap ...@@ -66,27 +66,7 @@ current_snap
The current snapshot for which the device is mapped. The current snapshot for which the device is mapped.
snap_*
A directory per each snapshot
parent parent
Information identifying the pool, image, and snapshot id for Information identifying the pool, image, and snapshot id for
the parent image in a layered rbd image (format 2 only). the parent image in a layered rbd image (format 2 only).
Entries under /sys/bus/rbd/devices/<dev-id>/snap_<snap-name>
-------------------------------------------------------------
snap_id
The rados internal snapshot id assigned for this snapshot
snap_size
The size of the image when this snapshot was taken.
snap_features
A hexadecimal encoding of the feature bits for this snapshot.
此差异已折叠。
...@@ -236,15 +236,21 @@ static int ceph_readpage(struct file *filp, struct page *page) ...@@ -236,15 +236,21 @@ static int ceph_readpage(struct file *filp, struct page *page)
static void finish_read(struct ceph_osd_request *req, struct ceph_msg *msg) static void finish_read(struct ceph_osd_request *req, struct ceph_msg *msg)
{ {
struct inode *inode = req->r_inode; struct inode *inode = req->r_inode;
struct ceph_osd_data *osd_data;
int rc = req->r_result; int rc = req->r_result;
int bytes = le32_to_cpu(msg->hdr.data_len); int bytes = le32_to_cpu(msg->hdr.data_len);
int num_pages;
int i; int i;
dout("finish_read %p req %p rc %d bytes %d\n", inode, req, rc, bytes); dout("finish_read %p req %p rc %d bytes %d\n", inode, req, rc, bytes);
/* unlock all pages, zeroing any data we didn't read */ /* unlock all pages, zeroing any data we didn't read */
for (i = 0; i < req->r_num_pages; i++, bytes -= PAGE_CACHE_SIZE) { osd_data = osd_req_op_extent_osd_data(req, 0);
struct page *page = req->r_pages[i]; BUG_ON(osd_data->type != CEPH_OSD_DATA_TYPE_PAGES);
num_pages = calc_pages_for((u64)osd_data->alignment,
(u64)osd_data->length);
for (i = 0; i < num_pages; i++) {
struct page *page = osd_data->pages[i];
if (bytes < (int)PAGE_CACHE_SIZE) { if (bytes < (int)PAGE_CACHE_SIZE) {
/* zero (remainder of) page */ /* zero (remainder of) page */
...@@ -257,8 +263,9 @@ static void finish_read(struct ceph_osd_request *req, struct ceph_msg *msg) ...@@ -257,8 +263,9 @@ static void finish_read(struct ceph_osd_request *req, struct ceph_msg *msg)
SetPageUptodate(page); SetPageUptodate(page);
unlock_page(page); unlock_page(page);
page_cache_release(page); page_cache_release(page);
bytes -= PAGE_CACHE_SIZE;
} }
kfree(req->r_pages); kfree(osd_data->pages);
} }
static void ceph_unlock_page_vector(struct page **pages, int num_pages) static void ceph_unlock_page_vector(struct page **pages, int num_pages)
...@@ -279,6 +286,7 @@ static int start_read(struct inode *inode, struct list_head *page_list, int max) ...@@ -279,6 +286,7 @@ static int start_read(struct inode *inode, struct list_head *page_list, int max)
&ceph_inode_to_client(inode)->client->osdc; &ceph_inode_to_client(inode)->client->osdc;
struct ceph_inode_info *ci = ceph_inode(inode); struct ceph_inode_info *ci = ceph_inode(inode);
struct page *page = list_entry(page_list->prev, struct page, lru); struct page *page = list_entry(page_list->prev, struct page, lru);
struct ceph_vino vino;
struct ceph_osd_request *req; struct ceph_osd_request *req;
u64 off; u64 off;
u64 len; u64 len;
...@@ -303,18 +311,17 @@ static int start_read(struct inode *inode, struct list_head *page_list, int max) ...@@ -303,18 +311,17 @@ static int start_read(struct inode *inode, struct list_head *page_list, int max)
len = nr_pages << PAGE_CACHE_SHIFT; len = nr_pages << PAGE_CACHE_SHIFT;
dout("start_read %p nr_pages %d is %lld~%lld\n", inode, nr_pages, dout("start_read %p nr_pages %d is %lld~%lld\n", inode, nr_pages,
off, len); off, len);
vino = ceph_vino(inode);
req = ceph_osdc_new_request(osdc, &ci->i_layout, ceph_vino(inode), req = ceph_osdc_new_request(osdc, &ci->i_layout, vino, off, &len,
off, &len, 1, CEPH_OSD_OP_READ,
CEPH_OSD_OP_READ, CEPH_OSD_FLAG_READ, CEPH_OSD_FLAG_READ, NULL,
NULL, 0,
ci->i_truncate_seq, ci->i_truncate_size, ci->i_truncate_seq, ci->i_truncate_size,
NULL, false, 0); false);
if (IS_ERR(req)) if (IS_ERR(req))
return PTR_ERR(req); return PTR_ERR(req);
/* build page vector */ /* build page vector */
nr_pages = len >> PAGE_CACHE_SHIFT; nr_pages = calc_pages_for(0, len);
pages = kmalloc(sizeof(*pages) * nr_pages, GFP_NOFS); pages = kmalloc(sizeof(*pages) * nr_pages, GFP_NOFS);
ret = -ENOMEM; ret = -ENOMEM;
if (!pages) if (!pages)
...@@ -336,11 +343,12 @@ static int start_read(struct inode *inode, struct list_head *page_list, int max) ...@@ -336,11 +343,12 @@ static int start_read(struct inode *inode, struct list_head *page_list, int max)
} }
pages[i] = page; pages[i] = page;
} }
req->r_pages = pages; osd_req_op_extent_osd_data_pages(req, 0, pages, len, 0, false, false);
req->r_num_pages = nr_pages;
req->r_callback = finish_read; req->r_callback = finish_read;
req->r_inode = inode; req->r_inode = inode;
ceph_osdc_build_request(req, off, NULL, vino.snap, NULL);
dout("start_read %p starting %p %lld~%lld\n", inode, req, off, len); dout("start_read %p starting %p %lld~%lld\n", inode, req, off, len);
ret = ceph_osdc_start_request(osdc, req, false); ret = ceph_osdc_start_request(osdc, req, false);
if (ret < 0) if (ret < 0)
...@@ -373,7 +381,8 @@ static int ceph_readpages(struct file *file, struct address_space *mapping, ...@@ -373,7 +381,8 @@ static int ceph_readpages(struct file *file, struct address_space *mapping,
max = (fsc->mount_options->rsize + PAGE_CACHE_SIZE - 1) max = (fsc->mount_options->rsize + PAGE_CACHE_SIZE - 1)
>> PAGE_SHIFT; >> PAGE_SHIFT;
dout("readpages %p file %p nr_pages %d max %d\n", inode, file, nr_pages, dout("readpages %p file %p nr_pages %d max %d\n", inode,
file, nr_pages,
max); max);
while (!list_empty(page_list)) { while (!list_empty(page_list)) {
rc = start_read(inode, page_list, max); rc = start_read(inode, page_list, max);
...@@ -548,17 +557,23 @@ static void writepages_finish(struct ceph_osd_request *req, ...@@ -548,17 +557,23 @@ static void writepages_finish(struct ceph_osd_request *req,
{ {
struct inode *inode = req->r_inode; struct inode *inode = req->r_inode;
struct ceph_inode_info *ci = ceph_inode(inode); struct ceph_inode_info *ci = ceph_inode(inode);
struct ceph_osd_data *osd_data;
unsigned wrote; unsigned wrote;
struct page *page; struct page *page;
int num_pages;
int i; int i;
struct ceph_snap_context *snapc = req->r_snapc; struct ceph_snap_context *snapc = req->r_snapc;
struct address_space *mapping = inode->i_mapping; struct address_space *mapping = inode->i_mapping;
int rc = req->r_result; int rc = req->r_result;
u64 bytes = le64_to_cpu(req->r_request_ops[0].extent.length); u64 bytes = req->r_ops[0].extent.length;
struct ceph_fs_client *fsc = ceph_inode_to_client(inode); struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
long writeback_stat; long writeback_stat;
unsigned issued = ceph_caps_issued(ci); unsigned issued = ceph_caps_issued(ci);
osd_data = osd_req_op_extent_osd_data(req, 0);
BUG_ON(osd_data->type != CEPH_OSD_DATA_TYPE_PAGES);
num_pages = calc_pages_for((u64)osd_data->alignment,
(u64)osd_data->length);
if (rc >= 0) { if (rc >= 0) {
/* /*
* Assume we wrote the pages we originally sent. The * Assume we wrote the pages we originally sent. The
...@@ -566,7 +581,7 @@ static void writepages_finish(struct ceph_osd_request *req, ...@@ -566,7 +581,7 @@ static void writepages_finish(struct ceph_osd_request *req,
* raced with a truncation and was adjusted at the osd, * raced with a truncation and was adjusted at the osd,
* so don't believe the reply. * so don't believe the reply.
*/ */
wrote = req->r_num_pages; wrote = num_pages;
} else { } else {
wrote = 0; wrote = 0;
mapping_set_error(mapping, rc); mapping_set_error(mapping, rc);
...@@ -575,8 +590,8 @@ static void writepages_finish(struct ceph_osd_request *req, ...@@ -575,8 +590,8 @@ static void writepages_finish(struct ceph_osd_request *req,
inode, rc, bytes, wrote); inode, rc, bytes, wrote);
/* clean all pages */ /* clean all pages */
for (i = 0; i < req->r_num_pages; i++) { for (i = 0; i < num_pages; i++) {
page = req->r_pages[i]; page = osd_data->pages[i];
BUG_ON(!page); BUG_ON(!page);
WARN_ON(!PageUptodate(page)); WARN_ON(!PageUptodate(page));
...@@ -605,32 +620,34 @@ static void writepages_finish(struct ceph_osd_request *req, ...@@ -605,32 +620,34 @@ static void writepages_finish(struct ceph_osd_request *req,
unlock_page(page); unlock_page(page);
} }
dout("%p wrote+cleaned %d pages\n", inode, wrote); dout("%p wrote+cleaned %d pages\n", inode, wrote);
ceph_put_wrbuffer_cap_refs(ci, req->r_num_pages, snapc); ceph_put_wrbuffer_cap_refs(ci, num_pages, snapc);
ceph_release_pages(req->r_pages, req->r_num_pages); ceph_release_pages(osd_data->pages, num_pages);
if (req->r_pages_from_pool) if (osd_data->pages_from_pool)
mempool_free(req->r_pages, mempool_free(osd_data->pages,
ceph_sb_to_client(inode->i_sb)->wb_pagevec_pool); ceph_sb_to_client(inode->i_sb)->wb_pagevec_pool);
else else
kfree(req->r_pages); kfree(osd_data->pages);
ceph_osdc_put_request(req); ceph_osdc_put_request(req);
} }
/* static struct ceph_osd_request *
* allocate a page vec, either directly, or if necessary, via a the ceph_writepages_osd_request(struct inode *inode, u64 offset, u64 *len,
* mempool. we avoid the mempool if we can because req->r_num_pages struct ceph_snap_context *snapc, int num_ops)
* may be less than the maximum write size.
*/
static void alloc_page_vec(struct ceph_fs_client *fsc,
struct ceph_osd_request *req)
{ {
req->r_pages = kmalloc(sizeof(struct page *) * req->r_num_pages, struct ceph_fs_client *fsc;
GFP_NOFS); struct ceph_inode_info *ci;
if (!req->r_pages) { struct ceph_vino vino;
req->r_pages = mempool_alloc(fsc->wb_pagevec_pool, GFP_NOFS);
req->r_pages_from_pool = 1; fsc = ceph_inode_to_client(inode);
WARN_ON(!req->r_pages); ci = ceph_inode(inode);
} vino = ceph_vino(inode);
/* BUG_ON(vino.snap != CEPH_NOSNAP); */
return ceph_osdc_new_request(&fsc->client->osdc, &ci->i_layout,
vino, offset, len, num_ops, CEPH_OSD_OP_WRITE,
CEPH_OSD_FLAG_WRITE|CEPH_OSD_FLAG_ONDISK,
snapc, ci->i_truncate_seq, ci->i_truncate_size, true);
} }
/* /*
...@@ -653,7 +670,7 @@ static int ceph_writepages_start(struct address_space *mapping, ...@@ -653,7 +670,7 @@ static int ceph_writepages_start(struct address_space *mapping,
unsigned wsize = 1 << inode->i_blkbits; unsigned wsize = 1 << inode->i_blkbits;
struct ceph_osd_request *req = NULL; struct ceph_osd_request *req = NULL;
int do_sync; int do_sync;
u64 snap_size = 0; u64 snap_size;
/* /*
* Include a 'sync' in the OSD request if this is a data * Include a 'sync' in the OSD request if this is a data
...@@ -699,6 +716,7 @@ static int ceph_writepages_start(struct address_space *mapping, ...@@ -699,6 +716,7 @@ static int ceph_writepages_start(struct address_space *mapping,
retry: retry:
/* find oldest snap context with dirty data */ /* find oldest snap context with dirty data */
ceph_put_snap_context(snapc); ceph_put_snap_context(snapc);
snap_size = 0;
snapc = get_oldest_context(inode, &snap_size); snapc = get_oldest_context(inode, &snap_size);
if (!snapc) { if (!snapc) {
/* hmm, why does writepages get called when there /* hmm, why does writepages get called when there
...@@ -706,6 +724,8 @@ static int ceph_writepages_start(struct address_space *mapping, ...@@ -706,6 +724,8 @@ static int ceph_writepages_start(struct address_space *mapping,
dout(" no snap context with dirty data?\n"); dout(" no snap context with dirty data?\n");
goto out; goto out;
} }
if (snap_size == 0)
snap_size = i_size_read(inode);
dout(" oldest snapc is %p seq %lld (%d snaps)\n", dout(" oldest snapc is %p seq %lld (%d snaps)\n",
snapc, snapc->seq, snapc->num_snaps); snapc, snapc->seq, snapc->num_snaps);
if (last_snapc && snapc != last_snapc) { if (last_snapc && snapc != last_snapc) {
...@@ -718,10 +738,14 @@ static int ceph_writepages_start(struct address_space *mapping, ...@@ -718,10 +738,14 @@ static int ceph_writepages_start(struct address_space *mapping,
last_snapc = snapc; last_snapc = snapc;
while (!done && index <= end) { while (!done && index <= end) {
int num_ops = do_sync ? 2 : 1;
struct ceph_vino vino;
unsigned i; unsigned i;
int first; int first;
pgoff_t next; pgoff_t next;
int pvec_pages, locked_pages; int pvec_pages, locked_pages;
struct page **pages = NULL;
mempool_t *pool = NULL; /* Becomes non-null if mempool used */
struct page *page; struct page *page;
int want; int want;
u64 offset, len; u64 offset, len;
...@@ -773,11 +797,8 @@ static int ceph_writepages_start(struct address_space *mapping, ...@@ -773,11 +797,8 @@ static int ceph_writepages_start(struct address_space *mapping,
dout("waiting on writeback %p\n", page); dout("waiting on writeback %p\n", page);
wait_on_page_writeback(page); wait_on_page_writeback(page);
} }
if ((snap_size && page_offset(page) > snap_size) || if (page_offset(page) >= snap_size) {
(!snap_size && dout("%p page eof %llu\n", page, snap_size);
page_offset(page) > i_size_read(inode))) {
dout("%p page eof %llu\n", page, snap_size ?
snap_size : i_size_read(inode));
done = 1; done = 1;
unlock_page(page); unlock_page(page);
break; break;
...@@ -805,22 +826,23 @@ static int ceph_writepages_start(struct address_space *mapping, ...@@ -805,22 +826,23 @@ static int ceph_writepages_start(struct address_space *mapping,
break; break;
} }
/* ok */ /*
* We have something to write. If this is
* the first locked page this time through,
* allocate an osd request and a page array
* that it will use.
*/
if (locked_pages == 0) { if (locked_pages == 0) {
size_t size;
BUG_ON(pages);
/* prepare async write request */ /* prepare async write request */
offset = (u64) page_offset(page); offset = (u64)page_offset(page);
len = wsize; len = wsize;
req = ceph_osdc_new_request(&fsc->client->osdc, req = ceph_writepages_osd_request(inode,
&ci->i_layout, offset, &len, snapc,
ceph_vino(inode), num_ops);
offset, &len,
CEPH_OSD_OP_WRITE,
CEPH_OSD_FLAG_WRITE |
CEPH_OSD_FLAG_ONDISK,
snapc, do_sync,
ci->i_truncate_seq,
ci->i_truncate_size,
&inode->i_mtime, true, 0);
if (IS_ERR(req)) { if (IS_ERR(req)) {
rc = PTR_ERR(req); rc = PTR_ERR(req);
...@@ -828,11 +850,17 @@ static int ceph_writepages_start(struct address_space *mapping, ...@@ -828,11 +850,17 @@ static int ceph_writepages_start(struct address_space *mapping,
break; break;
} }
max_pages = req->r_num_pages;
alloc_page_vec(fsc, req);
req->r_callback = writepages_finish; req->r_callback = writepages_finish;
req->r_inode = inode; req->r_inode = inode;
max_pages = calc_pages_for(0, (u64)len);
size = max_pages * sizeof (*pages);
pages = kmalloc(size, GFP_NOFS);
if (!pages) {
pool = fsc->wb_pagevec_pool;
pages = mempool_alloc(pool, GFP_NOFS);
BUG_ON(!pages);
}
} }
/* note position of first page in pvec */ /* note position of first page in pvec */
...@@ -850,7 +878,7 @@ static int ceph_writepages_start(struct address_space *mapping, ...@@ -850,7 +878,7 @@ static int ceph_writepages_start(struct address_space *mapping,
} }
set_page_writeback(page); set_page_writeback(page);
req->r_pages[locked_pages] = page; pages[locked_pages] = page;
locked_pages++; locked_pages++;
next = page->index + 1; next = page->index + 1;
} }
...@@ -879,18 +907,27 @@ static int ceph_writepages_start(struct address_space *mapping, ...@@ -879,18 +907,27 @@ static int ceph_writepages_start(struct address_space *mapping,
pvec.nr -= i-first; pvec.nr -= i-first;
} }
/* submit the write */ /* Format the osd request message and submit the write */
offset = req->r_pages[0]->index << PAGE_CACHE_SHIFT;
len = min((snap_size ? snap_size : i_size_read(inode)) - offset, offset = page_offset(pages[0]);
len = min(snap_size - offset,
(u64)locked_pages << PAGE_CACHE_SHIFT); (u64)locked_pages << PAGE_CACHE_SHIFT);
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);
/* revise final length, page count */ osd_req_op_extent_osd_data_pages(req, 0, pages, len, 0,
req->r_num_pages = locked_pages; !!pool, false);
req->r_request_ops[0].extent.length = cpu_to_le64(len);
req->r_request_ops[0].payload_len = cpu_to_le32(len); pages = NULL; /* request message now owns the pages array */
req->r_request->hdr.data_len = cpu_to_le32(len); pool = NULL;
/* Update the write op length in case we changed it */
osd_req_op_extent_update(req, 0, len);
vino = ceph_vino(inode);
ceph_osdc_build_request(req, offset, snapc, vino.snap,
&inode->i_mtime);
rc = ceph_osdc_start_request(&fsc->client->osdc, req, true); rc = ceph_osdc_start_request(&fsc->client->osdc, req, true);
BUG_ON(rc); BUG_ON(rc);
...@@ -1067,51 +1104,23 @@ static int ceph_write_begin(struct file *file, struct address_space *mapping, ...@@ -1067,51 +1104,23 @@ static int ceph_write_begin(struct file *file, struct address_space *mapping,
struct page **pagep, void **fsdata) struct page **pagep, void **fsdata)
{ {
struct inode *inode = file_inode(file); struct inode *inode = file_inode(file);
struct ceph_inode_info *ci = ceph_inode(inode);
struct ceph_file_info *fi = file->private_data;
struct page *page; struct page *page;
pgoff_t index = pos >> PAGE_CACHE_SHIFT; pgoff_t index = pos >> PAGE_CACHE_SHIFT;
int r, want, got = 0; int r;
if (fi->fmode & CEPH_FILE_MODE_LAZY)
want = CEPH_CAP_FILE_BUFFER | CEPH_CAP_FILE_LAZYIO;
else
want = CEPH_CAP_FILE_BUFFER;
dout("write_begin %p %llx.%llx %llu~%u getting caps. i_size %llu\n",
inode, ceph_vinop(inode), pos, len, inode->i_size);
r = ceph_get_caps(ci, CEPH_CAP_FILE_WR, want, &got, pos+len);
if (r < 0)
return r;
dout("write_begin %p %llx.%llx %llu~%u got cap refs on %s\n",
inode, ceph_vinop(inode), pos, len, ceph_cap_string(got));
if (!(got & (CEPH_CAP_FILE_BUFFER|CEPH_CAP_FILE_LAZYIO))) {
ceph_put_cap_refs(ci, got);
return -EAGAIN;
}
do { do {
/* get a page */ /* get a page */
page = grab_cache_page_write_begin(mapping, index, 0); page = grab_cache_page_write_begin(mapping, index, 0);
if (!page) { if (!page)
r = -ENOMEM; return -ENOMEM;
break; *pagep = page;
}
dout("write_begin file %p inode %p page %p %d~%d\n", file, dout("write_begin file %p inode %p page %p %d~%d\n", file,
inode, page, (int)pos, (int)len); inode, page, (int)pos, (int)len);
r = ceph_update_writeable_page(file, pos, len, page); r = ceph_update_writeable_page(file, pos, len, page);
if (r)
page_cache_release(page);
} while (r == -EAGAIN); } while (r == -EAGAIN);
if (r) {
ceph_put_cap_refs(ci, got);
} else {
*pagep = page;
*(int *)fsdata = got;
}
return r; return r;
} }
...@@ -1125,12 +1134,10 @@ static int ceph_write_end(struct file *file, struct address_space *mapping, ...@@ -1125,12 +1134,10 @@ static int ceph_write_end(struct file *file, struct address_space *mapping,
struct page *page, void *fsdata) struct page *page, void *fsdata)
{ {
struct inode *inode = file_inode(file); struct inode *inode = file_inode(file);
struct ceph_inode_info *ci = ceph_inode(inode);
struct ceph_fs_client *fsc = ceph_inode_to_client(inode); struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
struct ceph_mds_client *mdsc = fsc->mdsc; struct ceph_mds_client *mdsc = fsc->mdsc;
unsigned from = pos & (PAGE_CACHE_SIZE - 1); unsigned from = pos & (PAGE_CACHE_SIZE - 1);
int check_cap = 0; int check_cap = 0;
int got = (unsigned long)fsdata;
dout("write_end file %p inode %p page %p %d~%d (%d)\n", file, dout("write_end file %p inode %p page %p %d~%d (%d)\n", file,
inode, page, (int)pos, (int)copied, (int)len); inode, page, (int)pos, (int)copied, (int)len);
...@@ -1153,19 +1160,6 @@ static int ceph_write_end(struct file *file, struct address_space *mapping, ...@@ -1153,19 +1160,6 @@ static int ceph_write_end(struct file *file, struct address_space *mapping,
up_read(&mdsc->snap_rwsem); up_read(&mdsc->snap_rwsem);
page_cache_release(page); page_cache_release(page);
if (copied > 0) {
int dirty;
spin_lock(&ci->i_ceph_lock);
dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_FILE_WR);
spin_unlock(&ci->i_ceph_lock);
if (dirty)
__mark_inode_dirty(inode, dirty);
}
dout("write_end %p %llx.%llx %llu~%u dropping cap refs on %s\n",
inode, ceph_vinop(inode), pos, len, ceph_cap_string(got));
ceph_put_cap_refs(ci, got);
if (check_cap) if (check_cap)
ceph_check_caps(ceph_inode(inode), CHECK_CAPS_AUTHONLY, NULL); ceph_check_caps(ceph_inode(inode), CHECK_CAPS_AUTHONLY, NULL);
......
...@@ -490,15 +490,17 @@ static void __check_cap_issue(struct ceph_inode_info *ci, struct ceph_cap *cap, ...@@ -490,15 +490,17 @@ static void __check_cap_issue(struct ceph_inode_info *ci, struct ceph_cap *cap,
ci->i_rdcache_gen++; ci->i_rdcache_gen++;
/* /*
* if we are newly issued FILE_SHARED, clear D_COMPLETE; we * if we are newly issued FILE_SHARED, mark dir not complete; we
* don't know what happened to this directory while we didn't * don't know what happened to this directory while we didn't
* have the cap. * have the cap.
*/ */
if ((issued & CEPH_CAP_FILE_SHARED) && if ((issued & CEPH_CAP_FILE_SHARED) &&
(had & CEPH_CAP_FILE_SHARED) == 0) { (had & CEPH_CAP_FILE_SHARED) == 0) {
ci->i_shared_gen++; ci->i_shared_gen++;
if (S_ISDIR(ci->vfs_inode.i_mode)) if (S_ISDIR(ci->vfs_inode.i_mode)) {
ceph_dir_clear_complete(&ci->vfs_inode); dout(" marking %p NOT complete\n", &ci->vfs_inode);
__ceph_dir_clear_complete(ci);
}
} }
} }
...@@ -553,6 +555,7 @@ int ceph_add_cap(struct inode *inode, ...@@ -553,6 +555,7 @@ int ceph_add_cap(struct inode *inode,
cap->implemented = 0; cap->implemented = 0;
cap->mds = mds; cap->mds = mds;
cap->mds_wanted = 0; cap->mds_wanted = 0;
cap->mseq = 0;
cap->ci = ci; cap->ci = ci;
__insert_cap_node(ci, cap); __insert_cap_node(ci, cap);
...@@ -628,7 +631,10 @@ int ceph_add_cap(struct inode *inode, ...@@ -628,7 +631,10 @@ int ceph_add_cap(struct inode *inode,
cap->cap_id = cap_id; cap->cap_id = cap_id;
cap->issued = issued; cap->issued = issued;
cap->implemented |= issued; cap->implemented |= issued;
cap->mds_wanted |= wanted; if (mseq > cap->mseq)
cap->mds_wanted = wanted;
else
cap->mds_wanted |= wanted;
cap->seq = seq; cap->seq = seq;
cap->issue_seq = seq; cap->issue_seq = seq;
cap->mseq = mseq; cap->mseq = mseq;
...@@ -997,9 +1003,9 @@ static int send_cap_msg(struct ceph_mds_session *session, ...@@ -997,9 +1003,9 @@ static int send_cap_msg(struct ceph_mds_session *session,
return 0; return 0;
} }
static void __queue_cap_release(struct ceph_mds_session *session, void __queue_cap_release(struct ceph_mds_session *session,
u64 ino, u64 cap_id, u32 migrate_seq, u64 ino, u64 cap_id, u32 migrate_seq,
u32 issue_seq) u32 issue_seq)
{ {
struct ceph_msg *msg; struct ceph_msg *msg;
struct ceph_mds_cap_release *head; struct ceph_mds_cap_release *head;
...@@ -2046,6 +2052,13 @@ static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want, ...@@ -2046,6 +2052,13 @@ static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want,
goto out; goto out;
} }
/* finish pending truncate */
while (ci->i_truncate_pending) {
spin_unlock(&ci->i_ceph_lock);
__ceph_do_pending_vmtruncate(inode, !(need & CEPH_CAP_FILE_WR));
spin_lock(&ci->i_ceph_lock);
}
if (need & CEPH_CAP_FILE_WR) { if (need & CEPH_CAP_FILE_WR) {
if (endoff >= 0 && endoff > (loff_t)ci->i_max_size) { if (endoff >= 0 && endoff > (loff_t)ci->i_max_size) {
dout("get_cap_refs %p endoff %llu > maxsize %llu\n", dout("get_cap_refs %p endoff %llu > maxsize %llu\n",
...@@ -2067,12 +2080,6 @@ static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want, ...@@ -2067,12 +2080,6 @@ static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want,
} }
have = __ceph_caps_issued(ci, &implemented); have = __ceph_caps_issued(ci, &implemented);
/*
* disallow writes while a truncate is pending
*/
if (ci->i_truncate_pending)
have &= ~CEPH_CAP_FILE_WR;
if ((have & need) == need) { if ((have & need) == need) {
/* /*
* Look at (implemented & ~have & not) so that we keep waiting * Look at (implemented & ~have & not) so that we keep waiting
......
...@@ -107,7 +107,7 @@ static unsigned fpos_off(loff_t p) ...@@ -107,7 +107,7 @@ static unsigned fpos_off(loff_t p)
* falling back to a "normal" sync readdir if any dentries in the dir * falling back to a "normal" sync readdir if any dentries in the dir
* are dropped. * are dropped.
* *
* D_COMPLETE tells indicates we have all dentries in the dir. It is * Complete dir indicates that we have all dentries in the dir. It is
* defined IFF we hold CEPH_CAP_FILE_SHARED (which will be revoked by * defined IFF we hold CEPH_CAP_FILE_SHARED (which will be revoked by
* the MDS if/when the directory is modified). * the MDS if/when the directory is modified).
*/ */
...@@ -198,8 +198,8 @@ static int __dcache_readdir(struct file *filp, ...@@ -198,8 +198,8 @@ static int __dcache_readdir(struct file *filp,
filp->f_pos++; filp->f_pos++;
/* make sure a dentry wasn't dropped while we didn't have parent lock */ /* make sure a dentry wasn't dropped while we didn't have parent lock */
if (!ceph_dir_test_complete(dir)) { if (!ceph_dir_is_complete(dir)) {
dout(" lost D_COMPLETE on %p; falling back to mds\n", dir); dout(" lost dir complete on %p; falling back to mds\n", dir);
err = -EAGAIN; err = -EAGAIN;
goto out; goto out;
} }
...@@ -258,7 +258,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir) ...@@ -258,7 +258,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
if (filp->f_pos == 0) { if (filp->f_pos == 0) {
/* note dir version at start of readdir so we can tell /* note dir version at start of readdir so we can tell
* if any dentries get dropped */ * if any dentries get dropped */
fi->dir_release_count = ci->i_release_count; fi->dir_release_count = atomic_read(&ci->i_release_count);
dout("readdir off 0 -> '.'\n"); dout("readdir off 0 -> '.'\n");
if (filldir(dirent, ".", 1, ceph_make_fpos(0, 0), if (filldir(dirent, ".", 1, ceph_make_fpos(0, 0),
...@@ -284,7 +284,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir) ...@@ -284,7 +284,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
if ((filp->f_pos == 2 || fi->dentry) && if ((filp->f_pos == 2 || fi->dentry) &&
!ceph_test_mount_opt(fsc, NOASYNCREADDIR) && !ceph_test_mount_opt(fsc, NOASYNCREADDIR) &&
ceph_snap(inode) != CEPH_SNAPDIR && ceph_snap(inode) != CEPH_SNAPDIR &&
ceph_dir_test_complete(inode) && __ceph_dir_is_complete(ci) &&
__ceph_caps_issued_mask(ci, CEPH_CAP_FILE_SHARED, 1)) { __ceph_caps_issued_mask(ci, CEPH_CAP_FILE_SHARED, 1)) {
spin_unlock(&ci->i_ceph_lock); spin_unlock(&ci->i_ceph_lock);
err = __dcache_readdir(filp, dirent, filldir); err = __dcache_readdir(filp, dirent, filldir);
...@@ -350,7 +350,8 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir) ...@@ -350,7 +350,8 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
if (!req->r_did_prepopulate) { if (!req->r_did_prepopulate) {
dout("readdir !did_prepopulate"); dout("readdir !did_prepopulate");
fi->dir_release_count--; /* preclude D_COMPLETE */ /* preclude from marking dir complete */
fi->dir_release_count--;
} }
/* note next offset and last dentry name */ /* note next offset and last dentry name */
...@@ -428,8 +429,9 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir) ...@@ -428,8 +429,9 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
* the complete dir contents in our cache. * the complete dir contents in our cache.
*/ */
spin_lock(&ci->i_ceph_lock); spin_lock(&ci->i_ceph_lock);
if (ci->i_release_count == fi->dir_release_count) { if (atomic_read(&ci->i_release_count) == fi->dir_release_count) {
ceph_dir_set_complete(inode); dout(" marking %p complete\n", inode);
__ceph_dir_set_complete(ci, fi->dir_release_count);
ci->i_max_offset = filp->f_pos; ci->i_max_offset = filp->f_pos;
} }
spin_unlock(&ci->i_ceph_lock); spin_unlock(&ci->i_ceph_lock);
...@@ -604,7 +606,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry, ...@@ -604,7 +606,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
fsc->mount_options->snapdir_name, fsc->mount_options->snapdir_name,
dentry->d_name.len) && dentry->d_name.len) &&
!is_root_ceph_dentry(dir, dentry) && !is_root_ceph_dentry(dir, dentry) &&
ceph_dir_test_complete(dir) && __ceph_dir_is_complete(ci) &&
(__ceph_caps_issued_mask(ci, CEPH_CAP_FILE_SHARED, 1))) { (__ceph_caps_issued_mask(ci, CEPH_CAP_FILE_SHARED, 1))) {
spin_unlock(&ci->i_ceph_lock); spin_unlock(&ci->i_ceph_lock);
dout(" dir %p complete, -ENOENT\n", dir); dout(" dir %p complete, -ENOENT\n", dir);
...@@ -1064,44 +1066,6 @@ static int ceph_snapdir_d_revalidate(struct dentry *dentry, ...@@ -1064,44 +1066,6 @@ static int ceph_snapdir_d_revalidate(struct dentry *dentry,
return 1; return 1;
} }
/*
* Set/clear/test dir complete flag on the dir's dentry.
*/
void ceph_dir_set_complete(struct inode *inode)
{
struct dentry *dentry = d_find_any_alias(inode);
if (dentry && ceph_dentry(dentry) &&
ceph_test_mount_opt(ceph_sb_to_client(dentry->d_sb), DCACHE)) {
dout(" marking %p (%p) complete\n", inode, dentry);
set_bit(CEPH_D_COMPLETE, &ceph_dentry(dentry)->flags);
}
dput(dentry);
}
void ceph_dir_clear_complete(struct inode *inode)
{
struct dentry *dentry = d_find_any_alias(inode);
if (dentry && ceph_dentry(dentry)) {
dout(" marking %p (%p) complete\n", inode, dentry);
set_bit(CEPH_D_COMPLETE, &ceph_dentry(dentry)->flags);
}
dput(dentry);
}
bool ceph_dir_test_complete(struct inode *inode)
{
struct dentry *dentry = d_find_any_alias(inode);
if (dentry && ceph_dentry(dentry)) {
dout(" marking %p (%p) NOT complete\n", inode, dentry);
clear_bit(CEPH_D_COMPLETE, &ceph_dentry(dentry)->flags);
}
dput(dentry);
return false;
}
/* /*
* When the VFS prunes a dentry from the cache, we need to clear the * When the VFS prunes a dentry from the cache, we need to clear the
* complete flag on the parent directory. * complete flag on the parent directory.
...@@ -1110,15 +1074,13 @@ bool ceph_dir_test_complete(struct inode *inode) ...@@ -1110,15 +1074,13 @@ bool ceph_dir_test_complete(struct inode *inode)
*/ */
static void ceph_d_prune(struct dentry *dentry) static void ceph_d_prune(struct dentry *dentry)
{ {
struct ceph_dentry_info *di;
dout("ceph_d_prune %p\n", dentry); dout("ceph_d_prune %p\n", dentry);
/* do we have a valid parent? */ /* do we have a valid parent? */
if (IS_ROOT(dentry)) if (IS_ROOT(dentry))
return; return;
/* if we are not hashed, we don't affect D_COMPLETE */ /* if we are not hashed, we don't affect dir's completeness */
if (d_unhashed(dentry)) if (d_unhashed(dentry))
return; return;
...@@ -1126,8 +1088,7 @@ static void ceph_d_prune(struct dentry *dentry) ...@@ -1126,8 +1088,7 @@ static void ceph_d_prune(struct dentry *dentry)
* we hold d_lock, so d_parent is stable, and d_fsdata is never * we hold d_lock, so d_parent is stable, and d_fsdata is never
* cleared until d_release * cleared until d_release
*/ */
di = ceph_dentry(dentry->d_parent); ceph_dir_clear_complete(dentry->d_parent->d_inode);
clear_bit(CEPH_D_COMPLETE, &di->flags);
} }
/* /*
......
...@@ -446,19 +446,35 @@ static ssize_t ceph_sync_read(struct file *file, char __user *data, ...@@ -446,19 +446,35 @@ static ssize_t ceph_sync_read(struct file *file, char __user *data,
} }
/* /*
* Write commit callback, called if we requested both an ACK and * Write commit request unsafe callback, called to tell us when a
* ONDISK commit reply from the OSD. * request is unsafe (that is, in flight--has been handed to the
* messenger to send to its target osd). It is called again when
* we've received a response message indicating the request is
* "safe" (its CEPH_OSD_FLAG_ONDISK flag is set), or when a request
* is completed early (and unsuccessfully) due to a timeout or
* interrupt.
*
* This is used if we requested both an ACK and ONDISK commit reply
* from the OSD.
*/ */
static void sync_write_commit(struct ceph_osd_request *req, static void ceph_sync_write_unsafe(struct ceph_osd_request *req, bool unsafe)
struct ceph_msg *msg)
{ {
struct ceph_inode_info *ci = ceph_inode(req->r_inode); struct ceph_inode_info *ci = ceph_inode(req->r_inode);
dout("sync_write_commit %p tid %llu\n", req, req->r_tid); dout("%s %p tid %llu %ssafe\n", __func__, req, req->r_tid,
spin_lock(&ci->i_unsafe_lock); unsafe ? "un" : "");
list_del_init(&req->r_unsafe_item); if (unsafe) {
spin_unlock(&ci->i_unsafe_lock); ceph_get_cap_refs(ci, CEPH_CAP_FILE_WR);
ceph_put_cap_refs(ci, CEPH_CAP_FILE_WR); spin_lock(&ci->i_unsafe_lock);
list_add_tail(&req->r_unsafe_item,
&ci->i_unsafe_writes);
spin_unlock(&ci->i_unsafe_lock);
} else {
spin_lock(&ci->i_unsafe_lock);
list_del_init(&req->r_unsafe_item);
spin_unlock(&ci->i_unsafe_lock);
ceph_put_cap_refs(ci, CEPH_CAP_FILE_WR);
}
} }
/* /*
...@@ -470,36 +486,33 @@ static void sync_write_commit(struct ceph_osd_request *req, ...@@ -470,36 +486,33 @@ static void sync_write_commit(struct ceph_osd_request *req,
* objects, rollback on failure, etc.) * objects, rollback on failure, etc.)
*/ */
static ssize_t ceph_sync_write(struct file *file, const char __user *data, static ssize_t ceph_sync_write(struct file *file, const char __user *data,
size_t left, loff_t *offset) size_t left, loff_t pos, loff_t *ppos)
{ {
struct inode *inode = file_inode(file); struct inode *inode = file_inode(file);
struct ceph_inode_info *ci = ceph_inode(inode); struct ceph_inode_info *ci = ceph_inode(inode);
struct ceph_fs_client *fsc = ceph_inode_to_client(inode); struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
struct ceph_snap_context *snapc;
struct ceph_vino vino;
struct ceph_osd_request *req; struct ceph_osd_request *req;
int num_ops = 1;
struct page **pages; struct page **pages;
int num_pages; int num_pages;
long long unsigned pos;
u64 len; u64 len;
int written = 0; int written = 0;
int flags; int flags;
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; 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;
dout("sync_write on file %p %lld~%u %s\n", file, *offset, dout("sync_write on file %p %lld~%u %s\n", file, pos,
(unsigned)left, (file->f_flags & O_DIRECT) ? "O_DIRECT" : ""); (unsigned)left, (file->f_flags & O_DIRECT) ? "O_DIRECT" : "");
if (file->f_flags & O_APPEND)
pos = i_size_read(inode);
else
pos = *offset;
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)
return ret; return ret;
...@@ -516,7 +529,7 @@ static ssize_t ceph_sync_write(struct file *file, const char __user *data, ...@@ -516,7 +529,7 @@ static ssize_t ceph_sync_write(struct file *file, const char __user *data,
if ((file->f_flags & (O_SYNC|O_DIRECT)) == 0) if ((file->f_flags & (O_SYNC|O_DIRECT)) == 0)
flags |= CEPH_OSD_FLAG_ACK; flags |= CEPH_OSD_FLAG_ACK;
else else
do_sync = 1; num_ops++; /* Also include a 'startsync' command. */
/* /*
* we may need to do multiple writes here if we span an object * we may need to do multiple writes here if we span an object
...@@ -526,25 +539,20 @@ static ssize_t ceph_sync_write(struct file *file, const char __user *data, ...@@ -526,25 +539,20 @@ static ssize_t ceph_sync_write(struct file *file, const char __user *data,
io_align = pos & ~PAGE_MASK; io_align = pos & ~PAGE_MASK;
buf_align = (unsigned long)data & ~PAGE_MASK; buf_align = (unsigned long)data & ~PAGE_MASK;
len = left; len = left;
if (file->f_flags & O_DIRECT) {
/* write from beginning of first page, regardless of snapc = ci->i_snap_realm->cached_context;
io alignment */ vino = ceph_vino(inode);
page_align = (pos - io_align + buf_align) & ~PAGE_MASK;
num_pages = calc_pages_for((unsigned long)data, len);
} else {
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, vino, pos, &len, num_ops,
CEPH_OSD_OP_WRITE, flags, CEPH_OSD_OP_WRITE, flags, snapc,
ci->i_snap_realm->cached_context,
do_sync,
ci->i_truncate_seq, ci->i_truncate_size, ci->i_truncate_seq, ci->i_truncate_size,
&mtime, false, page_align); false);
if (IS_ERR(req)) if (IS_ERR(req))
return PTR_ERR(req); return PTR_ERR(req);
/* write from beginning of first page, regardless of io alignment */
page_align = file->f_flags & O_DIRECT ? buf_align : io_align;
num_pages = calc_pages_for(page_align, len);
if (file->f_flags & O_DIRECT) { if (file->f_flags & O_DIRECT) {
pages = ceph_get_direct_page_vector(data, num_pages, false); pages = ceph_get_direct_page_vector(data, num_pages, false);
if (IS_ERR(pages)) { if (IS_ERR(pages)) {
...@@ -572,36 +580,20 @@ static ssize_t ceph_sync_write(struct file *file, const char __user *data, ...@@ -572,36 +580,20 @@ 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_unsafe_callback = ceph_sync_write_unsafe;
req->r_own_pages = 1; req->r_inode = inode;
own_pages = true;
} }
} }
req->r_pages = pages; osd_req_op_extent_osd_data_pages(req, 0, pages, len, page_align,
req->r_num_pages = num_pages; false, own_pages);
req->r_inode = inode;
/* BUG_ON(vino.snap != CEPH_NOSNAP); */
ceph_osdc_build_request(req, pos, snapc, vino.snap, &mtime);
ret = ceph_osdc_start_request(&fsc->client->osdc, req, false); ret = ceph_osdc_start_request(&fsc->client->osdc, req, false);
if (!ret) { if (!ret)
if (req->r_safe_callback) {
/*
* Add to inode unsafe list only after we
* start_request so that a tid has been assigned.
*/
spin_lock(&ci->i_unsafe_lock);
list_add_tail(&req->r_unsafe_item,
&ci->i_unsafe_writes);
spin_unlock(&ci->i_unsafe_lock);
ceph_get_cap_refs(ci, CEPH_CAP_FILE_WR);
}
ret = ceph_osdc_wait_request(&fsc->client->osdc, req); ret = ceph_osdc_wait_request(&fsc->client->osdc, req);
if (ret < 0 && req->r_safe_callback) {
spin_lock(&ci->i_unsafe_lock);
list_del_init(&req->r_unsafe_item);
spin_unlock(&ci->i_unsafe_lock);
ceph_put_cap_refs(ci, CEPH_CAP_FILE_WR);
}
}
if (file->f_flags & O_DIRECT) if (file->f_flags & O_DIRECT)
ceph_put_page_vector(pages, num_pages, false); ceph_put_page_vector(pages, num_pages, false);
...@@ -614,12 +606,12 @@ static ssize_t ceph_sync_write(struct file *file, const char __user *data, ...@@ -614,12 +606,12 @@ static ssize_t ceph_sync_write(struct file *file, const char __user *data,
pos += len; pos += len;
written += len; written += len;
left -= len; left -= len;
data += written; data += len;
if (left) if (left)
goto more; goto more;
ret = written; ret = written;
*offset = pos; *ppos = pos;
if (pos > i_size_read(inode)) if (pos > i_size_read(inode))
check_caps = ceph_inode_set_size(inode, pos); check_caps = ceph_inode_set_size(inode, pos);
if (check_caps) if (check_caps)
...@@ -653,7 +645,6 @@ static ssize_t ceph_aio_read(struct kiocb *iocb, const struct iovec *iov, ...@@ -653,7 +645,6 @@ static ssize_t ceph_aio_read(struct kiocb *iocb, const struct iovec *iov,
dout("aio_read %p %llx.%llx %llu~%u trying to get caps on %p\n", dout("aio_read %p %llx.%llx %llu~%u trying to get caps on %p\n",
inode, ceph_vinop(inode), pos, (unsigned)len, inode); inode, ceph_vinop(inode), pos, (unsigned)len, inode);
again: again:
__ceph_do_pending_vmtruncate(inode);
if (fi->fmode & CEPH_FILE_MODE_LAZY) if (fi->fmode & CEPH_FILE_MODE_LAZY)
want = CEPH_CAP_FILE_CACHE | CEPH_CAP_FILE_LAZYIO; want = CEPH_CAP_FILE_CACHE | CEPH_CAP_FILE_LAZYIO;
else else
...@@ -717,55 +708,75 @@ static ssize_t ceph_aio_write(struct kiocb *iocb, const struct iovec *iov, ...@@ -717,55 +708,75 @@ static ssize_t ceph_aio_write(struct kiocb *iocb, const struct iovec *iov,
struct ceph_inode_info *ci = ceph_inode(inode); struct ceph_inode_info *ci = ceph_inode(inode);
struct ceph_osd_client *osdc = struct ceph_osd_client *osdc =
&ceph_sb_to_client(inode->i_sb)->client->osdc; &ceph_sb_to_client(inode->i_sb)->client->osdc;
loff_t endoff = pos + iov->iov_len; ssize_t count, written = 0;
int got = 0; int err, want, got;
int ret, err, written; bool hold_mutex;
if (ceph_snap(inode) != CEPH_NOSNAP) if (ceph_snap(inode) != CEPH_NOSNAP)
return -EROFS; return -EROFS;
retry_snap: sb_start_write(inode->i_sb);
written = 0; mutex_lock(&inode->i_mutex);
if (ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_FULL)) hold_mutex = true;
return -ENOSPC;
__ceph_do_pending_vmtruncate(inode);
/* err = generic_segment_checks(iov, &nr_segs, &count, VERIFY_READ);
* try to do a buffered write. if we don't have sufficient if (err)
* caps, we'll get -EAGAIN from generic_file_aio_write, or a goto out;
* short write if we only get caps for some pages.
*/ /* We can write back this queue in page reclaim */
if (!(iocb->ki_filp->f_flags & O_DIRECT) && current->backing_dev_info = file->f_mapping->backing_dev_info;
!(inode->i_sb->s_flags & MS_SYNCHRONOUS) &&
!(fi->flags & CEPH_F_SYNC)) { err = generic_write_checks(file, &pos, &count, S_ISBLK(inode->i_mode));
ret = generic_file_aio_write(iocb, iov, nr_segs, pos); if (err)
if (ret >= 0) goto out;
written = ret;
if (count == 0)
if ((ret >= 0 || ret == -EIOCBQUEUED) && goto out;
((file->f_flags & O_SYNC) || IS_SYNC(file->f_mapping->host)
|| ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_NEARFULL))) { err = file_remove_suid(file);
err = vfs_fsync_range(file, pos, pos + written - 1, 1); if (err)
if (err < 0) goto out;
ret = err;
} err = file_update_time(file);
if ((ret < 0 && ret != -EAGAIN) || pos + written >= endoff) if (err)
goto out; goto out;
retry_snap:
if (ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_FULL)) {
err = -ENOSPC;
goto out;
} }
dout("aio_write %p %llx.%llx %llu~%u getting caps. i_size %llu\n", dout("aio_write %p %llx.%llx %llu~%zd getting caps. i_size %llu\n",
inode, ceph_vinop(inode), pos + written, inode, ceph_vinop(inode), pos, count, inode->i_size);
(unsigned)iov->iov_len - written, inode->i_size); if (fi->fmode & CEPH_FILE_MODE_LAZY)
ret = ceph_get_caps(ci, CEPH_CAP_FILE_WR, 0, &got, endoff); want = CEPH_CAP_FILE_BUFFER | CEPH_CAP_FILE_LAZYIO;
if (ret < 0) else
want = CEPH_CAP_FILE_BUFFER;
got = 0;
err = ceph_get_caps(ci, CEPH_CAP_FILE_WR, want, &got, pos + count);
if (err < 0)
goto out; goto out;
dout("aio_write %p %llx.%llx %llu~%u got cap refs on %s\n", dout("aio_write %p %llx.%llx %llu~%zd got cap refs on %s\n",
inode, ceph_vinop(inode), pos + written, inode, ceph_vinop(inode), pos, count, ceph_cap_string(got));
(unsigned)iov->iov_len - written, ceph_cap_string(got));
ret = ceph_sync_write(file, iov->iov_base + written, if ((got & (CEPH_CAP_FILE_BUFFER|CEPH_CAP_FILE_LAZYIO)) == 0 ||
iov->iov_len - written, &iocb->ki_pos); (iocb->ki_filp->f_flags & O_DIRECT) ||
if (ret >= 0) { (inode->i_sb->s_flags & MS_SYNCHRONOUS) ||
(fi->flags & CEPH_F_SYNC)) {
mutex_unlock(&inode->i_mutex);
written = ceph_sync_write(file, iov->iov_base, count,
pos, &iocb->ki_pos);
} else {
written = generic_file_buffered_write(iocb, iov, nr_segs,
pos, &iocb->ki_pos,
count, 0);
mutex_unlock(&inode->i_mutex);
}
hold_mutex = false;
if (written >= 0) {
int dirty; int dirty;
spin_lock(&ci->i_ceph_lock); spin_lock(&ci->i_ceph_lock);
dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_FILE_WR); dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_FILE_WR);
...@@ -773,18 +784,34 @@ static ssize_t ceph_aio_write(struct kiocb *iocb, const struct iovec *iov, ...@@ -773,18 +784,34 @@ static ssize_t ceph_aio_write(struct kiocb *iocb, const struct iovec *iov,
if (dirty) if (dirty)
__mark_inode_dirty(inode, dirty); __mark_inode_dirty(inode, dirty);
} }
dout("aio_write %p %llx.%llx %llu~%u dropping cap refs on %s\n", dout("aio_write %p %llx.%llx %llu~%u dropping cap refs on %s\n",
inode, ceph_vinop(inode), pos + written, inode, ceph_vinop(inode), pos, (unsigned)iov->iov_len,
(unsigned)iov->iov_len - written, ceph_cap_string(got)); ceph_cap_string(got));
ceph_put_cap_refs(ci, got); ceph_put_cap_refs(ci, got);
out:
if (ret == -EOLDSNAPC) { if (written >= 0 &&
((file->f_flags & O_SYNC) || IS_SYNC(file->f_mapping->host) ||
ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_NEARFULL))) {
err = vfs_fsync_range(file, pos, pos + written - 1, 1);
if (err < 0)
written = err;
}
if (written == -EOLDSNAPC) {
dout("aio_write %p %llx.%llx %llu~%u got EOLDSNAPC, retrying\n", dout("aio_write %p %llx.%llx %llu~%u got EOLDSNAPC, retrying\n",
inode, ceph_vinop(inode), pos, (unsigned)iov->iov_len); inode, ceph_vinop(inode), pos, (unsigned)iov->iov_len);
mutex_lock(&inode->i_mutex);
hold_mutex = true;
goto retry_snap; goto retry_snap;
} }
out:
if (hold_mutex)
mutex_unlock(&inode->i_mutex);
sb_end_write(inode->i_sb);
current->backing_dev_info = NULL;
return ret; return written ? written : err;
} }
/* /*
...@@ -796,7 +823,7 @@ static loff_t ceph_llseek(struct file *file, loff_t offset, int whence) ...@@ -796,7 +823,7 @@ static loff_t ceph_llseek(struct file *file, loff_t offset, int whence)
int ret; int ret;
mutex_lock(&inode->i_mutex); mutex_lock(&inode->i_mutex);
__ceph_do_pending_vmtruncate(inode); __ceph_do_pending_vmtruncate(inode, false);
if (whence == SEEK_END || whence == SEEK_DATA || whence == SEEK_HOLE) { if (whence == SEEK_END || whence == SEEK_DATA || whence == SEEK_HOLE) {
ret = ceph_do_getattr(inode, CEPH_STAT_CAP_SIZE); ret = ceph_do_getattr(inode, CEPH_STAT_CAP_SIZE);
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册