Skip to content

Commit

Permalink
fix: Fix previously unmapped device discovery fix for new nodePublish…
Browse files Browse the repository at this point in the history
… code

restore and update previously unmapped device discovery check
  • Loading branch information
David-T-White committed Oct 6, 2023
1 parent 6ca0e8b commit 232d6ae
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 23 deletions.
4 changes: 2 additions & 2 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func (controller *Controller) GetNodeInitiators(ctx context.Context, nodeAddress
return initiators, err
}

func (controller *Controller) NotifyUnmap(ctx context.Context, nodeAddress string, volumeName string) error {
func (controller *Controller) NotifyUnmap(ctx context.Context, nodeAddress string, volumeWWN string) error {
clientConnection := controller.nodeServiceClients[nodeAddress]
if clientConnection == nil {
klog.V(3).InfoS("node grpc client not found, establishing...", "nodeAddress", nodeAddress)
Expand All @@ -350,7 +350,7 @@ func (controller *Controller) NotifyUnmap(ctx context.Context, nodeAddress strin
}
controller.nodeServiceClients[nodeAddress] = clientConnection
}
return node_service.NotifyUnmap(ctx, clientConnection, volumeName)
return node_service.NotifyUnmap(ctx, clientConnection, volumeWWN)
}

// Graceful shutdown of Node-Controller RPC Clients
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func (driver *Controller) ControllerUnpublishVolume(ctx context.Context, req *cs
}

volumeName, _ := common.VolumeIdGetName(req.GetVolumeId())
volumeWWN, _ := common.VolumeIdGetWwn(req.GetVolumeId())
nodeIP := req.GetNodeId()
storageProtocol, err := common.VolumeIdGetStorageProtocol(req.GetVolumeId())
if err != nil {
Expand All @@ -78,7 +79,7 @@ func (driver *Controller) ControllerUnpublishVolume(ctx context.Context, req *cs
klog.Errorf("unknown error while unmapping initiator %s: %v", initiator, err)
}
} else {
driver.NotifyUnmap(ctx, nodeIP, volumeName)
driver.NotifyUnmap(ctx, nodeIP, volumeWWN)
}
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/node_service/node_service_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ func GetNodeInitiators(ctx context.Context, conn *grpc.ClientConn, reqType pb.In
return initiators.Initiators, nil
}

func NotifyUnmap(ctx context.Context, conn *grpc.ClientConn, volumeName string) (err error) {
func NotifyUnmap(ctx context.Context, conn *grpc.ClientConn, volumeWWN string) (err error) {
client := pb.NewNodeServiceClient(conn)
unmappedVolumePb := pb.UnmappedVolume{VolumeName: volumeName}
unmappedVolumePb := pb.UnmappedVolume{VolumeName: volumeWWN}
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
_, err = client.NotifyUnmap(ctx, &unmappedVolumePb)
if err != nil {
klog.ErrorS(err, "Error during unmap notification", "unmappedVolumeName", volumeName)
klog.ErrorS(err, "Error during unmap notification", "unmappedVolumeName", volumeWWN)
}
return
}
5 changes: 3 additions & 2 deletions pkg/node_service/node_service_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ func (s *server) GetInitiators(ctx context.Context, in *pb.InitiatorRequest) (*p

// Notify node that a volume has been unmapped from the controller
func (s *server) NotifyUnmap(ctx context.Context, in *pb.UnmappedVolume) (*pb.Ack, error) {
delete(storage.GlobalRemovedDevicesMap, in.GetVolumeName())
klog.V(5).InfoS("Global unmapped device map deletion", "globalMap", storage.GlobalRemovedDevicesMap, "volumeName", in.GetVolumeName())
storage.CheckPreviouslyRemovedDevices(ctx)
delete(storage.SASandFCRemovedDevicesMap, in.GetVolumeName())
klog.V(4).InfoS("Previously unmapped device - ControllerUnpublishComplete Notification", "deviceMap", storage.SASandFCRemovedDevicesMap, "volumeName", in.GetVolumeName())
return &pb.Ack{Ack: 1}, nil
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/storage/fcNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"os/exec"
"path/filepath"
"strings"
"time"

fclib "github.com/Seagate/csi-lib-sas/sas"
"github.com/Seagate/seagate-exos-x-csi/pkg/common"
Expand All @@ -53,6 +54,7 @@ func (fc *fcStorage) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstage
}

func (fc *fcStorage) AttachStorage(ctx context.Context, req *csi.NodePublishVolumeRequest) (string, error) {
CheckPreviouslyRemovedDevices(ctx)
klog.InfoS("initiating FC connection...")
wwn, _ := common.VolumeIdGetWwn(req.GetVolumeId())
connector := &fclib.Connector{VolumeWWN: wwn}
Expand Down Expand Up @@ -122,6 +124,7 @@ func (fc *fcStorage) DetachStorage(ctx context.Context, req *csi.NodeUnpublishVo

klog.InfoS("deleting FC connection info file", "fc.connectorInfoPath", fc.connectorInfoPath)
os.Remove(fc.connectorInfoPath)
SASandFCRemovedDevicesMap[connector.VolumeWWN] = time.Now()
return nil
}

Expand Down
19 changes: 5 additions & 14 deletions pkg/storage/sasNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"path/filepath"
"strconv"
"strings"
"time"

saslib "github.com/Seagate/csi-lib-sas/sas"
"github.com/Seagate/seagate-exos-x-csi/pkg/common"
Expand Down Expand Up @@ -121,6 +122,8 @@ func GetSASInitiators() ([]string, error) {
}

func (sas *sasStorage) AttachStorage(ctx context.Context, req *csi.NodePublishVolumeRequest) (string, error) {
CheckPreviouslyRemovedDevices(ctx)

klog.InfoS("initiating SAS connection...")
wwn, _ := common.VolumeIdGetWwn(req.GetVolumeId())
connector := saslib.Connector{VolumeWWN: wwn}
Expand Down Expand Up @@ -183,11 +186,13 @@ func (sas *sasStorage) DetachStorage(ctx context.Context, req *csi.NodeUnpublish
klog.Info("DisconnectVolume, detaching SAS device")
err = saslib.Detach(ctx, connector.OSPathName, connector.IoHandler)
if err != nil {
klog.ErrorS(err, "error detaching FC connection")
return err
}

klog.InfoS("deleting SAS connection info file", "sas.connectorInfoPath", sas.connectorInfoPath)
os.Remove(sas.connectorInfoPath)
SASandFCRemovedDevicesMap[connector.VolumeWWN] = time.Now()
return nil
}

Expand All @@ -200,20 +205,6 @@ func (sas *sasStorage) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnp
return nil, status.Error(codes.Unimplemented, "SAS specific NodeUnpublishVolume not implemented")
}

func checkPreviouslyRemovedDevices(ctx context.Context) error {
klog.Info("Checking previously removed devices")
for wwn := range GlobalRemovedDevicesMap {
klog.Infof("Checking for rediscovery of wwn:%s", wwn)

dm, devices := saslib.FindDiskById(klog.FromContext(ctx), wwn, &saslib.OSioHandler{})
if dm != "" {
klog.Infof("Rediscovery found for wwn:%s -- mpath device: %s, devices: %v", wwn, dm, devices)
saslib.Detach(ctx, dm, &saslib.OSioHandler{})
}
}
return nil
}

// NodeGetVolumeStats return info about a given volume
// Will not be called as the plugin does not have the GET_VOLUME_STATS capability
func (sas *sasStorage) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGetVolumeStatsRequest) (*csi.NodeGetVolumeStatsResponse, error) {
Expand Down
19 changes: 18 additions & 1 deletion pkg/storage/storageService.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"strings"
"time"

saslib "github.com/Seagate/csi-lib-sas/sas"
"github.com/Seagate/seagate-exos-x-csi/pkg/common"
"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/pkg/errors"
Expand Down Expand Up @@ -67,7 +68,7 @@ type sasStorage struct {
}

// Map of device WWNs to timestamp of when they were unpublished from the node
var GlobalRemovedDevicesMap = map[string]time.Time{}
var SASandFCRemovedDevicesMap = map[string]time.Time{}

// buildCommonService:
func buildCommonService(config map[string]string) (commonService, error) {
Expand Down Expand Up @@ -152,6 +153,22 @@ func CheckFs(path string, fstype string, context string) error {
return nil
}

// Check for and remove any rediscovered iscsi devices that were previously unmapped
// This is a common function for SAS and FC
func CheckPreviouslyRemovedDevices(ctx context.Context) error {
klog.Info("Checking previously removed devices")
for wwn := range SASandFCRemovedDevicesMap {
klog.Infof("Checking for rediscovery of wwn:%s", wwn)

dm, devices := saslib.FindDiskById(klog.FromContext(ctx), wwn, &saslib.OSioHandler{})
if dm != "" {
klog.Infof("Rediscovery found for wwn:%s -- mpath device: %s, devices: %v", wwn, dm, devices)
saslib.Detach(ctx, dm, &saslib.OSioHandler{})
}
}
return nil
}

// FindDeviceFormat:
func FindDeviceFormat(device string) (string, error) {
klog.V(2).Infof("Trying to find filesystem format on device %q", device)
Expand Down

0 comments on commit 232d6ae

Please sign in to comment.