Skip to content

Commit 99ccbd2

Browse files
author
Milosz Tanski
committed
ceph: use fscache as a local presisent cache
Adding support for fscache to the Ceph filesystem. This would bring it to on par with some of the other network filesystems in Linux (like NFS, AFS, etc...) In order to mount the filesystem with fscache the 'fsc' mount option must be passed. Signed-off-by: Milosz Tanski <milosz@adfin.com> Signed-off-by: Sage Weil <sage@inktank.com>
1 parent cd0a2df commit 99ccbd2

10 files changed

Lines changed: 666 additions & 13 deletions

File tree

‎fs/ceph/Kconfig‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,12 @@ config CEPH_FS
1616

1717
If unsure, say N.
1818

19+
if CEPH_FS
20+
config CEPH_FSCACHE
21+
bool "Enable Ceph client caching support"
22+
depends on CEPH_FS=m && FSCACHE || CEPH_FS=y && FSCACHE=y
23+
help
24+
Choose Y here to enable persistent, read-only local
25+
caching support for Ceph clients using FS-Cache
26+
27+
endif

‎fs/ceph/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ ceph-y := super.o inode.o dir.o file.o locks.o addr.o ioctl.o \
99
mds_client.o mdsmap.o strings.o ceph_frag.o \
1010
debugfs.o
1111

12+
ceph-$(CONFIG_CEPH_FSCACHE) += cache.o

‎fs/ceph/addr.c‎

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "super.h"
1313
#include "mds_client.h"
14+
#include "cache.h"
1415
#include <linux/ceph/osd_client.h>
1516

1617
/*
@@ -144,6 +145,11 @@ static void ceph_invalidatepage(struct page *page, unsigned int offset,
144145
return;
145146
}
146147

148+
ceph_invalidate_fscache_page(inode, page);
149+
150+
if (!PagePrivate(page))
151+
return;
152+
147153
/*
148154
* We can get non-dirty pages here due to races between
149155
* set_page_dirty and truncate_complete_page; just spit out a
@@ -163,14 +169,17 @@ static void ceph_invalidatepage(struct page *page, unsigned int offset,
163169
ClearPagePrivate(page);
164170
}
165171

166-
/* just a sanity check */
167172
static int ceph_releasepage(struct page *page, gfp_t g)
168173
{
169174
struct inode *inode = page->mapping ? page->mapping->host : NULL;
170175
dout("%p releasepage %p idx %lu\n", inode, page, page->index);
171176
WARN_ON(PageDirty(page));
172-
WARN_ON(PagePrivate(page));
173-
return 0;
177+
178+
/* Can we release the page from the cache? */
179+
if (!ceph_release_fscache_page(page, g))
180+
return 0;
181+
182+
return !PagePrivate(page);
174183
}
175184

176185
/*
@@ -180,11 +189,16 @@ static int readpage_nounlock(struct file *filp, struct page *page)
180189
{
181190
struct inode *inode = file_inode(filp);
182191
struct ceph_inode_info *ci = ceph_inode(inode);
183-
struct ceph_osd_client *osdc =
192+
struct ceph_osd_client *osdc =
184193
&ceph_inode_to_client(inode)->client->osdc;
185194
int err = 0;
186195
u64 len = PAGE_CACHE_SIZE;
187196

197+
err = ceph_readpage_from_fscache(inode, page);
198+
199+
if (err == 0)
200+
goto out;
201+
188202
dout("readpage inode %p file %p page %p index %lu\n",
189203
inode, filp, page, page->index);
190204
err = ceph_osdc_readpages(osdc, ceph_vino(inode), &ci->i_layout,
@@ -202,6 +216,9 @@ static int readpage_nounlock(struct file *filp, struct page *page)
202216
}
203217
SetPageUptodate(page);
204218

219+
if (err == 0)
220+
ceph_readpage_to_fscache(inode, page);
221+
205222
out:
206223
return err < 0 ? err : 0;
207224
}
@@ -244,6 +261,7 @@ static void finish_read(struct ceph_osd_request *req, struct ceph_msg *msg)
244261
page->index);
245262
flush_dcache_page(page);
246263
SetPageUptodate(page);
264+
ceph_readpage_to_fscache(inode, page);
247265
unlock_page(page);
248266
page_cache_release(page);
249267
bytes -= PAGE_CACHE_SIZE;
@@ -313,7 +331,7 @@ static int start_read(struct inode *inode, struct list_head *page_list, int max)
313331
page = list_entry(page_list->prev, struct page, lru);
314332
BUG_ON(PageLocked(page));
315333
list_del(&page->lru);
316-
334+
317335
dout("start_read %p adding %p idx %lu\n", inode, page,
318336
page->index);
319337
if (add_to_page_cache_lru(page, &inode->i_data, page->index,
@@ -360,6 +378,12 @@ static int ceph_readpages(struct file *file, struct address_space *mapping,
360378
int rc = 0;
361379
int max = 0;
362380

381+
rc = ceph_readpages_from_fscache(mapping->host, mapping, page_list,
382+
&nr_pages);
383+
384+
if (rc == 0)
385+
goto out;
386+
363387
if (fsc->mount_options->rsize >= PAGE_CACHE_SIZE)
364388
max = (fsc->mount_options->rsize + PAGE_CACHE_SIZE - 1)
365389
>> PAGE_SHIFT;
@@ -479,6 +503,8 @@ static int writepage_nounlock(struct page *page, struct writeback_control *wbc)
479503
CONGESTION_ON_THRESH(fsc->mount_options->congestion_kb))
480504
set_bdi_congested(&fsc->backing_dev_info, BLK_RW_ASYNC);
481505

506+
ceph_readpage_to_fscache(inode, page);
507+
482508
set_page_writeback(page);
483509
err = ceph_osdc_writepages(osdc, ceph_vino(inode),
484510
&ci->i_layout, snapc,
@@ -534,7 +560,6 @@ static void ceph_release_pages(struct page **pages, int num)
534560
pagevec_release(&pvec);
535561
}
536562

537-
538563
/*
539564
* async writeback completion handler.
540565
*

0 commit comments

Comments
 (0)