Skip to content

Commit 453924d

Browse files
committed
afs: Overhaul invalidation handling to better support RO volumes
Overhaul the third party-induced invalidation handling, making use of the previously added volume-level event counters (cb_scrub and cb_ro_snapshot) that are now being parsed out of the VolSync record returned by the fileserver in many of its replies. This allows better handling of RO (and Backup) volumes. Since these are snapshot of a RW volume that are updated atomically simultantanously across all servers that host them, they only require a single callback promise for the entire volume. The currently upstream code assumes that RO volumes operate in the same manner as RW volumes, and that each file has its own individual callback - which means that it does a status fetch for *every* file in a RO volume, whether or not the volume got "released" (volume callback breaks can occur for other reasons too, such as the volumeserver taking ownership of a volume from a fileserver). To this end, make the following changes: (1) Change the meaning of the volume's cb_v_break counter so that it is now a hint that we need to issue a status fetch to work out the state of a volume. cb_v_break is incremented by volume break callbacks and by server initialisation callbacks. (2) Add a second counter, cb_v_check, to the afs_volume struct such that if this differs from cb_v_break, we need to do a check. When the check is complete, cb_v_check is advanced to what cb_v_break was at the start of the status fetch. (3) Move the list of mmap'd vnodes to the volume and trigger removal of PTEs that map to files on a volume break rather than on a server break. (4) When a server reinitialisation callback comes in, use the server-to-volume reverse mapping added in a preceding patch to iterate over all the volumes using that server and clear the volume callback promises for that server and the general volume promise as a whole to trigger reanalysis. (5) Replace the AFS_VNODE_CB_PROMISED flag with an AFS_NO_CB_PROMISE (TIME64_MIN) value in the cb_expires_at field, reducing the number of checks we need to make. (6) Change afs_check_validity() to quickly see if various event counters have been incremented or if the vnode or volume callback promise is due to expire/has expired without making any changes to the state. That is now left to afs_validate() as this may get more complicated in future as we may have to examine server records too. (7) Overhaul afs_validate() so that it does a single status fetch if we need to check the state of either the vnode or the volume - and do so under appropriate locking. The function does the following steps: (A) If the vnode/volume is no longer seen as valid, then we take the vnode validation lock and, if the volume promise has expired, the volume check lock also. The latter prevents redundant checks being made to find out if a new version of the volume got released. (B) If a previous RPC call found that the volsync changed unexpectedly or that a RO volume was updated, then we unmap all PTEs pointing to the file to stop mmap being used for access. (C) If the vnode is still seen to be of uncertain validity, then we perform an FS.FetchStatus RPC op to jointly update the volume status and the vnode status. This assessment is done as part of parsing the reply: If the RO volume creation timestamp advances, cb_ro_snapshot is incremented; if either the creation or update timestamps changes in an unexpected way, the cb_scrub counter is incremented If the Data Version returned doesn't match the copy we have locally, then we ask for the pagecache to be zapped. This takes care of handling RO update. (D) If cb_scrub differs between volume and vnode, the vnode's pagecache is zapped and the vnode's cb_scrub is updated unless the file is marked as having been deleted. Signed-off-by: David Howells <dhowells@redhat.com> cc: Marc Dionne <marc.dionne@auristor.com> cc: linux-afs@lists.infradead.org
1 parent 16069e1 commit 453924d

13 files changed

Lines changed: 344 additions & 203 deletions

File tree

fs/afs/callback.c

Lines changed: 76 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,20 @@ void afs_invalidate_mmap_work(struct work_struct *work)
3333
unmap_mapping_pages(vnode->netfs.inode.i_mapping, 0, 0, false);
3434
}
3535

