mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-09-23 09:47:25 +00:00
Merge pull request #1326 from ganeshmaharaj/fix-rootfs-mount
Fix rootfs mount assumptions
This commit is contained in:
@@ -276,6 +276,7 @@ type Container struct {
|
||||
runPath string
|
||||
configPath string
|
||||
containerPath string
|
||||
rootfsSuffix string
|
||||
|
||||
state types.State
|
||||
|
||||
@@ -640,6 +641,7 @@ func newContainer(sandbox *Sandbox, contConfig ContainerConfig) (*Container, err
|
||||
runPath: store.ContainerRuntimeRootPath(sandbox.id, contConfig.ID),
|
||||
configPath: store.ContainerConfigurationRootPath(sandbox.id, contConfig.ID),
|
||||
containerPath: filepath.Join(sandbox.id, contConfig.ID),
|
||||
rootfsSuffix: "rootfs",
|
||||
state: types.State{},
|
||||
process: Process{},
|
||||
mounts: contConfig.Mounts,
|
||||
@@ -1131,6 +1133,10 @@ func (c *Container) hotplugDrive() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
if dev.mountPoint == c.rootFs {
|
||||
c.rootfsSuffix = ""
|
||||
}
|
||||
|
||||
// If device mapper device, then fetch the full path of the device
|
||||
devicePath, fsType, err := getDevicePathAndFsType(dev.mountPoint)
|
||||
if err != nil {
|
||||
|
@@ -275,6 +275,57 @@ func TestContainerAddDriveDir(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestContainerRootfsPath(t *testing.T) {
|
||||
|
||||
testRawFile, loopDev, fakeRootfs, err := testSetupFakeRootfs(t)
|
||||
defer cleanupFakeRootfsSetup(testRawFile, loopDev, fakeRootfs)
|
||||
assert.Nil(t, err)
|
||||
|
||||
truecheckstoragedriver := checkStorageDriver
|
||||
checkStorageDriver = func(major, minor int) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
defer func() {
|
||||
checkStorageDriver = truecheckstoragedriver
|
||||
}()
|
||||
|
||||
sandbox := &Sandbox{
|
||||
ctx: context.Background(),
|
||||
id: "rootfstestsandbox",
|
||||
agent: &noopAgent{},
|
||||
hypervisor: &mockHypervisor{},
|
||||
config: &SandboxConfig{
|
||||
HypervisorConfig: HypervisorConfig{
|
||||
DisableBlockDeviceUse: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
vcstore, err := store.NewVCSandboxStore(sandbox.ctx, sandbox.id)
|
||||
sandbox.store = vcstore
|
||||
assert.Nil(t, err)
|
||||
container := Container{
|
||||
id: "rootfstestcontainerid",
|
||||
sandbox: sandbox,
|
||||
rootFs: fakeRootfs,
|
||||
rootfsSuffix: "rootfs",
|
||||
}
|
||||
cvcstore, err := store.NewVCContainerStore(context.Background(),
|
||||
sandbox.id,
|
||||
container.id)
|
||||
assert.Nil(t, err)
|
||||
container.store = cvcstore
|
||||
|
||||
container.hotplugDrive()
|
||||
assert.Empty(t, container.rootfsSuffix)
|
||||
|
||||
// Reset the value to test the other case
|
||||
container.rootFs = fakeRootfs + "/rootfs"
|
||||
container.rootfsSuffix = "rootfs"
|
||||
|
||||
container.hotplugDrive()
|
||||
assert.Equal(t, container.rootfsSuffix, "rootfs")
|
||||
}
|
||||
|
||||
func TestCheckSandboxRunningEmptyCmdFailure(t *testing.T) {
|
||||
c := &Container{}
|
||||
err := c.checkSandboxRunning("")
|
||||
|
@@ -1004,7 +1004,7 @@ func (k *kataAgent) createContainer(sandbox *Sandbox, c *Container) (p *Process,
|
||||
|
||||
// This is the guest absolute root path for that container.
|
||||
rootPathParent := filepath.Join(kataGuestSharedDir, c.id)
|
||||
rootPath := filepath.Join(rootPathParent, rootfsDir)
|
||||
rootPath := filepath.Join(rootPathParent, c.rootfsSuffix)
|
||||
|
||||
// In case the container creation fails, the following defer statement
|
||||
// takes care of rolling back actions previously performed.
|
||||
|
Reference in New Issue
Block a user