mirror of https://github.com/docker/docs.git
Extract ioctl from wrapper
This commit is contained in:
parent
eb528b959e
commit
1214b8897b
|
@ -3,63 +3,14 @@ package devmapper
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dotcloud/docker/utils"
|
"github.com/dotcloud/docker/utils"
|
||||||
"unsafe"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func ioctlLoopCtlGetFree(fd uintptr) (int, error) {
|
func stringToLoopName(src string) [LoNameSize]uint8 {
|
||||||
index, _, err := sysSyscall(sysSysIoctl, fd, LoopCtlGetFree, 0)
|
var dst [LoNameSize]uint8
|
||||||
if err != 0 {
|
copy(dst[:], src[:])
|
||||||
return 0, err
|
return dst
|
||||||
}
|
|
||||||
return int(index), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ioctlLoopSetFd(loopFd, sparseFd uintptr) error {
|
|
||||||
if _, _, err := sysSyscall(sysSysIoctl, loopFd, LoopSetFd, sparseFd); err != 0 {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func ioctlLoopSetStatus64(loopFd uintptr, loopInfo *LoopInfo64) error {
|
|
||||||
_, _, err := sysSyscall(sysSysIoctl, loopFd, LoopSetStatus64, uintptr(unsafe.Pointer(loopInfo)))
|
|
||||||
if err != 0 {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func ioctlLoopClrFd(loopFd uintptr) error {
|
|
||||||
_, _, err := sysSyscall(sysSysIoctl, loopFd, LoopClrFd, 0)
|
|
||||||
if err != 0 {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// //func dmGetLoopbackBackingFileFct(fd uintptr) (uint64, uint64, sysErrno) {
|
|
||||||
// func ioctlLoopGetStatus64(loopFd uintptr) (*LoopInfo64, error) {
|
|
||||||
// var lo64 C.struct_loop_info64
|
|
||||||
// _, _, err := sysSyscall(sysSysIoctl, fd, C.LOOP_GET_STATUS64, uintptr(unsafe.Pointer(&lo64)))
|
|
||||||
// return uint64(lo64.lo_device), uint64(lo64.lo_inode), sysErrno(err)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func dmLoopbackSetCapacityFct(fd uintptr) sysErrno {
|
|
||||||
// _, _, err := sysSyscall(sysSysIoctl, fd, C.LOOP_SET_CAPACITY, 0)
|
|
||||||
// return sysErrno(err)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func dmGetBlockSizeFct(fd uintptr) (int64, sysErrno) {
|
|
||||||
// var size int64
|
|
||||||
// _, _, err := sysSyscall(sysSysIoctl, fd, C.BLKGETSIZE64, uintptr(unsafe.Pointer(&size)))
|
|
||||||
// return size, sysErrno(err)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func getBlockSizeFct(fd uintptr, size *uint64) sysErrno {
|
|
||||||
// _, _, err := sysSyscall(sysSysIoctl, fd, C.BLKGETSIZE64, uintptr(unsafe.Pointer(&size)))
|
|
||||||
// return sysErrno(err)
|
|
||||||
// }
|
|
||||||
|
|
||||||
func getNextFreeLoopbackIndex() (int, error) {
|
func getNextFreeLoopbackIndex() (int, error) {
|
||||||
f, err := osOpenFile("/dev/loop-control", osORdOnly, 0644)
|
f, err := osOpenFile("/dev/loop-control", osORdOnly, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -125,12 +76,6 @@ func openNextAvailableLoopback(index int, sparseFile *osFile) (loopFile *osFile,
|
||||||
return loopFile, nil
|
return loopFile, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func stringToLoopName(src string) [LoNameSize]uint8 {
|
|
||||||
var dst [LoNameSize]uint8
|
|
||||||
copy(dst[:], src[:])
|
|
||||||
return dst
|
|
||||||
}
|
|
||||||
|
|
||||||
// attachLoopDevice attaches the given sparse file to the next
|
// attachLoopDevice attaches the given sparse file to the next
|
||||||
// available loopback device. It returns an opened *osFile.
|
// available loopback device. It returns an opened *osFile.
|
||||||
func attachLoopDevice(sparseName string) (loop *osFile, err error) {
|
func attachLoopDevice(sparseName string) (loop *osFile, err error) {
|
||||||
|
|
|
@ -178,15 +178,17 @@ func (t *Task) GetNextTarget(next uintptr) (nextPtr uintptr, start uint64,
|
||||||
}
|
}
|
||||||
|
|
||||||
func getLoopbackBackingFile(file *osFile) (uint64, uint64, error) {
|
func getLoopbackBackingFile(file *osFile) (uint64, uint64, error) {
|
||||||
dev, inode, err := DmGetLoopbackBackingFile(file.Fd())
|
loopInfo, err := ioctlLoopGetStatus64(file.Fd())
|
||||||
if err != 0 {
|
if err != nil {
|
||||||
|
utils.Errorf("Error get loopback backing file: %s\n", err)
|
||||||
return 0, 0, ErrGetLoopbackBackingFile
|
return 0, 0, ErrGetLoopbackBackingFile
|
||||||
}
|
}
|
||||||
return dev, inode, nil
|
return loopInfo.loDevice, loopInfo.loInode, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoopbackSetCapacity(file *osFile) error {
|
func LoopbackSetCapacity(file *osFile) error {
|
||||||
if err := DmLoopbackSetCapacity(file.Fd()); err != 0 {
|
if err := ioctlLoopSetCapacity(file.Fd(), 0); err != nil {
|
||||||
|
utils.Errorf("Error loopbackSetCapacity: %s", err)
|
||||||
return ErrLoopbackSetCapacity
|
return ErrLoopbackSetCapacity
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -276,8 +278,9 @@ func RemoveDevice(name string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetBlockDeviceSize(file *osFile) (uint64, error) {
|
func GetBlockDeviceSize(file *osFile) (uint64, error) {
|
||||||
size, errno := DmGetBlockSize(file.Fd())
|
size, err := ioctlBlkGetSize64(file.Fd())
|
||||||
if size == -1 || errno != 0 {
|
if err != nil {
|
||||||
|
utils.Errorf("Error getblockdevicesize: %s", err)
|
||||||
return 0, ErrGetBlockSize
|
return 0, ErrGetBlockSize
|
||||||
}
|
}
|
||||||
return uint64(size), nil
|
return uint64(size), nil
|
||||||
|
|
|
@ -34,6 +34,7 @@ import (
|
||||||
|
|
||||||
type (
|
type (
|
||||||
CDmTask C.struct_dm_task
|
CDmTask C.struct_dm_task
|
||||||
|
|
||||||
CLoopInfo64 C.struct_loop_info64
|
CLoopInfo64 C.struct_loop_info64
|
||||||
LoopInfo64 struct {
|
LoopInfo64 struct {
|
||||||
loDevice uint64 /* ioctl r/o */
|
loDevice uint64 /* ioctl r/o */
|
||||||
|
@ -56,17 +57,21 @@ type (
|
||||||
const (
|
const (
|
||||||
LoopSetFd = C.LOOP_SET_FD
|
LoopSetFd = C.LOOP_SET_FD
|
||||||
LoopCtlGetFree = C.LOOP_CTL_GET_FREE
|
LoopCtlGetFree = C.LOOP_CTL_GET_FREE
|
||||||
|
LoopGetStatus64 = C.LOOP_GET_STATUS64
|
||||||
LoopSetStatus64 = C.LOOP_SET_STATUS64
|
LoopSetStatus64 = C.LOOP_SET_STATUS64
|
||||||
LoopClrFd = C.LOOP_CLR_FD
|
LoopClrFd = C.LOOP_CLR_FD
|
||||||
|
LoopSetCapacity = C.LOOP_SET_CAPACITY
|
||||||
|
|
||||||
LoFlagsAutoClear = C.LO_FLAGS_AUTOCLEAR
|
LoFlagsAutoClear = C.LO_FLAGS_AUTOCLEAR
|
||||||
LoFlagsReadOnly = C.LO_FLAGS_READ_ONLY
|
LoFlagsReadOnly = C.LO_FLAGS_READ_ONLY
|
||||||
LoFlagsPartScan = C.LO_FLAGS_PARTSCAN
|
LoFlagsPartScan = C.LO_FLAGS_PARTSCAN
|
||||||
LoKeySize = C.LO_KEY_SIZE
|
LoKeySize = C.LO_KEY_SIZE
|
||||||
LoNameSize = C.LO_NAME_SIZE
|
LoNameSize = C.LO_NAME_SIZE
|
||||||
|
|
||||||
|
BlkGetSize64 = C.BLKGETSIZE64
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
DmGetBlockSize = dmGetBlockSizeFct
|
|
||||||
DmGetLibraryVersion = dmGetLibraryVersionFct
|
DmGetLibraryVersion = dmGetLibraryVersionFct
|
||||||
DmGetNextTarget = dmGetNextTargetFct
|
DmGetNextTarget = dmGetNextTargetFct
|
||||||
DmLogInitVerbose = dmLogInitVerboseFct
|
DmLogInitVerbose = dmLogInitVerboseFct
|
||||||
|
@ -83,10 +88,7 @@ var (
|
||||||
DmTaskSetRo = dmTaskSetRoFct
|
DmTaskSetRo = dmTaskSetRoFct
|
||||||
DmTaskSetSector = dmTaskSetSectorFct
|
DmTaskSetSector = dmTaskSetSectorFct
|
||||||
DmUdevWait = dmUdevWaitFct
|
DmUdevWait = dmUdevWaitFct
|
||||||
GetBlockSize = getBlockSizeFct
|
|
||||||
LogWithErrnoInit = logWithErrnoInitFct
|
LogWithErrnoInit = logWithErrnoInitFct
|
||||||
DmGetLoopbackBackingFile = dmGetLoopbackBackingFileFct
|
|
||||||
DmLoopbackSetCapacity = dmLoopbackSetCapacityFct
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func free(p *C.char) {
|
func free(p *C.char) {
|
||||||
|
@ -185,28 +187,6 @@ func dmGetNextTargetFct(task *CDmTask, next uintptr, start, length *uint64, targ
|
||||||
return uintptr(nextp)
|
return uintptr(nextp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func dmGetLoopbackBackingFileFct(fd uintptr) (uint64, uint64, sysErrno) {
|
|
||||||
var lo64 C.struct_loop_info64
|
|
||||||
_, _, err := sysSyscall(sysSysIoctl, fd, C.LOOP_GET_STATUS64, uintptr(unsafe.Pointer(&lo64)))
|
|
||||||
return uint64(lo64.lo_device), uint64(lo64.lo_inode), sysErrno(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func dmLoopbackSetCapacityFct(fd uintptr) sysErrno {
|
|
||||||
_, _, err := sysSyscall(sysSysIoctl, fd, C.LOOP_SET_CAPACITY, 0)
|
|
||||||
return sysErrno(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func dmGetBlockSizeFct(fd uintptr) (int64, sysErrno) {
|
|
||||||
var size int64
|
|
||||||
_, _, err := sysSyscall(sysSysIoctl, fd, C.BLKGETSIZE64, uintptr(unsafe.Pointer(&size)))
|
|
||||||
return size, sysErrno(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func getBlockSizeFct(fd uintptr, size *uint64) sysErrno {
|
|
||||||
_, _, err := sysSyscall(sysSysIoctl, fd, C.BLKGETSIZE64, uintptr(unsafe.Pointer(&size)))
|
|
||||||
return sysErrno(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func dmUdevWaitFct(cookie uint) int {
|
func dmUdevWaitFct(cookie uint) int {
|
||||||
return int(C.dm_udev_wait(C.uint32_t(cookie)))
|
return int(C.dm_udev_wait(C.uint32_t(cookie)))
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
package devmapper
|
||||||
|
|
||||||
|
import (
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ioctlLoopCtlGetFree(fd uintptr) (int, error) {
|
||||||
|
index, _, err := sysSyscall(sysSysIoctl, fd, LoopCtlGetFree, 0)
|
||||||
|
if err != 0 {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return int(index), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ioctlLoopSetFd(loopFd, sparseFd uintptr) error {
|
||||||
|
if _, _, err := sysSyscall(sysSysIoctl, loopFd, LoopSetFd, sparseFd); err != 0 {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ioctlLoopSetStatus64(loopFd uintptr, loopInfo *LoopInfo64) error {
|
||||||
|
if _, _, err := sysSyscall(sysSysIoctl, loopFd, LoopSetStatus64, uintptr(unsafe.Pointer(loopInfo))); err != 0 {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ioctlLoopClrFd(loopFd uintptr) error {
|
||||||
|
if _, _, err := sysSyscall(sysSysIoctl, loopFd, LoopClrFd, 0); err != 0 {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ioctlLoopGetStatus64(loopFd uintptr) (*LoopInfo64, error) {
|
||||||
|
loopInfo := &LoopInfo64{}
|
||||||
|
|
||||||
|
if _, _, err := sysSyscall(sysSysIoctl, loopFd, LoopGetStatus64, uintptr(unsafe.Pointer(loopInfo))); err != 0 {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return loopInfo, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ioctlLoopSetCapacity(loopFd uintptr, value int) error {
|
||||||
|
if _, _, err := sysSyscall(sysSysIoctl, loopFd, LoopSetCapacity, uintptr(value)); err != 0 {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ioctlBlkGetSize64(fd uintptr) (int64, error) {
|
||||||
|
var size int64
|
||||||
|
if _, _, err := sysSyscall(sysSysIoctl, fd, BlkGetSize64, uintptr(unsafe.Pointer(&size))); err != 0 {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return size, nil
|
||||||
|
}
|
Loading…
Reference in New Issue