Linux CIFS filesystem development
 help / color / mirror / Atom feed
From: Huiwen He <huiwen.he@linux.dev>
To: smfrench@gmail.com, linkinjeon@kernel.org, pc@manguebit.org,
	ronniesahlberg@gmail.com, sprasad@microsoft.com, tom@talpey.com,
	bharathsm@microsoft.com, senozhatsky@chromium.org,
	dhowells@redhat.com, metze@samba.org, chenxiaosong@kylinos.cn
Cc: linux-cifs@vger.kernel.org
Subject: [PATCH v2 3/3] smb/client: refresh allocation size after fallocate
Date: Sat,  6 Jun 2026 00:35:19 +0800	[thread overview]
Message-ID: <20260605163519.169916-4-huiwen.he@linux.dev> (raw)
In-Reply-To: <20260605163519.169916-1-huiwen.he@linux.dev>

From: Huiwen He <hehuiwen@kylinos.cn>

SMB3 fallocate extends EOF using FILE_END_OF_FILE_INFORMATION, but the
server may also update the file's AllocationSize.  If the client keeps
the old cached i_blocks value after fallocate, the swapfile hole check
can still see:

        i_blocks * 512 < i_size

and reject the file as sparse.

This shows up in xfstests generic/496 as:

        generic/496         [not run] fallocated swap not supported here

After a successful EOF-extending fallocate, query FILE_ALL_INFORMATION on
the open handle and update i_blocks from the returned AllocationSize. If
the query fails, leave the fallocate result unchanged and force a later
attribute revalidation by setting cifsi->time to zero.

With this client-side refresh, and with a server that really allocates the
fallocated range, for example Samba configured with:

        [scratch_share]
        strict allocate = yes

generic/496 can pass the swapfile hole check.

Signed-off-by: Huiwen He <hehuiwen@kylinos.cn>
Reviewed-by: ChenXiaoSong <chenxiaosong@kylinos.cn>
---
 fs/smb/client/smb2ops.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c
index d4875f9532b4..89230141b5dd 100644
--- a/fs/smb/client/smb2ops.c
+++ b/fs/smb/client/smb2ops.c
@@ -3698,8 +3698,23 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
 		rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
 				  cfile->fid.volatile_fid, cfile->pid, new_eof);
 		if (rc == 0) {
+			struct smb2_file_all_info file_inf;
+			u64 asize;
+			int qrc;
+
 			netfs_resize_file(&cifsi->netfs, new_eof, true);
 			cifs_setsize(inode, new_eof);
+
+			qrc = SMB2_query_info(xid, tcon, cfile->fid.persistent_fid,
+					      cfile->fid.volatile_fid, &file_inf);
+			spin_lock(&inode->i_lock);
+			if (qrc == 0) {
+				asize = le64_to_cpu(file_inf.AllocationSize);
+				inode->i_blocks = CIFS_INO_BLOCKS(asize);
+			} else {
+				cifsi->time = 0;
+			}
+			spin_unlock(&inode->i_lock);
 		}
 		goto out;
 	}
-- 
2.43.0


  parent reply	other threads:[~2026-06-05 16:36 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-05 16:35 [PATCH v2 0/3] smb: client: fix i_blocks accounting for swapfile xfstests Huiwen He
2026-06-05 16:35 ` [PATCH v2 1/3] smb/client: update i_blocks after contiguous writes Huiwen He
2026-06-05 16:35 ` [PATCH v2 2/3] smb/client: do not account EOF extension as allocation Huiwen He
2026-06-07 15:33   ` Steve French
2026-06-05 16:35 ` Huiwen He [this message]
2026-06-07 15:35   ` [PATCH v2 3/3] smb/client: refresh allocation size after fallocate Steve French
2026-06-07 16:20     ` hehuiwen
2026-06-08 15:28     ` hehuiwen

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=20260605163519.169916-4-huiwen.he@linux.dev \
    --to=huiwen.he@linux.dev \
    --cc=bharathsm@microsoft.com \
    --cc=chenxiaosong@kylinos.cn \
    --cc=dhowells@redhat.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=metze@samba.org \
    --cc=pc@manguebit.org \
    --cc=ronniesahlberg@gmail.com \
    --cc=senozhatsky@chromium.org \
    --cc=smfrench@gmail.com \
    --cc=sprasad@microsoft.com \
    --cc=tom@talpey.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox