本文整理汇总了Golang中github.com/docker/docker/pkg/devicemapper.ActivateDevice函数的典型用法代码示例。如果您正苦于以下问题:Golang ActivateDevice函数的具体用法?Golang ActivateDevice怎么用?Golang ActivateDevice使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ActivateDevice函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: activateDeviceIfNeeded
func (devices *DeviceSet) activateDeviceIfNeeded(info *DevInfo) error {
log.Debugf("activateDeviceIfNeeded(%v)", info.Hash)
if devinfo, _ := devicemapper.GetInfo(info.Name()); devinfo != nil && devinfo.Exists != 0 {
return nil
}
return devicemapper.ActivateDevice(devices.getPoolDevName(), info.Name(), info.DeviceId, info.Size)
}
开发者ID:Crispy1975,项目名称:deis,代码行数:9,代码来源:deviceset.go
示例2: activateDeviceIfNeeded
func (devices *DeviceSet) activateDeviceIfNeeded(info *DevInfo) error {
logrus.Debugf("activateDeviceIfNeeded(%v)", info.Hash)
// Make sure deferred removal on device is canceled, if one was
// scheduled.
if err := devices.cancelDeferredRemoval(info); err != nil {
return fmt.Errorf("Deivce Deferred Removal Cancellation Failed: %s", err)
}
if devinfo, _ := devicemapper.GetInfo(info.Name()); devinfo != nil && devinfo.Exists != 0 {
return nil
}
return devicemapper.ActivateDevice(devices.getPoolDevName(), info.Name(), info.DeviceId, info.Size)
}
开发者ID:ifa6,项目名称:docker-1,代码行数:15,代码来源:deviceset.go
示例3: activatePool
func (d *Driver) activatePool() error {
dev := d.Device
if _, err := os.Stat(dev.ThinpoolDevice); err == nil {
log.Debug("Found created pool, skip pool reinit")
return nil
}
dataDev, err := os.Open(dev.DataDevice)
if err != nil {
return err
}
defer dataDev.Close()
metadataDev, err := os.Open(dev.MetadataDevice)
if err != nil {
return err
}
defer metadataDev.Close()
if err := createPool(filepath.Base(dev.ThinpoolDevice), dataDev, metadataDev, uint32(dev.ThinpoolBlockSize)); err != nil {
return err
}
log.Debug("Reinitialized the existing pool ", dev.ThinpoolDevice)
volumeIDs, err := dev.listVolumeIDs()
if err != nil {
return err
}
for _, id := range volumeIDs {
volume := d.blankVolume(id)
if err := util.ObjectLoad(volume); err != nil {
return err
}
if err := devicemapper.ActivateDevice(dev.ThinpoolDevice, id, volume.DevID, uint64(volume.Size)); err != nil {
return err
}
log.WithFields(logrus.Fields{
LOG_FIELD_EVENT: LOG_EVENT_ACTIVATE,
LOG_FIELD_VOLUME: id,
}).Debug("Reactivated volume device")
}
return nil
}
开发者ID:ppawiggers,项目名称:convoy,代码行数:43,代码来源:devmapper.go
示例4: OpenSnapshot
func (d *Driver) OpenSnapshot(id, volumeID string) error {
snapshot, volume, err := d.getSnapshotAndVolume(id, volumeID)
if err != nil {
return err
}
log.WithFields(logrus.Fields{
LOG_FIELD_REASON: LOG_REASON_START,
LOG_FIELD_EVENT: LOG_EVENT_ACTIVATE,
LOG_FIELD_OBJECT: LOG_OBJECT_SNAPSHOT,
LOG_FIELD_VOLUME: volumeID,
LOG_FIELD_SNAPSHOT: id,
LOG_FIELD_SIZE: volume.Size,
DM_LOG_FIELD_SNAPSHOT_DEVID: snapshot.DevID,
}).Debug()
if err = devicemapper.ActivateDevice(d.ThinpoolDevice, id, snapshot.DevID, uint64(volume.Size)); err != nil {
return err
}
snapshot.Activated = true
return util.ObjectSave(volume)
}
开发者ID:alwang1234,项目名称:convoy,代码行数:22,代码来源:backup.go
示例5: CreateVolume
func (d *Driver) CreateVolume(id string, opts map[string]string) error {
var (
size int64
err error
)
backupURL := opts[convoydriver.OPT_BACKUP_URL]
if backupURL != "" {
objVolume, err := objectstore.LoadVolume(backupURL)
if err != nil {
return err
}
if objVolume.Driver != d.Name() {
return fmt.Errorf("Cannot restore backup of %v to %v", objVolume.Driver, d.Name())
}
size, err = d.getSize(opts, objVolume.Size)
if err != nil {
return err
}
if size != objVolume.Size {
return fmt.Errorf("Volume size must match with backup's size")
}
} else {
size, err = d.getSize(opts, d.DefaultVolumeSize)
if err != nil {
return err
}
}
if size%(d.ThinpoolBlockSize*SECTOR_SIZE) != 0 {
return fmt.Errorf("Size must be multiple of block size")
}
volume := d.blankVolume(id)
exists, err := util.ObjectExists(volume)
if err != nil {
return err
}
if exists {
return generateError(logrus.Fields{
LOG_FIELD_VOLUME: id,
}, "Already has volume with specific uuid")
}
devID, err := d.allocateDevID()
if err != nil {
return err
}
log.WithFields(logrus.Fields{
LOG_FIELD_REASON: LOG_REASON_START,
LOG_FIELD_EVENT: LOG_EVENT_CREATE,
LOG_FIELD_OBJECT: LOG_OBJECT_VOLUME,
LOG_FIELD_VOLUME: id,
DM_LOG_FIELD_VOLUME_DEVID: devID,
}).Debugf("Creating volume")
err = devicemapper.CreateDevice(d.ThinpoolDevice, devID)
if err != nil {
return err
}
log.WithFields(logrus.Fields{
LOG_FIELD_REASON: LOG_REASON_START,
LOG_FIELD_EVENT: LOG_EVENT_ACTIVATE,
LOG_FIELD_OBJECT: LOG_OBJECT_VOLUME,
LOG_FIELD_VOLUME: id,
DM_LOG_FIELD_VOLUME_DEVID: devID,
}).Debugf("Activating device for volume")
err = devicemapper.ActivateDevice(d.ThinpoolDevice, id, devID, uint64(size))
if err != nil {
log.WithFields(logrus.Fields{
LOG_FIELD_REASON: LOG_REASON_ROLLBACK,
LOG_FIELD_EVENT: LOG_EVENT_REMOVE,
LOG_FIELD_OBJECT: LOG_OBJECT_VOLUME,
LOG_FIELD_VOLUME: id,
DM_LOG_FIELD_VOLUME_DEVID: devID,
}).Debugf("Removing device for volume due to fail to activate")
if err := devicemapper.DeleteDevice(d.ThinpoolDevice, devID); err != nil {
log.WithFields(logrus.Fields{
LOG_FIELD_REASON: LOG_REASON_FAILURE,
LOG_FIELD_EVENT: LOG_EVENT_REMOVE,
LOG_FIELD_OBJECT: LOG_OBJECT_VOLUME,
LOG_FIELD_VOLUME: id,
DM_LOG_FIELD_VOLUME_DEVID: devID,
}).Debugf("Failed to remove device")
}
return err
}
volume.DevID = devID
volume.Size = size
volume.Snapshots = make(map[string]Snapshot)
if err := util.ObjectSave(volume); err != nil {
return err
}
dev, err := d.GetVolumeDevice(id)
if err != nil {
return err
}
if backupURL == "" {
// format the device
//.........这里部分代码省略.........
开发者ID:ppawiggers,项目名称:convoy,代码行数:101,代码来源:devmapper.go
示例6: CreateVolume
func (d *Driver) CreateVolume(id, baseID string, size int64) error {
var err error
if size%(d.ThinpoolBlockSize*SECTOR_SIZE) != 0 {
return fmt.Errorf("Size must be multiple of block size")
}
volume := d.loadVolume(id)
if volume != nil {
return generateError(logrus.Fields{
LOG_FIELD_VOLUME: id,
}, "Already has volume with specific uuid")
}
var image *Image
if baseID != "" {
image = d.loadImage(baseID)
if image == nil {
return generateError(logrus.Fields{
LOG_FIELD_IMAGE: baseID,
}, "Cannot find activated base image")
}
if _, err := os.Stat(image.Device); err != nil {
return generateError(logrus.Fields{
LOG_FIELD_IMAGE_DEV: image.Device,
}, "Base image device doesn't exist")
}
if size != image.Size {
return generateError(logrus.Fields{
LOG_FIELD_IMAGE: baseID,
LOG_FIELD_VOLUME: id,
}, "Volume has different size(%v) than base image(%v)", size, image.Size)
}
}
devID, err := d.allocateDevID()
if err != nil {
return err
}
log.WithFields(logrus.Fields{
LOG_FIELD_REASON: LOG_REASON_START,
LOG_FIELD_EVENT: LOG_EVENT_CREATE,
LOG_FIELD_OBJECT: LOG_OBJECT_VOLUME,
LOG_FIELD_VOLUME: id,
LOG_FIELD_IMAGE: baseID,
DM_LOG_FIELD_VOLUME_DEVID: devID,
}).Debugf("Creating volume")
err = devicemapper.CreateDevice(d.ThinpoolDevice, devID)
if err != nil {
return err
}
log.WithFields(logrus.Fields{
LOG_FIELD_REASON: LOG_REASON_START,
LOG_FIELD_EVENT: LOG_EVENT_ACTIVATE,
LOG_FIELD_OBJECT: LOG_OBJECT_VOLUME,
LOG_FIELD_VOLUME: id,
LOG_FIELD_IMAGE: baseID,
DM_LOG_FIELD_VOLUME_DEVID: devID,
}).Debugf("Activating device for volume")
if image == nil {
err = devicemapper.ActivateDevice(d.ThinpoolDevice, id, devID, uint64(size))
} else {
err = devicemapper.ActivateDeviceWithExternal(d.ThinpoolDevice, id, devID, uint64(size), image.Device)
}
if err != nil {
log.WithFields(logrus.Fields{
LOG_FIELD_REASON: LOG_REASON_ROLLBACK,
LOG_FIELD_EVENT: LOG_EVENT_REMOVE,
LOG_FIELD_OBJECT: LOG_OBJECT_VOLUME,
LOG_FIELD_VOLUME: id,
LOG_FIELD_IMAGE: baseID,
DM_LOG_FIELD_VOLUME_DEVID: devID,
}).Debugf("Removing device for volume due to fail to activate")
if err := devicemapper.DeleteDevice(d.ThinpoolDevice, devID); err != nil {
log.WithFields(logrus.Fields{
LOG_FIELD_REASON: LOG_REASON_FAILURE,
LOG_FIELD_EVENT: LOG_EVENT_REMOVE,
LOG_FIELD_OBJECT: LOG_OBJECT_VOLUME,
LOG_FIELD_VOLUME: id,
LOG_FIELD_IMAGE: baseID,
DM_LOG_FIELD_VOLUME_DEVID: devID,
}).Debugf("Failed to remove device")
}
return err
}
volume = &Volume{
UUID: id,
DevID: devID,
Size: size,
Snapshots: make(map[string]Snapshot),
}
if image != nil {
volume.Base = image.UUID
image.VolumeRef[id] = true
if err := d.saveImage(image); err != nil {
return err
}
}
if err := d.saveVolume(volume); err != nil {
//.........这里部分代码省略.........
开发者ID:deniseschannon,项目名称:rancher-volume,代码行数:101,代码来源:devmapper.go
注:本文中的github.com/docker/docker/pkg/devicemapper.ActivateDevice函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论