Skip to content

Commit a58823a

Browse files
committed
afs: Fix application of status and callback to be under same lock
When applying the status and callback in the response of an operation, apply them in the same critical section so that there's no race between checking the callback state and checking status-dependent state (such as the data version). Fix this by: (1) Allocating a joint {status,callback} record (afs_status_cb) before calling the RPC function for each vnode for which the RPC reply contains a status or a status plus a callback. A flag is set in the record to indicate if a callback was actually received. (2) These records are passed into the RPC functions to be filled in. The afs_decode_status() and yfs_decode_status() functions are removed and the cb_lock is no longer taken. (3) xdr_decode_AFSFetchStatus() and xdr_decode_YFSFetchStatus() no longer update the vnode. (4) xdr_decode_AFSCallBack() and xdr_decode_YFSCallBack() no longer update the vnode. (5) vnodes, expected data-version numbers and callback break counters (cb_break) no longer need to be passed to the reply delivery functions. Note that, for the moment, the file locking functions still need access to both the call and the vnode at the same time. (6) afs_vnode_commit_status() is now given the cb_break value and the expected data_version and the task of applying the status and the callback to the vnode are now done here. This is done under a single taking of vnode->cb_lock. (7) afs_pages_written_back() is now called by afs_store_data() rather than by the reply delivery function. afs_pages_written_back() has been moved to before the call point and is now given the first and last page numbers rather than a pointer to the call. (8) The indicator from YFS.RemoveFile2 as to whether the target file actually got removed (status.abort_code == VNOVNODE) rather than merely dropping a link is now checked in afs_unlink rather than in xdr_decode_YFSFetchStatus(). Supplementary fixes: (*) afs_cache_permit() now gets the caller_access mask from the afs_status_cb object rather than picking it out of the vnode's status record. afs_fetch_status() returns caller_access through its argument list for this purpose also. (*) afs_inode_init_from_status() now uses a write lock on cb_lock rather than a read lock and now sets the callback inside the same critical section. Fixes: c435ee3 ("afs: Overhaul the callback handling") Signed-off-by: David Howells <dhowells@redhat.com>
1 parent 4571577 commit a58823a

12 files changed

Lines changed: 921 additions & 1004 deletions

File tree

‎fs/afs/dir.c‎

Lines changed: 139 additions & 65 deletions
Large diffs are not rendered by default.

‎fs/afs/dir_silly.c‎

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,28 @@ static int afs_do_silly_rename(struct afs_vnode *dvnode, struct afs_vnode *vnode
2424
struct key *key)
2525
{
2626
struct afs_fs_cursor fc;
27-
u64 dir_data_version = dvnode->status.data_version;
27+
struct afs_status_cb *scb;
2828
int ret = -ERESTARTSYS;
2929

3030
_enter("%pd,%pd", old, new);
3131

32+
scb = kzalloc(sizeof(struct afs_status_cb), GFP_KERNEL);
33+
if (!scb)
34+
return -ENOMEM;
35+
3236
trace_afs_silly_rename(vnode, false);
3337
if (afs_begin_vnode_operation(&fc, dvnode, key, true)) {
38+
afs_dataversion_t dir_data_version = dvnode->status.data_version + 1;
39+
3440
while (afs_select_fileserver(&fc)) {
3541
fc.cb_break = afs_calc_vnode_cb_break(dvnode);
3642
afs_fs_rename(&fc, old->d_name.name,
3743
dvnode, new->d_name.name,
38-
dir_data_version, dir_data_version);
44+
scb, scb);
3945
}
4046

41-
afs_vnode_commit_status(&fc, dvnode, fc.cb_break);
47+
afs_vnode_commit_status(&fc, dvnode, fc.cb_break,
48+
&dir_data_version, scb);
4249
ret = afs_end_vnode_operation(&fc);
4350
}
4451

@@ -64,6 +71,7 @@ static int afs_do_silly_rename(struct afs_vnode *dvnode, struct afs_vnode *vnode
6471
fsnotify_nameremove(old, 0);
6572
}
6673

