Skip to content

Commit cd0f3aa

Browse files
committed
Merge tag 'afs-fixes-20190620' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs
Pull AFS fixes from David Howells: "The in-kernel AFS client has been undergoing testing on opendev.org on one of their mirror machines. They are using AFS to hold data that is then served via apache, and Ian Wienand had reported seeing oopses, spontaneous machine reboots and updates to volumes going missing. This patch series appears to have fixed the problem, very probably due to patch (2), but it's not 100% certain. (1) Fix the printing of the "vnode modified" warning to exclude checks on files for which we don't have a callback promise from the server (and so don't expect the server to tell us when it changes). Without this, for every file or directory for which we still have an in-core inode that gets changed on the server, we may get a message logged when we next look at it. This can happen in bulk if, for instance, someone does "vos release" to update a R/O volume from a R/W volume and a whole set of files are all changed together. We only really want to log a message if the file changed and the server didn't tell us about it or we failed to track the state internally. (2) Fix accidental corruption of either afs_vlserver struct objects or the the following memory locations (which could hold anything). The issue is caused by a union that points to two different structs in struct afs_call (to save space in the struct). The call cleanup code assumes that it can simply call the cleanup for one of those structs if not NULL - when it might be actually pointing to the other struct. This means that every Volume Location RPC op is going to corrupt something. (3) Fix an uninitialised spinlock. This isn't too bad, it just causes a one-off warning if lockdep is enabled when "vos release" is called, but the spinlock still behaves correctly. (4) Fix the setting of i_block in the inode. This causes du, for example, to produce incorrect results, but otherwise should not be dangerous to the kernel" * tag 'afs-fixes-20190620' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs: afs: Fix setting of i_blocks afs: Fix uninitialised spinlock afs_volume::cb_break_lock afs: Fix vlserver record corruption afs: Fix over zealous "vnode modified" warnings
2 parents 139ca25 + 2cd42d1 commit cd0f3aa

File tree

4 files changed

+25
-19
lines changed

4 files changed

+25
-19
lines changed

fs/afs/callback.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,9 @@ static void afs_break_one_callback(struct afs_server *server,
275275
struct afs_super_info *as = AFS_FS_S(cbi->sb);
276276
struct afs_volume *volume = as->volume;
277277

278-
write_lock(&volume->cb_break_lock);
278+
write_lock(&volume->cb_v_break_lock);
279279
volume->cb_v_break++;
280-
write_unlock(&volume->cb_break_lock);
280+
write_unlock(&volume->cb_v_break_lock);
281281
} else {
282282
data.volume = NULL;
283283
data.fid = *fid;

fs/afs/inode.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ static noinline void dump_vnode(struct afs_vnode *vnode, struct afs_vnode *paren
5555
dump_stack();
5656
}
5757

58+
/*
59+
* Set the file size and block count. Estimate the number of 512 bytes blocks
60+
* used, rounded up to nearest 1K for consistency with other AFS clients.
61+
*/
62+
static void afs_set_i_size(struct afs_vnode *vnode, u64 size)
63+
{
64+
i_size_write(&vnode->vfs_inode, size);
65+
vnode->vfs_inode.i_blocks = ((size + 1023) >> 10) << 1;
66+
}
67+
5868
/*
5969
* Initialise an inode from the vnode status.
6070
*/
@@ -124,12 +134,7 @@ static int afs_inode_init_from_status(struct afs_vnode *vnode, struct key *key,
124134
return afs_protocol_error(NULL, -EBADMSG, afs_eproto_file_type);
125135
}
126136

127-
/*
128-
* Estimate 512 bytes blocks used, rounded up to nearest 1K
129-
* for consistency with other AFS clients.
130-
*/
131-
inode->i_blocks = ((i_size_read(inode) + 1023) >> 10) << 1;
132-
i_size_write(&vnode->vfs_inode, status->size);
137+
afs_set_i_size(vnode, status->size);
133138

134139
vnode->invalid_before = status->data_version;
135140
inode_set_iversion_raw(&vnode->vfs_inode, status->data_version);
@@ -207,11 +212,13 @@ static void afs_apply_status(struct afs_fs_cursor *fc,
207212

208213
if (expected_version &&
209214
*expected_version != status->data_version) {
210-
kdebug("vnode modified %llx on {%llx:%llu} [exp %llx] %s",
211-
(unsigned long long) status->data_version,
212-
vnode->fid.vid, vnode->fid.vnode,
213-
(unsigned long long) *expected_version,
214-
fc->type ? fc->type->name : "???");
215+
if (test_bit(AFS_VNODE_CB_PROMISED, &vnode->flags))
216+
pr_warn("kAFS: vnode modified {%llx:%llu} %llx->%llx %s\n",
217+
vnode->fid.vid, vnode->fid.vnode,
218+
(unsigned long long)*expected_version,
219+
(unsigned long long)status->data_version,
220+
fc->type ? fc->type->name : "???");
221+
215222
vnode->invalid_before = status->data_version;
216223
if (vnode->status.type == AFS_FTYPE_DIR) {
217224
if (test_and_clear_bit(AFS_VNODE_DIR_VALID, &vnode->flags))
@@ -230,7 +237,7 @@ static void afs_apply_status(struct afs_fs_cursor *fc,
230237

231238
if (data_changed) {
232239
inode_set_iversion_raw(&vnode->vfs_inode, status->data_version);
233-
i_size_write(&vnode->vfs_inode, status->size);
240+
afs_set_i_size(vnode, status->size);
234241
}
235242
}
236243

fs/afs/internal.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,8 @@ struct afs_call {
109109
struct rxrpc_call *rxcall; /* RxRPC call handle */
110110
struct key *key; /* security for this call */
111111
struct afs_net *net; /* The network namespace */
112-
union {
113-
struct afs_server *server;
114-
struct afs_vlserver *vlserver;
115-
};
112+
struct afs_server *server; /* The fileserver record if fs op (pins ref) */
113+
struct afs_vlserver *vlserver; /* The vlserver record if vl op */
116114
struct afs_cb_interest *cbi; /* Callback interest for server used */
117115
struct afs_vnode *lvnode; /* vnode being locked */
118116
void *request; /* request data (first part) */
@@ -616,7 +614,7 @@ struct afs_volume {
616614
unsigned int servers_seq; /* Incremented each time ->servers changes */
617615

618616
unsigned cb_v_break; /* Break-everything counter. */
619-
rwlock_t cb_break_lock;
617+
rwlock_t cb_v_break_lock;
620618

621619
afs_voltype_t type; /* type of volume */
622620
short error;

fs/afs/volume.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ static struct afs_volume *afs_alloc_volume(struct afs_fs_context *params,
4343
atomic_set(&volume->usage, 1);
4444
INIT_LIST_HEAD(&volume->proc_link);
4545
rwlock_init(&volume->servers_lock);
46+
rwlock_init(&volume->cb_v_break_lock);
4647
memcpy(volume->name, vldb->name, vldb->name_len + 1);
4748

4849
slist = afs_alloc_server_list(params->cell, params->key, vldb, type_mask);

0 commit comments

Comments
 (0)