Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 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 | |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 24 | #include "super.h" |
| 25 | #include "cache.h" |
| 26 | |
| 27 | struct ceph_aux_inode { |
Yan, Zheng | f6973c0 | 2016-05-20 16:57:29 +0800 | [diff] [blame] | 28 | u64 version; |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 29 | struct timespec mtime; |
| 30 | loff_t size; |
| 31 | }; |
| 32 | |
| 33 | struct fscache_netfs ceph_cache_netfs = { |
| 34 | .name = "ceph", |
| 35 | .version = 0, |
| 36 | }; |
| 37 | |
Yan, Zheng | 1d8f836 | 2017-06-27 11:57:56 +0800 | [diff] [blame] | 38 | static DEFINE_MUTEX(ceph_fscache_lock); |
| 39 | static LIST_HEAD(ceph_fscache_list); |
| 40 | |
| 41 | struct ceph_fscache_entry { |
| 42 | struct list_head list; |
| 43 | struct fscache_cookie *fscache; |
| 44 | struct ceph_fsid fsid; |
| 45 | size_t uniq_len; |
| 46 | char uniquifier[0]; |
| 47 | }; |
| 48 | |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 49 | static uint16_t ceph_fscache_session_get_key(const void *cookie_netfs_data, |
| 50 | void *buffer, uint16_t maxbuf) |
| 51 | { |
| 52 | const struct ceph_fs_client* fsc = cookie_netfs_data; |
Yan, Zheng | 1d8f836 | 2017-06-27 11:57:56 +0800 | [diff] [blame] | 53 | const char *fscache_uniq = fsc->mount_options->fscache_uniq; |
| 54 | uint16_t fsid_len, uniq_len; |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 55 | |
Yan, Zheng | 1d8f836 | 2017-06-27 11:57:56 +0800 | [diff] [blame] | 56 | fsid_len = sizeof(fsc->client->fsid); |
| 57 | uniq_len = fscache_uniq ? strlen(fscache_uniq) : 0; |
| 58 | if (fsid_len + uniq_len > maxbuf) |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 59 | return 0; |
| 60 | |
Yan, Zheng | 1d8f836 | 2017-06-27 11:57:56 +0800 | [diff] [blame] | 61 | memcpy(buffer, &fsc->client->fsid, fsid_len); |
| 62 | if (uniq_len) |
| 63 | memcpy(buffer + fsid_len, fscache_uniq, uniq_len); |
| 64 | |
| 65 | return fsid_len + uniq_len; |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | static const struct fscache_cookie_def ceph_fscache_fsid_object_def = { |
| 69 | .name = "CEPH.fsid", |
| 70 | .type = FSCACHE_COOKIE_TYPE_INDEX, |
| 71 | .get_key = ceph_fscache_session_get_key, |
| 72 | }; |
| 73 | |
Milosz Tanski | 971f0bd | 2013-09-06 15:13:18 +0000 | [diff] [blame] | 74 | int ceph_fscache_register(void) |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 75 | { |
| 76 | return fscache_register_netfs(&ceph_cache_netfs); |
| 77 | } |
| 78 | |
Milosz Tanski | 971f0bd | 2013-09-06 15:13:18 +0000 | [diff] [blame] | 79 | void ceph_fscache_unregister(void) |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 80 | { |
| 81 | fscache_unregister_netfs(&ceph_cache_netfs); |
| 82 | } |
| 83 | |
| 84 | int ceph_fscache_register_fs(struct ceph_fs_client* fsc) |
| 85 | { |
Yan, Zheng | 1d8f836 | 2017-06-27 11:57:56 +0800 | [diff] [blame] | 86 | const struct ceph_fsid *fsid = &fsc->client->fsid; |
| 87 | const char *fscache_uniq = fsc->mount_options->fscache_uniq; |
| 88 | size_t uniq_len = fscache_uniq ? strlen(fscache_uniq) : 0; |
| 89 | struct ceph_fscache_entry *ent; |
| 90 | int err = 0; |
| 91 | |
| 92 | mutex_lock(&ceph_fscache_lock); |
| 93 | list_for_each_entry(ent, &ceph_fscache_list, list) { |
| 94 | if (memcmp(&ent->fsid, fsid, sizeof(*fsid))) |
| 95 | continue; |
| 96 | if (ent->uniq_len != uniq_len) |
| 97 | continue; |
| 98 | if (uniq_len && memcmp(ent->uniquifier, fscache_uniq, uniq_len)) |
| 99 | continue; |
| 100 | |
| 101 | pr_err("fscache cookie already registered for fsid %pU\n", fsid); |
| 102 | pr_err(" use fsc=%%s mount option to specify a uniquifier\n"); |
| 103 | err = -EBUSY; |
| 104 | goto out_unlock; |
| 105 | } |
| 106 | |
| 107 | ent = kzalloc(sizeof(*ent) + uniq_len, GFP_KERNEL); |
| 108 | if (!ent) { |
| 109 | err = -ENOMEM; |
| 110 | goto out_unlock; |
| 111 | } |
| 112 | |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 113 | fsc->fscache = fscache_acquire_cookie(ceph_cache_netfs.primary_index, |
| 114 | &ceph_fscache_fsid_object_def, |
David Howells | 94d30ae | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 115 | fsc, true); |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 116 | |
Yan, Zheng | 1d8f836 | 2017-06-27 11:57:56 +0800 | [diff] [blame] | 117 | if (fsc->fscache) { |
| 118 | memcpy(&ent->fsid, fsid, sizeof(*fsid)); |
| 119 | if (uniq_len > 0) { |
| 120 | memcpy(&ent->uniquifier, fscache_uniq, uniq_len); |
| 121 | ent->uniq_len = uniq_len; |
| 122 | } |
| 123 | ent->fscache = fsc->fscache; |
| 124 | list_add_tail(&ent->list, &ceph_fscache_list); |
| 125 | } else { |
| 126 | kfree(ent); |
| 127 | pr_err("unable to register fscache cookie for fsid %pU\n", |
| 128 | fsid); |
| 129 | /* all other fs ignore this error */ |
| 130 | } |
| 131 | out_unlock: |
| 132 | mutex_unlock(&ceph_fscache_lock); |
| 133 | return err; |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | static uint16_t ceph_fscache_inode_get_key(const void *cookie_netfs_data, |
| 137 | void *buffer, uint16_t maxbuf) |
| 138 | { |
| 139 | const struct ceph_inode_info* ci = cookie_netfs_data; |
| 140 | uint16_t klen; |
| 141 | |
Geliang Tang | 1291fb9 | 2015-09-30 11:41:05 +0800 | [diff] [blame] | 142 | /* use ceph virtual inode (id + snapshot) */ |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 143 | klen = sizeof(ci->i_vino); |
| 144 | if (klen > maxbuf) |
| 145 | return 0; |
| 146 | |
| 147 | memcpy(buffer, &ci->i_vino, klen); |
| 148 | return klen; |
| 149 | } |
| 150 | |
| 151 | static uint16_t ceph_fscache_inode_get_aux(const void *cookie_netfs_data, |
| 152 | void *buffer, uint16_t bufmax) |
| 153 | { |
| 154 | struct ceph_aux_inode aux; |
| 155 | const struct ceph_inode_info* ci = cookie_netfs_data; |
| 156 | const struct inode* inode = &ci->vfs_inode; |
| 157 | |
| 158 | memset(&aux, 0, sizeof(aux)); |
Yan, Zheng | f6973c0 | 2016-05-20 16:57:29 +0800 | [diff] [blame] | 159 | aux.version = ci->i_version; |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 160 | aux.mtime = inode->i_mtime; |
Yan, Zheng | 99c88e6 | 2015-12-30 11:32:46 +0800 | [diff] [blame] | 161 | aux.size = i_size_read(inode); |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 162 | |
| 163 | memcpy(buffer, &aux, sizeof(aux)); |
| 164 | |
| 165 | return sizeof(aux); |
| 166 | } |
| 167 | |
| 168 | static void ceph_fscache_inode_get_attr(const void *cookie_netfs_data, |
| 169 | uint64_t *size) |
| 170 | { |
| 171 | const struct ceph_inode_info* ci = cookie_netfs_data; |
Yan, Zheng | 99c88e6 | 2015-12-30 11:32:46 +0800 | [diff] [blame] | 172 | *size = i_size_read(&ci->vfs_inode); |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | static enum fscache_checkaux ceph_fscache_inode_check_aux( |
| 176 | void *cookie_netfs_data, const void *data, uint16_t dlen) |
| 177 | { |
| 178 | struct ceph_aux_inode aux; |
| 179 | struct ceph_inode_info* ci = cookie_netfs_data; |
| 180 | struct inode* inode = &ci->vfs_inode; |
| 181 | |
| 182 | if (dlen != sizeof(aux)) |
| 183 | return FSCACHE_CHECKAUX_OBSOLETE; |
| 184 | |
| 185 | memset(&aux, 0, sizeof(aux)); |
Yan, Zheng | f6973c0 | 2016-05-20 16:57:29 +0800 | [diff] [blame] | 186 | aux.version = ci->i_version; |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 187 | aux.mtime = inode->i_mtime; |
Yan, Zheng | 99c88e6 | 2015-12-30 11:32:46 +0800 | [diff] [blame] | 188 | aux.size = i_size_read(inode); |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 189 | |
| 190 | if (memcmp(data, &aux, sizeof(aux)) != 0) |
| 191 | return FSCACHE_CHECKAUX_OBSOLETE; |
| 192 | |
| 193 | dout("ceph inode 0x%p cached okay", ci); |
| 194 | return FSCACHE_CHECKAUX_OKAY; |
| 195 | } |
| 196 | |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 197 | static const struct fscache_cookie_def ceph_fscache_inode_object_def = { |
| 198 | .name = "CEPH.inode", |
| 199 | .type = FSCACHE_COOKIE_TYPE_DATAFILE, |
| 200 | .get_key = ceph_fscache_inode_get_key, |
| 201 | .get_attr = ceph_fscache_inode_get_attr, |
| 202 | .get_aux = ceph_fscache_inode_get_aux, |
| 203 | .check_aux = ceph_fscache_inode_check_aux, |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 204 | }; |
| 205 | |
Yan, Zheng | 46b59b2 | 2016-05-18 15:25:03 +0800 | [diff] [blame] | 206 | void ceph_fscache_register_inode_cookie(struct inode *inode) |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 207 | { |
Yan, Zheng | 46b59b2 | 2016-05-18 15:25:03 +0800 | [diff] [blame] | 208 | struct ceph_inode_info *ci = ceph_inode(inode); |
| 209 | struct ceph_fs_client *fsc = ceph_inode_to_client(inode); |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 210 | |
| 211 | /* No caching for filesystem */ |
Markus Elfring | d37b1d9 | 2017-08-20 20:22:02 +0200 | [diff] [blame] | 212 | if (!fsc->fscache) |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 213 | return; |
| 214 | |
| 215 | /* Only cache for regular files that are read only */ |
Yan, Zheng | 46b59b2 | 2016-05-18 15:25:03 +0800 | [diff] [blame] | 216 | if (!S_ISREG(inode->i_mode)) |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 217 | return; |
| 218 | |
Yan, Zheng | 46b59b2 | 2016-05-18 15:25:03 +0800 | [diff] [blame] | 219 | inode_lock_nested(inode, I_MUTEX_CHILD); |
| 220 | if (!ci->fscache) { |
| 221 | ci->fscache = fscache_acquire_cookie(fsc->fscache, |
| 222 | &ceph_fscache_inode_object_def, |
| 223 | ci, false); |
| 224 | } |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 225 | inode_unlock(inode); |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | void ceph_fscache_unregister_inode_cookie(struct ceph_inode_info* ci) |
| 229 | { |
| 230 | struct fscache_cookie* cookie; |
| 231 | |
| 232 | if ((cookie = ci->fscache) == NULL) |
| 233 | return; |
| 234 | |
| 235 | ci->fscache = NULL; |
| 236 | |
| 237 | fscache_uncache_all_inode_pages(cookie, &ci->vfs_inode); |
| 238 | fscache_relinquish_cookie(cookie, 0); |
| 239 | } |
| 240 | |
Yan, Zheng | 46b59b2 | 2016-05-18 15:25:03 +0800 | [diff] [blame] | 241 | static bool ceph_fscache_can_enable(void *data) |
| 242 | { |
| 243 | struct inode *inode = data; |
| 244 | return !inode_is_open_for_write(inode); |
| 245 | } |
| 246 | |
| 247 | void ceph_fscache_file_set_cookie(struct inode *inode, struct file *filp) |
| 248 | { |
| 249 | struct ceph_inode_info *ci = ceph_inode(inode); |
| 250 | |
| 251 | if (!fscache_cookie_valid(ci->fscache)) |
| 252 | return; |
| 253 | |
| 254 | if (inode_is_open_for_write(inode)) { |
| 255 | dout("fscache_file_set_cookie %p %p disabling cache\n", |
| 256 | inode, filp); |
| 257 | fscache_disable_cookie(ci->fscache, false); |
| 258 | fscache_uncache_all_inode_pages(ci->fscache, inode); |
| 259 | } else { |
| 260 | fscache_enable_cookie(ci->fscache, ceph_fscache_can_enable, |
| 261 | inode); |
| 262 | if (fscache_cookie_enabled(ci->fscache)) { |
Colin Ian King | 0fbc536 | 2016-12-29 20:19:32 +0000 | [diff] [blame] | 263 | dout("fscache_file_set_cookie %p %p enabling cache\n", |
Yan, Zheng | 46b59b2 | 2016-05-18 15:25:03 +0800 | [diff] [blame] | 264 | inode, filp); |
| 265 | } |
| 266 | } |
| 267 | } |
| 268 | |
Yan, Zheng | dd2bc47 | 2017-08-04 11:22:31 +0800 | [diff] [blame] | 269 | static void ceph_readpage_from_fscache_complete(struct page *page, void *data, int error) |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 270 | { |
| 271 | if (!error) |
| 272 | SetPageUptodate(page); |
| 273 | |
| 274 | unlock_page(page); |
| 275 | } |
| 276 | |
Zhang Zhuoyu | 3b33f69 | 2016-03-25 05:18:39 -0400 | [diff] [blame] | 277 | static inline bool cache_valid(struct ceph_inode_info *ci) |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 278 | { |
Yan, Zheng | f7f7e7a | 2016-05-18 20:31:55 +0800 | [diff] [blame] | 279 | return ci->i_fscache_gen == ci->i_rdcache_gen; |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | |
| 283 | /* Atempt to read from the fscache, |
| 284 | * |
| 285 | * This function is called from the readpage_nounlock context. DO NOT attempt to |
| 286 | * unlock the page here (or in the callback). |
| 287 | */ |
| 288 | int ceph_readpage_from_fscache(struct inode *inode, struct page *page) |
| 289 | { |
| 290 | struct ceph_inode_info *ci = ceph_inode(inode); |
| 291 | int ret; |
| 292 | |
| 293 | if (!cache_valid(ci)) |
| 294 | return -ENOBUFS; |
| 295 | |
| 296 | ret = fscache_read_or_alloc_page(ci->fscache, page, |
Yan, Zheng | dd2bc47 | 2017-08-04 11:22:31 +0800 | [diff] [blame] | 297 | ceph_readpage_from_fscache_complete, NULL, |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 298 | GFP_KERNEL); |
| 299 | |
| 300 | switch (ret) { |
| 301 | case 0: /* Page found */ |
| 302 | dout("page read submitted\n"); |
| 303 | return 0; |
| 304 | case -ENOBUFS: /* Pages were not found, and can't be */ |
| 305 | case -ENODATA: /* Pages were not found */ |
| 306 | dout("page/inode not in cache\n"); |
| 307 | return ret; |
| 308 | default: |
| 309 | dout("%s: unknown error ret = %i\n", __func__, ret); |
| 310 | return ret; |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | int ceph_readpages_from_fscache(struct inode *inode, |
| 315 | struct address_space *mapping, |
| 316 | struct list_head *pages, |
| 317 | unsigned *nr_pages) |
| 318 | { |
| 319 | struct ceph_inode_info *ci = ceph_inode(inode); |
| 320 | int ret; |
| 321 | |
| 322 | if (!cache_valid(ci)) |
| 323 | return -ENOBUFS; |
| 324 | |
| 325 | ret = fscache_read_or_alloc_pages(ci->fscache, mapping, pages, nr_pages, |
Yan, Zheng | dd2bc47 | 2017-08-04 11:22:31 +0800 | [diff] [blame] | 326 | ceph_readpage_from_fscache_complete, |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 327 | NULL, mapping_gfp_mask(mapping)); |
| 328 | |
| 329 | switch (ret) { |
| 330 | case 0: /* All pages found */ |
| 331 | dout("all-page read submitted\n"); |
| 332 | return 0; |
| 333 | case -ENOBUFS: /* Some pages were not found, and can't be */ |
| 334 | case -ENODATA: /* some pages were not found */ |
| 335 | dout("page/inode not in cache\n"); |
| 336 | return ret; |
| 337 | default: |
| 338 | dout("%s: unknown error ret = %i\n", __func__, ret); |
| 339 | return ret; |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | void ceph_readpage_to_fscache(struct inode *inode, struct page *page) |
| 344 | { |
| 345 | struct ceph_inode_info *ci = ceph_inode(inode); |
| 346 | int ret; |
| 347 | |
Milosz Tanski | 9b8dd1e | 2013-09-03 19:11:01 -0400 | [diff] [blame] | 348 | if (!PageFsCache(page)) |
| 349 | return; |
| 350 | |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 351 | if (!cache_valid(ci)) |
| 352 | return; |
| 353 | |
| 354 | ret = fscache_write_page(ci->fscache, page, GFP_KERNEL); |
| 355 | if (ret) |
| 356 | fscache_uncache_page(ci->fscache, page); |
| 357 | } |
| 358 | |
| 359 | void ceph_invalidate_fscache_page(struct inode* inode, struct page *page) |
| 360 | { |
| 361 | struct ceph_inode_info *ci = ceph_inode(inode); |
| 362 | |
Milosz Tanski | ffc7966 | 2013-09-25 11:18:14 -0400 | [diff] [blame] | 363 | if (!PageFsCache(page)) |
| 364 | return; |
| 365 | |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 366 | fscache_wait_on_page_write(ci->fscache, page); |
| 367 | fscache_uncache_page(ci->fscache, page); |
| 368 | } |
| 369 | |
| 370 | void ceph_fscache_unregister_fs(struct ceph_fs_client* fsc) |
| 371 | { |
Yan, Zheng | 1d8f836 | 2017-06-27 11:57:56 +0800 | [diff] [blame] | 372 | if (fscache_cookie_valid(fsc->fscache)) { |
| 373 | struct ceph_fscache_entry *ent; |
| 374 | bool found = false; |
| 375 | |
| 376 | mutex_lock(&ceph_fscache_lock); |
| 377 | list_for_each_entry(ent, &ceph_fscache_list, list) { |
| 378 | if (ent->fscache == fsc->fscache) { |
| 379 | list_del(&ent->list); |
| 380 | kfree(ent); |
| 381 | found = true; |
| 382 | break; |
| 383 | } |
| 384 | } |
| 385 | WARN_ON_ONCE(!found); |
| 386 | mutex_unlock(&ceph_fscache_lock); |
| 387 | |
| 388 | __fscache_relinquish_cookie(fsc->fscache, 0); |
| 389 | } |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 390 | fsc->fscache = NULL; |
| 391 | } |
| 392 | |
Yan, Zheng | f7f7e7a | 2016-05-18 20:31:55 +0800 | [diff] [blame] | 393 | /* |
| 394 | * caller should hold CEPH_CAP_FILE_{RD,CACHE} |
| 395 | */ |
| 396 | void ceph_fscache_revalidate_cookie(struct ceph_inode_info *ci) |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 397 | { |
Yan, Zheng | f7f7e7a | 2016-05-18 20:31:55 +0800 | [diff] [blame] | 398 | if (cache_valid(ci)) |
Milosz Tanski | e81568e | 2013-09-05 18:29:03 +0000 | [diff] [blame] | 399 | return; |
| 400 | |
Yan, Zheng | f7f7e7a | 2016-05-18 20:31:55 +0800 | [diff] [blame] | 401 | /* resue i_truncate_mutex. There should be no pending |
| 402 | * truncate while the caller holds CEPH_CAP_FILE_RD */ |
| 403 | mutex_lock(&ci->i_truncate_mutex); |
| 404 | if (!cache_valid(ci)) { |
| 405 | if (fscache_check_consistency(ci->fscache)) |
| 406 | fscache_invalidate(ci->fscache); |
| 407 | spin_lock(&ci->i_ceph_lock); |
| 408 | ci->i_fscache_gen = ci->i_rdcache_gen; |
| 409 | spin_unlock(&ci->i_ceph_lock); |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 410 | } |
Yan, Zheng | f7f7e7a | 2016-05-18 20:31:55 +0800 | [diff] [blame] | 411 | mutex_unlock(&ci->i_truncate_mutex); |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 412 | } |