74+
kfree(scb);
6775
_leave(" = %d", ret);
6876
return ret;
6977
}
@@ -143,31 +151,37 @@ static int afs_do_silly_unlink(struct afs_vnode *dvnode, struct afs_vnode *vnode
143151
struct dentry *dentry, struct key *key)
144152
{
145153
struct afs_fs_cursor fc;
146-
u64 dir_data_version = dvnode->status.data_version;
154+
struct afs_status_cb *scb;
147155
int ret = -ERESTARTSYS;
148156

149157
_enter("");
150158

159+
scb = kcalloc(2, sizeof(struct afs_status_cb), GFP_KERNEL);
160+
if (!scb)
161+
return -ENOMEM;
162+
151163
trace_afs_silly_rename(vnode, true);
152164
if (afs_begin_vnode_operation(&fc, dvnode, key, false)) {
165+
afs_dataversion_t dir_data_version = dvnode->status.data_version + 1;
166+
153167
while (afs_select_fileserver(&fc)) {
154168
fc.cb_break = afs_calc_vnode_cb_break(dvnode);
155169

156170
if (test_bit(AFS_SERVER_FL_IS_YFS, &fc.cbi->server->flags) &&
157171
!test_bit(AFS_SERVER_FL_NO_RM2, &fc.cbi->server->flags)) {
158172
yfs_fs_remove_file2(&fc, vnode, dentry->d_name.name,
159-
dir_data_version);
173+
&scb[0], &scb[1]);
160174
if (fc.ac.error != -ECONNABORTED ||
161175
fc.ac.abort_code != RXGEN_OPCODE)
162176
continue;
163177
set_bit(AFS_SERVER_FL_NO_RM2, &fc.cbi->server->flags);
164178
}
165179

166-
afs_fs_remove(&fc, vnode, dentry->d_name.name, false,
167-
dir_data_version);
180+
afs_fs_remove(&fc, vnode, dentry->d_name.name, false, &scb[0]);
168181
}
169182

170-
afs_vnode_commit_status(&fc, dvnode, fc.cb_break);
183+
afs_vnode_commit_status(&fc, dvnode, fc.cb_break,
184+
&dir_data_version, &scb[0]);
171185
ret = afs_end_vnode_operation(&fc);
172186
if (ret == 0) {
173187
drop_nlink(&vnode->vfs_inode);
@@ -182,6 +196,7 @@ static int afs_do_silly_unlink(struct afs_vnode *dvnode, struct afs_vnode *vnode
182196
afs_edit_dir_for_unlink);
183197
}
184198

199+
kfree(scb);
185200
_leave(" = %d", ret);
186201
return ret;
187202
}

