Skip to content

Commit

Permalink
Merge pull request #1234 from opensds/development
Browse files Browse the repository at this point in the history
Merge development branch into master for v0.10.2 release
  • Loading branch information
skdwriting authored Feb 10, 2020
2 parents d7ab66c + e5629be commit 3f1209e
Show file tree
Hide file tree
Showing 59 changed files with 1,801 additions and 200 deletions.
1 change: 1 addition & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func processListParam(args []interface{}) (string, error) {
if v == "" {
continue
}
v = strings.Replace(v, " ", "%20", -1)
urlParam = append(urlParam, k+"="+v)
}
}
Expand Down
12 changes: 0 additions & 12 deletions contrib/connector/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,6 @@ func Mount(device, mountpoint, fsType string, mountFlags []string) error {
return err
}

// Make sure the mount is not lost after the host reboots
cmd := fmt.Sprintf("echo \"%s %s %s defaults 0 0\" >> /etc/fstab", device, mountpoint, fsType)
_, err = ExecCmd("/bin/bash", "-c", cmd)
if err != nil {
return err
}

return nil
}

Expand All @@ -131,11 +124,6 @@ func Umount(mountpoint string) error {
return err
}

cmd := fmt.Sprintf("cat -n /etc/fstab | grep -w '%s' | awk -F ' ' '{ print $1 }'| xargs -i sed -i '{}d' /etc/fstab", mountpoint)
_, err = ExecCmd("/bin/bash", "-c", cmd)
if err != nil {
return err
}
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion contrib/connector/connector.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const (
type Connector interface {
Attach(map[string]interface{}) (string, error)
Detach(map[string]interface{}) error
GetInitiatorInfo() (string, error)
GetInitiatorInfo() ([]string, error)
}

var cnts = map[string]Connector{}
Expand Down
2 changes: 1 addition & 1 deletion contrib/connector/fc/fc.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ func (f *FC) Detach(conn map[string]interface{}) error {
}

// GetInitiatorInfo ...
func (f *FC) GetInitiatorInfo() (string, error) {
func (f *FC) GetInitiatorInfo() ([]string, error) {
return getInitiatorInfo()
}
25 changes: 17 additions & 8 deletions contrib/connector/fc/fibreChannel.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ func connectVolume(connMap map[string]interface{}) (map[string]string, error) {
return nil, err
}

dmPath, err := getMultipathDevice(deviceWWN)
if err != nil {
return nil, err
}
if len(dmPath) > 0 {
devicePath = dmPath
}

return map[string]string{"scsi_wwn": deviceWWN, "path": devicePath}, nil
}

Expand Down Expand Up @@ -227,22 +235,23 @@ func getFChbasInfo() ([]map[string]string, error) {
return hbasInfos, nil
}

func getInitiatorInfo() (string, error) {
func getInitiatorInfo() ([]string, error) {
hbas, err := getFChbasInfo()
if err != nil {
return "", err
return nil, err
}

var initiatorInfo []string

for _, hba := range hbas {
if v, ok := hba[connector.PortName]; ok {
initiatorInfo = append(initiatorInfo, "port_name:"+v)
}
if v, ok := hba[connector.NodeName]; ok {
initiatorInfo = append(initiatorInfo, "node_name:"+v)
initiatorInfo = append(initiatorInfo, v)
}
}

return strings.Join(initiatorInfo, ","), nil
//Check for atleast one initiator
if (0 == len(initiatorInfo)){
return nil, errors.New("No initiator info found.")
}

return initiatorInfo, nil
}
25 changes: 25 additions & 0 deletions contrib/connector/fc/linuxfc.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,28 @@ func trimDoubleQuotesInText(str string) string {
}
return str
}

func getMultipathDevice(deviceWWN string) (string, error) {
cmd := fmt.Sprintf("ls -l /dev/disk/by-id/ | grep %s", deviceWWN)
out, err := connector.ExecCmd("/bin/bash", "-c", cmd)
if err != nil {
msg := fmt.Sprintf("No DM of wwn %s exist", deviceWWN)
log.Println(msg)
return "", nil
}

lines := strings.Split(strings.TrimSpace(out), "\n")
for _, line := range lines {
splits := strings.Split(line, "../../")
if len(splits) == 2 {
name := splits[1]
if strings.HasPrefix(name, "dm") {
return fmt.Sprintf("/dev/%s", name), nil
}
}
}

msg := fmt.Sprintf("No DM of wwn %s exist", deviceWWN)
log.Println(msg)
return "", nil
}
10 changes: 5 additions & 5 deletions contrib/connector/iscsi/helper.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -372,19 +372,19 @@ func getTgtPortalAndTgtIQN() (string, string, error) {

}

func getInitiatorInfo() (string, error) {
func getInitiatorInfo() ([]string, error) {
initiators, err := getInitiator()
if err != nil {
return "", err
return nil, err
}

if len(initiators) == 0 {
return "", errors.New("No iqn found")
return nil, errors.New("No iqn found")
}

if len(initiators) > 1 {
return "", errors.New("the number of iqn is wrong")
return nil, errors.New("the number of iqn is wrong")
}

return initiators[0], nil
return initiators, nil
}
2 changes: 1 addition & 1 deletion contrib/connector/iscsi/iscsi.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ func (isc *Iscsi) Detach(conn map[string]interface{}) error {
}

// GetInitiatorInfo implementation
func (isc *Iscsi) GetInitiatorInfo() (string, error) {
func (isc *Iscsi) GetInitiatorInfo() ([]string, error) {
return getInitiatorInfo()
}
4 changes: 2 additions & 2 deletions contrib/connector/nfs/helper.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,6 @@ func disconnect(conn map[string]interface{}) error {
return errors.New("disconnect method of nfs is not implemented")
}

func getInitiatorInfo() (string, error) {
return "", errors.New("get initiator information method of nfs is not implemented")
func getInitiatorInfo() ([]string, error) {
return nil, errors.New("get initiator information method of nfs is not implemented")
}
2 changes: 1 addition & 1 deletion contrib/connector/nfs/nfs.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ func (n *NFS) Detach(conn map[string]interface{}) error {
}

// GetInitiatorInfo implementation
func (n *NFS) GetInitiatorInfo() (string, error) {
func (n *NFS) GetInitiatorInfo() ([]string, error) {
return getInitiatorInfo()
}
2 changes: 1 addition & 1 deletion contrib/connector/nvmeof/nvmeof.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ func (nof *Nvmeof) Detach(conn map[string]interface{}) error {
}

// GetInitiatorInfo implementation
func (nof *Nvmeof) GetInitiatorInfo() (string, error) {
func (nof *Nvmeof) GetInitiatorInfo() ([]string, error) {
return getInitiatorInfo()
}
18 changes: 11 additions & 7 deletions contrib/connector/nvmeof/nvmeof_helper.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,32 @@ func GetInitiator() ([]string, error) {
return nqns, errors.New("can not find any nqn initiator")
}

func getInitiatorInfo() (string, error) {
func getInitiatorInfo() ([]string, error) {

initiators, err := GetInitiator()
if err != nil {
return "", err
return nil, err
}

if len(initiators) == 0 {
return "", errors.New("no nqn found")
return nil, errors.New("no nqn found")
}

if len(initiators) > 1 {
return "", errors.New("the number of nqn is wrong")
return nil, errors.New("the number of nqn is wrong")
}

hostName, err := connector.GetHostName()
if err != nil {
return "", errors.New("can not get hostname")
return nil, errors.New("can not get hostname")
}

info := initiators[0] + "." + hostName
return info, nil
hostName = initiators[0] + "." + hostName

initiator := make([]string, 1)
initiator = append(initiator, hostName)

return initiator, nil
}

// GetNvmeDevice get all the nvme devices
Expand Down
10 changes: 7 additions & 3 deletions contrib/connector/rbd/rbd.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,18 @@ func (*RBD) Detach(conn map[string]interface{}) error {
}

// GetInitiatorInfo implementation
func (*RBD) GetInitiatorInfo() (string, error) {
func (*RBD) GetInitiatorInfo() ([]string, error) {

hostName, err := connector.GetHostName()

if err != nil {
return "", err
return nil, err
}

return hostName, nil
initiator := make([]string, 1)
initiator = append(initiator, hostName)

return initiator, nil
}

func parseName(name string) (poolName, imageName, snapName string, err error) {
Expand Down
Loading

0 comments on commit 3f1209e

Please sign in to comment.