From 67b62427e1256eeaa8cb332d276ec74f82d0c574 Mon Sep 17 00:00:00 2001 From: Peng Tao Date: Fri, 25 Aug 2017 14:55:46 +0800 Subject: [PATCH] dm: limit device name length Kernel dm driver has name length limit < 128 bytes. Signed-off-by: Peng Tao --- daemon/storage.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/daemon/storage.go b/daemon/storage.go index 6fd757fe..71583172 100644 --- a/daemon/storage.go +++ b/daemon/storage.go @@ -1,6 +1,8 @@ package daemon import ( + "crypto/sha256" + "encoding/hex" "errors" "fmt" "io" @@ -182,9 +184,14 @@ func (dms *DevMapperStorage) getPersistedId(podId, volName string) (int, error) func (dms *DevMapperStorage) CreateVolume(podId string, spec *apitypes.UserVolume) error { var err error - deviceName := fmt.Sprintf("%s-%s-%s", dms.VolPoolName, podId, spec.Name) + // kernel dm has limitation of 128 bytes on device name length + // include/uapi/linux/dm-ioctl.h#L16 + // #define DM_NAME_LEN 128 + // Use sha256 so it is fixed 64 bytes + chksum := sha256.Sum256([]byte(podId + spec.Name)) + deviceName := fmt.Sprintf("%s-%s", dms.VolPoolName, hex.EncodeToString(chksum[:sha256.Size])) dev_id, _ := dms.getPersistedId(podId, deviceName) - glog.Infof("DeviceID is %d", dev_id) + glog.Infof("DeviceID is %d for %s of pod %s container %s", dev_id, deviceName, podId, spec.Name) restore := dev_id > 0