1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Use variable to call functions in devmapper_wrapper + some formatting

This commit is contained in:
Guillaume J. Charmes 2013-11-20 11:39:15 -08:00
parent 437bdeee59
commit 79e2b33ede
No known key found for this signature in database
GPG key ID: B33E4642CB6E3FF3
3 changed files with 33 additions and 41 deletions

View file

@ -187,7 +187,7 @@ func AttachLoopDevice(filename string) (*osFile, error) {
}
func getLoopbackBackingFile(file *osFile) (uint64, uint64, error) {
dev, inode, err := dmGetLoopbackBackingFile(file.Fd())
dev, inode, err := DmGetLoopbackBackingFile(file.Fd())
if err != 0 {
return 0, 0, ErrGetLoopbackBackingFile
}
@ -195,8 +195,7 @@ func getLoopbackBackingFile(file *osFile) (uint64, uint64, error) {
}
func LoopbackSetCapacity(file *osFile) error {
err := dmLoopbackSetCapacity(file.Fd())
if err != 0 {
if err := DmLoopbackSetCapacity(file.Fd()); err != 0 {
return ErrLoopbackSetCapacity
}
return nil

View file

@ -148,26 +148,28 @@ type (
)
var (
DmAttachLoopDevice = dmAttachLoopDeviceFct
DmGetBlockSize = dmGetBlockSizeFct
DmGetLibraryVersion = dmGetLibraryVersionFct
DmGetNextTarget = dmGetNextTargetFct
DmLogInitVerbose = dmLogInitVerboseFct
DmSetDevDir = dmSetDevDirFct
DmTaskAddTarget = dmTaskAddTargetFct
DmTaskCreate = dmTaskCreateFct
DmTaskDestroy = dmTaskDestroyFct
DmTaskGetInfo = dmTaskGetInfoFct
DmTaskRun = dmTaskRunFct
DmTaskSetAddNode = dmTaskSetAddNodeFct
DmTaskSetCookie = dmTaskSetCookieFct
DmTaskSetMessage = dmTaskSetMessageFct
DmTaskSetName = dmTaskSetNameFct
DmTaskSetRo = dmTaskSetRoFct
DmTaskSetSector = dmTaskSetSectorFct
DmUdevWait = dmUdevWaitFct
GetBlockSize = getBlockSizeFct
LogWithErrnoInit = logWithErrnoInitFct
DmAttachLoopDevice = dmAttachLoopDeviceFct
DmGetBlockSize = dmGetBlockSizeFct
DmGetLibraryVersion = dmGetLibraryVersionFct
DmGetNextTarget = dmGetNextTargetFct
DmLogInitVerbose = dmLogInitVerboseFct
DmSetDevDir = dmSetDevDirFct
DmTaskAddTarget = dmTaskAddTargetFct
DmTaskCreate = dmTaskCreateFct
DmTaskDestroy = dmTaskDestroyFct
DmTaskGetInfo = dmTaskGetInfoFct
DmTaskRun = dmTaskRunFct
DmTaskSetAddNode = dmTaskSetAddNodeFct
DmTaskSetCookie = dmTaskSetCookieFct
DmTaskSetMessage = dmTaskSetMessageFct
DmTaskSetName = dmTaskSetNameFct
DmTaskSetRo = dmTaskSetRoFct
DmTaskSetSector = dmTaskSetSectorFct
DmUdevWait = dmUdevWaitFct
GetBlockSize = getBlockSizeFct
LogWithErrnoInit = logWithErrnoInitFct
DmGetLoopbackBackingFile = dmGetLoopbackBackingFileFct
DmLoopbackSetCapacity = dmLoopbackSetCapacityFct
)
func free(p *C.char) {
@ -238,14 +240,14 @@ func dmTaskAddTargetFct(task *CDmTask,
C.uint64_t(start), C.uint64_t(size), Cttype, Cparams))
}
func dmGetLoopbackBackingFile(fd uintptr) (uint64, uint64, sysErrno) {
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 dmLoopbackSetCapacity(fd uintptr) sysErrno {
func dmLoopbackSetCapacityFct(fd uintptr) sysErrno {
_, _, err := sysSyscall(sysSysIoctl, fd, C.LOOP_SET_CAPACITY, 0)
return sysErrno(err)
}

View file

@ -8,8 +8,6 @@ import (
"path"
)
var DefaultDriver string
type InitFunc func(root string) (Driver, error)
type Driver interface {
@ -34,6 +32,7 @@ type Differ interface {
}
var (
DefaultDriver string
// All registred drivers
drivers map[string]InitFunc
// Slice of drivers that should be used in an order
@ -64,14 +63,8 @@ func GetDriver(name, home string) (Driver, error) {
return nil, fmt.Errorf("No such driver: %s", name)
}
func New(root string) (Driver, error) {
var driver Driver
var lastError error
for _, name := range []string{
os.Getenv("DOCKER_DRIVER"),
DefaultDriver,
} {
func New(root string) (driver Driver, err error) {
for _, name := range []string{os.Getenv("DOCKER_DRIVER"), DefaultDriver} {
if name != "" {
return GetDriver(name, root)
}
@ -79,9 +72,8 @@ func New(root string) (Driver, error) {
// Check for priority drivers first
for _, name := range priority {
driver, lastError = GetDriver(name, root)
if lastError != nil {
utils.Debugf("Error loading driver %s: %s", name, lastError)
if driver, err = GetDriver(name, root); err != nil {
utils.Debugf("Error loading driver %s: %s", name, err)
continue
}
return driver, nil
@ -89,11 +81,10 @@ func New(root string) (Driver, error) {
// Check all registered drivers if no priority driver is found
for _, initFunc := range drivers {
driver, lastError = initFunc(root)
if lastError != nil {
if driver, err = initFunc(root); err != nil {
continue
}
return driver, nil
}
return nil, lastError
return nil, err
}