mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Remove os from devmapper
This commit is contained in:
parent
5690139785
commit
a39bd65662
6 changed files with 52 additions and 44 deletions
|
@ -6,7 +6,6 @@ import (
|
||||||
"github.com/dotcloud/docker/utils"
|
"github.com/dotcloud/docker/utils"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -104,7 +103,7 @@ func (devices *DeviceSet) hasImage(name string) bool {
|
||||||
dirname := devices.loopbackDir()
|
dirname := devices.loopbackDir()
|
||||||
filename := path.Join(dirname, name)
|
filename := path.Join(dirname, name)
|
||||||
|
|
||||||
_, err := os.Stat(filename)
|
_, err := osStat(filename)
|
||||||
return err == nil
|
return err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,16 +115,16 @@ func (devices *DeviceSet) ensureImage(name string, size int64) (string, error) {
|
||||||
dirname := devices.loopbackDir()
|
dirname := devices.loopbackDir()
|
||||||
filename := path.Join(dirname, name)
|
filename := path.Join(dirname, name)
|
||||||
|
|
||||||
if err := os.MkdirAll(dirname, 0700); err != nil && !os.IsExist(err) {
|
if err := osMkdirAll(dirname, 0700); err != nil && !osIsExist(err) {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := os.Stat(filename); err != nil {
|
if _, err := osStat(filename); err != nil {
|
||||||
if !os.IsNotExist(err) {
|
if !osIsNotExist(err) {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
utils.Debugf("Creating loopback file %s for device-manage use", filename)
|
utils.Debugf("Creating loopback file %s for device-manage use", filename)
|
||||||
file, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE, 0600)
|
file, err := osOpenFile(filename, osORdWr|osOCreate, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -173,7 +172,7 @@ func (devices *DeviceSet) saveMetadata() error {
|
||||||
if err := tmpFile.Close(); err != nil {
|
if err := tmpFile.Close(); err != nil {
|
||||||
return fmt.Errorf("Error closing metadata file %s: %s", tmpFile.Name(), err)
|
return fmt.Errorf("Error closing metadata file %s: %s", tmpFile.Name(), err)
|
||||||
}
|
}
|
||||||
if err := os.Rename(tmpFile.Name(), devices.jsonFile()); err != nil {
|
if err := osRename(tmpFile.Name(), devices.jsonFile()); err != nil {
|
||||||
return fmt.Errorf("Error committing metadata file", err)
|
return fmt.Errorf("Error committing metadata file", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,7 +250,7 @@ func (devices *DeviceSet) loadMetaData() error {
|
||||||
devices.NewTransactionId = devices.TransactionId
|
devices.NewTransactionId = devices.TransactionId
|
||||||
|
|
||||||
jsonData, err := ioutil.ReadFile(devices.jsonFile())
|
jsonData, err := ioutil.ReadFile(devices.jsonFile())
|
||||||
if err != nil && !os.IsNotExist(err) {
|
if err != nil && !osIsNotExist(err) {
|
||||||
utils.Debugf("\n--->Err: %s\n", err)
|
utils.Debugf("\n--->Err: %s\n", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -336,10 +335,9 @@ func (devices *DeviceSet) setupBaseImage() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func setCloseOnExec(name string) {
|
func setCloseOnExec(name string) {
|
||||||
fileInfos, _ := ioutil.ReadDir("/proc/self/fd")
|
if fileInfos, _ := ioutil.ReadDir("/proc/self/fd"); fileInfos != nil {
|
||||||
if fileInfos != nil {
|
|
||||||
for _, i := range fileInfos {
|
for _, i := range fileInfos {
|
||||||
link, _ := os.Readlink(filepath.Join("/proc/self/fd", i.Name()))
|
link, _ := osReadlink(filepath.Join("/proc/self/fd", i.Name()))
|
||||||
if link == name {
|
if link == name {
|
||||||
fd, err := strconv.Atoi(i.Name())
|
fd, err := strconv.Atoi(i.Name())
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -371,7 +369,7 @@ func (devices *DeviceSet) ResizePool(size int64) error {
|
||||||
datafilename := path.Join(dirname, "data")
|
datafilename := path.Join(dirname, "data")
|
||||||
metadatafilename := path.Join(dirname, "metadata")
|
metadatafilename := path.Join(dirname, "metadata")
|
||||||
|
|
||||||
datafile, err := os.OpenFile(datafilename, os.O_RDWR, 0)
|
datafile, err := osOpenFile(datafilename, osORdWr, 0)
|
||||||
if datafile == nil {
|
if datafile == nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -386,19 +384,19 @@ func (devices *DeviceSet) ResizePool(size int64) error {
|
||||||
return fmt.Errorf("Can't shrink file")
|
return fmt.Errorf("Can't shrink file")
|
||||||
}
|
}
|
||||||
|
|
||||||
dataloopback := FindLoopDeviceFor(datafile)
|
dataloopback := FindLoopDeviceFor(&osFile{File: datafile})
|
||||||
if dataloopback == nil {
|
if dataloopback == nil {
|
||||||
return fmt.Errorf("Unable to find loopback mount for: %s", datafilename)
|
return fmt.Errorf("Unable to find loopback mount for: %s", datafilename)
|
||||||
}
|
}
|
||||||
defer dataloopback.Close()
|
defer dataloopback.Close()
|
||||||
|
|
||||||
metadatafile, err := os.OpenFile(metadatafilename, os.O_RDWR, 0)
|
metadatafile, err := osOpenFile(metadatafilename, osORdWr, 0)
|
||||||
if metadatafile == nil {
|
if metadatafile == nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer metadatafile.Close()
|
defer metadatafile.Close()
|
||||||
|
|
||||||
metadataloopback := FindLoopDeviceFor(metadatafile)
|
metadataloopback := FindLoopDeviceFor(&osFile{File: metadatafile})
|
||||||
if metadataloopback == nil {
|
if metadataloopback == nil {
|
||||||
return fmt.Errorf("Unable to find loopback mount for: %s", metadatafilename)
|
return fmt.Errorf("Unable to find loopback mount for: %s", metadatafilename)
|
||||||
}
|
}
|
||||||
|
@ -463,7 +461,7 @@ func (devices *DeviceSet) initDevmapper(doInit bool) error {
|
||||||
|
|
||||||
// Set the device prefix from the device id and inode of the docker root dir
|
// Set the device prefix from the device id and inode of the docker root dir
|
||||||
|
|
||||||
st, err := os.Stat(devices.root)
|
st, err := osStat(devices.root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error looking up dir %s: %s", devices.root, err)
|
return fmt.Errorf("Error looking up dir %s: %s", devices.root, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dotcloud/docker/utils"
|
"github.com/dotcloud/docker/utils"
|
||||||
"os"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -179,16 +178,16 @@ func (t *Task) GetNextTarget(next uintptr) (nextPtr uintptr, start uint64,
|
||||||
start, length, targetType, params
|
start, length, targetType, params
|
||||||
}
|
}
|
||||||
|
|
||||||
func AttachLoopDevice(filename string) (*os.File, error) {
|
func AttachLoopDevice(filename string) (*osFile, error) {
|
||||||
var fd int
|
var fd int
|
||||||
res := DmAttachLoopDevice(filename, &fd)
|
res := DmAttachLoopDevice(filename, &fd)
|
||||||
if res == "" {
|
if res == "" {
|
||||||
return nil, ErrAttachLoopbackDevice
|
return nil, ErrAttachLoopbackDevice
|
||||||
}
|
}
|
||||||
return os.NewFile(uintptr(fd), res), nil
|
return &osFile{File: osNewFile(uintptr(fd), res)}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getLoopbackBackingFile(file *os.File) (uint64, uint64, error) {
|
func getLoopbackBackingFile(file *osFile) (uint64, uint64, error) {
|
||||||
dev, inode, err := dmGetLoopbackBackingFile(file.Fd())
|
dev, inode, err := dmGetLoopbackBackingFile(file.Fd())
|
||||||
if err != 0 {
|
if err != 0 {
|
||||||
return 0, 0, ErrGetLoopbackBackingFile
|
return 0, 0, ErrGetLoopbackBackingFile
|
||||||
|
@ -196,7 +195,7 @@ func getLoopbackBackingFile(file *os.File) (uint64, uint64, error) {
|
||||||
return dev, inode, nil
|
return dev, inode, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoopbackSetCapacity(file *os.File) error {
|
func LoopbackSetCapacity(file *osFile) error {
|
||||||
err := dmLoopbackSetCapacity(file.Fd())
|
err := dmLoopbackSetCapacity(file.Fd())
|
||||||
if err != 0 {
|
if err != 0 {
|
||||||
return ErrLoopbackSetCapacity
|
return ErrLoopbackSetCapacity
|
||||||
|
@ -204,7 +203,7 @@ func LoopbackSetCapacity(file *os.File) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func FindLoopDeviceFor(file *os.File) *os.File {
|
func FindLoopDeviceFor(file *osFile) *osFile {
|
||||||
stat, err := file.Stat()
|
stat, err := file.Stat()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -215,9 +214,9 @@ func FindLoopDeviceFor(file *os.File) *os.File {
|
||||||
for i := 0; true; i++ {
|
for i := 0; true; i++ {
|
||||||
path := fmt.Sprintf("/dev/loop%d", i)
|
path := fmt.Sprintf("/dev/loop%d", i)
|
||||||
|
|
||||||
file, err := osOpenFile(path, os.O_RDWR, 0)
|
file, err := osOpenFile(path, osORdWr, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if osIsNotExist(err) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,9 +225,9 @@ func FindLoopDeviceFor(file *os.File) *os.File {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
dev, inode, err := getLoopbackBackingFile(file)
|
dev, inode, err := getLoopbackBackingFile(&osFile{File: file})
|
||||||
if err == nil && dev == targetDevice && inode == targetInode {
|
if err == nil && dev == targetDevice && inode == targetInode {
|
||||||
return file
|
return &osFile{File: file}
|
||||||
}
|
}
|
||||||
|
|
||||||
file.Close()
|
file.Close()
|
||||||
|
@ -288,7 +287,7 @@ func RemoveDevice(name string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetBlockDeviceSize(file *os.File) (uint64, error) {
|
func GetBlockDeviceSize(file *osFile) (uint64, error) {
|
||||||
size, errno := DmGetBlockSize(file.Fd())
|
size, errno := DmGetBlockSize(file.Fd())
|
||||||
if size == -1 || errno != 0 {
|
if size == -1 || errno != 0 {
|
||||||
return 0, ErrGetBlockSize
|
return 0, ErrGetBlockSize
|
||||||
|
@ -297,7 +296,7 @@ func GetBlockDeviceSize(file *os.File) (uint64, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is the programmatic example of "dmsetup create"
|
// This is the programmatic example of "dmsetup create"
|
||||||
func createPool(poolName string, dataFile *os.File, metadataFile *os.File) error {
|
func createPool(poolName string, dataFile, metadataFile *osFile) error {
|
||||||
task, err := createTask(DeviceCreate, poolName)
|
task, err := createTask(DeviceCreate, poolName)
|
||||||
if task == nil {
|
if task == nil {
|
||||||
return err
|
return err
|
||||||
|
@ -327,7 +326,7 @@ func createPool(poolName string, dataFile *os.File, metadataFile *os.File) error
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func reloadPool(poolName string, dataFile *os.File, metadataFile *os.File) error {
|
func reloadPool(poolName string, dataFile, metadataFile *osFile) error {
|
||||||
task, err := createTask(DeviceReload, poolName)
|
task, err := createTask(DeviceReload, poolName)
|
||||||
if task == nil {
|
if task == nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dotcloud/docker/graphdriver"
|
"github.com/dotcloud/docker/graphdriver"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
|
||||||
"path"
|
"path"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -67,7 +66,7 @@ func (d *Driver) Create(id string, parent string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := os.MkdirAll(path.Join(mp, "rootfs"), 0755); err != nil && !os.IsExist(err) {
|
if err := osMkdirAll(path.Join(mp, "rootfs"), 0755); err != nil && !osIsExist(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +97,7 @@ func (d *Driver) Get(id string) (string, error) {
|
||||||
|
|
||||||
func (d *Driver) mount(id, mountPoint string) error {
|
func (d *Driver) mount(id, mountPoint string) error {
|
||||||
// Create the target directories if they don't exist
|
// Create the target directories if they don't exist
|
||||||
if err := os.MkdirAll(mountPoint, 0755); err != nil && !os.IsExist(err) {
|
if err := osMkdirAll(mountPoint, 0755); err != nil && !osIsExist(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// If mountpoint is already mounted, do nothing
|
// If mountpoint is already mounted, do nothing
|
||||||
|
|
|
@ -2,7 +2,6 @@ package devmapper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
|
||||||
"path"
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
@ -34,12 +33,12 @@ func newDriver(t *testing.T) *Driver {
|
||||||
|
|
||||||
func cleanup(d *Driver) {
|
func cleanup(d *Driver) {
|
||||||
d.Cleanup()
|
d.Cleanup()
|
||||||
os.RemoveAll(d.home)
|
osRemoveAll(d.home)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInit(t *testing.T) {
|
func TestInit(t *testing.T) {
|
||||||
home := mkTestDirectory(t)
|
home := mkTestDirectory(t)
|
||||||
defer os.RemoveAll(home)
|
defer osRemoveAll(home)
|
||||||
driver, err := Init(home)
|
driver, err := Init(home)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -58,7 +57,7 @@ func TestInit(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if st, err := os.Stat(dir); err != nil {
|
if st, err := osStat(dir); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
} else if !st.IsDir() {
|
} else if !st.IsDir() {
|
||||||
t.Fatalf("Get(%V) did not return a directory", id)
|
t.Fatalf("Get(%V) did not return a directory", id)
|
||||||
|
@ -99,7 +98,7 @@ func TestDriverRemove(t *testing.T) {
|
||||||
func TestCleanup(t *testing.T) {
|
func TestCleanup(t *testing.T) {
|
||||||
t.Skip("Unimplemented")
|
t.Skip("Unimplemented")
|
||||||
d := newDriver(t)
|
d := newDriver(t)
|
||||||
defer os.RemoveAll(d.home)
|
defer osRemoveAll(d.home)
|
||||||
|
|
||||||
mountPoints := make([]string, 2)
|
mountPoints := make([]string, 2)
|
||||||
|
|
||||||
|
@ -284,7 +283,7 @@ func TestDriverGetSize(t *testing.T) {
|
||||||
|
|
||||||
size := int64(1024)
|
size := int64(1024)
|
||||||
|
|
||||||
f, err := os.Create(path.Join(mountPoint, "test_file"))
|
f, err := osCreate(path.Join(mountPoint, "test_file"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package devmapper
|
package devmapper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -9,14 +8,14 @@ import (
|
||||||
// It should be moved into the core.
|
// It should be moved into the core.
|
||||||
|
|
||||||
func Mounted(mountpoint string) (bool, error) {
|
func Mounted(mountpoint string) (bool, error) {
|
||||||
mntpoint, err := os.Stat(mountpoint)
|
mntpoint, err := osStat(mountpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if osIsNotExist(err) {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
parent, err := os.Stat(filepath.Join(mountpoint, ".."))
|
parent, err := osStat(filepath.Join(mountpoint, ".."))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,15 +8,26 @@ import (
|
||||||
type (
|
type (
|
||||||
sysStatT syscall.Stat_t
|
sysStatT syscall.Stat_t
|
||||||
sysErrno syscall.Errno
|
sysErrno syscall.Errno
|
||||||
|
|
||||||
|
osFile struct{ *os.File }
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// functions
|
|
||||||
sysMount = syscall.Mount
|
sysMount = syscall.Mount
|
||||||
sysUnmount = syscall.Unmount
|
sysUnmount = syscall.Unmount
|
||||||
sysCloseOnExec = syscall.CloseOnExec
|
sysCloseOnExec = syscall.CloseOnExec
|
||||||
sysSyscall = syscall.Syscall
|
sysSyscall = syscall.Syscall
|
||||||
osOpenFile = os.OpenFile
|
|
||||||
|
osOpenFile = os.OpenFile
|
||||||
|
osNewFile = os.NewFile
|
||||||
|
osCreate = os.Create
|
||||||
|
osStat = os.Stat
|
||||||
|
osIsNotExist = os.IsNotExist
|
||||||
|
osIsExist = os.IsExist
|
||||||
|
osMkdirAll = os.MkdirAll
|
||||||
|
osRemoveAll = os.RemoveAll
|
||||||
|
osRename = os.Rename
|
||||||
|
osReadlink = os.Readlink
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -24,6 +35,9 @@ const (
|
||||||
sysMsRdOnly = syscall.MS_RDONLY
|
sysMsRdOnly = syscall.MS_RDONLY
|
||||||
sysEInval = syscall.EINVAL
|
sysEInval = syscall.EINVAL
|
||||||
sysSysIoctl = syscall.SYS_IOCTL
|
sysSysIoctl = syscall.SYS_IOCTL
|
||||||
|
|
||||||
|
osORdWr = os.O_RDWR
|
||||||
|
osOCreate = os.O_CREATE
|
||||||
)
|
)
|
||||||
|
|
||||||
func toSysStatT(i interface{}) *sysStatT {
|
func toSysStatT(i interface{}) *sysStatT {
|
||||||
|
|
Loading…
Reference in a new issue