Skip to content

Commit 97d2eb1

Browse files
committed
Merge branch 'for-linus' of git://ceph.newdream.net/git/ceph-client
* 'for-linus' of git://ceph.newdream.net/git/ceph-client: libceph: fix double-free of page vector ceph: fix 32-bit ino numbers libceph: force resend of osd requests if we skip an osdmap ceph: use kernel DNS resolver ceph: fix ceph_monc_init memory leak ceph: let the set_layout ioctl set single traits Revert "ceph: don't truncate dirty pages in invalidate work thread" ceph: replace leading spaces with tabs libceph: warn on msg allocation failures libceph: don't complain on msgpool alloc failures libceph: always preallocate mon connection libceph: create messenger with client ceph: document ioctls ceph: implement (optional) max read size ceph: rename rsize -> rasize ceph: make readpages fully async
2 parents 68d99b2 + 3395734 commit 97d2eb1

17 files changed

Lines changed: 483 additions & 255 deletions

File tree

‎drivers/block/rbd.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ static struct rbd_client *rbd_client_create(struct ceph_options *opt,
260260
kref_init(&rbdc->kref);
261261
INIT_LIST_HEAD(&rbdc->node);
262262

263-
rbdc->client = ceph_create_client(opt, rbdc);
263+
rbdc->client = ceph_create_client(opt, rbdc, 0, 0);
264264
if (IS_ERR(rbdc->client))
265265
goto out_rbdc;
266266
opt = NULL; /* Now rbdc->client is responsible for opt */

‎fs/ceph/addr.c‎

Lines changed: 123 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -228,102 +228,155 @@ static int ceph_readpage(struct file *filp, struct page *page)
228228
}
229229

