Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/Scalingo/go-etcd-lock/v5 v5.0.8
github.com/container-storage-interface/spec v1.7.0
github.com/golang/protobuf v1.5.4
github.com/hpe-storage/common-host-libs v0.0.0-20250814050617-b92e778a7508
github.com/hpe-storage/common-host-libs v0.0.0-20251030032113-e9caff71ad6b
github.com/hpe-storage/k8s-custom-resources v0.0.0-20240118202512-5f62990a7c2d
github.com/kubernetes-csi/csi-lib-utils v0.11.0
github.com/kubernetes-csi/csi-test v2.2.0+incompatible
Expand All @@ -17,6 +17,7 @@ require (
github.com/stretchr/testify v1.10.0
golang.org/x/mod v0.24.0
golang.org/x/net v0.38.0
golang.org/x/sys v0.33.0
google.golang.org/grpc v1.71.1
k8s.io/api v0.29.0
k8s.io/apimachinery v0.29.0
Expand Down Expand Up @@ -78,7 +79,6 @@ require (
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.38.0 // indirect
golang.org/x/oauth2 v0.25.0 // indirect
golang.org/x/sys v0.33.0 // indirect
golang.org/x/term v0.32.0 // indirect
golang.org/x/text v0.25.0 // indirect
golang.org/x/time v0.5.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFb
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/hpe-storage/common-host-libs v0.0.0-20250814050617-b92e778a7508 h1:urKXbbZW3Snld+VZqLgmnxjFH9cdiQAZPzpWz+sfMtw=
github.com/hpe-storage/common-host-libs v0.0.0-20250814050617-b92e778a7508/go.mod h1:LtFiruLqjTXLJ5TfFAYDEgSja5oW0rey5D1fSBTe2OY=
github.com/hpe-storage/common-host-libs v0.0.0-20251030032113-e9caff71ad6b h1:pfoON+u3bzyvxgVb43cTk2PvP6QXc7BZUw/cXh+pGiA=
github.com/hpe-storage/common-host-libs v0.0.0-20251030032113-e9caff71ad6b/go.mod h1:LtFiruLqjTXLJ5TfFAYDEgSja5oW0rey5D1fSBTe2OY=
github.com/hpe-storage/k8s-custom-resources v0.0.0-20240118202512-5f62990a7c2d h1:ui+o/+dBn3pwOBHL3AB14XsYaeogpPJZF0Dk3vJh7zY=
github.com/hpe-storage/k8s-custom-resources v0.0.0-20240118202512-5f62990a7c2d/go.mod h1:+zrGrGKf/jqr38KxLEGRll+UsjeUybdLH0MZCBxPPoI=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
Expand Down
59 changes: 39 additions & 20 deletions pkg/driver/node_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

"github.com/container-storage-interface/spec/lib/go/csi"
"golang.org/x/net/context"
"golang.org/x/sys/unix"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -1029,31 +1030,49 @@ func (driver *Driver) nodePublishVolume(

// If Block, then stage the volume for raw block device access
if volAccessType.String() == model.BlockType.String() {
log.Tracef("Publishing the volume for raw block access (create symlink), devicePath: %s, targetPath: %v",
log.Tracef("Publishing the volume for raw block access (create block device), devicePath: %s, targetPath: %v",
stagingDev.Device.AltFullPathName, targetPath)

// Check if target path symlink to the device already exists
exists, symlink, _ := util.IsFileSymlink(targetPath)
if symlink {
errMsg := fmt.Sprintf("Target path %s already published as symlink to the device %s", targetPath, stagingDev.Device.AltFullPathName)
// Check if target path block device to the mpath device already exists
exists, blockDevice, _ := util.IsFileBlockDevice(targetPath)
if blockDevice {
errMsg := fmt.Sprintf("Target path %s already published as block device to the mpath device %s", targetPath, stagingDev.Device.AltFullPathName)
log.Error("Error: ", errMsg)
return status.Error(codes.Internal, errMsg)
}
if exists {
// Remove the target path before creating the symlink
log.Tracef("Removing the target path %s before creating symlink to the device", targetPath)
log.Tracef("Removing the target block device %s before creating block device to the mpath device", targetPath)
if err := util.FileDelete(targetPath); err != nil {
return status.Error(codes.Internal,
fmt.Sprintf("Error removing the target path %s before creating symlink to the device, err: %s",
fmt.Sprintf("Error removing the target block device %s before creating block device to the mpath device, err: %s",
targetPath, err.Error()))
}
}

// Note: Bind-mount is not allowed for raw block device as there is no filesystem on it.
// So, we create softlink to the device file. TODO: mknode() instead ???
// Ex: ln -s /dev/mpathbm <targetPath>
if err := os.Symlink(stagingDev.Device.AltFullPathName, targetPath); err != nil {
errMsg := fmt.Sprintf("Failed to create symlink %s to the device path %s, err: %v",
rawDeviceMinor, err := strconv.Atoi(stagingDev.Device.Minor)
if err != nil {
errMsg := fmt.Sprintf("Failed to retrieve device minor to create %s from the mpath device path %s, err: %v",
targetPath, stagingDev.Device.AltFullPathName, err.Error())
log.Error("Error: ", errMsg)
return status.Error(codes.Internal, errMsg)
}

rawDeviceMajor, err := strconv.Atoi(stagingDev.Device.Major)
if err != nil {
errMsg := fmt.Sprintf("Failed to retrieve device major to create %s from the mpath device path %s, err: %v",
targetPath, stagingDev.Device.AltFullPathName, err.Error())
log.Error("Error: ", errMsg)
return status.Error(codes.Internal, errMsg)
}

rawDeviceMode := uint32(unix.S_IFBLK | 0660)
rawDeviceMM := int(unix.Mkdev(uint32(rawDeviceMajor), uint32(rawDeviceMinor)))

// Create block device
if err := unix.Mknod(targetPath, rawDeviceMode, rawDeviceMM); err != nil {
errMsg := fmt.Sprintf("Failed to create block device %s to the mpath device path %s, err: %v",
targetPath, stagingDev.Device.AltFullPathName, err.Error())
log.Error("Error: ", errMsg)
return status.Error(codes.Internal, errMsg)
Expand Down Expand Up @@ -1456,10 +1475,10 @@ func (driver *Driver) isVolumePublished(
return false, nil // Not published yet as targetPath does not exists
}

// Check if target path is the symlink to the device
_, symlink, _ := util.IsFileSymlink(targetPath)
if !symlink {
log.Tracef("Target path %s is not symlink to the device %s", targetPath, stagingDev.Device.AltFullPathName)
// Check if target path is a block device
_, blockDevice, _ := util.IsFileBlockDevice(targetPath)
if !blockDevice {
log.Tracef("Target path %s is not a block device to the mpath device %s", targetPath, stagingDev.Device.AltFullPathName)
return false, nil // Not published yet as symlink does not exists
}

Expand Down Expand Up @@ -1732,13 +1751,13 @@ func (driver *Driver) nodeUnpublishVolume(targetPath string) error {
defer log.Trace("<<<<< nodeUnpublishVolume")

// Block volume: Check for symlink and remove it
_, symlink, _ := util.IsFileSymlink(targetPath)
if symlink {
// Remove the symlink
log.Tracef("Removing the symlink from target path %s", targetPath)
_, blockDevice, _ := util.IsFileBlockDevice(targetPath)
if blockDevice {
// Remove the block device
log.Tracef("Removing the block device from mpath device %s", targetPath)
if err := util.FileDelete(targetPath); err != nil {
return status.Error(codes.Internal,
fmt.Sprintf("Error removing the symlink target path %s, err: %s",
fmt.Sprintf("Error removing the block device target path%s, err: %s",
targetPath, err.Error()))
}
return nil
Expand Down
34 changes: 25 additions & 9 deletions vendor/github.com/hpe-storage/common-host-libs/model/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions vendor/github.com/hpe-storage/common-host-libs/util/file.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ github.com/google/uuid
# github.com/gorilla/mux v1.8.0
## explicit; go 1.12
github.com/gorilla/mux
# github.com/hpe-storage/common-host-libs v0.0.0-20250814050617-b92e778a7508
# github.com/hpe-storage/common-host-libs v0.0.0-20251030032113-e9caff71ad6b
## explicit; go 1.23.0
github.com/hpe-storage/common-host-libs/chapi
github.com/hpe-storage/common-host-libs/concurrent
Expand Down