mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-28 00:07:16 +00:00
virtcontainers/fc: improve create disk pool process
Create a raw file and bind mount it to use it as disk is not needed, instead a the raw file can be created at the jail path and use it directly as disk, if a new container is added the real disk/device can be bind mounted in the raw file. Signed-off-by: Julio Montes <julio.montes@intel.com>
This commit is contained in:
parent
07932d59ab
commit
7e9cc5690d
@ -10,7 +10,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -493,6 +492,24 @@ func (fc *firecracker) client() *client.Firecracker {
|
|||||||
return fc.connection
|
return fc.connection
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fc *firecracker) createJailedDrive(name string) (string, error) {
|
||||||
|
// Don't bind mount the resource, just create a raw file
|
||||||
|
// that can be bind-mounted later
|
||||||
|
r := filepath.Join(fc.jailerRoot, name)
|
||||||
|
f, err := os.Create(r)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
f.Close()
|
||||||
|
|
||||||
|
if fc.jailed {
|
||||||
|
// use path relative to the jail
|
||||||
|
r = filepath.Join("/", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
return r, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (fc *firecracker) fcJailResource(src, dst string) (string, error) {
|
func (fc *firecracker) fcJailResource(src, dst string) (string, error) {
|
||||||
if src == "" || dst == "" {
|
if src == "" || dst == "" {
|
||||||
return "", fmt.Errorf("fcJailResource: invalid jail locations: src:%v, dst:%v",
|
return "", fmt.Errorf("fcJailResource: invalid jail locations: src:%v, dst:%v",
|
||||||
@ -652,7 +669,9 @@ func (fc *firecracker) startSandbox(timeout int) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fc.fcSetVMRootfs(image)
|
fc.fcSetVMRootfs(image)
|
||||||
fc.createDiskPool()
|
if err := fc.createDiskPool(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
for _, d := range fc.pendingDevices {
|
for _, d := range fc.pendingDevices {
|
||||||
if err = fc.addDevice(d.dev, d.devType); err != nil {
|
if err = fc.addDevice(d.dev, d.devType); err != nil {
|
||||||
@ -683,24 +702,11 @@ func (fc *firecracker) createDiskPool() error {
|
|||||||
isRootDevice := false
|
isRootDevice := false
|
||||||
|
|
||||||
// Create a temporary file as a placeholder backend for the drive
|
// Create a temporary file as a placeholder backend for the drive
|
||||||
//hostURL, err := fc.store.Raw("")
|
jailedDrive, err := fc.createJailedDrive(driveID)
|
||||||
hostURL, err := fc.store.Raw(driveID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// We get a full URL from Raw(), we need to parse it.
|
|
||||||
u, err := url.Parse(hostURL)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
jailedDrive, err := fc.fcJailResource(u.Path, driveID)
|
|
||||||
if err != nil {
|
|
||||||
fc.Logger().WithField("createDiskPool failed", err).Error()
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
drive := &models.Drive{
|
drive := &models.Drive{
|
||||||
DriveID: &driveID,
|
DriveID: &driveID,
|
||||||
IsReadOnly: &isReadOnly,
|
IsReadOnly: &isReadOnly,
|
||||||
@ -734,17 +740,6 @@ func (fc *firecracker) cleanupJail() {
|
|||||||
fc.umountResource(fcKernel)
|
fc.umountResource(fcKernel)
|
||||||
fc.umountResource(fcRootfs)
|
fc.umountResource(fcRootfs)
|
||||||
|
|
||||||
for i := 0; i < fcDiskPoolSize; i++ {
|
|
||||||
fc.umountResource(fcDriveIndexToID(i))
|
|
||||||
}
|
|
||||||
|
|
||||||
//Run through the list second time as may have bindmounted
|
|
||||||
//to the same location twice. In the future this needs to
|
|
||||||
//be tracked so that we do not do this blindly
|
|
||||||
for i := 0; i < fcDiskPoolSize; i++ {
|
|
||||||
fc.umountResource(fcDriveIndexToID(i))
|
|
||||||
}
|
|
||||||
|
|
||||||
fc.Logger().WithField("cleaningJail", fc.vmPath).Info()
|
fc.Logger().WithField("cleaningJail", fc.vmPath).Info()
|
||||||
if err := os.RemoveAll(fc.vmPath); err != nil {
|
if err := os.RemoveAll(fc.vmPath); err != nil {
|
||||||
fc.Logger().WithField("cleanupJail failed", err).Error()
|
fc.Logger().WithField("cleanupJail failed", err).Error()
|
||||||
|
Loading…
Reference in New Issue
Block a user