Merge pull request #8986 from vbatts/vbatts-pkg_devicemapper_bindings

devicemapper: split out devicemapper bindings
This commit is contained in:
Vincent Batts 2014-11-12 19:59:36 -05:00
Родитель 9670871e01 e2f8fbfbcc
Коммит 42861f3b45
7 изменённых файлов: 87 добавлений и 82 удалений

Просмотреть файл

@ -20,6 +20,7 @@ import (
log "github.com/Sirupsen/logrus" log "github.com/Sirupsen/logrus"
"github.com/docker/docker/daemon/graphdriver" "github.com/docker/docker/daemon/graphdriver"
"github.com/docker/docker/pkg/devicemapper"
"github.com/docker/docker/pkg/parsers" "github.com/docker/docker/pkg/parsers"
"github.com/docker/docker/pkg/units" "github.com/docker/docker/pkg/units"
"github.com/docker/libcontainer/label" "github.com/docker/libcontainer/label"
@ -243,7 +244,7 @@ func (devices *DeviceSet) saveMetadata(info *DevInfo) error {
} }
if devices.NewTransactionId != devices.TransactionId { if devices.NewTransactionId != devices.TransactionId {
if err = setTransactionId(devices.getPoolDevName(), devices.TransactionId, devices.NewTransactionId); err != nil { if err = devicemapper.SetTransactionId(devices.getPoolDevName(), devices.TransactionId, devices.NewTransactionId); err != nil {
return fmt.Errorf("Error setting devmapper transition ID: %s", err) return fmt.Errorf("Error setting devmapper transition ID: %s", err)
} }
devices.TransactionId = devices.NewTransactionId devices.TransactionId = devices.NewTransactionId
@ -295,11 +296,11 @@ func (devices *DeviceSet) registerDevice(id int, hash string, size uint64) (*Dev
func (devices *DeviceSet) activateDeviceIfNeeded(info *DevInfo) error { func (devices *DeviceSet) activateDeviceIfNeeded(info *DevInfo) error {
log.Debugf("activateDeviceIfNeeded(%v)", info.Hash) log.Debugf("activateDeviceIfNeeded(%v)", info.Hash)
if devinfo, _ := getInfo(info.Name()); devinfo != nil && devinfo.Exists != 0 { if devinfo, _ := devicemapper.GetInfo(info.Name()); devinfo != nil && devinfo.Exists != 0 {
return nil return nil
} }
return activateDevice(devices.getPoolDevName(), info.Name(), info.DeviceId, info.Size) return devicemapper.ActivateDevice(devices.getPoolDevName(), info.Name(), info.DeviceId, info.Size)
} }
func (devices *DeviceSet) createFilesystem(info *DevInfo) error { func (devices *DeviceSet) createFilesystem(info *DevInfo) error {
@ -336,7 +337,7 @@ func (devices *DeviceSet) createFilesystem(info *DevInfo) error {
} }
func (devices *DeviceSet) initMetaData() error { func (devices *DeviceSet) initMetaData() error {
_, _, _, params, err := getStatus(devices.getPoolName()) _, _, _, params, err := devicemapper.GetStatus(devices.getPoolName())
if err != nil { if err != nil {
return err return err
} }
@ -415,7 +416,7 @@ func (devices *DeviceSet) setupBaseImage() error {
id := devices.NextDeviceId id := devices.NextDeviceId
// Create initial device // Create initial device
if err := createDevice(devices.getPoolDevName(), &id); err != nil { if err := devicemapper.CreateDevice(devices.getPoolDevName(), &id); err != nil {
return err return err
} }
@ -425,7 +426,7 @@ func (devices *DeviceSet) setupBaseImage() error {
log.Debugf("Registering base device (id %v) with FS size %v", id, devices.baseFsSize) log.Debugf("Registering base device (id %v) with FS size %v", id, devices.baseFsSize)
info, err := devices.registerDevice(id, "", devices.baseFsSize) info, err := devices.registerDevice(id, "", devices.baseFsSize)
if err != nil { if err != nil {
_ = deleteDevice(devices.getPoolDevName(), id) _ = devicemapper.DeleteDevice(devices.getPoolDevName(), id)
return err return err
} }
@ -462,11 +463,12 @@ func setCloseOnExec(name string) {
} }
} }
func (devices *DeviceSet) log(level int, file string, line int, dmError int, message string) { func (devices *DeviceSet) DMLog(level int, file string, line int, dmError int, message string) {
if level >= 7 { if level >= 7 {
return // Ignore _LOG_DEBUG return // Ignore _LOG_DEBUG
} }
// FIXME(vbatts) push this back into ./pkg/devicemapper/
log.Debugf("libdevmapper(%d): %s:%d (%d) %s", level, file, line, dmError, message) log.Debugf("libdevmapper(%d): %s:%d (%d) %s", level, file, line, dmError, message)
} }
@ -504,7 +506,7 @@ 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 := devicemapper.FindLoopDeviceFor(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)
} }
@ -516,7 +518,7 @@ func (devices *DeviceSet) ResizePool(size int64) error {
} }
defer metadatafile.Close() defer metadatafile.Close()
metadataloopback := FindLoopDeviceFor(metadatafile) metadataloopback := devicemapper.FindLoopDeviceFor(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)
} }
@ -528,22 +530,22 @@ func (devices *DeviceSet) ResizePool(size int64) error {
} }
// Reload size for loopback device // Reload size for loopback device
if err := LoopbackSetCapacity(dataloopback); err != nil { if err := devicemapper.LoopbackSetCapacity(dataloopback); err != nil {
return fmt.Errorf("Unable to update loopback capacity: %s", err) return fmt.Errorf("Unable to update loopback capacity: %s", err)
} }
// Suspend the pool // Suspend the pool
if err := suspendDevice(devices.getPoolName()); err != nil { if err := devicemapper.SuspendDevice(devices.getPoolName()); err != nil {
return fmt.Errorf("Unable to suspend pool: %s", err) return fmt.Errorf("Unable to suspend pool: %s", err)
} }
// Reload with the new block sizes // Reload with the new block sizes
if err := reloadPool(devices.getPoolName(), dataloopback, metadataloopback, devices.thinpBlockSize); err != nil { if err := devicemapper.ReloadPool(devices.getPoolName(), dataloopback, metadataloopback, devices.thinpBlockSize); err != nil {
return fmt.Errorf("Unable to reload pool: %s", err) return fmt.Errorf("Unable to reload pool: %s", err)
} }
// Resume the pool // Resume the pool
if err := resumeDevice(devices.getPoolName()); err != nil { if err := devicemapper.ResumeDevice(devices.getPoolName()); err != nil {
return fmt.Errorf("Unable to resume pool: %s", err) return fmt.Errorf("Unable to resume pool: %s", err)
} }
@ -574,9 +576,10 @@ func (devices *DeviceSet) saveDeviceSetMetaData() error {
} }
func (devices *DeviceSet) initDevmapper(doInit bool) error { func (devices *DeviceSet) initDevmapper(doInit bool) error {
logInit(devices) // give ourselves to libdm as a log handler
devicemapper.LogInit(devices)
_, err := getDriverVersion() _, err := devicemapper.GetDriverVersion()
if err != nil { if err != nil {
// Can't even get driver version, assume not supported // Can't even get driver version, assume not supported
return graphdriver.ErrNotSupported return graphdriver.ErrNotSupported
@ -604,9 +607,9 @@ func (devices *DeviceSet) initDevmapper(doInit bool) error {
// Check for the existence of the device <prefix>-pool // Check for the existence of the device <prefix>-pool
log.Debugf("Checking for existence of the pool '%s'", devices.getPoolName()) log.Debugf("Checking for existence of the pool '%s'", devices.getPoolName())
info, err := getInfo(devices.getPoolName()) info, err := devicemapper.GetInfo(devices.getPoolName())
if info == nil { if info == nil {
log.Debugf("Error device getInfo: %s", err) log.Debugf("Error device devicemapper.GetInfo: %s", err)
return err return err
} }
@ -648,7 +651,7 @@ func (devices *DeviceSet) initDevmapper(doInit bool) error {
return err return err
} }
dataFile, err = attachLoopDevice(data) dataFile, err = devicemapper.AttachLoopDevice(data)
if err != nil { if err != nil {
return err return err
} }
@ -679,7 +682,7 @@ func (devices *DeviceSet) initDevmapper(doInit bool) error {
return err return err
} }
metadataFile, err = attachLoopDevice(metadata) metadataFile, err = devicemapper.AttachLoopDevice(metadata)
if err != nil { if err != nil {
return err return err
} }
@ -691,7 +694,7 @@ func (devices *DeviceSet) initDevmapper(doInit bool) error {
} }
defer metadataFile.Close() defer metadataFile.Close()
if err := createPool(devices.getPoolName(), dataFile, metadataFile, devices.thinpBlockSize); err != nil { if err := devicemapper.CreatePool(devices.getPoolName(), dataFile, metadataFile, devices.thinpBlockSize); err != nil {
return err return err
} }
} }
@ -739,7 +742,7 @@ func (devices *DeviceSet) AddDevice(hash, baseHash string) error {
deviceId := devices.NextDeviceId deviceId := devices.NextDeviceId
if err := createSnapDevice(devices.getPoolDevName(), &deviceId, baseInfo.Name(), baseInfo.DeviceId); err != nil { if err := devicemapper.CreateSnapDevice(devices.getPoolDevName(), &deviceId, baseInfo.Name(), baseInfo.DeviceId); err != nil {
log.Debugf("Error creating snap device: %s", err) log.Debugf("Error creating snap device: %s", err)
return err return err
} }
@ -748,7 +751,7 @@ func (devices *DeviceSet) AddDevice(hash, baseHash string) error {
devices.NextDeviceId = (deviceId + 1) & 0xffffff devices.NextDeviceId = (deviceId + 1) & 0xffffff
if _, err := devices.registerDevice(deviceId, hash, baseInfo.Size); err != nil { if _, err := devices.registerDevice(deviceId, hash, baseInfo.Size); err != nil {
deleteDevice(devices.getPoolDevName(), deviceId) devicemapper.DeleteDevice(devices.getPoolDevName(), deviceId)
log.Debugf("Error registering device: %s", err) log.Debugf("Error registering device: %s", err)
return err return err
} }
@ -761,13 +764,13 @@ func (devices *DeviceSet) deleteDevice(info *DevInfo) error {
// on the thin pool when we remove a thinp device, so we do it // on the thin pool when we remove a thinp device, so we do it
// manually // manually
if err := devices.activateDeviceIfNeeded(info); err == nil { if err := devices.activateDeviceIfNeeded(info); err == nil {
if err := BlockDeviceDiscard(info.DevName()); err != nil { if err := devicemapper.BlockDeviceDiscard(info.DevName()); err != nil {
log.Debugf("Error discarding block on device: %s (ignoring)", err) log.Debugf("Error discarding block on device: %s (ignoring)", err)
} }
} }
} }
devinfo, _ := getInfo(info.Name()) devinfo, _ := devicemapper.GetInfo(info.Name())
if devinfo != nil && devinfo.Exists != 0 { if devinfo != nil && devinfo.Exists != 0 {
if err := devices.removeDeviceAndWait(info.Name()); err != nil { if err := devices.removeDeviceAndWait(info.Name()); err != nil {
log.Debugf("Error removing device: %s", err) log.Debugf("Error removing device: %s", err)
@ -775,7 +778,7 @@ func (devices *DeviceSet) deleteDevice(info *DevInfo) error {
} }
} }
if err := deleteDevice(devices.getPoolDevName(), info.DeviceId); err != nil { if err := devicemapper.DeleteDevice(devices.getPoolDevName(), info.DeviceId); err != nil {
log.Debugf("Error deleting device: %s", err) log.Debugf("Error deleting device: %s", err)
return err return err
} }
@ -816,16 +819,16 @@ func (devices *DeviceSet) deactivatePool() error {
defer log.Debugf("[devmapper] deactivatePool END") defer log.Debugf("[devmapper] deactivatePool END")
devname := devices.getPoolDevName() devname := devices.getPoolDevName()
devinfo, err := getInfo(devname) devinfo, err := devicemapper.GetInfo(devname)
if err != nil { if err != nil {
return err return err
} }
if d, err := getDeps(devname); err == nil { if d, err := devicemapper.GetDeps(devname); err == nil {
// Access to more Debug output // Access to more Debug output
log.Debugf("[devmapper] getDeps() %s: %#v", devname, d) log.Debugf("[devmapper] devicemapper.GetDeps() %s: %#v", devname, d)
} }
if devinfo.Exists != 0 { if devinfo.Exists != 0 {
return removeDevice(devname) return devicemapper.RemoveDevice(devname)
} }
return nil return nil
@ -841,7 +844,7 @@ func (devices *DeviceSet) deactivateDevice(info *DevInfo) error {
log.Errorf("Warning: error waiting for device %s to close: %s", info.Hash, err) log.Errorf("Warning: error waiting for device %s to close: %s", info.Hash, err)
} }
devinfo, err := getInfo(info.Name()) devinfo, err := devicemapper.GetInfo(info.Name())
if err != nil { if err != nil {
return err return err
} }
@ -860,11 +863,11 @@ func (devices *DeviceSet) removeDeviceAndWait(devname string) error {
var err error var err error
for i := 0; i < 1000; i++ { for i := 0; i < 1000; i++ {
err = removeDevice(devname) err = devicemapper.RemoveDevice(devname)
if err == nil { if err == nil {
break break
} }
if err != ErrBusy { if err != devicemapper.ErrBusy {
return err return err
} }
@ -892,7 +895,7 @@ func (devices *DeviceSet) waitRemove(devname string) error {
defer log.Debugf("[deviceset %s] waitRemove(%s) END", devices.devicePrefix, devname) defer log.Debugf("[deviceset %s] waitRemove(%s) END", devices.devicePrefix, devname)
i := 0 i := 0
for ; i < 1000; i++ { for ; i < 1000; i++ {
devinfo, err := getInfo(devname) devinfo, err := devicemapper.GetInfo(devname)
if err != nil { if err != nil {
// If there is an error we assume the device doesn't exist. // If there is an error we assume the device doesn't exist.
// The error might actually be something else, but we can't differentiate. // The error might actually be something else, but we can't differentiate.
@ -921,7 +924,7 @@ func (devices *DeviceSet) waitRemove(devname string) error {
func (devices *DeviceSet) waitClose(info *DevInfo) error { func (devices *DeviceSet) waitClose(info *DevInfo) error {
i := 0 i := 0
for ; i < 1000; i++ { for ; i < 1000; i++ {
devinfo, err := getInfo(info.Name()) devinfo, err := devicemapper.GetInfo(info.Name())
if err != nil { if err != nil {
return err return err
} }
@ -942,7 +945,6 @@ func (devices *DeviceSet) waitClose(info *DevInfo) error {
} }
func (devices *DeviceSet) Shutdown() error { func (devices *DeviceSet) Shutdown() error {
log.Debugf("[deviceset %s] shutdown()", devices.devicePrefix) log.Debugf("[deviceset %s] shutdown()", devices.devicePrefix)
log.Debugf("[devmapper] Shutting down DeviceSet: %s", devices.root) log.Debugf("[devmapper] Shutting down DeviceSet: %s", devices.root)
defer log.Debugf("[deviceset %s] shutdown END", devices.devicePrefix) defer log.Debugf("[deviceset %s] shutdown END", devices.devicePrefix)
@ -1111,7 +1113,7 @@ func (devices *DeviceSet) HasActivatedDevice(hash string) bool {
devices.Lock() devices.Lock()
defer devices.Unlock() defer devices.Unlock()
devinfo, _ := getInfo(info.Name()) devinfo, _ := devicemapper.GetInfo(info.Name())
return devinfo != nil && devinfo.Exists != 0 return devinfo != nil && devinfo.Exists != 0
} }
@ -1133,7 +1135,7 @@ func (devices *DeviceSet) List() []string {
func (devices *DeviceSet) deviceStatus(devName string) (sizeInSectors, mappedSectors, highestMappedSector uint64, err error) { func (devices *DeviceSet) deviceStatus(devName string) (sizeInSectors, mappedSectors, highestMappedSector uint64, err error) {
var params string var params string
_, sizeInSectors, _, params, err = getStatus(devName) _, sizeInSectors, _, params, err = devicemapper.GetStatus(devName)
if err != nil { if err != nil {
return return
} }
@ -1178,7 +1180,7 @@ func (devices *DeviceSet) GetDeviceStatus(hash string) (*DevStatus, error) {
func (devices *DeviceSet) poolStatus() (totalSizeInSectors, transactionId, dataUsed, dataTotal, metadataUsed, metadataTotal uint64, err error) { func (devices *DeviceSet) poolStatus() (totalSizeInSectors, transactionId, dataUsed, dataTotal, metadataUsed, metadataTotal uint64, err error) {
var params string var params string
if _, totalSizeInSectors, _, params, err = getStatus(devices.getPoolName()); err == nil { if _, totalSizeInSectors, _, params, err = devicemapper.GetStatus(devices.getPoolName()); err == nil {
_, err = fmt.Sscanf(params, "%d %d/%d %d/%d", &transactionId, &metadataUsed, &metadataTotal, &dataUsed, &dataTotal) _, err = fmt.Sscanf(params, "%d %d/%d %d/%d", &transactionId, &metadataUsed, &metadataTotal, &dataUsed, &dataTotal)
} }
return return
@ -1221,7 +1223,7 @@ func (devices *DeviceSet) Status() *Status {
} }
func NewDeviceSet(root string, doInit bool, options []string) (*DeviceSet, error) { func NewDeviceSet(root string, doInit bool, options []string) (*DeviceSet, error) {
SetDevDir("/dev") devicemapper.SetDevDir("/dev")
devices := &DeviceSet{ devices := &DeviceSet{
root: root, root: root,

Просмотреть файл

@ -10,6 +10,7 @@ import (
log "github.com/Sirupsen/logrus" log "github.com/Sirupsen/logrus"
"github.com/docker/docker/daemon/graphdriver" "github.com/docker/docker/daemon/graphdriver"
"github.com/docker/docker/pkg/devicemapper"
"github.com/docker/docker/pkg/mount" "github.com/docker/docker/pkg/mount"
"github.com/docker/docker/pkg/units" "github.com/docker/docker/pkg/units"
) )
@ -63,7 +64,7 @@ func (d *Driver) Status() [][2]string {
{"Metadata Space Used", fmt.Sprintf("%s", units.HumanSize(int64(s.Metadata.Used)))}, {"Metadata Space Used", fmt.Sprintf("%s", units.HumanSize(int64(s.Metadata.Used)))},
{"Metadata Space Total", fmt.Sprintf("%s", units.HumanSize(int64(s.Metadata.Total)))}, {"Metadata Space Total", fmt.Sprintf("%s", units.HumanSize(int64(s.Metadata.Total)))},
} }
if vStr, err := GetLibraryVersion(); err == nil { if vStr, err := devicemapper.GetLibraryVersion(); err == nil {
status = append(status, [2]string{"Library Version", vStr}) status = append(status, [2]string{"Library Version", vStr})
} }
return status return status

Просмотреть файл

@ -1,6 +1,6 @@
// +build linux // +build linux
package devmapper package devicemapper
import ( import (
"fmt" "fmt"
@ -84,7 +84,7 @@ func openNextAvailableLoopback(index int, sparseFile *os.File) (loopFile *os.Fil
// 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 *os.File. // available loopback device. It returns an opened *os.File.
func attachLoopDevice(sparseName string) (loop *os.File, err error) { func AttachLoopDevice(sparseName string) (loop *os.File, err error) {
// Try to retrieve the next available loopback device via syscall. // Try to retrieve the next available loopback device via syscall.
// If it fails, we discard error and start loopking for a // If it fails, we discard error and start loopking for a

Просмотреть файл

@ -1,6 +1,6 @@
// +build linux // +build linux
package devmapper package devicemapper
import ( import (
"errors" "errors"
@ -13,7 +13,7 @@ import (
) )
type DevmapperLogger interface { type DevmapperLogger interface {
log(level int, file string, line int, dmError int, message string) DMLog(level int, file string, line int, dmError int, message string)
} }
const ( const (
@ -272,7 +272,8 @@ func LogInitVerbose(level int) {
var dmLogger DevmapperLogger = nil var dmLogger DevmapperLogger = nil
func logInit(logger DevmapperLogger) { // initialize the logger for the device mapper library
func LogInit(logger DevmapperLogger) {
dmLogger = logger dmLogger = logger
LogWithErrnoInit() LogWithErrnoInit()
} }
@ -295,6 +296,7 @@ func GetLibraryVersion() (string, error) {
// Useful helper for cleanup // Useful helper for cleanup
func RemoveDevice(name string) error { func RemoveDevice(name string) error {
// TODO(vbatts) just use the other removeDevice()
task := TaskCreate(DeviceRemove) task := TaskCreate(DeviceRemove)
if task == nil { if task == nil {
return ErrCreateRemoveTask return ErrCreateRemoveTask
@ -342,7 +344,7 @@ func BlockDeviceDiscard(path string) error {
} }
// This is the programmatic example of "dmsetup create" // This is the programmatic example of "dmsetup create"
func createPool(poolName string, dataFile, metadataFile *os.File, poolBlockSize uint32) error { func CreatePool(poolName string, dataFile, metadataFile *os.File, poolBlockSize uint32) error {
task, err := createTask(DeviceCreate, poolName) task, err := createTask(DeviceCreate, poolName)
if task == nil { if task == nil {
return err return err
@ -364,7 +366,7 @@ func createPool(poolName string, dataFile, metadataFile *os.File, poolBlockSize
} }
if err := task.Run(); err != nil { if err := task.Run(); err != nil {
return fmt.Errorf("Error running DeviceCreate (createPool) %s", err) return fmt.Errorf("Error running DeviceCreate (CreatePool) %s", err)
} }
UdevWait(cookie) UdevWait(cookie)
@ -372,7 +374,7 @@ func createPool(poolName string, dataFile, metadataFile *os.File, poolBlockSize
return nil return nil
} }
func reloadPool(poolName string, dataFile, metadataFile *os.File, poolBlockSize uint32) error { func ReloadPool(poolName string, dataFile, metadataFile *os.File, poolBlockSize uint32) error {
task, err := createTask(DeviceReload, poolName) task, err := createTask(DeviceReload, poolName)
if task == nil { if task == nil {
return err return err
@ -406,7 +408,7 @@ func createTask(t TaskType, name string) (*Task, error) {
return task, nil return task, nil
} }
func getDeps(name string) (*Deps, error) { func GetDeps(name string) (*Deps, error) {
task, err := createTask(DeviceDeps, name) task, err := createTask(DeviceDeps, name)
if task == nil { if task == nil {
return nil, err return nil, err
@ -417,7 +419,7 @@ func getDeps(name string) (*Deps, error) {
return task.GetDeps() return task.GetDeps()
} }
func getInfo(name string) (*Info, error) { func GetInfo(name string) (*Info, error) {
task, err := createTask(DeviceInfo, name) task, err := createTask(DeviceInfo, name)
if task == nil { if task == nil {
return nil, err return nil, err
@ -428,7 +430,7 @@ func getInfo(name string) (*Info, error) {
return task.GetInfo() return task.GetInfo()
} }
func getDriverVersion() (string, error) { func GetDriverVersion() (string, error) {
task := TaskCreate(DeviceVersion) task := TaskCreate(DeviceVersion)
if task == nil { if task == nil {
return "", fmt.Errorf("Can't create DeviceVersion task") return "", fmt.Errorf("Can't create DeviceVersion task")
@ -439,24 +441,24 @@ func getDriverVersion() (string, error) {
return task.GetDriverVersion() return task.GetDriverVersion()
} }
func getStatus(name string) (uint64, uint64, string, string, error) { func GetStatus(name string) (uint64, uint64, string, string, error) {
task, err := createTask(DeviceStatus, name) task, err := createTask(DeviceStatus, name)
if task == nil { if task == nil {
log.Debugf("getStatus: Error createTask: %s", err) log.Debugf("GetStatus: Error createTask: %s", err)
return 0, 0, "", "", err return 0, 0, "", "", err
} }
if err := task.Run(); err != nil { if err := task.Run(); err != nil {
log.Debugf("getStatus: Error Run: %s", err) log.Debugf("GetStatus: Error Run: %s", err)
return 0, 0, "", "", err return 0, 0, "", "", err
} }
devinfo, err := task.GetInfo() devinfo, err := task.GetInfo()
if err != nil { if err != nil {
log.Debugf("getStatus: Error GetInfo: %s", err) log.Debugf("GetStatus: Error GetInfo: %s", err)
return 0, 0, "", "", err return 0, 0, "", "", err
} }
if devinfo.Exists == 0 { if devinfo.Exists == 0 {
log.Debugf("getStatus: Non existing device %s", name) log.Debugf("GetStatus: Non existing device %s", name)
return 0, 0, "", "", fmt.Errorf("Non existing device %s", name) return 0, 0, "", "", fmt.Errorf("Non existing device %s", name)
} }
@ -464,7 +466,7 @@ func getStatus(name string) (uint64, uint64, string, string, error) {
return start, length, targetType, params, nil return start, length, targetType, params, nil
} }
func setTransactionId(poolName string, oldId uint64, newId uint64) error { func SetTransactionId(poolName string, oldId uint64, newId uint64) error {
task, err := createTask(DeviceTargetMsg, poolName) task, err := createTask(DeviceTargetMsg, poolName)
if task == nil { if task == nil {
return err return err
@ -479,12 +481,12 @@ func setTransactionId(poolName string, oldId uint64, newId uint64) error {
} }
if err := task.Run(); err != nil { if err := task.Run(); err != nil {
return fmt.Errorf("Error running setTransactionId %s", err) return fmt.Errorf("Error running SetTransactionId %s", err)
} }
return nil return nil
} }
func suspendDevice(name string) error { func SuspendDevice(name string) error {
task, err := createTask(DeviceSuspend, name) task, err := createTask(DeviceSuspend, name)
if task == nil { if task == nil {
return err return err
@ -495,7 +497,7 @@ func suspendDevice(name string) error {
return nil return nil
} }
func resumeDevice(name string) error { func ResumeDevice(name string) error {
task, err := createTask(DeviceResume, name) task, err := createTask(DeviceResume, name)
if task == nil { if task == nil {
return err return err
@ -515,8 +517,8 @@ func resumeDevice(name string) error {
return nil return nil
} }
func createDevice(poolName string, deviceId *int) error { func CreateDevice(poolName string, deviceId *int) error {
log.Debugf("[devmapper] createDevice(poolName=%v, deviceId=%v)", poolName, *deviceId) log.Debugf("[devmapper] CreateDevice(poolName=%v, deviceId=%v)", poolName, *deviceId)
for { for {
task, err := createTask(DeviceTargetMsg, poolName) task, err := createTask(DeviceTargetMsg, poolName)
@ -539,14 +541,14 @@ func createDevice(poolName string, deviceId *int) error {
*deviceId++ *deviceId++
continue continue
} }
return fmt.Errorf("Error running createDevice %s", err) return fmt.Errorf("Error running CreateDevice %s", err)
} }
break break
} }
return nil return nil
} }
func deleteDevice(poolName string, deviceId int) error { func DeleteDevice(poolName string, deviceId int) error {
task, err := createTask(DeviceTargetMsg, poolName) task, err := createTask(DeviceTargetMsg, poolName)
if task == nil { if task == nil {
return err return err
@ -561,14 +563,14 @@ func deleteDevice(poolName string, deviceId int) error {
} }
if err := task.Run(); err != nil { if err := task.Run(); err != nil {
return fmt.Errorf("Error running deleteDevice %s", err) return fmt.Errorf("Error running DeleteDevice %s", err)
} }
return nil return nil
} }
func removeDevice(name string) error { func removeDevice(name string) error {
log.Debugf("[devmapper] removeDevice START") log.Debugf("[devmapper] RemoveDevice START")
defer log.Debugf("[devmapper] removeDevice END") defer log.Debugf("[devmapper] RemoveDevice END")
task, err := createTask(DeviceRemove, name) task, err := createTask(DeviceRemove, name)
if task == nil { if task == nil {
return err return err
@ -578,12 +580,12 @@ func removeDevice(name string) error {
if dmSawBusy { if dmSawBusy {
return ErrBusy return ErrBusy
} }
return fmt.Errorf("Error running removeDevice %s", err) return fmt.Errorf("Error running RemoveDevice %s", err)
} }
return nil return nil
} }
func activateDevice(poolName string, name string, deviceId int, size uint64) error { func ActivateDevice(poolName string, name string, deviceId int, size uint64) error {
task, err := createTask(DeviceCreate, name) task, err := createTask(DeviceCreate, name)
if task == nil { if task == nil {
return err return err
@ -603,7 +605,7 @@ func activateDevice(poolName string, name string, deviceId int, size uint64) err
} }
if err := task.Run(); err != nil { if err := task.Run(); err != nil {
return fmt.Errorf("Error running DeviceCreate (activateDevice) %s", err) return fmt.Errorf("Error running DeviceCreate (ActivateDevice) %s", err)
} }
UdevWait(cookie) UdevWait(cookie)
@ -611,12 +613,12 @@ func activateDevice(poolName string, name string, deviceId int, size uint64) err
return nil return nil
} }
func createSnapDevice(poolName string, deviceId *int, baseName string, baseDeviceId int) error { func CreateSnapDevice(poolName string, deviceId *int, baseName string, baseDeviceId int) error {
devinfo, _ := getInfo(baseName) devinfo, _ := GetInfo(baseName)
doSuspend := devinfo != nil && devinfo.Exists != 0 doSuspend := devinfo != nil && devinfo.Exists != 0
if doSuspend { if doSuspend {
if err := suspendDevice(baseName); err != nil { if err := SuspendDevice(baseName); err != nil {
return err return err
} }
} }
@ -625,21 +627,21 @@ func createSnapDevice(poolName string, deviceId *int, baseName string, baseDevic
task, err := createTask(DeviceTargetMsg, poolName) task, err := createTask(DeviceTargetMsg, poolName)
if task == nil { if task == nil {
if doSuspend { if doSuspend {
resumeDevice(baseName) ResumeDevice(baseName)
} }
return err return err
} }
if err := task.SetSector(0); err != nil { if err := task.SetSector(0); err != nil {
if doSuspend { if doSuspend {
resumeDevice(baseName) ResumeDevice(baseName)
} }
return fmt.Errorf("Can't set sector %s", err) return fmt.Errorf("Can't set sector %s", err)
} }
if err := task.SetMessage(fmt.Sprintf("create_snap %d %d", *deviceId, baseDeviceId)); err != nil { if err := task.SetMessage(fmt.Sprintf("create_snap %d %d", *deviceId, baseDeviceId)); err != nil {
if doSuspend { if doSuspend {
resumeDevice(baseName) ResumeDevice(baseName)
} }
return fmt.Errorf("Can't set message %s", err) return fmt.Errorf("Can't set message %s", err)
} }
@ -653,7 +655,7 @@ func createSnapDevice(poolName string, deviceId *int, baseName string, baseDevic
} }
if doSuspend { if doSuspend {
resumeDevice(baseName) ResumeDevice(baseName)
} }
return fmt.Errorf("Error running DeviceCreate (createSnapDevice) %s", err) return fmt.Errorf("Error running DeviceCreate (createSnapDevice) %s", err)
} }
@ -662,7 +664,7 @@ func createSnapDevice(poolName string, deviceId *int, baseName string, baseDevic
} }
if doSuspend { if doSuspend {
if err := resumeDevice(baseName); err != nil { if err := ResumeDevice(baseName); err != nil {
return err return err
} }
} }

Просмотреть файл

@ -1,6 +1,6 @@
// +build linux // +build linux
package devmapper package devicemapper
import "C" import "C"
@ -25,6 +25,6 @@ func DevmapperLogCallback(level C.int, file *C.char, line C.int, dm_errno_or_cla
} }
if dmLogger != nil { if dmLogger != nil {
dmLogger.log(int(level), C.GoString(file), int(line), int(dm_errno_or_class), msg) dmLogger.DMLog(int(level), C.GoString(file), int(line), int(dm_errno_or_class), msg)
} }
} }

Просмотреть файл

@ -1,6 +1,6 @@
// +build linux // +build linux
package devmapper package devicemapper
/* /*
#cgo LDFLAGS: -L. -ldevmapper #cgo LDFLAGS: -L. -ldevmapper

Просмотреть файл

@ -1,6 +1,6 @@
// +build linux // +build linux
package devmapper package devicemapper
import ( import (
"syscall" "syscall"