Skip to content

Commit

Permalink
Update V3.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
cabbetlong committed Aug 1, 2024
1 parent ef9a6a5 commit 7ec82c5
Show file tree
Hide file tree
Showing 23 changed files with 403 additions and 405 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM busybox:stable-glibc

LABEL maintainers="The Huawei CSI Team"
LABEL description="Kubernetes CSI Driver for Huawei Storage"
LABEL version="3.2.2"
LABEL version="3.2.3"

COPY huawei-csi /

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# usage: make -f Makefile VER=3.2.2 PLATFORM=X86 RELEASE_VER=2.5.RC3
# usage: make -f Makefile VER=3.2.3 PLATFORM=X86 RELEASE_VER=2.5.RC3

# (required) [3.2.2]
# (required) [3.2.3]
VER=VER
# (required) [X86 ARM]
PLATFORM=PLATFORM
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Step 1. Download the package and **cd** into the package
Step 2. Run following command to compile the Huawei CSI Driver

// PLATFORM support [X86|ARM]
make -f Makefile VER=3.2.2 PLATFORM=X86
make -f Makefile VER=3.2.3 PLATFORM=X86

Step 3. After the compilation is finished, a bin directory will be created in the current
directory, the structure is as follows:
Expand Down
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
# limitations under the License.
#

# usage: sh build.sh 3.2.2 X86
# usage: sh build.sh 3.2.3 X86

# [3.2.2]
# [3.2.3]
VER=$1
# [X86 ARM]
PLATFORM=$2
Expand Down
58 changes: 58 additions & 0 deletions connector/connector_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
Expand All @@ -44,6 +45,10 @@ const (
UseUltraPath
// UseUltraPathNVMe means the device use huawei-UltraPath-NVMe service
UseUltraPathNVMe
// How many times to retry for a consistent read of /proc/mounts.
maxListTries = 10
// Location of the mount file to use
procMountsPath = "/proc/mounts"
)

var (
Expand Down Expand Up @@ -1777,3 +1782,56 @@ func isUpMultiPathAvailable(ctx context.Context, multipathType, dev, lunWWN stri

return true, nil
}

// MountPathIsExist if mount point exist in /proc/mounts file, this function will return true
func MountPathIsExist(ctx context.Context, mountPoint string) (bool, error) {
mountMap, err := ReadMountPoints(ctx)
if err != nil {
return false, err
}
_, ok := mountMap[mountPoint]
return ok, nil
}

// ReadMountPoints read mount file
// mountMap: key means mountPath; value means devicePath.
func ReadMountPoints(ctx context.Context) (map[string]string, error) {
data, err := ConsistentRead(procMountsPath, maxListTries)
if err != nil {
log.AddContext(ctx).Errorf("Read the mount file error: %v", err)
return nil, err
}

mountMap := make(map[string]string)
for _, line := range strings.Split(string(data), "\n") {
if strings.TrimSpace(line) != "" {
splitValue := strings.Split(line, " ")
if len(splitValue) >= 2 && splitValue[0] != "#" {
mountMap[splitValue[1]] = splitValue[0]
}
}
}
return mountMap, nil
}

// ConsistentRead repeatedly reads a file until it gets the same content twice.
// This is useful when reading files in /proc/mount that are larger than page size
// and kernel may modify them between individual read() syscalls
func ConsistentRead(filename string, attempts int) ([]byte, error) {
oldContent, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
for i := 0; i < attempts; i++ {
newContent, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
if bytes.Equal(oldContent, newContent) {
return newContent, nil
}
// Files are different, continue reading
oldContent = newContent
}
return nil, fmt.Errorf("could not get consistent content of %s after %d attempts", filename, attempts)
}
31 changes: 27 additions & 4 deletions connector/iscsi/iscsi_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,17 @@ import (
connutils "huawei-csi-driver/connector/utils"
"huawei-csi-driver/csi/app"
"huawei-csi-driver/utils"
"huawei-csi-driver/utils/concurrent"
"huawei-csi-driver/utils/log"
)

var singleGroup = concurrent.NewSingleGroup()

type connectResult struct {
sessionId string
manualScan bool
}

type chapInfo struct {
authUserName string
authPassword string
Expand Down Expand Up @@ -246,6 +254,21 @@ func getAllISCSISession(ctx context.Context) [][]string {
return iSCSIInfo
}

func singleConnectISCSIPortal(ctx context.Context, tgtPortal, targetIQN string, tgtChapInfo chapInfo) (string, bool) {
key := fmt.Sprintf("%s::%s", tgtPortal, targetIQN)
res, _ := singleGroup.Do(key, func() (interface{}, error) {
result := connectResult{}
result.sessionId, result.manualScan = connectISCSIPortal(ctx, tgtPortal, targetIQN, tgtChapInfo)
return result, nil
})

result, ok := res.(connectResult)
if !ok {
return "", false
}
return result.sessionId, result.manualScan
}

func connectISCSIPortal(ctx context.Context,
tgtPortal, targetIQN string,
tgtChapInfo chapInfo) (string, bool) {
Expand Down Expand Up @@ -420,7 +443,7 @@ func connectVol(ctx context.Context,
iSCSIShareData *shareData) {
var device string

session, manualScan := connectISCSIPortal(ctx, tgt.tgtPortal, tgt.tgtIQN, conn.tgtChapInfo)
session, manualScan := singleConnectISCSIPortal(ctx, tgt.tgtPortal, tgt.tgtIQN, conn.tgtChapInfo)
if session != "" {
var numRescans, secondNextScan int
var hostChannelTargetLun []string
Expand Down Expand Up @@ -659,15 +682,15 @@ func addMultiWWN(ctx context.Context, tgtLunWWN string) (bool, error) {
}

func addMultiPath(ctx context.Context, devPath string) error {
output, err := utils.ExecShellCmd(ctx, "multipath add path %s", devPath)
output, err := utils.ExecShellCmd(ctx, "multipathd add path %s", devPath)
if err != nil {
msg := "run cmd multipath add path error"
msg := "run cmd multipathd add path error"
log.AddContext(ctx).Errorln(msg)
return errors.New(msg)
}

if strings.TrimSpace(output) != "ok" {
log.AddContext(ctx).Warningln("run cmd multiPath add path, output is not ok")
log.AddContext(ctx).Warningln("run cmd multipathd add path, output is not ok")
}
return nil
}
Expand Down
3 changes: 3 additions & 0 deletions csi/app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ type Config struct {
ScsiMultiPathType string
NvmeMultiPathType string
AllPathOnline bool

// kubeletVolumeDevicesDirName, default is /volumeDevices/
KubeletVolumeDevicesDirName string
}

// GetGlobalConfig used to get global configuration
Expand Down
6 changes: 6 additions & 0 deletions csi/app/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,9 @@ func (c *Config) WithAllPathOnline(allPathOnline bool) *Config {
func (c *Config) Build() {
globalCfg = c
}

// WithKubeletVolumeDevicesDirName The dir name of volume devices
func (c *Config) WithKubeletVolumeDevicesDirName(KubeletVolumeDevicesDirName string) *Config {
c.KubeletVolumeDevicesDirName = KubeletVolumeDevicesDirName
return c
}
7 changes: 6 additions & 1 deletion csi/backend/plugin/oceanstor.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,16 @@ func (p *OceanstorPlugin) init(config map[string]interface{}, keepLogin bool) er

if p.product == utils.OceanStorDoradoV6 {
clientV6 := clientv6.NewClientV6(urls, user, password, vstoreName, parallelNum)
cli.Logout(context.Background())
if keepLogin {
cli.Logout(context.Background())
}
err := p.switchClient(clientV6)
if err != nil {
return err
}
if !keepLogin {
p.Logout(context.Background())
}
} else {
p.cli = cli
}
Expand Down
46 changes: 28 additions & 18 deletions csi/driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ import (
"encoding/json"
"fmt"
"strings"
"time"

"huawei-csi-driver/connector"
"huawei-csi-driver/csi/app"

// init the nfs connector
_ "huawei-csi-driver/connector/nfs"
"huawei-csi-driver/csi/backend"
Expand Down Expand Up @@ -179,27 +182,34 @@ func (d *Driver) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublish

log.AddContext(ctx).Infof("Start to node unpublish volume %s from %s", volumeId, targetPath)

pathExist, err := utils.PathExist(targetPath)
if !pathExist {
log.AddContext(ctx).Warningf("TargetPath [%v] doesn't exist", targetPath)
return &csi.NodeUnpublishVolumeResponse{}, nil
}

symLink, _ := utils.IsPathSymlink(targetPath)
if symLink {
log.AddContext(ctx).Infof("Removing the symlink [%s]", targetPath)
err = utils.RemoveSymlink(ctx, targetPath)
if !strings.Contains(targetPath, app.GetGlobalConfig().KubeletVolumeDevicesDirName) {
log.AddContext(ctx).Infof("Unmounting the targetPath [%s]", targetPath)
mounted, err := connector.MountPathIsExist(ctx, targetPath)
if err != nil {
log.AddContext(ctx).Errorf("Failed to remove symlink for target path [%v]", targetPath)
return nil, err
log.AddContext(ctx).Errorf("Failed to get mount point [%s], error: %v", targetPath, err)
return nil, status.Error(codes.Internal, err.Error())
}
if mounted {
output, err := utils.ExecShellCmd(ctx, "umount %s", targetPath)
if err != nil && !strings.Contains(output, "not mounted") {
msg := fmt.Sprintf("umount %s for volume %s error: %s", targetPath, volumeId, output)
log.AddContext(ctx).Errorln(msg)
return nil, status.Error(codes.Internal, msg)
}
}
} else {
log.AddContext(ctx).Infof("Unmounting the targetPath [%s]", targetPath)
output, err := utils.ExecShellCmd(ctx, "umount %s", targetPath)
if err != nil && !strings.Contains(output, "not mounted") {
msg := fmt.Sprintf("umount %s for volume %s error: %s", targetPath, volumeId, output)
log.AddContext(ctx).Errorln(msg)
return nil, status.Error(codes.Internal, msg)
symLink, err := utils.IsPathSymlinkWithTimeout(targetPath, 10*time.Second)
if err != nil {
log.AddContext(ctx).Errorf("Failed to Access path %s, error: %v", targetPath, err)
return nil, status.Error(codes.Internal, err.Error())
}
if symLink {
log.AddContext(ctx).Infof("Removing the symlink [%s]", targetPath)
err := utils.RemoveSymlink(ctx, targetPath)
if err != nil {
log.AddContext(ctx).Errorf("Failed to remove symlink for target path [%v]", targetPath)
return nil, err
}
}
}
log.AddContext(ctx).Infof("Volume %s is node unpublished from %s", volumeId, targetPath)
Expand Down
5 changes: 4 additions & 1 deletion csi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const (
nodeLogFile = "huawei-csi-node"
csiLogFile = "huawei-csi"

csiVersion = "3.2.2"
csiVersion = "3.2.3"
defaultDriverName = "csi.huawei.com"
endpointDirPerm = 0755

Expand Down Expand Up @@ -108,6 +108,8 @@ var (
allPathOnline = flag.Bool("all-path-online",
false,
"Whether to check the number of online paths for DM-multipath aggregation, default false")
kubeletVolumeDevicesDirName = flag.String("kubelet-volume-devices-dir-name", "/volumeDevices/",
"The dir name of volume devices")

config CSIConfig
secret CSISecret
Expand Down Expand Up @@ -360,6 +362,7 @@ func doNodeAction() {
notify.Stop("Init Lock error for driver %s: %v", *driverName, err)
}

app.Builder().WithKubeletVolumeDevicesDirName(*kubeletVolumeDevicesDirName).Build()
checkMultiPathType()
checkMultiPathService()
}
Expand Down
1 change: 1 addition & 0 deletions deploy/huawei-csi-node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ spec:
- "--scsi-multipath-type=DM-multipath"
- "--nvme-multipath-type=HW-UltraPath-NVMe"
- "--scan-volume-timeout=3"
- "--kubelet-volume-devices-dir-name=volumeDevices"
env:
- name: CSI_NODENAME
valueFrom:
Expand Down
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 7ec82c5

Please sign in to comment.