Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pipe: implement readv and writev #91

Merged
merged 2 commits into from
Jan 5, 2024
Merged

pipe: implement readv and writev #91

merged 2 commits into from
Jan 5, 2024

Conversation

petershh
Copy link
Contributor

@petershh petershh commented Jan 5, 2024

Now these use pipe::read_iter and pipe::write_iter and don't block when they shouldn't

@heatd
Copy link
Owner

heatd commented Jan 5, 2024

Hi, thanks for the patches!

I'm leaving comments in the individual commits, but in general:

LGTM, but you should restructure things differently. For instance:

  1. The commit sequence breaks bisection
  2. The commit sequence is too granular and leaves things in a borked state between commits 0b80b0c and 5e5f36d

Copy link
Owner

@heatd heatd left a comment

Choose a reason for hiding this comment

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

This should be squashed with the previous patch, as the current ->read() code isn't borked in this regard. You introduced a regression, then fixed it up, but this shouldn't be exposed as a separate commit

@@ -415,7 +416,7 @@ ssize_t pipe::append_iter(iovec_iter *iter, bool atomic)
// See if we have space in this pipe buffer
// TODO: Idea to test: memmove data back if we have offset != 0
// May compact things a bit.
if (PAGE_SIZE - last_buf->len_ <= len)
if (PAGE_SIZE - last_buf->len_ <= iter->bytes)
Copy link
Owner

Choose a reason for hiding this comment

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

This function has typos and tiny bugs which should be fixed up and squashed with the previous commit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

squashed

@@ -451,7 +452,7 @@ ssize_t pipe::append_iter(iovec_iter *iter, bool atomic)
}
}

page *p = cached_page
page *p = cached_page;
Copy link
Owner

Choose a reason for hiding this comment

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

this one as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

squashed


if (wait_for_event_mutex_interruptible(
&write_queue,
(is_atomic_write && available_space() >= (iter->bytes - ret)) || !is_full() ||
Copy link
Owner

Choose a reason for hiding this comment

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

Hmm. I know that the ->write code doesn't handle this. But I think this could be slightly simplified to

(is_atomic_write && available_space() >= iter->bytes) || !is_full() ||

because is_atomic_write means (hopefully) that we're not going to do a partial write, and ret is used to know how much we've written from to the pipe (for partial writes). I think this is correct, but I haven't looked at this code for a while. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this should be correct, since iter->bytes shows amount of unwritten bytes

@petershh petershh force-pushed the pipe-iter branch 2 times, most recently from 86bc000 to 7fb6508 Compare January 5, 2024 18:56
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017 - 2023 Pedro Falcato
* Copyright (c) 2017 - 2024 Pedro Falcato
Copy link
Owner

Choose a reason for hiding this comment

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

I didn't actually touch this this time around, so whether you want to add your name or not is fine for me. But this isn't :)

while (!iter->empty())
{
iovec iov = iter->curiovec();
if (iov.iov_len == 0)
Copy link
Owner

Choose a reason for hiding this comment

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

I'm pretty sure iovec_iter already deals with these iov_len = 0 cases. Did you find an edge case? Do these lines fix anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is older code which was written without clear understanding of what should be done. Will remove


ssize_t copied = copy_to_iter(iter, page_buf, pbf->len_);

if (copied < 0) {
Copy link
Owner

Choose a reason for hiding this comment

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

Wrong brace style, see the rest of the code (and use clang-format!)

curr_len -= copied;
ret += copied;

if (!can_read()) {
Copy link
Owner

Choose a reason for hiding this comment

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

Wrong brace style again

kernel/kernel/fs/pipe.cpp Show resolved Hide resolved
Signed-off-by: Peter Shkenev <[email protected]>
Signed-off-by: Peter Shkenev <[email protected]>
@heatd heatd merged commit 1599d09 into heatd:master Jan 5, 2024
23 checks passed
@heatd
Copy link
Owner

heatd commented Jan 5, 2024

Merged, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants