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

agent: Simplify mount point creation #2428

Merged
merged 5 commits into from Sep 16, 2021

Conversation

dgibson
Copy link
Contributor

@dgibson dgibson commented Aug 11, 2021

mount_storage() first makes sure the mount point for the storage volume
exists. It uses fs::create_dir_all() in the case of 9p or virtiofs volumes
otherwise ensure_destination_exists(). But.. ensure_destination_exists()
boils down to an fs::create_dir_all() in most cases anyway. The only case
it doesn't is for a bind fstype, where it creates a file instead of a
directory. But..

  1. mount_storage() isn't used for bind mounts
  2. That behaviour for bind mounts isn't correct anyway, because we would
    need to create either a file or a directory depending on the source of
    the bind mount, which ensure_destination_exists() doesn't know about.

Furthermore the 9p/virtiofs path checks if the mountpoint exists before
calling fs::create_dir_all(), which is unnecessary, because create_dir_all
has an equivalent test built in.

Signed-off-by: David Gibson david@gibson.dropbear.id.au

@dgibson dgibson self-assigned this Aug 11, 2021
@dgibson dgibson added the wip Work in Progress (PR incomplete - needs more work or rework) label Aug 11, 2021
@dgibson
Copy link
Contributor Author

dgibson commented Aug 11, 2021

/test
/test-vfio

@dgibson
Copy link
Contributor Author

dgibson commented Aug 11, 2021

Hrm, AFAICT the metrics and vfio test failures aren't related to this patch (I've seen them on unrelated PRs). Seems to be some problem setting up the environment there.

@dgibson dgibson removed the wip Work in Progress (PR incomplete - needs more work or rework) label Aug 11, 2021
Copy link
Member

@fidencio fidencio left a comment

Choose a reason for hiding this comment

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

nice clean-up, @dgibson!
LGTM

@dgibson
Copy link
Contributor Author

dgibson commented Aug 11, 2021

/test
/test-vfio

@marcel-apf
Copy link
Contributor

/retest-vfio

@devimc
Copy link

devimc commented Aug 11, 2021

/test-ubuntu-metrics
/test-vfio

@egernst
Copy link
Member

egernst commented Aug 11, 2021

I'm reviewing now (thanks!)

Reviewing now. We'll want to make sure Fupan get's a chance to review as well.

@fidencio fidencio added the do-not-merge PR has problems or depends on another label Aug 11, 2021
@fidencio
Copy link
Member

We'll want to make sure Fupan get's a chance to review as well.

I just added the do-not-merge label to ensure Fupan can get to it.

@egernst
Copy link
Member

egernst commented Aug 11, 2021

@dgibson - thanks for this PR. I was looking to use ensure_destination_exists as part of the watchable bind mount logic, but came to the same conclusion you did that it doesn't quite behave as you'd hope (in particular, as you highlight in your commit message, the bind should create file or or directory depending on the source's type, not just a file).

I ended up just writing my own as a result. Kudos for digging a bit more and seeing the function doesn't appear necessary. This LGTM.

@lifupan WDYT?

Copy link
Member

@egernst egernst left a comment

Choose a reason for hiding this comment

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

LGTM, but I'll want to ensure the original code author to comment as well.

@dgibson
Copy link
Contributor Author

dgibson commented Aug 16, 2021

/test
/test-vfio

Copy link
Member

@bergwolf bergwolf left a comment

Choose a reason for hiding this comment

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

Thanks!

src/agent/src/mount.rs Show resolved Hide resolved
src/agent/src/mount.rs Outdated Show resolved Hide resolved
@dgibson
Copy link
Contributor Author

dgibson commented Sep 10, 2021

@dgibson, although this not exactly a bug fix (as it's rather a simplification), I'd really appreciate if we could have this one backported to the stable-2.2 branch.

It is a bug fix, if it's ever possible to get to this path with a bind mount of a directory. I suspect not, since a directory volume would be a virtiofs mount instead, but I'm not certain.

In any case, what would I need to do for such a backport.

@fidencio
Copy link
Member

@dgibson, although this not exactly a bug fix (as it's rather a simplification), I'd really appreciate if we could have this one backported to the stable-2.2 branch.

It is a bug fix, if it's ever possible to get to this path with a bind mount of a directory. I suspect not, since a directory volume would be a virtiofs mount instead, but I'm not certain.

In any case, what would I need to do for such a backport.

Once this one gets merged, please, open another PR targetting the stable-2.2 branch, and we'll be happy to have it merged there. Simple as that.

@dgibson
Copy link
Contributor Author

dgibson commented Sep 14, 2021

/test
/test-vfio

@dgibson dgibson force-pushed the simplify-mount-storage branch 5 times, most recently from 86d0b3c to bba0419 Compare September 14, 2021 04:47
@dgibson dgibson added the do-not-merge PR has problems or depends on another label Sep 14, 2021
@dgibson
Copy link
Contributor Author

dgibson commented Sep 14, 2021

Setting do-not-merge label temporarily while I debug some weird failures on the static checks.

@dgibson dgibson force-pushed the simplify-mount-storage branch 3 times, most recently from 9b06480 to 86d0b3c Compare September 14, 2021 06:30
@dgibson
Copy link
Contributor Author

dgibson commented Sep 14, 2021

Bother, found the problem. Fixing a lint name which corrects a clippy failure run locally appears to break the CI, I think because it's tripping Rust bug rust-lang/rust-clippy#7422

@dgibson
Copy link
Contributor Author

dgibson commented Sep 15, 2021

Rebased on #2634 to address the bogus clippy warning issues.

@dgibson dgibson removed the do-not-merge PR has problems or depends on another label Sep 15, 2021
BareMount::mount does some complicated marshalling and uses unsafe code to
call into the mount(2) system call.  However, we're already using the nix
crate which provides a more Rust-like wrapper for mount(2).  We're even
already using nix::mount::umount and nix::mount::MsFlags from the same
module.

In the same way, we can replace the direct usage of libc::umount() with
nix::mount::umount() in one of the tests.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
struct Baremount contains the information necessary to make a new mount.
As a datastructure, however, it's pointless, since every user just
constructs it, immediately calls the BareMount::mount() method then
discards the structure.

Simplify the code by making this a direct function call baremount().

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
…ts()

ensure_destination_exists() can create either a directory or a regular file
depending on the arguments.  This patch extracts the regular file specific
option into its own helper: ensure_destination_file_exists().  This:
 - Avoids doing some steps in the directory case (they're already handled
   by create_dir_all())
 - Enables some further future cleanups

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
mount_storage() first makes sure the mount point for the storage volume
exists.  It uses fs::create_dir_all() in the case of 9p or virtiofs volumes
otherwise ensure_destination_exists().  But.. ensure_destination_exists()
boils down to an fs::create_dir_all() in most cases anyway.  The only case
it doesn't is for a bind fstype, where it creates a file instead of a
directory.  But, that's not correct anyway because we need to create either
a file or a directory depending on the source of the bind mount, which
ensure_destination_exists() doesn't know.

The 9p/virtiofs paths also check if the mountpoint exists before calling
fs::create_dir_all(), which is unnecessary (fs::create_dir_all already
handles that case).

mount_storage() does have the information to know what we need to create,
so have it explicitly call ensure_destination_file_exists() for the bind
mount to a non-directory case, and fs::create_dir_all() in all other cases.

fixes kata-containers#2390

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
The only remaining callers of ensure_destination_exists() are in its own
unit tests.  So, just remove it.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
@dgibson
Copy link
Contributor Author

dgibson commented Sep 16, 2021

/test

@dgibson
Copy link
Contributor Author

dgibson commented Sep 16, 2021

/retest-metrics

@dgibson
Copy link
Contributor Author

dgibson commented Sep 16, 2021

/retest-ubuntu-metrics

@dgibson dgibson merged commit b46adbc into kata-containers:main Sep 16, 2021
@dgibson dgibson deleted the simplify-mount-storage branch September 16, 2021 04:43
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.

ensure_destination_exists() has incorrect and unused "bind" mount handling
8 participants