‎fs/afs/file.c‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ static void afs_file_readpage_read_complete(struct page *page,
228228
int afs_fetch_data(struct afs_vnode *vnode, struct key *key, struct afs_read *desc)
229229
{
230230
struct afs_fs_cursor fc;
231+
struct afs_status_cb *scb;
231232
int ret;
232233

233234
_enter("%s{%llx:%llu.%u},%x,,,",
@@ -237,15 +238,22 @@ int afs_fetch_data(struct afs_vnode *vnode, struct key *key, struct afs_read *de
237238
vnode->fid.unique,
238239
key_serial(key));
239240

241+
scb = kzalloc(sizeof(struct afs_status_cb), GFP_KERNEL);
242+
if (!scb)
243+
return -ENOMEM;
244+
240245
ret = -ERESTARTSYS;
241246
if (afs_begin_vnode_operation(&fc, vnode, key, true)) {
247+
afs_dataversion_t data_version = vnode->status.data_version;
248+
242249
while (afs_select_fileserver(&fc)) {
243250
fc.cb_break = afs_calc_vnode_cb_break(vnode);
244-
afs_fs_fetch_data(&fc, desc);
251+
afs_fs_fetch_data(&fc, scb, desc);
245252
}
246253

247-
afs_check_for_remote_deletion(&fc, fc.vnode);
248-
afs_vnode_commit_status(&fc, vnode, fc.cb_break);
254+
afs_check_for_remote_deletion(&fc, vnode);
255+
afs_vnode_commit_status(&fc, vnode, fc.cb_break,
256+
&data_version, scb);
249257
ret = afs_end_vnode_operation(&fc);
250258
}
251259

@@ -255,6 +263,7 @@ int afs_fetch_data(struct afs_vnode *vnode, struct key *key, struct afs_read *de
255263
&afs_v2net(vnode)->n_fetch_bytes);
256264
}
257265

266+
kfree(scb);
258267
_leave(" = %d", ret);
259268
return ret;
260269
}
@@ -405,10 +414,10 @@ static int afs_readpage(struct file *file, struct page *page)
405414
/*
406415
* Make pages available as they're filled.
407416
*/
408-
static void afs_readpages_page_done(struct afs_call *call, struct afs_read *req)
417+
static void afs_readpages_page_done(struct afs_read *req)
409418
{
410419
#ifdef CONFIG_AFS_FSCACHE
411-
struct afs_vnode *vnode = call->xvnode;
420+
struct afs_vnode *vnode = req->vnode;
412421
#endif
413422
struct page *page = req->pages[req->index];
414423

@@ -462,6 +471,7 @@ static int afs_readpages_one(struct file *file, struct address_space *mapping,
462471
return -ENOMEM;
463472

464473
refcount_set(&req->usage, 1);
474+
req->vnode = vnode;
465475
req->page_done = afs_readpages_page_done;
466476
req->pos = first->index;
467477
req->pos <<= PAGE_SHIFT;

‎fs/afs/flock.c‎

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static void afs_schedule_lock_extension(struct afs_vnode *vnode)
7474
*/
7575
void afs_lock_op_done(struct afs_call *call)
7676
{
77-
struct afs_vnode *vnode = call->xvnode;
77+
struct afs_vnode *vnode = call->lvnode;
7878

7979
if (call->error == 0) {
8080
spin_lock(&vnode->lock);
@@ -182,6 +182,7 @@ static void afs_kill_lockers_enoent(struct afs_vnode *vnode)
182182
static int afs_set_lock(struct afs_vnode *vnode, struct key *key,
183183
afs_lock_type_t type)
184184
{
185+
struct afs_status_cb *scb;
185186
struct afs_fs_cursor fc;
186187
int ret;
187188

@@ -192,18 +193,23 @@ static int afs_set_lock(struct afs_vnode *vnode, struct key *key,
192193
vnode->fid.unique,
193194
key_serial(key), type);
194195

196+
scb = kzalloc(sizeof(struct afs_status_cb), GFP_KERNEL);
197+
if (!scb)
198+
return -ENOMEM;
199+
195200
ret = -ERESTARTSYS;
196201
if (afs_begin_vnode_operation(&fc, vnode, key, true)) {
197202
while (afs_select_fileserver(&fc)) {
198203
fc.cb_break = afs_calc_vnode_cb_break(vnode);
199-
afs_fs_set_lock(&fc, type);
204+
afs_fs_set_lock(&fc, type, scb);
200205
}
201206

202-
afs_check_for_remote_deletion(&fc, fc.vnode);
203-
afs_vnode_commit_status(&fc, vnode, fc.cb_break);
207+
afs_check_for_remote_deletion(&fc, vnode);
208+
afs_vnode_commit_status(&fc, vnode, fc.cb_break, NULL, scb);
204209
ret = afs_end_vnode_operation(&fc);
205210
}
206211

212+
kfree(scb);
207213
_leave(" = %d", ret);
208214
return ret;
209215
}
@@ -213,6 +219,7 @@ static int afs_set_lock(struct afs_vnode *vnode, struct key *key,
213219
*/
214220
static int afs_extend_lock(struct afs_vnode *vnode, struct key *key)
215221
{
222+
struct afs_status_cb *scb;
216223
struct afs_fs_cursor fc;
217224
int ret;
218225

@@ -223,18 +230,23 @@ static int afs_extend_lock(struct afs_vnode *vnode, struct key *key)
223230
vnode->fid.unique,
224231
key_serial(key));
225232

233+
scb = kzalloc(sizeof(struct afs_status_cb), GFP_KERNEL);
234+
if (!scb)
235+
return -ENOMEM;
236+
226237
ret = -ERESTARTSYS;
227238
if (afs_begin_vnode_operation(&fc, vnode, key, false)) {
228239
while (afs_select_current_fileserver(&fc)) {
229240
fc.cb_break = afs_calc_vnode_cb_break(vnode);
230-
afs_fs_extend_lock(&fc);
241+
afs_fs_extend_lock(&fc, scb);
231242
}
232243

233-
afs_check_for_remote_deletion(&fc, fc.vnode);
234-
afs_vnode_commit_status(&fc, vnode, fc.cb_break);
244+
afs_check_for_remote_deletion(&fc, vnode);
245+
afs_vnode_commit_status(&fc, vnode, fc.cb_break, NULL, scb);
235246
ret = afs_end_vnode_operation(&fc);
236247
}
237248

249+
kfree(scb);
238250
_leave(" = %d", ret);
239251
return ret;
240252
}
@@ -244,6 +256,7 @@ static int afs_extend_lock(struct afs_vnode *vnode, struct key *key)
244256
*/
245257
static int afs_release_lock(struct afs_vnode *vnode, struct key *key)
246258
{
259+
struct afs_status_cb *scb;
247260
struct afs_fs_cursor fc;
248261
int ret;
249262

@@ -254,18 +267,23 @@ static int afs_release_lock(struct afs_vnode *vnode, struct key *key)
254267
vnode->fid.unique,
255268
key_serial(key));
256269

270+
scb = kzalloc(sizeof(struct afs_status_cb), GFP_KERNEL);
271+
if (!scb)
272+
return -ENOMEM;
273+
257274
ret = -ERESTARTSYS;
258275
if (afs_begin_vnode_operation(&fc, vnode, key, false)) {
259276
while (afs_select_current_fileserver(&fc)) {
260277
fc.cb_break = afs_calc_vnode_cb_break(vnode);
261-
afs_fs_release_lock(&fc);
278+
afs_fs_release_lock(&fc, scb);
262279
}
263280

264-
afs_check_for_remote_deletion(&fc, fc.vnode);
265-
afs_vnode_commit_status(&fc, vnode, fc.cb_break);
281+
afs_check_for_remote_deletion(&fc, vnode);
282+
afs_vnode_commit_status(&fc, vnode, fc.cb_break, NULL, scb);
266283
ret = afs_end_vnode_operation(&fc);
267284
}
268285

286+
kfree(scb);
269287
_leave(" = %d", ret);
270288
return ret;
271289
}
@@ -733,7 +751,7 @@ static int afs_do_getlk(struct file *file, struct file_lock *fl)
733751
posix_test_lock(file, fl);
734752
if (fl->fl_type == F_UNLCK) {
735753
/* no local locks; consult the server */
736-
ret = afs_fetch_status(vnode, key, false);
754+
ret = afs_fetch_status(vnode, key, false, NULL);
737755
if (ret < 0)
738756
goto error;
739757

0 commit comments

Comments
 (0)