Skip to content

Commit

Permalink
ksmbd: retrieve number of blocks using vfs_getattr in set_file_alloca…
Browse files Browse the repository at this point in the history
…tion_info

Use vfs_getattr() to retrieve stat information, rather than make
assumptions about how a filesystem fills inode structs.

Signed-off-by: Marios Makassikis <[email protected]>
Signed-off-by: Namjae Jeon <[email protected]>
  • Loading branch information
Marios Makassikis authored and namjaejeon committed Mar 1, 2024
1 parent 7843475 commit bb21d03
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions smb2pdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -6286,23 +6286,29 @@ static int set_file_allocation_info(struct ksmbd_work *work,

loff_t alloc_blks;
struct inode *inode;
struct kstat stat;
int rc;

if (!(fp->daccess & FILE_WRITE_DATA_LE))
return -EACCES;

rc = vfs_getattr(&fp->filp->f_path, &stat, STATX_BASIC_STATS | STATX_BTIME,
AT_STATX_SYNC_AS_STAT);
if (rc)
return rc;

alloc_blks = (le64_to_cpu(file_alloc_info->AllocationSize) + 511) >> 9;
inode = file_inode(fp->filp);

if (alloc_blks > inode->i_blocks) {
if (alloc_blks > stat.blocks) {
smb_break_all_levII_oplock(work, fp, 1);
rc = vfs_fallocate(fp->filp, FALLOC_FL_KEEP_SIZE, 0,
alloc_blks * 512);
if (rc && rc != -EOPNOTSUPP) {
pr_err("vfs_fallocate is failed : %d\n", rc);
return rc;
}
} else if (alloc_blks < inode->i_blocks) {
} else if (alloc_blks < stat.blocks) {
loff_t size;

/*
Expand Down

0 comments on commit bb21d03

Please sign in to comment.