36-
static void afs_server_init_callback(struct afs_server *server)
36+
static void afs_volume_init_callback(struct afs_volume *volume)
3737
{
3838
struct afs_vnode *vnode;
39-
struct afs_cell *cell = server->cell;
4039

41-
down_read(&cell->fs_open_mmaps_lock);
40+
down_read(&volume->open_mmaps_lock);
4241

43-
list_for_each_entry(vnode, &cell->fs_open_mmaps, cb_mmap_link) {
44-
if (vnode->cb_server == server) {
45-
clear_bit(AFS_VNODE_CB_PROMISED, &vnode->flags);
42+
list_for_each_entry(vnode, &volume->open_mmaps, cb_mmap_link) {
43+
if (vnode->cb_v_check != atomic_read(&volume->cb_v_break)) {
44+
atomic64_set(&vnode->cb_expires_at, AFS_NO_CB_PROMISE);
4645
queue_work(system_unbound_wq, &vnode->cb_work);
4746
}
4847
}
4948

50-
up_read(&cell->fs_open_mmaps_lock);
49+
up_read(&volume->open_mmaps_lock);
5150
}
5251

5352
/*
@@ -56,19 +55,20 @@ static void afs_server_init_callback(struct afs_server *server)
5655
*/
5756
void afs_init_callback_state(struct afs_server *server)
5857
{
59-
struct afs_cell *cell = server->cell;
58+
struct afs_server_entry *se;
6059

61-
down_read(&cell->vs_lock);
60+
down_read(&server->cell->vs_lock);
6261

63-
do {
64-
server->cb_s_break++;
65-
atomic_inc(&server->cell->fs_s_break);
66-
if (!list_empty(&server->cell->fs_open_mmaps))
67-
afs_server_init_callback(server);
68-
69-
} while ((server = rcu_dereference(server->uuid_next)));
62+
list_for_each_entry(se, &server->volumes, slink) {
63+
se->cb_expires_at = AFS_NO_CB_PROMISE;
64+
se->volume->cb_expires_at = AFS_NO_CB_PROMISE;
65+
trace_afs_cb_v_break(se->volume->vid, atomic_read(&se->volume->cb_v_break),
66+
afs_cb_break_for_s_reinit);
67+
if (!list_empty(&se->volume->open_mmaps))
68+
afs_volume_init_callback(se->volume);
69+
}
7070

71-
up_read(&cell->vs_lock);
71+
up_read(&server->cell->vs_lock);
7272
}
7373

7474
/*
@@ -79,9 +79,9 @@ void __afs_break_callback(struct afs_vnode *vnode, enum afs_cb_break_reason reas
7979
_enter("");
8080

8181
clear_bit(AFS_VNODE_NEW_CONTENT, &vnode->flags);
82-
if (test_and_clear_bit(AFS_VNODE_CB_PROMISED, &vnode->flags)) {
82+
if (atomic64_xchg(&vnode->cb_expires_at, AFS_NO_CB_PROMISE) != AFS_NO_CB_PROMISE) {
8383
vnode->cb_break++;
84-
vnode->cb_v_break = atomic_read(&vnode->volume->cb_v_break);
84+
vnode->cb_v_check = atomic_read(&vnode->volume->cb_v_break);
8585
afs_clear_permits(vnode);
8686

8787
if (vnode->lock_state == AFS_VNODE_LOCK_WAITING_FOR_CB)
@@ -147,29 +147,51 @@ static struct afs_volume *afs_lookup_volume_rcu(struct afs_cell *cell,
147147
return volume;
148148
}
149149

150+
/*
151+
* Allow the fileserver to break callbacks at the volume-level. This is
152+
* typically done when, for example, a R/W volume is snapshotted to a R/O
153+
* volume (the only way to change an R/O volume). It may also, however, happen
154+
* when a volserver takes control of a volume (offlining it, moving it, etc.).
155+
*
156+
* Every file in that volume will need to be reevaluated.
157+
*/
158+
static void afs_break_volume_callback(struct afs_server *server,
159+
struct afs_volume *volume)
160+
__releases(RCU)
161+
{
162+
struct afs_server_list *slist = rcu_dereference(volume->servers);
163+
unsigned int i, cb_v_break;
164+
165+
write_lock(&volume->cb_v_break_lock);
166+
167+
for (i = 0; i < slist->nr_servers; i++)
168+
if (slist->servers[i].server == server)
169+
slist->servers[i].cb_expires_at = AFS_NO_CB_PROMISE;
170+
volume->cb_expires_at = AFS_NO_CB_PROMISE;
171+
172+
cb_v_break = atomic_inc_return_release(&volume->cb_v_break);
173+
trace_afs_cb_v_break(volume->vid, cb_v_break, afs_cb_break_for_volume_callback);
174+
175+
write_unlock(&volume->cb_v_break_lock);
176+
rcu_read_unlock();
177+
178+
if (!list_empty(&volume->open_mmaps))
179+
afs_volume_init_callback(volume);
180+
}
181+
150182
/*
151183
* allow the fileserver to explicitly break one callback
152184
* - happens when
153185
* - the backing file is changed
154186
* - a lock is released
155187
*/
156-
static void afs_break_one_callback(struct afs_volume *volume,
188+
static void afs_break_one_callback(struct afs_server *server,
189+
struct afs_volume *volume,
157190
struct afs_fid *fid)
158191
{
159192
struct super_block *sb;
160193
struct afs_vnode *vnode;
161194
struct inode *inode;
162-
unsigned int cb_v_break;
163-
164-
if (fid->vnode == 0 && fid->unique == 0) {
165-
/* The callback break applies to an entire volume. */
166-
write_lock(&volume->cb_v_break_lock);
167-
cb_v_break = atomic_inc_return(&volume->cb_v_break);
168-
trace_afs_cb_break(fid, cb_v_break,
169-
afs_cb_break_for_volume_callback, false);
170-
write_unlock(&volume->cb_v_break_lock);
171-
return;
172-
}
173195

174196
/* See if we can find a matching inode - even an I_NEW inode needs to
175197
* be marked as it can have its callback broken before we finish
@@ -199,24 +221,32 @@ static void afs_break_some_callbacks(struct afs_server *server,
199221

200222
rcu_read_lock();
201223
volume = afs_lookup_volume_rcu(server->cell, vid);
202-
/* TODO: Find all matching volumes if we couldn't match the server and
203-
* break them anyway.
204-
*/
205-
for (i = *_count; i > 0; cbb++, i--) {
206-
if (cbb->fid.vid == vid) {
207-
_debug("- Fid { vl=%08llx n=%llu u=%u }",
208-
cbb->fid.vid,
209-
cbb->fid.vnode,
210-
cbb->fid.unique);
211-
--*_count;
212-
if (volume)
213-
afs_break_one_callback(volume, &cbb->fid);
214-
} else {
215-
*residue++ = *cbb;
224+
if (cbb->fid.vnode == 0 && cbb->fid.unique == 0) {
225+
afs_break_volume_callback(server, volume);
226+
*_count -= 1;
227+
if (*_count)
228+
memmove(cbb, cbb + 1, sizeof(*cbb) * *_count);
229+
} else {
230+
/* TODO: Find all matching volumes if we couldn't match the server and
231+
* break them anyway.
232+
*/
233+
234+
for (i = *_count; i > 0; cbb++, i--) {
235+
if (cbb->fid.vid == vid) {
236+
_debug("- Fid { vl=%08llx n=%llu u=%u }",
237+
cbb->fid.vid,
238+
cbb->fid.vnode,
239+
cbb->fid.unique);
240+
--*_count;
241+
if (volume)
242+
afs_break_one_callback(server, volume, &cbb->fid);
243+
} else {
244+
*residue++ = *cbb;
245+
}
216246
}
247+
rcu_read_unlock();
217248
}
218249

219-
rcu_read_unlock();
220250
afs_put_volume(volume, afs_volume_trace_put_callback);
221251
}
222252

fs/afs/cell.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,6 @@ static struct afs_cell *afs_alloc_cell(struct afs_net *net,
167167
seqlock_init(&cell->volume_lock);
168168
cell->fs_servers = RB_ROOT;
169169
seqlock_init(&cell->fs_lock);
170-
INIT_LIST_HEAD(&cell->fs_open_mmaps);
171-
init_rwsem(&cell->fs_open_mmaps_lock);
172170
rwlock_init(&cell->vl_servers_lock);
173171
cell->flags = (1 << AFS_CELL_FL_CHECK_ALIAS);
174172

fs/afs/dir.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,12 @@ static int afs_d_revalidate(struct dentry *dentry, unsigned int flags)
11181118
dir = AFS_FS_I(d_inode(parent));
11191119

11201120
/* validate the parent directory */
1121-
afs_validate(dir, key);
1121+
ret = afs_validate(dir, key);
1122+
if (ret == -ERESTARTSYS) {
1123+
dput(parent);
1124+
key_put(key);
1125+
return ret;
1126+
}
11221127

11231128
if (test_bit(AFS_VNODE_DELETED, &dir->flags)) {
11241129
_debug("%pd: parent dir deleted", dentry);
@@ -1260,6 +1265,7 @@ void afs_check_for_remote_deletion(struct afs_operation *op)
12601265
switch (afs_op_abort_code(op)) {
12611266
case VNOVNODE:
12621267
set_bit(AFS_VNODE_DELETED, &vnode->flags);
1268+
clear_nlink(&vnode->netfs.inode);
12631269
afs_break_callback(vnode, afs_cb_break_for_deleted);
12641270
}
12651271
}
@@ -1375,7 +1381,7 @@ static void afs_dir_remove_subdir(struct dentry *dentry)
13751381

13761382
clear_nlink(&vnode->netfs.inode);
13771383
set_bit(AFS_VNODE_DELETED, &vnode->flags);
1378-
clear_bit(AFS_VNODE_CB_PROMISED, &vnode->flags);
1384+
atomic64_set(&vnode->cb_expires_at, AFS_NO_CB_PROMISE);
13791385
clear_bit(AFS_VNODE_DIR_VALID, &vnode->flags);
13801386
}
13811387
}

fs/afs/file.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -514,13 +514,12 @@ static bool afs_release_folio(struct folio *folio, gfp_t gfp)
514514
static void afs_add_open_mmap(struct afs_vnode *vnode)
515515
{
516516
if (atomic_inc_return(&vnode->cb_nr_mmap) == 1) {
517-
down_write(&vnode->volume->cell->fs_open_mmaps_lock);
517+
down_write(&vnode->volume->open_mmaps_lock);
518518

519519
if (list_empty(&vnode->cb_mmap_link))
520-
list_add_tail(&vnode->cb_mmap_link,
521-
&vnode->volume->cell->fs_open_mmaps);
520+
list_add_tail(&vnode->cb_mmap_link, &vnode->volume->open_mmaps);
522521

523-
up_write(&vnode->volume->cell->fs_open_mmaps_lock);
522+
up_write(&vnode->volume->open_mmaps_lock);
524523
}
525524
}
526525

@@ -529,12 +528,12 @@ static void afs_drop_open_mmap(struct afs_vnode *vnode)
529528
if (!atomic_dec_and_test(&vnode->cb_nr_mmap))
530529
return;
531530

532-
down_write(&vnode->volume->cell->fs_open_mmaps_lock);
531+
down_write(&vnode->volume->open_mmaps_lock);
533532

534533
if (atomic_read(&vnode->cb_nr_mmap) == 0)
535534
list_del_init(&vnode->cb_mmap_link);
536535

537-
up_write(&vnode->volume->cell->fs_open_mmaps_lock);
536+
up_write(&vnode->volume->open_mmaps_lock);
538537
flush_work(&vnode->cb_work);
539538
}
540539

@@ -570,7 +569,7 @@ static vm_fault_t afs_vm_map_pages(struct vm_fault *vmf, pgoff_t start_pgoff, pg
570569
{
571570
struct afs_vnode *vnode = AFS_FS_I(file_inode(vmf->vma->vm_file));
572571

573-
if (afs_pagecache_valid(vnode))
572+
if (afs_check_validity(vnode))
574573
return filemap_map_pages(vmf, start_pgoff, end_pgoff);
575574
return 0;
576575
}

fs/afs/fs_operation.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct afs_operation *afs_alloc_operation(struct key *key, struct afs_volume *vo
4242
op->pre_volsync.creation = volume->creation_time;
4343
op->pre_volsync.update = volume->update_time;
4444
op->debug_id = atomic_inc_return(&afs_operation_debug_counter);
45-
op->nr_iterations = -1;
45+
op->nr_iterations = -1;
4646
afs_op_set_error(op, -EDESTADDRREQ);
4747

4848
_leave(" = [op=%08x]", op->debug_id);
@@ -184,7 +184,6 @@ void afs_wait_for_operation(struct afs_operation *op)
184184
op->call_responded = false;
185185
op->call_error = 0;
186186
op->call_abort_code = 0;
187-
op->cb_s_break = op->server->cb_s_break;
188187
if (test_bit(AFS_SERVER_FL_IS_YFS, &op->server->flags) &&
189188
op->ops->issue_yfs_rpc)
190189
op->ops->issue_yfs_rpc(op);

fs/afs/inode.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ static int afs_inode_init_from_status(struct afs_operation *op,
8585

8686
write_seqlock(&vnode->cb_lock);
8787

88-
vnode->cb_v_break = op->cb_v_break;
89-
vnode->cb_s_break = op->cb_s_break;
88+
vnode->cb_v_check = op->cb_v_break;
9089
vnode->status = *status;
9190

9291
t = status->mtime_client;
@@ -146,11 +145,10 @@ static int afs_inode_init_from_status(struct afs_operation *op,
146145
if (!vp->scb.have_cb) {
147146
/* it's a symlink we just created (the fileserver
148147
* didn't give us a callback) */
149-
vnode->cb_expires_at = ktime_get_real_seconds();
148+
atomic64_set(&vnode->cb_expires_at, AFS_NO_CB_PROMISE);
150149
} else {
151-
vnode->cb_expires_at = vp->scb.callback.expires_at;
152150
vnode->cb_server = op->server;
153-
set_bit(AFS_VNODE_CB_PROMISED, &vnode->flags);
151+
atomic64_set(&vnode->cb_expires_at, vp->scb.callback.expires_at);
154152
}
155153

156154
write_sequnlock(&vnode->cb_lock);
@@ -214,7 +212,8 @@ static void afs_apply_status(struct afs_operation *op,
214212
vnode->status = *status;
215213

216214
if (vp->dv_before + vp->dv_delta != status->data_version) {
217-
if (test_bit(AFS_VNODE_CB_PROMISED, &vnode->flags))
215+
if (vnode->cb_ro_snapshot == atomic_read(&vnode->volume->cb_ro_snapshot) &&
216+
atomic64_read(&vnode->cb_expires_at) != AFS_NO_CB_PROMISE)
218217
pr_warn("kAFS: vnode modified {%llx:%llu} %llx->%llx %s (op=%x)\n",
219218
vnode->fid.vid, vnode->fid.vnode,
220219
(unsigned long long)vp->dv_before + vp->dv_delta,
@@ -268,9 +267,9 @@ static void afs_apply_callback(struct afs_operation *op,
268267
struct afs_vnode *vnode = vp->vnode;
269268

270269
if (!afs_cb_is_broken(vp->cb_break_before, vnode)) {
271-
vnode->cb_expires_at = cb->expires_at;
272-
vnode->cb_server = op->server;
273-
set_bit(AFS_VNODE_CB_PROMISED, &vnode->flags);
270+
if (op->volume->type == AFSVL_RWVOL)
271+
vnode->cb_server = op->server;
272+
atomic64_set(&vnode->cb_expires_at, cb->expires_at);
274273
}
275274
}
276275

@@ -542,7 +541,7 @@ struct inode *afs_root_iget(struct super_block *sb, struct key *key)
542541
BUG_ON(!(inode->i_state & I_NEW));
543542

544543
vnode = AFS_FS_I(inode);
545-
vnode->cb_v_break = atomic_read(&as->volume->cb_v_break),
544+
vnode->cb_v_check = atomic_read(&as->volume->cb_v_break),
546545
afs_set_netfs_context(vnode);
547546

548547
op = afs_alloc_operation(key, as->volume);
@@ -587,7 +586,7 @@ int afs_getattr(struct mnt_idmap *idmap, const struct path *path,
587586

588587
if (vnode->volume &&
589588
!(query_flags & AT_STATX_DONT_SYNC) &&
590-
!test_bit(AFS_VNODE_CB_PROMISED, &vnode->flags)) {
589+
atomic64_read(&vnode->cb_expires_at) == AFS_NO_CB_PROMISE) {
591590
key = afs_request_key(vnode->volume->cell);
592591
if (IS_ERR(key))
593592
return PTR_ERR(key);

0 commit comments

Comments
 (0)