mirror of
https://github.com/kubernetes-csi/csi-driver-nvmf.git
synced 2025-06-24 21:41:34 +00:00
refactor: refactor nvmfDiskInfo and mounter/unmounter creation
- Refactor function arguments to allow reuse across multiple components - Remove unused variables and parameters for cleaner implementation Signed-off-by: cheolho.kang <cheolho.kang@samsung.com>
This commit is contained in:
parent
e6be700ac2
commit
8a4641f6e1
@ -74,11 +74,15 @@ func (n *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublish
|
||||
}
|
||||
|
||||
// 2. attachdisk
|
||||
nvmfInfo, err := getNVMfDiskInfo(req)
|
||||
// Create mounter for the volume to be published
|
||||
parameter := req.GetVolumeContext()
|
||||
volumeID := req.GetVolumeId()
|
||||
targetPath := req.GetTargetPath()
|
||||
nvmfInfo, err := getNVMfDiskInfo(volumeID, parameter)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "NodePublishVolume: get NVMf disk info from req err: %v", err)
|
||||
}
|
||||
diskMounter := getNVMfDiskMounter(nvmfInfo, req)
|
||||
diskMounter := getNVMfDiskMounter(nvmfInfo, targetPath, req.GetVolumeCapability())
|
||||
|
||||
// attachDisk realize connect NVMf disk and mount to docker path
|
||||
_, err = AttachDisk(req, *diskMounter)
|
||||
@ -100,7 +104,8 @@ func (n *NodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpub
|
||||
return nil, status.Error(codes.InvalidArgument, "NodeUnpublishVolume Staging TargetPath must be provided")
|
||||
}
|
||||
targetPath := req.GetTargetPath()
|
||||
err := DetachDisk(req.VolumeId, getNVMfDiskUnMounter(req), targetPath)
|
||||
unmounter := getNVMfDiskUnMounter()
|
||||
err := DetachDisk(req.VolumeId, unmounter, targetPath)
|
||||
if err != nil {
|
||||
klog.Errorf("NodeUnpublishVolume: VolumeID: %s detachDisk err: %v", req.VolumeId, err)
|
||||
return nil, err
|
||||
|
@ -44,7 +44,7 @@ type nvmfDiskInfo struct {
|
||||
|
||||
type nvmfDiskMounter struct {
|
||||
*nvmfDiskInfo
|
||||
readOnly bool
|
||||
isBlock bool
|
||||
fsType string
|
||||
mountOptions []string
|
||||
mounter *mount.SafeFormatAndMount
|
||||
@ -58,22 +58,24 @@ type nvmfDiskUnMounter struct {
|
||||
exec exec.Interface
|
||||
}
|
||||
|
||||
func getNVMfDiskInfo(req *csi.NodePublishVolumeRequest) (*nvmfDiskInfo, error) {
|
||||
volName := req.GetVolumeId()
|
||||
// getNVMfDiskInfo extracts NVMf disk information from the provided parameters
|
||||
func getNVMfDiskInfo(volID string, params map[string]string) (*nvmfDiskInfo, error) {
|
||||
if params == nil {
|
||||
return nil, fmt.Errorf("discovery parameters are nil")
|
||||
}
|
||||
|
||||
volOpts := req.GetVolumeContext()
|
||||
targetTrAddr := volOpts[paramAddr]
|
||||
targetTrPort := volOpts[paramPort]
|
||||
targetTrType := volOpts[paramType]
|
||||
deviceUUID := volOpts["deviceUUID"]
|
||||
nqn := volOpts["nqn"]
|
||||
targetTrAddr := params[paramAddr]
|
||||
targetTrPort := params[paramPort]
|
||||
targetTrType := params[paramType]
|
||||
deviceUUID := params["deviceUUID"]
|
||||
nqn := volID
|
||||
|
||||
if targetTrAddr == "" || nqn == "" || targetTrPort == "" || targetTrType == "" || deviceUUID == "" {
|
||||
return nil, fmt.Errorf("some nvme target info is missing, volID: %s ", volName)
|
||||
return nil, fmt.Errorf("some nvme target info is missing, volID: %s ", volID)
|
||||
}
|
||||
|
||||
return &nvmfDiskInfo{
|
||||
VolName: volName,
|
||||
VolName: volID,
|
||||
Addr: targetTrAddr,
|
||||
Port: targetTrPort,
|
||||
Nqn: nqn,
|
||||
@ -82,24 +84,22 @@ func getNVMfDiskInfo(req *csi.NodePublishVolumeRequest) (*nvmfDiskInfo, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func getNVMfDiskMounter(nvmfInfo *nvmfDiskInfo, req *csi.NodePublishVolumeRequest) *nvmfDiskMounter {
|
||||
readOnly := req.GetReadonly()
|
||||
fsType := req.GetVolumeCapability().GetMount().GetFsType()
|
||||
mountOptions := req.GetVolumeCapability().GetMount().GetMountFlags()
|
||||
|
||||
// getNVMfDiskMounter creates and configures a new disk mounter
|
||||
func getNVMfDiskMounter(nvmfInfo *nvmfDiskInfo, targetPath string, cap *csi.VolumeCapability) *nvmfDiskMounter {
|
||||
return &nvmfDiskMounter{
|
||||
nvmfDiskInfo: nvmfInfo,
|
||||
readOnly: readOnly,
|
||||
fsType: fsType,
|
||||
mountOptions: mountOptions,
|
||||
isBlock: cap.GetBlock() != nil,
|
||||
fsType: cap.GetMount().GetFsType(),
|
||||
mountOptions: cap.GetMount().GetMountFlags(),
|
||||
mounter: &mount.SafeFormatAndMount{Interface: mount.New(""), Exec: exec.New()},
|
||||
exec: exec.New(),
|
||||
targetPath: req.GetTargetPath(),
|
||||
connector: getNvmfConnector(nvmfInfo, req.GetTargetPath()),
|
||||
targetPath: targetPath,
|
||||
connector: getNvmfConnector(nvmfInfo, targetPath),
|
||||
}
|
||||
}
|
||||
|
||||
func getNVMfDiskUnMounter(req *csi.NodeUnpublishVolumeRequest) *nvmfDiskUnMounter {
|
||||
// getNVMfDiskUnMounter creates a new disk unmounter
|
||||
func getNVMfDiskUnMounter() *nvmfDiskUnMounter {
|
||||
return &nvmfDiskUnMounter{
|
||||
mounter: mount.New(""),
|
||||
exec: exec.New(),
|
||||
|
Loading…
Reference in New Issue
Block a user