Commit | Line | Data |
---|---|---|
1f327613 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
99ccbd22 MT |
2 | /* |
3 | * Ceph cache definitions. | |
4 | * | |
5 | * Copyright (C) 2013 by Adfin Solutions, Inc. All Rights Reserved. | |
6 | * Written by Milosz Tanski (milosz@adfin.com) | |
99ccbd22 MT |
7 | */ |
8 | ||
48f930ea ID |
9 | #include <linux/ceph/ceph_debug.h> |
10 | ||
82995cc6 | 11 | #include <linux/fs_context.h> |
99ccbd22 MT |
12 | #include "super.h" |
13 | #include "cache.h" | |
14 | ||
400e1286 | 15 | void ceph_fscache_register_inode_cookie(struct inode *inode) |
99ccbd22 | 16 | { |
400e1286 JL |
17 | struct ceph_inode_info *ci = ceph_inode(inode); |
18 | struct ceph_fs_client *fsc = ceph_inode_to_client(inode); | |
1d8f8360 | 19 | |
400e1286 JL |
20 | /* No caching for filesystem? */ |
21 | if (!fsc->fscache) | |
22 | return; | |
1d8f8360 | 23 | |
400e1286 JL |
24 | /* Regular files only */ |
25 | if (!S_ISREG(inode->i_mode)) | |
26 | return; | |
1d8f8360 | 27 | |
400e1286 JL |
28 | /* Only new inodes! */ |
29 | if (!(inode->i_state & I_NEW)) | |
30 | return; | |
402cb8dd | 31 | |
400e1286 | 32 | WARN_ON_ONCE(ci->fscache); |
99ccbd22 | 33 | |
400e1286 JL |
34 | ci->fscache = fscache_acquire_cookie(fsc->fscache, 0, |
35 | &ci->i_vino, sizeof(ci->i_vino), | |
36 | &ci->i_version, sizeof(ci->i_version), | |
37 | i_size_read(inode)); | |
99ccbd22 MT |
38 | } |
39 | ||
400e1286 | 40 | void ceph_fscache_unregister_inode_cookie(struct ceph_inode_info* ci) |
99ccbd22 | 41 | { |
400e1286 | 42 | struct fscache_cookie *cookie = ci->fscache; |
99ccbd22 | 43 | |
400e1286 JL |
44 | fscache_relinquish_cookie(cookie, false); |
45 | } | |
99ccbd22 | 46 | |
400e1286 JL |
47 | void ceph_fscache_use_cookie(struct inode *inode, bool will_modify) |
48 | { | |
49 | struct ceph_inode_info *ci = ceph_inode(inode); | |
99ccbd22 | 50 | |
400e1286 | 51 | fscache_use_cookie(ci->fscache, will_modify); |
99ccbd22 MT |
52 | } |
53 | ||
400e1286 | 54 | void ceph_fscache_unuse_cookie(struct inode *inode, bool update) |
99ccbd22 | 55 | { |
46b59b2b | 56 | struct ceph_inode_info *ci = ceph_inode(inode); |
99ccbd22 | 57 | |
400e1286 JL |
58 | if (update) { |
59 | loff_t i_size = i_size_read(inode); | |
99ccbd22 | 60 | |
400e1286 JL |
61 | fscache_unuse_cookie(ci->fscache, &ci->i_version, &i_size); |
62 | } else { | |
63 | fscache_unuse_cookie(ci->fscache, NULL, NULL); | |
46b59b2b | 64 | } |
99ccbd22 MT |
65 | } |
66 | ||
400e1286 | 67 | void ceph_fscache_update(struct inode *inode) |
99ccbd22 | 68 | { |
400e1286 JL |
69 | struct ceph_inode_info *ci = ceph_inode(inode); |
70 | loff_t i_size = i_size_read(inode); | |
99ccbd22 | 71 | |
400e1286 | 72 | fscache_update_cookie(ci->fscache, &ci->i_version, &i_size); |
99ccbd22 MT |
73 | } |
74 | ||
400e1286 | 75 | void ceph_fscache_invalidate(struct inode *inode, bool dio_write) |
46b59b2b | 76 | { |
400e1286 JL |
77 | struct ceph_inode_info *ci = ceph_inode(inode); |
78 | ||
79 | fscache_invalidate(ceph_inode(inode)->fscache, | |
80 | &ci->i_version, i_size_read(inode), | |
81 | dio_write ? FSCACHE_INVAL_DIO_WRITE : 0); | |
46b59b2b YZ |
82 | } |
83 | ||
400e1286 | 84 | int ceph_fscache_register_fs(struct ceph_fs_client* fsc, struct fs_context *fc) |
46b59b2b | 85 | { |
400e1286 JL |
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 | char *name; | |
90 | int err = 0; | |
46b59b2b | 91 | |
400e1286 JL |
92 | name = kasprintf(GFP_KERNEL, "ceph,%pU%s%s", fsid, uniq_len ? "," : "", |
93 | uniq_len ? fscache_uniq : ""); | |
94 | if (!name) | |
95 | return -ENOMEM; | |
46b59b2b | 96 | |
400e1286 JL |
97 | fsc->fscache = fscache_acquire_volume(name, NULL, NULL, 0); |
98 | if (IS_ERR_OR_NULL(fsc->fscache)) { | |
99 | errorfc(fc, "Unable to register fscache cookie for %s", name); | |
100 | err = fsc->fscache ? PTR_ERR(fsc->fscache) : -EOPNOTSUPP; | |
101 | fsc->fscache = NULL; | |
46b59b2b | 102 | } |
400e1286 JL |
103 | kfree(name); |
104 | return err; | |
46b59b2b YZ |
105 | } |
106 | ||
99ccbd22 MT |
107 | void ceph_fscache_unregister_fs(struct ceph_fs_client* fsc) |
108 | { | |
400e1286 | 109 | fscache_relinquish_volume(fsc->fscache, NULL, false); |
99ccbd22 | 110 | } |