Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: CheckVolumeExists() optimization and new GetVolumeWwn() #18

Merged
merged 2 commits into from
May 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,18 +389,17 @@ func (client *Client) mapVolumeProcess(volumeName, initiatorName string, lun int

// CheckVolumeExists: Return true if a volume already exists
func (client *Client) CheckVolumeExists(volumeID string, size int64) (bool, error) {
data, responseStatus, err := client.ShowVolumes()
data, responseStatus, err := client.ShowVolumes(volumeID)
if err != nil && responseStatus.ReturnCode != badInputParam {
return false, err
}

for _, object := range data.Objects {
if object.Name == "volume" {
klog.V(2).Infof("volume exists: checking (%s) for (%s) size (%d)", object.PropertiesMap["volume-name"].Data, volumeID, size)

if object.PropertiesMap["volume-name"].Data == volumeID {
blocks, _ := strconv.ParseInt(object.PropertiesMap["blocks"].Data, 10, 64)
blocksize, _ := strconv.ParseInt(object.PropertiesMap["blocksize"].Data, 10, 64)
klog.V(3).Infof("volume exists: checking (%s) size (%d) against blocksize (%d)", volumeID, size, blocksize)

if blocks*blocksize == size {
return true, nil
Expand Down Expand Up @@ -444,3 +443,18 @@ func (client *Client) PublishVolume(volumeId string, initiatorName string) (stri
klog.Infof("successfully mapped volume (%s) for initiator (%s) using LUN (%d)", volumeId, initiatorName, lun)
return strconv.Itoa(lun), nil
}

// GetVolumeWwn: Retrieve the WWN for a volume, very useful for host operating system device mapping
func (client *Client) GetVolumeWwn(volumeName string) (string, error) {

wwn := ""
response, status, err := client.ShowVolumes(volumeName)
if err == nil && status.ResponseTypeNumeric == 0 {
if response.ObjectsMap["volume"] != nil {
wwn = strings.ToLower(response.ObjectsMap["volume"].PropertiesMap["wwn"].Data)
}
}

klog.V(3).Infof("GetVolumeWwn (%s) returning wwn (%s)", volumeName, wwn)
return wwn, err
}