Fix CSI driver volumeMode: Block support
parent
caa2cc2e6c
commit
8e88f77101
|
@ -67,29 +67,44 @@ func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
|
||||||
klog.Infof("received node publish volume request %+v", protosanitizer.StripSecrets(req))
|
klog.Infof("received node publish volume request %+v", protosanitizer.StripSecrets(req))
|
||||||
|
|
||||||
targetPath := req.GetTargetPath()
|
targetPath := req.GetTargetPath()
|
||||||
|
isBlock := req.GetVolumeCapability().GetBlock() != nil
|
||||||
|
|
||||||
// Check that it's not already mounted
|
// Check that it's not already mounted
|
||||||
free, error := mount.IsNotMountPoint(ns.mounter, targetPath)
|
_, error := mount.IsNotMountPoint(ns.mounter, targetPath)
|
||||||
if (error != nil)
|
if (error != nil)
|
||||||
{
|
{
|
||||||
if (os.IsNotExist(error))
|
if (os.IsNotExist(error))
|
||||||
{
|
{
|
||||||
error := os.MkdirAll(targetPath, 0777)
|
if (isBlock)
|
||||||
if (error != nil)
|
|
||||||
{
|
{
|
||||||
return nil, status.Error(codes.Internal, error.Error())
|
pathFile, err := os.OpenFile(targetPath, os.O_CREATE|os.O_RDWR, 0o600)
|
||||||
|
if (err != nil)
|
||||||
|
{
|
||||||
|
klog.Errorf("failed to create block device mount target %s with error: %v", targetPath, err)
|
||||||
|
return nil, status.Error(codes.Internal, err.Error())
|
||||||
|
}
|
||||||
|
err = pathFile.Close()
|
||||||
|
if (err != nil)
|
||||||
|
{
|
||||||
|
klog.Errorf("failed to close %s with error: %v", targetPath, err)
|
||||||
|
return nil, status.Error(codes.Internal, err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
err := os.MkdirAll(targetPath, 0777)
|
||||||
|
if (err != nil)
|
||||||
|
{
|
||||||
|
klog.Errorf("failed to create fs mount target %s with error: %v", targetPath, err)
|
||||||
|
return nil, status.Error(codes.Internal, err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
free = true
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return nil, status.Error(codes.Internal, error.Error())
|
return nil, status.Error(codes.Internal, error.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!free)
|
|
||||||
{
|
|
||||||
return &csi.NodePublishVolumeResponse{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
ctxVars := make(map[string]string)
|
ctxVars := make(map[string]string)
|
||||||
err := json.Unmarshal([]byte(req.VolumeId), &ctxVars)
|
err := json.Unmarshal([]byte(req.VolumeId), &ctxVars)
|
||||||
|
@ -149,7 +164,6 @@ func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
|
||||||
|
|
||||||
// Format the device (ext4 or xfs)
|
// Format the device (ext4 or xfs)
|
||||||
fsType := req.GetVolumeCapability().GetMount().GetFsType()
|
fsType := req.GetVolumeCapability().GetMount().GetFsType()
|
||||||
isBlock := req.GetVolumeCapability().GetBlock() != nil
|
|
||||||
opt := req.GetVolumeCapability().GetMount().GetMountFlags()
|
opt := req.GetVolumeCapability().GetMount().GetMountFlags()
|
||||||
opt = append(opt, "_netdev")
|
opt = append(opt, "_netdev")
|
||||||
if ((req.VolumeCapability.AccessMode.Mode == csi.VolumeCapability_AccessMode_MULTI_NODE_READER_ONLY ||
|
if ((req.VolumeCapability.AccessMode.Mode == csi.VolumeCapability_AccessMode_MULTI_NODE_READER_ONLY ||
|
||||||
|
|
Loading…
Reference in New Issue