Linux Audio

Check our new training course

Loading...
v3.15
  1/*
  2 * Ceph cache definitions.
  3 *
  4 *  Copyright (C) 2013 by Adfin Solutions, Inc. All Rights Reserved.
  5 *  Written by Milosz Tanski (milosz@adfin.com)
  6 *
  7 *  This program is free software; you can redistribute it and/or modify
  8 *  it under the terms of the GNU General Public License version 2
  9 *  as published by the Free Software Foundation.
 10 *
 11 *  This program is distributed in the hope that it will be useful,
 12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14 *  GNU General Public License for more details.
 15 *
 16 *  You should have received a copy of the GNU General Public License
 17 *  along with this program; if not, write to:
 18 *  Free Software Foundation
 19 *  51 Franklin Street, Fifth Floor
 20 *  Boston, MA  02111-1301  USA
 21 *
 22 */
 23
 24#include "super.h"
 25#include "cache.h"
 26
 27struct ceph_aux_inode {
 
 28	struct timespec	mtime;
 29	loff_t          size;
 30};
 31
 32struct fscache_netfs ceph_cache_netfs = {
 33	.name		= "ceph",
 34	.version	= 0,
 35};
 36
 37static uint16_t ceph_fscache_session_get_key(const void *cookie_netfs_data,
 38					     void *buffer, uint16_t maxbuf)
 39{
 40	const struct ceph_fs_client* fsc = cookie_netfs_data;
 41	uint16_t klen;
 42
 43	klen = sizeof(fsc->client->fsid);
 44	if (klen > maxbuf)
 45		return 0;
 46
 47	memcpy(buffer, &fsc->client->fsid, klen);
 48	return klen;
 49}
 50
 51static const struct fscache_cookie_def ceph_fscache_fsid_object_def = {
 52	.name		= "CEPH.fsid",
 53	.type		= FSCACHE_COOKIE_TYPE_INDEX,
 54	.get_key	= ceph_fscache_session_get_key,
 55};
 56
 57int ceph_fscache_register(void)
 58{
 59	return fscache_register_netfs(&ceph_cache_netfs);
 60}
 61
 62void ceph_fscache_unregister(void)
 63{
 64	fscache_unregister_netfs(&ceph_cache_netfs);
 65}
 66
 67int ceph_fscache_register_fs(struct ceph_fs_client* fsc)
 68{
 69	fsc->fscache = fscache_acquire_cookie(ceph_cache_netfs.primary_index,
 70					      &ceph_fscache_fsid_object_def,
 71					      fsc, true);
 72
 73	if (fsc->fscache == NULL) {
 74		pr_err("Unable to resgister fsid: %p fscache cookie", fsc);
 75		return 0;
 76	}
 77
 78	fsc->revalidate_wq = alloc_workqueue("ceph-revalidate", 0, 1);
 79	if (fsc->revalidate_wq == NULL)
 80		return -ENOMEM;
 81
 82	return 0;
 83}
 84
 85static uint16_t ceph_fscache_inode_get_key(const void *cookie_netfs_data,
 86					   void *buffer, uint16_t maxbuf)
 87{
 88	const struct ceph_inode_info* ci = cookie_netfs_data;
 89	uint16_t klen;
 90
 91	/* use ceph virtual inode (id + snaphot) */
 92	klen = sizeof(ci->i_vino);
 93	if (klen > maxbuf)
 94		return 0;
 95
 96	memcpy(buffer, &ci->i_vino, klen);
 97	return klen;
 98}
 99
