aboutsummaryrefslogtreecommitdiffstats
path: root/fs/9p
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2018-04-04 08:41:28 -0400
committerDavid Howells <dhowells@redhat.com>2018-04-04 08:41:28 -0400
commit402cb8dda949d9b8c0df20ad2527d139faad7ca1 (patch)
tree83cdb77f5490a0990eade886aa7f8dd087864996 /fs/9p
parent08c2e3d087840cd1e7141b62d92f3dc897147984 (diff)
fscache: Attach the index key and aux data to the cookie
Attach copies of the index key and auxiliary data to the fscache cookie so that: (1) The callbacks to the netfs for this stuff can be eliminated. This can simplify things in the cache as the information is still available, even after the cache has relinquished the cookie. (2) Simplifies the locking requirements of accessing the information as we don't have to worry about the netfs object going away on us. (3) The cache can do lazy updating of the coherency information on disk. As long as the cache is flushed before reboot/poweroff, there's no need to update the coherency info on disk every time it changes. (4) Cookies can be hashed or put in a tree as the index key is easily available. This allows: (a) Checks for duplicate cookies can be made at the top fscache layer rather than down in the bowels of the cache backend. (b) Caching can be added to a netfs object that has a cookie if the cache is brought online after the netfs object is allocated. A certain amount of space is made in the cookie for inline copies of the data, but if it won't fit there, extra memory will be allocated for it. The downside of this is that live cache operation requires more memory. Signed-off-by: David Howells <dhowells@redhat.com> Acked-by: Anna Schumaker <anna.schumaker@netapp.com> Tested-by: Steve Dickson <steved@redhat.com>
Diffstat (limited to 'fs/9p')
-rw-r--r--fs/9p/cache.c73
1 files changed, 22 insertions, 51 deletions
diff --git a/fs/9p/cache.c b/fs/9p/cache.c
index 64c58eb26159..9d0030af5672 100644
--- a/fs/9p/cache.c
+++ b/fs/9p/cache.c
@@ -55,41 +55,26 @@ int v9fs_random_cachetag(struct v9fs_session_info *v9ses)
55 return scnprintf(v9ses->cachetag, CACHETAG_LEN, "%lu", jiffies); 55 return scnprintf(v9ses->cachetag, CACHETAG_LEN, "%lu", jiffies);
56} 56}
57 57
58static uint16_t v9fs_cache_session_get_key(const void *cookie_netfs_data,
59 void *buffer, uint16_t bufmax)
60{
61 struct v9fs_session_info *v9ses;
62 uint16_t klen = 0;
63
64 v9ses = (struct v9fs_session_info *)cookie_netfs_data;
65 p9_debug(P9_DEBUG_FSC, "session %p buf %p size %u\n",
66 v9ses, buffer, bufmax);
67
68 if (v9ses->cachetag)
69 klen = strlen(v9ses->cachetag);
70
71 if (klen > bufmax)
72 return 0;
73
74 memcpy(buffer, v9ses->cachetag, klen);
75 p9_debug(P9_DEBUG_FSC, "cache session tag %s\n", v9ses->cachetag);
76 return klen;
77}
78
79const struct fscache_cookie_def v9fs_cache_session_index_def = { 58const struct fscache_cookie_def v9fs_cache_session_index_def = {
80 .name = "9P.session", 59 .name = "9P.session",
81 .type = FSCACHE_COOKIE_TYPE_INDEX, 60 .type = FSCACHE_COOKIE_TYPE_INDEX,
82 .get_key = v9fs_cache_session_get_key,
83}; 61};
84 62
85void v9fs_cache_session_get_cookie(struct v9fs_session_info *v9ses) 63void v9fs_cache_session_get_cookie(struct v9fs_session_info *v9ses)
86{ 64{
87 /* If no cache session tag was specified, we generate a random one. */ 65 /* If no cache session tag was specified, we generate a random one. */
88 if (!v9ses->cachetag) 66 if (!v9ses->cachetag) {
89 v9fs_random_cachetag(v9ses); 67 if (v9fs_random_cachetag(v9ses) < 0) {
68 v9ses->fscache = NULL;
69 return;
70 }
71 }
90 72
91 v9ses->fscache = fscache_acquire_cookie(v9fs_cache_netfs.primary_index, 73 v9ses->fscache = fscache_acquire_cookie(v9fs_cache_netfs.primary_index,
92 &v9fs_cache_session_index_def, 74 &v9fs_cache_session_index_def,
75 v9ses->cachetag,
76 strlen(v9ses->cachetag),
77 NULL, 0,
93 v9ses, true); 78 v9ses, true);
94 p9_debug(P9_DEBUG_FSC, "session %p get cookie %p\n", 79 p9_debug(P9_DEBUG_FSC, "session %p get cookie %p\n",
95 v9ses, v9ses->fscache); 80 v9ses, v9ses->fscache);
@@ -99,21 +84,10 @@ void v9fs_cache_session_put_cookie(struct v9fs_session_info *v9ses)
99{ 84{
100 p9_debug(P9_DEBUG_FSC, "session %p put cookie %p\n", 85 p9_debug(P9_DEBUG_FSC, "session %p put cookie %p\n",
101 v9ses, v9ses->fscache); 86 v9ses, v9ses->fscache);
102 fscache_relinquish_cookie(v9ses->fscache, 0); 87 fscache_relinquish_cookie(v9ses->fscache, NULL, false);
103 v9ses->fscache = NULL; 88 v9ses->fscache = NULL;
104} 89}
105 90
106
107static uint16_t v9fs_cache_inode_get_key(const void *cookie_netfs_data,
108 void *buffer, uint16_t bufmax)
109{
110 const struct v9fs_inode *v9inode = cookie_netfs_data;
111 memcpy(buffer, &v9inode->qid.path, sizeof(v9inode->qid.path));
112 p9_debug(P9_DEBUG_FSC, "inode %p get key %llu\n",
113 &v9inode->vfs_inode, v9inode->qid.path);
114 return sizeof(v9inode->qid.path);
115}
116
117static void v9fs_cache_inode_get_attr(const void *cookie_netfs_data, 91static void v9fs_cache_inode_get_attr(const void *cookie_netfs_data,
118 uint64_t *size) 92 uint64_t *size)
119{ 93{
@@ -124,16 +98,6 @@ static void v9fs_cache_inode_get_attr(const void *cookie_netfs_data,
124 &v9inode->vfs_inode, *size); 98 &v9inode->vfs_inode, *size);
125} 99}
126 100
127static uint16_t v9fs_cache_inode_get_aux(const void *cookie_netfs_data,
128 void *buffer, uint16_t buflen)
129{
130 const struct v9fs_inode *v9inode = cookie_netfs_data;
131 memcpy(buffer, &v9inode->qid.version, sizeof(v9inode->qid.version));
132 p9_debug(P9_DEBUG_FSC, "inode %p get aux %u\n",
133 &v9inode->vfs_inode, v9inode->qid.version);
134 return sizeof(v9inode->qid.version);
135}
136
137static enum 101static enum
138fscache_checkaux v9fs_cache_inode_check_aux(void *cookie_netfs_data, 102fscache_checkaux v9fs_cache_inode_check_aux(void *cookie_netfs_data,
139 const void *buffer, 103 const void *buffer,
@@ -154,9 +118,7 @@ fscache_checkaux v9fs_cache_inode_check_aux(void *cookie_netfs_data,
154const struct fscache_cookie_def v9fs_cache_inode_index_def = { 118const struct fscache_cookie_def v9fs_cache_inode_index_def = {
155 .name = "9p.inode", 119 .name = "9p.inode",
156 .type = FSCACHE_COOKIE_TYPE_DATAFILE, 120 .type = FSCACHE_COOKIE_TYPE_DATAFILE,
157 .get_key = v9fs_cache_inode_get_key,
158 .get_attr = v9fs_cache_inode_get_attr, 121 .get_attr = v9fs_cache_inode_get_attr,
159 .get_aux = v9fs_cache_inode_get_aux,
160 .check_aux = v9fs_cache_inode_check_aux, 122 .check_aux = v9fs_cache_inode_check_aux,
161}; 123};
162 124
@@ -175,6 +137,10 @@ void v9fs_cache_inode_get_cookie(struct inode *inode)
175 v9ses = v9fs_inode2v9ses(inode); 137 v9ses = v9fs_inode2v9ses(inode);
176 v9inode->fscache = fscache_acquire_cookie(v9ses->fscache, 138 v9inode->fscache = fscache_acquire_cookie(v9ses->fscache,
177 &v9fs_cache_inode_index_def, 139 &v9fs_cache_inode_index_def,
140 &v9inode->qid.path,
141 sizeof(v9inode->qid.path),
142 &v9inode->qid.version,
143 sizeof(v9inode->qid.version),
178 v9inode, true); 144 v9inode, true);
179 145
180 p9_debug(P9_DEBUG_FSC, "inode %p get cookie %p\n", 146 p9_debug(P9_DEBUG_FSC, "inode %p get cookie %p\n",
@@ -190,7 +156,8 @@ void v9fs_cache_inode_put_cookie(struct inode *inode)
190 p9_debug(P9_DEBUG_FSC, "inode %p put cookie %p\n", 156 p9_debug(P9_DEBUG_FSC, "inode %p put cookie %p\n",
191 inode, v9inode->fscache); 157 inode, v9inode->fscache);
192 158
193 fscache_relinquish_cookie(v9inode->fscache, 0); 159 fscache_relinquish_cookie(v9inode->fscache, &v9inode->qid.version,
160 false);
194 v9inode->fscache = NULL; 161 v9inode->fscache = NULL;
195} 162}
196 163
@@ -203,7 +170,7 @@ void v9fs_cache_inode_flush_cookie(struct inode *inode)
203 p9_debug(P9_DEBUG_FSC, "inode %p flush cookie %p\n", 170 p9_debug(P9_DEBUG_FSC, "inode %p flush cookie %p\n",
204 inode, v9inode->fscache); 171 inode, v9inode->fscache);
205 172
206 fscache_relinquish_cookie(v9inode->fscache, 1); 173 fscache_relinquish_cookie(v9inode->fscache, NULL, true);
207 v9inode->fscache = NULL; 174 v9inode->fscache = NULL;
208} 175}
209 176
@@ -236,11 +203,15 @@ void v9fs_cache_inode_reset_cookie(struct inode *inode)
236 old = v9inode->fscache; 203 old = v9inode->fscache;
237 204
238 mutex_lock(&v9inode->fscache_lock); 205 mutex_lock(&v9inode->fscache_lock);
239 fscache_relinquish_cookie(v9inode->fscache, 1); 206 fscache_relinquish_cookie(v9inode->fscache, NULL, true);
240 207
241 v9ses = v9fs_inode2v9ses(inode); 208 v9ses = v9fs_inode2v9ses(inode);
242 v9inode->fscache = fscache_acquire_cookie(v9ses->fscache, 209 v9inode->fscache = fscache_acquire_cookie(v9ses->fscache,
243 &v9fs_cache_inode_index_def, 210 &v9fs_cache_inode_index_def,
211 &v9inode->qid.path,
212 sizeof(v9inode->qid.path),
213 &v9inode->qid.version,
214 sizeof(v9inode->qid.version),
244 v9inode, true); 215 v9inode, true);
245 p9_debug(P9_DEBUG_FSC, "inode %p revalidating cookie old %p new %p\n", 216 p9_debug(P9_DEBUG_FSC, "inode %p revalidating cookie old %p new %p\n",
246 inode, old, v9inode->fscache); 217 inode, old, v9inode->fscache);