diff mbox series

[2/2] ksmbd: retrieve number of blocks using vfs_getattr in set_file_allocation_info

Message ID 20240220142601.3624584-2-mmakassikis@freebox.fr
State New
Headers show
Series [1/2] ksmbd: replace generic_fillattr with vfs_getattr | expand

Commit Message

Marios Makassikis Feb. 20, 2024, 2:26 p.m. UTC
Use vfs_getattr() as inode->i_blocks may be 0 on some filesystems (XFS
for example).

Signed-off-by: Marios Makassikis <mmakassikis@freebox.fr>
---
 fs/smb/server/smb2pdu.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Comments

Christoph Hellwig Feb. 21, 2024, 6:44 a.m. UTC | #1
On Tue, Feb 20, 2024 at 03:26:01PM +0100, Marios Makassikis wrote:
> Use vfs_getattr() as inode->i_blocks may be 0 on some filesystems (XFS
> for example).

Same comment as for patch 1.  The code changes also look good to me.
Namjae Jeon Feb. 21, 2024, 4:34 p.m. UTC | #2
2024-02-20 23:26 GMT+09:00, Marios Makassikis <mmakassikis@freebox.fr>:
> Use vfs_getattr() as inode->i_blocks may be 0 on some filesystems (XFS
> for example).
>
> Signed-off-by: Marios Makassikis <mmakassikis@freebox.fr>
> ---
>  fs/smb/server/smb2pdu.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c
> index 1a594753f606..f4de2198b71b 100644
> --- a/fs/smb/server/smb2pdu.c
> +++ b/fs/smb/server/smb2pdu.c
> @@ -5812,15 +5812,21 @@ 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(&path, &stat, STATX_BASIC_STATS | STATX_BTIME,
> +			 AT_STATX_SYNC_AS_STAT);
fs/smb/server/smb2pdu.c: In function ‘set_file_allocation_info’:
fs/smb/server/smb2pdu.c:5821:20: error: ‘path’ undeclared (first use
in this function)
 5821 |  rc = vfs_getattr(&path, &stat, STATX_BASIC_STATS | STATX_BTIME,

There is a build error with your patch.
You need to change it with fp->filp->f_path.
> +	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);
> @@ -5828,7 +5834,7 @@ static int set_file_allocation_info(struct ksmbd_work
> *work,
>  			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;
>
>  		/*
> --
> 2.34.1
>
>
>
diff mbox series

Patch

diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c
index 1a594753f606..f4de2198b71b 100644
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -5812,15 +5812,21 @@  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(&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);
@@ -5828,7 +5834,7 @@  static int set_file_allocation_info(struct ksmbd_work *work,
 			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;
 
 		/*