Skip to content

Commit

Permalink
Implementation of Unique Durable Identifier for Volume (#1001)
Browse files Browse the repository at this point in the history
*  Adding scsi id for tagets and use it as wwn for volumes

*  Implemnted Durable identifier for volume model changes and lvm driver changes
  • Loading branch information
NajmudheenCT authored and skdwriting committed Nov 15, 2019
1 parent 6d22464 commit 3dab5dc
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
6 changes: 4 additions & 2 deletions contrib/drivers/lvm/lvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ const (
)

const (
KLvPath = "lvPath"
KLvsPath = "lvsPath"
KLvPath = "lvPath"
KLvsPath = "lvsPath"
KLvIdFormat = "NAA"
)

type LVMConfig struct {
Expand Down Expand Up @@ -171,6 +172,7 @@ func (d *Driver) CreateVolume(opt *pb.CreateVolumeOpts) (vol *model.VolumeSpec,
Name: opt.GetName(),
Size: opt.GetSize(),
Description: opt.GetDescription(),
Identifier: &model.Identifier{DurableName: targets.CreateScsiIDFromVolID(opt.GetId()), DurableNameFormat: KLvIdFormat},
Metadata: map[string]string{
KLvPath: lvPath,
},
Expand Down
2 changes: 2 additions & 0 deletions contrib/drivers/lvm/lvm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func TestCreateVolume(t *testing.T) {
Name: "test001",
Description: "volume for testing",
Size: int64(1),
Identifier: &model.Identifier{DurableName: "61bb066c5ce746eb933625508cee9f71", DurableNameFormat: "NAA"},
Metadata: map[string]string{
"lvPath": "/dev/vg001/volume-e1bb066c-5ce7-46eb-9336-25508cee9f71",
},
Expand Down Expand Up @@ -157,6 +158,7 @@ func TestCreateVolumeFromSnapshot(t *testing.T) {
Name: "test001",
Description: "volume for testing",
Size: int64(1),
Identifier: &model.Identifier{DurableName: "61bb066c5ce746eb933625508cee9f71", DurableNameFormat: "NAA"},
Metadata: map[string]string{
"lvPath": "/dev/vg001/volume-e1bb066c-5ce7-46eb-9336-25508cee9f71",
},
Expand Down
10 changes: 10 additions & 0 deletions contrib/drivers/lvm/targets/iscsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ func (t *tgtTarget) getTgtConfPath(volId string) string {

type configMap map[string][]string

func CreateScsiIDFromVolID(volID string) string {
//Construct a 32 digit NAA.6 ( Network Addressing Authority) Identifier for the volume.
scsi_id := strings.Replace(volID, "-", "", -1)
out := []rune(scsi_id)
// Make the first digit 6 , which specifies the IEEE registerd extended format for WWN.
out[0] = '6'
return string(out)
}
func (t *tgtTarget) CreateISCSITarget(volId, tgtIqn, path, hostIp, initiator string, chapAuth []string) error {
// Multi-attach require a specific ip
if hostIp == "" || hostIp == "ALL" {
Expand All @@ -108,6 +116,7 @@ func (t *tgtTarget) CreateISCSITarget(volId, tgtIqn, path, hostIp, initiator str
config := make(configMap)

configFile := t.getTgtConfPath(volId)
scsiID := CreateScsiIDFromVolID(volId)

if IsExist(configFile) {
data, err := ioutil.ReadFile(configFile)
Expand All @@ -127,6 +136,7 @@ func (t *tgtTarget) CreateISCSITarget(volId, tgtIqn, path, hostIp, initiator str
config.updateConfigmap("driver", "iscsi")
config.updateConfigmap("backing-store", path)
config.updateConfigmap("write-cache", "on")
config.updateConfigmap("scsi_id", scsiID)

err := config.writeConfig(configFile, tgtIqn)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions pkg/db/drivers/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -1993,6 +1993,9 @@ func (c *Client) UpdateVolume(ctx *c.Context, vol *model.VolumeSpec) (*model.Vol
if vol.Metadata != nil {
result.Metadata = utils.MergeStringMaps(result.Metadata, vol.Metadata)
}
if vol.Identifier != nil {
result.Identifier = vol.Identifier
}
if vol.PoolId != "" {
result.PoolId = vol.PoolId
}
Expand Down
10 changes: 9 additions & 1 deletion pkg/model/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,15 @@ type VolumeSpec struct {
AttachStatus string

// Whether the volume can be attached more than once, default value is false.
MultiAttach bool `json:"multiAttach,omitempty"`
MultiAttach bool `json:"multiAttach,omitempty"`
Identifier *Identifier `json:"identifier,omitempty"`
}

// This type describes any additional identifiers for a resource which is used to uniquly identify the resource.
type Identifier struct {
//This indicates the world wide, persistent name of the resource
DurableName string `json:"durableName,omitempty"`
DurableNameFormat string `json:"durableNameFormat,omitempty"`
}

// VolumeAttachmentSpec is a description of volume attached resource.
Expand Down

0 comments on commit 3dab5dc

Please sign in to comment.