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

Commit

Permalink
Merge pull request #659 from bergwolf/dm-name
Browse files Browse the repository at this point in the history
dm: limit device name length
  • Loading branch information
laijs authored Aug 25, 2017
2 parents a3db7eb + 67b6242 commit bb3ac60
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions daemon/storage.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package daemon

import (
"crypto/sha256"
"encoding/hex"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit bb3ac60

Please sign in to comment.