!10 syscontainer-tools: do not create device soft link in /dev

Merge pull request !10 from zhangsong234/master
This commit is contained in:
openeuler-ci-bot 2020-03-23 15:34:13 +08:00 committed by Gitee
commit 397cd53e92

View File

@ -18,15 +18,16 @@ package libdevice
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/mrunalp/fileutils"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
"isula.org/syscontainer-tools/types"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"strings" "strings"
"syscall" "syscall"
"github.com/mrunalp/fileutils"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
"isula.org/syscontainer-tools/types"
) )
var ( var (
@ -286,7 +287,6 @@ func AddDeviceToSysBlock(node *types.Device) error {
if err != nil { if err != nil {
return err return err
} }
hostDeviceName := filepath.Base(realPath)
containerDeviceName := filepath.Base(node.Path) containerDeviceName := filepath.Base(node.Path)
if err := os.Chdir(filepath.Join(node.Root, MountSourcePath)); err != nil { if err := os.Chdir(filepath.Join(node.Root, MountSourcePath)); err != nil {
return err return err
@ -303,14 +303,6 @@ func AddDeviceToSysBlock(node *types.Device) error {
if err := os.Symlink(destPath, containerDeviceName); err != nil { if err := os.Symlink(destPath, containerDeviceName); err != nil {
return err return err
} }
if err := os.Chdir(filepath.Join(node.Root, "/dev")); err != nil {
return err
}
if hostDeviceName != containerDeviceName {
if _, err := os.Stat(hostDeviceName); os.IsNotExist(err) {
return os.Symlink(containerDeviceName, hostDeviceName)
}
}
return nil return nil
} }
@ -318,20 +310,11 @@ func AddDeviceToSysBlock(node *types.Device) error {
func RemoveDeviceFromSysBlock(path string) error { func RemoveDeviceFromSysBlock(path string) error {
containerDeviceName := filepath.Base(path) containerDeviceName := filepath.Base(path)
linkPath := filepath.Join(MountDestPath, containerDeviceName) linkPath := filepath.Join(MountDestPath, containerDeviceName)
realPath, err := os.Readlink(linkPath)
if err != nil {
return err
}
hostDeviceName := filepath.Base(realPath)
devPath := filepath.Join("/dev", hostDeviceName)
if _, err := os.Lstat(linkPath); err == nil { if _, err := os.Lstat(linkPath); err == nil {
if err := os.Remove(linkPath); err != nil { if err := os.Remove(linkPath); err != nil {
return err return err
} }
} }
if hostDeviceName != containerDeviceName {
return os.Remove(devPath)
}
return nil return nil
} }