Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit bb3ac60

Browse files
authored
Merge pull request #659 from bergwolf/dm-name
dm: limit device name length
2 parents a3db7eb + 67b6242 commit bb3ac60

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

daemon/storage.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package daemon
22

33
import (
4+
"crypto/sha256"
5+
"encoding/hex"
46
"errors"
57
"fmt"
68
"io"
@@ -182,9 +184,14 @@ func (dms *DevMapperStorage) getPersistedId(podId, volName string) (int, error)
182184
func (dms *DevMapperStorage) CreateVolume(podId string, spec *apitypes.UserVolume) error {
183185
var err error
184186

185-
deviceName := fmt.Sprintf("%s-%s-%s", dms.VolPoolName, podId, spec.Name)
187+
// kernel dm has limitation of 128 bytes on device name length
188+
// include/uapi/linux/dm-ioctl.h#L16
189+
// #define DM_NAME_LEN 128
190+
// Use sha256 so it is fixed 64 bytes
191+
chksum := sha256.Sum256([]byte(podId + spec.Name))
192+
deviceName := fmt.Sprintf("%s-%s", dms.VolPoolName, hex.EncodeToString(chksum[:sha256.Size]))
186193
dev_id, _ := dms.getPersistedId(podId, deviceName)
187-
glog.Infof("DeviceID is %d", dev_id)
194+
glog.Infof("DeviceID is %d for %s of pod %s container %s", dev_id, deviceName, podId, spec.Name)
188195

189196
restore := dev_id > 0
190197

0 commit comments

Comments
 (0)