230230
/*
231-
* Build a vector of contiguous pages from the provided page list.
231+
* Finish an async read(ahead) op.
232232
*/
233-
static struct page **page_vector_from_list(struct list_head *page_list,
234-
unsigned *nr_pages)
233+
static void finish_read(struct ceph_osd_request *req, struct ceph_msg *msg)
235234
{
236-
struct page **pages;
237-
struct page *page;
238-
int next_index, contig_pages = 0;
235+
struct inode *inode = req->r_inode;
236+
struct ceph_osd_reply_head *replyhead;
237+
int rc, bytes;
238+
int i;
239239

240-
/* build page vector */
241-
pages = kmalloc(sizeof(*pages) * *nr_pages, GFP_NOFS);
242-
if (!pages)
243-
return ERR_PTR(-ENOMEM);
240+
/* parse reply */
241+
replyhead = msg->front.iov_base;
242+
WARN_ON(le32_to_cpu(replyhead->num_ops) == 0);
243+
rc = le32_to_cpu(replyhead->result);
244+
bytes = le32_to_cpu(msg->hdr.data_len);
244245

245-
BUG_ON(list_empty(page_list));
246-
next_index = list_entry(page_list->prev, struct page, lru)->index;
247-
list_for_each_entry_reverse(page, page_list, lru) {
248-
if (page->index == next_index) {
249-
dout("readpages page %d %p\n", contig_pages, page);
250-
pages[contig_pages] = page;
251-
contig_pages++;
252-
next_index++;
253-
} else {
254-
break;
246+
dout("finish_read %p req %p rc %d bytes %d\n", inode, req, rc, bytes);
247+
248+
/* unlock all pages, zeroing any data we didn't read */
249+
for (i = 0; i < req->r_num_pages; i++, bytes -= PAGE_CACHE_SIZE) {
250+
struct page *page = req->r_pages[i];
251+
252+
if (bytes < (int)PAGE_CACHE_SIZE) {
253+
/* zero (remainder of) page */
254+
int s = bytes < 0 ? 0 : bytes;
255+
zero_user_segment(page, s, PAGE_CACHE_SIZE);
255256
}
257+
dout("finish_read %p uptodate %p idx %lu\n", inode, page,
258+
page->index);
259+
flush_dcache_page(page);
260+
SetPageUptodate(page);
261+
unlock_page(page);
262+
page_cache_release(page);
256263
}
257-
*nr_pages = contig_pages;
258-
return pages;
264+
kfree(req->r_pages);
259265
}
260266

261267
/*
262-
* Read multiple pages. Leave pages we don't read + unlock in page_list;
263-
* the caller (VM) cleans them up.
268+
* start an async read(ahead) operation. return nr_pages we submitted
269+
* a read for on success, or negative error code.
264270
*/
265-
static int ceph_readpages(struct file *file, struct address_space *mapping,
266-
struct list_head *page_list, unsigned nr_pages)
271+
static int start_read(struct inode *inode, struct list_head *page_list, int max)
267272
{
268-
struct inode *inode = file->f_dentry->d_inode;
269-
struct ceph_inode_info *ci = ceph_inode(inode);
270273
struct ceph_osd_client *osdc =
271274
&ceph_inode_to_client(inode)->client->osdc;
272-
int rc = 0;
273-
struct page **pages;
274-
loff_t offset;
275+
struct ceph_inode_info *ci = ceph_inode(inode);
276+
struct page *page = list_entry(page_list->prev, struct page, lru);
277+
struct ceph_osd_request *req;
278+
u64 off;
275279
u64 len;
280+
int i;
281+
struct page **pages;
282+
pgoff_t next_index;
283+
int nr_pages = 0;
284+
int ret;
276285

277-
dout("readpages %p file %p nr_pages %d\n",
278-
inode, file, nr_pages);
279-
280-
pages = page_vector_from_list(page_list, &nr_pages);
281-
if (IS_ERR(pages))
282-
return PTR_ERR(pages);
286+
off = page->index << PAGE_CACHE_SHIFT;
283287

284-
/* guess read extent */
285-
offset = pages[0]->index << PAGE_CACHE_SHIFT;
288+
/* count pages */
289+
next_index = page->index;
290+
list_for_each_entry_reverse(page, page_list, lru) {
291+
if (page->index != next_index)
292+
break;
293+
nr_pages++;
294+
next_index++;
295+
if (max && nr_pages == max)
296+
break;
297+
}
286298
len = nr_pages << PAGE_CACHE_SHIFT;
287-
rc = ceph_osdc_readpages(osdc, ceph_vino(inode), &ci->i_layout,
288-
offset, &len,
289-
ci->i_truncate_seq, ci->i_truncate_size,
290-
pages, nr_pages, 0);
291-
if (rc == -ENOENT)
292-
rc = 0;
293-
if (rc < 0)
294-
goto out;
295-
296-
for (; !list_empty(page_list) && len > 0;
297-
rc -= PAGE_CACHE_SIZE, len -= PAGE_CACHE_SIZE) {
298-
struct page *page =
299-
list_entry(page_list->prev, struct page, lru);
299+
dout("start_read %p nr_pages %d is %lld~%lld\n", inode, nr_pages,
300+
off, len);
301+
302+
req = ceph_osdc_new_request(osdc, &ci->i_layout, ceph_vino(inode),
303+
off, &len,
304+
CEPH_OSD_OP_READ, CEPH_OSD_FLAG_READ,
305+
NULL, 0,
306+
ci->i_truncate_seq, ci->i_truncate_size,
307+
NULL, false, 1, 0);
308+
if (!req)
309+
return -ENOMEM;
300310

311+
/* build page vector */
312+
nr_pages = len >> PAGE_CACHE_SHIFT;
313+
pages = kmalloc(sizeof(*pages) * nr_pages, GFP_NOFS);
314+
ret = -ENOMEM;
315+
if (!pages)
316+
goto out;
317+
for (i = 0; i < nr_pages; ++i) {
318+
page = list_entry(page_list->prev, struct page, lru);
319+
BUG_ON(PageLocked(page));
301320
list_del(&page->lru);
302-
303-
if (rc < (int)PAGE_CACHE_SIZE) {
304-
/* zero (remainder of) page */
305-
int s = rc < 0 ? 0 : rc;
306-
zero_user_segment(page, s, PAGE_CACHE_SIZE);
307-
}
308-
309-
if (add_to_page_cache_lru(page, mapping, page->index,
321+
322+
dout("start_read %p adding %p idx %lu\n", inode, page,
323+
page->index);
324+
if (add_to_page_cache_lru(page, &inode->i_data, page->index,
310325
GFP_NOFS)) {
311326
page_cache_release(page);
312-
dout("readpages %p add_to_page_cache failed %p\n",
327+
dout("start_read %p add_to_page_cache failed %p\n",
313328
inode, page);
314-
continue;
329+
nr_pages = i;
330+
goto out_pages;
315331
}
316-
dout("readpages %p adding %p idx %lu\n", inode, page,
317-
page->index);
318-
flush_dcache_page(page);
319-
SetPageUptodate(page);
320-
unlock_page(page);
321-
page_cache_release(page);
332+
pages[i] = page;
322333
}
323-
rc = 0;
334+
req->r_pages = pages;
335+
req->r_num_pages = nr_pages;
336+
req->r_callback = finish_read;
337+
req->r_inode = inode;
338+
339+
dout("start_read %p starting %p %lld~%lld\n", inode, req, off, len);
340+
ret = ceph_osdc_start_request(osdc, req, false);
341+
if (ret < 0)
342+
goto out_pages;
343+
ceph_osdc_put_request(req);
344+
return nr_pages;
324345

346+
out_pages:
347+
ceph_release_page_vector(pages, nr_pages);
348+
out:
349+
ceph_osdc_put_request(req);
350+
return ret;
351+
}
352+
353+
354+
/*
355+
* Read multiple pages. Leave pages we don't read + unlock in page_list;
356+
* the caller (VM) cleans them up.
357+
*/
358+
static int ceph_readpages(struct file *file, struct address_space *mapping,
359+
struct list_head *page_list, unsigned nr_pages)
360+
{
361+
struct inode *inode = file->f_dentry->d_inode;
362+
struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
363+
int rc = 0;
364+
int max = 0;
365+
366+
if (fsc->mount_options->rsize >= PAGE_CACHE_SIZE)
367+
max = (fsc->mount_options->rsize + PAGE_CACHE_SIZE - 1)
368+
>> PAGE_SHIFT;
369+
370+
dout("readpages %p file %p nr_pages %d max %d\n", inode, file, nr_pages,
371+
max);
372+
while (!list_empty(page_list)) {
373+
rc = start_read(inode, page_list, max);
374+
if (rc < 0)
375+
goto out;
376+
BUG_ON(rc == 0);
377+
}
325378
out:
326-
kfree(pages);
379+
dout("readpages %p file %p ret %d\n", inode, file, rc);
327380
return rc;
328381
}
329382

‎fs/ceph/caps.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ static int send_cap_msg(struct ceph_mds_session *session,
945945
seq, issue_seq, mseq, follows, size, max_size,
946946
xattr_version, xattrs_buf ? (int)xattrs_buf->vec.iov_len : 0);
947947

948-
msg = ceph_msg_new(CEPH_MSG_CLIENT_CAPS, sizeof(*fc), GFP_NOFS);
948+
msg = ceph_msg_new(CEPH_MSG_CLIENT_CAPS, sizeof(*fc), GFP_NOFS, false);
949949
if (!msg)
950950
return -ENOMEM;
951951

‎fs/ceph/inode.c‎

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <linux/namei.h>
1010
#include <linux/writeback.h>
1111
#include <linux/vmalloc.h>
12-
#include <linux/pagevec.h>
1312

1413
#include "super.h"
1514
#include "mds_client.h"
@@ -1363,49 +1362,6 @@ void ceph_queue_invalidate(struct inode *inode)
13631362
}
13641363
}
13651364

1366-
/*
1367-
* invalidate any pages that are not dirty or under writeback. this
1368-
* includes pages that are clean and mapped.
1369-
*/
1370-
static void ceph_invalidate_nondirty_pages(struct address_space *mapping)
1371-
{
1372-
struct pagevec pvec;
1373-
pgoff_t next = 0;
1374-
int i;
1375-
1376-
pagevec_init(&pvec, 0);
1377-
while (pagevec_lookup(&pvec, mapping, next, PAGEVEC_SIZE)) {
1378-
for (i = 0; i < pagevec_count(&pvec); i++) {
1379-
struct page *page = pvec.pages[i];
1380-
pgoff_t index;
1381-
int skip_page =
1382-
(PageDirty(page) || PageWriteback(page));
1383-
1384-
if (!skip_page)
1385-
skip_page = !trylock_page(page);
1386-
1387-
/*
1388-
* We really shouldn't be looking at the ->index of an
1389-
* unlocked page. But we're not allowed to lock these
1390-
* pages. So we rely upon nobody altering the ->index
1391-
* of this (pinned-by-us) page.
1392-
*/
1393-
index = page->index;
1394-
if (index > next)
1395-
next = index;
1396-
next++;
1397-
1398-
if (skip_page)
1399-
continue;
1400-
1401-
generic_error_remove_page(mapping, page);
1402-
unlock_page(page);
1403-
}
1404-
pagevec_release(&pvec);
1405-
cond_resched();
1406-
}
1407-
}
1408-
14091365
/*
14101366
* Invalidate inode pages in a worker thread. (This can't be done
14111367
* in the message handler context.)
@@ -1429,7 +1385,7 @@ static void ceph_invalidate_work(struct work_struct *work)
14291385
orig_gen = ci->i_rdcache_gen;
14301386
spin_unlock(&inode->i_lock);
14311387

1432-
ceph_invalidate_nondirty_pages(inode->i_mapping);
1388+
truncate_inode_pages(&inode->i_data, 0);
14331389

14341390
spin_lock(&inode->i_lock);
14351391
if (orig_gen == ci->i_rdcache_gen &&

‎fs/ceph/ioctl.c‎

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,39 @@ static long ceph_ioctl_set_layout(struct file *file, void __user *arg)
4242
struct ceph_mds_client *mdsc = ceph_sb_to_client(inode->i_sb)->mdsc;
4343
struct ceph_mds_request *req;
4444
struct ceph_ioctl_layout l;
45+
struct ceph_inode_info *ci = ceph_inode(file->f_dentry->d_inode);
46+
struct ceph_ioctl_layout nl;
4547
int err, i;
4648

47-
/* copy and validate */
4849
if (copy_from_user(&l, arg, sizeof(l)))
4950
return -EFAULT;
5051

51-
if ((l.object_size & ~PAGE_MASK) ||
52-
(l.stripe_unit & ~PAGE_MASK) ||
53-
!l.stripe_unit ||
54-
(l.object_size &&
55-
(unsigned)l.object_size % (unsigned)l.stripe_unit))
52+
/* validate changed params against current layout */
53+
err = ceph_do_getattr(file->f_dentry->d_inode, CEPH_STAT_CAP_LAYOUT);
54+
if (!err) {
55+
nl.stripe_unit = ceph_file_layout_su(ci->i_layout);
56+
nl.stripe_count = ceph_file_layout_stripe_count(ci->i_layout);
57+
nl.object_size = ceph_file_layout_object_size(ci->i_layout);
58+
nl.data_pool = le32_to_cpu(ci->i_layout.fl_pg_pool);
59+
nl.preferred_osd =
60+
(s32)le32_to_cpu(ci->i_layout.fl_pg_preferred);
61+
} else
62+
return err;
63+
64+
if (l.stripe_count)
65+
nl.stripe_count = l.stripe_count;
66+
if (l.stripe_unit)
67+
nl.stripe_unit = l.stripe_unit;
68+
if (l.object_size)
69+
nl.object_size = l.object_size;
70+
if (l.data_pool)
71+
nl.data_pool = l.data_pool;
72+
if (l.preferred_osd)
73+
nl.preferred_osd = l.preferred_osd;
74+
75+
if ((nl.object_size & ~PAGE_MASK) ||
76+
(nl.stripe_unit & ~PAGE_MASK) ||
77+
((unsigned)nl.object_size % (unsigned)nl.stripe_unit))
5678
return -EINVAL;
5779

5880
/* make sure it's a valid data pool */

0 commit comments

Comments
 (0)