0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/jiffies.h>
0009 #include <linux/file.h>
0010 #include <linux/slab.h>
0011 #include <linux/stat.h>
0012 #include <linux/sched.h>
0013 #include <linux/fs.h>
0014 #include <net/9p/9p.h>
0015
0016 #include "v9fs.h"
0017 #include "cache.h"
0018
0019 int v9fs_cache_session_get_cookie(struct v9fs_session_info *v9ses,
0020 const char *dev_name)
0021 {
0022 struct fscache_volume *vcookie;
0023 char *name, *p;
0024
0025 name = kasprintf(GFP_KERNEL, "9p,%s,%s",
0026 dev_name, v9ses->cachetag ?: v9ses->aname);
0027 if (!name)
0028 return -ENOMEM;
0029
0030 for (p = name; *p; p++)
0031 if (*p == '/')
0032 *p = ';';
0033
0034 vcookie = fscache_acquire_volume(name, NULL, NULL, 0);
0035 p9_debug(P9_DEBUG_FSC, "session %p get volume %p (%s)\n",
0036 v9ses, vcookie, name);
0037 if (IS_ERR(vcookie)) {
0038 if (vcookie != ERR_PTR(-EBUSY)) {
0039 kfree(name);
0040 return PTR_ERR(vcookie);
0041 }
0042 pr_err("Cache volume key already in use (%s)\n", name);
0043 vcookie = NULL;
0044 }
0045 v9ses->fscache = vcookie;
0046 kfree(name);
0047 return 0;
0048 }
0049
0050 void v9fs_cache_inode_get_cookie(struct inode *inode)
0051 {
0052 struct v9fs_inode *v9inode = V9FS_I(inode);
0053 struct v9fs_session_info *v9ses;
0054 __le32 version;
0055 __le64 path;
0056
0057 if (!S_ISREG(inode->i_mode))
0058 return;
0059 if (WARN_ON(v9fs_inode_cookie(v9inode)))
0060 return;
0061
0062 version = cpu_to_le32(v9inode->qid.version);
0063 path = cpu_to_le64(v9inode->qid.path);
0064 v9ses = v9fs_inode2v9ses(inode);
0065 v9inode->netfs.cache =
0066 fscache_acquire_cookie(v9fs_session_cache(v9ses),
0067 0,
0068 &path, sizeof(path),
0069 &version, sizeof(version),
0070 i_size_read(&v9inode->netfs.inode));
0071
0072 p9_debug(P9_DEBUG_FSC, "inode %p get cookie %p\n",
0073 inode, v9fs_inode_cookie(v9inode));
0074 }