Skip to contentSkip to conversation

ceph: fix generic/639 xfstests failure

PATCH In review Viacheslav Dubeyko 3 participants 3 messages Feb 6 – Apr 28

Subsystems (2)
lore
Share & tools
lore

Viacheslav Dubeyko

author maintainer
#0 lore raw

PATCH 1/1 ceph: fix generic/639 xfstests failure

From: Viacheslav Dubeyko <[email protected]>

The generic/639 xfstest fails for Ceph msgr2 protocol:

Ubuntu 22.04.5 LTS (GNU/Linux 6.17.0-rc7+ x86_64)

sudo mount -t ceph :/ /mnt/cephfs/ -o name=admin,fs=cephfs,ms_mode=secure

sudo ./check generic/639
FSTYP -- ceph
PLATFORM -- Linux/x86_64 ceph-0005 6.17.0-rc7+ #16 SMP PREEMPT_DYNAMIC Wed Nov 12 11:01:48 PST 2025 MKFS_OPTIONS -- 192.168.1.213:3300:/scratch
MOUNT_OPTIONS -- -o name=admin,ms_mode=secure 192.168.1.213:3300:/scratch /mnt/cephfs/scratch

generic/639 - output mismatch (see /home/slavad/XFSTESTS-2/xfstests-dev/results//generic/639.out.bad)

The simple way to reproduce the issue simply running these steps:

mount -t ceph :/ /mnt/cephfs/ -o name=admin,fs=cephfs,ms_mode=secure xfs_io -f -c "pwrite -q 0 32" ./testfile251125-0004 umount /mnt/cephfs/
mount -t ceph :/ /mnt/cephfs/ -o name=admin,fs=cephfs,ms_mode=secure xfs_io -c "pwrite -q 32 32" ./testfile251125-0004

Finally, we have the unexpected content of the file:

hexdump ./testfile251125-0004
0000000 0000 0000 0000 0000 0000 0000 0000 0000
*
0000020 cdcd cdcd cdcd cdcd cdcd cdcd cdcd cdcd
*
0000040

Initial analysis has shown that if we try to write out of end of file, then ceph_write_begin() is responsible for the issue because it calls netfs_write_begin() and we have such logic:

int netfs_write_begin(struct netfs_inode *ctx,
struct file *file, struct address_space *mapping, loff_t pos, unsigned int len, struct folio **_folio, void **_fsdata)
{
<skipped>

folio = __filemap_get_folio(mapping, index, FGP_WRITEBEGIN,
mapping_gfp_mask(mapping));

<skipped>

    if (folio_test_uptodate(folio))
        goto have_folio;

<skipped>
}

The reason of the issue that somehow we have folio in uptodate state and netfs_write_begin() simply skips the logic of reading existing file's content.

Futher analysis revealed that we call ceph_fill_inode() and ceph_fill_inline_data() before ceph_write_begin().

void ceph_fill_inline_data(struct inode *inode, struct page *locked_page,
char *data, size_t len)
{
<skipped>

    if (page != locked_page) {
        if (len < PAGE_SIZE)
            zero_user_segment(page, len, PAGE_SIZE);
        else
            flush_dcache_page(page);

        SetPageUptodate(page); <--- We set page uptodate if len == 0!!!!
        unlock_page(page);
        put_page(page);
    }
}

This patch fixes the issue by checking the len argument and setting memory page uptodate only if len > 0.

sudo ./check generic/639

FSTYP         -- ceph
PLATFORM      -- Linux/x86_64 ceph-0005 6.19.0-rc5+ #2 SMP PREEMPT_DYNAMIC Thu Feb  5 15:43:51 PST 2026
MKFS_OPTIONS  -- 192.168.1.213:3300:/scratch

MOUNT_OPTIONS -- -o name=admin,ms_mode=secure 192.168.1.213:3300:/scratch /mnt/cephfs/scratch

generic/639 6s ... 6s
Ran: generic/639
Passed all 1 tests

[1] https://tracker.ceph.com/issues/73829

cc Alex Markuze <[email protected]>
cc Ilya Dryomov <[email protected]>
cc Patrick Donnelly <[email protected]>
cc Ceph Development <[email protected]>
---
 fs/ceph/addr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/ceph/addr.c +3 -1
index 63b75d214210..436a287fd311 100644
@@ -2184,7 +2184,9 @@ void ceph_fill_inline_data(struct inode *inode, struct page *locked_page,
 		else
 			flush_dcache_page(page);
 
-		SetPageUptodate(page);
+		if (len > 0)
+			SetPageUptodate(page);
+
 		unlock_page(page);
 		put_page(page);
 	}
Signature · 1 line
2.53.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 123 lines · Viacheslav Dubeyko

From: Viacheslav Dubeyko <[email protected]>

The generic/639 xfstest fails for Ceph msgr2 protocol:

Ubuntu 22.04.5 LTS (GNU/Linux 6.17.0-rc7+ x86_64)

sudo mount -t ceph :/ /mnt/cephfs/ -o name=admin,fs=cephfs,ms_mode=secure

sudo ./check generic/639
FSTYP -- ceph
PLATFORM -- Linux/x86_64 ceph-0005 6.17.0-rc7+ #16 SMP PREEMPT_DYNAMIC Wed Nov 12 11:01:48 PST 2025 MKFS_OPTIONS -- 192.168.1.213:3300:/scratch
MOUNT_OPTIONS -- -o name=admin,ms_mode=secure 192.168.1.213:3300:/scratch /mnt/cephfs/scratch

generic/639 - output mismatch (see /home/slavad/XFSTESTS-2/xfstests-dev/results//generic/639.out.bad)

The simple way to reproduce the issue simply running these steps:

mount -t ceph :/ /mnt/cephfs/ -o name=admin,fs=cephfs,ms_mode=secure xfs_io -f -c "pwrite -q 0 32" ./testfile251125-0004 umount /mnt/cephfs/
mount -t ceph :/ /mnt/cephfs/ -o name=admin,fs=cephfs,ms_mode=secure xfs_io -c "pwrite -q 32 32" ./testfile251125-0004

Finally, we have the unexpected content of the file:

hexdump ./testfile251125-0004
0000000 0000 0000 0000 0000 0000 0000 0000 0000
*
0000020 cdcd cdcd cdcd cdcd cdcd cdcd cdcd cdcd
*
0000040

Initial analysis has shown that if we try to write out of end of file, then ceph_write_begin() is responsible for the issue because it calls netfs_write_begin() and we have such logic:

int netfs_write_begin(struct netfs_inode *ctx,
struct file *file, struct address_space *mapping, loff_t pos, unsigned int len, struct folio **_folio, void **_fsdata)
{
<skipped>

folio = __filemap_get_folio(mapping, index, FGP_WRITEBEGIN,
mapping_gfp_mask(mapping));

<skipped>

    if (folio_test_uptodate(folio))
        goto have_folio;

<skipped>
}

The reason of the issue that somehow we have folio in uptodate state and netfs_write_begin() simply skips the logic of reading existing file's content.

Futher analysis revealed that we call ceph_fill_inode() and ceph_fill_inline_data() before ceph_write_begin().

void ceph_fill_inline_data(struct inode *inode, struct page *locked_page,
char *data, size_t len)
{
<skipped>

    if (page != locked_page) {
        if (len < PAGE_SIZE)
            zero_user_segment(page, len, PAGE_SIZE);
        else
            flush_dcache_page(page);

        SetPageUptodate(page); <--- We set page uptodate if len == 0!!!!
        unlock_page(page);
        put_page(page);
    }
}

This patch fixes the issue by checking the len argument and setting memory page uptodate only if len > 0.

sudo ./check generic/639

FSTYP         -- ceph
PLATFORM      -- Linux/x86_64 ceph-0005 6.19.0-rc5+ #2 SMP PREEMPT_DYNAMIC Thu Feb  5 15:43:51 PST 2026
MKFS_OPTIONS  -- 192.168.1.213:3300:/scratch

MOUNT_OPTIONS -- -o name=admin,ms_mode=secure 192.168.1.213:3300:/scratch /mnt/cephfs/scratch

generic/639 6s ... 6s
Ran: generic/639
Passed all 1 tests

[1] https://tracker.ceph.com/issues/73829

cc Alex Markuze <[email protected]>
cc Ilya Dryomov <[email protected]>
cc Patrick Donnelly <[email protected]>
cc Ceph Development <[email protected]>
---
 fs/ceph/addr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/ceph/addr.c +3 -2
index 63b75d214210..436a287fd311 100644
@@ -2184,7 +2184,9 @@ void ceph_fill_inline_data(struct inode *inode, struct page *locked_page,
                else
                        flush_dcache_page(page);
 
-               SetPageUptodate(page);
+               if (len > 0)
+                       SetPageUptodate(page);
+
                unlock_page(page);
                put_page(page);
        }
--

2.53.0

maintainer
#2 lore raw
Quoted 9 lines · Alex Markuze
Quoted 4 lines · Viacheslav Dubeyko

From: Viacheslav Dubeyko <[email protected]>

The generic/639 xfstest fails for Ceph msgr2 protocol:

Hi Slava, Alex,

This can't be specific to msgr2 protocol, so I wouldn't emphasize it.

Quoted 53 lines
Quoted 53 lines

Ubuntu 22.04.5 LTS (GNU/Linux 6.17.0-rc7+ x86_64)

sudo mount -t ceph :/ /mnt/cephfs/ -o name=admin,fs=cephfs,ms_mode=secure

sudo ./check generic/639
FSTYP -- ceph
PLATFORM -- Linux/x86_64 ceph-0005 6.17.0-rc7+ #16 SMP PREEMPT_DYNAMIC Wed Nov 12 11:01:48 PST 2025 MKFS_OPTIONS -- 192.168.1.213:3300:/scratch
MOUNT_OPTIONS -- -o name=admin,ms_mode=secure 192.168.1.213:3300:/scratch /mnt/cephfs/scratch

generic/639 - output mismatch (see /home/slavad/XFSTESTS-2/xfstests-dev/results//generic/639.out.bad)

The simple way to reproduce the issue simply running these steps:

mount -t ceph :/ /mnt/cephfs/ -o name=admin,fs=cephfs,ms_mode=secure xfs_io -f -c "pwrite -q 0 32" ./testfile251125-0004 umount /mnt/cephfs/
mount -t ceph :/ /mnt/cephfs/ -o name=admin,fs=cephfs,ms_mode=secure xfs_io -c "pwrite -q 32 32" ./testfile251125-0004

Finally, we have the unexpected content of the file:

hexdump ./testfile251125-0004
0000000 0000 0000 0000 0000 0000 0000 0000 0000
*
0000020 cdcd cdcd cdcd cdcd cdcd cdcd cdcd cdcd
*
0000040

Initial analysis has shown that if we try to write out of end of file, then ceph_write_begin() is responsible for the issue because it calls netfs_write_begin() and we have such logic:

int netfs_write_begin(struct netfs_inode *ctx,
struct file *file, struct address_space *mapping, loff_t pos, unsigned int len, struct folio **_folio, void **_fsdata)
{
<skipped>

folio = __filemap_get_folio(mapping, index, FGP_WRITEBEGIN,
mapping_gfp_mask(mapping));

<skipped>

    if (folio_test_uptodate(folio))
        goto have_folio;

<skipped>
}

Quoted 6 lines
Quoted 6 lines

The reason of the issue that somehow we have folio in uptodate state and netfs_write_begin() simply skips the logic of reading existing file's content.

Futher analysis revealed that we call ceph_fill_inode() and ceph_fill_inline_data() before ceph_write_begin().

With my limited understanding of the inline data feature and its history (it was deprecated years ago but is still in "will likely be removed altogether in a future release" state?), it doesn't make sense that ceph_fill_inline_data() gets called on a file that is created by the kernel client. The kernel client doesn't write inline data -- it only supports reading it (after it's written by the userspace client) and potentially uninlining it.

Quoted 6 lines
Quoted 6 lines

void ceph_fill_inline_data(struct inode *inode, struct page *locked_page,
char *data, size_t len)
{
<skipped>

Quoted 7 lines
Quoted 7 lines
    if (page != locked_page) {
        if (len < PAGE_SIZE)
            zero_user_segment(page, len, PAGE_SIZE);
        else
            flush_dcache_page(page);

        SetPageUptodate(page); <--- We set page uptodate if len == 0!!!!

How does a small file that has a non-zero size but no data (e.g. "truncate -s 32 testfile") is supposed to look when the inline data feature is enabled?

I'm asking because I'm not sure I see anything wrong with this call given the surrounding code. In case of len == 0 zero_user_segment() is called to zero out the entire page. This call to SetPageUptodate() follows that and seems to be on point: if the page isn't going to be marked uptodate, the whole sequence of looking up, locking, zeroing and unlocking it is pointless.

IMO the actual root cause of the issue here is ceph_fill_inline_data() getting called in the first place. ci->i_inline_version for the file in question should be 1 and according to commit 4849077604f0 ("ceph:
don't get the inline data for new creating files") that is equivalent to "no inline data". That commit changed how fill_inline is assigned in ceph_fill_inode() but not in handle_cap_grant() -- I think that was an unintended omission and adding Xiubo to confirm.

If handle_cap_grant() gets changed to use ceph_has_inline_data() instead of checking for CEPH_INLINE_NONE directly, the issue should go away.

Thanks,

Ilya

Quoted 48 lines
Quoted 47 lines
        unlock_page(page);
        put_page(page);
    }
}

This patch fixes the issue by checking the len argument and setting memory page uptodate only if len > 0.

sudo ./check generic/639

FSTYP         -- ceph
PLATFORM      -- Linux/x86_64 ceph-0005 6.19.0-rc5+ #2 SMP PREEMPT_DYNAMIC Thu Feb  5 15:43:51 PST 2026
MKFS_OPTIONS  -- 192.168.1.213:3300:/scratch

MOUNT_OPTIONS -- -o name=admin,ms_mode=secure 192.168.1.213:3300:/scratch /mnt/cephfs/scratch

generic/639 6s ... 6s
Ran: generic/639
Passed all 1 tests

[1] https://tracker.ceph.com/issues/73829

cc Alex Markuze <[email protected]>
cc Ilya Dryomov <[email protected]>
cc Patrick Donnelly <[email protected]>
cc Ceph Development <[email protected]>
---
 fs/ceph/addr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/ceph/addr.c +3 -2
index 63b75d214210..436a287fd311 100644
@@ -2184,7 +2184,9 @@ void ceph_fill_inline_data(struct inode *inode, struct page *locked_page,
                else
                        flush_dcache_page(page);
 
-               SetPageUptodate(page);
+               if (len > 0)
+                       SetPageUptodate(page);
+
                unlock_page(page);
                put_page(page);
        }
--

2.53.0