All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marios Makassikis <mmakassikis@freebox.fr>
To: linux-cifs@vger.kernel.org
Cc: Marios Makassikis <mmakassikis@freebox.fr>
Subject: [PATCH 2/2] ksmbd: retrieve number of blocks using vfs_getattr in set_file_allocation_info
Date: Tue, 20 Feb 2024 15:26:01 +0100	[thread overview]
Message-ID: <20240220142601.3624584-2-mmakassikis@freebox.fr> (raw)
In-Reply-To: <20240220142601.3624584-1-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);
+	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


  reply	other threads:[~2024-02-20 14:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-20 14:26 [PATCH 1/2] ksmbd: replace generic_fillattr with vfs_getattr Marios Makassikis
2024-02-20 14:26 ` Marios Makassikis [this message]
2024-02-21  6:44   ` [PATCH 2/2] ksmbd: retrieve number of blocks using vfs_getattr in set_file_allocation_info Christoph Hellwig
2024-02-21 16:34   ` Namjae Jeon
2024-02-21  6:44 ` [PATCH 1/2] ksmbd: replace generic_fillattr with vfs_getattr Christoph Hellwig
2024-02-21 16:33 ` Namjae Jeon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240220142601.3624584-2-mmakassikis@freebox.fr \
    --to=mmakassikis@freebox.fr \
    --cc=linux-cifs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.