Suresh Jayaraman | 488f1d2d | 2010-07-05 18:12:15 +0530 | [diff] [blame] | 1 | /* |
| 2 | * fs/cifs/fscache.c - CIFS filesystem cache interface |
| 3 | * |
| 4 | * Copyright (c) 2010 Novell, Inc. |
Suresh Jayaraman | b81209d | 2010-11-24 17:49:06 +0530 | [diff] [blame] | 5 | * Author(s): Suresh Jayaraman <sjayaraman@suse.de> |
Suresh Jayaraman | 488f1d2d | 2010-07-05 18:12:15 +0530 | [diff] [blame] | 6 | * |
| 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. |
| 11 | * |
| 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. |
| 16 | * |
| 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 |
| 20 | */ |
| 21 | #include "fscache.h" |
| 22 | #include "cifsglob.h" |
| 23 | #include "cifs_debug.h" |
Suresh Jayaraman | 9451a9a | 2010-07-05 18:12:45 +0530 | [diff] [blame] | 24 | #include "cifs_fs_sb.h" |
Samuel Cabrero | e73a42e | 2020-11-30 19:02:48 +0100 | [diff] [blame] | 25 | #include "cifsproto.h" |
Suresh Jayaraman | 488f1d2d | 2010-07-05 18:12:15 +0530 | [diff] [blame] | 26 | |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 27 | /* |
| 28 | * Key layout of CIFS server cache index object |
| 29 | */ |
| 30 | struct cifs_server_key { |
| 31 | struct { |
| 32 | uint16_t family; /* address family */ |
| 33 | __be16 port; /* IP port */ |
| 34 | } hdr; |
| 35 | union { |
| 36 | struct in_addr ipv4_addr; |
| 37 | struct in6_addr ipv6_addr; |
| 38 | }; |
| 39 | } __packed; |
| 40 | |
| 41 | /* |
| 42 | * Get a cookie for a server object keyed by {IPaddress,port,family} tuple |
| 43 | */ |
Suresh Jayaraman | 488f1d2d | 2010-07-05 18:12:15 +0530 | [diff] [blame] | 44 | void cifs_fscache_get_client_cookie(struct TCP_Server_Info *server) |
| 45 | { |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 46 | const struct sockaddr *sa = (struct sockaddr *) &server->dstaddr; |
| 47 | const struct sockaddr_in *addr = (struct sockaddr_in *) sa; |
| 48 | const struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *) sa; |
| 49 | struct cifs_server_key key; |
| 50 | uint16_t key_len = sizeof(key.hdr); |
| 51 | |
| 52 | memset(&key, 0, sizeof(key)); |
| 53 | |
| 54 | /* |
| 55 | * Should not be a problem as sin_family/sin6_family overlays |
| 56 | * sa_family field |
| 57 | */ |
| 58 | key.hdr.family = sa->sa_family; |
| 59 | switch (sa->sa_family) { |
| 60 | case AF_INET: |
| 61 | key.hdr.port = addr->sin_port; |
| 62 | key.ipv4_addr = addr->sin_addr; |
| 63 | key_len += sizeof(key.ipv4_addr); |
| 64 | break; |
| 65 | |
| 66 | case AF_INET6: |
| 67 | key.hdr.port = addr6->sin6_port; |
| 68 | key.ipv6_addr = addr6->sin6_addr; |
| 69 | key_len += sizeof(key.ipv6_addr); |
| 70 | break; |
| 71 | |
| 72 | default: |
| 73 | cifs_dbg(VFS, "Unknown network family '%d'\n", sa->sa_family); |
| 74 | server->fscache = NULL; |
| 75 | return; |
| 76 | } |
| 77 | |
Suresh Jayaraman | 488f1d2d | 2010-07-05 18:12:15 +0530 | [diff] [blame] | 78 | server->fscache = |
| 79 | fscache_acquire_cookie(cifs_fscache_netfs.primary_index, |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 80 | &cifs_fscache_server_index_def, |
| 81 | &key, key_len, |
| 82 | NULL, 0, |
David Howells | ee1235a | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 83 | server, 0, true); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 84 | cifs_dbg(FYI, "%s: (0x%p/0x%p)\n", |
| 85 | __func__, server, server->fscache); |
Suresh Jayaraman | 488f1d2d | 2010-07-05 18:12:15 +0530 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | void cifs_fscache_release_client_cookie(struct TCP_Server_Info *server) |
| 89 | { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 90 | cifs_dbg(FYI, "%s: (0x%p/0x%p)\n", |
| 91 | __func__, server, server->fscache); |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 92 | fscache_relinquish_cookie(server->fscache, NULL, false); |
Suresh Jayaraman | 488f1d2d | 2010-07-05 18:12:15 +0530 | [diff] [blame] | 93 | server->fscache = NULL; |
| 94 | } |
| 95 | |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 96 | void cifs_fscache_get_super_cookie(struct cifs_tcon *tcon) |
Suresh Jayaraman | d03382c | 2010-07-05 18:12:27 +0530 | [diff] [blame] | 97 | { |
| 98 | struct TCP_Server_Info *server = tcon->ses->server; |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 99 | char *sharename; |
Steve French | 5865985 | 2020-06-05 17:19:46 -0500 | [diff] [blame] | 100 | struct cifs_fscache_super_auxdata auxdata; |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 101 | |
| 102 | sharename = extract_sharename(tcon->treeName); |
| 103 | if (IS_ERR(sharename)) { |
| 104 | cifs_dbg(FYI, "%s: couldn't extract sharename\n", __func__); |
| 105 | tcon->fscache = NULL; |
| 106 | return; |
| 107 | } |
Suresh Jayaraman | d03382c | 2010-07-05 18:12:27 +0530 | [diff] [blame] | 108 | |
Steve French | 5865985 | 2020-06-05 17:19:46 -0500 | [diff] [blame] | 109 | memset(&auxdata, 0, sizeof(auxdata)); |
| 110 | auxdata.resource_id = tcon->resource_id; |
| 111 | auxdata.vol_create_time = tcon->vol_create_time; |
| 112 | auxdata.vol_serial_number = tcon->vol_serial_number; |
| 113 | |
Suresh Jayaraman | d03382c | 2010-07-05 18:12:27 +0530 | [diff] [blame] | 114 | tcon->fscache = |
| 115 | fscache_acquire_cookie(server->fscache, |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 116 | &cifs_fscache_super_index_def, |
| 117 | sharename, strlen(sharename), |
Steve French | 5865985 | 2020-06-05 17:19:46 -0500 | [diff] [blame] | 118 | &auxdata, sizeof(auxdata), |
David Howells | ee1235a | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 119 | tcon, 0, true); |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 120 | kfree(sharename); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 121 | cifs_dbg(FYI, "%s: (0x%p/0x%p)\n", |
| 122 | __func__, server->fscache, tcon->fscache); |
Suresh Jayaraman | d03382c | 2010-07-05 18:12:27 +0530 | [diff] [blame] | 123 | } |
| 124 | |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 125 | void cifs_fscache_release_super_cookie(struct cifs_tcon *tcon) |
Suresh Jayaraman | d03382c | 2010-07-05 18:12:27 +0530 | [diff] [blame] | 126 | { |
Steve French | 5865985 | 2020-06-05 17:19:46 -0500 | [diff] [blame] | 127 | struct cifs_fscache_super_auxdata auxdata; |
| 128 | |
| 129 | memset(&auxdata, 0, sizeof(auxdata)); |
| 130 | auxdata.resource_id = tcon->resource_id; |
| 131 | auxdata.vol_create_time = tcon->vol_create_time; |
| 132 | auxdata.vol_serial_number = tcon->vol_serial_number; |
| 133 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 134 | cifs_dbg(FYI, "%s: (0x%p)\n", __func__, tcon->fscache); |
Steve French | 5865985 | 2020-06-05 17:19:46 -0500 | [diff] [blame] | 135 | fscache_relinquish_cookie(tcon->fscache, &auxdata, false); |
Suresh Jayaraman | d03382c | 2010-07-05 18:12:27 +0530 | [diff] [blame] | 136 | tcon->fscache = NULL; |
| 137 | } |
Suresh Jayaraman | 9451a9a | 2010-07-05 18:12:45 +0530 | [diff] [blame] | 138 | |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 139 | static void cifs_fscache_acquire_inode_cookie(struct cifsInodeInfo *cifsi, |
| 140 | struct cifs_tcon *tcon) |
| 141 | { |
| 142 | struct cifs_fscache_inode_auxdata auxdata; |
| 143 | |
| 144 | memset(&auxdata, 0, sizeof(auxdata)); |
| 145 | auxdata.eof = cifsi->server_eof; |
Arnd Bergmann | cbedead | 2018-06-19 17:27:59 +0200 | [diff] [blame] | 146 | auxdata.last_write_time_sec = cifsi->vfs_inode.i_mtime.tv_sec; |
| 147 | auxdata.last_change_time_sec = cifsi->vfs_inode.i_ctime.tv_sec; |
| 148 | auxdata.last_write_time_nsec = cifsi->vfs_inode.i_mtime.tv_nsec; |
| 149 | auxdata.last_change_time_nsec = cifsi->vfs_inode.i_ctime.tv_nsec; |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 150 | |
| 151 | cifsi->fscache = |
| 152 | fscache_acquire_cookie(tcon->fscache, |
| 153 | &cifs_fscache_inode_object_def, |
| 154 | &cifsi->uniqueid, sizeof(cifsi->uniqueid), |
| 155 | &auxdata, sizeof(auxdata), |
David Howells | ee1235a | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 156 | cifsi, cifsi->vfs_inode.i_size, true); |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 157 | } |
| 158 | |
Suresh Jayaraman | 9451a9a | 2010-07-05 18:12:45 +0530 | [diff] [blame] | 159 | static void cifs_fscache_enable_inode_cookie(struct inode *inode) |
| 160 | { |
| 161 | struct cifsInodeInfo *cifsi = CIFS_I(inode); |
| 162 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 163 | struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb); |
Suresh Jayaraman | 9451a9a | 2010-07-05 18:12:45 +0530 | [diff] [blame] | 164 | |
| 165 | if (cifsi->fscache) |
| 166 | return; |
| 167 | |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 168 | if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_FSCACHE)) |
| 169 | return; |
| 170 | |
| 171 | cifs_fscache_acquire_inode_cookie(cifsi, tcon); |
| 172 | |
| 173 | cifs_dbg(FYI, "%s: got FH cookie (0x%p/0x%p)\n", |
| 174 | __func__, tcon->fscache, cifsi->fscache); |
Suresh Jayaraman | 9451a9a | 2010-07-05 18:12:45 +0530 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | void cifs_fscache_release_inode_cookie(struct inode *inode) |
| 178 | { |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 179 | struct cifs_fscache_inode_auxdata auxdata; |
Suresh Jayaraman | 9451a9a | 2010-07-05 18:12:45 +0530 | [diff] [blame] | 180 | struct cifsInodeInfo *cifsi = CIFS_I(inode); |
| 181 | |
| 182 | if (cifsi->fscache) { |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 183 | memset(&auxdata, 0, sizeof(auxdata)); |
| 184 | auxdata.eof = cifsi->server_eof; |
Arnd Bergmann | cbedead | 2018-06-19 17:27:59 +0200 | [diff] [blame] | 185 | auxdata.last_write_time_sec = cifsi->vfs_inode.i_mtime.tv_sec; |
| 186 | auxdata.last_change_time_sec = cifsi->vfs_inode.i_ctime.tv_sec; |
| 187 | auxdata.last_write_time_nsec = cifsi->vfs_inode.i_mtime.tv_nsec; |
| 188 | auxdata.last_change_time_nsec = cifsi->vfs_inode.i_ctime.tv_nsec; |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 189 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 190 | cifs_dbg(FYI, "%s: (0x%p)\n", __func__, cifsi->fscache); |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 191 | fscache_relinquish_cookie(cifsi->fscache, &auxdata, false); |
Suresh Jayaraman | 9451a9a | 2010-07-05 18:12:45 +0530 | [diff] [blame] | 192 | cifsi->fscache = NULL; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | static void cifs_fscache_disable_inode_cookie(struct inode *inode) |
| 197 | { |
| 198 | struct cifsInodeInfo *cifsi = CIFS_I(inode); |
| 199 | |
| 200 | if (cifsi->fscache) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 201 | cifs_dbg(FYI, "%s: (0x%p)\n", __func__, cifsi->fscache); |
David Howells | c902ce1 | 2011-07-07 12:19:48 +0100 | [diff] [blame] | 202 | fscache_uncache_all_inode_pages(cifsi->fscache, inode); |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 203 | fscache_relinquish_cookie(cifsi->fscache, NULL, true); |
Suresh Jayaraman | 9451a9a | 2010-07-05 18:12:45 +0530 | [diff] [blame] | 204 | cifsi->fscache = NULL; |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | void cifs_fscache_set_inode_cookie(struct inode *inode, struct file *filp) |
| 209 | { |
| 210 | if ((filp->f_flags & O_ACCMODE) != O_RDONLY) |
| 211 | cifs_fscache_disable_inode_cookie(inode); |
Suresh Jayaraman | b81209d | 2010-11-24 17:49:06 +0530 | [diff] [blame] | 212 | else |
Suresh Jayaraman | 9451a9a | 2010-07-05 18:12:45 +0530 | [diff] [blame] | 213 | cifs_fscache_enable_inode_cookie(inode); |
Suresh Jayaraman | 9451a9a | 2010-07-05 18:12:45 +0530 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | void cifs_fscache_reset_inode_cookie(struct inode *inode) |
| 217 | { |
| 218 | struct cifsInodeInfo *cifsi = CIFS_I(inode); |
| 219 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 220 | struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb); |
Suresh Jayaraman | 9451a9a | 2010-07-05 18:12:45 +0530 | [diff] [blame] | 221 | struct fscache_cookie *old = cifsi->fscache; |
| 222 | |
| 223 | if (cifsi->fscache) { |
| 224 | /* retire the current fscache cache and get a new one */ |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 225 | fscache_relinquish_cookie(cifsi->fscache, NULL, true); |
Suresh Jayaraman | 9451a9a | 2010-07-05 18:12:45 +0530 | [diff] [blame] | 226 | |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 227 | cifs_fscache_acquire_inode_cookie(cifsi, tcon); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 228 | cifs_dbg(FYI, "%s: new cookie 0x%p oldcookie 0x%p\n", |
| 229 | __func__, cifsi->fscache, old); |
Suresh Jayaraman | 9451a9a | 2010-07-05 18:12:45 +0530 | [diff] [blame] | 230 | } |
| 231 | } |
Suresh Jayaraman | 85f2d6b | 2010-07-05 18:13:00 +0530 | [diff] [blame] | 232 | |
| 233 | int cifs_fscache_release_page(struct page *page, gfp_t gfp) |
| 234 | { |
| 235 | if (PageFsCache(page)) { |
| 236 | struct inode *inode = page->mapping->host; |
| 237 | struct cifsInodeInfo *cifsi = CIFS_I(inode); |
| 238 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 239 | cifs_dbg(FYI, "%s: (0x%p/0x%p)\n", |
| 240 | __func__, page, cifsi->fscache); |
Suresh Jayaraman | 85f2d6b | 2010-07-05 18:13:00 +0530 | [diff] [blame] | 241 | if (!fscache_maybe_release_page(cifsi->fscache, page, gfp)) |
| 242 | return 0; |
| 243 | } |
| 244 | |
| 245 | return 1; |
| 246 | } |
| 247 | |
Suresh Jayaraman | 56698236 | 2010-07-05 18:13:25 +0530 | [diff] [blame] | 248 | static void cifs_readpage_from_fscache_complete(struct page *page, void *ctx, |
| 249 | int error) |
| 250 | { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 251 | cifs_dbg(FYI, "%s: (0x%p/%d)\n", __func__, page, error); |
Suresh Jayaraman | 56698236 | 2010-07-05 18:13:25 +0530 | [diff] [blame] | 252 | if (!error) |
| 253 | SetPageUptodate(page); |
| 254 | unlock_page(page); |
| 255 | } |
| 256 | |
| 257 | /* |
| 258 | * Retrieve a page from FS-Cache |
| 259 | */ |
| 260 | int __cifs_readpage_from_fscache(struct inode *inode, struct page *page) |
| 261 | { |
| 262 | int ret; |
| 263 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 264 | cifs_dbg(FYI, "%s: (fsc:%p, p:%p, i:0x%p\n", |
| 265 | __func__, CIFS_I(inode)->fscache, page, inode); |
Suresh Jayaraman | 56698236 | 2010-07-05 18:13:25 +0530 | [diff] [blame] | 266 | ret = fscache_read_or_alloc_page(CIFS_I(inode)->fscache, page, |
| 267 | cifs_readpage_from_fscache_complete, |
| 268 | NULL, |
| 269 | GFP_KERNEL); |
| 270 | switch (ret) { |
| 271 | |
| 272 | case 0: /* page found in fscache, read submitted */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 273 | cifs_dbg(FYI, "%s: submitted\n", __func__); |
Suresh Jayaraman | 56698236 | 2010-07-05 18:13:25 +0530 | [diff] [blame] | 274 | return ret; |
| 275 | case -ENOBUFS: /* page won't be cached */ |
| 276 | case -ENODATA: /* page not in cache */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 277 | cifs_dbg(FYI, "%s: %d\n", __func__, ret); |
Suresh Jayaraman | 56698236 | 2010-07-05 18:13:25 +0530 | [diff] [blame] | 278 | return 1; |
| 279 | |
| 280 | default: |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 281 | cifs_dbg(VFS, "unknown error ret = %d\n", ret); |
Suresh Jayaraman | 56698236 | 2010-07-05 18:13:25 +0530 | [diff] [blame] | 282 | } |
| 283 | return ret; |
| 284 | } |
| 285 | |
| 286 | /* |
| 287 | * Retrieve a set of pages from FS-Cache |
| 288 | */ |
| 289 | int __cifs_readpages_from_fscache(struct inode *inode, |
| 290 | struct address_space *mapping, |
| 291 | struct list_head *pages, |
| 292 | unsigned *nr_pages) |
| 293 | { |
| 294 | int ret; |
| 295 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 296 | cifs_dbg(FYI, "%s: (0x%p/%u/0x%p)\n", |
| 297 | __func__, CIFS_I(inode)->fscache, *nr_pages, inode); |
Suresh Jayaraman | 56698236 | 2010-07-05 18:13:25 +0530 | [diff] [blame] | 298 | ret = fscache_read_or_alloc_pages(CIFS_I(inode)->fscache, mapping, |
| 299 | pages, nr_pages, |
| 300 | cifs_readpage_from_fscache_complete, |
| 301 | NULL, |
| 302 | mapping_gfp_mask(mapping)); |
| 303 | switch (ret) { |
| 304 | case 0: /* read submitted to the cache for all pages */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 305 | cifs_dbg(FYI, "%s: submitted\n", __func__); |
Suresh Jayaraman | 56698236 | 2010-07-05 18:13:25 +0530 | [diff] [blame] | 306 | return ret; |
| 307 | |
| 308 | case -ENOBUFS: /* some pages are not cached and can't be */ |
| 309 | case -ENODATA: /* some pages are not cached */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 310 | cifs_dbg(FYI, "%s: no page\n", __func__); |
Suresh Jayaraman | 56698236 | 2010-07-05 18:13:25 +0530 | [diff] [blame] | 311 | return 1; |
| 312 | |
| 313 | default: |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 314 | cifs_dbg(FYI, "unknown error ret = %d\n", ret); |
Suresh Jayaraman | 56698236 | 2010-07-05 18:13:25 +0530 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | return ret; |
| 318 | } |
| 319 | |
Suresh Jayaraman | 9dc0655 | 2010-07-05 18:13:11 +0530 | [diff] [blame] | 320 | void __cifs_readpage_to_fscache(struct inode *inode, struct page *page) |
| 321 | { |
David Howells | ee1235a | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 322 | struct cifsInodeInfo *cifsi = CIFS_I(inode); |
Suresh Jayaraman | 9dc0655 | 2010-07-05 18:13:11 +0530 | [diff] [blame] | 323 | int ret; |
| 324 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 325 | cifs_dbg(FYI, "%s: (fsc: %p, p: %p, i: %p)\n", |
David Howells | ee1235a | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 326 | __func__, cifsi->fscache, page, inode); |
| 327 | ret = fscache_write_page(cifsi->fscache, page, |
| 328 | cifsi->vfs_inode.i_size, GFP_KERNEL); |
Suresh Jayaraman | 9dc0655 | 2010-07-05 18:13:11 +0530 | [diff] [blame] | 329 | if (ret != 0) |
David Howells | ee1235a | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 330 | fscache_uncache_page(cifsi->fscache, page); |
Suresh Jayaraman | 9dc0655 | 2010-07-05 18:13:11 +0530 | [diff] [blame] | 331 | } |
| 332 | |
David Howells | 54afa99 | 2013-09-04 17:10:39 +0000 | [diff] [blame] | 333 | void __cifs_fscache_readpages_cancel(struct inode *inode, struct list_head *pages) |
| 334 | { |
| 335 | cifs_dbg(FYI, "%s: (fsc: %p, i: %p)\n", |
| 336 | __func__, CIFS_I(inode)->fscache, inode); |
| 337 | fscache_readpages_cancel(CIFS_I(inode)->fscache, pages); |
| 338 | } |
| 339 | |
Suresh Jayaraman | 85f2d6b | 2010-07-05 18:13:00 +0530 | [diff] [blame] | 340 | void __cifs_fscache_invalidate_page(struct page *page, struct inode *inode) |
| 341 | { |
| 342 | struct cifsInodeInfo *cifsi = CIFS_I(inode); |
| 343 | struct fscache_cookie *cookie = cifsi->fscache; |
| 344 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 345 | cifs_dbg(FYI, "%s: (0x%p/0x%p)\n", __func__, page, cookie); |
Suresh Jayaraman | 85f2d6b | 2010-07-05 18:13:00 +0530 | [diff] [blame] | 346 | fscache_wait_on_page_write(cookie, page); |
| 347 | fscache_uncache_page(cookie, page); |
| 348 | } |