Skip to content

client: do not allow zero‑length reads - #65656

Merged
vshankar merged 3 commits into
ceph:mainfrom
dparmar18:i73037
Apr 23, 2026
Merged

vshankar merged 3 commits into
ceph:mainfrom
dparmar18:i73037

Conversation

@dparmar18

@dparmar18 dparmar18 commented Sep 24, 2025 •

Copy link
Copy Markdown
Contributor

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

@github-actions github-actions Bot added cephfs Ceph File System tests labels Sep 24, 2025
@dparmar18
dparmar18 requested a review from a team September 24, 2025 11:52
Comment thread src/client/Client.cc Resolved
Comment thread src/client/Client.cc Resolved
@dparmar18
dparmar18 force-pushed the i73037 branch 5 times, most recently from 6232c76 to b31d6a8 Compare October 31, 2025 08:12
Comment thread src/client/Client.cc
@@ -11135,6 +11139,14 @@ int64_t Client::_read(Fh *f, int64_t offset, uint64_t size, bufferlist *bl,
{
ceph_assert(ceph_mutex_is_locked_by_me(client_lock));

// zero bytes read is not supported by osd

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I'm thinking more about this approach. If we put this up this high, we'll miss the check for f->mode & CEPH_FILE_MODE_RD) == 0.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can move that check above before declaring all those variables

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this current form, we still exit if size == 0, but f->mode doesn't have CEPH_FILE_MODE_RD. It should fail in that case regardless of size. We should probably still do this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you take a look now? I've moved the ldout statement to top, first check the file handle mode and then the size.

Comment thread src/client/Client.cc
@@ -11266,18 +11278,6 @@ int64_t Client::_read(Fh *f, int64_t offset, uint64_t size, bufferlist *bl,
// is duplicated and modified and exists in
// C_Read_Sync_NonBlocking::finish().

// trim read based on file size?

@chrisphoffman chrisphoffman Nov 4, 2025 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to keep things consistent. Right now case 1 (_read_async) and case 3 (_read_sync) both check again if the size/len is 0 within the functions. They both are only called from _read(). Do we want to remove those checks, or add a check to C_Read_Sync_NonBlocking to complete immediately in retry() if len == 0? That way we can potentially avoid bugs later on.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now case 1 (_read_async) and case 3 (_read_sync) both check again if the size/len is 0 within the functions. They both are only called from _read()

I did thought about this initially but then wondered - what if in future these member functions are called independently from some new API? I felt that considering they are helper functions to carry out async/sync read; i kept those functions intact. WDYT?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a check to C_Read_Sync_NonBlocking to complete immediately in retry() if len == 0? That way we can potentially avoid bugs later on.

Yeah, doable. It's called from case 2 right now and fixing the retry() could help prevent future bugs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also what about C_Read_Async_Finisher::finish? In Client::do_readahead - pair<uint64_t, uint64_t> readahead_extent = f->readahead.update(off, len, in->size); returns an extent and the extent.second would be readahead_length and then is passed in

int r2 = objectcacher->file_read(&in->oset, &in->layout, in->snapid,
				       readahead_extent.first, readahead_extent.second,
				       NULL, 0, onfinish2);

this could again crash

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some new API? I felt that considering they are helper functions to carry out async/sync read; i kept those functions intact. WDYT?

Yeah we can keep those, if _read_sync and _read_async both bail if the size is zero that will keep it from failing on unchecked new code paths.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also what about C_Read_Async_Finisher::finish?

Unless I'm missing something, that has a check, that skips do_readahead if size is 0.
https://github.com/ceph/ceph/blob/9d82c94d62564743964ee0899a401c4270907557/src/client/Client.cc#L11825-L11826

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also what about C_Read_Async_Finisher::finish?

Unless I'm missing something, that has a check, that skips do_readahead if size is 0.

https://github.com/ceph/ceph/blob/9d82c94d62564743964ee0899a401c4270907557/src/client/Client.cc#L11825-L11826

oh glad it is, wonder how i missed it but thanks for pointing out!

@github-actions

github-actions Bot commented Nov 6, 2025

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@vshankar

Copy link
Copy Markdown
Contributor

@dparmar18 please rebase

@dparmar18

Copy link
Copy Markdown
Contributor Author

@dparmar18 please rebase

@vshankar this is ready

@anoopcs9 anoopcs9 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the commit message subject and PR title: client: do not allow zero‑length reads or client: disallow zero length reads

Please fix the typo in the commit message subject: src/test: test zero-length async-fsync read using ll_preadv_pwritev -> s/async/sync.

@dparmar18
dparmar18 force-pushed the i73037 branch 2 times, most recently from fd60702 to d3ca82b Compare December 3, 2025 11:32
@dparmar18

Copy link
Copy Markdown
Contributor Author

Please fix the typo in the commit message subject: src/test: test zero-length async-fsync read using ll_preadv_pwritev -> s/async/sync.

from the https://tracker.ceph.com/issues/73037 description, i think it should be async

@dparmar18 dparmar18 changed the title client: no do allow zero length read client: do not allow zero‑length reads Dec 3, 2025
@anoopcs9
anoopcs9 dismissed their stale review December 4, 2025 11:11

Requested changes have been made in the updated version.

@chrisphoffman chrisphoffman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all my comments were addressed. lgtm

Comment thread src/client/Client.cc Resolved
@github-actions

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@dparmar18

Copy link
Copy Markdown
Contributor Author

@vshankar request for a teuthology run

@dparmar18

Copy link
Copy Markdown
Contributor Author

@vshankar ping

@vshankar

vshankar commented Jan 5, 2026

Copy link
Copy Markdown
Contributor

@vshankar request for a teuthology run

I don't have access to the new lab yet. Working it out...

@vshankar

Copy link
Copy Markdown
Contributor

vshankar added a commit to vshankar/ceph that referenced this pull request Mar 24, 2026
* refs/pull/65656/head:

Reviewed-by: Christopher Hoffman <[email protected]>
vshankar added a commit to vshankar/ceph that referenced this pull request Apr 20, 2026
* refs/pull/65656/head:
	client: do not allow zero‑length reads
	src/test: test zero-length async-fsync read using ceph_ll_nonblocking_readv_writev
	src/test: test zero-length async-fsync read using ll_preadv_pwritev

Reviewed-by: Christopher Hoffman <[email protected]>

@vshankar vshankar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vshankar

Copy link
Copy Markdown
Contributor

jenkins test windows

char fname[256];
sprintf(fname, "test_llreadvllwritevfsyncfile%u", mypid);
ASSERT_EQ(0, client->ll_createx(root, fname, 0666,
O_RDWR | O_CREAT | O_TRUNC | O_RSYNC,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dparmar18 - this is failing windows build

src/test/libcephfs/CMakeFiles/ceph_test_libcephfs.dir/test.cc.obj -MF src/test/libcephfs/CMakeFiles/ceph_test_libcephfs.dir/test.cc.obj.d -o src/test/libcephfs/CMakeFiles/ceph_test_libcephfs.dir/test.cc.obj -c /home/ubuntu/ceph/src/test/libcephfs/test.cc
/home/ubuntu/ceph/src/test/libcephfs/test.cc:4635:57: error: use of undeclared identifier 'O_RSYNC'
                           O_RDWR | O_CREAT | O_TRUNC | O_RSYNC,
                                                        ^

Missing O_RSYNC definition is probably causing this??

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test.cc needs to do what client does i guess

ceph/src/client/Client.cc

Lines 140 to 142 in 1b2dbcf

#ifndef O_RSYNC
#define O_RSYNC 0x0
#endif

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

windows build is passing now.

@dparmar18

Copy link
Copy Markdown
Contributor Author

jenkins test make check

@dparmar18

Copy link
Copy Markdown
Contributor Author

@vshankar all green

@vshankar

Copy link
Copy Markdown
Contributor

@vshankar all green

Can you explain the fix a bit please? Would it require a rerun of tests?

@vshankar
vshankar merged commit a40bf61 into ceph:main Apr 23, 2026
6 checks passed
@dparmar18

Copy link
Copy Markdown
Contributor Author

@vshankar all green

Can you explain the fix a bit please? Would it require a rerun of tests?

O_RSYNC doesn't exist in windows/darwin, therefore defining it the way client does acts as a fallback to make the build pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants