Commit 91f85756 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

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
  ...
parents 2e378f3e b5b09be3
...@@ -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.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -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);
......
...@@ -302,7 +302,8 @@ struct inode *ceph_alloc_inode(struct super_block *sb) ...@@ -302,7 +302,8 @@ struct inode *ceph_alloc_inode(struct super_block *sb)
ci->i_version = 0; ci->i_version = 0;
ci->i_time_warp_seq = 0; ci->i_time_warp_seq = 0;
ci->i_ceph_flags = 0; ci->i_ceph_flags = 0;
ci->i_release_count = 0; atomic_set(&ci->i_release_count, 1);
atomic_set(&ci->i_complete_count, 0);
ci->i_symlink = NULL; ci->i_symlink = NULL;
memset(&ci->i_dir_layout, 0, sizeof(ci->i_dir_layout)); memset(&ci->i_dir_layout, 0, sizeof(ci->i_dir_layout));
...@@ -561,7 +562,6 @@ static int fill_inode(struct inode *inode, ...@@ -561,7 +562,6 @@ static int fill_inode(struct inode *inode,
struct ceph_inode_info *ci = ceph_inode(inode); struct ceph_inode_info *ci = ceph_inode(inode);
int i; int i;
int issued = 0, implemented; int issued = 0, implemented;
int updating_inode = 0;
struct timespec mtime, atime, ctime; struct timespec mtime, atime, ctime;
u32 nsplits; u32 nsplits;
struct ceph_buffer *xattr_blob = NULL; struct ceph_buffer *xattr_blob = NULL;
...@@ -601,7 +601,6 @@ static int fill_inode(struct inode *inode, ...@@ -601,7 +601,6 @@ static int fill_inode(struct inode *inode,
(ci->i_version & ~1) >= le64_to_cpu(info->version)) (ci->i_version & ~1) >= le64_to_cpu(info->version))
goto no_change; goto no_change;
updating_inode = 1;
issued = __ceph_caps_issued(ci, &implemented); issued = __ceph_caps_issued(ci, &implemented);
issued |= implemented | __ceph_caps_dirty(ci); issued |= implemented | __ceph_caps_dirty(ci);
...@@ -717,6 +716,17 @@ static int fill_inode(struct inode *inode, ...@@ -717,6 +716,17 @@ static int fill_inode(struct inode *inode,
ceph_vinop(inode), inode->i_mode); ceph_vinop(inode), inode->i_mode);
} }
/* set dir completion flag? */
if (S_ISDIR(inode->i_mode) &&
ci->i_files == 0 && ci->i_subdirs == 0 &&
ceph_snap(inode) == CEPH_NOSNAP &&
(le32_to_cpu(info->cap.caps) & CEPH_CAP_FILE_SHARED) &&
(issued & CEPH_CAP_FILE_EXCL) == 0 &&
!__ceph_dir_is_complete(ci)) {
dout(" marking %p complete (empty)\n", inode);
__ceph_dir_set_complete(ci, atomic_read(&ci->i_release_count));
ci->i_max_offset = 2;
}
no_change: no_change:
spin_unlock(&ci->i_ceph_lock); spin_unlock(&ci->i_ceph_lock);
...@@ -767,19 +777,6 @@ static int fill_inode(struct inode *inode, ...@@ -767,19 +777,6 @@ static int fill_inode(struct inode *inode,
__ceph_get_fmode(ci, cap_fmode); __ceph_get_fmode(ci, cap_fmode);
} }
/* set dir completion flag? */
if (S_ISDIR(inode->i_mode) &&
updating_inode && /* didn't jump to no_change */
ci->i_files == 0 && ci->i_subdirs == 0 &&
ceph_snap(inode) == CEPH_NOSNAP &&
(le32_to_cpu(info->cap.caps) & CEPH_CAP_FILE_SHARED) &&
(issued & CEPH_CAP_FILE_EXCL) == 0 &&
!ceph_dir_test_complete(inode)) {
dout(" marking %p complete (empty)\n", inode);
ceph_dir_set_complete(inode);
ci->i_max_offset = 2;
}
/* update delegation info? */ /* update delegation info? */
if (dirinfo) if (dirinfo)
ceph_fill_dirfrag(inode, dirinfo); ceph_fill_dirfrag(inode, dirinfo);
...@@ -861,7 +858,7 @@ static void ceph_set_dentry_offset(struct dentry *dn) ...@@ -861,7 +858,7 @@ static void ceph_set_dentry_offset(struct dentry *dn)
di = ceph_dentry(dn); di = ceph_dentry(dn);
spin_lock(&ci->i_ceph_lock); spin_lock(&ci->i_ceph_lock);
if (!ceph_dir_test_complete(inode)) { if (!__ceph_dir_is_complete(ci)) {
spin_unlock(&ci->i_ceph_lock); spin_unlock(&ci->i_ceph_lock);
return; return;
} }
...@@ -1065,8 +1062,8 @@ int ceph_fill_trace(struct super_block *sb, struct ceph_mds_request *req, ...@@ -1065,8 +1062,8 @@ int ceph_fill_trace(struct super_block *sb, struct ceph_mds_request *req,
/* /*
* d_move() puts the renamed dentry at the end of * d_move() puts the renamed dentry at the end of
* d_subdirs. We need to assign it an appropriate * d_subdirs. We need to assign it an appropriate
* directory offset so we can behave when holding * directory offset so we can behave when dir is
* D_COMPLETE. * complete.
*/ */
ceph_set_dentry_offset(req->r_old_dentry); ceph_set_dentry_offset(req->r_old_dentry);
dout("dn %p gets new offset %lld\n", req->r_old_dentry, dout("dn %p gets new offset %lld\n", req->r_old_dentry,
...@@ -1457,7 +1454,7 @@ static void ceph_invalidate_work(struct work_struct *work) ...@@ -1457,7 +1454,7 @@ static void ceph_invalidate_work(struct work_struct *work)
/* /*
* called by trunc_wq; take i_mutex ourselves * called by trunc_wq;
* *
* We also truncate in a separate thread as well. * We also truncate in a separate thread as well.
*/ */
...@@ -1468,9 +1465,7 @@ static void ceph_vmtruncate_work(struct work_struct *work) ...@@ -1468,9 +1465,7 @@ static void ceph_vmtruncate_work(struct work_struct *work)
struct inode *inode = &ci->vfs_inode; struct inode *inode = &ci->vfs_inode;
dout("vmtruncate_work %p\n", inode); dout("vmtruncate_work %p\n", inode);
mutex_lock(&inode->i_mutex); __ceph_do_pending_vmtruncate(inode, true);
__ceph_do_pending_vmtruncate(inode);
mutex_unlock(&inode->i_mutex);
iput(inode); iput(inode);
} }
...@@ -1494,12 +1489,10 @@ void ceph_queue_vmtruncate(struct inode *inode) ...@@ -1494,12 +1489,10 @@ void ceph_queue_vmtruncate(struct inode *inode)
} }
/* /*
* called with i_mutex held.
*
* Make sure any pending truncation is applied before doing anything * Make sure any pending truncation is applied before doing anything
* that may depend on it. * that may depend on it.
*/ */
void __ceph_do_pending_vmtruncate(struct inode *inode) void __ceph_do_pending_vmtruncate(struct inode *inode, bool needlock)
{ {
struct ceph_inode_info *ci = ceph_inode(inode); struct ceph_inode_info *ci = ceph_inode(inode);
u64 to; u64 to;
...@@ -1532,7 +1525,11 @@ void __ceph_do_pending_vmtruncate(struct inode *inode) ...@@ -1532,7 +1525,11 @@ void __ceph_do_pending_vmtruncate(struct inode *inode)
ci->i_truncate_pending, to); ci->i_truncate_pending, to);
spin_unlock(&ci->i_ceph_lock); spin_unlock(&ci->i_ceph_lock);
if (needlock)
mutex_lock(&inode->i_mutex);
truncate_inode_pages(inode->i_mapping, to); truncate_inode_pages(inode->i_mapping, to);
if (needlock)
mutex_unlock(&inode->i_mutex);
spin_lock(&ci->i_ceph_lock); spin_lock(&ci->i_ceph_lock);
if (to == ci->i_truncate_size) { if (to == ci->i_truncate_size) {
...@@ -1563,6 +1560,12 @@ static void *ceph_sym_follow_link(struct dentry *dentry, struct nameidata *nd) ...@@ -1563,6 +1560,12 @@ static void *ceph_sym_follow_link(struct dentry *dentry, struct nameidata *nd)
static const struct inode_operations ceph_symlink_iops = { static const struct inode_operations ceph_symlink_iops = {
.readlink = generic_readlink, .readlink = generic_readlink,
.follow_link = ceph_sym_follow_link, .follow_link = ceph_sym_follow_link,
.setattr = ceph_setattr,
.getattr = ceph_getattr,
.setxattr = ceph_setxattr,
.getxattr = ceph_getxattr,
.listxattr = ceph_listxattr,
.removexattr = ceph_removexattr,
}; };
/* /*
...@@ -1585,7 +1588,7 @@ int ceph_setattr(struct dentry *dentry, struct iattr *attr) ...@@ -1585,7 +1588,7 @@ int ceph_setattr(struct dentry *dentry, struct iattr *attr)
if (ceph_snap(inode) != CEPH_NOSNAP) if (ceph_snap(inode) != CEPH_NOSNAP)
return -EROFS; return -EROFS;
__ceph_do_pending_vmtruncate(inode); __ceph_do_pending_vmtruncate(inode, false);
err = inode_change_ok(inode, attr); err = inode_change_ok(inode, attr);
if (err != 0) if (err != 0)
...@@ -1767,7 +1770,7 @@ int ceph_setattr(struct dentry *dentry, struct iattr *attr) ...@@ -1767,7 +1770,7 @@ int ceph_setattr(struct dentry *dentry, struct iattr *attr)
ceph_cap_string(dirtied), mask); ceph_cap_string(dirtied), mask);
ceph_mdsc_put_request(req); ceph_mdsc_put_request(req);
__ceph_do_pending_vmtruncate(inode); __ceph_do_pending_vmtruncate(inode, false);
return err; return err;
out: out:
spin_unlock(&ci->i_ceph_lock); spin_unlock(&ci->i_ceph_lock);
......
...@@ -208,8 +208,9 @@ static long ceph_ioctl_get_dataloc(struct file *file, void __user *arg) ...@@ -208,8 +208,9 @@ static long ceph_ioctl_get_dataloc(struct file *file, void __user *arg)
snprintf(dl.object_name, sizeof(dl.object_name), "%llx.%08llx", snprintf(dl.object_name, sizeof(dl.object_name), "%llx.%08llx",
ceph_ino(inode), dl.object_no); ceph_ino(inode), dl.object_no);
ceph_calc_object_layout(&pgid, dl.object_name, &ci->i_layout,
osdc->osdmap); ceph_calc_ceph_pg(&pgid, dl.object_name, osdc->osdmap,
ceph_file_layout_pg_pool(ci->i_layout));
dl.osd = ceph_calc_pg_primary(osdc->osdmap, pgid); dl.osd = ceph_calc_pg_primary(osdc->osdmap, pgid);
if (dl.osd >= 0) { if (dl.osd >= 0) {
......
...@@ -265,7 +265,8 @@ static int parse_reply_info_extra(void **p, void *end, ...@@ -265,7 +265,8 @@ static int parse_reply_info_extra(void **p, void *end,
{ {
if (info->head->op == CEPH_MDS_OP_GETFILELOCK) if (info->head->op == CEPH_MDS_OP_GETFILELOCK)
return parse_reply_info_filelock(p, end, info, features); return parse_reply_info_filelock(p, end, info, features);
else if (info->head->op == CEPH_MDS_OP_READDIR) else if (info->head->op == CEPH_MDS_OP_READDIR ||
info->head->op == CEPH_MDS_OP_LSSNAP)
return parse_reply_info_dir(p, end, info, features); return parse_reply_info_dir(p, end, info, features);
else if (info->head->op == CEPH_MDS_OP_CREATE) else if (info->head->op == CEPH_MDS_OP_CREATE)
return parse_reply_info_create(p, end, info, features); return parse_reply_info_create(p, end, info, features);
...@@ -364,9 +365,9 @@ void ceph_put_mds_session(struct ceph_mds_session *s) ...@@ -364,9 +365,9 @@ void ceph_put_mds_session(struct ceph_mds_session *s)
atomic_read(&s->s_ref), atomic_read(&s->s_ref)-1); atomic_read(&s->s_ref), atomic_read(&s->s_ref)-1);
if (atomic_dec_and_test(&s->s_ref)) { if (atomic_dec_and_test(&s->s_ref)) {
if (s->s_auth.authorizer) if (s->s_auth.authorizer)
s->s_mdsc->fsc->client->monc.auth->ops->destroy_authorizer( ceph_auth_destroy_authorizer(
s->s_mdsc->fsc->client->monc.auth, s->s_mdsc->fsc->client->monc.auth,
s->s_auth.authorizer); s->s_auth.authorizer);
kfree(s); kfree(s);
} }
} }
...@@ -1196,6 +1197,8 @@ static int trim_caps_cb(struct inode *inode, struct ceph_cap *cap, void *arg) ...@@ -1196,6 +1197,8 @@ static int trim_caps_cb(struct inode *inode, struct ceph_cap *cap, void *arg)
session->s_trim_caps--; session->s_trim_caps--;
if (oissued) { if (oissued) {
/* we aren't the only cap.. just remove us */ /* we aren't the only cap.. just remove us */
__queue_cap_release(session, ceph_ino(inode), cap->cap_id,
cap->mseq, cap->issue_seq);
__ceph_remove_cap(cap); __ceph_remove_cap(cap);
} else { } else {
/* try to drop referring dentries */ /* try to drop referring dentries */
...@@ -1718,8 +1721,12 @@ static struct ceph_msg *create_request_message(struct ceph_mds_client *mdsc, ...@@ -1718,8 +1721,12 @@ static struct ceph_msg *create_request_message(struct ceph_mds_client *mdsc,
msg->front.iov_len = p - msg->front.iov_base; msg->front.iov_len = p - msg->front.iov_base;
msg->hdr.front_len = cpu_to_le32(msg->front.iov_len); msg->hdr.front_len = cpu_to_le32(msg->front.iov_len);
msg->pages = req->r_pages; if (req->r_data_len) {
msg->nr_pages = req->r_num_pages; /* outbound data set only by ceph_sync_setxattr() */
BUG_ON(!req->r_pages);
ceph_msg_data_add_pages(msg, req->r_pages, req->r_data_len, 0);
}
msg->hdr.data_len = cpu_to_le32(req->r_data_len); msg->hdr.data_len = cpu_to_le32(req->r_data_len);
msg->hdr.data_off = cpu_to_le16(0); msg->hdr.data_off = cpu_to_le16(0);
...@@ -1913,6 +1920,7 @@ static void __wake_requests(struct ceph_mds_client *mdsc, ...@@ -1913,6 +1920,7 @@ static void __wake_requests(struct ceph_mds_client *mdsc,
req = list_entry(tmp_list.next, req = list_entry(tmp_list.next,
struct ceph_mds_request, r_wait); struct ceph_mds_request, r_wait);
list_del_init(&req->r_wait); list_del_init(&req->r_wait);
dout(" wake request %p tid %llu\n", req, req->r_tid);
__do_request(mdsc, req); __do_request(mdsc, req);
} }
} }
...@@ -2026,20 +2034,16 @@ int ceph_mdsc_do_request(struct ceph_mds_client *mdsc, ...@@ -2026,20 +2034,16 @@ int ceph_mdsc_do_request(struct ceph_mds_client *mdsc,
} }
/* /*
* Invalidate dir D_COMPLETE, dentry lease state on an aborted MDS * Invalidate dir's completeness, dentry lease state on an aborted MDS
* namespace request. * namespace request.
*/ */
void ceph_invalidate_dir_request(struct ceph_mds_request *req) void ceph_invalidate_dir_request(struct ceph_mds_request *req)
{ {
struct inode *inode = req->r_locked_dir; struct inode *inode = req->r_locked_dir;
struct ceph_inode_info *ci = ceph_inode(inode);
dout("invalidate_dir_request %p (D_COMPLETE, lease(s))\n", inode); dout("invalidate_dir_request %p (complete, lease(s))\n", inode);
spin_lock(&ci->i_ceph_lock);
ceph_dir_clear_complete(inode);
ci->i_release_count++;
spin_unlock(&ci->i_ceph_lock);
ceph_dir_clear_complete(inode);
if (req->r_dentry) if (req->r_dentry)
ceph_invalidate_dentry_lease(req->r_dentry); ceph_invalidate_dentry_lease(req->r_dentry);
if (req->r_old_dentry) if (req->r_old_dentry)
...@@ -2599,11 +2603,13 @@ static void send_mds_reconnect(struct ceph_mds_client *mdsc, ...@@ -2599,11 +2603,13 @@ static void send_mds_reconnect(struct ceph_mds_client *mdsc,
goto fail; goto fail;
} }
reply->pagelist = pagelist;
if (recon_state.flock) if (recon_state.flock)
reply->hdr.version = cpu_to_le16(2); reply->hdr.version = cpu_to_le16(2);
reply->hdr.data_len = cpu_to_le32(pagelist->length); if (pagelist->length) {
reply->nr_pages = calc_pages_for(0, pagelist->length); /* set up outbound data if we have any */
reply->hdr.data_len = cpu_to_le32(pagelist->length);
ceph_msg_data_add_pagelist(reply, pagelist);
}
ceph_con_send(&session->s_con, reply); ceph_con_send(&session->s_con, reply);
mutex_unlock(&session->s_mutex); mutex_unlock(&session->s_mutex);
...@@ -3433,13 +3439,17 @@ static struct ceph_auth_handshake *get_authorizer(struct ceph_connection *con, ...@@ -3433,13 +3439,17 @@ static struct ceph_auth_handshake *get_authorizer(struct ceph_connection *con,
struct ceph_auth_handshake *auth = &s->s_auth; struct ceph_auth_handshake *auth = &s->s_auth;
if (force_new && auth->authorizer) { if (force_new && auth->authorizer) {
if (ac->ops && ac->ops->destroy_authorizer) ceph_auth_destroy_authorizer(ac, auth->authorizer);
ac->ops->destroy_authorizer(ac, auth->authorizer);
auth->authorizer = NULL; auth->authorizer = NULL;
} }
if (!auth->authorizer && ac->ops && ac->ops->create_authorizer) { if (!auth->authorizer) {
int ret = ac->ops->create_authorizer(ac, CEPH_ENTITY_TYPE_MDS, int ret = ceph_auth_create_authorizer(ac, CEPH_ENTITY_TYPE_MDS,
auth); auth);
if (ret)
return ERR_PTR(ret);
} else {
int ret = ceph_auth_update_authorizer(ac, CEPH_ENTITY_TYPE_MDS,
auth);
if (ret) if (ret)
return ERR_PTR(ret); return ERR_PTR(ret);
} }
...@@ -3455,7 +3465,7 @@ static int verify_authorizer_reply(struct ceph_connection *con, int len) ...@@ -3455,7 +3465,7 @@ static int verify_authorizer_reply(struct ceph_connection *con, int len)
struct ceph_mds_client *mdsc = s->s_mdsc; struct ceph_mds_client *mdsc = s->s_mdsc;
struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth; struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth;
return ac->ops->verify_authorizer_reply(ac, s->s_auth.authorizer, len); return ceph_auth_verify_authorizer_reply(ac, s->s_auth.authorizer, len);
} }
static int invalidate_authorizer(struct ceph_connection *con) static int invalidate_authorizer(struct ceph_connection *con)
...@@ -3464,12 +3474,32 @@ static int invalidate_authorizer(struct ceph_connection *con) ...@@ -3464,12 +3474,32 @@ static int invalidate_authorizer(struct ceph_connection *con)
struct ceph_mds_client *mdsc = s->s_mdsc; struct ceph_mds_client *mdsc = s->s_mdsc;
struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth; struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth;
if (ac->ops->invalidate_authorizer) ceph_auth_invalidate_authorizer(ac, CEPH_ENTITY_TYPE_MDS);
ac->ops->invalidate_authorizer(ac, CEPH_ENTITY_TYPE_MDS);
return ceph_monc_validate_auth(&mdsc->fsc->client->monc); return ceph_monc_validate_auth(&mdsc->fsc->client->monc);
} }
static struct ceph_msg *mds_alloc_msg(struct ceph_connection *con,
struct ceph_msg_header *hdr, int *skip)
{
struct ceph_msg *msg;
int type = (int) le16_to_cpu(hdr->type);
int front_len = (int) le32_to_cpu(hdr->front_len);
if (con->in_msg)
return con->in_msg;
*skip = 0;
msg = ceph_msg_new(type, front_len, GFP_NOFS, false);
if (!msg) {
pr_err("unable to allocate msg type %d len %d\n",
type, front_len);
return NULL;
}
return msg;
}
static const struct ceph_connection_operations mds_con_ops = { static const struct ceph_connection_operations mds_con_ops = {
.get = con_get, .get = con_get,
.put = con_put, .put = con_put,
...@@ -3478,6 +3508,7 @@ static const struct ceph_connection_operations mds_con_ops = { ...@@ -3478,6 +3508,7 @@ static const struct ceph_connection_operations mds_con_ops = {
.verify_authorizer_reply = verify_authorizer_reply, .verify_authorizer_reply = verify_authorizer_reply,
.invalidate_authorizer = invalidate_authorizer, .invalidate_authorizer = invalidate_authorizer,
.peer_reset = peer_reset, .peer_reset = peer_reset,
.alloc_msg = mds_alloc_msg,
}; };
/* eof */ /* eof */
...@@ -20,7 +20,10 @@ int ceph_mdsmap_get_random_mds(struct ceph_mdsmap *m) ...@@ -20,7 +20,10 @@ int ceph_mdsmap_get_random_mds(struct ceph_mdsmap *m)
{ {
int n = 0; int n = 0;
int i; int i;
char r;
/* special case for one mds */
if (1 == m->m_max_mds && m->m_info[0].state > 0)
return 0;
/* count */ /* count */
for (i = 0; i < m->m_max_mds; i++) for (i = 0; i < m->m_max_mds; i++)
...@@ -30,8 +33,7 @@ int ceph_mdsmap_get_random_mds(struct ceph_mdsmap *m) ...@@ -30,8 +33,7 @@ int ceph_mdsmap_get_random_mds(struct ceph_mdsmap *m)
return -1; return -1;
/* pick */ /* pick */
get_random_bytes(&r, 1); n = prandom_u32() % n;
n = r % n;
i = 0; i = 0;
for (i = 0; n > 0; i++, n--) for (i = 0; n > 0; i++, n--)
while (m->m_info[i].state <= 0) while (m->m_info[i].state <= 0)
......
...@@ -332,10 +332,9 @@ static int build_snap_context(struct ceph_snap_realm *realm) ...@@ -332,10 +332,9 @@ static int build_snap_context(struct ceph_snap_realm *realm)
err = -ENOMEM; err = -ENOMEM;
if (num > (SIZE_MAX - sizeof(*snapc)) / sizeof(u64)) if (num > (SIZE_MAX - sizeof(*snapc)) / sizeof(u64))
goto fail; goto fail;
snapc = kzalloc(sizeof(*snapc) + num*sizeof(u64), GFP_NOFS); snapc = ceph_create_snap_context(num, GFP_NOFS);
if (!snapc) if (!snapc)
goto fail; goto fail;
atomic_set(&snapc->nref, 1);
/* build (reverse sorted) snap vector */ /* build (reverse sorted) snap vector */
num = 0; num = 0;
......
...@@ -479,6 +479,8 @@ static struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt, ...@@ -479,6 +479,8 @@ static struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt,
CEPH_FEATURE_FLOCK | CEPH_FEATURE_FLOCK |
CEPH_FEATURE_DIRLAYOUTHASH; CEPH_FEATURE_DIRLAYOUTHASH;
const unsigned required_features = 0; const unsigned required_features = 0;
int page_count;
size_t size;
int err = -ENOMEM; int err = -ENOMEM;
fsc = kzalloc(sizeof(*fsc), GFP_KERNEL); fsc = kzalloc(sizeof(*fsc), GFP_KERNEL);
...@@ -522,8 +524,9 @@ static struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt, ...@@ -522,8 +524,9 @@ static struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt,
/* set up mempools */ /* set up mempools */
err = -ENOMEM; err = -ENOMEM;
fsc->wb_pagevec_pool = mempool_create_kmalloc_pool(10, page_count = fsc->mount_options->wsize >> PAGE_CACHE_SHIFT;
fsc->mount_options->wsize >> PAGE_CACHE_SHIFT); size = sizeof (struct page *) * (page_count ? page_count : 1);
fsc->wb_pagevec_pool = mempool_create_kmalloc_pool(10, size);
if (!fsc->wb_pagevec_pool) if (!fsc->wb_pagevec_pool)
goto fail_trunc_wq; goto fail_trunc_wq;
......
...@@ -204,7 +204,6 @@ struct ceph_inode_xattr { ...@@ -204,7 +204,6 @@ struct ceph_inode_xattr {
* Ceph dentry state * Ceph dentry state
*/ */
struct ceph_dentry_info { struct ceph_dentry_info {
unsigned long flags;
struct ceph_mds_session *lease_session; struct ceph_mds_session *lease_session;
u32 lease_gen, lease_shared_gen; u32 lease_gen, lease_shared_gen;
u32 lease_seq; u32 lease_seq;
...@@ -215,18 +214,6 @@ struct ceph_dentry_info { ...@@ -215,18 +214,6 @@ struct ceph_dentry_info {
u64 offset; u64 offset;
}; };
/*
* dentry flags
*
* The locking for D_COMPLETE is a bit odd:
* - we can clear it at almost any time (see ceph_d_prune)
* - it is only meaningful if:
* - we hold dir inode i_ceph_lock
* - we hold dir FILE_SHARED caps
* - the dentry D_COMPLETE is set
*/
#define CEPH_D_COMPLETE 1 /* if set, d_u.d_subdirs is complete directory */
struct ceph_inode_xattrs_info { struct ceph_inode_xattrs_info {
/* /*
* (still encoded) xattr blob. we avoid the overhead of parsing * (still encoded) xattr blob. we avoid the overhead of parsing
...@@ -257,7 +244,8 @@ struct ceph_inode_info { ...@@ -257,7 +244,8 @@ struct ceph_inode_info {
u32 i_time_warp_seq; u32 i_time_warp_seq;
unsigned i_ceph_flags; unsigned i_ceph_flags;
unsigned long i_release_count; atomic_t i_release_count;
atomic_t i_complete_count;
struct ceph_dir_layout i_dir_layout; struct ceph_dir_layout i_dir_layout;
struct ceph_file_layout i_layout; struct ceph_file_layout i_layout;
...@@ -267,7 +255,7 @@ struct ceph_inode_info { ...@@ -267,7 +255,7 @@ struct ceph_inode_info {
struct timespec i_rctime; struct timespec i_rctime;
u64 i_rbytes, i_rfiles, i_rsubdirs; u64 i_rbytes, i_rfiles, i_rsubdirs;
u64 i_files, i_subdirs; u64 i_files, i_subdirs;
u64 i_max_offset; /* largest readdir offset, set with D_COMPLETE */ u64 i_max_offset; /* largest readdir offset, set with complete dir */
struct rb_root i_fragtree; struct rb_root i_fragtree;
struct mutex i_fragtree_mutex; struct mutex i_fragtree_mutex;
...@@ -436,33 +424,31 @@ static inline struct inode *ceph_find_inode(struct super_block *sb, ...@@ -436,33 +424,31 @@ static inline struct inode *ceph_find_inode(struct super_block *sb,
#define CEPH_I_FLUSH 8 /* do not delay flush of dirty metadata */ #define CEPH_I_FLUSH 8 /* do not delay flush of dirty metadata */
#define CEPH_I_NOFLUSH 16 /* do not flush dirty caps */ #define CEPH_I_NOFLUSH 16 /* do not flush dirty caps */
static inline void ceph_i_clear(struct inode *inode, unsigned mask) static inline void __ceph_dir_set_complete(struct ceph_inode_info *ci,
int release_count)
{ {
struct ceph_inode_info *ci = ceph_inode(inode); atomic_set(&ci->i_complete_count, release_count);
spin_lock(&ci->i_ceph_lock);
ci->i_ceph_flags &= ~mask;
spin_unlock(&ci->i_ceph_lock);
} }
static inline void ceph_i_set(struct inode *inode, unsigned mask) static inline void __ceph_dir_clear_complete(struct ceph_inode_info *ci)
{ {
struct ceph_inode_info *ci = ceph_inode(inode); atomic_inc(&ci->i_release_count);
}
spin_lock(&ci->i_ceph_lock); static inline bool __ceph_dir_is_complete(struct ceph_inode_info *ci)
ci->i_ceph_flags |= mask; {
spin_unlock(&ci->i_ceph_lock); return atomic_read(&ci->i_complete_count) ==
atomic_read(&ci->i_release_count);
} }
static inline bool ceph_i_test(struct inode *inode, unsigned mask) static inline void ceph_dir_clear_complete(struct inode *inode)
{ {
struct ceph_inode_info *ci = ceph_inode(inode); __ceph_dir_clear_complete(ceph_inode(inode));
bool r; }
spin_lock(&ci->i_ceph_lock); static inline bool ceph_dir_is_complete(struct inode *inode)
r = (ci->i_ceph_flags & mask) == mask; {
spin_unlock(&ci->i_ceph_lock); return __ceph_dir_is_complete(ceph_inode(inode));
return r;
} }
...@@ -488,13 +474,6 @@ static inline loff_t ceph_make_fpos(unsigned frag, unsigned off) ...@@ -488,13 +474,6 @@ static inline loff_t ceph_make_fpos(unsigned frag, unsigned off)
return ((loff_t)frag << 32) | (loff_t)off; return ((loff_t)frag << 32) | (loff_t)off;
} }
/*
* set/clear directory D_COMPLETE flag
*/
void ceph_dir_set_complete(struct inode *inode);
void ceph_dir_clear_complete(struct inode *inode);
bool ceph_dir_test_complete(struct inode *inode);
/* /*
* caps helpers * caps helpers
*/ */
...@@ -584,7 +563,7 @@ struct ceph_file_info { ...@@ -584,7 +563,7 @@ struct ceph_file_info {
u64 next_offset; /* offset of next chunk (last_name's + 1) */ u64 next_offset; /* offset of next chunk (last_name's + 1) */
char *last_name; /* last entry in previous chunk */ char *last_name; /* last entry in previous chunk */
struct dentry *dentry; /* next dentry (for dcache readdir) */ struct dentry *dentry; /* next dentry (for dcache readdir) */
unsigned long dir_release_count; int dir_release_count;
/* used for -o dirstat read() on directory thing */ /* used for -o dirstat read() on directory thing */
char *dir_info; char *dir_info;
...@@ -713,7 +692,7 @@ extern int ceph_readdir_prepopulate(struct ceph_mds_request *req, ...@@ -713,7 +692,7 @@ extern int ceph_readdir_prepopulate(struct ceph_mds_request *req,
extern int ceph_inode_holds_cap(struct inode *inode, int mask); extern int ceph_inode_holds_cap(struct inode *inode, int mask);
extern int ceph_inode_set_size(struct inode *inode, loff_t size); extern int ceph_inode_set_size(struct inode *inode, loff_t size);
extern void __ceph_do_pending_vmtruncate(struct inode *inode); extern void __ceph_do_pending_vmtruncate(struct inode *inode, bool needlock);
extern void ceph_queue_vmtruncate(struct inode *inode); extern void ceph_queue_vmtruncate(struct inode *inode);
extern void ceph_queue_invalidate(struct inode *inode); extern void ceph_queue_invalidate(struct inode *inode);
...@@ -755,6 +734,8 @@ static inline void ceph_remove_cap(struct ceph_cap *cap) ...@@ -755,6 +734,8 @@ static inline void ceph_remove_cap(struct ceph_cap *cap)
extern void ceph_put_cap(struct ceph_mds_client *mdsc, extern void ceph_put_cap(struct ceph_mds_client *mdsc,
struct ceph_cap *cap); struct ceph_cap *cap);
extern void __queue_cap_release(struct ceph_mds_session *session, u64 ino,
u64 cap_id, u32 migrate_seq, u32 issue_seq);
extern void ceph_queue_caps_release(struct inode *inode); extern void ceph_queue_caps_release(struct inode *inode);
extern int ceph_write_inode(struct inode *inode, struct writeback_control *wbc); extern int ceph_write_inode(struct inode *inode, struct writeback_control *wbc);
extern int ceph_fsync(struct file *file, loff_t start, loff_t end, extern int ceph_fsync(struct file *file, loff_t start, loff_t end,
......
...@@ -52,6 +52,9 @@ struct ceph_auth_client_ops { ...@@ -52,6 +52,9 @@ struct ceph_auth_client_ops {
*/ */
int (*create_authorizer)(struct ceph_auth_client *ac, int peer_type, int (*create_authorizer)(struct ceph_auth_client *ac, int peer_type,
struct ceph_auth_handshake *auth); struct ceph_auth_handshake *auth);
/* ensure that an existing authorizer is up to date */
int (*update_authorizer)(struct ceph_auth_client *ac, int peer_type,
struct ceph_auth_handshake *auth);
int (*verify_authorizer_reply)(struct ceph_auth_client *ac, int (*verify_authorizer_reply)(struct ceph_auth_client *ac,
struct ceph_authorizer *a, size_t len); struct ceph_authorizer *a, size_t len);
void (*destroy_authorizer)(struct ceph_auth_client *ac, void (*destroy_authorizer)(struct ceph_auth_client *ac,
...@@ -75,6 +78,8 @@ struct ceph_auth_client { ...@@ -75,6 +78,8 @@ struct ceph_auth_client {
u64 global_id; /* our unique id in system */ u64 global_id; /* our unique id in system */
const struct ceph_crypto_key *key; /* our secret key */ const struct ceph_crypto_key *key; /* our secret key */
unsigned want_keys; /* which services we want */ unsigned want_keys; /* which services we want */
struct mutex mutex;
}; };
extern struct ceph_auth_client *ceph_auth_init(const char *name, extern struct ceph_auth_client *ceph_auth_init(const char *name,
...@@ -94,5 +99,18 @@ extern int ceph_build_auth(struct ceph_auth_client *ac, ...@@ -94,5 +99,18 @@ extern int ceph_build_auth(struct ceph_auth_client *ac,
void *msg_buf, size_t msg_len); void *msg_buf, size_t msg_len);
extern int ceph_auth_is_authenticated(struct ceph_auth_client *ac); extern int ceph_auth_is_authenticated(struct ceph_auth_client *ac);
extern int ceph_auth_create_authorizer(struct ceph_auth_client *ac,
int peer_type,
struct ceph_auth_handshake *auth);
extern void ceph_auth_destroy_authorizer(struct ceph_auth_client *ac,
struct ceph_authorizer *a);
extern int ceph_auth_update_authorizer(struct ceph_auth_client *ac,
int peer_type,
struct ceph_auth_handshake *a);
extern int ceph_auth_verify_authorizer_reply(struct ceph_auth_client *ac,
struct ceph_authorizer *a,
size_t len);
extern void ceph_auth_invalidate_authorizer(struct ceph_auth_client *ac,
int peer_type);
#endif #endif
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
*/ */
#define CEPH_FEATURES_SUPPORTED_DEFAULT \ #define CEPH_FEATURES_SUPPORTED_DEFAULT \
(CEPH_FEATURE_NOSRCADDR | \ (CEPH_FEATURE_NOSRCADDR | \
CEPH_FEATURE_RECONNECT_SEQ | \
CEPH_FEATURE_PGID64 | \ CEPH_FEATURE_PGID64 | \
CEPH_FEATURE_PGPOOL3 | \ CEPH_FEATURE_PGPOOL3 | \
CEPH_FEATURE_OSDENC | \ CEPH_FEATURE_OSDENC | \
...@@ -51,6 +52,7 @@ ...@@ -51,6 +52,7 @@
#define CEPH_FEATURES_REQUIRED_DEFAULT \ #define CEPH_FEATURES_REQUIRED_DEFAULT \
(CEPH_FEATURE_NOSRCADDR | \ (CEPH_FEATURE_NOSRCADDR | \
CEPH_FEATURE_RECONNECT_SEQ | \
CEPH_FEATURE_PGID64 | \ CEPH_FEATURE_PGID64 | \
CEPH_FEATURE_PGPOOL3 | \ CEPH_FEATURE_PGPOOL3 | \
CEPH_FEATURE_OSDENC) CEPH_FEATURE_OSDENC)
......
...@@ -8,6 +8,23 @@ ...@@ -8,6 +8,23 @@
#include <linux/ceph/types.h> #include <linux/ceph/types.h>
/* This seemed to be the easiest place to define these */
#define U8_MAX ((u8)(~0U))
#define U16_MAX ((u16)(~0U))
#define U32_MAX ((u32)(~0U))
#define U64_MAX ((u64)(~0ULL))
#define S8_MAX ((s8)(U8_MAX >> 1))
#define S16_MAX ((s16)(U16_MAX >> 1))
#define S32_MAX ((s32)(U32_MAX >> 1))
#define S64_MAX ((s64)(U64_MAX >> 1LL))
#define S8_MIN ((s8)(-S8_MAX - 1))
#define S16_MIN ((s16)(-S16_MAX - 1))
#define S32_MIN ((s32)(-S32_MAX - 1))
#define S64_MIN ((s64)(-S64_MAX - 1LL))
/* /*
* in all cases, * in all cases,
* void **p pointer to position pointer * void **p pointer to position pointer
...@@ -137,14 +154,19 @@ static inline char *ceph_extract_encoded_string(void **p, void *end, ...@@ -137,14 +154,19 @@ static inline char *ceph_extract_encoded_string(void **p, void *end,
static inline void ceph_decode_timespec(struct timespec *ts, static inline void ceph_decode_timespec(struct timespec *ts,
const struct ceph_timespec *tv) const struct ceph_timespec *tv)
{ {
ts->tv_sec = le32_to_cpu(tv->tv_sec); ts->tv_sec = (__kernel_time_t)le32_to_cpu(tv->tv_sec);
ts->tv_nsec = le32_to_cpu(tv->tv_nsec); ts->tv_nsec = (long)le32_to_cpu(tv->tv_nsec);
} }
static inline void ceph_encode_timespec(struct ceph_timespec *tv, static inline void ceph_encode_timespec(struct ceph_timespec *tv,
const struct timespec *ts) const struct timespec *ts)
{ {
tv->tv_sec = cpu_to_le32(ts->tv_sec); BUG_ON(ts->tv_sec < 0);
tv->tv_nsec = cpu_to_le32(ts->tv_nsec); BUG_ON(ts->tv_sec > (__kernel_time_t)U32_MAX);
BUG_ON(ts->tv_nsec < 0);
BUG_ON(ts->tv_nsec > (long)U32_MAX);
tv->tv_sec = cpu_to_le32((u32)ts->tv_sec);
tv->tv_nsec = cpu_to_le32((u32)ts->tv_nsec);
} }
/* /*
......
...@@ -66,6 +66,7 @@ struct ceph_options { ...@@ -66,6 +66,7 @@ struct ceph_options {
#define CEPH_OSD_IDLE_TTL_DEFAULT 60 #define CEPH_OSD_IDLE_TTL_DEFAULT 60
#define CEPH_MSG_MAX_FRONT_LEN (16*1024*1024) #define CEPH_MSG_MAX_FRONT_LEN (16*1024*1024)
#define CEPH_MSG_MAX_MIDDLE_LEN (16*1024*1024)
#define CEPH_MSG_MAX_DATA_LEN (16*1024*1024) #define CEPH_MSG_MAX_DATA_LEN (16*1024*1024)
#define CEPH_AUTH_NAME_DEFAULT "guest" #define CEPH_AUTH_NAME_DEFAULT "guest"
...@@ -156,31 +157,11 @@ struct ceph_snap_context { ...@@ -156,31 +157,11 @@ struct ceph_snap_context {
u64 snaps[]; u64 snaps[];
}; };
static inline struct ceph_snap_context * extern struct ceph_snap_context *ceph_create_snap_context(u32 snap_count,
ceph_get_snap_context(struct ceph_snap_context *sc) gfp_t gfp_flags);
{ extern struct ceph_snap_context *ceph_get_snap_context(
/* struct ceph_snap_context *sc);
printk("get_snap_context %p %d -> %d\n", sc, atomic_read(&sc->nref), extern void ceph_put_snap_context(struct ceph_snap_context *sc);
atomic_read(&sc->nref)+1);
*/
if (sc)
atomic_inc(&sc->nref);
return sc;
}
static inline void ceph_put_snap_context(struct ceph_snap_context *sc)
{
if (!sc)
return;
/*
printk("put_snap_context %p %d -> %d\n", sc, atomic_read(&sc->nref),
atomic_read(&sc->nref)-1);
*/
if (atomic_dec_and_test(&sc->nref)) {
/*printk(" deleting snap_context %p\n", sc);*/
kfree(sc);
}
}
/* /*
* calculate the number of pages a given length and offset map onto, * calculate the number of pages a given length and offset map onto,
......
...@@ -64,6 +64,77 @@ struct ceph_messenger { ...@@ -64,6 +64,77 @@ struct ceph_messenger {
u32 required_features; u32 required_features;
}; };
enum ceph_msg_data_type {
CEPH_MSG_DATA_NONE, /* message contains no data payload */
CEPH_MSG_DATA_PAGES, /* data source/destination is a page array */
CEPH_MSG_DATA_PAGELIST, /* data source/destination is a pagelist */
#ifdef CONFIG_BLOCK
CEPH_MSG_DATA_BIO, /* data source/destination is a bio list */
#endif /* CONFIG_BLOCK */
};
static __inline__ bool ceph_msg_data_type_valid(enum ceph_msg_data_type type)
{
switch (type) {
case CEPH_MSG_DATA_NONE:
case CEPH_MSG_DATA_PAGES:
case CEPH_MSG_DATA_PAGELIST:
#ifdef CONFIG_BLOCK
case CEPH_MSG_DATA_BIO:
#endif /* CONFIG_BLOCK */
return true;
default:
return false;
}
}
struct ceph_msg_data {
struct list_head links; /* ceph_msg->data */
enum ceph_msg_data_type type;
union {
#ifdef CONFIG_BLOCK
struct {
struct bio *bio;
size_t bio_length;
};
#endif /* CONFIG_BLOCK */
struct {
struct page **pages; /* NOT OWNER. */
size_t length; /* total # bytes */
unsigned int alignment; /* first page */
};
struct ceph_pagelist *pagelist;
};
};
struct ceph_msg_data_cursor {
size_t total_resid; /* across all data items */
struct list_head *data_head; /* = &ceph_msg->data */
struct ceph_msg_data *data; /* current data item */
size_t resid; /* bytes not yet consumed */
bool last_piece; /* current is last piece */
bool need_crc; /* crc update needed */
union {
#ifdef CONFIG_BLOCK
struct { /* bio */
struct bio *bio; /* bio from list */
unsigned int vector_index; /* vector from bio */
unsigned int vector_offset; /* bytes from vector */
};
#endif /* CONFIG_BLOCK */
struct { /* pages */
unsigned int page_offset; /* offset in page */
unsigned short page_index; /* index in array */
unsigned short page_count; /* pages in array */
};
struct { /* pagelist */
struct page *page; /* page from list */
size_t offset; /* bytes from list */
};
};
};
/* /*
* a single message. it contains a header (src, dest, message type, etc.), * a single message. it contains a header (src, dest, message type, etc.),
* footer (crc values, mainly), a "front" message body, and possibly a * footer (crc values, mainly), a "front" message body, and possibly a
...@@ -74,21 +145,15 @@ struct ceph_msg { ...@@ -74,21 +145,15 @@ struct ceph_msg {
struct ceph_msg_footer footer; /* footer */ struct ceph_msg_footer footer; /* footer */
struct kvec front; /* unaligned blobs of message */ struct kvec front; /* unaligned blobs of message */
struct ceph_buffer *middle; struct ceph_buffer *middle;
struct page **pages; /* data payload. NOT OWNER. */
unsigned nr_pages; /* size of page array */ size_t data_length;
unsigned page_alignment; /* io offset in first page */ struct list_head data;
struct ceph_pagelist *pagelist; /* instead of pages */ struct ceph_msg_data_cursor cursor;
struct ceph_connection *con; struct ceph_connection *con;
struct list_head list_head; struct list_head list_head; /* links for connection lists */
struct kref kref; struct kref kref;
#ifdef CONFIG_BLOCK
struct bio *bio; /* instead of pages/pagelist */
struct bio *bio_iter; /* bio iterator */
int bio_seg; /* current bio segment */
#endif /* CONFIG_BLOCK */
struct ceph_pagelist *trail; /* the trailing part of the data */
bool front_is_vmalloc; bool front_is_vmalloc;
bool more_to_follow; bool more_to_follow;
bool needs_out_seq; bool needs_out_seq;
...@@ -98,12 +163,6 @@ struct ceph_msg { ...@@ -98,12 +163,6 @@ struct ceph_msg {
struct ceph_msgpool *pool; struct ceph_msgpool *pool;
}; };
struct ceph_msg_pos {
int page, page_pos; /* which page; offset in page */
int data_pos; /* offset in data payload */
bool did_page_crc; /* true if we've calculated crc for current page */
};
/* ceph connection fault delay defaults, for exponential backoff */ /* ceph connection fault delay defaults, for exponential backoff */
#define BASE_DELAY_INTERVAL (HZ/2) #define BASE_DELAY_INTERVAL (HZ/2)
#define MAX_DELAY_INTERVAL (5 * 60 * HZ) #define MAX_DELAY_INTERVAL (5 * 60 * HZ)
...@@ -161,7 +220,6 @@ struct ceph_connection { ...@@ -161,7 +220,6 @@ struct ceph_connection {
struct ceph_msg *out_msg; /* sending message (== tail of struct ceph_msg *out_msg; /* sending message (== tail of
out_sent) */ out_sent) */
bool out_msg_done; bool out_msg_done;
struct ceph_msg_pos out_msg_pos;
struct kvec out_kvec[8], /* sending header/footer data */ struct kvec out_kvec[8], /* sending header/footer data */
*out_kvec_cur; *out_kvec_cur;
...@@ -175,7 +233,6 @@ struct ceph_connection { ...@@ -175,7 +233,6 @@ struct ceph_connection {
/* message in temps */ /* message in temps */
struct ceph_msg_header in_hdr; struct ceph_msg_header in_hdr;
struct ceph_msg *in_msg; struct ceph_msg *in_msg;
struct ceph_msg_pos in_msg_pos;
u32 in_front_crc, in_middle_crc, in_data_crc; /* calculated crc */ u32 in_front_crc, in_middle_crc, in_data_crc; /* calculated crc */
char in_tag; /* protocol control byte */ char in_tag; /* protocol control byte */
...@@ -218,6 +275,15 @@ extern void ceph_msg_revoke_incoming(struct ceph_msg *msg); ...@@ -218,6 +275,15 @@ extern void ceph_msg_revoke_incoming(struct ceph_msg *msg);
extern void ceph_con_keepalive(struct ceph_connection *con); extern void ceph_con_keepalive(struct ceph_connection *con);
extern void ceph_msg_data_add_pages(struct ceph_msg *msg, struct page **pages,
size_t length, size_t alignment);
extern void ceph_msg_data_add_pagelist(struct ceph_msg *msg,
struct ceph_pagelist *pagelist);
#ifdef CONFIG_BLOCK
extern void ceph_msg_data_add_bio(struct ceph_msg *msg, struct bio *bio,
size_t length);
#endif /* CONFIG_BLOCK */
extern struct ceph_msg *ceph_msg_new(int type, int front_len, gfp_t flags, extern struct ceph_msg *ceph_msg_new(int type, int front_len, gfp_t flags,
bool can_fail); bool can_fail);
extern void ceph_msg_kfree(struct ceph_msg *m); extern void ceph_msg_kfree(struct ceph_msg *m);
......
...@@ -87,6 +87,7 @@ struct ceph_entity_inst { ...@@ -87,6 +87,7 @@ struct ceph_entity_inst {
#define CEPH_MSGR_TAG_BADPROTOVER 10 /* bad protocol version */ #define CEPH_MSGR_TAG_BADPROTOVER 10 /* bad protocol version */
#define CEPH_MSGR_TAG_BADAUTHORIZER 11 /* bad authorizer */ #define CEPH_MSGR_TAG_BADAUTHORIZER 11 /* bad authorizer */
#define CEPH_MSGR_TAG_FEATURES 12 /* insufficient features */ #define CEPH_MSGR_TAG_FEATURES 12 /* insufficient features */
#define CEPH_MSGR_TAG_SEQ 13 /* 64-bit int follows with seen seq number */
/* /*
......
...@@ -29,6 +29,7 @@ struct ceph_authorizer; ...@@ -29,6 +29,7 @@ struct ceph_authorizer;
*/ */
typedef void (*ceph_osdc_callback_t)(struct ceph_osd_request *, typedef void (*ceph_osdc_callback_t)(struct ceph_osd_request *,
struct ceph_msg *); struct ceph_msg *);
typedef void (*ceph_osdc_unsafe_callback_t)(struct ceph_osd_request *, bool);
/* a given osd we're communicating with */ /* a given osd we're communicating with */
struct ceph_osd { struct ceph_osd {
...@@ -48,7 +49,67 @@ struct ceph_osd { ...@@ -48,7 +49,67 @@ struct ceph_osd {
}; };
#define CEPH_OSD_MAX_OP 10 #define CEPH_OSD_MAX_OP 2
enum ceph_osd_data_type {
CEPH_OSD_DATA_TYPE_NONE = 0,
CEPH_OSD_DATA_TYPE_PAGES,
CEPH_OSD_DATA_TYPE_PAGELIST,
#ifdef CONFIG_BLOCK
CEPH_OSD_DATA_TYPE_BIO,
#endif /* CONFIG_BLOCK */
};
struct ceph_osd_data {
enum ceph_osd_data_type type;
union {
struct {
struct page **pages;
u64 length;
u32 alignment;
bool pages_from_pool;
bool own_pages;
};
struct ceph_pagelist *pagelist;
#ifdef CONFIG_BLOCK
struct {
struct bio *bio; /* list of bios */
size_t bio_length; /* total in list */
};
#endif /* CONFIG_BLOCK */
};
};
struct ceph_osd_req_op {
u16 op; /* CEPH_OSD_OP_* */
u32 payload_len;
union {
struct ceph_osd_data raw_data_in;
struct {
u64 offset, length;
u64 truncate_size;
u32 truncate_seq;
struct ceph_osd_data osd_data;
} extent;
struct {
const char *class_name;
const char *method_name;
struct ceph_osd_data request_info;
struct ceph_osd_data request_data;
struct ceph_osd_data response_data;
__u8 class_len;
__u8 method_len;
__u8 argc;
} cls;
struct {
u64 cookie;
u64 ver;
u32 prot_ver;
u32 timeout;
__u8 flag;
} watch;
};
};
/* an in-flight request */ /* an in-flight request */
struct ceph_osd_request { struct ceph_osd_request {
...@@ -63,15 +124,14 @@ struct ceph_osd_request { ...@@ -63,15 +124,14 @@ struct ceph_osd_request {
int r_pg_osds[CEPH_PG_MAX_SIZE]; int r_pg_osds[CEPH_PG_MAX_SIZE];
int r_num_pg_osds; int r_num_pg_osds;
struct ceph_connection *r_con_filling_msg;
struct ceph_msg *r_request, *r_reply; struct ceph_msg *r_request, *r_reply;
int r_flags; /* any additional flags for the osd */ int r_flags; /* any additional flags for the osd */
u32 r_sent; /* >0 if r_request is sending/sent */ u32 r_sent; /* >0 if r_request is sending/sent */
int r_num_ops;
/* encoded message content */ /* request osd ops array */
struct ceph_osd_op *r_request_ops; unsigned int r_num_ops;
struct ceph_osd_req_op r_ops[CEPH_OSD_MAX_OP];
/* these are updated on each send */ /* these are updated on each send */
__le32 *r_request_osdmap_epoch; __le32 *r_request_osdmap_epoch;
__le32 *r_request_flags; __le32 *r_request_flags;
...@@ -85,12 +145,14 @@ struct ceph_osd_request { ...@@ -85,12 +145,14 @@ struct ceph_osd_request {
s32 r_reply_op_result[CEPH_OSD_MAX_OP]; s32 r_reply_op_result[CEPH_OSD_MAX_OP];
int r_got_reply; int r_got_reply;
int r_linger; int r_linger;
int r_completed;
struct ceph_osd_client *r_osdc; struct ceph_osd_client *r_osdc;
struct kref r_kref; struct kref r_kref;
bool r_mempool; bool r_mempool;
struct completion r_completion, r_safe_completion; struct completion r_completion, r_safe_completion;
ceph_osdc_callback_t r_callback, r_safe_callback; ceph_osdc_callback_t r_callback;
ceph_osdc_unsafe_callback_t r_unsafe_callback;
struct ceph_eversion r_reassert_version; struct ceph_eversion r_reassert_version;
struct list_head r_unsafe_item; struct list_head r_unsafe_item;
...@@ -104,16 +166,6 @@ struct ceph_osd_request { ...@@ -104,16 +166,6 @@ struct ceph_osd_request {
struct ceph_file_layout r_file_layout; struct ceph_file_layout r_file_layout;
struct ceph_snap_context *r_snapc; /* snap context for writes */ struct ceph_snap_context *r_snapc; /* snap context for writes */
unsigned r_num_pages; /* size of page array (follows) */
unsigned r_page_alignment; /* io offset in first page */
struct page **r_pages; /* pages for data payload */
int r_pages_from_pool;
int r_own_pages; /* if true, i own page list */
#ifdef CONFIG_BLOCK
struct bio *r_bio; /* instead of pages */
#endif
struct ceph_pagelist r_trail; /* trailing part of the data */
}; };
struct ceph_osd_event { struct ceph_osd_event {
...@@ -172,48 +224,8 @@ struct ceph_osd_client { ...@@ -172,48 +224,8 @@ struct ceph_osd_client {
struct workqueue_struct *notify_wq; struct workqueue_struct *notify_wq;
}; };
struct ceph_osd_req_op { extern int ceph_osdc_setup(void);
u16 op; /* CEPH_OSD_OP_* */ extern void ceph_osdc_cleanup(void);
u32 payload_len;
union {
struct {
u64 offset, length;
u64 truncate_size;
u32 truncate_seq;
} extent;
struct {
const char *name;
const char *val;
u32 name_len;
u32 value_len;
__u8 cmp_op; /* CEPH_OSD_CMPXATTR_OP_* */
__u8 cmp_mode; /* CEPH_OSD_CMPXATTR_MODE_* */
} xattr;
struct {
const char *class_name;
const char *method_name;
const char *indata;
u32 indata_len;
__u8 class_len;
__u8 method_len;
__u8 argc;
} cls;
struct {
u64 cookie;
u64 count;
} pgls;
struct {
u64 snapid;
} snap;
struct {
u64 cookie;
u64 ver;
u32 prot_ver;
u32 timeout;
__u8 flag;
} watch;
};
};
extern int ceph_osdc_init(struct ceph_osd_client *osdc, extern int ceph_osdc_init(struct ceph_osd_client *osdc,
struct ceph_client *client); struct ceph_client *client);
...@@ -224,16 +236,71 @@ extern void ceph_osdc_handle_reply(struct ceph_osd_client *osdc, ...@@ -224,16 +236,71 @@ extern void ceph_osdc_handle_reply(struct ceph_osd_client *osdc,
extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc, extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc,
struct ceph_msg *msg); struct ceph_msg *msg);
extern void osd_req_op_init(struct ceph_osd_request *osd_req,
unsigned int which, u16 opcode);
extern void osd_req_op_raw_data_in_pages(struct ceph_osd_request *,
unsigned int which,
struct page **pages, u64 length,
u32 alignment, bool pages_from_pool,
bool own_pages);
extern void osd_req_op_extent_init(struct ceph_osd_request *osd_req,
unsigned int which, u16 opcode,
u64 offset, u64 length,
u64 truncate_size, u32 truncate_seq);
extern void osd_req_op_extent_update(struct ceph_osd_request *osd_req,
unsigned int which, u64 length);
extern struct ceph_osd_data *osd_req_op_extent_osd_data(
struct ceph_osd_request *osd_req,
unsigned int which);
extern struct ceph_osd_data *osd_req_op_cls_response_data(
struct ceph_osd_request *osd_req,
unsigned int which);
extern void osd_req_op_extent_osd_data_pages(struct ceph_osd_request *,
unsigned int which,
struct page **pages, u64 length,
u32 alignment, bool pages_from_pool,
bool own_pages);
extern void osd_req_op_extent_osd_data_pagelist(struct ceph_osd_request *,
unsigned int which,
struct ceph_pagelist *pagelist);
#ifdef CONFIG_BLOCK
extern void osd_req_op_extent_osd_data_bio(struct ceph_osd_request *,
unsigned int which,
struct bio *bio, size_t bio_length);
#endif /* CONFIG_BLOCK */
extern void osd_req_op_cls_request_data_pagelist(struct ceph_osd_request *,
unsigned int which,
struct ceph_pagelist *pagelist);
extern void osd_req_op_cls_request_data_pages(struct ceph_osd_request *,
unsigned int which,
struct page **pages, u64 length,
u32 alignment, bool pages_from_pool,
bool own_pages);
extern void osd_req_op_cls_response_data_pages(struct ceph_osd_request *,
unsigned int which,
struct page **pages, u64 length,
u32 alignment, bool pages_from_pool,
bool own_pages);
extern void osd_req_op_cls_init(struct ceph_osd_request *osd_req,
unsigned int which, u16 opcode,
const char *class, const char *method);
extern void osd_req_op_watch_init(struct ceph_osd_request *osd_req,
unsigned int which, u16 opcode,
u64 cookie, u64 version, int flag);
extern struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc, extern struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
struct ceph_snap_context *snapc, struct ceph_snap_context *snapc,
unsigned int num_op, unsigned int num_ops,
bool use_mempool, bool use_mempool,
gfp_t gfp_flags); gfp_t gfp_flags);
extern void ceph_osdc_build_request(struct ceph_osd_request *req, extern void ceph_osdc_build_request(struct ceph_osd_request *req, u64 off,
u64 off, u64 len,
unsigned int num_op,
struct ceph_osd_req_op *src_ops,
struct ceph_snap_context *snapc, struct ceph_snap_context *snapc,
u64 snap_id, u64 snap_id,
struct timespec *mtime); struct timespec *mtime);
...@@ -241,12 +308,11 @@ extern void ceph_osdc_build_request(struct ceph_osd_request *req, ...@@ -241,12 +308,11 @@ extern void ceph_osdc_build_request(struct ceph_osd_request *req,
extern struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *, extern struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *,
struct ceph_file_layout *layout, struct ceph_file_layout *layout,
struct ceph_vino vino, struct ceph_vino vino,
u64 offset, u64 *len, int op, int flags, u64 offset, u64 *len,
int num_ops, int opcode, int flags,
struct ceph_snap_context *snapc, struct ceph_snap_context *snapc,
int do_sync, u32 truncate_seq, u32 truncate_seq, u64 truncate_size,
u64 truncate_size, bool use_mempool);
struct timespec *mtime,
bool use_mempool, int page_align);
extern void ceph_osdc_set_request_linger(struct ceph_osd_client *osdc, extern void ceph_osdc_set_request_linger(struct ceph_osd_client *osdc,
struct ceph_osd_request *req); struct ceph_osd_request *req);
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <linux/rbtree.h> #include <linux/rbtree.h>
#include <linux/ceph/types.h> #include <linux/ceph/types.h>
#include <linux/ceph/decode.h>
#include <linux/ceph/ceph_fs.h> #include <linux/ceph/ceph_fs.h>
#include <linux/crush/crush.h> #include <linux/crush/crush.h>
...@@ -119,6 +120,29 @@ static inline struct ceph_entity_addr *ceph_osd_addr(struct ceph_osdmap *map, ...@@ -119,6 +120,29 @@ static inline struct ceph_entity_addr *ceph_osd_addr(struct ceph_osdmap *map,
return &map->osd_addr[osd]; return &map->osd_addr[osd];
} }
static inline int ceph_decode_pgid(void **p, void *end, struct ceph_pg *pgid)
{
__u8 version;
if (!ceph_has_room(p, end, 1 + 8 + 4 + 4)) {
pr_warning("incomplete pg encoding");
return -EINVAL;
}
version = ceph_decode_8(p);
if (version > 1) {
pr_warning("do not understand pg encoding %d > 1",
(int)version);
return -EINVAL;
}
pgid->pool = ceph_decode_64(p);
pgid->seed = ceph_decode_32(p);
*p += 4; /* skip deprecated preferred value */
return 0;
}
extern struct ceph_osdmap *osdmap_decode(void **p, void *end); extern struct ceph_osdmap *osdmap_decode(void **p, void *end);
extern struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end, extern struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end,
struct ceph_osdmap *map, struct ceph_osdmap *map,
...@@ -131,10 +155,8 @@ extern int ceph_calc_file_object_mapping(struct ceph_file_layout *layout, ...@@ -131,10 +155,8 @@ extern int ceph_calc_file_object_mapping(struct ceph_file_layout *layout,
u64 *bno, u64 *oxoff, u64 *oxlen); u64 *bno, u64 *oxoff, u64 *oxlen);
/* calculate mapping of object to a placement group */ /* calculate mapping of object to a placement group */
extern int ceph_calc_object_layout(struct ceph_pg *pg, extern int ceph_calc_ceph_pg(struct ceph_pg *pg, const char *oid,
const char *oid, struct ceph_osdmap *osdmap, uint64_t pool);
struct ceph_file_layout *fl,
struct ceph_osdmap *osdmap);
extern int ceph_calc_pg_acting(struct ceph_osdmap *osdmap, extern int ceph_calc_pg_acting(struct ceph_osdmap *osdmap,
struct ceph_pg pgid, struct ceph_pg pgid,
int *acting); int *acting);
......
...@@ -11,5 +11,5 @@ libceph-y := ceph_common.o messenger.o msgpool.o buffer.o pagelist.o \ ...@@ -11,5 +11,5 @@ libceph-y := ceph_common.o messenger.o msgpool.o buffer.o pagelist.o \
crypto.o armor.o \ crypto.o armor.o \
auth_x.o \ auth_x.o \
ceph_fs.o ceph_strings.o ceph_hash.o \ ceph_fs.o ceph_strings.o ceph_hash.o \
pagevec.o pagevec.o snapshot.o
...@@ -47,6 +47,7 @@ struct ceph_auth_client *ceph_auth_init(const char *name, const struct ceph_cryp ...@@ -47,6 +47,7 @@ struct ceph_auth_client *ceph_auth_init(const char *name, const struct ceph_cryp
if (!ac) if (!ac)
goto out; goto out;
mutex_init(&ac->mutex);
ac->negotiating = true; ac->negotiating = true;
if (name) if (name)
ac->name = name; ac->name = name;
...@@ -73,10 +74,12 @@ void ceph_auth_destroy(struct ceph_auth_client *ac) ...@@ -73,10 +74,12 @@ void ceph_auth_destroy(struct ceph_auth_client *ac)
*/ */
void ceph_auth_reset(struct ceph_auth_client *ac) void ceph_auth_reset(struct ceph_auth_client *ac)
{ {
mutex_lock(&ac->mutex);
dout("auth_reset %p\n", ac); dout("auth_reset %p\n", ac);
if (ac->ops && !ac->negotiating) if (ac->ops && !ac->negotiating)
ac->ops->reset(ac); ac->ops->reset(ac);
ac->negotiating = true; ac->negotiating = true;
mutex_unlock(&ac->mutex);
} }
int ceph_entity_name_encode(const char *name, void **p, void *end) int ceph_entity_name_encode(const char *name, void **p, void *end)
...@@ -102,6 +105,7 @@ int ceph_auth_build_hello(struct ceph_auth_client *ac, void *buf, size_t len) ...@@ -102,6 +105,7 @@ int ceph_auth_build_hello(struct ceph_auth_client *ac, void *buf, size_t len)
int i, num; int i, num;
int ret; int ret;
mutex_lock(&ac->mutex);
dout("auth_build_hello\n"); dout("auth_build_hello\n");
monhdr->have_version = 0; monhdr->have_version = 0;
monhdr->session_mon = cpu_to_le16(-1); monhdr->session_mon = cpu_to_le16(-1);
...@@ -122,15 +126,19 @@ int ceph_auth_build_hello(struct ceph_auth_client *ac, void *buf, size_t len) ...@@ -122,15 +126,19 @@ int ceph_auth_build_hello(struct ceph_auth_client *ac, void *buf, size_t len)
ret = ceph_entity_name_encode(ac->name, &p, end); ret = ceph_entity_name_encode(ac->name, &p, end);
if (ret < 0) if (ret < 0)
return ret; goto out;
ceph_decode_need(&p, end, sizeof(u64), bad); ceph_decode_need(&p, end, sizeof(u64), bad);
ceph_encode_64(&p, ac->global_id); ceph_encode_64(&p, ac->global_id);
ceph_encode_32(&lenp, p - lenp - sizeof(u32)); ceph_encode_32(&lenp, p - lenp - sizeof(u32));
return p - buf; ret = p - buf;
out:
mutex_unlock(&ac->mutex);
return ret;
bad: bad:
return -ERANGE; ret = -ERANGE;
goto out;
} }
static int ceph_build_auth_request(struct ceph_auth_client *ac, static int ceph_build_auth_request(struct ceph_auth_client *ac,
...@@ -151,11 +159,13 @@ static int ceph_build_auth_request(struct ceph_auth_client *ac, ...@@ -151,11 +159,13 @@ static int ceph_build_auth_request(struct ceph_auth_client *ac,
if (ret < 0) { if (ret < 0) {
pr_err("error %d building auth method %s request\n", ret, pr_err("error %d building auth method %s request\n", ret,
ac->ops->name); ac->ops->name);
return ret; goto out;
} }
dout(" built request %d bytes\n", ret); dout(" built request %d bytes\n", ret);
ceph_encode_32(&p, ret); ceph_encode_32(&p, ret);
return p + ret - msg_buf; ret = p + ret - msg_buf;
out:
return ret;
} }
/* /*
...@@ -176,6 +186,7 @@ int ceph_handle_auth_reply(struct ceph_auth_client *ac, ...@@ -176,6 +186,7 @@ int ceph_handle_auth_reply(struct ceph_auth_client *ac,
int result_msg_len; int result_msg_len;
int ret = -EINVAL; int ret = -EINVAL;
mutex_lock(&ac->mutex);
dout("handle_auth_reply %p %p\n", p, end); dout("handle_auth_reply %p %p\n", p, end);
ceph_decode_need(&p, end, sizeof(u32) * 3 + sizeof(u64), bad); ceph_decode_need(&p, end, sizeof(u32) * 3 + sizeof(u64), bad);
protocol = ceph_decode_32(&p); protocol = ceph_decode_32(&p);
...@@ -227,33 +238,103 @@ int ceph_handle_auth_reply(struct ceph_auth_client *ac, ...@@ -227,33 +238,103 @@ int ceph_handle_auth_reply(struct ceph_auth_client *ac,
ret = ac->ops->handle_reply(ac, result, payload, payload_end); ret = ac->ops->handle_reply(ac, result, payload, payload_end);
if (ret == -EAGAIN) { if (ret == -EAGAIN) {
return ceph_build_auth_request(ac, reply_buf, reply_len); ret = ceph_build_auth_request(ac, reply_buf, reply_len);
} else if (ret) { } else if (ret) {
pr_err("auth method '%s' error %d\n", ac->ops->name, ret); pr_err("auth method '%s' error %d\n", ac->ops->name, ret);
return ret;
} }
return 0;
bad:
pr_err("failed to decode auth msg\n");
out: out:
mutex_unlock(&ac->mutex);
return ret; return ret;
bad:
pr_err("failed to decode auth msg\n");
ret = -EINVAL;
goto out;
} }
int ceph_build_auth(struct ceph_auth_client *ac, int ceph_build_auth(struct ceph_auth_client *ac,
void *msg_buf, size_t msg_len) void *msg_buf, size_t msg_len)
{ {
int ret = 0;
mutex_lock(&ac->mutex);
if (!ac->protocol) if (!ac->protocol)
return ceph_auth_build_hello(ac, msg_buf, msg_len); ret = ceph_auth_build_hello(ac, msg_buf, msg_len);
BUG_ON(!ac->ops); else if (ac->ops->should_authenticate(ac))
if (ac->ops->should_authenticate(ac)) ret = ceph_build_auth_request(ac, msg_buf, msg_len);
return ceph_build_auth_request(ac, msg_buf, msg_len); mutex_unlock(&ac->mutex);
return 0; return ret;
} }
int ceph_auth_is_authenticated(struct ceph_auth_client *ac) int ceph_auth_is_authenticated(struct ceph_auth_client *ac)
{ {
if (!ac->ops) int ret = 0;
return 0;
return ac->ops->is_authenticated(ac); mutex_lock(&ac->mutex);
if (ac->ops)
ret = ac->ops->is_authenticated(ac);
mutex_unlock(&ac->mutex);
return ret;
}
EXPORT_SYMBOL(ceph_auth_is_authenticated);
int ceph_auth_create_authorizer(struct ceph_auth_client *ac,
int peer_type,
struct ceph_auth_handshake *auth)
{
int ret = 0;
mutex_lock(&ac->mutex);
if (ac->ops && ac->ops->create_authorizer)
ret = ac->ops->create_authorizer(ac, peer_type, auth);
mutex_unlock(&ac->mutex);
return ret;
}
EXPORT_SYMBOL(ceph_auth_create_authorizer);
void ceph_auth_destroy_authorizer(struct ceph_auth_client *ac,
struct ceph_authorizer *a)
{
mutex_lock(&ac->mutex);
if (ac->ops && ac->ops->destroy_authorizer)
ac->ops->destroy_authorizer(ac, a);
mutex_unlock(&ac->mutex);
}
EXPORT_SYMBOL(ceph_auth_destroy_authorizer);
int ceph_auth_update_authorizer(struct ceph_auth_client *ac,
int peer_type,
struct ceph_auth_handshake *a)
{
int ret = 0;
mutex_lock(&ac->mutex);
if (ac->ops && ac->ops->update_authorizer)
ret = ac->ops->update_authorizer(ac, peer_type, a);
mutex_unlock(&ac->mutex);
return ret;
}
EXPORT_SYMBOL(ceph_auth_update_authorizer);
int ceph_auth_verify_authorizer_reply(struct ceph_auth_client *ac,
struct ceph_authorizer *a, size_t len)
{
int ret = 0;
mutex_lock(&ac->mutex);
if (ac->ops && ac->ops->verify_authorizer_reply)
ret = ac->ops->verify_authorizer_reply(ac, a, len);
mutex_unlock(&ac->mutex);
return ret;
}
EXPORT_SYMBOL(ceph_auth_verify_authorizer_reply);
void ceph_auth_invalidate_authorizer(struct ceph_auth_client *ac, int peer_type)
{
mutex_lock(&ac->mutex);
if (ac->ops && ac->ops->invalidate_authorizer)
ac->ops->invalidate_authorizer(ac, peer_type);
mutex_unlock(&ac->mutex);
} }
EXPORT_SYMBOL(ceph_auth_invalidate_authorizer);
...@@ -298,6 +298,7 @@ static int ceph_x_build_authorizer(struct ceph_auth_client *ac, ...@@ -298,6 +298,7 @@ static int ceph_x_build_authorizer(struct ceph_auth_client *ac,
return -ENOMEM; return -ENOMEM;
} }
au->service = th->service; au->service = th->service;
au->secret_id = th->secret_id;
msg_a = au->buf->vec.iov_base; msg_a = au->buf->vec.iov_base;
msg_a->struct_v = 1; msg_a->struct_v = 1;
...@@ -555,6 +556,26 @@ static int ceph_x_create_authorizer( ...@@ -555,6 +556,26 @@ static int ceph_x_create_authorizer(
return 0; return 0;
} }
static int ceph_x_update_authorizer(
struct ceph_auth_client *ac, int peer_type,
struct ceph_auth_handshake *auth)
{
struct ceph_x_authorizer *au;
struct ceph_x_ticket_handler *th;
th = get_ticket_handler(ac, peer_type);
if (IS_ERR(th))
return PTR_ERR(th);
au = (struct ceph_x_authorizer *)auth->authorizer;
if (au->secret_id < th->secret_id) {
dout("ceph_x_update_authorizer service %u secret %llu < %llu\n",
au->service, au->secret_id, th->secret_id);
return ceph_x_build_authorizer(ac, th, au);
}
return 0;
}
static int ceph_x_verify_authorizer_reply(struct ceph_auth_client *ac, static int ceph_x_verify_authorizer_reply(struct ceph_auth_client *ac,
struct ceph_authorizer *a, size_t len) struct ceph_authorizer *a, size_t len)
{ {
...@@ -630,7 +651,7 @@ static void ceph_x_invalidate_authorizer(struct ceph_auth_client *ac, ...@@ -630,7 +651,7 @@ static void ceph_x_invalidate_authorizer(struct ceph_auth_client *ac,
th = get_ticket_handler(ac, peer_type); th = get_ticket_handler(ac, peer_type);
if (!IS_ERR(th)) if (!IS_ERR(th))
remove_ticket_handler(ac, th); memset(&th->validity, 0, sizeof(th->validity));
} }
...@@ -641,6 +662,7 @@ static const struct ceph_auth_client_ops ceph_x_ops = { ...@@ -641,6 +662,7 @@ static const struct ceph_auth_client_ops ceph_x_ops = {
.build_request = ceph_x_build_request, .build_request = ceph_x_build_request,
.handle_reply = ceph_x_handle_reply, .handle_reply = ceph_x_handle_reply,
.create_authorizer = ceph_x_create_authorizer, .create_authorizer = ceph_x_create_authorizer,
.update_authorizer = ceph_x_update_authorizer,
.verify_authorizer_reply = ceph_x_verify_authorizer_reply, .verify_authorizer_reply = ceph_x_verify_authorizer_reply,
.destroy_authorizer = ceph_x_destroy_authorizer, .destroy_authorizer = ceph_x_destroy_authorizer,
.invalidate_authorizer = ceph_x_invalidate_authorizer, .invalidate_authorizer = ceph_x_invalidate_authorizer,
......
...@@ -29,6 +29,7 @@ struct ceph_x_authorizer { ...@@ -29,6 +29,7 @@ struct ceph_x_authorizer {
struct ceph_buffer *buf; struct ceph_buffer *buf;
unsigned int service; unsigned int service;
u64 nonce; u64 nonce;
u64 secret_id;
char reply_buf[128]; /* big enough for encrypted blob */ char reply_buf[128]; /* big enough for encrypted blob */
}; };
......
...@@ -606,11 +606,17 @@ static int __init init_ceph_lib(void) ...@@ -606,11 +606,17 @@ static int __init init_ceph_lib(void)
if (ret < 0) if (ret < 0)
goto out_crypto; goto out_crypto;
ret = ceph_osdc_setup();
if (ret < 0)
goto out_msgr;
pr_info("loaded (mon/osd proto %d/%d)\n", pr_info("loaded (mon/osd proto %d/%d)\n",
CEPH_MONC_PROTOCOL, CEPH_OSDC_PROTOCOL); CEPH_MONC_PROTOCOL, CEPH_OSDC_PROTOCOL);
return 0; return 0;
out_msgr:
ceph_msgr_exit();
out_crypto: out_crypto:
ceph_crypto_shutdown(); ceph_crypto_shutdown();
out_debugfs: out_debugfs:
...@@ -622,6 +628,7 @@ static int __init init_ceph_lib(void) ...@@ -622,6 +628,7 @@ static int __init init_ceph_lib(void)
static void __exit exit_ceph_lib(void) static void __exit exit_ceph_lib(void)
{ {
dout("exit_ceph_lib\n"); dout("exit_ceph_lib\n");
ceph_osdc_cleanup();
ceph_msgr_exit(); ceph_msgr_exit();
ceph_crypto_shutdown(); ceph_crypto_shutdown();
ceph_debugfs_cleanup(); ceph_debugfs_cleanup();
......
...@@ -123,8 +123,8 @@ static int osdc_show(struct seq_file *s, void *pp) ...@@ -123,8 +123,8 @@ static int osdc_show(struct seq_file *s, void *pp)
mutex_lock(&osdc->request_mutex); mutex_lock(&osdc->request_mutex);
for (p = rb_first(&osdc->requests); p; p = rb_next(p)) { for (p = rb_first(&osdc->requests); p; p = rb_next(p)) {
struct ceph_osd_request *req; struct ceph_osd_request *req;
unsigned int i;
int opcode; int opcode;
int i;
req = rb_entry(p, struct ceph_osd_request, r_node); req = rb_entry(p, struct ceph_osd_request, r_node);
...@@ -142,7 +142,7 @@ static int osdc_show(struct seq_file *s, void *pp) ...@@ -142,7 +142,7 @@ static int osdc_show(struct seq_file *s, void *pp)
seq_printf(s, "\t"); seq_printf(s, "\t");
for (i = 0; i < req->r_num_ops; i++) { for (i = 0; i < req->r_num_ops; i++) {
opcode = le16_to_cpu(req->r_request_ops[i].op); opcode = req->r_ops[i].op;
seq_printf(s, "\t%s", ceph_osd_op_name(opcode)); seq_printf(s, "\t%s", ceph_osd_op_name(opcode));
} }
......
...@@ -21,6 +21,9 @@ ...@@ -21,6 +21,9 @@
#include <linux/ceph/pagelist.h> #include <linux/ceph/pagelist.h>
#include <linux/export.h> #include <linux/export.h>
#define list_entry_next(pos, member) \
list_entry(pos->member.next, typeof(*pos), member)
/* /*
* Ceph uses the messenger to exchange ceph_msg messages with other * Ceph uses the messenger to exchange ceph_msg messages with other
* hosts in the system. The messenger provides ordered and reliable * hosts in the system. The messenger provides ordered and reliable
...@@ -149,6 +152,11 @@ static bool con_flag_test_and_set(struct ceph_connection *con, ...@@ -149,6 +152,11 @@ static bool con_flag_test_and_set(struct ceph_connection *con,
return test_and_set_bit(con_flag, &con->flags); return test_and_set_bit(con_flag, &con->flags);
} }
/* Slab caches for frequently-allocated structures */
static struct kmem_cache *ceph_msg_cache;
static struct kmem_cache *ceph_msg_data_cache;
/* static tag bytes (protocol control messages) */ /* static tag bytes (protocol control messages) */
static char tag_msg = CEPH_MSGR_TAG_MSG; static char tag_msg = CEPH_MSGR_TAG_MSG;
static char tag_ack = CEPH_MSGR_TAG_ACK; static char tag_ack = CEPH_MSGR_TAG_ACK;
...@@ -223,6 +231,41 @@ static void encode_my_addr(struct ceph_messenger *msgr) ...@@ -223,6 +231,41 @@ static void encode_my_addr(struct ceph_messenger *msgr)
*/ */
static struct workqueue_struct *ceph_msgr_wq; static struct workqueue_struct *ceph_msgr_wq;
static int ceph_msgr_slab_init(void)
{
BUG_ON(ceph_msg_cache);
ceph_msg_cache = kmem_cache_create("ceph_msg",
sizeof (struct ceph_msg),
__alignof__(struct ceph_msg), 0, NULL);
if (!ceph_msg_cache)
return -ENOMEM;
BUG_ON(ceph_msg_data_cache);
ceph_msg_data_cache = kmem_cache_create("ceph_msg_data",
sizeof (struct ceph_msg_data),
__alignof__(struct ceph_msg_data),
0, NULL);
if (ceph_msg_data_cache)
return 0;
kmem_cache_destroy(ceph_msg_cache);
ceph_msg_cache = NULL;
return -ENOMEM;
}
static void ceph_msgr_slab_exit(void)
{
BUG_ON(!ceph_msg_data_cache);
kmem_cache_destroy(ceph_msg_data_cache);
ceph_msg_data_cache = NULL;
BUG_ON(!ceph_msg_cache);
kmem_cache_destroy(ceph_msg_cache);
ceph_msg_cache = NULL;
}
static void _ceph_msgr_exit(void) static void _ceph_msgr_exit(void)
{ {
if (ceph_msgr_wq) { if (ceph_msgr_wq) {
...@@ -230,6 +273,8 @@ static void _ceph_msgr_exit(void) ...@@ -230,6 +273,8 @@ static void _ceph_msgr_exit(void)
ceph_msgr_wq = NULL; ceph_msgr_wq = NULL;
} }
ceph_msgr_slab_exit();
BUG_ON(zero_page == NULL); BUG_ON(zero_page == NULL);
kunmap(zero_page); kunmap(zero_page);
page_cache_release(zero_page); page_cache_release(zero_page);
...@@ -242,6 +287,9 @@ int ceph_msgr_init(void) ...@@ -242,6 +287,9 @@ int ceph_msgr_init(void)
zero_page = ZERO_PAGE(0); zero_page = ZERO_PAGE(0);
page_cache_get(zero_page); page_cache_get(zero_page);
if (ceph_msgr_slab_init())
return -ENOMEM;
ceph_msgr_wq = alloc_workqueue("ceph-msgr", WQ_NON_REENTRANT, 0); ceph_msgr_wq = alloc_workqueue("ceph-msgr", WQ_NON_REENTRANT, 0);
if (ceph_msgr_wq) if (ceph_msgr_wq)
return 0; return 0;
...@@ -471,6 +519,22 @@ static int ceph_tcp_recvmsg(struct socket *sock, void *buf, size_t len) ...@@ -471,6 +519,22 @@ static int ceph_tcp_recvmsg(struct socket *sock, void *buf, size_t len)
return r; return r;
} }
static int ceph_tcp_recvpage(struct socket *sock, struct page *page,
int page_offset, size_t length)
{
void *kaddr;
int ret;
BUG_ON(page_offset + length > PAGE_SIZE);
kaddr = kmap(page);
BUG_ON(!kaddr);
ret = ceph_tcp_recvmsg(sock, kaddr + page_offset, length);
kunmap(page);
return ret;
}
/* /*
* write something. @more is true if caller will be sending more data * write something. @more is true if caller will be sending more data
* shortly. * shortly.
...@@ -493,7 +557,7 @@ static int ceph_tcp_sendmsg(struct socket *sock, struct kvec *iov, ...@@ -493,7 +557,7 @@ static int ceph_tcp_sendmsg(struct socket *sock, struct kvec *iov,
} }
static int ceph_tcp_sendpage(struct socket *sock, struct page *page, static int ceph_tcp_sendpage(struct socket *sock, struct page *page,
int offset, size_t size, int more) int offset, size_t size, bool more)
{ {
int flags = MSG_DONTWAIT | MSG_NOSIGNAL | (more ? MSG_MORE : MSG_EOR); int flags = MSG_DONTWAIT | MSG_NOSIGNAL | (more ? MSG_MORE : MSG_EOR);
int ret; int ret;
...@@ -697,50 +761,397 @@ static void con_out_kvec_add(struct ceph_connection *con, ...@@ -697,50 +761,397 @@ static void con_out_kvec_add(struct ceph_connection *con,
} }
#ifdef CONFIG_BLOCK #ifdef CONFIG_BLOCK
static void init_bio_iter(struct bio *bio, struct bio **iter, int *seg)
/*
* For a bio data item, a piece is whatever remains of the next
* entry in the current bio iovec, or the first entry in the next
* bio in the list.
*/
static void ceph_msg_data_bio_cursor_init(struct ceph_msg_data_cursor *cursor,
size_t length)
{ {
if (!bio) { struct ceph_msg_data *data = cursor->data;
*iter = NULL; struct bio *bio;
*seg = 0;
return; BUG_ON(data->type != CEPH_MSG_DATA_BIO);
bio = data->bio;
BUG_ON(!bio);
BUG_ON(!bio->bi_vcnt);
cursor->resid = min(length, data->bio_length);
cursor->bio = bio;
cursor->vector_index = 0;
cursor->vector_offset = 0;
cursor->last_piece = length <= bio->bi_io_vec[0].bv_len;
}
static struct page *ceph_msg_data_bio_next(struct ceph_msg_data_cursor *cursor,
size_t *page_offset,
size_t *length)
{
struct ceph_msg_data *data = cursor->data;
struct bio *bio;
struct bio_vec *bio_vec;
unsigned int index;
BUG_ON(data->type != CEPH_MSG_DATA_BIO);
bio = cursor->bio;
BUG_ON(!bio);
index = cursor->vector_index;
BUG_ON(index >= (unsigned int) bio->bi_vcnt);
bio_vec = &bio->bi_io_vec[index];
BUG_ON(cursor->vector_offset >= bio_vec->bv_len);
*page_offset = (size_t) (bio_vec->bv_offset + cursor->vector_offset);
BUG_ON(*page_offset >= PAGE_SIZE);
if (cursor->last_piece) /* pagelist offset is always 0 */
*length = cursor->resid;
else
*length = (size_t) (bio_vec->bv_len - cursor->vector_offset);
BUG_ON(*length > cursor->resid);
BUG_ON(*page_offset + *length > PAGE_SIZE);
return bio_vec->bv_page;
}
static bool ceph_msg_data_bio_advance(struct ceph_msg_data_cursor *cursor,
size_t bytes)
{
struct bio *bio;
struct bio_vec *bio_vec;
unsigned int index;
BUG_ON(cursor->data->type != CEPH_MSG_DATA_BIO);
bio = cursor->bio;
BUG_ON(!bio);
index = cursor->vector_index;
BUG_ON(index >= (unsigned int) bio->bi_vcnt);
bio_vec = &bio->bi_io_vec[index];
/* Advance the cursor offset */
BUG_ON(cursor->resid < bytes);
cursor->resid -= bytes;
cursor->vector_offset += bytes;
if (cursor->vector_offset < bio_vec->bv_len)
return false; /* more bytes to process in this segment */
BUG_ON(cursor->vector_offset != bio_vec->bv_len);
/* Move on to the next segment, and possibly the next bio */
if (++index == (unsigned int) bio->bi_vcnt) {
bio = bio->bi_next;
index = 0;
} }
*iter = bio; cursor->bio = bio;
*seg = bio->bi_idx; cursor->vector_index = index;
cursor->vector_offset = 0;
if (!cursor->last_piece) {
BUG_ON(!cursor->resid);
BUG_ON(!bio);
/* A short read is OK, so use <= rather than == */
if (cursor->resid <= bio->bi_io_vec[index].bv_len)
cursor->last_piece = true;
}
return true;
} }
#endif /* CONFIG_BLOCK */
static void iter_bio_next(struct bio **bio_iter, int *seg) /*
* For a page array, a piece comes from the first page in the array
* that has not already been fully consumed.
*/
static void ceph_msg_data_pages_cursor_init(struct ceph_msg_data_cursor *cursor,
size_t length)
{ {
if (*bio_iter == NULL) struct ceph_msg_data *data = cursor->data;
return; int page_count;
BUG_ON(data->type != CEPH_MSG_DATA_PAGES);
BUG_ON(*seg >= (*bio_iter)->bi_vcnt); BUG_ON(!data->pages);
BUG_ON(!data->length);
(*seg)++; cursor->resid = min(length, data->length);
if (*seg == (*bio_iter)->bi_vcnt) page_count = calc_pages_for(data->alignment, (u64)data->length);
init_bio_iter((*bio_iter)->bi_next, bio_iter, seg); cursor->page_offset = data->alignment & ~PAGE_MASK;
cursor->page_index = 0;
BUG_ON(page_count > (int)USHRT_MAX);
cursor->page_count = (unsigned short)page_count;
BUG_ON(length > SIZE_MAX - cursor->page_offset);
cursor->last_piece = (size_t)cursor->page_offset + length <= PAGE_SIZE;
} }
#endif
static void prepare_write_message_data(struct ceph_connection *con) static struct page *
ceph_msg_data_pages_next(struct ceph_msg_data_cursor *cursor,
size_t *page_offset, size_t *length)
{ {
struct ceph_msg *msg = con->out_msg; struct ceph_msg_data *data = cursor->data;
BUG_ON(!msg); BUG_ON(data->type != CEPH_MSG_DATA_PAGES);
BUG_ON(!msg->hdr.data_len);
BUG_ON(cursor->page_index >= cursor->page_count);
BUG_ON(cursor->page_offset >= PAGE_SIZE);
*page_offset = cursor->page_offset;
if (cursor->last_piece)
*length = cursor->resid;
else
*length = PAGE_SIZE - *page_offset;
return data->pages[cursor->page_index];
}
static bool ceph_msg_data_pages_advance(struct ceph_msg_data_cursor *cursor,
size_t bytes)
{
BUG_ON(cursor->data->type != CEPH_MSG_DATA_PAGES);
BUG_ON(cursor->page_offset + bytes > PAGE_SIZE);
/* Advance the cursor page offset */
cursor->resid -= bytes;
cursor->page_offset = (cursor->page_offset + bytes) & ~PAGE_MASK;
if (!bytes || cursor->page_offset)
return false; /* more bytes to process in the current page */
/* Move on to the next page; offset is already at 0 */
BUG_ON(cursor->page_index >= cursor->page_count);
cursor->page_index++;
cursor->last_piece = cursor->resid <= PAGE_SIZE;
return true;
}
/*
* For a pagelist, a piece is whatever remains to be consumed in the
* first page in the list, or the front of the next page.
*/
static void
ceph_msg_data_pagelist_cursor_init(struct ceph_msg_data_cursor *cursor,
size_t length)
{
struct ceph_msg_data *data = cursor->data;
struct ceph_pagelist *pagelist;
struct page *page;
BUG_ON(data->type != CEPH_MSG_DATA_PAGELIST);
pagelist = data->pagelist;
BUG_ON(!pagelist);
if (!length)
return; /* pagelist can be assigned but empty */
BUG_ON(list_empty(&pagelist->head));
page = list_first_entry(&pagelist->head, struct page, lru);
cursor->resid = min(length, pagelist->length);
cursor->page = page;
cursor->offset = 0;
cursor->last_piece = cursor->resid <= PAGE_SIZE;
}
static struct page *
ceph_msg_data_pagelist_next(struct ceph_msg_data_cursor *cursor,
size_t *page_offset, size_t *length)
{
struct ceph_msg_data *data = cursor->data;
struct ceph_pagelist *pagelist;
BUG_ON(data->type != CEPH_MSG_DATA_PAGELIST);
/* initialize page iterator */ pagelist = data->pagelist;
con->out_msg_pos.page = 0; BUG_ON(!pagelist);
if (msg->pages)
con->out_msg_pos.page_pos = msg->page_alignment; BUG_ON(!cursor->page);
BUG_ON(cursor->offset + cursor->resid != pagelist->length);
/* offset of first page in pagelist is always 0 */
*page_offset = cursor->offset & ~PAGE_MASK;
if (cursor->last_piece)
*length = cursor->resid;
else else
con->out_msg_pos.page_pos = 0; *length = PAGE_SIZE - *page_offset;
return cursor->page;
}
static bool ceph_msg_data_pagelist_advance(struct ceph_msg_data_cursor *cursor,
size_t bytes)
{
struct ceph_msg_data *data = cursor->data;
struct ceph_pagelist *pagelist;
BUG_ON(data->type != CEPH_MSG_DATA_PAGELIST);
pagelist = data->pagelist;
BUG_ON(!pagelist);
BUG_ON(cursor->offset + cursor->resid != pagelist->length);
BUG_ON((cursor->offset & ~PAGE_MASK) + bytes > PAGE_SIZE);
/* Advance the cursor offset */
cursor->resid -= bytes;
cursor->offset += bytes;
/* offset of first page in pagelist is always 0 */
if (!bytes || cursor->offset & ~PAGE_MASK)
return false; /* more bytes to process in the current page */
/* Move on to the next page */
BUG_ON(list_is_last(&cursor->page->lru, &pagelist->head));
cursor->page = list_entry_next(cursor->page, lru);
cursor->last_piece = cursor->resid <= PAGE_SIZE;
return true;
}
/*
* Message data is handled (sent or received) in pieces, where each
* piece resides on a single page. The network layer might not
* consume an entire piece at once. A data item's cursor keeps
* track of which piece is next to process and how much remains to
* be processed in that piece. It also tracks whether the current
* piece is the last one in the data item.
*/
static void __ceph_msg_data_cursor_init(struct ceph_msg_data_cursor *cursor)
{
size_t length = cursor->total_resid;
switch (cursor->data->type) {
case CEPH_MSG_DATA_PAGELIST:
ceph_msg_data_pagelist_cursor_init(cursor, length);
break;
case CEPH_MSG_DATA_PAGES:
ceph_msg_data_pages_cursor_init(cursor, length);
break;
#ifdef CONFIG_BLOCK #ifdef CONFIG_BLOCK
if (msg->bio) case CEPH_MSG_DATA_BIO:
init_bio_iter(msg->bio, &msg->bio_iter, &msg->bio_seg); ceph_msg_data_bio_cursor_init(cursor, length);
#endif break;
con->out_msg_pos.data_pos = 0; #endif /* CONFIG_BLOCK */
con->out_msg_pos.did_page_crc = false; case CEPH_MSG_DATA_NONE:
con->out_more = 1; /* data + footer will follow */ default:
/* BUG(); */
break;
}
cursor->need_crc = true;
}
static void ceph_msg_data_cursor_init(struct ceph_msg *msg, size_t length)
{
struct ceph_msg_data_cursor *cursor = &msg->cursor;
struct ceph_msg_data *data;
BUG_ON(!length);
BUG_ON(length > msg->data_length);
BUG_ON(list_empty(&msg->data));
cursor->data_head = &msg->data;
cursor->total_resid = length;
data = list_first_entry(&msg->data, struct ceph_msg_data, links);
cursor->data = data;
__ceph_msg_data_cursor_init(cursor);
}
/*
* Return the page containing the next piece to process for a given
* data item, and supply the page offset and length of that piece.
* Indicate whether this is the last piece in this data item.
*/
static struct page *ceph_msg_data_next(struct ceph_msg_data_cursor *cursor,
size_t *page_offset, size_t *length,
bool *last_piece)
{
struct page *page;
switch (cursor->data->type) {
case CEPH_MSG_DATA_PAGELIST:
page = ceph_msg_data_pagelist_next(cursor, page_offset, length);
break;
case CEPH_MSG_DATA_PAGES:
page = ceph_msg_data_pages_next(cursor, page_offset, length);
break;
#ifdef CONFIG_BLOCK
case CEPH_MSG_DATA_BIO:
page = ceph_msg_data_bio_next(cursor, page_offset, length);
break;
#endif /* CONFIG_BLOCK */
case CEPH_MSG_DATA_NONE:
default:
page = NULL;
break;
}
BUG_ON(!page);
BUG_ON(*page_offset + *length > PAGE_SIZE);
BUG_ON(!*length);
if (last_piece)
*last_piece = cursor->last_piece;
return page;
}
/*
* Returns true if the result moves the cursor on to the next piece
* of the data item.
*/
static bool ceph_msg_data_advance(struct ceph_msg_data_cursor *cursor,
size_t bytes)
{
bool new_piece;
BUG_ON(bytes > cursor->resid);
switch (cursor->data->type) {
case CEPH_MSG_DATA_PAGELIST:
new_piece = ceph_msg_data_pagelist_advance(cursor, bytes);
break;
case CEPH_MSG_DATA_PAGES:
new_piece = ceph_msg_data_pages_advance(cursor, bytes);
break;
#ifdef CONFIG_BLOCK
case CEPH_MSG_DATA_BIO:
new_piece = ceph_msg_data_bio_advance(cursor, bytes);
break;
#endif /* CONFIG_BLOCK */
case CEPH_MSG_DATA_NONE:
default:
BUG();
break;
}
cursor->total_resid -= bytes;
if (!cursor->resid && cursor->total_resid) {
WARN_ON(!cursor->last_piece);
BUG_ON(list_is_last(&cursor->data->links, cursor->data_head));
cursor->data = list_entry_next(cursor->data, links);
__ceph_msg_data_cursor_init(cursor);
new_piece = true;
}
cursor->need_crc = new_piece;
return new_piece;
}
static void prepare_message_data(struct ceph_msg *msg, u32 data_len)
{
BUG_ON(!msg);
BUG_ON(!data_len);
/* Initialize data cursor */
ceph_msg_data_cursor_init(msg, (size_t)data_len);
} }
/* /*
...@@ -803,16 +1214,12 @@ static void prepare_write_message(struct ceph_connection *con) ...@@ -803,16 +1214,12 @@ static void prepare_write_message(struct ceph_connection *con)
m->hdr.seq = cpu_to_le64(++con->out_seq); m->hdr.seq = cpu_to_le64(++con->out_seq);
m->needs_out_seq = false; m->needs_out_seq = false;
} }
#ifdef CONFIG_BLOCK WARN_ON(m->data_length != le32_to_cpu(m->hdr.data_len));
else
m->bio_iter = NULL;
#endif
dout("prepare_write_message %p seq %lld type %d len %d+%d+%d %d pgs\n", dout("prepare_write_message %p seq %lld type %d len %d+%d+%zd\n",
m, con->out_seq, le16_to_cpu(m->hdr.type), m, con->out_seq, le16_to_cpu(m->hdr.type),
le32_to_cpu(m->hdr.front_len), le32_to_cpu(m->hdr.middle_len), le32_to_cpu(m->hdr.front_len), le32_to_cpu(m->hdr.middle_len),
le32_to_cpu(m->hdr.data_len), m->data_length);
m->nr_pages);
BUG_ON(le32_to_cpu(m->hdr.front_len) != m->front.iov_len); BUG_ON(le32_to_cpu(m->hdr.front_len) != m->front.iov_len);
/* tag + hdr + front + middle */ /* tag + hdr + front + middle */
...@@ -843,11 +1250,13 @@ static void prepare_write_message(struct ceph_connection *con) ...@@ -843,11 +1250,13 @@ static void prepare_write_message(struct ceph_connection *con)
/* is there a data payload? */ /* is there a data payload? */
con->out_msg->footer.data_crc = 0; con->out_msg->footer.data_crc = 0;
if (m->hdr.data_len) if (m->data_length) {
prepare_write_message_data(con); prepare_message_data(con->out_msg, m->data_length);
else con->out_more = 1; /* data + footer will follow */
} else {
/* no, queue up footer too and be done */ /* no, queue up footer too and be done */
prepare_write_message_footer(con); prepare_write_message_footer(con);
}
con_flag_set(con, CON_FLAG_WRITE_PENDING); con_flag_set(con, CON_FLAG_WRITE_PENDING);
} }
...@@ -873,6 +1282,24 @@ static void prepare_write_ack(struct ceph_connection *con) ...@@ -873,6 +1282,24 @@ static void prepare_write_ack(struct ceph_connection *con)
con_flag_set(con, CON_FLAG_WRITE_PENDING); con_flag_set(con, CON_FLAG_WRITE_PENDING);
} }
/*
* Prepare to share the seq during handshake
*/
static void prepare_write_seq(struct ceph_connection *con)
{
dout("prepare_write_seq %p %llu -> %llu\n", con,
con->in_seq_acked, con->in_seq);
con->in_seq_acked = con->in_seq;
con_out_kvec_reset(con);
con->out_temp_ack = cpu_to_le64(con->in_seq_acked);
con_out_kvec_add(con, sizeof (con->out_temp_ack),
&con->out_temp_ack);
con_flag_set(con, CON_FLAG_WRITE_PENDING);
}
/* /*
* Prepare to write keepalive byte. * Prepare to write keepalive byte.
*/ */
...@@ -1022,35 +1449,19 @@ static int write_partial_kvec(struct ceph_connection *con) ...@@ -1022,35 +1449,19 @@ static int write_partial_kvec(struct ceph_connection *con)
return ret; /* done! */ return ret; /* done! */
} }
static void out_msg_pos_next(struct ceph_connection *con, struct page *page, static u32 ceph_crc32c_page(u32 crc, struct page *page,
size_t len, size_t sent, bool in_trail) unsigned int page_offset,
unsigned int length)
{ {
struct ceph_msg *msg = con->out_msg; char *kaddr;
BUG_ON(!msg); kaddr = kmap(page);
BUG_ON(!sent); BUG_ON(kaddr == NULL);
crc = crc32c(crc, kaddr + page_offset, length);
con->out_msg_pos.data_pos += sent; kunmap(page);
con->out_msg_pos.page_pos += sent;
if (sent < len)
return;
BUG_ON(sent != len); return crc;
con->out_msg_pos.page_pos = 0;
con->out_msg_pos.page++;
con->out_msg_pos.did_page_crc = false;
if (in_trail)
list_move_tail(&page->lru,
&msg->trail->head);
else if (msg->pagelist)
list_move_tail(&page->lru,
&msg->pagelist->head);
#ifdef CONFIG_BLOCK
else if (msg->bio)
iter_bio_next(&msg->bio_iter, &msg->bio_seg);
#endif
} }
/* /*
* Write as much message data payload as we can. If we finish, queue * Write as much message data payload as we can. If we finish, queue
* up the footer. * up the footer.
...@@ -1058,21 +1469,17 @@ static void out_msg_pos_next(struct ceph_connection *con, struct page *page, ...@@ -1058,21 +1469,17 @@ static void out_msg_pos_next(struct ceph_connection *con, struct page *page,
* 0 -> socket full, but more to do * 0 -> socket full, but more to do
* <0 -> error * <0 -> error
*/ */
static int write_partial_msg_pages(struct ceph_connection *con) static int write_partial_message_data(struct ceph_connection *con)
{ {
struct ceph_msg *msg = con->out_msg; struct ceph_msg *msg = con->out_msg;
unsigned int data_len = le32_to_cpu(msg->hdr.data_len); struct ceph_msg_data_cursor *cursor = &msg->cursor;
size_t len;
bool do_datacrc = !con->msgr->nocrc; bool do_datacrc = !con->msgr->nocrc;
int ret; u32 crc;
int total_max_write;
bool in_trail = false;
const size_t trail_len = (msg->trail ? msg->trail->length : 0);
const size_t trail_off = data_len - trail_len;
dout("write_partial_msg_pages %p msg %p page %d/%d offset %d\n", dout("%s %p msg %p\n", __func__, con, msg);
con, msg, con->out_msg_pos.page, msg->nr_pages,
con->out_msg_pos.page_pos); if (list_empty(&msg->data))
return -EINVAL;
/* /*
* Iterate through each page that contains data to be * Iterate through each page that contains data to be
...@@ -1082,72 +1489,41 @@ static int write_partial_msg_pages(struct ceph_connection *con) ...@@ -1082,72 +1489,41 @@ static int write_partial_msg_pages(struct ceph_connection *con)
* need to map the page. If we have no pages, they have * need to map the page. If we have no pages, they have
* been revoked, so use the zero page. * been revoked, so use the zero page.
*/ */
while (data_len > con->out_msg_pos.data_pos) { crc = do_datacrc ? le32_to_cpu(msg->footer.data_crc) : 0;
struct page *page = NULL; while (cursor->resid) {
int max_write = PAGE_SIZE; struct page *page;
int bio_offset = 0; size_t page_offset;
size_t length;
in_trail = in_trail || con->out_msg_pos.data_pos >= trail_off; bool last_piece;
if (!in_trail) bool need_crc;
total_max_write = trail_off - con->out_msg_pos.data_pos; int ret;
if (in_trail) {
total_max_write = data_len - con->out_msg_pos.data_pos;
page = list_first_entry(&msg->trail->head,
struct page, lru);
} else if (msg->pages) {
page = msg->pages[con->out_msg_pos.page];
} else if (msg->pagelist) {
page = list_first_entry(&msg->pagelist->head,
struct page, lru);
#ifdef CONFIG_BLOCK
} else if (msg->bio) {
struct bio_vec *bv;
bv = bio_iovec_idx(msg->bio_iter, msg->bio_seg); page = ceph_msg_data_next(&msg->cursor, &page_offset, &length,
page = bv->bv_page; &last_piece);
bio_offset = bv->bv_offset; ret = ceph_tcp_sendpage(con->sock, page, page_offset,
max_write = bv->bv_len; length, last_piece);
#endif if (ret <= 0) {
} else { if (do_datacrc)
page = zero_page; msg->footer.data_crc = cpu_to_le32(crc);
}
len = min_t(int, max_write - con->out_msg_pos.page_pos,
total_max_write);
if (do_datacrc && !con->out_msg_pos.did_page_crc) {
void *base;
u32 crc = le32_to_cpu(msg->footer.data_crc);
char *kaddr;
kaddr = kmap(page);
BUG_ON(kaddr == NULL);
base = kaddr + con->out_msg_pos.page_pos + bio_offset;
crc = crc32c(crc, base, len);
kunmap(page);
msg->footer.data_crc = cpu_to_le32(crc);
con->out_msg_pos.did_page_crc = true;
}
ret = ceph_tcp_sendpage(con->sock, page,
con->out_msg_pos.page_pos + bio_offset,
len, 1);
if (ret <= 0)
goto out;
out_msg_pos_next(con, page, len, (size_t) ret, in_trail); return ret;
}
if (do_datacrc && cursor->need_crc)
crc = ceph_crc32c_page(crc, page, page_offset, length);
need_crc = ceph_msg_data_advance(&msg->cursor, (size_t)ret);
} }
dout("write_partial_msg_pages %p msg %p done\n", con, msg); dout("%s %p msg %p done\n", __func__, con, msg);
/* prepare and queue up footer, too */ /* prepare and queue up footer, too */
if (!do_datacrc) if (do_datacrc)
msg->footer.data_crc = cpu_to_le32(crc);
else
msg->footer.flags |= CEPH_MSG_FOOTER_NOCRC; msg->footer.flags |= CEPH_MSG_FOOTER_NOCRC;
con_out_kvec_reset(con); con_out_kvec_reset(con);
prepare_write_message_footer(con); prepare_write_message_footer(con);
ret = 1;
out: return 1; /* must return > 0 to indicate success */
return ret;
} }
/* /*
...@@ -1160,7 +1536,7 @@ static int write_partial_skip(struct ceph_connection *con) ...@@ -1160,7 +1536,7 @@ static int write_partial_skip(struct ceph_connection *con)
while (con->out_skip > 0) { while (con->out_skip > 0) {
size_t size = min(con->out_skip, (int) PAGE_CACHE_SIZE); size_t size = min(con->out_skip, (int) PAGE_CACHE_SIZE);
ret = ceph_tcp_sendpage(con->sock, zero_page, 0, size, 1); ret = ceph_tcp_sendpage(con->sock, zero_page, 0, size, true);
if (ret <= 0) if (ret <= 0)
goto out; goto out;
con->out_skip -= ret; con->out_skip -= ret;
...@@ -1191,6 +1567,13 @@ static void prepare_read_ack(struct ceph_connection *con) ...@@ -1191,6 +1567,13 @@ static void prepare_read_ack(struct ceph_connection *con)
con->in_base_pos = 0; con->in_base_pos = 0;
} }
static void prepare_read_seq(struct ceph_connection *con)
{
dout("prepare_read_seq %p\n", con);
con->in_base_pos = 0;
con->in_tag = CEPH_MSGR_TAG_SEQ;
}
static void prepare_read_tag(struct ceph_connection *con) static void prepare_read_tag(struct ceph_connection *con)
{ {
dout("prepare_read_tag %p\n", con); dout("prepare_read_tag %p\n", con);
...@@ -1597,7 +1980,6 @@ static int process_connect(struct ceph_connection *con) ...@@ -1597,7 +1980,6 @@ static int process_connect(struct ceph_connection *con)
con->error_msg = "connect authorization failure"; con->error_msg = "connect authorization failure";
return -1; return -1;
} }
con->auth_retry = 1;
con_out_kvec_reset(con); con_out_kvec_reset(con);
ret = prepare_write_connect(con); ret = prepare_write_connect(con);
if (ret < 0) if (ret < 0)
...@@ -1668,6 +2050,7 @@ static int process_connect(struct ceph_connection *con) ...@@ -1668,6 +2050,7 @@ static int process_connect(struct ceph_connection *con)
prepare_read_connect(con); prepare_read_connect(con);
break; break;
case CEPH_MSGR_TAG_SEQ:
case CEPH_MSGR_TAG_READY: case CEPH_MSGR_TAG_READY:
if (req_feat & ~server_feat) { if (req_feat & ~server_feat) {
pr_err("%s%lld %s protocol feature mismatch," pr_err("%s%lld %s protocol feature mismatch,"
...@@ -1682,7 +2065,7 @@ static int process_connect(struct ceph_connection *con) ...@@ -1682,7 +2065,7 @@ static int process_connect(struct ceph_connection *con)
WARN_ON(con->state != CON_STATE_NEGOTIATING); WARN_ON(con->state != CON_STATE_NEGOTIATING);
con->state = CON_STATE_OPEN; con->state = CON_STATE_OPEN;
con->auth_retry = 0; /* we authenticated; clear flag */
con->peer_global_seq = le32_to_cpu(con->in_reply.global_seq); con->peer_global_seq = le32_to_cpu(con->in_reply.global_seq);
con->connect_seq++; con->connect_seq++;
con->peer_features = server_feat; con->peer_features = server_feat;
...@@ -1698,7 +2081,12 @@ static int process_connect(struct ceph_connection *con) ...@@ -1698,7 +2081,12 @@ static int process_connect(struct ceph_connection *con)
con->delay = 0; /* reset backoff memory */ con->delay = 0; /* reset backoff memory */
prepare_read_tag(con); if (con->in_reply.tag == CEPH_MSGR_TAG_SEQ) {
prepare_write_seq(con);
prepare_read_seq(con);
} else {
prepare_read_tag(con);
}
break; break;
case CEPH_MSGR_TAG_WAIT: case CEPH_MSGR_TAG_WAIT:
...@@ -1732,7 +2120,6 @@ static int read_partial_ack(struct ceph_connection *con) ...@@ -1732,7 +2120,6 @@ static int read_partial_ack(struct ceph_connection *con)
return read_partial(con, end, size, &con->in_temp_ack); return read_partial(con, end, size, &con->in_temp_ack);
} }
/* /*
* We can finally discard anything that's been acked. * We can finally discard anything that's been acked.
*/ */
...@@ -1757,8 +2144,6 @@ static void process_ack(struct ceph_connection *con) ...@@ -1757,8 +2144,6 @@ static void process_ack(struct ceph_connection *con)
} }
static int read_partial_message_section(struct ceph_connection *con, static int read_partial_message_section(struct ceph_connection *con,
struct kvec *section, struct kvec *section,
unsigned int sec_len, u32 *crc) unsigned int sec_len, u32 *crc)
...@@ -1782,77 +2167,49 @@ static int read_partial_message_section(struct ceph_connection *con, ...@@ -1782,77 +2167,49 @@ static int read_partial_message_section(struct ceph_connection *con,
return 1; return 1;
} }
static int ceph_con_in_msg_alloc(struct ceph_connection *con, int *skip); static int read_partial_msg_data(struct ceph_connection *con)
static int read_partial_message_pages(struct ceph_connection *con,
struct page **pages,
unsigned int data_len, bool do_datacrc)
{ {
void *p; struct ceph_msg *msg = con->in_msg;
struct ceph_msg_data_cursor *cursor = &msg->cursor;
const bool do_datacrc = !con->msgr->nocrc;
struct page *page;
size_t page_offset;
size_t length;
u32 crc = 0;
int ret; int ret;
int left;
left = min((int)(data_len - con->in_msg_pos.data_pos), BUG_ON(!msg);
(int)(PAGE_SIZE - con->in_msg_pos.page_pos)); if (list_empty(&msg->data))
/* (page) data */ return -EIO;
BUG_ON(pages == NULL);
p = kmap(pages[con->in_msg_pos.page]);
ret = ceph_tcp_recvmsg(con->sock, p + con->in_msg_pos.page_pos,
left);
if (ret > 0 && do_datacrc)
con->in_data_crc =
crc32c(con->in_data_crc,
p + con->in_msg_pos.page_pos, ret);
kunmap(pages[con->in_msg_pos.page]);
if (ret <= 0)
return ret;
con->in_msg_pos.data_pos += ret;
con->in_msg_pos.page_pos += ret;
if (con->in_msg_pos.page_pos == PAGE_SIZE) {
con->in_msg_pos.page_pos = 0;
con->in_msg_pos.page++;
}
return ret;
}
#ifdef CONFIG_BLOCK
static int read_partial_message_bio(struct ceph_connection *con,
struct bio **bio_iter, int *bio_seg,
unsigned int data_len, bool do_datacrc)
{
struct bio_vec *bv = bio_iovec_idx(*bio_iter, *bio_seg);
void *p;
int ret, left;
left = min((int)(data_len - con->in_msg_pos.data_pos), if (do_datacrc)
(int)(bv->bv_len - con->in_msg_pos.page_pos)); crc = con->in_data_crc;
while (cursor->resid) {
page = ceph_msg_data_next(&msg->cursor, &page_offset, &length,
NULL);
ret = ceph_tcp_recvpage(con->sock, page, page_offset, length);
if (ret <= 0) {
if (do_datacrc)
con->in_data_crc = crc;
p = kmap(bv->bv_page) + bv->bv_offset; return ret;
}
ret = ceph_tcp_recvmsg(con->sock, p + con->in_msg_pos.page_pos, if (do_datacrc)
left); crc = ceph_crc32c_page(crc, page, page_offset, ret);
if (ret > 0 && do_datacrc) (void) ceph_msg_data_advance(&msg->cursor, (size_t)ret);
con->in_data_crc =
crc32c(con->in_data_crc,
p + con->in_msg_pos.page_pos, ret);
kunmap(bv->bv_page);
if (ret <= 0)
return ret;
con->in_msg_pos.data_pos += ret;
con->in_msg_pos.page_pos += ret;
if (con->in_msg_pos.page_pos == bv->bv_len) {
con->in_msg_pos.page_pos = 0;
iter_bio_next(bio_iter, bio_seg);
} }
if (do_datacrc)
con->in_data_crc = crc;
return ret; return 1; /* must return > 0 to indicate success */
} }
#endif
/* /*
* read (part of) a message. * read (part of) a message.
*/ */
static int ceph_con_in_msg_alloc(struct ceph_connection *con, int *skip);
static int read_partial_message(struct ceph_connection *con) static int read_partial_message(struct ceph_connection *con)
{ {
struct ceph_msg *m = con->in_msg; struct ceph_msg *m = con->in_msg;
...@@ -1885,7 +2242,7 @@ static int read_partial_message(struct ceph_connection *con) ...@@ -1885,7 +2242,7 @@ static int read_partial_message(struct ceph_connection *con)
if (front_len > CEPH_MSG_MAX_FRONT_LEN) if (front_len > CEPH_MSG_MAX_FRONT_LEN)
return -EIO; return -EIO;
middle_len = le32_to_cpu(con->in_hdr.middle_len); middle_len = le32_to_cpu(con->in_hdr.middle_len);
if (middle_len > CEPH_MSG_MAX_DATA_LEN) if (middle_len > CEPH_MSG_MAX_MIDDLE_LEN)
return -EIO; return -EIO;
data_len = le32_to_cpu(con->in_hdr.data_len); data_len = le32_to_cpu(con->in_hdr.data_len);
if (data_len > CEPH_MSG_MAX_DATA_LEN) if (data_len > CEPH_MSG_MAX_DATA_LEN)
...@@ -1914,14 +2271,22 @@ static int read_partial_message(struct ceph_connection *con) ...@@ -1914,14 +2271,22 @@ static int read_partial_message(struct ceph_connection *con)
int skip = 0; int skip = 0;
dout("got hdr type %d front %d data %d\n", con->in_hdr.type, dout("got hdr type %d front %d data %d\n", con->in_hdr.type,
con->in_hdr.front_len, con->in_hdr.data_len); front_len, data_len);
ret = ceph_con_in_msg_alloc(con, &skip); ret = ceph_con_in_msg_alloc(con, &skip);
if (ret < 0) if (ret < 0)
return ret; return ret;
BUG_ON(!con->in_msg ^ skip);
if (con->in_msg && data_len > con->in_msg->data_length) {
pr_warning("%s skipping long message (%u > %zd)\n",
__func__, data_len, con->in_msg->data_length);
ceph_msg_put(con->in_msg);
con->in_msg = NULL;
skip = 1;
}
if (skip) { if (skip) {
/* skip this message */ /* skip this message */
dout("alloc_msg said skip message\n"); dout("alloc_msg said skip message\n");
BUG_ON(con->in_msg);
con->in_base_pos = -front_len - middle_len - data_len - con->in_base_pos = -front_len - middle_len - data_len -
sizeof(m->footer); sizeof(m->footer);
con->in_tag = CEPH_MSGR_TAG_READY; con->in_tag = CEPH_MSGR_TAG_READY;
...@@ -1936,17 +2301,10 @@ static int read_partial_message(struct ceph_connection *con) ...@@ -1936,17 +2301,10 @@ static int read_partial_message(struct ceph_connection *con)
if (m->middle) if (m->middle)
m->middle->vec.iov_len = 0; m->middle->vec.iov_len = 0;
con->in_msg_pos.page = 0; /* prepare for data payload, if any */
if (m->pages)
con->in_msg_pos.page_pos = m->page_alignment;
else
con->in_msg_pos.page_pos = 0;
con->in_msg_pos.data_pos = 0;
#ifdef CONFIG_BLOCK if (data_len)
if (m->bio) prepare_message_data(con->in_msg, data_len);
init_bio_iter(m->bio, &m->bio_iter, &m->bio_seg);
#endif
} }
/* front */ /* front */
...@@ -1965,24 +2323,10 @@ static int read_partial_message(struct ceph_connection *con) ...@@ -1965,24 +2323,10 @@ static int read_partial_message(struct ceph_connection *con)
} }
/* (page) data */ /* (page) data */
while (con->in_msg_pos.data_pos < data_len) { if (data_len) {
if (m->pages) { ret = read_partial_msg_data(con);
ret = read_partial_message_pages(con, m->pages, if (ret <= 0)
data_len, do_datacrc); return ret;
if (ret <= 0)
return ret;
#ifdef CONFIG_BLOCK
} else if (m->bio) {
BUG_ON(!m->bio_iter);
ret = read_partial_message_bio(con,
&m->bio_iter, &m->bio_seg,
data_len, do_datacrc);
if (ret <= 0)
return ret;
#endif
} else {
BUG_ON(1);
}
} }
/* footer */ /* footer */
...@@ -2108,13 +2452,13 @@ static int try_write(struct ceph_connection *con) ...@@ -2108,13 +2452,13 @@ static int try_write(struct ceph_connection *con)
goto do_next; goto do_next;
} }
ret = write_partial_msg_pages(con); ret = write_partial_message_data(con);
if (ret == 1) if (ret == 1)
goto more_kvec; /* we need to send the footer, too! */ goto more_kvec; /* we need to send the footer, too! */
if (ret == 0) if (ret == 0)
goto out; goto out;
if (ret < 0) { if (ret < 0) {
dout("try_write write_partial_msg_pages err %d\n", dout("try_write write_partial_message_data err %d\n",
ret); ret);
goto out; goto out;
} }
...@@ -2266,7 +2610,12 @@ static int try_read(struct ceph_connection *con) ...@@ -2266,7 +2610,12 @@ static int try_read(struct ceph_connection *con)
prepare_read_tag(con); prepare_read_tag(con);
goto more; goto more;
} }
if (con->in_tag == CEPH_MSGR_TAG_ACK) { if (con->in_tag == CEPH_MSGR_TAG_ACK ||
con->in_tag == CEPH_MSGR_TAG_SEQ) {
/*
* the final handshake seq exchange is semantically
* equivalent to an ACK
*/
ret = read_partial_ack(con); ret = read_partial_ack(con);
if (ret <= 0) if (ret <= 0)
goto out; goto out;
...@@ -2672,6 +3021,88 @@ void ceph_con_keepalive(struct ceph_connection *con) ...@@ -2672,6 +3021,88 @@ void ceph_con_keepalive(struct ceph_connection *con)
} }
EXPORT_SYMBOL(ceph_con_keepalive); EXPORT_SYMBOL(ceph_con_keepalive);
static struct ceph_msg_data *ceph_msg_data_create(enum ceph_msg_data_type type)
{
struct ceph_msg_data *data;
if (WARN_ON(!ceph_msg_data_type_valid(type)))
return NULL;
data = kmem_cache_zalloc(ceph_msg_data_cache, GFP_NOFS);
if (data)
data->type = type;
INIT_LIST_HEAD(&data->links);
return data;
}
static void ceph_msg_data_destroy(struct ceph_msg_data *data)
{
if (!data)
return;
WARN_ON(!list_empty(&data->links));
if (data->type == CEPH_MSG_DATA_PAGELIST) {
ceph_pagelist_release(data->pagelist);
kfree(data->pagelist);
}
kmem_cache_free(ceph_msg_data_cache, data);
}
void ceph_msg_data_add_pages(struct ceph_msg *msg, struct page **pages,
size_t length, size_t alignment)
{
struct ceph_msg_data *data;
BUG_ON(!pages);
BUG_ON(!length);
data = ceph_msg_data_create(CEPH_MSG_DATA_PAGES);
BUG_ON(!data);
data->pages = pages;
data->length = length;
data->alignment = alignment & ~PAGE_MASK;
list_add_tail(&data->links, &msg->data);
msg->data_length += length;
}
EXPORT_SYMBOL(ceph_msg_data_add_pages);
void ceph_msg_data_add_pagelist(struct ceph_msg *msg,
struct ceph_pagelist *pagelist)
{
struct ceph_msg_data *data;
BUG_ON(!pagelist);
BUG_ON(!pagelist->length);
data = ceph_msg_data_create(CEPH_MSG_DATA_PAGELIST);
BUG_ON(!data);
data->pagelist = pagelist;
list_add_tail(&data->links, &msg->data);
msg->data_length += pagelist->length;
}
EXPORT_SYMBOL(ceph_msg_data_add_pagelist);
#ifdef CONFIG_BLOCK
void ceph_msg_data_add_bio(struct ceph_msg *msg, struct bio *bio,
size_t length)
{
struct ceph_msg_data *data;
BUG_ON(!bio);
data = ceph_msg_data_create(CEPH_MSG_DATA_BIO);
BUG_ON(!data);
data->bio = bio;
data->bio_length = length;
list_add_tail(&data->links, &msg->data);
msg->data_length += length;
}
EXPORT_SYMBOL(ceph_msg_data_add_bio);
#endif /* CONFIG_BLOCK */
/* /*
* construct a new message with given type, size * construct a new message with given type, size
...@@ -2682,49 +3113,20 @@ struct ceph_msg *ceph_msg_new(int type, int front_len, gfp_t flags, ...@@ -2682,49 +3113,20 @@ struct ceph_msg *ceph_msg_new(int type, int front_len, gfp_t flags,
{ {
struct ceph_msg *m; struct ceph_msg *m;
m = kmalloc(sizeof(*m), flags); m = kmem_cache_zalloc(ceph_msg_cache, flags);
if (m == NULL) if (m == NULL)
goto out; goto out;
kref_init(&m->kref);
m->con = NULL;
INIT_LIST_HEAD(&m->list_head);
m->hdr.tid = 0;
m->hdr.type = cpu_to_le16(type); m->hdr.type = cpu_to_le16(type);
m->hdr.priority = cpu_to_le16(CEPH_MSG_PRIO_DEFAULT); m->hdr.priority = cpu_to_le16(CEPH_MSG_PRIO_DEFAULT);
m->hdr.version = 0;
m->hdr.front_len = cpu_to_le32(front_len); m->hdr.front_len = cpu_to_le32(front_len);
m->hdr.middle_len = 0;
m->hdr.data_len = 0;
m->hdr.data_off = 0;
m->hdr.reserved = 0;
m->footer.front_crc = 0;
m->footer.middle_crc = 0;
m->footer.data_crc = 0;
m->footer.flags = 0;
m->front_max = front_len;
m->front_is_vmalloc = false;
m->more_to_follow = false;
m->ack_stamp = 0;
m->pool = NULL;
/* middle */
m->middle = NULL;
/* data */ INIT_LIST_HEAD(&m->list_head);
m->nr_pages = 0; kref_init(&m->kref);
m->page_alignment = 0; INIT_LIST_HEAD(&m->data);
m->pages = NULL;
m->pagelist = NULL;
#ifdef CONFIG_BLOCK
m->bio = NULL;
m->bio_iter = NULL;
m->bio_seg = 0;
#endif /* CONFIG_BLOCK */
m->trail = NULL;
/* front */ /* front */
m->front_max = front_len;
if (front_len) { if (front_len) {
if (front_len > PAGE_CACHE_SIZE) { if (front_len > PAGE_CACHE_SIZE) {
m->front.iov_base = __vmalloc(front_len, flags, m->front.iov_base = __vmalloc(front_len, flags,
...@@ -2802,49 +3204,37 @@ static int ceph_alloc_middle(struct ceph_connection *con, struct ceph_msg *msg) ...@@ -2802,49 +3204,37 @@ static int ceph_alloc_middle(struct ceph_connection *con, struct ceph_msg *msg)
static int ceph_con_in_msg_alloc(struct ceph_connection *con, int *skip) static int ceph_con_in_msg_alloc(struct ceph_connection *con, int *skip)
{ {
struct ceph_msg_header *hdr = &con->in_hdr; struct ceph_msg_header *hdr = &con->in_hdr;
int type = le16_to_cpu(hdr->type);
int front_len = le32_to_cpu(hdr->front_len);
int middle_len = le32_to_cpu(hdr->middle_len); int middle_len = le32_to_cpu(hdr->middle_len);
struct ceph_msg *msg;
int ret = 0; int ret = 0;
BUG_ON(con->in_msg != NULL); BUG_ON(con->in_msg != NULL);
BUG_ON(!con->ops->alloc_msg);
if (con->ops->alloc_msg) { mutex_unlock(&con->mutex);
struct ceph_msg *msg; msg = con->ops->alloc_msg(con, hdr, skip);
mutex_lock(&con->mutex);
mutex_unlock(&con->mutex); if (con->state != CON_STATE_OPEN) {
msg = con->ops->alloc_msg(con, hdr, skip); if (msg)
mutex_lock(&con->mutex); ceph_msg_put(msg);
if (con->state != CON_STATE_OPEN) { return -EAGAIN;
if (msg)
ceph_msg_put(msg);
return -EAGAIN;
}
con->in_msg = msg;
if (con->in_msg) {
con->in_msg->con = con->ops->get(con);
BUG_ON(con->in_msg->con == NULL);
}
if (*skip) {
con->in_msg = NULL;
return 0;
}
if (!con->in_msg) {
con->error_msg =
"error allocating memory for incoming message";
return -ENOMEM;
}
} }
if (!con->in_msg) { if (msg) {
con->in_msg = ceph_msg_new(type, front_len, GFP_NOFS, false); BUG_ON(*skip);
if (!con->in_msg) { con->in_msg = msg;
pr_err("unable to allocate msg type %d len %d\n",
type, front_len);
return -ENOMEM;
}
con->in_msg->con = con->ops->get(con); con->in_msg->con = con->ops->get(con);
BUG_ON(con->in_msg->con == NULL); BUG_ON(con->in_msg->con == NULL);
con->in_msg->page_alignment = le16_to_cpu(hdr->data_off); } else {
/*
* Null message pointer means either we should skip
* this message or we couldn't allocate memory. The
* former is not an error.
*/
if (*skip)
return 0;
con->error_msg = "error allocating memory for incoming message";
return -ENOMEM;
} }
memcpy(&con->in_msg->hdr, &con->in_hdr, sizeof(con->in_hdr)); memcpy(&con->in_msg->hdr, &con->in_hdr, sizeof(con->in_hdr));
...@@ -2870,7 +3260,7 @@ void ceph_msg_kfree(struct ceph_msg *m) ...@@ -2870,7 +3260,7 @@ void ceph_msg_kfree(struct ceph_msg *m)
vfree(m->front.iov_base); vfree(m->front.iov_base);
else else
kfree(m->front.iov_base); kfree(m->front.iov_base);
kfree(m); kmem_cache_free(ceph_msg_cache, m);
} }
/* /*
...@@ -2879,6 +3269,9 @@ void ceph_msg_kfree(struct ceph_msg *m) ...@@ -2879,6 +3269,9 @@ void ceph_msg_kfree(struct ceph_msg *m)
void ceph_msg_last_put(struct kref *kref) void ceph_msg_last_put(struct kref *kref)
{ {
struct ceph_msg *m = container_of(kref, struct ceph_msg, kref); struct ceph_msg *m = container_of(kref, struct ceph_msg, kref);
LIST_HEAD(data);
struct list_head *links;
struct list_head *next;
dout("ceph_msg_put last one on %p\n", m); dout("ceph_msg_put last one on %p\n", m);
WARN_ON(!list_empty(&m->list_head)); WARN_ON(!list_empty(&m->list_head));
...@@ -2888,16 +3281,16 @@ void ceph_msg_last_put(struct kref *kref) ...@@ -2888,16 +3281,16 @@ void ceph_msg_last_put(struct kref *kref)
ceph_buffer_put(m->middle); ceph_buffer_put(m->middle);
m->middle = NULL; m->middle = NULL;
} }
m->nr_pages = 0;
m->pages = NULL;
if (m->pagelist) { list_splice_init(&m->data, &data);
ceph_pagelist_release(m->pagelist); list_for_each_safe(links, next, &data) {
kfree(m->pagelist); struct ceph_msg_data *data;
m->pagelist = NULL;
}
m->trail = NULL; data = list_entry(links, struct ceph_msg_data, links);
list_del_init(links);
ceph_msg_data_destroy(data);
}
m->data_length = 0;
if (m->pool) if (m->pool)
ceph_msgpool_put(m->pool, m); ceph_msgpool_put(m->pool, m);
...@@ -2908,8 +3301,8 @@ EXPORT_SYMBOL(ceph_msg_last_put); ...@@ -2908,8 +3301,8 @@ EXPORT_SYMBOL(ceph_msg_last_put);
void ceph_msg_dump(struct ceph_msg *msg) void ceph_msg_dump(struct ceph_msg *msg)
{ {
pr_debug("msg_dump %p (front_max %d nr_pages %d)\n", msg, pr_debug("msg_dump %p (front_max %d length %zd)\n", msg,
msg->front_max, msg->nr_pages); msg->front_max, msg->data_length);
print_hex_dump(KERN_DEBUG, "header: ", print_hex_dump(KERN_DEBUG, "header: ",
DUMP_PREFIX_OFFSET, 16, 1, DUMP_PREFIX_OFFSET, 16, 1,
&msg->hdr, sizeof(msg->hdr), true); &msg->hdr, sizeof(msg->hdr), true);
......
...@@ -737,7 +737,7 @@ static void delayed_work(struct work_struct *work) ...@@ -737,7 +737,7 @@ static void delayed_work(struct work_struct *work)
__validate_auth(monc); __validate_auth(monc);
if (monc->auth->ops->is_authenticated(monc->auth)) if (ceph_auth_is_authenticated(monc->auth))
__send_subscribe(monc); __send_subscribe(monc);
} }
__schedule_delayed(monc); __schedule_delayed(monc);
...@@ -892,8 +892,7 @@ static void handle_auth_reply(struct ceph_mon_client *monc, ...@@ -892,8 +892,7 @@ static void handle_auth_reply(struct ceph_mon_client *monc,
mutex_lock(&monc->mutex); mutex_lock(&monc->mutex);
had_debugfs_info = have_debugfs_info(monc); had_debugfs_info = have_debugfs_info(monc);
if (monc->auth->ops) was_auth = ceph_auth_is_authenticated(monc->auth);
was_auth = monc->auth->ops->is_authenticated(monc->auth);
monc->pending_auth = 0; monc->pending_auth = 0;
ret = ceph_handle_auth_reply(monc->auth, msg->front.iov_base, ret = ceph_handle_auth_reply(monc->auth, msg->front.iov_base,
msg->front.iov_len, msg->front.iov_len,
...@@ -904,7 +903,7 @@ static void handle_auth_reply(struct ceph_mon_client *monc, ...@@ -904,7 +903,7 @@ static void handle_auth_reply(struct ceph_mon_client *monc,
wake_up_all(&monc->client->auth_wq); wake_up_all(&monc->client->auth_wq);
} else if (ret > 0) { } else if (ret > 0) {
__send_prepared_auth_request(monc, ret); __send_prepared_auth_request(monc, ret);
} else if (!was_auth && monc->auth->ops->is_authenticated(monc->auth)) { } else if (!was_auth && ceph_auth_is_authenticated(monc->auth)) {
dout("authenticated, starting session\n"); dout("authenticated, starting session\n");
monc->client->msgr.inst.name.type = CEPH_ENTITY_TYPE_CLIENT; monc->client->msgr.inst.name.type = CEPH_ENTITY_TYPE_CLIENT;
......
#include <linux/ceph/ceph_debug.h> #include <linux/ceph/ceph_debug.h>
#include <linux/module.h> #include <linux/module.h>
...@@ -21,6 +22,8 @@ ...@@ -21,6 +22,8 @@
#define OSD_OP_FRONT_LEN 4096 #define OSD_OP_FRONT_LEN 4096
#define OSD_OPREPLY_FRONT_LEN 512 #define OSD_OPREPLY_FRONT_LEN 512
static struct kmem_cache *ceph_osd_request_cache;
static const struct ceph_connection_operations osd_con_ops; static const struct ceph_connection_operations osd_con_ops;
static void __send_queued(struct ceph_osd_client *osdc); static void __send_queued(struct ceph_osd_client *osdc);
...@@ -32,12 +35,6 @@ static void __unregister_linger_request(struct ceph_osd_client *osdc, ...@@ -32,12 +35,6 @@ static void __unregister_linger_request(struct ceph_osd_client *osdc,
static void __send_request(struct ceph_osd_client *osdc, static void __send_request(struct ceph_osd_client *osdc,
struct ceph_osd_request *req); struct ceph_osd_request *req);
static int op_has_extent(int op)
{
return (op == CEPH_OSD_OP_READ ||
op == CEPH_OSD_OP_WRITE);
}
/* /*
* Implement client access to distributed object storage cluster. * Implement client access to distributed object storage cluster.
* *
...@@ -63,53 +60,238 @@ static int op_has_extent(int op) ...@@ -63,53 +60,238 @@ static int op_has_extent(int op)
* *
* fill osd op in request message. * fill osd op in request message.
*/ */
static int calc_layout(struct ceph_vino vino, static int calc_layout(struct ceph_file_layout *layout, u64 off, u64 *plen,
struct ceph_file_layout *layout, u64 *objnum, u64 *objoff, u64 *objlen)
u64 off, u64 *plen,
struct ceph_osd_request *req,
struct ceph_osd_req_op *op)
{ {
u64 orig_len = *plen; u64 orig_len = *plen;
u64 bno = 0;
u64 objoff = 0;
u64 objlen = 0;
int r; int r;
/* object extent? */ /* object extent? */
r = ceph_calc_file_object_mapping(layout, off, orig_len, &bno, r = ceph_calc_file_object_mapping(layout, off, orig_len, objnum,
&objoff, &objlen); objoff, objlen);
if (r < 0) if (r < 0)
return r; return r;
if (objlen < orig_len) { if (*objlen < orig_len) {
*plen = objlen; *plen = *objlen;
dout(" skipping last %llu, final file extent %llu~%llu\n", dout(" skipping last %llu, final file extent %llu~%llu\n",
orig_len - *plen, off, *plen); orig_len - *plen, off, *plen);
} }
if (op_has_extent(op->op)) { dout("calc_layout objnum=%llx %llu~%llu\n", *objnum, *objoff, *objlen);
u32 osize = le32_to_cpu(layout->fl_object_size);
op->extent.offset = objoff; return 0;
op->extent.length = objlen; }
if (op->extent.truncate_size <= off - objoff) {
op->extent.truncate_size = 0; static void ceph_osd_data_init(struct ceph_osd_data *osd_data)
} else { {
op->extent.truncate_size -= off - objoff; memset(osd_data, 0, sizeof (*osd_data));
if (op->extent.truncate_size > osize) osd_data->type = CEPH_OSD_DATA_TYPE_NONE;
op->extent.truncate_size = osize; }
}
static 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;
}
static 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;
}
#ifdef CONFIG_BLOCK
static 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;
}
#endif /* CONFIG_BLOCK */
#define osd_req_op_data(oreq, whch, typ, fld) \
({ \
BUG_ON(whch >= (oreq)->r_num_ops); \
&(oreq)->r_ops[whch].typ.fld; \
})
static struct ceph_osd_data *
osd_req_op_raw_data_in(struct ceph_osd_request *osd_req, unsigned int which)
{
BUG_ON(which >= osd_req->r_num_ops);
return &osd_req->r_ops[which].raw_data_in;
}
struct ceph_osd_data *
osd_req_op_extent_osd_data(struct ceph_osd_request *osd_req,
unsigned int which)
{
return osd_req_op_data(osd_req, which, extent, osd_data);
}
EXPORT_SYMBOL(osd_req_op_extent_osd_data);
struct ceph_osd_data *
osd_req_op_cls_response_data(struct ceph_osd_request *osd_req,
unsigned int which)
{
return osd_req_op_data(osd_req, which, cls, response_data);
}
EXPORT_SYMBOL(osd_req_op_cls_response_data); /* ??? */
void osd_req_op_raw_data_in_pages(struct ceph_osd_request *osd_req,
unsigned int which, struct page **pages,
u64 length, u32 alignment,
bool pages_from_pool, bool own_pages)
{
struct ceph_osd_data *osd_data;
osd_data = osd_req_op_raw_data_in(osd_req, which);
ceph_osd_data_pages_init(osd_data, pages, length, alignment,
pages_from_pool, own_pages);
}
EXPORT_SYMBOL(osd_req_op_raw_data_in_pages);
void osd_req_op_extent_osd_data_pages(struct ceph_osd_request *osd_req,
unsigned int which, struct page **pages,
u64 length, u32 alignment,
bool pages_from_pool, bool own_pages)
{
struct ceph_osd_data *osd_data;
osd_data = osd_req_op_data(osd_req, which, extent, osd_data);
ceph_osd_data_pages_init(osd_data, pages, length, alignment,
pages_from_pool, own_pages);
}
EXPORT_SYMBOL(osd_req_op_extent_osd_data_pages);
void osd_req_op_extent_osd_data_pagelist(struct ceph_osd_request *osd_req,
unsigned int which, struct ceph_pagelist *pagelist)
{
struct ceph_osd_data *osd_data;
osd_data = osd_req_op_data(osd_req, which, extent, osd_data);
ceph_osd_data_pagelist_init(osd_data, pagelist);
}
EXPORT_SYMBOL(osd_req_op_extent_osd_data_pagelist);
#ifdef CONFIG_BLOCK
void osd_req_op_extent_osd_data_bio(struct ceph_osd_request *osd_req,
unsigned int which, struct bio *bio, size_t bio_length)
{
struct ceph_osd_data *osd_data;
osd_data = osd_req_op_data(osd_req, which, extent, osd_data);
ceph_osd_data_bio_init(osd_data, bio, bio_length);
}
EXPORT_SYMBOL(osd_req_op_extent_osd_data_bio);
#endif /* CONFIG_BLOCK */
static void osd_req_op_cls_request_info_pagelist(
struct ceph_osd_request *osd_req,
unsigned int which, struct ceph_pagelist *pagelist)
{
struct ceph_osd_data *osd_data;
osd_data = osd_req_op_data(osd_req, which, cls, request_info);
ceph_osd_data_pagelist_init(osd_data, pagelist);
}
void osd_req_op_cls_request_data_pagelist(
struct ceph_osd_request *osd_req,
unsigned int which, struct ceph_pagelist *pagelist)
{
struct ceph_osd_data *osd_data;
osd_data = osd_req_op_data(osd_req, which, cls, request_data);
ceph_osd_data_pagelist_init(osd_data, pagelist);
}
EXPORT_SYMBOL(osd_req_op_cls_request_data_pagelist);
void osd_req_op_cls_request_data_pages(struct ceph_osd_request *osd_req,
unsigned int which, struct page **pages, u64 length,
u32 alignment, bool pages_from_pool, bool own_pages)
{
struct ceph_osd_data *osd_data;
osd_data = osd_req_op_data(osd_req, which, cls, request_data);
ceph_osd_data_pages_init(osd_data, pages, length, alignment,
pages_from_pool, own_pages);
}
EXPORT_SYMBOL(osd_req_op_cls_request_data_pages);
void osd_req_op_cls_response_data_pages(struct ceph_osd_request *osd_req,
unsigned int which, struct page **pages, u64 length,
u32 alignment, bool pages_from_pool, bool own_pages)
{
struct ceph_osd_data *osd_data;
osd_data = osd_req_op_data(osd_req, which, cls, response_data);
ceph_osd_data_pages_init(osd_data, pages, length, alignment,
pages_from_pool, own_pages);
}
EXPORT_SYMBOL(osd_req_op_cls_response_data_pages);
static u64 ceph_osd_data_length(struct ceph_osd_data *osd_data)
{
switch (osd_data->type) {
case CEPH_OSD_DATA_TYPE_NONE:
return 0;
case CEPH_OSD_DATA_TYPE_PAGES:
return osd_data->length;
case CEPH_OSD_DATA_TYPE_PAGELIST:
return (u64)osd_data->pagelist->length;
#ifdef CONFIG_BLOCK
case CEPH_OSD_DATA_TYPE_BIO:
return (u64)osd_data->bio_length;
#endif /* CONFIG_BLOCK */
default:
WARN(true, "unrecognized data type %d\n", (int)osd_data->type);
return 0;
} }
req->r_num_pages = calc_pages_for(off, *plen); }
req->r_page_alignment = off & ~PAGE_MASK;
if (op->op == CEPH_OSD_OP_WRITE)
op->payload_len = *plen;
dout("calc_layout bno=%llx %llu~%llu (%d pages)\n", static void ceph_osd_data_release(struct ceph_osd_data *osd_data)
bno, objoff, objlen, req->r_num_pages); {
if (osd_data->type == CEPH_OSD_DATA_TYPE_PAGES && osd_data->own_pages) {
int num_pages;
snprintf(req->r_oid, sizeof(req->r_oid), "%llx.%08llx", vino.ino, bno); num_pages = calc_pages_for((u64)osd_data->alignment,
req->r_oid_len = strlen(req->r_oid); (u64)osd_data->length);
ceph_release_page_vector(osd_data->pages, num_pages);
}
ceph_osd_data_init(osd_data);
}
static void osd_req_op_data_release(struct ceph_osd_request *osd_req,
unsigned int which)
{
struct ceph_osd_req_op *op;
BUG_ON(which >= osd_req->r_num_ops);
op = &osd_req->r_ops[which];
return r; switch (op->op) {
case CEPH_OSD_OP_READ:
case CEPH_OSD_OP_WRITE:
ceph_osd_data_release(&op->extent.osd_data);
break;
case CEPH_OSD_OP_CALL:
ceph_osd_data_release(&op->cls.request_info);
ceph_osd_data_release(&op->cls.request_data);
ceph_osd_data_release(&op->cls.response_data);
break;
default:
break;
}
} }
/* /*
...@@ -117,30 +299,26 @@ static int calc_layout(struct ceph_vino vino, ...@@ -117,30 +299,26 @@ static int calc_layout(struct ceph_vino vino,
*/ */
void ceph_osdc_release_request(struct kref *kref) void ceph_osdc_release_request(struct kref *kref)
{ {
struct ceph_osd_request *req = container_of(kref, struct ceph_osd_request *req;
struct ceph_osd_request, unsigned int which;
r_kref);
req = container_of(kref, struct ceph_osd_request, r_kref);
if (req->r_request) if (req->r_request)
ceph_msg_put(req->r_request); ceph_msg_put(req->r_request);
if (req->r_con_filling_msg) { if (req->r_reply) {
dout("%s revoking msg %p from con %p\n", __func__,
req->r_reply, req->r_con_filling_msg);
ceph_msg_revoke_incoming(req->r_reply); ceph_msg_revoke_incoming(req->r_reply);
req->r_con_filling_msg->ops->put(req->r_con_filling_msg);
req->r_con_filling_msg = NULL;
}
if (req->r_reply)
ceph_msg_put(req->r_reply); ceph_msg_put(req->r_reply);
if (req->r_own_pages) }
ceph_release_page_vector(req->r_pages,
req->r_num_pages); for (which = 0; which < req->r_num_ops; which++)
osd_req_op_data_release(req, which);
ceph_put_snap_context(req->r_snapc); ceph_put_snap_context(req->r_snapc);
ceph_pagelist_release(&req->r_trail);
if (req->r_mempool) if (req->r_mempool)
mempool_free(req, req->r_osdc->req_mempool); mempool_free(req, req->r_osdc->req_mempool);
else else
kfree(req); kmem_cache_free(ceph_osd_request_cache, req);
} }
EXPORT_SYMBOL(ceph_osdc_release_request); EXPORT_SYMBOL(ceph_osdc_release_request);
...@@ -154,6 +332,9 @@ struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc, ...@@ -154,6 +332,9 @@ struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
struct ceph_msg *msg; struct ceph_msg *msg;
size_t msg_size; size_t msg_size;
BUILD_BUG_ON(CEPH_OSD_MAX_OP > U16_MAX);
BUG_ON(num_ops > CEPH_OSD_MAX_OP);
msg_size = 4 + 4 + 8 + 8 + 4+8; msg_size = 4 + 4 + 8 + 8 + 4+8;
msg_size += 2 + 4 + 8 + 4 + 4; /* oloc */ msg_size += 2 + 4 + 8 + 4 + 4; /* oloc */
msg_size += 1 + 8 + 4 + 4; /* pg_t */ msg_size += 1 + 8 + 4 + 4; /* pg_t */
...@@ -168,13 +349,14 @@ struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc, ...@@ -168,13 +349,14 @@ struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
req = mempool_alloc(osdc->req_mempool, gfp_flags); req = mempool_alloc(osdc->req_mempool, gfp_flags);
memset(req, 0, sizeof(*req)); memset(req, 0, sizeof(*req));
} else { } else {
req = kzalloc(sizeof(*req), gfp_flags); req = kmem_cache_zalloc(ceph_osd_request_cache, gfp_flags);
} }
if (req == NULL) if (req == NULL)
return NULL; return NULL;
req->r_osdc = osdc; req->r_osdc = osdc;
req->r_mempool = use_mempool; req->r_mempool = use_mempool;
req->r_num_ops = num_ops;
kref_init(&req->r_kref); kref_init(&req->r_kref);
init_completion(&req->r_completion); init_completion(&req->r_completion);
...@@ -198,8 +380,6 @@ struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc, ...@@ -198,8 +380,6 @@ struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
} }
req->r_reply = msg; req->r_reply = msg;
ceph_pagelist_init(&req->r_trail);
/* create request message; allow space for oid */ /* create request message; allow space for oid */
if (use_mempool) if (use_mempool)
msg = ceph_msgpool_get(&osdc->msgpool_op, 0); msg = ceph_msgpool_get(&osdc->msgpool_op, 0);
...@@ -218,60 +398,24 @@ struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc, ...@@ -218,60 +398,24 @@ struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
} }
EXPORT_SYMBOL(ceph_osdc_alloc_request); EXPORT_SYMBOL(ceph_osdc_alloc_request);
static void osd_req_encode_op(struct ceph_osd_request *req, static bool osd_req_opcode_valid(u16 opcode)
struct ceph_osd_op *dst,
struct ceph_osd_req_op *src)
{ {
dst->op = cpu_to_le16(src->op); switch (opcode) {
switch (src->op) {
case CEPH_OSD_OP_STAT:
break;
case CEPH_OSD_OP_READ: case CEPH_OSD_OP_READ:
case CEPH_OSD_OP_WRITE: case CEPH_OSD_OP_STAT:
dst->extent.offset =
cpu_to_le64(src->extent.offset);
dst->extent.length =
cpu_to_le64(src->extent.length);
dst->extent.truncate_size =
cpu_to_le64(src->extent.truncate_size);
dst->extent.truncate_seq =
cpu_to_le32(src->extent.truncate_seq);
break;
case CEPH_OSD_OP_CALL:
dst->cls.class_len = src->cls.class_len;
dst->cls.method_len = src->cls.method_len;
dst->cls.indata_len = cpu_to_le32(src->cls.indata_len);
ceph_pagelist_append(&req->r_trail, src->cls.class_name,
src->cls.class_len);
ceph_pagelist_append(&req->r_trail, src->cls.method_name,
src->cls.method_len);
ceph_pagelist_append(&req->r_trail, src->cls.indata,
src->cls.indata_len);
break;
case CEPH_OSD_OP_STARTSYNC:
break;
case CEPH_OSD_OP_NOTIFY_ACK:
case CEPH_OSD_OP_WATCH:
dst->watch.cookie = cpu_to_le64(src->watch.cookie);
dst->watch.ver = cpu_to_le64(src->watch.ver);
dst->watch.flag = src->watch.flag;
break;
default:
pr_err("unrecognized osd opcode %d\n", dst->op);
WARN_ON(1);
break;
case CEPH_OSD_OP_MAPEXT: case CEPH_OSD_OP_MAPEXT:
case CEPH_OSD_OP_MASKTRUNC: case CEPH_OSD_OP_MASKTRUNC:
case CEPH_OSD_OP_SPARSE_READ: case CEPH_OSD_OP_SPARSE_READ:
case CEPH_OSD_OP_NOTIFY: case CEPH_OSD_OP_NOTIFY:
case CEPH_OSD_OP_NOTIFY_ACK:
case CEPH_OSD_OP_ASSERT_VER: case CEPH_OSD_OP_ASSERT_VER:
case CEPH_OSD_OP_WRITE:
case CEPH_OSD_OP_WRITEFULL: case CEPH_OSD_OP_WRITEFULL:
case CEPH_OSD_OP_TRUNCATE: case CEPH_OSD_OP_TRUNCATE:
case CEPH_OSD_OP_ZERO: case CEPH_OSD_OP_ZERO:
case CEPH_OSD_OP_DELETE: case CEPH_OSD_OP_DELETE:
case CEPH_OSD_OP_APPEND: case CEPH_OSD_OP_APPEND:
case CEPH_OSD_OP_STARTSYNC:
case CEPH_OSD_OP_SETTRUNC: case CEPH_OSD_OP_SETTRUNC:
case CEPH_OSD_OP_TRIMTRUNC: case CEPH_OSD_OP_TRIMTRUNC:
case CEPH_OSD_OP_TMAPUP: case CEPH_OSD_OP_TMAPUP:
...@@ -279,11 +423,11 @@ static void osd_req_encode_op(struct ceph_osd_request *req, ...@@ -279,11 +423,11 @@ static void osd_req_encode_op(struct ceph_osd_request *req,
case CEPH_OSD_OP_TMAPGET: case CEPH_OSD_OP_TMAPGET:
case CEPH_OSD_OP_CREATE: case CEPH_OSD_OP_CREATE:
case CEPH_OSD_OP_ROLLBACK: case CEPH_OSD_OP_ROLLBACK:
case CEPH_OSD_OP_WATCH:
case CEPH_OSD_OP_OMAPGETKEYS: case CEPH_OSD_OP_OMAPGETKEYS:
case CEPH_OSD_OP_OMAPGETVALS: case CEPH_OSD_OP_OMAPGETVALS:
case CEPH_OSD_OP_OMAPGETHEADER: case CEPH_OSD_OP_OMAPGETHEADER:
case CEPH_OSD_OP_OMAPGETVALSBYKEYS: case CEPH_OSD_OP_OMAPGETVALSBYKEYS:
case CEPH_OSD_OP_MODE_RD:
case CEPH_OSD_OP_OMAPSETVALS: case CEPH_OSD_OP_OMAPSETVALS:
case CEPH_OSD_OP_OMAPSETHEADER: case CEPH_OSD_OP_OMAPSETHEADER:
case CEPH_OSD_OP_OMAPCLEAR: case CEPH_OSD_OP_OMAPCLEAR:
...@@ -314,113 +458,233 @@ static void osd_req_encode_op(struct ceph_osd_request *req, ...@@ -314,113 +458,233 @@ static void osd_req_encode_op(struct ceph_osd_request *req,
case CEPH_OSD_OP_RDUNLOCK: case CEPH_OSD_OP_RDUNLOCK:
case CEPH_OSD_OP_UPLOCK: case CEPH_OSD_OP_UPLOCK:
case CEPH_OSD_OP_DNLOCK: case CEPH_OSD_OP_DNLOCK:
case CEPH_OSD_OP_CALL:
case CEPH_OSD_OP_PGLS: case CEPH_OSD_OP_PGLS:
case CEPH_OSD_OP_PGLS_FILTER: case CEPH_OSD_OP_PGLS_FILTER:
pr_err("unsupported osd opcode %s\n", return true;
ceph_osd_op_name(dst->op)); default:
WARN_ON(1); return false;
break;
} }
dst->payload_len = cpu_to_le32(src->payload_len);
} }
/* /*
* build new request AND message * This is an osd op init function for opcodes that have no data or
* * other information associated with them. It also serves as a
* common init routine for all the other init functions, below.
*/ */
void ceph_osdc_build_request(struct ceph_osd_request *req, static struct ceph_osd_req_op *
u64 off, u64 len, unsigned int num_ops, _osd_req_op_init(struct ceph_osd_request *osd_req, unsigned int which,
struct ceph_osd_req_op *src_ops, u16 opcode)
struct ceph_snap_context *snapc, u64 snap_id,
struct timespec *mtime)
{ {
struct ceph_msg *msg = req->r_request; struct ceph_osd_req_op *op;
struct ceph_osd_req_op *src_op;
void *p;
size_t msg_size;
int flags = req->r_flags;
u64 data_len;
int i;
req->r_num_ops = num_ops; BUG_ON(which >= osd_req->r_num_ops);
req->r_snapid = snap_id; BUG_ON(!osd_req_opcode_valid(opcode));
req->r_snapc = ceph_get_snap_context(snapc);
/* encode request */ op = &osd_req->r_ops[which];
msg->hdr.version = cpu_to_le16(4); memset(op, 0, sizeof (*op));
op->op = opcode;
p = msg->front.iov_base; return op;
ceph_encode_32(&p, 1); /* client_inc is always 1 */ }
req->r_request_osdmap_epoch = p;
p += 4;
req->r_request_flags = p;
p += 4;
if (req->r_flags & CEPH_OSD_FLAG_WRITE)
ceph_encode_timespec(p, mtime);
p += sizeof(struct ceph_timespec);
req->r_request_reassert_version = p;
p += sizeof(struct ceph_eversion); /* will get filled in */
/* oloc */ void osd_req_op_init(struct ceph_osd_request *osd_req,
ceph_encode_8(&p, 4); unsigned int which, u16 opcode)
ceph_encode_8(&p, 4); {
ceph_encode_32(&p, 8 + 4 + 4); (void)_osd_req_op_init(osd_req, which, opcode);
req->r_request_pool = p; }
p += 8; EXPORT_SYMBOL(osd_req_op_init);
ceph_encode_32(&p, -1); /* preferred */
ceph_encode_32(&p, 0); /* key len */
ceph_encode_8(&p, 1); void osd_req_op_extent_init(struct ceph_osd_request *osd_req,
req->r_request_pgid = p; unsigned int which, u16 opcode,
p += 8 + 4; u64 offset, u64 length,
ceph_encode_32(&p, -1); /* preferred */ u64 truncate_size, u32 truncate_seq)
{
struct ceph_osd_req_op *op = _osd_req_op_init(osd_req, which, opcode);
size_t payload_len = 0;
/* oid */ BUG_ON(opcode != CEPH_OSD_OP_READ && opcode != CEPH_OSD_OP_WRITE);
ceph_encode_32(&p, req->r_oid_len);
memcpy(p, req->r_oid, req->r_oid_len);
dout("oid '%.*s' len %d\n", req->r_oid_len, req->r_oid, req->r_oid_len);
p += req->r_oid_len;
/* ops */ op->extent.offset = offset;
ceph_encode_16(&p, num_ops); op->extent.length = length;
src_op = src_ops; op->extent.truncate_size = truncate_size;
req->r_request_ops = p; op->extent.truncate_seq = truncate_seq;
for (i = 0; i < num_ops; i++, src_op++) { if (opcode == CEPH_OSD_OP_WRITE)
osd_req_encode_op(req, p, src_op); payload_len += length;
p += sizeof(struct ceph_osd_op);
}
/* snaps */ op->payload_len = payload_len;
ceph_encode_64(&p, req->r_snapid); }
ceph_encode_64(&p, req->r_snapc ? req->r_snapc->seq : 0); EXPORT_SYMBOL(osd_req_op_extent_init);
ceph_encode_32(&p, req->r_snapc ? req->r_snapc->num_snaps : 0);
if (req->r_snapc) { void osd_req_op_extent_update(struct ceph_osd_request *osd_req,
for (i = 0; i < snapc->num_snaps; i++) { unsigned int which, u64 length)
ceph_encode_64(&p, req->r_snapc->snaps[i]); {
} struct ceph_osd_req_op *op;
u64 previous;
BUG_ON(which >= osd_req->r_num_ops);
op = &osd_req->r_ops[which];
previous = op->extent.length;
if (length == previous)
return; /* Nothing to do */
BUG_ON(length > previous);
op->extent.length = length;
op->payload_len -= previous - length;
}
EXPORT_SYMBOL(osd_req_op_extent_update);
void osd_req_op_cls_init(struct ceph_osd_request *osd_req, unsigned int which,
u16 opcode, const char *class, const char *method)
{
struct ceph_osd_req_op *op = _osd_req_op_init(osd_req, which, opcode);
struct ceph_pagelist *pagelist;
size_t payload_len = 0;
size_t size;
BUG_ON(opcode != CEPH_OSD_OP_CALL);
pagelist = kmalloc(sizeof (*pagelist), GFP_NOFS);
BUG_ON(!pagelist);
ceph_pagelist_init(pagelist);
op->cls.class_name = class;
size = strlen(class);
BUG_ON(size > (size_t) U8_MAX);
op->cls.class_len = size;
ceph_pagelist_append(pagelist, class, size);
payload_len += size;
op->cls.method_name = method;
size = strlen(method);
BUG_ON(size > (size_t) U8_MAX);
op->cls.method_len = size;
ceph_pagelist_append(pagelist, method, size);
payload_len += size;
osd_req_op_cls_request_info_pagelist(osd_req, which, pagelist);
op->cls.argc = 0; /* currently unused */
op->payload_len = payload_len;
}
EXPORT_SYMBOL(osd_req_op_cls_init);
void osd_req_op_watch_init(struct ceph_osd_request *osd_req,
unsigned int which, u16 opcode,
u64 cookie, u64 version, int flag)
{
struct ceph_osd_req_op *op = _osd_req_op_init(osd_req, which, opcode);
BUG_ON(opcode != CEPH_OSD_OP_NOTIFY_ACK && opcode != CEPH_OSD_OP_WATCH);
op->watch.cookie = cookie;
op->watch.ver = version;
if (opcode == CEPH_OSD_OP_WATCH && flag)
op->watch.flag = (u8)1;
}
EXPORT_SYMBOL(osd_req_op_watch_init);
static void ceph_osdc_msg_data_add(struct ceph_msg *msg,
struct ceph_osd_data *osd_data)
{
u64 length = ceph_osd_data_length(osd_data);
if (osd_data->type == CEPH_OSD_DATA_TYPE_PAGES) {
BUG_ON(length > (u64) SIZE_MAX);
if (length)
ceph_msg_data_add_pages(msg, osd_data->pages,
length, osd_data->alignment);
} else if (osd_data->type == CEPH_OSD_DATA_TYPE_PAGELIST) {
BUG_ON(!length);
ceph_msg_data_add_pagelist(msg, osd_data->pagelist);
#ifdef CONFIG_BLOCK
} else if (osd_data->type == CEPH_OSD_DATA_TYPE_BIO) {
ceph_msg_data_add_bio(msg, osd_data->bio, length);
#endif
} else {
BUG_ON(osd_data->type != CEPH_OSD_DATA_TYPE_NONE);
} }
}
req->r_request_attempts = p; static u64 osd_req_encode_op(struct ceph_osd_request *req,
p += 4; struct ceph_osd_op *dst, unsigned int which)
{
struct ceph_osd_req_op *src;
struct ceph_osd_data *osd_data;
u64 request_data_len = 0;
u64 data_length;
data_len = req->r_trail.length; BUG_ON(which >= req->r_num_ops);
if (flags & CEPH_OSD_FLAG_WRITE) { src = &req->r_ops[which];
req->r_request->hdr.data_off = cpu_to_le16(off); if (WARN_ON(!osd_req_opcode_valid(src->op))) {
data_len += len; pr_err("unrecognized osd opcode %d\n", src->op);
return 0;
} }
req->r_request->hdr.data_len = cpu_to_le32(data_len);
req->r_request->page_alignment = req->r_page_alignment;
BUG_ON(p > msg->front.iov_base + msg->front.iov_len); switch (src->op) {
msg_size = p - msg->front.iov_base; case CEPH_OSD_OP_STAT:
msg->front.iov_len = msg_size; osd_data = &src->raw_data_in;
msg->hdr.front_len = cpu_to_le32(msg_size); ceph_osdc_msg_data_add(req->r_reply, osd_data);
break;
case CEPH_OSD_OP_READ:
case CEPH_OSD_OP_WRITE:
if (src->op == CEPH_OSD_OP_WRITE)
request_data_len = src->extent.length;
dst->extent.offset = cpu_to_le64(src->extent.offset);
dst->extent.length = cpu_to_le64(src->extent.length);
dst->extent.truncate_size =
cpu_to_le64(src->extent.truncate_size);
dst->extent.truncate_seq =
cpu_to_le32(src->extent.truncate_seq);
osd_data = &src->extent.osd_data;
if (src->op == CEPH_OSD_OP_WRITE)
ceph_osdc_msg_data_add(req->r_request, osd_data);
else
ceph_osdc_msg_data_add(req->r_reply, osd_data);
break;
case CEPH_OSD_OP_CALL:
dst->cls.class_len = src->cls.class_len;
dst->cls.method_len = src->cls.method_len;
osd_data = &src->cls.request_info;
ceph_osdc_msg_data_add(req->r_request, osd_data);
BUG_ON(osd_data->type != CEPH_OSD_DATA_TYPE_PAGELIST);
request_data_len = osd_data->pagelist->length;
osd_data = &src->cls.request_data;
data_length = ceph_osd_data_length(osd_data);
if (data_length) {
BUG_ON(osd_data->type == CEPH_OSD_DATA_TYPE_NONE);
dst->cls.indata_len = cpu_to_le32(data_length);
ceph_osdc_msg_data_add(req->r_request, osd_data);
src->payload_len += data_length;
request_data_len += data_length;
}
osd_data = &src->cls.response_data;
ceph_osdc_msg_data_add(req->r_reply, osd_data);
break;
case CEPH_OSD_OP_STARTSYNC:
break;
case CEPH_OSD_OP_NOTIFY_ACK:
case CEPH_OSD_OP_WATCH:
dst->watch.cookie = cpu_to_le64(src->watch.cookie);
dst->watch.ver = cpu_to_le64(src->watch.ver);
dst->watch.flag = src->watch.flag;
break;
default:
pr_err("unsupported osd opcode %s\n",
ceph_osd_op_name(src->op));
WARN_ON(1);
dout("build_request msg_size was %d num_ops %d\n", (int)msg_size, return 0;
num_ops); }
return; dst->op = cpu_to_le16(src->op);
dst->payload_len = cpu_to_le32(src->payload_len);
return request_data_len;
} }
EXPORT_SYMBOL(ceph_osdc_build_request);
/* /*
* build new request AND message, calculate layout, and adjust file * build new request AND message, calculate layout, and adjust file
...@@ -436,51 +700,63 @@ EXPORT_SYMBOL(ceph_osdc_build_request); ...@@ -436,51 +700,63 @@ EXPORT_SYMBOL(ceph_osdc_build_request);
struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc, struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
struct ceph_file_layout *layout, struct ceph_file_layout *layout,
struct ceph_vino vino, struct ceph_vino vino,
u64 off, u64 *plen, u64 off, u64 *plen, int num_ops,
int opcode, int flags, int opcode, int flags,
struct ceph_snap_context *snapc, struct ceph_snap_context *snapc,
int do_sync,
u32 truncate_seq, u32 truncate_seq,
u64 truncate_size, u64 truncate_size,
struct timespec *mtime, bool use_mempool)
bool use_mempool,
int page_align)
{ {
struct ceph_osd_req_op ops[2];
struct ceph_osd_request *req; struct ceph_osd_request *req;
unsigned int num_op = 1; u64 objnum = 0;
u64 objoff = 0;
u64 objlen = 0;
u32 object_size;
u64 object_base;
int r; int r;
memset(&ops, 0, sizeof ops); BUG_ON(opcode != CEPH_OSD_OP_READ && opcode != CEPH_OSD_OP_WRITE);
ops[0].op = opcode;
ops[0].extent.truncate_seq = truncate_seq;
ops[0].extent.truncate_size = truncate_size;
if (do_sync) {
ops[1].op = CEPH_OSD_OP_STARTSYNC;
num_op++;
}
req = ceph_osdc_alloc_request(osdc, snapc, num_op, use_mempool, req = ceph_osdc_alloc_request(osdc, snapc, num_ops, use_mempool,
GFP_NOFS); GFP_NOFS);
if (!req) if (!req)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
req->r_flags = flags; req->r_flags = flags;
/* calculate max write size */ /* calculate max write size */
r = calc_layout(vino, layout, off, plen, req, ops); r = calc_layout(layout, off, plen, &objnum, &objoff, &objlen);
if (r < 0) if (r < 0) {
ceph_osdc_put_request(req);
return ERR_PTR(r); return ERR_PTR(r);
req->r_file_layout = *layout; /* keep a copy */ }
/* in case it differs from natural (file) alignment that object_size = le32_to_cpu(layout->fl_object_size);
calc_layout filled in for us */ object_base = off - objoff;
req->r_num_pages = calc_pages_for(page_align, *plen); if (truncate_size <= object_base) {
req->r_page_alignment = page_align; truncate_size = 0;
} else {
truncate_size -= object_base;
if (truncate_size > object_size)
truncate_size = object_size;
}
osd_req_op_extent_init(req, 0, opcode, objoff, objlen,
truncate_size, truncate_seq);
/*
* A second op in the ops array means the caller wants to
* also issue a include a 'startsync' command so that the
* osd will flush data quickly.
*/
if (num_ops > 1)
osd_req_op_init(req, 1, CEPH_OSD_OP_STARTSYNC);
req->r_file_layout = *layout; /* keep a copy */
ceph_osdc_build_request(req, off, *plen, num_op, ops, snprintf(req->r_oid, sizeof(req->r_oid), "%llx.%08llx",
snapc, vino.snap, mtime); vino.ino, objnum);
req->r_oid_len = strlen(req->r_oid);
return req; return req;
} }
...@@ -558,21 +834,46 @@ static void __kick_osd_requests(struct ceph_osd_client *osdc, ...@@ -558,21 +834,46 @@ static void __kick_osd_requests(struct ceph_osd_client *osdc,
struct ceph_osd *osd) struct ceph_osd *osd)
{ {
struct ceph_osd_request *req, *nreq; struct ceph_osd_request *req, *nreq;
LIST_HEAD(resend);
int err; int err;
dout("__kick_osd_requests osd%d\n", osd->o_osd); dout("__kick_osd_requests osd%d\n", osd->o_osd);
err = __reset_osd(osdc, osd); err = __reset_osd(osdc, osd);
if (err) if (err)
return; return;
/*
* Build up a list of requests to resend by traversing the
* osd's list of requests. Requests for a given object are
* sent in tid order, and that is also the order they're
* kept on this list. Therefore all requests that are in
* flight will be found first, followed by all requests that
* have not yet been sent. And to resend requests while
* preserving this order we will want to put any sent
* requests back on the front of the osd client's unsent
* list.
*
* So we build a separate ordered list of already-sent
* requests for the affected osd and splice it onto the
* front of the osd client's unsent list. Once we've seen a
* request that has not yet been sent we're done. Those
* requests are already sitting right where they belong.
*/
list_for_each_entry(req, &osd->o_requests, r_osd_item) { list_for_each_entry(req, &osd->o_requests, r_osd_item) {
list_move(&req->r_req_lru_item, &osdc->req_unsent); if (!req->r_sent)
dout("requeued %p tid %llu osd%d\n", req, req->r_tid, break;
list_move_tail(&req->r_req_lru_item, &resend);
dout("requeueing %p tid %llu osd%d\n", req, req->r_tid,
osd->o_osd); osd->o_osd);
if (!req->r_linger) if (!req->r_linger)
req->r_flags |= CEPH_OSD_FLAG_RETRY; req->r_flags |= CEPH_OSD_FLAG_RETRY;
} }
list_splice(&resend, &osdc->req_unsent);
/*
* Linger requests are re-registered before sending, which
* sets up a new tid for each. We add them to the unsent
* list at the end to keep things in tid order.
*/
list_for_each_entry_safe(req, nreq, &osd->o_linger_requests, list_for_each_entry_safe(req, nreq, &osd->o_linger_requests,
r_linger_osd) { r_linger_osd) {
/* /*
...@@ -581,8 +882,8 @@ static void __kick_osd_requests(struct ceph_osd_client *osdc, ...@@ -581,8 +882,8 @@ static void __kick_osd_requests(struct ceph_osd_client *osdc,
*/ */
BUG_ON(!list_empty(&req->r_req_lru_item)); BUG_ON(!list_empty(&req->r_req_lru_item));
__register_request(osdc, req); __register_request(osdc, req);
list_add(&req->r_req_lru_item, &osdc->req_unsent); list_add_tail(&req->r_req_lru_item, &osdc->req_unsent);
list_add(&req->r_osd_item, &req->r_osd->o_requests); list_add_tail(&req->r_osd_item, &req->r_osd->o_requests);
__unregister_linger_request(osdc, req); __unregister_linger_request(osdc, req);
dout("requeued lingering %p tid %llu osd%d\n", req, req->r_tid, dout("requeued lingering %p tid %llu osd%d\n", req, req->r_tid,
osd->o_osd); osd->o_osd);
...@@ -654,8 +955,7 @@ static void put_osd(struct ceph_osd *osd) ...@@ -654,8 +955,7 @@ static void put_osd(struct ceph_osd *osd)
if (atomic_dec_and_test(&osd->o_ref) && osd->o_auth.authorizer) { if (atomic_dec_and_test(&osd->o_ref) && osd->o_auth.authorizer) {
struct ceph_auth_client *ac = osd->o_osdc->client->monc.auth; struct ceph_auth_client *ac = osd->o_osdc->client->monc.auth;
if (ac->ops && ac->ops->destroy_authorizer) ceph_auth_destroy_authorizer(ac, osd->o_auth.authorizer);
ac->ops->destroy_authorizer(ac, osd->o_auth.authorizer);
kfree(osd); kfree(osd);
} }
} }
...@@ -820,14 +1120,6 @@ static void __register_request(struct ceph_osd_client *osdc, ...@@ -820,14 +1120,6 @@ static void __register_request(struct ceph_osd_client *osdc,
} }
} }
static void register_request(struct ceph_osd_client *osdc,
struct ceph_osd_request *req)
{
mutex_lock(&osdc->request_mutex);
__register_request(osdc, req);
mutex_unlock(&osdc->request_mutex);
}
/* /*
* called under osdc->request_mutex * called under osdc->request_mutex
*/ */
...@@ -952,8 +1244,8 @@ static int __map_request(struct ceph_osd_client *osdc, ...@@ -952,8 +1244,8 @@ static int __map_request(struct ceph_osd_client *osdc,
int err; int err;
dout("map_request %p tid %lld\n", req, req->r_tid); dout("map_request %p tid %lld\n", req, req->r_tid);
err = ceph_calc_object_layout(&pgid, req->r_oid, err = ceph_calc_ceph_pg(&pgid, req->r_oid, osdc->osdmap,
&req->r_file_layout, osdc->osdmap); ceph_file_layout_pg_pool(req->r_file_layout));
if (err) { if (err) {
list_move(&req->r_req_lru_item, &osdc->req_notarget); list_move(&req->r_req_lru_item, &osdc->req_notarget);
return err; return err;
...@@ -1007,10 +1299,10 @@ static int __map_request(struct ceph_osd_client *osdc, ...@@ -1007,10 +1299,10 @@ static int __map_request(struct ceph_osd_client *osdc,
if (req->r_osd) { if (req->r_osd) {
__remove_osd_from_lru(req->r_osd); __remove_osd_from_lru(req->r_osd);
list_add(&req->r_osd_item, &req->r_osd->o_requests); list_add_tail(&req->r_osd_item, &req->r_osd->o_requests);
list_move(&req->r_req_lru_item, &osdc->req_unsent); list_move_tail(&req->r_req_lru_item, &osdc->req_unsent);
} else { } else {
list_move(&req->r_req_lru_item, &osdc->req_notarget); list_move_tail(&req->r_req_lru_item, &osdc->req_notarget);
} }
err = 1; /* osd or pg changed */ err = 1; /* osd or pg changed */
...@@ -1045,8 +1337,14 @@ static void __send_request(struct ceph_osd_client *osdc, ...@@ -1045,8 +1337,14 @@ static void __send_request(struct ceph_osd_client *osdc,
list_move_tail(&req->r_req_lru_item, &osdc->req_lru); list_move_tail(&req->r_req_lru_item, &osdc->req_lru);
ceph_msg_get(req->r_request); /* send consumes a ref */ ceph_msg_get(req->r_request); /* send consumes a ref */
ceph_con_send(&req->r_osd->o_con, req->r_request);
/* Mark the request unsafe if this is the first timet's being sent. */
if (!req->r_sent && req->r_unsafe_callback)
req->r_unsafe_callback(req, true);
req->r_sent = req->r_osd->o_incarnation; req->r_sent = req->r_osd->o_incarnation;
ceph_con_send(&req->r_osd->o_con, req->r_request);
} }
/* /*
...@@ -1134,31 +1432,11 @@ static void handle_osds_timeout(struct work_struct *work) ...@@ -1134,31 +1432,11 @@ static void handle_osds_timeout(struct work_struct *work)
static void complete_request(struct ceph_osd_request *req) static void complete_request(struct ceph_osd_request *req)
{ {
if (req->r_safe_callback) if (req->r_unsafe_callback)
req->r_safe_callback(req, NULL); req->r_unsafe_callback(req, false);
complete_all(&req->r_safe_completion); /* fsync waiter */ complete_all(&req->r_safe_completion); /* fsync waiter */
} }
static int __decode_pgid(void **p, void *end, struct ceph_pg *pgid)
{
__u8 v;
ceph_decode_need(p, end, 1 + 8 + 4 + 4, bad);
v = ceph_decode_8(p);
if (v > 1) {
pr_warning("do not understand pg encoding %d > 1", v);
return -EINVAL;
}
pgid->pool = ceph_decode_64(p);
pgid->seed = ceph_decode_32(p);
*p += 4;
return 0;
bad:
pr_warning("incomplete pg encoding");
return -EINVAL;
}
/* /*
* handle osd op reply. either call the callback if it is specified, * handle osd op reply. either call the callback if it is specified,
* or do the completion to wake up the waiting thread. * or do the completion to wake up the waiting thread.
...@@ -1170,7 +1448,8 @@ static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg, ...@@ -1170,7 +1448,8 @@ static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg,
struct ceph_osd_request *req; struct ceph_osd_request *req;
u64 tid; u64 tid;
int object_len; int object_len;
int numops, payload_len, flags; unsigned int numops;
int payload_len, flags;
s32 result; s32 result;
s32 retry_attempt; s32 retry_attempt;
struct ceph_pg pg; struct ceph_pg pg;
...@@ -1178,7 +1457,9 @@ static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg, ...@@ -1178,7 +1457,9 @@ static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg,
u32 reassert_epoch; u32 reassert_epoch;
u64 reassert_version; u64 reassert_version;
u32 osdmap_epoch; u32 osdmap_epoch;
int i; int already_completed;
u32 bytes;
unsigned int i;
tid = le64_to_cpu(msg->hdr.tid); tid = le64_to_cpu(msg->hdr.tid);
dout("handle_reply %p tid %llu\n", msg, tid); dout("handle_reply %p tid %llu\n", msg, tid);
...@@ -1191,7 +1472,7 @@ static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg, ...@@ -1191,7 +1472,7 @@ static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg,
ceph_decode_need(&p, end, object_len, bad); ceph_decode_need(&p, end, object_len, bad);
p += object_len; p += object_len;
err = __decode_pgid(&p, end, &pg); err = ceph_decode_pgid(&p, end, &pg);
if (err) if (err)
goto bad; goto bad;
...@@ -1207,8 +1488,7 @@ static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg, ...@@ -1207,8 +1488,7 @@ static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg,
req = __lookup_request(osdc, tid); req = __lookup_request(osdc, tid);
if (req == NULL) { if (req == NULL) {
dout("handle_reply tid %llu dne\n", tid); dout("handle_reply tid %llu dne\n", tid);
mutex_unlock(&osdc->request_mutex); goto bad_mutex;
return;
} }
ceph_osdc_get_request(req); ceph_osdc_get_request(req);
...@@ -1233,9 +1513,10 @@ static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg, ...@@ -1233,9 +1513,10 @@ static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg,
payload_len += len; payload_len += len;
p += sizeof(*op); p += sizeof(*op);
} }
if (payload_len != le32_to_cpu(msg->hdr.data_len)) { bytes = le32_to_cpu(msg->hdr.data_len);
if (payload_len != bytes) {
pr_warning("sum of op payload lens %d != data_len %d", pr_warning("sum of op payload lens %d != data_len %d",
payload_len, le32_to_cpu(msg->hdr.data_len)); payload_len, bytes);
goto bad_put; goto bad_put;
} }
...@@ -1244,21 +1525,9 @@ static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg, ...@@ -1244,21 +1525,9 @@ static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg,
for (i = 0; i < numops; i++) for (i = 0; i < numops; i++)
req->r_reply_op_result[i] = ceph_decode_32(&p); req->r_reply_op_result[i] = ceph_decode_32(&p);
/*
* if this connection filled our message, drop our reference now, to
* avoid a (safe but slower) revoke later.
*/
if (req->r_con_filling_msg == con && req->r_reply == msg) {
dout(" dropping con_filling_msg ref %p\n", con);
req->r_con_filling_msg = NULL;
con->ops->put(con);
}
if (!req->r_got_reply) { if (!req->r_got_reply) {
unsigned int bytes;
req->r_result = result; req->r_result = result;
bytes = le32_to_cpu(msg->hdr.data_len);
dout("handle_reply result %d bytes %d\n", req->r_result, dout("handle_reply result %d bytes %d\n", req->r_result,
bytes); bytes);
if (req->r_result == 0) if (req->r_result == 0)
...@@ -1286,7 +1555,11 @@ static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg, ...@@ -1286,7 +1555,11 @@ static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg,
((flags & CEPH_OSD_FLAG_WRITE) == 0)) ((flags & CEPH_OSD_FLAG_WRITE) == 0))
__unregister_request(osdc, req); __unregister_request(osdc, req);
already_completed = req->r_completed;
req->r_completed = 1;
mutex_unlock(&osdc->request_mutex); mutex_unlock(&osdc->request_mutex);
if (already_completed)
goto done;
if (req->r_callback) if (req->r_callback)
req->r_callback(req, msg); req->r_callback(req, msg);
...@@ -1303,6 +1576,8 @@ static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg, ...@@ -1303,6 +1576,8 @@ static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg,
bad_put: bad_put:
ceph_osdc_put_request(req); ceph_osdc_put_request(req);
bad_mutex:
mutex_unlock(&osdc->request_mutex);
bad: bad:
pr_err("corrupt osd_op_reply got %d %d\n", pr_err("corrupt osd_op_reply got %d %d\n",
(int)msg->front.iov_len, le32_to_cpu(msg->hdr.front_len)); (int)msg->front.iov_len, le32_to_cpu(msg->hdr.front_len));
...@@ -1735,6 +2010,104 @@ static void handle_watch_notify(struct ceph_osd_client *osdc, ...@@ -1735,6 +2010,104 @@ static void handle_watch_notify(struct ceph_osd_client *osdc,
return; return;
} }
/*
* build new request AND message
*
*/
void ceph_osdc_build_request(struct ceph_osd_request *req, u64 off,
struct ceph_snap_context *snapc, u64 snap_id,
struct timespec *mtime)
{
struct ceph_msg *msg = req->r_request;
void *p;
size_t msg_size;
int flags = req->r_flags;
u64 data_len;
unsigned int i;
req->r_snapid = snap_id;
req->r_snapc = ceph_get_snap_context(snapc);
/* encode request */
msg->hdr.version = cpu_to_le16(4);
p = msg->front.iov_base;
ceph_encode_32(&p, 1); /* client_inc is always 1 */
req->r_request_osdmap_epoch = p;
p += 4;
req->r_request_flags = p;
p += 4;
if (req->r_flags & CEPH_OSD_FLAG_WRITE)
ceph_encode_timespec(p, mtime);
p += sizeof(struct ceph_timespec);
req->r_request_reassert_version = p;
p += sizeof(struct ceph_eversion); /* will get filled in */
/* oloc */
ceph_encode_8(&p, 4);
ceph_encode_8(&p, 4);
ceph_encode_32(&p, 8 + 4 + 4);
req->r_request_pool = p;
p += 8;
ceph_encode_32(&p, -1); /* preferred */
ceph_encode_32(&p, 0); /* key len */
ceph_encode_8(&p, 1);
req->r_request_pgid = p;
p += 8 + 4;
ceph_encode_32(&p, -1); /* preferred */
/* oid */
ceph_encode_32(&p, req->r_oid_len);
memcpy(p, req->r_oid, req->r_oid_len);
dout("oid '%.*s' len %d\n", req->r_oid_len, req->r_oid, req->r_oid_len);
p += req->r_oid_len;
/* ops--can imply data */
ceph_encode_16(&p, (u16)req->r_num_ops);
data_len = 0;
for (i = 0; i < req->r_num_ops; i++) {
data_len += osd_req_encode_op(req, p, i);
p += sizeof(struct ceph_osd_op);
}
/* snaps */
ceph_encode_64(&p, req->r_snapid);
ceph_encode_64(&p, req->r_snapc ? req->r_snapc->seq : 0);
ceph_encode_32(&p, req->r_snapc ? req->r_snapc->num_snaps : 0);
if (req->r_snapc) {
for (i = 0; i < snapc->num_snaps; i++) {
ceph_encode_64(&p, req->r_snapc->snaps[i]);
}
}
req->r_request_attempts = p;
p += 4;
/* data */
if (flags & CEPH_OSD_FLAG_WRITE) {
u16 data_off;
/*
* The header "data_off" is a hint to the receiver
* allowing it to align received data into its
* buffers such that there's no need to re-copy
* it before writing it to disk (direct I/O).
*/
data_off = (u16) (off & 0xffff);
req->r_request->hdr.data_off = cpu_to_le16(data_off);
}
req->r_request->hdr.data_len = cpu_to_le32(data_len);
BUG_ON(p > msg->front.iov_base + msg->front.iov_len);
msg_size = p - msg->front.iov_base;
msg->front.iov_len = msg_size;
msg->hdr.front_len = cpu_to_le32(msg_size);
dout("build_request msg_size was %d\n", (int)msg_size);
}
EXPORT_SYMBOL(ceph_osdc_build_request);
/* /*
* Register request, send initial attempt. * Register request, send initial attempt.
*/ */
...@@ -1744,41 +2117,26 @@ int ceph_osdc_start_request(struct ceph_osd_client *osdc, ...@@ -1744,41 +2117,26 @@ int ceph_osdc_start_request(struct ceph_osd_client *osdc,
{ {
int rc = 0; int rc = 0;
req->r_request->pages = req->r_pages;
req->r_request->nr_pages = req->r_num_pages;
#ifdef CONFIG_BLOCK
req->r_request->bio = req->r_bio;
#endif
req->r_request->trail = &req->r_trail;
register_request(osdc, req);
down_read(&osdc->map_sem); down_read(&osdc->map_sem);
mutex_lock(&osdc->request_mutex); mutex_lock(&osdc->request_mutex);
/* __register_request(osdc, req);
* a racing kick_requests() may have sent the message for us WARN_ON(req->r_sent);
* while we dropped request_mutex above, so only send now if rc = __map_request(osdc, req, 0);
* the request still han't been touched yet. if (rc < 0) {
*/ if (nofail) {
if (req->r_sent == 0) { dout("osdc_start_request failed map, "
rc = __map_request(osdc, req, 0); " will retry %lld\n", req->r_tid);
if (rc < 0) { rc = 0;
if (nofail) {
dout("osdc_start_request failed map, "
" will retry %lld\n", req->r_tid);
rc = 0;
}
goto out_unlock;
}
if (req->r_osd == NULL) {
dout("send_request %p no up osds in pg\n", req);
ceph_monc_request_next_osdmap(&osdc->client->monc);
} else {
__send_request(osdc, req);
} }
rc = 0; goto out_unlock;
} }
if (req->r_osd == NULL) {
dout("send_request %p no up osds in pg\n", req);
ceph_monc_request_next_osdmap(&osdc->client->monc);
} else {
__send_queued(osdc);
}
rc = 0;
out_unlock: out_unlock:
mutex_unlock(&osdc->request_mutex); mutex_unlock(&osdc->request_mutex);
up_read(&osdc->map_sem); up_read(&osdc->map_sem);
...@@ -1940,18 +2298,22 @@ int ceph_osdc_readpages(struct ceph_osd_client *osdc, ...@@ -1940,18 +2298,22 @@ int ceph_osdc_readpages(struct ceph_osd_client *osdc,
dout("readpages on ino %llx.%llx on %llu~%llu\n", vino.ino, dout("readpages on ino %llx.%llx on %llu~%llu\n", vino.ino,
vino.snap, off, *plen); vino.snap, off, *plen);
req = ceph_osdc_new_request(osdc, layout, vino, off, plen, req = ceph_osdc_new_request(osdc, layout, vino, off, plen, 1,
CEPH_OSD_OP_READ, CEPH_OSD_FLAG_READ, CEPH_OSD_OP_READ, CEPH_OSD_FLAG_READ,
NULL, 0, truncate_seq, truncate_size, NULL, NULL, truncate_seq, truncate_size,
false, page_align); false);
if (IS_ERR(req)) if (IS_ERR(req))
return PTR_ERR(req); return PTR_ERR(req);
/* it may be a short read due to an object boundary */ /* it may be a short read due to an object boundary */
req->r_pages = pages;
dout("readpages final extent is %llu~%llu (%d pages align %d)\n", osd_req_op_extent_osd_data_pages(req, 0,
off, *plen, req->r_num_pages, page_align); pages, *plen, page_align, false, false);
dout("readpages final extent is %llu~%llu (%llu bytes align %d)\n",
off, *plen, *plen, page_align);
ceph_osdc_build_request(req, off, NULL, vino.snap, NULL);
rc = ceph_osdc_start_request(osdc, req, false); rc = ceph_osdc_start_request(osdc, req, false);
if (!rc) if (!rc)
...@@ -1978,20 +2340,21 @@ int ceph_osdc_writepages(struct ceph_osd_client *osdc, struct ceph_vino vino, ...@@ -1978,20 +2340,21 @@ int ceph_osdc_writepages(struct ceph_osd_client *osdc, struct ceph_vino vino,
int rc = 0; int rc = 0;
int page_align = off & ~PAGE_MASK; int page_align = off & ~PAGE_MASK;
BUG_ON(vino.snap != CEPH_NOSNAP); BUG_ON(vino.snap != CEPH_NOSNAP); /* snapshots aren't writeable */
req = ceph_osdc_new_request(osdc, layout, vino, off, &len, req = ceph_osdc_new_request(osdc, layout, vino, off, &len, 1,
CEPH_OSD_OP_WRITE, CEPH_OSD_OP_WRITE,
CEPH_OSD_FLAG_ONDISK | CEPH_OSD_FLAG_WRITE, CEPH_OSD_FLAG_ONDISK | CEPH_OSD_FLAG_WRITE,
snapc, 0, snapc, truncate_seq, truncate_size,
truncate_seq, truncate_size, mtime, true);
true, page_align);
if (IS_ERR(req)) if (IS_ERR(req))
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 */
req->r_pages = pages; osd_req_op_extent_osd_data_pages(req, 0, pages, len, page_align,
dout("writepages %llu~%llu (%d pages)\n", off, len, false, false);
req->r_num_pages); dout("writepages %llu~%llu (%llu bytes)\n", off, len, len);
ceph_osdc_build_request(req, off, snapc, CEPH_NOSNAP, mtime);
rc = ceph_osdc_start_request(osdc, req, true); rc = ceph_osdc_start_request(osdc, req, true);
if (!rc) if (!rc)
...@@ -2005,6 +2368,26 @@ int ceph_osdc_writepages(struct ceph_osd_client *osdc, struct ceph_vino vino, ...@@ -2005,6 +2368,26 @@ int ceph_osdc_writepages(struct ceph_osd_client *osdc, struct ceph_vino vino,
} }
EXPORT_SYMBOL(ceph_osdc_writepages); EXPORT_SYMBOL(ceph_osdc_writepages);
int ceph_osdc_setup(void)
{
BUG_ON(ceph_osd_request_cache);
ceph_osd_request_cache = kmem_cache_create("ceph_osd_request",
sizeof (struct ceph_osd_request),
__alignof__(struct ceph_osd_request),
0, NULL);
return ceph_osd_request_cache ? 0 : -ENOMEM;
}
EXPORT_SYMBOL(ceph_osdc_setup);
void ceph_osdc_cleanup(void)
{
BUG_ON(!ceph_osd_request_cache);
kmem_cache_destroy(ceph_osd_request_cache);
ceph_osd_request_cache = NULL;
}
EXPORT_SYMBOL(ceph_osdc_cleanup);
/* /*
* handle incoming message * handle incoming message
*/ */
...@@ -2064,13 +2447,10 @@ static struct ceph_msg *get_reply(struct ceph_connection *con, ...@@ -2064,13 +2447,10 @@ static struct ceph_msg *get_reply(struct ceph_connection *con,
goto out; goto out;
} }
if (req->r_con_filling_msg) { if (req->r_reply->con)
dout("%s revoking msg %p from old con %p\n", __func__, dout("%s revoking msg %p from old con %p\n", __func__,
req->r_reply, req->r_con_filling_msg); req->r_reply, req->r_reply->con);
ceph_msg_revoke_incoming(req->r_reply); ceph_msg_revoke_incoming(req->r_reply);
req->r_con_filling_msg->ops->put(req->r_con_filling_msg);
req->r_con_filling_msg = NULL;
}
if (front > req->r_reply->front.iov_len) { if (front > req->r_reply->front.iov_len) {
pr_warning("get_reply front %d > preallocated %d\n", pr_warning("get_reply front %d > preallocated %d\n",
...@@ -2084,26 +2464,29 @@ static struct ceph_msg *get_reply(struct ceph_connection *con, ...@@ -2084,26 +2464,29 @@ static struct ceph_msg *get_reply(struct ceph_connection *con,
m = ceph_msg_get(req->r_reply); m = ceph_msg_get(req->r_reply);
if (data_len > 0) { if (data_len > 0) {
int want = calc_pages_for(req->r_page_alignment, data_len); struct ceph_osd_data *osd_data;
if (req->r_pages && unlikely(req->r_num_pages < want)) { /*
pr_warning("tid %lld reply has %d bytes %d pages, we" * XXX This is assuming there is only one op containing
" had only %d pages ready\n", tid, data_len, * XXX page data. Probably OK for reads, but this
want, req->r_num_pages); * XXX ought to be done more generally.
*skip = 1; */
ceph_msg_put(m); osd_data = osd_req_op_extent_osd_data(req, 0);
m = NULL; if (osd_data->type == CEPH_OSD_DATA_TYPE_PAGES) {
goto out; if (osd_data->pages &&
unlikely(osd_data->length < data_len)) {
pr_warning("tid %lld reply has %d bytes "
"we had only %llu bytes ready\n",
tid, data_len, osd_data->length);
*skip = 1;
ceph_msg_put(m);
m = NULL;
goto out;
}
} }
m->pages = req->r_pages;
m->nr_pages = req->r_num_pages;
m->page_alignment = req->r_page_alignment;
#ifdef CONFIG_BLOCK
m->bio = req->r_bio;
#endif
} }
*skip = 0; *skip = 0;
req->r_con_filling_msg = con->ops->get(con);
dout("get_reply tid %lld %p\n", tid, m); dout("get_reply tid %lld %p\n", tid, m);
out: out:
...@@ -2168,13 +2551,17 @@ static struct ceph_auth_handshake *get_authorizer(struct ceph_connection *con, ...@@ -2168,13 +2551,17 @@ static struct ceph_auth_handshake *get_authorizer(struct ceph_connection *con,
struct ceph_auth_handshake *auth = &o->o_auth; struct ceph_auth_handshake *auth = &o->o_auth;
if (force_new && auth->authorizer) { if (force_new && auth->authorizer) {
if (ac->ops && ac->ops->destroy_authorizer) ceph_auth_destroy_authorizer(ac, auth->authorizer);
ac->ops->destroy_authorizer(ac, auth->authorizer);
auth->authorizer = NULL; auth->authorizer = NULL;
} }
if (!auth->authorizer && ac->ops && ac->ops->create_authorizer) { if (!auth->authorizer) {
int ret = ac->ops->create_authorizer(ac, CEPH_ENTITY_TYPE_OSD, int ret = ceph_auth_create_authorizer(ac, CEPH_ENTITY_TYPE_OSD,
auth); auth);
if (ret)
return ERR_PTR(ret);
} else {
int ret = ceph_auth_update_authorizer(ac, CEPH_ENTITY_TYPE_OSD,
auth);
if (ret) if (ret)
return ERR_PTR(ret); return ERR_PTR(ret);
} }
...@@ -2190,11 +2577,7 @@ static int verify_authorizer_reply(struct ceph_connection *con, int len) ...@@ -2190,11 +2577,7 @@ static int verify_authorizer_reply(struct ceph_connection *con, int len)
struct ceph_osd_client *osdc = o->o_osdc; struct ceph_osd_client *osdc = o->o_osdc;
struct ceph_auth_client *ac = osdc->client->monc.auth; struct ceph_auth_client *ac = osdc->client->monc.auth;
/* return ceph_auth_verify_authorizer_reply(ac, o->o_auth.authorizer, len);
* XXX If ac->ops or ac->ops->verify_authorizer_reply is null,
* XXX which do we do: succeed or fail?
*/
return ac->ops->verify_authorizer_reply(ac, o->o_auth.authorizer, len);
} }
static int invalidate_authorizer(struct ceph_connection *con) static int invalidate_authorizer(struct ceph_connection *con)
...@@ -2203,9 +2586,7 @@ static int invalidate_authorizer(struct ceph_connection *con) ...@@ -2203,9 +2586,7 @@ static int invalidate_authorizer(struct ceph_connection *con)
struct ceph_osd_client *osdc = o->o_osdc; struct ceph_osd_client *osdc = o->o_osdc;
struct ceph_auth_client *ac = osdc->client->monc.auth; struct ceph_auth_client *ac = osdc->client->monc.auth;
if (ac->ops && ac->ops->invalidate_authorizer) ceph_auth_invalidate_authorizer(ac, CEPH_ENTITY_TYPE_OSD);
ac->ops->invalidate_authorizer(ac, CEPH_ENTITY_TYPE_OSD);
return ceph_monc_validate_auth(&osdc->client->monc); return ceph_monc_validate_auth(&osdc->client->monc);
} }
......
...@@ -654,24 +654,6 @@ static int osdmap_set_max_osd(struct ceph_osdmap *map, int max) ...@@ -654,24 +654,6 @@ static int osdmap_set_max_osd(struct ceph_osdmap *map, int max)
return 0; return 0;
} }
static int __decode_pgid(void **p, void *end, struct ceph_pg *pg)
{
u8 v;
ceph_decode_need(p, end, 1+8+4+4, bad);
v = ceph_decode_8(p);
if (v != 1)
goto bad;
pg->pool = ceph_decode_64(p);
pg->seed = ceph_decode_32(p);
*p += 4; /* skip preferred */
return 0;
bad:
dout("error decoding pgid\n");
return -EINVAL;
}
/* /*
* decode a full map. * decode a full map.
*/ */
...@@ -765,7 +747,7 @@ struct ceph_osdmap *osdmap_decode(void **p, void *end) ...@@ -765,7 +747,7 @@ struct ceph_osdmap *osdmap_decode(void **p, void *end)
struct ceph_pg pgid; struct ceph_pg pgid;
struct ceph_pg_mapping *pg; struct ceph_pg_mapping *pg;
err = __decode_pgid(p, end, &pgid); err = ceph_decode_pgid(p, end, &pgid);
if (err) if (err)
goto bad; goto bad;
ceph_decode_need(p, end, sizeof(u32), bad); ceph_decode_need(p, end, sizeof(u32), bad);
...@@ -983,7 +965,7 @@ struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end, ...@@ -983,7 +965,7 @@ struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end,
struct ceph_pg pgid; struct ceph_pg pgid;
u32 pglen; u32 pglen;
err = __decode_pgid(p, end, &pgid); err = ceph_decode_pgid(p, end, &pgid);
if (err) if (err)
goto bad; goto bad;
ceph_decode_need(p, end, sizeof(u32), bad); ceph_decode_need(p, end, sizeof(u32), bad);
...@@ -1111,27 +1093,22 @@ EXPORT_SYMBOL(ceph_calc_file_object_mapping); ...@@ -1111,27 +1093,22 @@ EXPORT_SYMBOL(ceph_calc_file_object_mapping);
* calculate an object layout (i.e. pgid) from an oid, * calculate an object layout (i.e. pgid) from an oid,
* file_layout, and osdmap * file_layout, and osdmap
*/ */
int ceph_calc_object_layout(struct ceph_pg *pg, int ceph_calc_ceph_pg(struct ceph_pg *pg, const char *oid,
const char *oid, struct ceph_osdmap *osdmap, uint64_t pool)
struct ceph_file_layout *fl,
struct ceph_osdmap *osdmap)
{ {
unsigned int num, num_mask; struct ceph_pg_pool_info *pool_info;
struct ceph_pg_pool_info *pool;
BUG_ON(!osdmap); BUG_ON(!osdmap);
pg->pool = le32_to_cpu(fl->fl_pg_pool); pool_info = __lookup_pg_pool(&osdmap->pg_pools, pool);
pool = __lookup_pg_pool(&osdmap->pg_pools, pg->pool); if (!pool_info)
if (!pool)
return -EIO; return -EIO;
pg->seed = ceph_str_hash(pool->object_hash, oid, strlen(oid)); pg->pool = pool;
num = pool->pg_num; pg->seed = ceph_str_hash(pool_info->object_hash, oid, strlen(oid));
num_mask = pool->pg_num_mask;
dout("calc_object_layout '%s' pgid %lld.%x\n", oid, pg->pool, pg->seed); dout("%s '%s' pgid %lld.%x\n", __func__, oid, pg->pool, pg->seed);
return 0; return 0;
} }
EXPORT_SYMBOL(ceph_calc_object_layout); EXPORT_SYMBOL(ceph_calc_ceph_pg);
/* /*
* Calculate raw osd vector for the given pgid. Return pointer to osd * Calculate raw osd vector for the given pgid. Return pointer to osd
......
/*
* snapshot.c Ceph snapshot context utility routines (part of libceph)
*
* Copyright (C) 2013 Inktank Storage, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
#include <stddef.h>
#include <linux/types.h>
#include <linux/export.h>
#include <linux/ceph/libceph.h>
/*
* Ceph snapshot contexts are reference counted objects, and the
* returned structure holds a single reference. Acquire additional
* references with ceph_get_snap_context(), and release them with
* ceph_put_snap_context(). When the reference count reaches zero
* the entire structure is freed.
*/
/*
* Create a new ceph snapshot context large enough to hold the
* indicated number of snapshot ids (which can be 0). Caller has
* to fill in snapc->seq and snapc->snaps[0..snap_count-1].
*
* Returns a null pointer if an error occurs.
*/
struct ceph_snap_context *ceph_create_snap_context(u32 snap_count,
gfp_t gfp_flags)
{
struct ceph_snap_context *snapc;
size_t size;
size = sizeof (struct ceph_snap_context);
size += snap_count * sizeof (snapc->snaps[0]);
snapc = kzalloc(size, gfp_flags);
if (!snapc)
return NULL;
atomic_set(&snapc->nref, 1);
snapc->num_snaps = snap_count;
return snapc;
}
EXPORT_SYMBOL(ceph_create_snap_context);
struct ceph_snap_context *ceph_get_snap_context(struct ceph_snap_context *sc)
{
if (sc)
atomic_inc(&sc->nref);
return sc;
}
EXPORT_SYMBOL(ceph_get_snap_context);
void ceph_put_snap_context(struct ceph_snap_context *sc)
{
if (!sc)
return;
if (atomic_dec_and_test(&sc->nref)) {
/*printk(" deleting snap_context %p\n", sc);*/
kfree(sc);
}
}
EXPORT_SYMBOL(ceph_put_snap_context);
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