Skip to content

Commit 2cd42d1

Browse files
committed
afs: Fix setting of i_blocks
The setting of i_blocks, which is calculated from i_size, has got accidentally misordered relative to the setting of i_size when initially setting up an inode. Further, i_blocks isn't updated by afs_apply_status() when the size is updated. To fix this, break the i_size/i_blocks setting out into a helper function and call it from both places. Fixes: a58823a ("afs: Fix application of status and callback to be under same lock") Signed-off-by: David Howells <[email protected]>
1 parent 90fa9b6 commit 2cd42d1

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

fs/afs/inode.c

Lines changed: 12 additions & 7 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);
@@ -232,7 +237,7 @@ static void afs_apply_status(struct afs_fs_cursor *fc,
232237

233238
if (data_changed) {
234239
inode_set_iversion_raw(&vnode->vfs_inode, status->data_version);
235-
i_size_write(&vnode->vfs_inode, status->size);
240+
afs_set_i_size(vnode, status->size);
236241
}
237242
}
238243

0 commit comments

Comments
 (0)