2 * fs/cifs/fscache.c - CIFS filesystem cache interface
4 * Copyright (c) 2010 Novell, Inc.
5 * Author(s): Suresh Jayaraman (sjayaraman@suse.de>
7 * This library is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published
9 * by the Free Software Foundation; either version 2.1 of the License, or
10 * (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
15 * the GNU Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "cifs_debug.h"
24 #include "cifs_fs_sb.h"
26 void cifs_fscache_get_client_cookie(struct TCP_Server_Info
*server
)
29 fscache_acquire_cookie(cifs_fscache_netfs
.primary_index
,
30 &cifs_fscache_server_index_def
, server
);
31 cFYI(1, "CIFS: get client cookie (0x%p/0x%p)", server
,
35 void cifs_fscache_release_client_cookie(struct TCP_Server_Info
*server
)
37 cFYI(1, "CIFS: release client cookie (0x%p/0x%p)", server
,
39 fscache_relinquish_cookie(server
->fscache
, 0);
40 server
->fscache
= NULL
;
43 void cifs_fscache_get_super_cookie(struct cifsTconInfo
*tcon
)
45 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
48 fscache_acquire_cookie(server
->fscache
,
49 &cifs_fscache_super_index_def
, tcon
);
50 cFYI(1, "CIFS: get superblock cookie (0x%p/0x%p)",
51 server
->fscache
, tcon
->fscache
);
54 void cifs_fscache_release_super_cookie(struct cifsTconInfo
*tcon
)
56 cFYI(1, "CIFS: releasing superblock cookie (0x%p)", tcon
->fscache
);
57 fscache_relinquish_cookie(tcon
->fscache
, 0);
61 static void cifs_fscache_enable_inode_cookie(struct inode
*inode
)
63 struct cifsInodeInfo
*cifsi
= CIFS_I(inode
);
64 struct cifs_sb_info
*cifs_sb
= CIFS_SB(inode
->i_sb
);
69 cifsi
->fscache
= fscache_acquire_cookie(cifs_sb
->tcon
->fscache
,
70 &cifs_fscache_inode_object_def
,
72 cFYI(1, "CIFS: got FH cookie (0x%p/0x%p)",
73 cifs_sb
->tcon
->fscache
, cifsi
->fscache
);
76 void cifs_fscache_release_inode_cookie(struct inode
*inode
)
78 struct cifsInodeInfo
*cifsi
= CIFS_I(inode
);
81 cFYI(1, "CIFS releasing inode cookie (0x%p)",
83 fscache_relinquish_cookie(cifsi
->fscache
, 0);
84 cifsi
->fscache
= NULL
;
88 static void cifs_fscache_disable_inode_cookie(struct inode
*inode
)
90 struct cifsInodeInfo
*cifsi
= CIFS_I(inode
);
93 cFYI(1, "CIFS disabling inode cookie (0x%p)",
95 fscache_relinquish_cookie(cifsi
->fscache
, 1);
96 cifsi
->fscache
= NULL
;
100 void cifs_fscache_set_inode_cookie(struct inode
*inode
, struct file
*filp
)
102 if ((filp
->f_flags
& O_ACCMODE
) != O_RDONLY
)
103 cifs_fscache_disable_inode_cookie(inode
);
105 cifs_fscache_enable_inode_cookie(inode
);
106 cFYI(1, "CIFS: fscache inode cookie set");
110 void cifs_fscache_reset_inode_cookie(struct inode
*inode
)
112 struct cifsInodeInfo
*cifsi
= CIFS_I(inode
);
113 struct cifs_sb_info
*cifs_sb
= CIFS_SB(inode
->i_sb
);
114 struct fscache_cookie
*old
= cifsi
->fscache
;
116 if (cifsi
->fscache
) {
117 /* retire the current fscache cache and get a new one */
118 fscache_relinquish_cookie(cifsi
->fscache
, 1);
120 cifsi
->fscache
= fscache_acquire_cookie(cifs_sb
->tcon
->fscache
,
121 &cifs_fscache_inode_object_def
,
123 cFYI(1, "CIFS: new cookie 0x%p oldcookie 0x%p",
124 cifsi
->fscache
, old
);
128 int cifs_fscache_release_page(struct page
*page
, gfp_t gfp
)
130 if (PageFsCache(page
)) {
131 struct inode
*inode
= page
->mapping
->host
;
132 struct cifsInodeInfo
*cifsi
= CIFS_I(inode
);
134 cFYI(1, "CIFS: fscache release page (0x%p/0x%p)",
135 page
, cifsi
->fscache
);
136 if (!fscache_maybe_release_page(cifsi
->fscache
, page
, gfp
))
143 static void cifs_readpage_from_fscache_complete(struct page
*page
, void *ctx
,
146 cFYI(1, "CFS: readpage_from_fscache_complete (0x%p/%d)",
149 SetPageUptodate(page
);
154 * Retrieve a page from FS-Cache
156 int __cifs_readpage_from_fscache(struct inode
*inode
, struct page
*page
)
160 cFYI(1, "CIFS: readpage_from_fscache(fsc:%p, p:%p, i:0x%p",
161 CIFS_I(inode
)->fscache
, page
, inode
);
162 ret
= fscache_read_or_alloc_page(CIFS_I(inode
)->fscache
, page
,
163 cifs_readpage_from_fscache_complete
,
168 case 0: /* page found in fscache, read submitted */
169 cFYI(1, "CIFS: readpage_from_fscache: submitted");
171 case -ENOBUFS
: /* page won't be cached */
172 case -ENODATA
: /* page not in cache */
173 cFYI(1, "CIFS: readpage_from_fscache %d", ret
);
177 cERROR(1, "unknown error ret = %d", ret
);
183 * Retrieve a set of pages from FS-Cache
185 int __cifs_readpages_from_fscache(struct inode
*inode
,
186 struct address_space
*mapping
,
187 struct list_head
*pages
,
192 cFYI(1, "CIFS: __cifs_readpages_from_fscache (0x%p/%u/0x%p)",
193 CIFS_I(inode
)->fscache
, *nr_pages
, inode
);
194 ret
= fscache_read_or_alloc_pages(CIFS_I(inode
)->fscache
, mapping
,
196 cifs_readpage_from_fscache_complete
,
198 mapping_gfp_mask(mapping
));
200 case 0: /* read submitted to the cache for all pages */
201 cFYI(1, "CIFS: readpages_from_fscache: submitted");
204 case -ENOBUFS
: /* some pages are not cached and can't be */
205 case -ENODATA
: /* some pages are not cached */
206 cFYI(1, "CIFS: readpages_from_fscache: no page");
210 cFYI(1, "unknown error ret = %d", ret
);
216 void __cifs_readpage_to_fscache(struct inode
*inode
, struct page
*page
)
220 cFYI(1, "CIFS: readpage_to_fscache(fsc: %p, p: %p, i: %p",
221 CIFS_I(inode
)->fscache
, page
, inode
);
222 ret
= fscache_write_page(CIFS_I(inode
)->fscache
, page
, GFP_KERNEL
);
224 fscache_uncache_page(CIFS_I(inode
)->fscache
, page
);
227 void __cifs_fscache_invalidate_page(struct page
*page
, struct inode
*inode
)
229 struct cifsInodeInfo
*cifsi
= CIFS_I(inode
);
230 struct fscache_cookie
*cookie
= cifsi
->fscache
;
232 cFYI(1, "CIFS: fscache invalidatepage (0x%p/0x%p)", page
, cookie
);
233 fscache_wait_on_page_write(cookie
, page
);
234 fscache_uncache_page(cookie
, page
);