Skip to content

Commit

Permalink
deprecated k8s.io/utils/mount
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffrey1330 committed Oct 17, 2024
1 parent 143da1c commit dd40536
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
12 changes: 5 additions & 7 deletions pkg/spdk/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@ import (

csicommon "github.com/spdk/spdk-csi/pkg/csi-common"
"github.com/spdk/spdk-csi/pkg/util"
mountutils "k8s.io/mount-utils"
)

func Run(conf *util.Config) {
var (
cd *csicommon.CSIDriver
ids *identityServer
cs *controllerServer
ns *nodeServer
mounter mountutils.Interface
cd *csicommon.CSIDriver
ids *identityServer
cs *controllerServer
ns *nodeServer

controllerCaps = []csi.ControllerServiceCapability_RPC_Type{
csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME,
Expand Down Expand Up @@ -61,7 +59,7 @@ func Run(conf *util.Config) {

if conf.IsNodeServer {
var err error
ns, err = newNodeServer(cd, mounter)
ns, err = newNodeServer(cd)
if err != nil {
klog.Fatalf("failed to create node server: %s", err)
}
Expand Down
31 changes: 15 additions & 16 deletions pkg/spdk/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,28 @@ import (
"google.golang.org/grpc/status"
"k8s.io/klog"
"k8s.io/utils/exec"
"k8s.io/utils/mount"

// "k8s.io/utils/mount"

csicommon "github.com/spdk/spdk-csi/pkg/csi-common"
"github.com/spdk/spdk-csi/pkg/util"
mountutils "k8s.io/mount-utils"
mount "k8s.io/mount-utils"
)

type nodeServer struct {
*csicommon.DefaultNodeServer
mounter mount.Interface
mounter2 mountutils.Interface
volumeLocks *util.VolumeLocks
xpuConnClient *grpc.ClientConn
xpuTargetType string
kvmPciBridges int
spdkNode *util.NodeNVMf
}

func newNodeServer(d *csicommon.CSIDriver, mounter2 mountutils.Interface) (*nodeServer, error) {
func newNodeServer(d *csicommon.CSIDriver) (*nodeServer, error) {
ns := &nodeServer{
DefaultNodeServer: csicommon.NewDefaultNodeServer(d),
mounter: mount.New(""),
mounter2: mounter2,
volumeLocks: util.NewVolumeLocks(),
}

Expand Down Expand Up @@ -353,9 +352,9 @@ func (ns *nodeServer) stageVolume(devicePath, stagingPath string, req *csi.NodeS

klog.Infof("mount %s to %s, fstype: %s, flags: %v", devicePath, stagingPath, fsType, mntFlags)
klog.Infof("formatOptions %v", formatOptions)
mounter2 := mountutils.SafeFormatAndMount{Interface: ns.mounter2, Exec: exec.New()}
mounter := mount.SafeFormatAndMount{Interface: ns.mounter, Exec: exec.New()}
//err = mounter.FormatAndMount(devicePath, stagingPath, fsType, mntFlags)
err = mounter2.FormatAndMountSensitiveWithFormatOptions(devicePath, stagingPath, fsType, mntFlags, nil, formatOptions)
err = mounter.FormatAndMountSensitiveWithFormatOptions(devicePath, stagingPath, fsType, mntFlags, nil, formatOptions)

if err != nil {
return err
Expand All @@ -365,15 +364,15 @@ func (ns *nodeServer) stageVolume(devicePath, stagingPath string, req *csi.NodeS

// isStaged if stagingPath is a mount point, it means it is already staged, and vice versa
func (ns *nodeServer) isStaged(stagingPath string) (bool, error) {
unmounted, err := mount.IsNotMountPoint(ns.mounter, stagingPath)
isMount, err := ns.mounter.IsMountPoint(stagingPath)
if err != nil {
if os.IsNotExist(err) {
return false, nil
}
klog.Warningf("check is stage error: %v", err)
return true, err
return false, err
}
return !unmounted, nil
return isMount, nil
}

// must be idempotent
Expand All @@ -396,28 +395,28 @@ func (ns *nodeServer) publishVolume(stagingPath string, req *csi.NodePublishVolu

// create mount point if not exists, return whether already mounted
func (ns *nodeServer) createMountPoint(path string) (bool, error) {
unmounted, err := mount.IsNotMountPoint(ns.mounter, path)
isMount, err := ns.mounter.IsMountPoint(path)
if os.IsNotExist(err) {
unmounted = true
isMount = false
err = os.MkdirAll(path, 0o755)
}
if !unmounted {
if isMount {
klog.Infof("%s already mounted", path)
}
return !unmounted, err
return isMount, err
}

// unmount and delete mount point, must be idempotent
func (ns *nodeServer) deleteMountPoint(path string) error {
unmounted, err := mount.IsNotMountPoint(ns.mounter, path)
isMount, err := ns.mounter.IsMountPoint(path)
if os.IsNotExist(err) {
klog.Infof("%s already deleted", path)
return nil
}
if err != nil {
return err
}
if !unmounted {
if isMount {
err = ns.mounter.Unmount(path)
if err != nil {
return err
Expand Down

0 comments on commit dd40536

Please sign in to comment.