100static uint16_t ceph_fscache_inode_get_aux(const void *cookie_netfs_data,
101					   void *buffer, uint16_t bufmax)
102{
103	struct ceph_aux_inode aux;
104	const struct ceph_inode_info* ci = cookie_netfs_data;
105	const struct inode* inode = &ci->vfs_inode;
106
107	memset(&aux, 0, sizeof(aux));
 
108	aux.mtime = inode->i_mtime;
109	aux.size = inode->i_size;
110
111	memcpy(buffer, &aux, sizeof(aux));
112
113	return sizeof(aux);
114}
115
116static void ceph_fscache_inode_get_attr(const void *cookie_netfs_data,
117					uint64_t *size)
118{
119	const struct ceph_inode_info* ci = cookie_netfs_data;
120	const struct inode* inode = &ci->vfs_inode;
121
122	*size = inode->i_size;
123}
124
125static enum fscache_checkaux ceph_fscache_inode_check_aux(
126	void *cookie_netfs_data, const void *data, uint16_t dlen)
127{
128	struct ceph_aux_inode aux;
129	struct ceph_inode_info* ci = cookie_netfs_data;
130	struct inode* inode = &ci->vfs_inode;
131
132	if (dlen != sizeof(aux))
133		return FSCACHE_CHECKAUX_OBSOLETE;
134
135	memset(&aux, 0, sizeof(aux));
 
136	aux.mtime = inode->i_mtime;
137	aux.size = inode->i_size;
138
139	if (memcmp(data, &aux, sizeof(aux)) != 0)
140		return FSCACHE_CHECKAUX_OBSOLETE;
141
142	dout("ceph inode 0x%p cached okay", ci);
143	return FSCACHE_CHECKAUX_OKAY;
144}
145
146static void ceph_fscache_inode_now_uncached(void* cookie_netfs_data)
147{
148	struct ceph_inode_info* ci = cookie_netfs_data;
149	struct pagevec pvec;
150	pgoff_t first;
151	int loop, nr_pages;
152
153	pagevec_init(&pvec, 0);
154	first = 0;
155
156	dout("ceph inode 0x%p now uncached", ci);
157
158	while (1) {
159		nr_pages = pagevec_lookup(&pvec, ci->vfs_inode.i_mapping, first,
160					  PAGEVEC_SIZE - pagevec_count(&pvec));
161
162		if (!nr_pages)
163			break;
164
165		for (loop = 0; loop < nr_pages; loop++)
166			ClearPageFsCache(pvec.pages[loop]);
167
168		first = pvec.pages[nr_pages - 1]->index + 1;
169
170		pvec.nr = nr_pages;
171		pagevec_release(&pvec);
172		cond_resched();
173	}
174}
175
176static const struct fscache_cookie_def ceph_fscache_inode_object_def = {
177	.name		= "CEPH.inode",
178	.type		= FSCACHE_COOKIE_TYPE_DATAFILE,
179	.get_key	= ceph_fscache_inode_get_key,
180	.get_attr	= ceph_fscache_inode_get_attr,
181	.get_aux	= ceph_fscache_inode_get_aux,
182	.check_aux	= ceph_fscache_inode_check_aux,
183	.now_uncached	= ceph_fscache_inode_now_uncached,
184};
185
186void ceph_fscache_register_inode_cookie(struct ceph_fs_client* fsc,
187					struct ceph_inode_info* ci)
188{
189	struct inode* inode = &ci->vfs_inode;
 
190
191	/* No caching for filesystem */
192	if (fsc->fscache == NULL)
193		return;
194
195	/* Only cache for regular files that are read only */
196	if ((ci->vfs_inode.i_mode & S_IFREG) == 0)
197		return;
198
199	/* Avoid multiple racing open requests */
200	mutex_lock(&inode->i_mutex);
201
202	if (ci->fscache)
203		goto done;
204
205	ci->fscache = fscache_acquire_cookie(fsc->fscache,
206					     &ceph_fscache_inode_object_def,
207					     ci, true);
208	fscache_check_consistency(ci->fscache);
209done:
210	mutex_unlock(&inode->i_mutex);
211
212}
213
214void ceph_fscache_unregister_inode_cookie(struct ceph_inode_info* ci)
215{
216	struct fscache_cookie* cookie;
217
218	if ((cookie = ci->fscache) == NULL)
219		return;
220
221	ci->fscache = NULL;
222
223	fscache_uncache_all_inode_pages(cookie, &ci->vfs_inode);
224	fscache_relinquish_cookie(cookie, 0);
225}
226
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
227static void ceph_vfs_readpage_complete(struct page *page, void *data, int error)
228{
229	if (!error)
230		SetPageUptodate(page);
231}
232
233static void ceph_vfs_readpage_complete_unlock(struct page *page, void *data, int error)
234{
235	if (!error)
236		SetPageUptodate(page);
237
238	unlock_page(page);
239}
240
241static inline int cache_valid(struct ceph_inode_info *ci)
242{
243	return ((ceph_caps_issued(ci) & CEPH_CAP_FILE_CACHE) &&
244		(ci->i_fscache_gen == ci->i_rdcache_gen));
245}
246
247
248/* Atempt to read from the fscache,
249 *
250 * This function is called from the readpage_nounlock context. DO NOT attempt to
251 * unlock the page here (or in the callback).
252 */
253int ceph_readpage_from_fscache(struct inode *inode, struct page *page)
254{
255	struct ceph_inode_info *ci = ceph_inode(inode);
256	int ret;
257
258	if (!cache_valid(ci))
259		return -ENOBUFS;
260
261	ret = fscache_read_or_alloc_page(ci->fscache, page,
262					 ceph_vfs_readpage_complete, NULL,
263					 GFP_KERNEL);
264
265	switch (ret) {
266		case 0: /* Page found */
267			dout("page read submitted\n");
268			return 0;
269		case -ENOBUFS: /* Pages were not found, and can't be */
270		case -ENODATA: /* Pages were not found */
271			dout("page/inode not in cache\n");
272			return ret;
273		default:
274			dout("%s: unknown error ret = %i\n", __func__, ret);
275			return ret;
276	}
277}
278
279int ceph_readpages_from_fscache(struct inode *inode,
280				  struct address_space *mapping,
281				  struct list_head *pages,
282				  unsigned *nr_pages)
283{
284	struct ceph_inode_info *ci = ceph_inode(inode);
285	int ret;
286
287	if (!cache_valid(ci))
288		return -ENOBUFS;
289
290	ret = fscache_read_or_alloc_pages(ci->fscache, mapping, pages, nr_pages,
291					  ceph_vfs_readpage_complete_unlock,
292					  NULL, mapping_gfp_mask(mapping));
293
294	switch (ret) {
295		case 0: /* All pages found */
296			dout("all-page read submitted\n");
297			return 0;
298		case -ENOBUFS: /* Some pages were not found, and can't be */
299		case -ENODATA: /* some pages were not found */
300			dout("page/inode not in cache\n");
301			return ret;
302		default:
303			dout("%s: unknown error ret = %i\n", __func__, ret);
304			return ret;
305	}
306}
307
308void ceph_readpage_to_fscache(struct inode *inode, struct page *page)
309{
310	struct ceph_inode_info *ci = ceph_inode(inode);
311	int ret;
312
313	if (!PageFsCache(page))
314		return;
315
316	if (!cache_valid(ci))
317		return;
318
319	ret = fscache_write_page(ci->fscache, page, GFP_KERNEL);
320	if (ret)
321		 fscache_uncache_page(ci->fscache, page);
322}
323
324void ceph_invalidate_fscache_page(struct inode* inode, struct page *page)
325{
326	struct ceph_inode_info *ci = ceph_inode(inode);
327
328	if (!PageFsCache(page))
329		return;
330
331	fscache_wait_on_page_write(ci->fscache, page);
332	fscache_uncache_page(ci->fscache, page);
333}
334
335void ceph_fscache_unregister_fs(struct ceph_fs_client* fsc)
336{
337	if (fsc->revalidate_wq)
338		destroy_workqueue(fsc->revalidate_wq);
339
340	fscache_relinquish_cookie(fsc->fscache, 0);
341	fsc->fscache = NULL;
342}
343
344static void ceph_revalidate_work(struct work_struct *work)
345{
346	int issued;
347	u32 orig_gen;
348	struct ceph_inode_info *ci = container_of(work, struct ceph_inode_info,
349						  i_revalidate_work);
350	struct inode *inode = &ci->vfs_inode;
351
352	spin_lock(&ci->i_ceph_lock);
353	issued = __ceph_caps_issued(ci, NULL);
354	orig_gen = ci->i_rdcache_gen;
355	spin_unlock(&ci->i_ceph_lock);
356
357	if (!(issued & CEPH_CAP_FILE_CACHE)) {
358		dout("revalidate_work lost cache before validation %p\n",
359		     inode);
360		goto out;
361	}
362
363	if (!fscache_check_consistency(ci->fscache))
364		fscache_invalidate(ci->fscache);
365
366	spin_lock(&ci->i_ceph_lock);
367	/* Update the new valid generation (backwards sanity check too) */
368	if (orig_gen > ci->i_fscache_gen) {
369		ci->i_fscache_gen = orig_gen;
370	}
371	spin_unlock(&ci->i_ceph_lock);
372
373out:
374	iput(&ci->vfs_inode);
375}
376
377void ceph_queue_revalidate(struct inode *inode)
378{
379	struct ceph_fs_client *fsc = ceph_sb_to_client(inode->i_sb);
380	struct ceph_inode_info *ci = ceph_inode(inode);
381
382	if (fsc->revalidate_wq == NULL || ci->fscache == NULL)
383		return;
384
385	ihold(inode);
386
387	if (queue_work(ceph_sb_to_client(inode->i_sb)->revalidate_wq,
388		       &ci->i_revalidate_work)) {
389		dout("ceph_queue_revalidate %p\n", inode);
390	} else {
391		dout("ceph_queue_revalidate %p failed\n)", inode);
392		iput(inode);
 
393	}
394}
395
396void ceph_fscache_inode_init(struct ceph_inode_info *ci)
397{
398	ci->fscache = NULL;
399	/* The first load is verifed cookie open time */
400	ci->i_fscache_gen = 1;
401	INIT_WORK(&ci->i_revalidate_work, ceph_revalidate_work);
402}
v4.10.11
  1/*
  2 * Ceph cache definitions.
  3 *
  4 *  Copyright (C) 2013 by Adfin Solutions, Inc. All Rights Reserved.
  5 *  Written by Milosz Tanski (milosz@adfin.com)
  6 *
  7 *  This program is free software; you can redistribute it and/or modify
  8 *  it under the terms of the GNU General Public License version 2
  9 *  as published by the Free Software Foundation.
 10 *
 11 *  This program is distributed in the hope that it will be useful,
 12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14 *  GNU General Public License for more details.
 15 *
 16 *  You should have received a copy of the GNU General Public License
 17 *  along with this program; if not, write to:
 18 *  Free Software Foundation
 19 *  51 Franklin Street, Fifth Floor
 20 *  Boston, MA  02111-1301  USA
 21 *
 22 */
 23
 24#include "super.h"
 25#include "cache.h"
 26
 27struct ceph_aux_inode {
 28	u64 		version;
 29	struct timespec	mtime;
 30	loff_t          size;
 31};
 32
 33struct fscache_netfs ceph_cache_netfs = {
 34	.name		= "ceph",
 35	.version	= 0,
 36};
 37
 38static uint16_t ceph_fscache_session_get_key(const void *cookie_netfs_data,
 39					     void *buffer, uint16_t maxbuf)
 40{
 41	const struct ceph_fs_client* fsc = cookie_netfs_data;
 42	uint16_t klen;
 43
 44	klen = sizeof(fsc->client->fsid);
 45	if (klen > maxbuf)
 46		return 0;
 47
 48	memcpy(buffer, &fsc->client->fsid, klen);
 49	return klen;
 50}
 51
 52static const struct fscache_cookie_def ceph_fscache_fsid_object_def = {
 53	.name		= "CEPH.fsid",
 54	.type		= FSCACHE_COOKIE_TYPE_INDEX,
 55	.get_key	= ceph_fscache_session_get_key,
 56};
 57
 58int ceph_fscache_register(void)
 59{
 60	return fscache_register_netfs(&ceph_cache_netfs);
 61}
 62
 63void ceph_fscache_unregister(void)
 64{
 65	fscache_unregister_netfs(&ceph_cache_netfs);
 66}
 67
 68int ceph_fscache_register_fs(struct ceph_fs_client* fsc)
 69{
 70	fsc->fscache = fscache_acquire_cookie(ceph_cache_netfs.primary_index,
 71					      &ceph_fscache_fsid_object_def,
 72					      fsc, true);
 73	if (!fsc->fscache)
 74		pr_err("Unable to register fsid: %p fscache cookie\n", fsc);
 
 
 
 
 
 
 
 75
 76	return 0;
 77}
 78
 79static uint16_t ceph_fscache_inode_get_key(const void *cookie_netfs_data,
 80					   void *buffer, uint16_t maxbuf)
 81{
 82	const struct ceph_inode_info* ci = cookie_netfs_data;
 83	uint16_t klen;
 84
 85	/* use ceph virtual inode (id + snapshot) */
 86	klen = sizeof(ci->i_vino);
 87	if (klen > maxbuf)
 88		return 0;
 89
 90	memcpy(buffer, &ci->i_vino, klen);
 91	return klen;
 92}
 93
 94static uint16_t ceph_fscache_inode_get_aux(const void *cookie_netfs_data,
 95					   void *buffer, uint16_t bufmax)
 96{
 97	struct ceph_aux_inode aux;
 98	const struct ceph_inode_info* ci = cookie_netfs_data;
 99	const struct inode* inode = &ci->vfs_inode;
100
101	memset(&aux, 0, sizeof(aux));
102	aux.version = ci->i_version;
103	aux.mtime = inode->i_mtime;
104	aux.size = i_size_read(inode);
105
106	memcpy(buffer, &aux, sizeof(aux));
107
108	return sizeof(aux);
109}
110
111static void ceph_fscache_inode_get_attr(const void *cookie_netfs_data,
112					uint64_t *size)
113{
114	const struct ceph_inode_info* ci = cookie_netfs_data;
115	*size = i_size_read(&ci->vfs_inode);
 
 
116}
117
118static enum fscache_checkaux ceph_fscache_inode_check_aux(
119	void *cookie_netfs_data, const void *data, uint16_t dlen)
120{
121	struct ceph_aux_inode aux;
122	struct ceph_inode_info* ci = cookie_netfs_data;
123	struct inode* inode = &ci->vfs_inode;
124
125	if (dlen != sizeof(aux))
126		return FSCACHE_CHECKAUX_OBSOLETE;
127
128	memset(&aux, 0, sizeof(aux));
129	aux.version = ci->i_version;
130	aux.mtime = inode->i_mtime;
131	aux.size = i_size_read(inode);
132
133	if (memcmp(data, &aux, sizeof(aux)) != 0)
134		return FSCACHE_CHECKAUX_OBSOLETE;
135
136	dout("ceph inode 0x%p cached okay", ci);
137	return FSCACHE_CHECKAUX_OKAY;
138}
139
140static void ceph_fscache_inode_now_uncached(void* cookie_netfs_data)
141{
142	struct ceph_inode_info* ci = cookie_netfs_data;
143	struct pagevec pvec;
144	pgoff_t first;
145	int loop, nr_pages;
146
147	pagevec_init(&pvec, 0);
148	first = 0;
149
150	dout("ceph inode 0x%p now uncached", ci);
151
152	while (1) {
153		nr_pages = pagevec_lookup(&pvec, ci->vfs_inode.i_mapping, first,
154					  PAGEVEC_SIZE - pagevec_count(&pvec));
155
156		if (!nr_pages)
157			break;
158
159		for (loop = 0; loop < nr_pages; loop++)
160			ClearPageFsCache(pvec.pages[loop]);
161
162		first = pvec.pages[nr_pages - 1]->index + 1;
163
164		pvec.nr = nr_pages;
165		pagevec_release(&pvec);
166		cond_resched();
167	}
168}
169
170static const struct fscache_cookie_def ceph_fscache_inode_object_def = {
171	.name		= "CEPH.inode",
172	.type		= FSCACHE_COOKIE_TYPE_DATAFILE,
173	.get_key	= ceph_fscache_inode_get_key,
174	.get_attr	= ceph_fscache_inode_get_attr,
175	.get_aux	= ceph_fscache_inode_get_aux,
176	.check_aux	= ceph_fscache_inode_check_aux,
177	.now_uncached	= ceph_fscache_inode_now_uncached,
178};
179
180void ceph_fscache_register_inode_cookie(struct inode *inode)
 
