Skip to content

Commit cc87014

Browse files
committed
First revision of raw block volume
1 parent cd3c0b6 commit cc87014

File tree

7 files changed

+340
-32
lines changed

7 files changed

+340
-32
lines changed

pkg/csi-util/utils.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"net"
2121
"os"
2222
"os/exec"
23+
"path/filepath"
2324
"strconv"
2425
"strings"
2526
"sync"
@@ -70,6 +71,9 @@ const (
7071
FINDMNT_COMMAND = "findmnt"
7172
CAT_COMMAND = "cat"
7273
RPM_COMMAND = "rpm-host"
74+
75+
// For Raw Block Volumes, the name of the bind-mounted file inside StagingTargetPath
76+
RawBlockStagingFile = "mountfile"
7377
)
7478

7579
// Util interface
@@ -450,3 +454,36 @@ func ValidateFssId(id string) *FSSVolumeHandler {
450454
}
451455
return volumeHandler
452456
}
457+
458+
func GetStagingTargetPathForFile(stagingTargetPath string) string {
459+
stagingTargetPathFile := filepath.Join(stagingTargetPath, RawBlockStagingFile)
460+
return stagingTargetPathFile
461+
}
462+
463+
// Creates a file on the specified path after creating the containing directory
464+
func CreateFilePath(logger *zap.SugaredLogger, path string) error {
465+
pathDir := filepath.Dir(path)
466+
467+
logger.Infof("trying to create surrounding directory %s", pathDir)
468+
err := os.MkdirAll(pathDir, 0750)
469+
if err != nil {
470+
logger.Infof("failed to create surrounding directory %s", pathDir)
471+
return err
472+
}
473+
474+
logger.Infof("created surrounding directory, trying to create the target file %s", path)
475+
file, fileErr := os.OpenFile(path, os.O_CREATE, 0640)
476+
if fileErr != nil && !os.IsExist(fileErr) {
477+
logger.Infof("failed to create/open the target file at %s", path)
478+
return fileErr
479+
}
480+
481+
fileErr = file.Close()
482+
if fileErr != nil {
483+
logger.Infof("failed to close %s", path)
484+
return fileErr
485+
}
486+
487+
logger.Infof("ensured file at %s", path)
488+
return nil
489+
}

pkg/csi/driver/bv_controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -949,10 +949,10 @@ func (d *BlockVolumeControllerDriver) validateCapabilities(caps []*csi.VolumeCap
949949
}
950950

951951
for _, cap := range caps {
952-
if blk := cap.GetBlock(); blk != nil {
953-
d.logger.Error("volumeMode is set to Block which is not supported.")
954-
return fmt.Errorf("driver does not support Block volumeMode. Please use Filesystem mode")
955-
}
952+
// if blk := cap.GetBlock(); blk != nil {
953+
// d.logger.Error("volumeMode is set to Block which is not supported.")
954+
// return fmt.Errorf("driver does not support Block volumeMode. Please use Filesystem mode")
955+
// }
956956
if hasSupport(cap.AccessMode.Mode) {
957957
continue
958958
} else {

0 commit comments

Comments
 (0)