Skip to content

Commit

Permalink
add xfs option support (#72)
Browse files Browse the repository at this point in the history
* log volumecontext

* log volumecontext

* add logic to format xfs with additional parameters

* fixed codeQL error

* fixed mkfs.xfs param

* cleanup pr
  • Loading branch information
geoffrey1330 authored Sep 13, 2024
1 parent bc3ede1 commit ddf7eac
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions pkg/spdk/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"errors"
"fmt"
"os"
osExec "os/exec"
"strconv"
"time"

"github.com/container-storage-interface/spec/lib/go/csi"
Expand Down Expand Up @@ -180,7 +182,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())
}
Expand Down Expand Up @@ -302,7 +304,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
Expand All @@ -315,6 +317,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, errNdcs := strconv.Atoi(volumeContext["distr_ndcs"])
if errNdcs != nil {
return errNdcs
}
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 {
klog.Errorf("Error executing command: %v", errNdcs)
return errNdcs
}
}
mntFlags := req.GetVolumeCapability().GetMount().GetMountFlags()

Expand Down

0 comments on commit ddf7eac

Please sign in to comment.