181{
182	struct ceph_inode_info *ci = ceph_inode(inode);
183	struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
184
185	/* No caching for filesystem */
186	if (fsc->fscache == NULL)
187		return;
188
189	/* Only cache for regular files that are read only */
190	if (!S_ISREG(inode->i_mode))
191		return;
192
193	inode_lock_nested(inode, I_MUTEX_CHILD);
194	if (!ci->fscache) {
195		ci->fscache = fscache_acquire_cookie(fsc->fscache,
196					&ceph_fscache_inode_object_def,
197					ci, false);
198	}
199	inode_unlock(inode);
 
 
 
 
 
 
200}
201
202void ceph_fscache_unregister_inode_cookie(struct ceph_inode_info* ci)
203{
204	struct fscache_cookie* cookie;
205
206	if ((cookie = ci->fscache) == NULL)
207		return;
208
209	ci->fscache = NULL;
210
211	fscache_uncache_all_inode_pages(cookie, &ci->vfs_inode);
212	fscache_relinquish_cookie(cookie, 0);
213}
214
215static bool ceph_fscache_can_enable(void *data)
216{
217	struct inode *inode = data;
218	return !inode_is_open_for_write(inode);
219}
220
221void ceph_fscache_file_set_cookie(struct inode *inode, struct file *filp)
222{
223	struct ceph_inode_info *ci = ceph_inode(inode);
224
225	if (!fscache_cookie_valid(ci->fscache))
226		return;
227
228	if (inode_is_open_for_write(inode)) {
229		dout("fscache_file_set_cookie %p %p disabling cache\n",
230		     inode, filp);
231		fscache_disable_cookie(ci->fscache, false);
232		fscache_uncache_all_inode_pages(ci->fscache, inode);
233	} else {
234		fscache_enable_cookie(ci->fscache, ceph_fscache_can_enable,
235				inode);
236		if (fscache_cookie_enabled(ci->fscache)) {
237			dout("fscache_file_set_cookie %p %p enabing cache\n",
238			     inode, filp);
239		}
240	}
241}
242
243static void ceph_vfs_readpage_complete(struct page *page, void *data, int error)
244{
245	if (!error)
246		SetPageUptodate(page);
247}
248
249static void ceph_vfs_readpage_complete_unlock(struct page *page, void *data, int error)
250{
251	if (!error)
252		SetPageUptodate(page);
253
254	unlock_page(page);
255}
256
257static inline bool cache_valid(struct ceph_inode_info *ci)
258{
259	return ci->i_fscache_gen == ci->i_rdcache_gen;
 
260}
261
262
263/* Atempt to read from the fscache,
264 *
265 * This function is called from the readpage_nounlock context. DO NOT attempt to
266 * unlock the page here (or in the callback).
267 */
268int ceph_readpage_from_fscache(struct inode *inode, struct page *page)
269{
270	struct ceph_inode_info *ci = ceph_inode(inode);
271	int ret;
272
273	if (!cache_valid(ci))
274		return -ENOBUFS;
275
276	ret = fscache_read_or_alloc_page(ci->fscache, page,
277					 ceph_vfs_readpage_complete, NULL,
278					 GFP_KERNEL);
279
280	switch (ret) {
281		case 0: /* Page found */
282			dout("page read submitted\n");
283			return 0;
284		case -ENOBUFS: /* Pages were not found, and can't be */
285		case -ENODATA: /* Pages were not found */
286			dout("page/inode not in cache\n");
287			return ret;
288		default:
289			dout("%s: unknown error ret = %i\n", __func__, ret);
290			return ret;
291	}
292}
293
294int ceph_readpages_from_fscache(struct inode *inode,
295				  struct address_space *mapping,
296				  struct list_head *pages,
297				  unsigned *nr_pages)
298{
299	struct ceph_inode_info *ci = ceph_inode(inode);
300	int ret;
301
302	if (!cache_valid(ci))
303		return -ENOBUFS;
304
305	ret = fscache_read_or_alloc_pages(ci->fscache, mapping, pages, nr_pages,
306					  ceph_vfs_readpage_complete_unlock,
307					  NULL, mapping_gfp_mask(mapping));
308
309	switch (ret) {
310		case 0: /* All pages found */
311			dout("all-page read submitted\n");
312			return 0;
313		case -ENOBUFS: /* Some pages were not found, and can't be */
314		case -ENODATA: /* some pages were not found */
315			dout("page/inode not in cache\n");
316			return ret;
317		default:
318			dout("%s: unknown error ret = %i\n", __func__, ret);
319			return ret;
320	}
321}
322
323void ceph_readpage_to_fscache(struct inode *inode, struct page *page)
324{
325	struct ceph_inode_info *ci = ceph_inode(inode);
326	int ret;
327
328	if (!PageFsCache(page))
329		return;
330
331	if (!cache_valid(ci))
332		return;
333
334	ret = fscache_write_page(ci->fscache, page, GFP_KERNEL);
335	if (ret)
336		 fscache_uncache_page(ci->fscache, page);
337}
338
339void ceph_invalidate_fscache_page(struct inode* inode, struct page *page)
340{
341	struct ceph_inode_info *ci = ceph_inode(inode);
342
343	if (!PageFsCache(page))
344		return;
345
346	fscache_wait_on_page_write(ci->fscache, page);
347	fscache_uncache_page(ci->fscache, page);
348}
349
350void ceph_fscache_unregister_fs(struct ceph_fs_client* fsc)
351{
 
 
 
352	fscache_relinquish_cookie(fsc->fscache, 0);
353	fsc->fscache = NULL;
354}
355
356/*
357 * caller should hold CEPH_CAP_FILE_{RD,CACHE}
358 */
359void ceph_fscache_revalidate_cookie(struct ceph_inode_info *ci)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
360{
361	if (cache_valid(ci))
 
 
 
362		return;
363
364	/* resue i_truncate_mutex. There should be no pending
365	 * truncate while the caller holds CEPH_CAP_FILE_RD */
366	mutex_lock(&ci->i_truncate_mutex);
367	if (!cache_valid(ci)) {
368		if (fscache_check_consistency(ci->fscache))
369			fscache_invalidate(ci->fscache);
370		spin_lock(&ci->i_ceph_lock);
371		ci->i_fscache_gen = ci->i_rdcache_gen;
372		spin_unlock(&ci->i_ceph_lock);
373	}
374	mutex_unlock(&ci->i_truncate_mutex);
 
 
 
 
 
 
 
375}