From 7915709cafba52cf02a0b67c0c54c4a4b5480ed6 Mon Sep 17 00:00:00 2001 From: geoffrey1330 Date: Thu, 12 Sep 2024 12:57:27 +0100 Subject: [PATCH 1/6] log volumecontext --- pkg/spdk/nodeserver.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/spdk/nodeserver.go b/pkg/spdk/nodeserver.go index 5eee37e..0cb0791 100644 --- a/pkg/spdk/nodeserver.go +++ b/pkg/spdk/nodeserver.go @@ -156,6 +156,8 @@ func (ns *nodeServer) NodeStageVolume(_ context.Context, req *csi.NodeStageVolum var initiator util.SpdkCsiInitiator vc := req.GetVolumeContext() + klog.Infof("VolumeContext for volumeID %s: %+v", volumeID, vc) + // if ns.xpuConnClient != nil && ns.xpuTargetType != "" { // vc["stagingParentPath"] = stagingParentPath // initiator, err = util.NewSpdkCsiXpuInitiator(vc, ns.xpuConnClient, ns.xpuTargetType, ns.kvmPciBridges) From 602bb7a9b8d3fb8e0a2e19d2a5a088674e838aaf Mon Sep 17 00:00:00 2001 From: geoffrey1330 Date: Thu, 12 Sep 2024 13:03:46 +0100 Subject: [PATCH 2/6] log volumecontext --- pkg/spdk/nodeserver.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/spdk/nodeserver.go b/pkg/spdk/nodeserver.go index 0cb0791..b4c240d 100644 --- a/pkg/spdk/nodeserver.go +++ b/pkg/spdk/nodeserver.go @@ -157,7 +157,6 @@ func (ns *nodeServer) NodeStageVolume(_ context.Context, req *csi.NodeStageVolum vc := req.GetVolumeContext() klog.Infof("VolumeContext for volumeID %s: %+v", volumeID, vc) - // if ns.xpuConnClient != nil && ns.xpuTargetType != "" { // vc["stagingParentPath"] = stagingParentPath // initiator, err = util.NewSpdkCsiXpuInitiator(vc, ns.xpuConnClient, ns.xpuTargetType, ns.kvmPciBridges) From a7422dce343c06803043f01b875bf63f00d8ff7b Mon Sep 17 00:00:00 2001 From: geoffrey1330 Date: Thu, 12 Sep 2024 13:52:39 +0100 Subject: [PATCH 3/6] add logic to format xfs with additional parameters --- charts/latest/spdk-csi/values.yaml | 2 +- pkg/spdk/nodeserver.go | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/charts/latest/spdk-csi/values.yaml b/charts/latest/spdk-csi/values.yaml index abdb337..92b834c 100644 --- a/charts/latest/spdk-csi/values.yaml +++ b/charts/latest/spdk-csi/values.yaml @@ -7,7 +7,7 @@ driverName: csi.simplyblock.io image: spdkcsi: repository: simplyblock/spdkcsi - tag: latest + tag: pr-72 pullPolicy: Always csiProvisioner: repository: registry.k8s.io/sig-storage/csi-provisioner diff --git a/pkg/spdk/nodeserver.go b/pkg/spdk/nodeserver.go index b4c240d..02c9b76 100644 --- a/pkg/spdk/nodeserver.go +++ b/pkg/spdk/nodeserver.go @@ -21,6 +21,8 @@ import ( "errors" "fmt" "os" + osExec "os/exec" + "strconv" "time" "github.com/container-storage-interface/spec/lib/go/csi" @@ -181,7 +183,7 @@ func (ns *nodeServer) NodeStageVolume(_ context.Context, req *csi.NodeStageVolum initiator.Disconnect() //nolint:errcheck // ignore error } }() - if err = ns.stageVolume(devicePath, stagingTargetPath, req); err != nil { // idempotent + if err = ns.stageVolume(devicePath, stagingTargetPath, req, vc); err != nil { // idempotent klog.Errorf("failed to stage volume, volumeID: %s devicePath:%s err: %v", volumeID, devicePath, err) return nil, status.Error(codes.Internal, err.Error()) } @@ -303,7 +305,7 @@ func (ns *nodeServer) NodeExpandVolume(_ context.Context, req *csi.NodeExpandVol // must be idempotent // //nolint:cyclop // many cases in switch increases complexity -func (ns *nodeServer) stageVolume(devicePath, stagingPath string, req *csi.NodeStageVolumeRequest) error { +func (ns *nodeServer) stageVolume(devicePath, stagingPath string, req *csi.NodeStageVolumeRequest, volumeContext map[string]string) error { mounted, err := ns.createMountPoint(stagingPath) if err != nil { return err @@ -316,6 +318,18 @@ func (ns *nodeServer) stageVolume(devicePath, stagingPath string, req *csi.NodeS // if fsType is not specified, use ext4 as default if fsType == "" { fsType = "ext4" + } else if fsType == "xfs" { + distrNdcs, err := strconv.Atoi(volumeContext["distr_ndcs"]) + if err != nil { + return err + } + cmd := fmt.Sprintf("mkfs.xfs -d sunit=%d swidth=%d -l sunit=%d %s", 8*distrNdcs, 8*distrNdcs, 8*distrNdcs, devicePath) + klog.Infof("Executing command: %s", cmd) + err = osExec.Command("sh", "-c", cmd).Run() + if err != nil { + klog.Errorf("Error executing command: %v", err) + return err + } } mntFlags := req.GetVolumeCapability().GetMount().GetMountFlags() From cf47ecc2c6c99e48f25f0b85da8177457671e32f Mon Sep 17 00:00:00 2001 From: geoffrey1330 Date: Thu, 12 Sep 2024 13:58:11 +0100 Subject: [PATCH 4/6] fixed codeQL error --- pkg/spdk/nodeserver.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/spdk/nodeserver.go b/pkg/spdk/nodeserver.go index 02c9b76..70bfbed 100644 --- a/pkg/spdk/nodeserver.go +++ b/pkg/spdk/nodeserver.go @@ -319,16 +319,16 @@ func (ns *nodeServer) stageVolume(devicePath, stagingPath string, req *csi.NodeS if fsType == "" { fsType = "ext4" } else if fsType == "xfs" { - distrNdcs, err := strconv.Atoi(volumeContext["distr_ndcs"]) - if err != nil { - return err + distrNdcs, errNdcs := strconv.Atoi(volumeContext["distr_ndcs"]) + if errNdcs != nil { + return errNdcs } cmd := fmt.Sprintf("mkfs.xfs -d sunit=%d swidth=%d -l sunit=%d %s", 8*distrNdcs, 8*distrNdcs, 8*distrNdcs, devicePath) klog.Infof("Executing command: %s", cmd) - err = osExec.Command("sh", "-c", cmd).Run() - if err != nil { - klog.Errorf("Error executing command: %v", err) - return err + errNdcs = osExec.Command("sh", "-c", cmd).Run() + if errNdcs != nil { + klog.Errorf("Error executing command: %v", errNdcs) + return errNdcs } } mntFlags := req.GetVolumeCapability().GetMount().GetMountFlags() From b57f438a5eab1d92918b6c56317639f19f47792c Mon Sep 17 00:00:00 2001 From: geoffrey1330 Date: Thu, 12 Sep 2024 16:17:45 +0100 Subject: [PATCH 5/6] fixed mkfs.xfs param --- charts/latest/spdk-csi/templates/storageclass.yaml | 4 ++-- pkg/spdk/nodeserver.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/charts/latest/spdk-csi/templates/storageclass.yaml b/charts/latest/spdk-csi/templates/storageclass.yaml index 38f382a..6caedd4 100644 --- a/charts/latest/spdk-csi/templates/storageclass.yaml +++ b/charts/latest/spdk-csi/templates/storageclass.yaml @@ -10,7 +10,7 @@ metadata: name: spdkcsi-sc provisioner: csi.simplyblock.io parameters: - csi.storage.k8s.io/fstype: ext4 + csi.storage.k8s.io/fstype: xfs pool_name: {{ .Values.logicalVolume.pool_name }} qos_rw_iops: "{{ .Values.logicalVolume.qos_rw_iops }}" qos_rw_mbytes: "{{ .Values.logicalVolume.qos_rw_mbytes }}" @@ -31,7 +31,7 @@ metadata: name: spdkcsi-sc-cache provisioner: csi.simplyblock.io parameters: - csi.storage.k8s.io/fstype: ext4 + csi.storage.k8s.io/fstype: xfs type: cache pool_name: "{{ .Values.logicalVolume.pool_name }}" qos_rw_iops: "{{ .Values.logicalVolume.qos_rw_iops }}" diff --git a/pkg/spdk/nodeserver.go b/pkg/spdk/nodeserver.go index 70bfbed..4b1e190 100644 --- a/pkg/spdk/nodeserver.go +++ b/pkg/spdk/nodeserver.go @@ -323,7 +323,7 @@ func (ns *nodeServer) stageVolume(devicePath, stagingPath string, req *csi.NodeS if errNdcs != nil { return errNdcs } - cmd := fmt.Sprintf("mkfs.xfs -d sunit=%d swidth=%d -l sunit=%d %s", 8*distrNdcs, 8*distrNdcs, 8*distrNdcs, devicePath) + cmd := fmt.Sprintf("mkfs.xfs -f -d sunit=%d,swidth=%d -l sunit=%d %s", 8*distrNdcs, 8*distrNdcs, 8*distrNdcs, devicePath) klog.Infof("Executing command: %s", cmd) errNdcs = osExec.Command("sh", "-c", cmd).Run() if errNdcs != nil { From bb0c84582e3b15a554d2562e34d98f0dd6efd422 Mon Sep 17 00:00:00 2001 From: geoffrey1330 Date: Thu, 12 Sep 2024 23:42:56 +0100 Subject: [PATCH 6/6] cleanup pr --- charts/latest/spdk-csi/templates/storageclass.yaml | 4 ++-- charts/latest/spdk-csi/values.yaml | 2 +- pkg/spdk/nodeserver.go | 1 - 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/charts/latest/spdk-csi/templates/storageclass.yaml b/charts/latest/spdk-csi/templates/storageclass.yaml index 6caedd4..38f382a 100644 --- a/charts/latest/spdk-csi/templates/storageclass.yaml +++ b/charts/latest/spdk-csi/templates/storageclass.yaml @@ -10,7 +10,7 @@ metadata: name: spdkcsi-sc provisioner: csi.simplyblock.io parameters: - csi.storage.k8s.io/fstype: xfs + csi.storage.k8s.io/fstype: ext4 pool_name: {{ .Values.logicalVolume.pool_name }} qos_rw_iops: "{{ .Values.logicalVolume.qos_rw_iops }}" qos_rw_mbytes: "{{ .Values.logicalVolume.qos_rw_mbytes }}" @@ -31,7 +31,7 @@ metadata: name: spdkcsi-sc-cache provisioner: csi.simplyblock.io parameters: - csi.storage.k8s.io/fstype: xfs + csi.storage.k8s.io/fstype: ext4 type: cache pool_name: "{{ .Values.logicalVolume.pool_name }}" qos_rw_iops: "{{ .Values.logicalVolume.qos_rw_iops }}" diff --git a/charts/latest/spdk-csi/values.yaml b/charts/latest/spdk-csi/values.yaml index 92b834c..abdb337 100644 --- a/charts/latest/spdk-csi/values.yaml +++ b/charts/latest/spdk-csi/values.yaml @@ -7,7 +7,7 @@ driverName: csi.simplyblock.io image: spdkcsi: repository: simplyblock/spdkcsi - tag: pr-72 + tag: latest pullPolicy: Always csiProvisioner: repository: registry.k8s.io/sig-storage/csi-provisioner diff --git a/pkg/spdk/nodeserver.go b/pkg/spdk/nodeserver.go index 4b1e190..93e037d 100644 --- a/pkg/spdk/nodeserver.go +++ b/pkg/spdk/nodeserver.go @@ -158,7 +158,6 @@ func (ns *nodeServer) NodeStageVolume(_ context.Context, req *csi.NodeStageVolum var initiator util.SpdkCsiInitiator vc := req.GetVolumeContext() - klog.Infof("VolumeContext for volumeID %s: %+v", volumeID, vc) // if ns.xpuConnClient != nil && ns.xpuTargetType != "" { // vc["stagingParentPath"] = stagingParentPath // initiator, err = util.NewSpdkCsiXpuInitiator(vc, ns.xpuConnClient, ns.xpuTargetType, ns.kvmPciBridges)