0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <linux/ceph/ceph_debug.h>
0010
0011 #include <linux/fs_context.h>
0012 #include "super.h"
0013 #include "cache.h"
0014
0015 void ceph_fscache_register_inode_cookie(struct inode *inode)
0016 {
0017 struct ceph_inode_info *ci = ceph_inode(inode);
0018 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
0019
0020
0021 if (!fsc->fscache)
0022 return;
0023
0024
0025 if (!S_ISREG(inode->i_mode))
0026 return;
0027
0028
0029 if (!(inode->i_state & I_NEW))
0030 return;
0031
0032 WARN_ON_ONCE(ci->netfs.cache);
0033
0034 ci->netfs.cache =
0035 fscache_acquire_cookie(fsc->fscache, 0,
0036 &ci->i_vino, sizeof(ci->i_vino),
0037 &ci->i_version, sizeof(ci->i_version),
0038 i_size_read(inode));
0039 }
0040
0041 void ceph_fscache_unregister_inode_cookie(struct ceph_inode_info *ci)
0042 {
0043 fscache_relinquish_cookie(ceph_fscache_cookie(ci), false);
0044 }
0045
0046 void ceph_fscache_use_cookie(struct inode *inode, bool will_modify)
0047 {
0048 struct ceph_inode_info *ci = ceph_inode(inode);
0049
0050 fscache_use_cookie(ceph_fscache_cookie(ci), will_modify);
0051 }
0052
0053 void ceph_fscache_unuse_cookie(struct inode *inode, bool update)
0054 {
0055 struct ceph_inode_info *ci = ceph_inode(inode);
0056
0057 if (update) {
0058 loff_t i_size = i_size_read(inode);
0059
0060 fscache_unuse_cookie(ceph_fscache_cookie(ci),
0061 &ci->i_version, &i_size);
0062 } else {
0063 fscache_unuse_cookie(ceph_fscache_cookie(ci), NULL, NULL);
0064 }
0065 }
0066
0067 void ceph_fscache_update(struct inode *inode)
0068 {
0069 struct ceph_inode_info *ci = ceph_inode(inode);
0070 loff_t i_size = i_size_read(inode);
0071
0072 fscache_update_cookie(ceph_fscache_cookie(ci), &ci->i_version, &i_size);
0073 }
0074
0075 void ceph_fscache_invalidate(struct inode *inode, bool dio_write)
0076 {
0077 struct ceph_inode_info *ci = ceph_inode(inode);
0078
0079 fscache_invalidate(ceph_fscache_cookie(ci),
0080 &ci->i_version, i_size_read(inode),
0081 dio_write ? FSCACHE_INVAL_DIO_WRITE : 0);
0082 }
0083
0084 int ceph_fscache_register_fs(struct ceph_fs_client* fsc, struct fs_context *fc)
0085 {
0086 const struct ceph_fsid *fsid = &fsc->client->fsid;
0087 const char *fscache_uniq = fsc->mount_options->fscache_uniq;
0088 size_t uniq_len = fscache_uniq ? strlen(fscache_uniq) : 0;
0089 char *name;
0090 int err = 0;
0091
0092 name = kasprintf(GFP_KERNEL, "ceph,%pU%s%s", fsid, uniq_len ? "," : "",
0093 uniq_len ? fscache_uniq : "");
0094 if (!name)
0095 return -ENOMEM;
0096
0097 fsc->fscache = fscache_acquire_volume(name, NULL, NULL, 0);
0098 if (IS_ERR_OR_NULL(fsc->fscache)) {
0099 errorfc(fc, "Unable to register fscache cookie for %s", name);
0100 err = fsc->fscache ? PTR_ERR(fsc->fscache) : -EOPNOTSUPP;
0101 fsc->fscache = NULL;
0102 }
0103 kfree(name);
0104 return err;
0105 }
0106
0107 void ceph_fscache_unregister_fs(struct ceph_fs_client* fsc)
0108 {
0109 fscache_relinquish_volume(fsc->fscache, NULL, false);
0110 }