Skip to content

Commit 3dab5dc

Browse files
NajmudheenCTskdwriting
authored andcommitted
Implementation of Unique Durable Identifier for Volume (#1001)
* Adding scsi id for tagets and use it as wwn for volumes * Implemnted Durable identifier for volume model changes and lvm driver changes
1 parent 6d22464 commit 3dab5dc

5 files changed

Lines changed: 28 additions & 3 deletions

File tree

contrib/drivers/lvm/lvm.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ const (
4848
)
4949

5050
const (
51-
KLvPath = "lvPath"
52-
KLvsPath = "lvsPath"
51+
KLvPath = "lvPath"
52+
KLvsPath = "lvsPath"
53+
KLvIdFormat = "NAA"
5354
)
5455

5556
type LVMConfig struct {
@@ -171,6 +172,7 @@ func (d *Driver) CreateVolume(opt *pb.CreateVolumeOpts) (vol *model.VolumeSpec,
171172
Name: opt.GetName(),
172173
Size: opt.GetSize(),
173174
Description: opt.GetDescription(),
175+
Identifier: &model.Identifier{DurableName: targets.CreateScsiIDFromVolID(opt.GetId()), DurableNameFormat: KLvIdFormat},
174176
Metadata: map[string]string{
175177
KLvPath: lvPath,
176178
},

contrib/drivers/lvm/lvm_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ func TestCreateVolume(t *testing.T) {
117117
Name: "test001",
118118
Description: "volume for testing",
119119
Size: int64(1),
120+
Identifier: &model.Identifier{DurableName: "61bb066c5ce746eb933625508cee9f71", DurableNameFormat: "NAA"},
120121
Metadata: map[string]string{
121122
"lvPath": "/dev/vg001/volume-e1bb066c-5ce7-46eb-9336-25508cee9f71",
122123
},
@@ -157,6 +158,7 @@ func TestCreateVolumeFromSnapshot(t *testing.T) {
157158
Name: "test001",
158159
Description: "volume for testing",
159160
Size: int64(1),
161+
Identifier: &model.Identifier{DurableName: "61bb066c5ce746eb933625508cee9f71", DurableNameFormat: "NAA"},
160162
Metadata: map[string]string{
161163
"lvPath": "/dev/vg001/volume-e1bb066c-5ce7-46eb-9336-25508cee9f71",
162164
},

contrib/drivers/lvm/targets/iscsi.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ func (t *tgtTarget) getTgtConfPath(volId string) string {
8686

8787
type configMap map[string][]string
8888

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

110118
configFile := t.getTgtConfPath(volId)
119+
scsiID := CreateScsiIDFromVolID(volId)
111120

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

131141
err := config.writeConfig(configFile, tgtIqn)
132142
if err != nil {

pkg/db/drivers/etcd/etcd.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,6 +1993,9 @@ func (c *Client) UpdateVolume(ctx *c.Context, vol *model.VolumeSpec) (*model.Vol
19931993
if vol.Metadata != nil {
19941994
result.Metadata = utils.MergeStringMaps(result.Metadata, vol.Metadata)
19951995
}
1996+
if vol.Identifier != nil {
1997+
result.Identifier = vol.Identifier
1998+
}
19961999
if vol.PoolId != "" {
19972000
result.PoolId = vol.PoolId
19982001
}

pkg/model/volume.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,15 @@ type VolumeSpec struct {
8383
AttachStatus string
8484

8585
// Whether the volume can be attached more than once, default value is false.
86-
MultiAttach bool `json:"multiAttach,omitempty"`
86+
MultiAttach bool `json:"multiAttach,omitempty"`
87+
Identifier *Identifier `json:"identifier,omitempty"`
88+
}
89+
90+
// This type describes any additional identifiers for a resource which is used to uniquly identify the resource.
91+
type Identifier struct {
92+
//This indicates the world wide, persistent name of the resource
93+
DurableName string `json:"durableName,omitempty"`
94+
DurableNameFormat string `json:"durableNameFormat,omitempty"`
8795
}
8896

8997
// VolumeAttachmentSpec is a description of volume attached resource.

0 commit comments

Comments
 (0)