Skip to content

Conversation

@alexandruag
Copy link

The changes I propose are all in the "refactoring around file-backed mappings" commit. Here's the gist of things:

  • I've added a FileMappingConfig struct to guest_memory.rs. This structure holds the configuration of a file backed memory region. It currently only consists of the file and offset, but later it might also record things like flags, and more complex mapping configurations if we ever decide we'd like to have one region backed by multiple mappings.
  • I created some helper functions which for the common functionality used by multiple constructors etc.
  • I could not resist the temptation to rename a couple of things :(
  • I've updated the existing tests to use the new functionality/names, but I still didn't have a thorough look at them, and did not add tests for some of the newly introduced functionality.
  • There are some open questions I've added as TODOs.

If you'd like to keep these changes, I can add everything that's missing and we can merge them.

Sebastien Boeuf and others added 2 commits June 2, 2019 16:38
In order to support use cases where the memory needs to be backed by
actual files in order to be shared across processes (vhost-user case),
this patch introduces a new function creating the guest memory with
each region backed by a file descriptor provided by the caller.

It also introduces two helpers to retrieve file information related
to a region. Each file is owned by the memory region so that the
caller does not have to deal with ownership. This way, the file gets
to live as long as the memory region is active.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
Signed-off-by: Alexandru Agache <aagch@amazon.com>
@alexandruag alexandruag changed the title 4seb Refactoring around file base mappings Jun 2, 2019
#[derive(Debug)]
pub struct FileMappingConfig {
file: File,
offset: usize,
Copy link

Choose a reason for hiding this comment

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

How about using libc::off_t instead of usize here? Offset into file object may be differrent from usize.

Copy link
Owner

Choose a reason for hiding this comment

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

I would keep usize at the guest_memory level, in order to keep the cast into libc::off_t internal to the crate.

Copy link
Author

Choose a reason for hiding this comment

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

Ultimately, like Paolo mentioned on the discussions around the original PR, usize turns into a bad idea here because of files larger than 4G on 32 bit systems. I'll prob end up using a type alias for offset which will be equivalent to off_t on Linux, and something else on Windows, just to have a clean interface.

// even if we do verify, someone might truncate the file later. I guess it might still be a
// valuable sanity check.
// TODO: should we explicitly check that the offset is a multiple of PAGE_SIZE, or will mmap return
// an error anyway in this case?
Copy link
Owner

Choose a reason for hiding this comment

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

mmap will throw you an error, no need to check for this.

Copy link
Author

Choose a reason for hiding this comment

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

Ah right, didn't remember the documentation actually mentions this.

Copy link
Owner

@sboeuf sboeuf left a comment

Choose a reason for hiding this comment

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

@alexandruag this looks pretty good to me. Unless @jiangliu has some objections, I would say go ahead and finish the implementation that you started here. You can squash with my commit if you want I don't mind.

One comment though, you could have gone one step further by having a single function new() that would always take a tuple (GuestAddress, length, Option<file, offset>). This way, we would give the consumer the way to initialize non-homogeneous GuestMemoryMmap. From a single function we could have a GuestMemoryMmap describing both some non-backed and backed memory ranges. WDYT?

@jiangliu
Copy link

jiangliu commented Jun 4, 2019

@alexandruag this looks pretty good to me. Unless @jiangliu has some objections, I would say go ahead and finish the implementation that you started here. You can squash with my commit if you want I don't mind.

I like these changes:)

@alexandruag
Copy link
Author

@sboeuf You're right that sounds good, this was just like a minimal proof of concept implementation. Btw, when squashing commits how can I ensure all the authors show up in the history?

@sboeuf
Copy link
Owner

sboeuf commented Jun 4, 2019

@alexandruag

@sboeuf You're right that sounds good, this was just like a minimal proof of concept implementation. Btw, when squashing commits how can I ensure all the authors show up in the history?

Add Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com> in the commit message :)

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.

3 participants