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

[LibOS] Add O_APPEND emulation for single process #1935

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dimakuv
Copy link
Contributor

@dimakuv dimakuv commented Jul 4, 2024

Description of the changes

This PR adds O_APPEND emulation, but only within a single process.

Note that Gramine doesn't support multi-process operations on the same file anyhow, in particular, the file position is not synchronized among multiple processes. This PR doesn't change this limitation of Gramine, thus O_APPEND writes don't work correctly (may overwrite file contents).

Note that Linux has a bug in pwrite(). Gramine emulates this bug in the same way.

Fixes #1921.

See also:

How to test this PR?

A new FS test is added. One LTP test is uncommented.


This change is Reviewable

Note that Gramine doesn't support multi-process operations on the same
file anyhow, in particular, the file position is not synchronized among
multiple processes. This commit doesn't change this limitation of
Gramine, thus `O_APPEND` writes don't work correctly (may overwrite file
contents).

Note that Linux has a bug in `pwrite()`. Gramine emulates this bug
in the same way.

A new FS test is added. One LTP test is uncommented.

Signed-off-by: Dmitrii Kuvaiskii <[email protected]>
@dimakuv dimakuv force-pushed the dimakuv/add-oappend-only-singleprocess branch from a2a9b6b to 4950661 Compare July 9, 2024 10:01
Copy link
Contributor Author

@dimakuv dimakuv left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 18 files reviewed, 1 unresolved discussion, not enough approvals from maintainers (1 more required), not enough approvals from different teams (1 more required, approved so far: Intel)

a discussion (no related file):
FYI: implementation of O_APPEND in the Linux kernel is very simple and self-contained. I searched for APPEND keyword and these are the main sources:

I hope I covered all Linux logic on O_APPEND in this PR. (Note that some logic was already implemented in Gramine.)



libos/src/fs/chroot/encrypted.c line 480 at r2 (raw file):

    lock(&hdl->inode->lock);

    file_off_t actual_pos = (hdl->flags & O_APPEND) ? hdl->inode->size : *pos;

I admit that I don't understand the locking in these handlers... Technically, O_APPEND flag may be changed at runtime via fcntl(SET_FL), so there must be smth like lock(&hdl->lock). At the same time, I don't observe such locking in other (similar) places, and it's also confusing what needs to be locked where.

So for now I do not perform additional locking. I even wonder if hdl->flags can be considered thread-safe for well-behaved apps, because if some app changes the flags in one thread and e.g. writes in another thread, that's a data race and a bug in the app.


libos/src/sys/libos_file.c line 445 at r2 (raw file):

    }

    if (!(in_hdl->acc_mode & MAY_READ) || !(out_hdl->acc_mode & MAY_WRITE)

FYI: this change is orthogonal to this PR. Surprisingly, there was already handling of O_APPEND in this sendfile emulation, though it returned an incorrect error code. So I fixed this and also added two other checks. This could be moved out to a separate PR if needed.


libos/test/fs/test_fs.py line 136 at r2 (raw file):

        self.assertIn('TEST 1 (' + file_path + ')', stdout)
        self.assertIn('TEST 2 (' + file_path + ')', stdout)
        self.assertIn('TEST 3 (' + file_path + ')', stdout)

FYI: Other FS tests also do things like self.assertIn(close(...)), but there are so many lines in the log, that I found it stupid to check each line. So just checking that sub-tests are at least started and printed out. And of course the whole test must run to successful completion.

@dimakuv dimakuv marked this pull request as ready for review July 9, 2024 10:09
@dimakuv
Copy link
Contributor Author

dimakuv commented Jul 30, 2024

Jenkins, test this please (Jenkins was dead when this PR was created)

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.

MariaDB Replication Is Broken
1 participant