From 3480fd3466a151df28683d3bc71cf1f3c12a0b6e Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Mon, 22 Jun 2015 20:28:15 -0400 Subject: [PATCH] pkg/devicemapper: external device activation Reported-by: Sheng Yang Signed-off-by: Vincent Batts --- devicemapper/devmapper.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/devicemapper/devmapper.go b/devicemapper/devmapper.go index e7f17b8..3c58173 100644 --- a/devicemapper/devmapper.go +++ b/devicemapper/devmapper.go @@ -686,12 +686,25 @@ func DeleteDevice(poolName string, deviceId int) error { } func ActivateDevice(poolName string, name string, deviceId int, size uint64) error { + return activateDevice(poolName, name, deviceId, size, "") +} + +func ActivateDeviceWithExternal(poolName string, name string, deviceId int, size uint64, external string) error { + return activateDevice(poolName, name, deviceId, size, external) +} + +func activateDevice(poolName string, name string, deviceId int, size uint64, external string) error { task, err := TaskCreateNamed(DeviceCreate, name) if task == nil { return err } - params := fmt.Sprintf("%s %d", poolName, deviceId) + var params string + if len(external) > 0 { + params = fmt.Sprintf("%s %d %s", poolName, deviceId, external) + } else { + params = fmt.Sprintf("%s %d", poolName, deviceId) + } if err := task.AddTarget(0, size/512, "thin", params); err != nil { return fmt.Errorf("Can't add target %s", err) }