зеркало из https://github.com/microsoft/docker.git
Random improvments
This commit is contained in:
Родитель
06d0843a61
Коммит
8b2f4aab23
59
Dockerfile
59
Dockerfile
|
@ -24,54 +24,57 @@
|
|||
#
|
||||
|
||||
docker-version 0.6.1
|
||||
from ubuntu:12.04
|
||||
maintainer Solomon Hykes <solomon@dotcloud.com>
|
||||
from ubuntu:12.10
|
||||
maintainer Solomon Hykes <solomon@dotcloud.com>
|
||||
|
||||
# Build dependencies
|
||||
run echo 'deb http://archive.ubuntu.com/ubuntu precise main universe' > /etc/apt/sources.list
|
||||
run apt-get update
|
||||
run apt-get install -y -q curl
|
||||
run apt-get install -y -q git
|
||||
run apt-get install -y -q mercurial
|
||||
run apt-get install -y -q build-essential
|
||||
run apt-get update
|
||||
run apt-get install -y -q curl
|
||||
run apt-get install -y -q git
|
||||
run apt-get install -y -q mercurial
|
||||
run apt-get install -y -q build-essential
|
||||
|
||||
# Install Go from source (for eventual cross-compiling)
|
||||
run curl -s https://go.googlecode.com/files/go1.2rc1.src.tar.gz | tar -v -C / -xz && mv /go /goroot
|
||||
run cd /goroot/src && ./make.bash
|
||||
env GOROOT /goroot
|
||||
env PATH $PATH:/goroot/bin
|
||||
env GOPATH /go:/go/src/github.com/dotcloud/docker/vendor
|
||||
run curl -s https://go.googlecode.com/files/go1.2rc1.src.tar.gz | tar -v -C / -xz && mv /go /goroot
|
||||
run cd /goroot/src && ./make.bash
|
||||
env GOROOT /goroot
|
||||
env PATH $PATH:/goroot/bin
|
||||
env GOPATH /go:/go/src/github.com/dotcloud/docker/vendor
|
||||
|
||||
# Create Go cache with tag netgo (for static compilation of Go while preserving CGO support)
|
||||
run go install -ldflags '-w -linkmode external -extldflags "-static -Wl,--unresolved-symbols=ignore-in-shared-libs"' -tags netgo -a std
|
||||
run go install -ldflags '-w -linkmode external -extldflags "-static -Wl,--unresolved-symbols=ignore-in-shared-libs"' -tags netgo -a std
|
||||
|
||||
# Get lvm2 source for compiling statically
|
||||
run git clone git://git.fedorahosted.org/git/lvm2.git /lvm2
|
||||
run cd /lvm2 && git checkout v2_02_102
|
||||
run git clone git://git.fedorahosted.org/git/lvm2.git /lvm2
|
||||
run cd /lvm2 && git checkout v2_02_102
|
||||
|
||||
# can't use git clone -b because it's not supported by git versions before 1.7.10
|
||||
run cd /lvm2 && ./configure --enable-static_link && make && make install_device-mapper
|
||||
# see https://git.fedorahosted.org/cgit/lvm2.git/refs/tags for release tags
|
||||
|
||||
# Ubuntu stuff
|
||||
run apt-get install -y -q ruby1.9.3 rubygems libffi-dev
|
||||
run gem install --no-rdoc --no-ri fpm
|
||||
run apt-get install -y -q reprepro dpkg-sig
|
||||
run apt-get install -y -q ruby1.9.3 rubygems libffi-dev
|
||||
run gem install --no-rdoc --no-ri fpm
|
||||
run apt-get install -y -q reprepro dpkg-sig
|
||||
|
||||
# Install s3cmd 1.0.1 (earlier versions don't support env variables in the config)
|
||||
run apt-get install -y -q python-pip
|
||||
run pip install s3cmd
|
||||
run pip install python-magic
|
||||
run /bin/echo -e '[default]\naccess_key=$AWS_ACCESS_KEY\nsecret_key=$AWS_SECRET_KEY\n' > /.s3cfg
|
||||
run apt-get install -y -q python-pip
|
||||
run pip install s3cmd
|
||||
run pip install python-magic
|
||||
run /bin/echo -e '[default]\naccess_key=$AWS_ACCESS_KEY\nsecret_key=$AWS_SECRET_KEY\n' > /.s3cfg
|
||||
|
||||
# Runtime dependencies
|
||||
run apt-get install -y -q iptables
|
||||
run apt-get install -y -q lxc
|
||||
run apt-get install -y -q iptables
|
||||
run dpkg-divert --local --rename --add /sbin/initctl && \
|
||||
ln -s /bin/true /sbin/initctl && \
|
||||
apt-get install -y -q lxc
|
||||
|
||||
volume /var/lib/docker
|
||||
workdir /go/src/github.com/dotcloud/docker
|
||||
volume /var/lib/docker
|
||||
workdir /go/src/github.com/dotcloud/docker
|
||||
|
||||
# Wrap all commands in the "docker-in-docker" script to allow nested containers
|
||||
entrypoint ["hack/dind"]
|
||||
|
||||
# Upload docker source
|
||||
add . /go/src/github.com/dotcloud/docker
|
||||
add . /go/src/github.com/dotcloud/docker
|
||||
|
||||
|
|
1
api.go
1
api.go
|
@ -620,6 +620,7 @@ func postContainersStart(srv *Server, version float64, w http.ResponseWriter, r
|
|||
}
|
||||
name := vars["name"]
|
||||
if err := srv.ContainerStart(name, hostConfig); err != nil {
|
||||
utils.Debugf("error ContainerStart: %s", err)
|
||||
return err
|
||||
}
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
|
|
|
@ -66,9 +66,8 @@ func (wrapper *DeviceSetWrapper) HasActivatedDevice(hash string) bool {
|
|||
}
|
||||
|
||||
func NewDeviceSetWrapper(wrapped DeviceSet, prefix string) DeviceSet {
|
||||
wrapper := &DeviceSetWrapper{
|
||||
return &DeviceSetWrapper{
|
||||
wrapped: wrapped,
|
||||
prefix: prefix,
|
||||
}
|
||||
return wrapper
|
||||
}
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
package devmapper
|
||||
|
||||
import (
|
||||
"github.com/dotcloud/docker/utils"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/dotcloud/docker/utils"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
|
@ -15,9 +14,11 @@ import (
|
|||
"syscall"
|
||||
)
|
||||
|
||||
const defaultDataLoopbackSize int64 = 100 * 1024 * 1024 * 1024
|
||||
const defaultMetaDataLoopbackSize int64 = 2 * 1024 * 1024 * 1024
|
||||
const defaultBaseFsSize uint64 = 10 * 1024 * 1024 * 1024
|
||||
const (
|
||||
defaultDataLoopbackSize int64 = 100 * 1024 * 1024 * 1024
|
||||
defaultMetaDataLoopbackSize int64 = 2 * 1024 * 1024 * 1024
|
||||
defaultBaseFsSize uint64 = 10 * 1024 * 1024 * 1024
|
||||
)
|
||||
|
||||
type DevInfo struct {
|
||||
Hash string `json:"-"`
|
||||
|
@ -33,14 +34,14 @@ type MetaData struct {
|
|||
}
|
||||
|
||||
type DeviceSetDM struct {
|
||||
initialized bool
|
||||
root string
|
||||
devicePrefix string
|
||||
MetaData
|
||||
initialized bool
|
||||
root string
|
||||
devicePrefix string
|
||||
TransactionId uint64
|
||||
NewTransactionId uint64
|
||||
nextFreeDevice int
|
||||
activeMounts map[string]int
|
||||
activeMounts map[string]int
|
||||
}
|
||||
|
||||
func getDevName(name string) string {
|
||||
|
@ -68,7 +69,7 @@ func (devices *DeviceSetDM) jsonFile() string {
|
|||
}
|
||||
|
||||
func (devices *DeviceSetDM) getPoolName() string {
|
||||
return fmt.Sprintf("%s-pool", devices.devicePrefix)
|
||||
return devices.devicePrefix + "-pool"
|
||||
}
|
||||
|
||||
func (devices *DeviceSetDM) getPoolDevName() string {
|
||||
|
@ -80,8 +81,7 @@ func (devices *DeviceSetDM) createTask(t TaskType, name string) (*Task, error) {
|
|||
if task == nil {
|
||||
return nil, fmt.Errorf("Can't create task of type %d", int(t))
|
||||
}
|
||||
err := task.SetName(name)
|
||||
if err != nil {
|
||||
if err := task.SetName(name); err != nil {
|
||||
return nil, fmt.Errorf("Can't set task name %s", name)
|
||||
}
|
||||
return task, nil
|
||||
|
@ -92,60 +92,53 @@ func (devices *DeviceSetDM) getInfo(name string) (*Info, error) {
|
|||
if task == nil {
|
||||
return nil, err
|
||||
}
|
||||
err = task.Run()
|
||||
if err != nil {
|
||||
if err := task.Run(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
info, err := task.GetInfo()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return info, nil
|
||||
return task.GetInfo()
|
||||
}
|
||||
|
||||
func (devices *DeviceSetDM) getStatus(name string) (uint64, uint64, string, string, error) {
|
||||
task, err := devices.createTask(DeviceStatus, name)
|
||||
if task == nil {
|
||||
utils.Debugf("getStatus: Error createTask: %s", err)
|
||||
return 0, 0, "", "", err
|
||||
}
|
||||
err = task.Run()
|
||||
if err != nil {
|
||||
if err := task.Run(); err != nil {
|
||||
utils.Debugf("getStatus: Error Run: %s", err)
|
||||
return 0, 0, "", "", err
|
||||
}
|
||||
|
||||
devinfo, err := task.GetInfo()
|
||||
if err != nil {
|
||||
utils.Debugf("getStatus: Error GetInfo: %s", err)
|
||||
return 0, 0, "", "", err
|
||||
}
|
||||
if devinfo.Exists == 0 {
|
||||
utils.Debugf("getStatus: Non existing device %s", name)
|
||||
return 0, 0, "", "", fmt.Errorf("Non existing device %s", name)
|
||||
}
|
||||
|
||||
var next uintptr = 0
|
||||
next, start, length, target_type, params := task.GetNextTarget(next)
|
||||
|
||||
_, start, length, target_type, params := task.GetNextTarget(0)
|
||||
return start, length, target_type, params, nil
|
||||
}
|
||||
|
||||
func (devices *DeviceSetDM) setTransactionId(oldId uint64, newId uint64) error {
|
||||
task, err := devices.createTask(DeviceTargetMsg, devices.getPoolDevName())
|
||||
if task == nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
err = task.SetSector(0)
|
||||
if err != nil {
|
||||
if err := task.SetSector(0); err != nil {
|
||||
return fmt.Errorf("Can't set sector")
|
||||
}
|
||||
|
||||
message := fmt.Sprintf("set_transaction_id %d %d", oldId, newId)
|
||||
err = task.SetMessage(message)
|
||||
if err != nil {
|
||||
if err := task.SetMessage(fmt.Sprintf("set_transaction_id %d %d", oldId, newId)); err != nil {
|
||||
return fmt.Errorf("Can't set message")
|
||||
}
|
||||
|
||||
err = task.Run()
|
||||
if err != nil {
|
||||
if err := task.Run(); err != nil {
|
||||
return fmt.Errorf("Error running setTransactionId")
|
||||
}
|
||||
return nil
|
||||
|
@ -167,18 +160,17 @@ func (devices *DeviceSetDM) ensureImage(name string, size int64) (string, error)
|
|||
return "", err
|
||||
}
|
||||
|
||||
_, err := os.Stat(filename)
|
||||
if err != nil {
|
||||
if _, err := os.Stat(filename); err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
return "", err
|
||||
}
|
||||
log.Printf("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)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
err = file.Truncate(size)
|
||||
if err != nil {
|
||||
|
||||
if err = file.Truncate(size); err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
@ -189,6 +181,7 @@ func (devices *DeviceSetDM) createPool(dataFile *os.File, metadataFile *os.File)
|
|||
utils.Debugf("Activating device-mapper pool %s", devices.getPoolName())
|
||||
task, err := devices.createTask(DeviceCreate, devices.getPoolName())
|
||||
if task == nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -198,19 +191,16 @@ func (devices *DeviceSetDM) createPool(dataFile *os.File, metadataFile *os.File)
|
|||
}
|
||||
|
||||
params := metadataFile.Name() + " " + dataFile.Name() + " 512 8192"
|
||||
err = task.AddTarget(0, size/512, "thin-pool", params)
|
||||
if err != nil {
|
||||
if err := task.AddTarget(0, size/512, "thin-pool", params); err != nil {
|
||||
return fmt.Errorf("Can't add target")
|
||||
}
|
||||
|
||||
var cookie uint32 = 0
|
||||
err = task.SetCookie(&cookie, 0)
|
||||
if err != nil {
|
||||
if err := task.SetCookie(&cookie, 0); err != nil {
|
||||
return fmt.Errorf("Can't set cookie")
|
||||
}
|
||||
|
||||
err = task.Run()
|
||||
if err != nil {
|
||||
if err := task.Run(); err != nil {
|
||||
return fmt.Errorf("Error running DeviceCreate")
|
||||
}
|
||||
|
||||
|
@ -222,10 +212,10 @@ func (devices *DeviceSetDM) createPool(dataFile *os.File, metadataFile *os.File)
|
|||
func (devices *DeviceSetDM) suspendDevice(info *DevInfo) error {
|
||||
task, err := devices.createTask(DeviceSuspend, info.Name())
|
||||
if task == nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
err = task.Run()
|
||||
if err != nil {
|
||||
if err := task.Run(); err != nil {
|
||||
return fmt.Errorf("Error running DeviceSuspend")
|
||||
}
|
||||
return nil
|
||||
|
@ -234,17 +224,16 @@ func (devices *DeviceSetDM) suspendDevice(info *DevInfo) error {
|
|||
func (devices *DeviceSetDM) resumeDevice(info *DevInfo) error {
|
||||
task, err := devices.createTask(DeviceResume, info.Name())
|
||||
if task == nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
var cookie uint32 = 0
|
||||
err = task.SetCookie(&cookie, 0)
|
||||
if err != nil {
|
||||
if err := task.SetCookie(&cookie, 0); err != nil {
|
||||
return fmt.Errorf("Can't set cookie")
|
||||
}
|
||||
|
||||
err = task.Run()
|
||||
if err != nil {
|
||||
if err := task.Run(); err != nil {
|
||||
return fmt.Errorf("Error running DeviceSuspend")
|
||||
}
|
||||
|
||||
|
@ -256,68 +245,60 @@ func (devices *DeviceSetDM) resumeDevice(info *DevInfo) error {
|
|||
func (devices *DeviceSetDM) createDevice(deviceId int) error {
|
||||
task, err := devices.createTask(DeviceTargetMsg, devices.getPoolDevName())
|
||||
if task == nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
err = task.SetSector(0)
|
||||
if err != nil {
|
||||
if err := task.SetSector(0); err != nil {
|
||||
return fmt.Errorf("Can't set sector")
|
||||
}
|
||||
|
||||
message := fmt.Sprintf("create_thin %d", deviceId)
|
||||
err = task.SetMessage(message)
|
||||
if err != nil {
|
||||
if err := task.SetMessage(fmt.Sprintf("create_thin %d", deviceId)); err != nil {
|
||||
return fmt.Errorf("Can't set message")
|
||||
}
|
||||
|
||||
err = task.Run()
|
||||
if err != nil {
|
||||
if err := task.Run(); err != nil {
|
||||
return fmt.Errorf("Error running createDevice")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (devices *DeviceSetDM) createSnapDevice(deviceId int, baseInfo *DevInfo) error {
|
||||
doSuspend := false
|
||||
devinfo, _ := devices.getInfo(baseInfo.Name())
|
||||
if devinfo != nil && devinfo.Exists != 0 {
|
||||
doSuspend = true
|
||||
}
|
||||
doSuspend := devinfo != nil && devinfo.Exists != 0
|
||||
|
||||
if doSuspend {
|
||||
err := devices.suspendDevice(baseInfo)
|
||||
if err != nil {
|
||||
if err := devices.suspendDevice(baseInfo); err != nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
task, err := devices.createTask(DeviceTargetMsg, devices.getPoolDevName())
|
||||
if task == nil {
|
||||
_ = devices.resumeDevice(baseInfo)
|
||||
devices.resumeDevice(baseInfo)
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
err = task.SetSector(0)
|
||||
if err != nil {
|
||||
_ = devices.resumeDevice(baseInfo)
|
||||
|
||||
if err := task.SetSector(0); err != nil {
|
||||
devices.resumeDevice(baseInfo)
|
||||
return fmt.Errorf("Can't set sector")
|
||||
}
|
||||
|
||||
message := fmt.Sprintf("create_snap %d %d", deviceId, baseInfo.DeviceId)
|
||||
err = task.SetMessage(message)
|
||||
if err != nil {
|
||||
_ = devices.resumeDevice(baseInfo)
|
||||
if err := task.SetMessage(fmt.Sprintf("create_snap %d %d", deviceId, baseInfo.DeviceId)); err != nil {
|
||||
devices.resumeDevice(baseInfo)
|
||||
return fmt.Errorf("Can't set message")
|
||||
}
|
||||
|
||||
err = task.Run()
|
||||
if err != nil {
|
||||
_ = devices.resumeDevice(baseInfo)
|
||||
if err := task.Run(); err != nil {
|
||||
devices.resumeDevice(baseInfo)
|
||||
return fmt.Errorf("Error running DeviceCreate")
|
||||
}
|
||||
|
||||
if doSuspend {
|
||||
err = devices.resumeDevice(baseInfo)
|
||||
if err != nil {
|
||||
if err := devices.resumeDevice(baseInfo); err != nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -328,22 +309,19 @@ func (devices *DeviceSetDM) createSnapDevice(deviceId int, baseInfo *DevInfo) er
|
|||
func (devices *DeviceSetDM) deleteDevice(deviceId int) error {
|
||||
task, err := devices.createTask(DeviceTargetMsg, devices.getPoolDevName())
|
||||
if task == nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
err = task.SetSector(0)
|
||||
if err != nil {
|
||||
if err := task.SetSector(0); err != nil {
|
||||
return fmt.Errorf("Can't set sector")
|
||||
}
|
||||
|
||||
message := fmt.Sprintf("delete %d", deviceId)
|
||||
err = task.SetMessage(message)
|
||||
if err != nil {
|
||||
if err := task.SetMessage(fmt.Sprintf("delete %d", deviceId)); err != nil {
|
||||
return fmt.Errorf("Can't set message")
|
||||
}
|
||||
|
||||
err = task.Run()
|
||||
if err != nil {
|
||||
if err := task.Run(); err != nil {
|
||||
return fmt.Errorf("Error running deleteDevice")
|
||||
}
|
||||
return nil
|
||||
|
@ -352,10 +330,10 @@ func (devices *DeviceSetDM) deleteDevice(deviceId int) error {
|
|||
func (devices *DeviceSetDM) removeDevice(name string) error {
|
||||
task, err := devices.createTask(DeviceRemove, name)
|
||||
if task == nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
err = task.Run()
|
||||
if err != nil {
|
||||
if err = task.Run(); err != nil {
|
||||
return fmt.Errorf("Error running removeDevice")
|
||||
}
|
||||
return nil
|
||||
|
@ -364,23 +342,21 @@ func (devices *DeviceSetDM) removeDevice(name string) error {
|
|||
func (devices *DeviceSetDM) activateDevice(info *DevInfo) error {
|
||||
task, err := devices.createTask(DeviceCreate, info.Name())
|
||||
if task == nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
params := fmt.Sprintf("%s %d", devices.getPoolDevName(), info.DeviceId)
|
||||
err = task.AddTarget(0, info.Size/512, "thin", params)
|
||||
if err != nil {
|
||||
if err := task.AddTarget(0, info.Size/512, "thin", params); err != nil {
|
||||
return fmt.Errorf("Can't add target")
|
||||
}
|
||||
|
||||
var cookie uint32 = 0
|
||||
err = task.SetCookie(&cookie, 0)
|
||||
if err != nil {
|
||||
if err := task.SetCookie(&cookie, 0); err != nil {
|
||||
return fmt.Errorf("Can't set cookie")
|
||||
}
|
||||
|
||||
err = task.Run()
|
||||
if err != nil {
|
||||
if err := task.Run(); err != nil {
|
||||
return fmt.Errorf("Error running DeviceCreate")
|
||||
}
|
||||
|
||||
|
@ -404,61 +380,60 @@ func (devices *DeviceSetDM) allocateTransactionId() uint64 {
|
|||
func (devices *DeviceSetDM) saveMetadata() error {
|
||||
jsonData, err := json.Marshal(devices.MetaData)
|
||||
if err != nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
tmpFile, err := ioutil.TempFile(filepath.Dir(devices.jsonFile()), ".json")
|
||||
if err != nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
n, err := tmpFile.Write(jsonData)
|
||||
if err != nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
if n < len(jsonData) {
|
||||
err = io.ErrShortWrite
|
||||
return io.ErrShortWrite
|
||||
}
|
||||
err = tmpFile.Sync()
|
||||
if err != nil {
|
||||
if err := tmpFile.Sync(); err != nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
err = tmpFile.Close()
|
||||
if err != nil {
|
||||
if err := tmpFile.Close(); err != nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
err = os.Rename(tmpFile.Name(), devices.jsonFile())
|
||||
if err != nil {
|
||||
if err := os.Rename(tmpFile.Name(), devices.jsonFile()); err != nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
if devices.NewTransactionId != devices.TransactionId {
|
||||
err = devices.setTransactionId(devices.TransactionId, devices.NewTransactionId)
|
||||
if err != nil {
|
||||
if err = devices.setTransactionId(devices.TransactionId, devices.NewTransactionId); err != nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
devices.TransactionId = devices.NewTransactionId
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (devices *DeviceSetDM) registerDevice(id int, hash string, size uint64) (*DevInfo, error) {
|
||||
transaction := devices.allocateTransactionId()
|
||||
|
||||
info := &DevInfo{
|
||||
Hash: hash,
|
||||
DeviceId: id,
|
||||
Size: size,
|
||||
TransactionId: transaction,
|
||||
TransactionId: devices.allocateTransactionId(),
|
||||
Initialized: false,
|
||||
devices: devices,
|
||||
}
|
||||
|
||||
devices.Devices[hash] = info
|
||||
err := devices.saveMetadata()
|
||||
if err != nil {
|
||||
if err := devices.saveMetadata(); err != nil {
|
||||
// Try to remove unused device
|
||||
devices.Devices[hash] = nil
|
||||
delete(devices.Devices, hash)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -471,9 +446,7 @@ func (devices *DeviceSetDM) activateDeviceIfNeeded(hash string) error {
|
|||
return fmt.Errorf("Unknown device %s", hash)
|
||||
}
|
||||
|
||||
name := info.Name()
|
||||
devinfo, _ := devices.getInfo(name)
|
||||
if devinfo != nil && devinfo.Exists != 0 {
|
||||
if devinfo, _ := devices.getInfo(info.Name()); devinfo != nil && devinfo.Exists != 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -483,13 +456,12 @@ func (devices *DeviceSetDM) activateDeviceIfNeeded(hash string) error {
|
|||
func (devices *DeviceSetDM) createFilesystem(info *DevInfo) error {
|
||||
devname := info.DevName()
|
||||
|
||||
err := exec.Command("mkfs.ext4", "-E",
|
||||
"discard,lazy_itable_init=0,lazy_journal_init=0", devname).Run()
|
||||
err := exec.Command("mkfs.ext4", "-E", "discard,lazy_itable_init=0,lazy_journal_init=0", devname).Run()
|
||||
if err != nil {
|
||||
err = exec.Command("mkfs.ext4", "-E",
|
||||
"discard,lazy_itable_init=0", devname).Run()
|
||||
err = exec.Command("mkfs.ext4", "-E", "discard,lazy_itable_init=0", devname).Run()
|
||||
}
|
||||
if err != nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
@ -498,31 +470,29 @@ func (devices *DeviceSetDM) createFilesystem(info *DevInfo) error {
|
|||
func (devices *DeviceSetDM) loadMetaData() error {
|
||||
_, _, _, params, err := devices.getStatus(devices.getPoolName())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var currentTransaction uint64
|
||||
_, err = fmt.Sscanf(params, "%d", ¤tTransaction)
|
||||
if err != nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
devices.TransactionId = currentTransaction
|
||||
if _, err := fmt.Sscanf(params, "%d", &devices.TransactionId); err != nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
devices.NewTransactionId = devices.TransactionId
|
||||
|
||||
jsonData, err := ioutil.ReadFile(devices.jsonFile())
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
metadata := &MetaData{
|
||||
Devices: make(map[string]*DevInfo),
|
||||
}
|
||||
devices.MetaData.Devices = make(map[string]*DevInfo)
|
||||
if jsonData != nil {
|
||||
if err := json.Unmarshal(jsonData, metadata); err != nil {
|
||||
if err := json.Unmarshal(jsonData, &devices.MetaData); err != nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
devices.MetaData = *metadata
|
||||
|
||||
for hash, d := range devices.Devices {
|
||||
d.Hash = hash
|
||||
|
@ -533,12 +503,11 @@ func (devices *DeviceSetDM) loadMetaData() error {
|
|||
}
|
||||
|
||||
// If the transaction id is larger than the actual one we lost the device due to some crash
|
||||
if d.TransactionId > currentTransaction {
|
||||
log.Printf("Removing lost device %s with id %d", hash, d.TransactionId)
|
||||
if d.TransactionId > devices.TransactionId {
|
||||
utils.Debugf("Removing lost device %s with id %d", hash, d.TransactionId)
|
||||
delete(devices.Devices, hash)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -549,45 +518,46 @@ func (devices *DeviceSetDM) setupBaseImage() error {
|
|||
}
|
||||
|
||||
if oldInfo != nil && !oldInfo.Initialized {
|
||||
log.Printf("Removing uninitialized base image")
|
||||
utils.Debugf("Removing uninitialized base image")
|
||||
if err := devices.RemoveDevice(""); err != nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
log.Printf("Initializing base device-manager snapshot")
|
||||
utils.Debugf("Initializing base device-manager snapshot")
|
||||
|
||||
id := devices.allocateDeviceId()
|
||||
|
||||
// Create initial device
|
||||
err := devices.createDevice(id)
|
||||
if err != nil {
|
||||
if err := devices.createDevice(id); err != nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
info, err := devices.registerDevice(id, "", defaultBaseFsSize)
|
||||
if err != nil {
|
||||
_ = devices.deleteDevice(id)
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
log.Printf("Creating filesystem on base device-manager snapshot")
|
||||
utils.Debugf("Creating filesystem on base device-manager snapshot")
|
||||
|
||||
err = devices.activateDeviceIfNeeded("")
|
||||
if err != nil {
|
||||
if err = devices.activateDeviceIfNeeded(""); err != nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
err = devices.createFilesystem(info)
|
||||
if err != nil {
|
||||
if err := devices.createFilesystem(info); err != nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
info.Initialized = true
|
||||
|
||||
err = devices.saveMetadata()
|
||||
if err != nil {
|
||||
if err = devices.saveMetadata(); err != nil {
|
||||
info.Initialized = false
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -597,64 +567,67 @@ func (devices *DeviceSetDM) setupBaseImage() error {
|
|||
func (devices *DeviceSetDM) initDevmapper() error {
|
||||
info, err := devices.getInfo(devices.getPoolName())
|
||||
if info == nil {
|
||||
utils.Debugf("Error device getInfo: %s", err)
|
||||
return err
|
||||
}
|
||||
utils.Debugf("initDevmapper(). Pool exists: %v", info.Exists)
|
||||
|
||||
if info.Exists != 0 {
|
||||
/* Pool exists, assume everything is up */
|
||||
err = devices.loadMetaData()
|
||||
if err != nil {
|
||||
if err := devices.loadMetaData(); err != nil {
|
||||
utils.Debugf("Error device loadMetaData: %s\n", err)
|
||||
return err
|
||||
}
|
||||
err = devices.setupBaseImage()
|
||||
if err != nil {
|
||||
if err := devices.setupBaseImage(); err != nil {
|
||||
utils.Debugf("Error device setupBaseImage: %s\n", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
createdLoopback := false
|
||||
if !devices.hasImage("data") || !devices.hasImage("metadata") {
|
||||
/* If we create the loopback mounts we also need to initialize the base fs */
|
||||
createdLoopback = true
|
||||
}
|
||||
/* If we create the loopback mounts we also need to initialize the base fs */
|
||||
createdLoopback := !devices.hasImage("data") || !devices.hasImage("metadata")
|
||||
|
||||
data, err := devices.ensureImage("data", defaultDataLoopbackSize)
|
||||
if err != nil {
|
||||
utils.Debugf("Error device ensureImage (data): %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
metadata, err := devices.ensureImage("metadata", defaultMetaDataLoopbackSize)
|
||||
if err != nil {
|
||||
utils.Debugf("Error device ensureImage (metadata): %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
dataFile, err := AttachLoopDevice(data)
|
||||
if err != nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
defer dataFile.Close()
|
||||
|
||||
metadataFile, err := AttachLoopDevice(metadata)
|
||||
if err != nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
defer metadataFile.Close()
|
||||
|
||||
err = devices.createPool(dataFile, metadataFile)
|
||||
if err != nil {
|
||||
if err := devices.createPool(dataFile, metadataFile); err != nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
if !createdLoopback {
|
||||
err = devices.loadMetaData()
|
||||
if err != nil {
|
||||
if err = devices.loadMetaData(); err != nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
err = devices.setupBaseImage()
|
||||
if err != nil {
|
||||
if err := devices.setupBaseImage(); err != nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -663,6 +636,7 @@ func (devices *DeviceSetDM) initDevmapper() error {
|
|||
|
||||
func (devices *DeviceSetDM) AddDevice(hash, baseHash string) error {
|
||||
if err := devices.ensureInit(); err != nil {
|
||||
utils.Debugf("Error init: %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -672,19 +646,20 @@ func (devices *DeviceSetDM) AddDevice(hash, baseHash string) error {
|
|||
|
||||
baseInfo := devices.Devices[baseHash]
|
||||
if baseInfo == nil {
|
||||
utils.Debugf("Base Hash not found")
|
||||
return fmt.Errorf("Unknown base hash %s", baseHash)
|
||||
}
|
||||
|
||||
deviceId := devices.allocateDeviceId()
|
||||
|
||||
err := devices.createSnapDevice(deviceId, baseInfo)
|
||||
if err != nil {
|
||||
if err := devices.createSnapDevice(deviceId, baseInfo); err != nil {
|
||||
utils.Debugf("Error creating snap device: %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = devices.registerDevice(deviceId, hash, baseInfo.Size)
|
||||
if err != nil {
|
||||
_ = devices.deleteDevice(deviceId)
|
||||
if _, err := devices.registerDevice(deviceId, hash, baseInfo.Size); err != nil {
|
||||
devices.deleteDevice(deviceId)
|
||||
utils.Debugf("Error registering device: %s\n", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
@ -692,6 +667,7 @@ func (devices *DeviceSetDM) AddDevice(hash, baseHash string) error {
|
|||
|
||||
func (devices *DeviceSetDM) RemoveDevice(hash string) error {
|
||||
if err := devices.ensureInit(); err != nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -702,31 +678,31 @@ func (devices *DeviceSetDM) RemoveDevice(hash string) error {
|
|||
|
||||
devinfo, _ := devices.getInfo(info.Name())
|
||||
if devinfo != nil && devinfo.Exists != 0 {
|
||||
err := devices.removeDevice(info.Name())
|
||||
if err != nil {
|
||||
if err := devices.removeDevice(info.Name()); err != nil {
|
||||
utils.Debugf("Error removing device: %s\n", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if info.Initialized {
|
||||
info.Initialized = false
|
||||
err := devices.saveMetadata()
|
||||
if err != nil {
|
||||
if err := devices.saveMetadata(); err != nil {
|
||||
utils.Debugf("Error saving meta data: %s\n", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
err := devices.deleteDevice(info.DeviceId)
|
||||
if err != nil {
|
||||
if err := devices.deleteDevice(info.DeviceId); err != nil {
|
||||
utils.Debugf("Error deleting device: %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
_ = devices.allocateTransactionId()
|
||||
devices.allocateTransactionId()
|
||||
delete(devices.Devices, info.Hash)
|
||||
|
||||
err = devices.saveMetadata()
|
||||
if err != nil {
|
||||
if err := devices.saveMetadata(); err != nil {
|
||||
devices.Devices[info.Hash] = info
|
||||
utils.Debugf("Error saving meta data: %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -735,6 +711,7 @@ func (devices *DeviceSetDM) RemoveDevice(hash string) error {
|
|||
|
||||
func (devices *DeviceSetDM) DeactivateDevice(hash string) error {
|
||||
if err := devices.ensureInit(); err != nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -745,11 +722,12 @@ func (devices *DeviceSetDM) DeactivateDevice(hash string) error {
|
|||
|
||||
devinfo, err := devices.getInfo(info.Name())
|
||||
if err != nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
if devinfo.Exists != 0 {
|
||||
err := devices.removeDevice(info.Name())
|
||||
if err != nil {
|
||||
if err := devices.removeDevice(info.Name()); err != nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -764,9 +742,8 @@ func (devices *DeviceSetDM) Shutdown() error {
|
|||
|
||||
for path, count := range devices.activeMounts {
|
||||
for i := count; i > 0; i-- {
|
||||
err := syscall.Unmount(path, 0)
|
||||
if err != nil {
|
||||
fmt.Printf("Shutdown unmounting %s, error: %s\n", path, err)
|
||||
if err := syscall.Unmount(path, 0); err != nil {
|
||||
utils.Debugf("Shutdown unmounting %s, error: %s\n", path, err)
|
||||
}
|
||||
}
|
||||
delete(devices.activeMounts, path)
|
||||
|
@ -774,16 +751,14 @@ func (devices *DeviceSetDM) Shutdown() error {
|
|||
|
||||
for _, d := range devices.Devices {
|
||||
if err := devices.DeactivateDevice(d.Hash); err != nil {
|
||||
fmt.Printf("Shutdown deactivate %s , error: %s\n", d.Hash, err)
|
||||
utils.Debugf("Shutdown deactivate %s , error: %s\n", d.Hash, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pool := devices.getPoolDevName()
|
||||
devinfo, err := devices.getInfo(pool)
|
||||
if err == nil && devinfo.Exists != 0 {
|
||||
if devinfo, err := devices.getInfo(pool); err == nil && devinfo.Exists != 0 {
|
||||
if err := devices.removeDevice(pool); err != nil {
|
||||
fmt.Printf("Shutdown deactivate %s , error: %s\n", pool, err)
|
||||
utils.Debugf("Shutdown deactivate %s , error: %s\n", pool, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -792,21 +767,23 @@ func (devices *DeviceSetDM) Shutdown() error {
|
|||
|
||||
func (devices *DeviceSetDM) MountDevice(hash, path string) error {
|
||||
if err := devices.ensureInit(); err != nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
err := devices.activateDeviceIfNeeded(hash)
|
||||
if err != nil {
|
||||
if err := devices.activateDeviceIfNeeded(hash); err != nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
info := devices.Devices[hash]
|
||||
|
||||
err = syscall.Mount(info.DevName(), path, "ext4", syscall.MS_MGC_VAL, "discard")
|
||||
err := syscall.Mount(info.DevName(), path, "ext4", syscall.MS_MGC_VAL, "discard")
|
||||
if err != nil && err == syscall.EINVAL {
|
||||
err = syscall.Mount(info.DevName(), path, "ext4", syscall.MS_MGC_VAL, "")
|
||||
}
|
||||
if err != nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -817,13 +794,12 @@ func (devices *DeviceSetDM) MountDevice(hash, path string) error {
|
|||
}
|
||||
|
||||
func (devices *DeviceSetDM) UnmountDevice(hash, path string) error {
|
||||
err := syscall.Unmount(path, 0)
|
||||
if err != nil {
|
||||
if err := syscall.Unmount(path, 0); err != nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
count := devices.activeMounts[path]
|
||||
if count > 1 {
|
||||
if count := devices.activeMounts[path]; count > 1 {
|
||||
devices.activeMounts[path] = count - 1
|
||||
} else {
|
||||
delete(devices.activeMounts, path)
|
||||
|
@ -832,14 +808,11 @@ func (devices *DeviceSetDM) UnmountDevice(hash, path string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
|
||||
func (devices *DeviceSetDM) HasDevice(hash string) bool {
|
||||
if err := devices.ensureInit(); err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
info := devices.Devices[hash]
|
||||
return info != nil
|
||||
return devices.Devices[hash] != nil
|
||||
}
|
||||
|
||||
func (devices *DeviceSetDM) HasInitializedDevice(hash string) bool {
|
||||
|
@ -860,16 +833,13 @@ func (devices *DeviceSetDM) HasActivatedDevice(hash string) bool {
|
|||
if info == nil {
|
||||
return false
|
||||
}
|
||||
name := info.Name()
|
||||
devinfo, _ := devices.getInfo(name)
|
||||
if devinfo != nil && devinfo.Exists != 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
devinfo, _ := devices.getInfo(info.Name())
|
||||
return devinfo != nil && devinfo.Exists != 0
|
||||
}
|
||||
|
||||
func (devices *DeviceSetDM) SetInitialized(hash string) error {
|
||||
if err := devices.ensureInit(); err != nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -879,9 +849,9 @@ func (devices *DeviceSetDM) SetInitialized(hash string) error {
|
|||
}
|
||||
|
||||
info.Initialized = true
|
||||
err := devices.saveMetadata()
|
||||
if err != nil {
|
||||
if err := devices.saveMetadata(); err != nil {
|
||||
info.Initialized = false
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -889,10 +859,11 @@ func (devices *DeviceSetDM) SetInitialized(hash string) error {
|
|||
}
|
||||
|
||||
func (devices *DeviceSetDM) ensureInit() error {
|
||||
utils.Debugf("ensureInit(). Initialized: %v", devices.initialized)
|
||||
if !devices.initialized {
|
||||
devices.initialized = true
|
||||
err := devices.initDevmapper()
|
||||
if err != nil {
|
||||
if err := devices.initDevmapper(); err != nil {
|
||||
utils.Debugf("\n--->Err: %s\n", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -907,13 +878,11 @@ func NewDeviceSetDM(root string) *DeviceSetDM {
|
|||
base = "docker-" + base
|
||||
}
|
||||
|
||||
devices := &DeviceSetDM{
|
||||
initialized: false,
|
||||
root: root,
|
||||
return &DeviceSetDM{
|
||||
initialized: false,
|
||||
root: root,
|
||||
devicePrefix: base,
|
||||
MetaData: MetaData{Devices: make(map[string]*DevInfo)},
|
||||
activeMounts: make(map[string]int),
|
||||
}
|
||||
devices.Devices = make(map[string]*DevInfo)
|
||||
devices.activeMounts = make(map[string]int)
|
||||
|
||||
return devices
|
||||
}
|
||||
|
|
|
@ -108,30 +108,32 @@ get_block_size(int fd)
|
|||
|
||||
*/
|
||||
import "C"
|
||||
import "unsafe"
|
||||
import "fmt"
|
||||
import "runtime"
|
||||
import "os"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/dotcloud/docker/utils"
|
||||
"os"
|
||||
"runtime"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func SetDevDir(dir string) error {
|
||||
c_dir := C.CString(dir)
|
||||
defer C.free(unsafe.Pointer(c_dir))
|
||||
res := C.dm_set_dev_dir(c_dir)
|
||||
if res != 1 {
|
||||
|
||||
if res := C.dm_set_dev_dir(c_dir); res != 1 {
|
||||
utils.Debugf("Error dm_set_dev_dir")
|
||||
return fmt.Errorf("dm_set_dev_dir failed")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetLibraryVersion() (string, error) {
|
||||
buffer := (*C.char)(C.malloc(128))
|
||||
defer C.free(unsafe.Pointer(buffer))
|
||||
res := C.dm_get_library_version(buffer, 128)
|
||||
if res != 1 {
|
||||
buffer := make([]byte, 128)
|
||||
if res := C.dm_get_library_version((*C.char)(unsafe.Pointer(&buffer)), 128); res != 1 {
|
||||
return "", fmt.Errorf("dm_get_library_version failed")
|
||||
} else {
|
||||
return C.GoString(buffer), nil
|
||||
}
|
||||
return string(buffer), nil
|
||||
}
|
||||
|
||||
type TaskType int
|
||||
|
@ -183,18 +185,17 @@ func (t *Task) destroy() {
|
|||
}
|
||||
|
||||
func TaskCreate(tasktype TaskType) *Task {
|
||||
c_task := C.dm_task_create(C.int(int(tasktype)))
|
||||
c_task := C.dm_task_create(C.int(tasktype))
|
||||
if c_task == nil {
|
||||
return nil
|
||||
}
|
||||
task := &Task{c_task}
|
||||
task := &Task{unmanaged: c_task}
|
||||
runtime.SetFinalizer(task, (*Task).destroy)
|
||||
return task
|
||||
}
|
||||
|
||||
func (t *Task) Run() error {
|
||||
res := C.dm_task_run(t.unmanaged)
|
||||
if res != 1 {
|
||||
if res := C.dm_task_run(t.unmanaged); res != 1 {
|
||||
return fmt.Errorf("dm_task_run failed")
|
||||
}
|
||||
return nil
|
||||
|
@ -204,8 +205,10 @@ func (t *Task) SetName(name string) error {
|
|||
c_name := C.CString(name)
|
||||
defer C.free(unsafe.Pointer(c_name))
|
||||
|
||||
res := C.dm_task_set_name(t.unmanaged, c_name)
|
||||
if res != 1 {
|
||||
if res := C.dm_task_set_name(t.unmanaged, c_name); res != 1 {
|
||||
if os.Getenv("DEBUG") != "" {
|
||||
C.perror(C.CString(fmt.Sprintf("[debug] Error dm_task_set_name(%s, %#v)", name, t.unmanaged)))
|
||||
}
|
||||
return fmt.Errorf("dm_task_set_name failed")
|
||||
}
|
||||
return nil
|
||||
|
@ -215,26 +218,22 @@ func (t *Task) SetMessage(message string) error {
|
|||
c_message := C.CString(message)
|
||||
defer C.free(unsafe.Pointer(c_message))
|
||||
|
||||
res := C.dm_task_set_message(t.unmanaged, c_message)
|
||||
if res != 1 {
|
||||
if res := C.dm_task_set_message(t.unmanaged, c_message); res != 1 {
|
||||
return fmt.Errorf("dm_task_set_message failed")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *Task) SetSector(sector uint64) error {
|
||||
res := C.dm_task_set_sector(t.unmanaged, C.uint64_t(sector))
|
||||
if res != 1 {
|
||||
if res := C.dm_task_set_sector(t.unmanaged, C.uint64_t(sector)); res != 1 {
|
||||
return fmt.Errorf("dm_task_set_add_node failed")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *Task) SetCookie(cookie *uint32, flags uint16) error {
|
||||
var c_cookie C.uint32_t
|
||||
c_cookie = C.uint32_t(*cookie)
|
||||
res := C.dm_task_set_cookie(t.unmanaged, &c_cookie, C.uint16_t(flags))
|
||||
if res != 1 {
|
||||
c_cookie := C.uint32_t(*cookie)
|
||||
if res := C.dm_task_set_cookie(t.unmanaged, &c_cookie, C.uint16_t(flags)); res != 1 {
|
||||
return fmt.Errorf("dm_task_set_add_node failed")
|
||||
}
|
||||
*cookie = uint32(c_cookie)
|
||||
|
@ -242,8 +241,7 @@ func (t *Task) SetCookie(cookie *uint32, flags uint16) error {
|
|||
}
|
||||
|
||||
func (t *Task) SetRo() error {
|
||||
res := C.dm_task_set_ro(t.unmanaged)
|
||||
if res != 1 {
|
||||
if res := C.dm_task_set_ro(t.unmanaged); res != 1 {
|
||||
return fmt.Errorf("dm_task_set_ro failed")
|
||||
}
|
||||
return nil
|
||||
|
@ -256,8 +254,7 @@ func (t *Task) AddTarget(start uint64, size uint64, ttype string, params string)
|
|||
c_params := C.CString(params)
|
||||
defer C.free(unsafe.Pointer(c_params))
|
||||
|
||||
res := C.dm_task_add_target(t.unmanaged, C.uint64_t(start), C.uint64_t(size), c_ttype, c_params)
|
||||
if res != 1 {
|
||||
if res := C.dm_task_add_target(t.unmanaged, C.uint64_t(start), C.uint64_t(size), c_ttype, c_params); res != 1 {
|
||||
return fmt.Errorf("dm_task_add_target failed")
|
||||
}
|
||||
return nil
|
||||
|
@ -267,49 +264,39 @@ func (t *Task) GetDriverVersion() (string, error) {
|
|||
buffer := (*C.char)(C.malloc(128))
|
||||
defer C.free(unsafe.Pointer(buffer))
|
||||
|
||||
res := C.dm_task_get_driver_version(t.unmanaged, buffer, 128)
|
||||
if res != 1 {
|
||||
if res := C.dm_task_get_driver_version(t.unmanaged, buffer, 128); res != 1 {
|
||||
return "", fmt.Errorf("dm_task_get_driver_version")
|
||||
} else {
|
||||
return C.GoString(buffer), nil
|
||||
}
|
||||
return C.GoString(buffer), nil
|
||||
}
|
||||
|
||||
func (t *Task) GetInfo() (*Info, error) {
|
||||
c_info := C.struct_dm_info{}
|
||||
res := C.dm_task_get_info(t.unmanaged, &c_info)
|
||||
if res != 1 {
|
||||
if res := C.dm_task_get_info(t.unmanaged, &c_info); res != 1 {
|
||||
return nil, fmt.Errorf("dm_task_get_driver_version")
|
||||
} else {
|
||||
info := &Info{}
|
||||
info.Exists = int(c_info.exists)
|
||||
info.Suspended = int(c_info.suspended)
|
||||
info.LiveTable = int(c_info.live_table)
|
||||
info.InactiveTable = int(c_info.inactive_table)
|
||||
info.OpenCount = int32(c_info.open_count)
|
||||
info.EventNr = uint32(c_info.event_nr)
|
||||
info.Major = uint32(c_info.major)
|
||||
info.Minor = uint32(c_info.minor)
|
||||
info.ReadOnly = int(c_info.read_only)
|
||||
info.TargetCount = int32(c_info.target_count)
|
||||
|
||||
return info, nil
|
||||
}
|
||||
return &Info{
|
||||
Exists: int(c_info.exists),
|
||||
Suspended: int(c_info.suspended),
|
||||
LiveTable: int(c_info.live_table),
|
||||
InactiveTable: int(c_info.inactive_table),
|
||||
OpenCount: int32(c_info.open_count),
|
||||
EventNr: uint32(c_info.event_nr),
|
||||
Major: uint32(c_info.major),
|
||||
Minor: uint32(c_info.minor),
|
||||
ReadOnly: int(c_info.read_only),
|
||||
TargetCount: int32(c_info.target_count),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (t *Task) GetNextTarget(next uintptr) (uintptr, uint64, uint64, string, string) {
|
||||
nextp := unsafe.Pointer(next)
|
||||
var c_start C.uint64_t
|
||||
var c_length C.uint64_t
|
||||
var c_target_type *C.char
|
||||
var c_params *C.char
|
||||
var (
|
||||
c_start, c_length C.uint64_t
|
||||
c_target_type, c_params *C.char
|
||||
)
|
||||
|
||||
nextp = C.dm_get_next_target(t.unmanaged, nextp, &c_start, &c_length, &c_target_type, &c_params)
|
||||
|
||||
target_type := C.GoString(c_target_type)
|
||||
params := C.GoString(c_params)
|
||||
|
||||
return uintptr(nextp), uint64(c_start), uint64(c_length), target_type, params
|
||||
nextp := C.dm_get_next_target(t.unmanaged, unsafe.Pointer(next), &c_start, &c_length, &c_target_type, &c_params)
|
||||
return uintptr(nextp), uint64(c_start), uint64(c_length), C.GoString(c_target_type), C.GoString(c_params)
|
||||
}
|
||||
|
||||
func AttachLoopDevice(filename string) (*os.File, error) {
|
||||
|
@ -321,19 +308,16 @@ func AttachLoopDevice(filename string) (*os.File, error) {
|
|||
if res == nil {
|
||||
return nil, fmt.Errorf("error loopback mounting")
|
||||
}
|
||||
file := os.NewFile(uintptr(fd), C.GoString(res))
|
||||
C.free(unsafe.Pointer(res))
|
||||
return file, nil
|
||||
defer C.free(unsafe.Pointer(res))
|
||||
return os.NewFile(uintptr(fd), C.GoString(res)), nil
|
||||
}
|
||||
|
||||
func GetBlockDeviceSize(file *os.File) (uint64, error) {
|
||||
fd := file.Fd()
|
||||
size := C.get_block_size(C.int(fd))
|
||||
if size == -1 {
|
||||
if size := C.get_block_size(C.int(file.Fd())); size == -1 {
|
||||
return 0, fmt.Errorf("Can't get block size")
|
||||
} else {
|
||||
return uint64(size), nil
|
||||
}
|
||||
return uint64(size), nil
|
||||
|
||||
}
|
||||
|
||||
func UdevWait(cookie uint32) error {
|
||||
|
@ -354,12 +338,10 @@ func RemoveDevice(name string) error {
|
|||
if task == nil {
|
||||
return fmt.Errorf("Can't create task of type DeviceRemove")
|
||||
}
|
||||
err := task.SetName(name)
|
||||
if err != nil {
|
||||
if err := task.SetName(name); err != nil {
|
||||
return fmt.Errorf("Can't set task name %s", name)
|
||||
}
|
||||
err = task.Run()
|
||||
if err != nil {
|
||||
if err := task.Run(); err != nil {
|
||||
return fmt.Errorf("Error running removeDevice")
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -123,7 +123,7 @@ func daemon(pidfile string, flGraphPath string, protoAddrs []string, autoRestart
|
|||
defer removePidFile(pidfile)
|
||||
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, os.Interrupt, os.Kill, os.Signal(syscall.SIGTERM))
|
||||
signal.Notify(c, os.Interrupt, os.Kill, syscall.SIGTERM)
|
||||
go func() {
|
||||
sig := <-c
|
||||
log.Printf("Received signal '%v', exiting\n", sig)
|
||||
|
|
|
@ -11,7 +11,7 @@ bundle_test() {
|
|||
for test_dir in $(find_test_dirs); do (
|
||||
set -x
|
||||
cd $test_dir
|
||||
go test -v -ldflags "$LDFLAGS" $BUILDFLAGS
|
||||
DEBUG=1 go test -v -ldflags "$LDFLAGS" $BUILDFLAGS -run TestRunHostname
|
||||
) done
|
||||
} 2>&1 | tee $DEST/test.log
|
||||
}
|
||||
|
|
46
image.go
46
image.go
|
@ -378,28 +378,28 @@ func (image *Image) ensureImageDevice(devices DeviceSet) error {
|
|||
}
|
||||
|
||||
utils.Debugf("Creating device-mapper device for image id %s", image.ID)
|
||||
err = devices.AddDevice(image.ID, image.Parent)
|
||||
if err != nil {
|
||||
if err := devices.AddDevice(image.ID, image.Parent); err != nil {
|
||||
utils.Debugf("Error add device: %s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
err = devices.MountDevice(image.ID, mountDir)
|
||||
if err != nil {
|
||||
_ = devices.RemoveDevice(image.ID)
|
||||
if err := devices.MountDevice(image.ID, mountDir); err != nil {
|
||||
utils.Debugf("Error mounting device: %s", err)
|
||||
devices.RemoveDevice(image.ID)
|
||||
return err
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(path.Join(mountDir, ".docker-id"), []byte(image.ID), 0600)
|
||||
if err != nil {
|
||||
_ = devices.UnmountDevice(image.ID, mountDir)
|
||||
_ = devices.RemoveDevice(image.ID)
|
||||
if err := ioutil.WriteFile(path.Join(mountDir, ".docker-id"), []byte(image.ID), 0600); err != nil {
|
||||
utils.Debugf("Error writing file: %s", err)
|
||||
devices.UnmountDevice(image.ID, mountDir)
|
||||
devices.RemoveDevice(image.ID)
|
||||
return err
|
||||
}
|
||||
|
||||
err = image.applyLayer(layerPath(root), mountDir)
|
||||
if err != nil {
|
||||
_ = devices.UnmountDevice(image.ID, mountDir)
|
||||
_ = devices.RemoveDevice(image.ID)
|
||||
if err = image.applyLayer(layerPath(root), mountDir); err != nil {
|
||||
utils.Debugf("Error applying layer: %s", err)
|
||||
devices.UnmountDevice(image.ID, mountDir)
|
||||
devices.RemoveDevice(image.ID)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -415,16 +415,15 @@ func (image *Image) ensureImageDevice(devices DeviceSet) error {
|
|||
_ = devices.RemoveDevice(image.ID)
|
||||
return err
|
||||
}
|
||||
err = image.applyLayer(dockerinitLayer, mountDir)
|
||||
if err != nil {
|
||||
_ = devices.UnmountDevice(image.ID, mountDir)
|
||||
_ = devices.RemoveDevice(image.ID)
|
||||
|
||||
if err := image.applyLayer(dockerinitLayer, mountDir); err != nil {
|
||||
devices.UnmountDevice(image.ID, mountDir)
|
||||
devices.RemoveDevice(image.ID)
|
||||
return err
|
||||
}
|
||||
|
||||
err = devices.UnmountDevice(image.ID, mountDir)
|
||||
if err != nil {
|
||||
_ = devices.RemoveDevice(image.ID)
|
||||
if err := devices.UnmountDevice(image.ID, mountDir); err != nil {
|
||||
devices.RemoveDevice(image.ID)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -455,8 +454,8 @@ func (image *Image) Mount(runtime *Runtime, root, rw string, id string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = image.ensureImageDevice(devices)
|
||||
if err != nil {
|
||||
|
||||
if err := image.ensureImageDevice(devices); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -471,8 +470,7 @@ func (image *Image) Mount(runtime *Runtime, root, rw string, id string) error {
|
|||
}
|
||||
|
||||
utils.Debugf("Mounting container %s at %s for container", id, root)
|
||||
err = devices.MountDevice(id, root)
|
||||
if err != nil {
|
||||
if err := devices.MountDevice(id, root); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
14
server.go
14
server.go
|
@ -1307,7 +1307,7 @@ func NewServer(flGraphPath string, deviceSet DeviceSet, autoRestart, enableCors
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
srv := &Server{
|
||||
runtime.srv = &Server{
|
||||
runtime: runtime,
|
||||
enableCors: enableCors,
|
||||
pullingPool: make(map[string]struct{}),
|
||||
|
@ -1316,18 +1316,14 @@ func NewServer(flGraphPath string, deviceSet DeviceSet, autoRestart, enableCors
|
|||
listeners: make(map[string]chan utils.JSONMessage),
|
||||
reqFactory: nil,
|
||||
}
|
||||
runtime.srv = srv
|
||||
return srv, nil
|
||||
return runtime.srv, nil
|
||||
}
|
||||
|
||||
func (srv *Server) HTTPRequestFactory(metaHeaders map[string][]string) *utils.HTTPRequestFactory {
|
||||
if srv.reqFactory == nil {
|
||||
ud := utils.NewHTTPUserAgentDecorator(srv.versionInfos()...)
|
||||
md := &utils.HTTPMetaHeadersDecorator{
|
||||
Headers: metaHeaders,
|
||||
}
|
||||
factory := utils.NewHTTPRequestFactory(ud, md)
|
||||
srv.reqFactory = factory
|
||||
srv.reqFactory = utils.NewHTTPRequestFactory(
|
||||
utils.NewHTTPUserAgentDecorator(srv.versionInfos()...),
|
||||
&utils.HTTPMetaHeadersDecorator{Headers: metaHeaders})
|
||||
}
|
||||
return srv.reqFactory
|
||||
}
|
||||
|
|
|
@ -59,7 +59,15 @@ func Debugf(format string, a ...interface{}) {
|
|||
file = file[strings.LastIndex(file, "/")+1:]
|
||||
}
|
||||
|
||||
fmt.Fprintf(os.Stderr, fmt.Sprintf("[debug] %s:%d %s\n", file, line, format), a...)
|
||||
_, file2, line2, ok := runtime.Caller(2)
|
||||
if !ok {
|
||||
file2 = "<unknown>"
|
||||
line2 = -1
|
||||
} else {
|
||||
file2 = file2[strings.LastIndex(file2, "/")+1:]
|
||||
}
|
||||
|
||||
fmt.Fprintf(os.Stderr, fmt.Sprintf("[debug] %s:%d %s:%d %s\n", file, line, file2, line2, format), a...)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче