Skip to content

Commit 65af8f0

Browse files
committed
cifs: fix allocation size on newly created files
Applications that create and extend and write to a file do not expect to see 0 allocation size. When file is extended, set its allocation size to a plausible value until we have a chance to query the server for it. When the file is cached this will prevent showing an impossible number of allocated blocks (like 0). This fixes e.g. xfstests 614 which does 1) create a file and set its size to 64K 2) mmap write 64K to the file 3) stat -c %b for the file (to query the number of allocated blocks) It was failing because we returned 0 blocks. Even though we would return the correct cached file size, we returned an impossible allocation size. Signed-off-by: Steve French <[email protected]> CC: <[email protected]> Reviewed-by: Aurelien Aptel <[email protected]>
1 parent af3ef3b commit 65af8f0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

fs/cifs/inode.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2395,7 +2395,7 @@ int cifs_getattr(struct user_namespace *mnt_userns, const struct path *path,
23952395
* We need to be sure that all dirty pages are written and the server
23962396
* has actual ctime, mtime and file length.
23972397
*/
2398-
if ((request_mask & (STATX_CTIME | STATX_MTIME | STATX_SIZE)) &&
2398+
if ((request_mask & (STATX_CTIME | STATX_MTIME | STATX_SIZE | STATX_BLOCKS)) &&
23992399
!CIFS_CACHE_READ(CIFS_I(inode)) &&
24002400
inode->i_mapping && inode->i_mapping->nrpages != 0) {
24012401
rc = filemap_fdatawait(inode->i_mapping);
@@ -2585,6 +2585,14 @@ cifs_set_file_size(struct inode *inode, struct iattr *attrs,
25852585
if (rc == 0) {
25862586
cifsInode->server_eof = attrs->ia_size;
25872587
cifs_setsize(inode, attrs->ia_size);
2588+
/*
2589+
* i_blocks is not related to (i_size / i_blksize), but instead
2590+
* 512 byte (2**9) size is required for calculating num blocks.
2591+
* Until we can query the server for actual allocation size,
2592+
* this is best estimate we have for blocks allocated for a file
2593+
* Number of blocks must be rounded up so size 1 is not 0 blocks
2594+
*/
2595+
inode->i_blocks = (512 - 1 + attrs->ia_size) >> 9;
25882596

25892597
/*
25902598
* The man page of truncate says if the size changed,

0 commit comments

Comments
 (0)