2018-03-05 11:59:47 +00:00
|
|
|
/*
|
2019-04-03 08:46:15 +00:00
|
|
|
Copyright 2018 The Ceph-CSI Authors.
|
2018-03-05 11:59:47 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package cephfs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-06-25 08:35:19 +00:00
|
|
|
"errors"
|
2018-08-28 08:21:11 +00:00
|
|
|
"fmt"
|
2018-04-13 13:53:43 +00:00
|
|
|
"os"
|
2020-06-16 07:29:20 +00:00
|
|
|
"strings"
|
2018-03-05 11:59:47 +00:00
|
|
|
|
2021-09-16 13:47:57 +00:00
|
|
|
"github.com/ceph/ceph-csi/internal/cephfs/core"
|
2021-08-25 06:46:03 +00:00
|
|
|
cerrors "github.com/ceph/ceph-csi/internal/cephfs/errors"
|
2021-09-16 14:46:07 +00:00
|
|
|
"github.com/ceph/ceph-csi/internal/cephfs/mounter"
|
2021-09-16 13:47:57 +00:00
|
|
|
fsutil "github.com/ceph/ceph-csi/internal/cephfs/util"
|
2020-04-17 09:23:49 +00:00
|
|
|
csicommon "github.com/ceph/ceph-csi/internal/csi-common"
|
|
|
|
"github.com/ceph/ceph-csi/internal/util"
|
2021-08-24 15:03:25 +00:00
|
|
|
"github.com/ceph/ceph-csi/internal/util/log"
|
2019-02-18 11:30:28 +00:00
|
|
|
|
|
|
|
"github.com/container-storage-interface/spec/lib/go/csi"
|
2018-03-05 11:59:47 +00:00
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
|
|
|
)
|
|
|
|
|
2019-01-28 11:47:06 +00:00
|
|
|
// NodeServer struct of ceph CSI driver with supported methods of CSI
|
|
|
|
// node server spec.
|
2019-01-17 07:51:06 +00:00
|
|
|
type NodeServer struct {
|
2018-03-05 11:59:47 +00:00
|
|
|
*csicommon.DefaultNodeServer
|
2019-09-12 04:53:37 +00:00
|
|
|
// A map storing all volumes with ongoing operations so that additional operations
|
|
|
|
// for that same volume (as defined by VolumeID) return an Aborted error
|
|
|
|
VolumeLocks *util.VolumeLocks
|
2018-03-05 11:59:47 +00:00
|
|
|
}
|
|
|
|
|
2021-09-16 13:47:57 +00:00
|
|
|
func getCredentialsForVolume(
|
|
|
|
volOptions *core.VolumeOptions,
|
|
|
|
req *csi.NodeStageVolumeRequest) (*util.Credentials, error) {
|
2018-04-13 13:53:43 +00:00
|
|
|
var (
|
2019-06-25 19:29:17 +00:00
|
|
|
err error
|
2019-06-01 21:26:42 +00:00
|
|
|
cr *util.Credentials
|
2019-02-13 12:57:16 +00:00
|
|
|
secrets = req.GetSecrets()
|
2018-04-13 13:53:43 +00:00
|
|
|
)
|
2019-02-13 12:57:16 +00:00
|
|
|
|
2018-04-13 13:53:43 +00:00
|
|
|
if volOptions.ProvisionVolume {
|
2019-06-25 19:29:17 +00:00
|
|
|
// The volume is provisioned dynamically, use passed in admin credentials
|
2018-04-13 13:53:43 +00:00
|
|
|
|
2019-06-25 19:29:17 +00:00
|
|
|
cr, err = util.NewAdminCredentials(secrets)
|
2018-06-12 15:08:14 +00:00
|
|
|
if err != nil {
|
2020-07-13 03:56:51 +00:00
|
|
|
return nil, fmt.Errorf("failed to get admin credentials from node stage secrets: %w", err)
|
2018-06-12 15:08:14 +00:00
|
|
|
}
|
2018-04-13 13:53:43 +00:00
|
|
|
} else {
|
2018-08-28 08:21:11 +00:00
|
|
|
// The volume is pre-made, credentials are in node stage secrets
|
2018-04-13 13:53:43 +00:00
|
|
|
|
2019-06-25 19:29:17 +00:00
|
|
|
cr, err = util.NewUserCredentials(req.GetSecrets())
|
2018-04-13 13:53:43 +00:00
|
|
|
if err != nil {
|
2020-07-13 03:56:51 +00:00
|
|
|
return nil, fmt.Errorf("failed to get user credentials from node stage secrets: %w", err)
|
2018-04-13 13:53:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-13 12:57:16 +00:00
|
|
|
return cr, nil
|
2018-04-13 13:53:43 +00:00
|
|
|
}
|
|
|
|
|
2019-01-28 11:47:06 +00:00
|
|
|
// NodeStageVolume mounts the volume to a staging path on the node.
|
2021-06-25 10:18:59 +00:00
|
|
|
func (ns *NodeServer) NodeStageVolume(
|
|
|
|
ctx context.Context,
|
|
|
|
req *csi.NodeStageVolumeRequest) (*csi.NodeStageVolumeResponse, error) {
|
2021-09-16 13:47:57 +00:00
|
|
|
var volOptions *core.VolumeOptions
|
2019-07-03 10:02:36 +00:00
|
|
|
if err := util.ValidateNodeStageVolumeRequest(req); err != nil {
|
|
|
|
return nil, err
|
2018-03-05 11:59:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Configuration
|
|
|
|
|
2018-07-28 08:24:07 +00:00
|
|
|
stagingTargetPath := req.GetStagingTargetPath()
|
2021-09-16 13:47:57 +00:00
|
|
|
volID := fsutil.VolumeID(req.GetVolumeId())
|
2018-03-05 11:59:47 +00:00
|
|
|
|
2019-09-12 04:53:37 +00:00
|
|
|
if acquired := ns.VolumeLocks.TryAcquire(req.GetVolumeId()); !acquired {
|
2021-08-24 15:03:25 +00:00
|
|
|
log.ErrorLog(ctx, util.VolumeOperationAlreadyExistsFmt, volID)
|
2021-07-22 05:45:17 +00:00
|
|
|
|
2019-09-12 04:53:37 +00:00
|
|
|
return nil, status.Errorf(codes.Aborted, util.VolumeOperationAlreadyExistsFmt, req.GetVolumeId())
|
|
|
|
}
|
|
|
|
defer ns.VolumeLocks.Release(req.GetVolumeId())
|
|
|
|
|
2021-09-16 13:47:57 +00:00
|
|
|
volOptions, _, err := core.NewVolumeOptionsFromVolID(ctx, string(volID), req.GetVolumeContext(), req.GetSecrets())
|
2018-03-20 15:14:14 +00:00
|
|
|
if err != nil {
|
2021-08-25 06:46:03 +00:00
|
|
|
if !errors.Is(err, cerrors.ErrInvalidVolID) {
|
2019-05-28 19:03:18 +00:00
|
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
|
|
}
|
2018-03-05 11:59:47 +00:00
|
|
|
|
2020-07-12 04:55:14 +00:00
|
|
|
// gets mon IPs from the supplied cluster info
|
2021-09-16 13:47:57 +00:00
|
|
|
volOptions, _, err = core.NewVolumeOptionsFromStaticVolume(string(volID), req.GetVolumeContext())
|
2019-05-28 19:03:18 +00:00
|
|
|
if err != nil {
|
2021-08-25 06:46:03 +00:00
|
|
|
if !errors.Is(err, cerrors.ErrNonStaticVolume) {
|
2019-05-28 19:03:18 +00:00
|
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
|
|
}
|
|
|
|
|
2020-07-12 04:55:14 +00:00
|
|
|
// get mon IPs from the volume context
|
2021-09-16 13:47:57 +00:00
|
|
|
volOptions, _, err = core.NewVolumeOptionsFromMonitorList(string(volID), req.GetVolumeContext(),
|
2019-05-28 19:03:18 +00:00
|
|
|
req.GetSecrets())
|
|
|
|
if err != nil {
|
|
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
|
|
}
|
|
|
|
}
|
2018-08-28 08:21:11 +00:00
|
|
|
}
|
2020-08-05 10:10:04 +00:00
|
|
|
defer volOptions.Destroy()
|
2018-08-28 08:21:11 +00:00
|
|
|
|
2018-03-05 11:59:47 +00:00
|
|
|
// Check if the volume is already mounted
|
|
|
|
|
2019-07-03 10:02:36 +00:00
|
|
|
isMnt, err := util.IsMountPoint(stagingTargetPath)
|
2018-03-05 11:59:47 +00:00
|
|
|
if err != nil {
|
2021-08-24 15:03:25 +00:00
|
|
|
log.ErrorLog(ctx, "stat failed: %v", err)
|
2021-07-22 05:45:17 +00:00
|
|
|
|
2018-03-05 11:59:47 +00:00
|
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
if isMnt {
|
2021-08-24 15:03:25 +00:00
|
|
|
log.DebugLog(ctx, "cephfs: volume %s is already mounted to %s, skipping", volID, stagingTargetPath)
|
2021-07-22 05:45:17 +00:00
|
|
|
|
2018-07-28 08:24:07 +00:00
|
|
|
return &csi.NodeStageVolumeResponse{}, nil
|
2018-03-05 11:59:47 +00:00
|
|
|
}
|
|
|
|
|
2018-04-13 13:53:43 +00:00
|
|
|
// It's not, mount now
|
2019-08-22 17:19:06 +00:00
|
|
|
if err = ns.mount(ctx, volOptions, req); err != nil {
|
2019-01-29 05:49:16 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-08-24 15:03:25 +00:00
|
|
|
log.DebugLog(ctx, "cephfs: successfully mounted volume %s to %s", volID, stagingTargetPath)
|
2019-01-29 05:49:16 +00:00
|
|
|
|
|
|
|
return &csi.NodeStageVolumeResponse{}, nil
|
|
|
|
}
|
|
|
|
|
2021-09-16 13:47:57 +00:00
|
|
|
func (*NodeServer) mount(ctx context.Context, volOptions *core.VolumeOptions, req *csi.NodeStageVolumeRequest) error {
|
2019-01-29 05:49:16 +00:00
|
|
|
stagingTargetPath := req.GetStagingTargetPath()
|
2021-09-16 13:47:57 +00:00
|
|
|
volID := fsutil.VolumeID(req.GetVolumeId())
|
2018-04-13 13:53:43 +00:00
|
|
|
|
2019-06-20 07:35:53 +00:00
|
|
|
cr, err := getCredentialsForVolume(volOptions, req)
|
2018-03-22 13:11:51 +00:00
|
|
|
if err != nil {
|
2021-08-24 15:03:25 +00:00
|
|
|
log.ErrorLog(ctx, "failed to get ceph credentials for volume %s: %v", volID, err)
|
2021-07-22 05:45:17 +00:00
|
|
|
|
2019-01-29 05:49:16 +00:00
|
|
|
return status.Error(codes.Internal, err.Error())
|
2018-03-22 13:11:51 +00:00
|
|
|
}
|
2019-06-25 19:29:17 +00:00
|
|
|
defer cr.DeleteCredentials()
|
2018-03-09 16:05:19 +00:00
|
|
|
|
2021-09-16 14:46:07 +00:00
|
|
|
m, err := mounter.New(volOptions)
|
2018-08-14 09:19:41 +00:00
|
|
|
if err != nil {
|
2021-08-24 15:03:25 +00:00
|
|
|
log.ErrorLog(ctx, "failed to create mounter for volume %s: %v", volID, err)
|
2021-07-22 05:45:17 +00:00
|
|
|
|
2019-01-29 05:49:16 +00:00
|
|
|
return status.Error(codes.Internal, err.Error())
|
2018-08-14 09:19:41 +00:00
|
|
|
}
|
2018-07-28 08:24:07 +00:00
|
|
|
|
2021-09-16 13:47:57 +00:00
|
|
|
log.DebugLog(ctx, "cephfs: mounting volume %s with %s", volID, m.Name())
|
2018-08-28 08:21:11 +00:00
|
|
|
|
2020-06-16 07:38:37 +00:00
|
|
|
readOnly := "ro"
|
|
|
|
fuseMountOptions := strings.Split(volOptions.FuseMountOptions, ",")
|
|
|
|
kernelMountOptions := strings.Split(volOptions.KernelMountOptions, ",")
|
|
|
|
|
2020-06-16 07:29:20 +00:00
|
|
|
if req.VolumeCapability.AccessMode.Mode == csi.VolumeCapability_AccessMode_MULTI_NODE_READER_ONLY ||
|
|
|
|
req.VolumeCapability.AccessMode.Mode == csi.VolumeCapability_AccessMode_SINGLE_NODE_READER_ONLY {
|
|
|
|
switch m.(type) {
|
2021-09-16 14:46:07 +00:00
|
|
|
case *mounter.FuseMounter:
|
2020-06-16 07:29:20 +00:00
|
|
|
if !csicommon.MountOptionContains(strings.Split(volOptions.FuseMountOptions, ","), readOnly) {
|
|
|
|
volOptions.FuseMountOptions = util.MountOptionsAdd(volOptions.FuseMountOptions, readOnly)
|
2020-06-16 07:38:37 +00:00
|
|
|
fuseMountOptions = append(fuseMountOptions, readOnly)
|
2020-06-16 07:29:20 +00:00
|
|
|
}
|
2021-09-16 14:46:07 +00:00
|
|
|
case *mounter.KernelMounter:
|
2020-06-16 07:29:20 +00:00
|
|
|
if !csicommon.MountOptionContains(strings.Split(volOptions.KernelMountOptions, ","), readOnly) {
|
|
|
|
volOptions.KernelMountOptions = util.MountOptionsAdd(volOptions.KernelMountOptions, readOnly)
|
2020-06-16 07:38:37 +00:00
|
|
|
kernelMountOptions = append(kernelMountOptions, readOnly)
|
2020-06-16 07:29:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-16 13:47:57 +00:00
|
|
|
if err = m.Mount(ctx, stagingTargetPath, cr, volOptions); err != nil {
|
2021-08-24 15:03:25 +00:00
|
|
|
log.ErrorLog(ctx,
|
2020-08-11 12:11:51 +00:00
|
|
|
"failed to mount volume %s: %v Check dmesg logs if required.",
|
2020-05-19 12:29:31 +00:00
|
|
|
volID,
|
|
|
|
err)
|
2021-07-22 05:45:17 +00:00
|
|
|
|
2019-01-29 05:49:16 +00:00
|
|
|
return status.Error(codes.Internal, err.Error())
|
2018-03-05 11:59:47 +00:00
|
|
|
}
|
2021-06-25 10:18:59 +00:00
|
|
|
if !csicommon.MountOptionContains(kernelMountOptions, readOnly) &&
|
|
|
|
!csicommon.MountOptionContains(fuseMountOptions, readOnly) {
|
2020-06-16 07:38:37 +00:00
|
|
|
// #nosec - allow anyone to write inside the stagingtarget path
|
2021-07-13 12:21:05 +00:00
|
|
|
err = os.Chmod(stagingTargetPath, 0o777)
|
2020-06-16 07:38:37 +00:00
|
|
|
if err != nil {
|
2021-08-24 15:03:25 +00:00
|
|
|
log.ErrorLog(
|
2021-06-25 10:18:59 +00:00
|
|
|
ctx,
|
|
|
|
"failed to change stagingtarget path %s permission for volume %s: %v",
|
|
|
|
stagingTargetPath,
|
|
|
|
volID,
|
|
|
|
err)
|
2021-09-16 14:46:07 +00:00
|
|
|
uErr := mounter.UnmountVolume(ctx, stagingTargetPath)
|
2020-06-16 07:38:37 +00:00
|
|
|
if uErr != nil {
|
2021-08-24 15:03:25 +00:00
|
|
|
log.ErrorLog(
|
2021-06-25 10:18:59 +00:00
|
|
|
ctx,
|
|
|
|
"failed to umount stagingtarget path %s for volume %s: %v",
|
|
|
|
stagingTargetPath,
|
|
|
|
volID,
|
|
|
|
uErr)
|
2020-06-16 07:38:37 +00:00
|
|
|
}
|
2021-07-22 05:45:17 +00:00
|
|
|
|
2020-06-16 07:38:37 +00:00
|
|
|
return status.Error(codes.Internal, err.Error())
|
|
|
|
}
|
|
|
|
}
|
2021-07-22 05:45:17 +00:00
|
|
|
|
2019-01-29 05:49:16 +00:00
|
|
|
return nil
|
2018-07-28 08:24:07 +00:00
|
|
|
}
|
|
|
|
|
2019-01-28 11:47:06 +00:00
|
|
|
// NodePublishVolume mounts the volume mounted to the staging path to the target
|
2020-07-19 12:21:03 +00:00
|
|
|
// path.
|
2021-06-25 10:18:59 +00:00
|
|
|
func (ns *NodeServer) NodePublishVolume(
|
|
|
|
ctx context.Context,
|
|
|
|
req *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) {
|
2020-01-23 08:24:46 +00:00
|
|
|
mountOptions := []string{"bind", "_netdev"}
|
2019-07-03 10:02:36 +00:00
|
|
|
if err := util.ValidateNodePublishVolumeRequest(req); err != nil {
|
|
|
|
return nil, err
|
2018-07-28 08:24:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
targetPath := req.GetTargetPath()
|
2019-01-17 05:46:32 +00:00
|
|
|
volID := req.GetVolumeId()
|
2018-07-28 08:24:07 +00:00
|
|
|
|
2021-07-13 05:28:32 +00:00
|
|
|
// Considering kubelet make sure the stage and publish operations
|
|
|
|
// are serialized, we dont need any extra locking in nodePublish
|
2019-09-12 04:53:37 +00:00
|
|
|
|
2019-07-03 10:02:36 +00:00
|
|
|
if err := util.CreateMountPoint(targetPath); err != nil {
|
2021-08-24 15:03:25 +00:00
|
|
|
log.ErrorLog(ctx, "failed to create mount point at %s: %v", targetPath, err)
|
2021-07-22 05:45:17 +00:00
|
|
|
|
2018-07-28 08:24:07 +00:00
|
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
|
|
}
|
|
|
|
|
2019-06-06 12:18:11 +00:00
|
|
|
if req.GetReadonly() {
|
|
|
|
mountOptions = append(mountOptions, "ro")
|
|
|
|
}
|
|
|
|
|
2020-01-23 08:24:46 +00:00
|
|
|
mountOptions = csicommon.ConstructMountOptions(mountOptions, req.GetVolumeCapability())
|
2019-06-06 12:18:11 +00:00
|
|
|
|
2018-07-28 08:24:07 +00:00
|
|
|
// Check if the volume is already mounted
|
|
|
|
|
2019-07-03 10:02:36 +00:00
|
|
|
isMnt, err := util.IsMountPoint(targetPath)
|
2018-07-28 08:24:07 +00:00
|
|
|
if err != nil {
|
2021-08-24 15:03:25 +00:00
|
|
|
log.ErrorLog(ctx, "stat failed: %v", err)
|
2021-07-22 05:45:17 +00:00
|
|
|
|
2018-07-28 08:24:07 +00:00
|
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
if isMnt {
|
2021-08-24 15:03:25 +00:00
|
|
|
log.DebugLog(ctx, "cephfs: volume %s is already bind-mounted to %s", volID, targetPath)
|
2021-07-22 05:45:17 +00:00
|
|
|
|
2018-07-28 08:24:07 +00:00
|
|
|
return &csi.NodePublishVolumeResponse{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// It's not, mount now
|
|
|
|
|
2021-09-16 14:46:07 +00:00
|
|
|
if err = mounter.BindMount(
|
2021-09-16 13:47:57 +00:00
|
|
|
ctx,
|
|
|
|
req.GetStagingTargetPath(),
|
|
|
|
req.GetTargetPath(),
|
|
|
|
req.GetReadonly(),
|
|
|
|
mountOptions); err != nil {
|
2021-08-24 15:03:25 +00:00
|
|
|
log.ErrorLog(ctx, "failed to bind-mount volume %s: %v", volID, err)
|
2021-07-22 05:45:17 +00:00
|
|
|
|
2018-07-28 08:24:07 +00:00
|
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
|
|
}
|
|
|
|
|
2021-08-24 15:03:25 +00:00
|
|
|
log.DebugLog(ctx, "cephfs: successfully bind-mounted volume %s to %s", volID, targetPath)
|
2018-03-05 11:59:47 +00:00
|
|
|
|
|
|
|
return &csi.NodePublishVolumeResponse{}, nil
|
|
|
|
}
|
|
|
|
|
2020-07-19 12:21:03 +00:00
|
|
|
// NodeUnpublishVolume unmounts the volume from the target path.
|
2021-06-25 10:18:59 +00:00
|
|
|
func (ns *NodeServer) NodeUnpublishVolume(
|
|
|
|
ctx context.Context,
|
|
|
|
req *csi.NodeUnpublishVolumeRequest) (*csi.NodeUnpublishVolumeResponse, error) {
|
2019-01-28 13:59:16 +00:00
|
|
|
var err error
|
2019-07-03 10:02:36 +00:00
|
|
|
if err = util.ValidateNodeUnpublishVolumeRequest(req); err != nil {
|
|
|
|
return nil, err
|
2018-03-05 11:59:47 +00:00
|
|
|
}
|
2021-07-13 05:24:21 +00:00
|
|
|
// considering kubelet make sure node operations like unpublish/unstage...etc can not be called
|
|
|
|
// at same time, an explicit locking at time of nodeunpublish is not required.
|
2018-04-13 13:53:43 +00:00
|
|
|
targetPath := req.GetTargetPath()
|
2021-06-07 05:30:03 +00:00
|
|
|
isMnt, err := util.IsMountPoint(targetPath)
|
|
|
|
if err != nil {
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
// targetPath has already been deleted
|
2021-08-24 15:03:25 +00:00
|
|
|
log.DebugLog(ctx, "targetPath: %s has already been deleted", targetPath)
|
2021-07-22 05:45:17 +00:00
|
|
|
|
2021-06-07 05:30:03 +00:00
|
|
|
return &csi.NodeUnpublishVolumeResponse{}, nil
|
|
|
|
}
|
2021-07-22 05:45:17 +00:00
|
|
|
|
2021-06-07 05:40:16 +00:00
|
|
|
return nil, status.Error(codes.Internal, err.Error())
|
2021-06-07 05:30:03 +00:00
|
|
|
}
|
|
|
|
if !isMnt {
|
|
|
|
if err = os.RemoveAll(targetPath); err != nil {
|
|
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
|
|
}
|
2021-07-22 05:45:17 +00:00
|
|
|
|
2021-06-07 05:30:03 +00:00
|
|
|
return &csi.NodeUnpublishVolumeResponse{}, nil
|
|
|
|
}
|
|
|
|
|
2018-04-13 13:53:43 +00:00
|
|
|
// Unmount the bind-mount
|
2021-09-16 14:46:07 +00:00
|
|
|
if err = mounter.UnmountVolume(ctx, targetPath); err != nil {
|
2018-03-05 11:59:47 +00:00
|
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
|
|
}
|
|
|
|
|
2019-12-17 09:07:46 +00:00
|
|
|
err = os.Remove(targetPath)
|
|
|
|
if err != nil && !os.IsNotExist(err) {
|
2019-01-28 13:59:16 +00:00
|
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
|
|
}
|
2018-07-28 08:24:07 +00:00
|
|
|
|
2021-08-24 15:03:25 +00:00
|
|
|
log.DebugLog(ctx, "cephfs: successfully unbounded volume %s from %s", req.GetVolumeId(), targetPath)
|
2018-07-28 08:24:07 +00:00
|
|
|
|
|
|
|
return &csi.NodeUnpublishVolumeResponse{}, nil
|
|
|
|
}
|
2018-04-13 13:53:43 +00:00
|
|
|
|
2020-07-19 12:21:03 +00:00
|
|
|
// NodeUnstageVolume unstages the volume from the staging path.
|
2021-06-25 10:18:59 +00:00
|
|
|
func (ns *NodeServer) NodeUnstageVolume(
|
|
|
|
ctx context.Context,
|
|
|
|
req *csi.NodeUnstageVolumeRequest) (*csi.NodeUnstageVolumeResponse, error) {
|
2019-01-28 13:59:16 +00:00
|
|
|
var err error
|
2019-07-03 10:02:36 +00:00
|
|
|
if err = util.ValidateNodeUnstageVolumeRequest(req); err != nil {
|
|
|
|
return nil, err
|
2018-07-28 08:24:07 +00:00
|
|
|
}
|
|
|
|
|
2019-09-12 04:53:37 +00:00
|
|
|
volID := req.GetVolumeId()
|
|
|
|
if acquired := ns.VolumeLocks.TryAcquire(volID); !acquired {
|
2021-08-24 15:03:25 +00:00
|
|
|
log.ErrorLog(ctx, util.VolumeOperationAlreadyExistsFmt, volID)
|
2021-07-22 05:45:17 +00:00
|
|
|
|
2019-09-12 04:53:37 +00:00
|
|
|
return nil, status.Errorf(codes.Aborted, util.VolumeOperationAlreadyExistsFmt, volID)
|
|
|
|
}
|
|
|
|
defer ns.VolumeLocks.Release(volID)
|
|
|
|
|
2018-07-28 08:24:07 +00:00
|
|
|
stagingTargetPath := req.GetStagingTargetPath()
|
2021-06-07 05:30:03 +00:00
|
|
|
|
|
|
|
isMnt, err := util.IsMountPoint(stagingTargetPath)
|
|
|
|
if err != nil {
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
// targetPath has already been deleted
|
2021-08-24 15:03:25 +00:00
|
|
|
log.DebugLog(ctx, "targetPath: %s has already been deleted", stagingTargetPath)
|
2021-07-22 05:45:17 +00:00
|
|
|
|
2021-06-07 05:30:03 +00:00
|
|
|
return &csi.NodeUnstageVolumeResponse{}, nil
|
|
|
|
}
|
2021-07-22 05:45:17 +00:00
|
|
|
|
2021-06-07 05:40:16 +00:00
|
|
|
return nil, status.Error(codes.Internal, err.Error())
|
2021-06-07 05:30:03 +00:00
|
|
|
}
|
|
|
|
if !isMnt {
|
|
|
|
return &csi.NodeUnstageVolumeResponse{}, nil
|
|
|
|
}
|
2018-07-28 08:24:07 +00:00
|
|
|
// Unmount the volume
|
2021-09-16 14:46:07 +00:00
|
|
|
if err = mounter.UnmountVolume(ctx, stagingTargetPath); err != nil {
|
2018-04-13 13:53:43 +00:00
|
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
|
|
}
|
|
|
|
|
2021-08-24 15:03:25 +00:00
|
|
|
log.DebugLog(ctx, "cephfs: successfully unmounted volume %s from %s", req.GetVolumeId(), stagingTargetPath)
|
2018-03-20 15:14:14 +00:00
|
|
|
|
2018-07-28 08:24:07 +00:00
|
|
|
return &csi.NodeUnstageVolumeResponse{}, nil
|
2018-03-20 15:14:14 +00:00
|
|
|
}
|
|
|
|
|
2020-07-19 12:21:03 +00:00
|
|
|
// NodeGetCapabilities returns the supported capabilities of the node server.
|
2021-06-25 10:18:59 +00:00
|
|
|
func (ns *NodeServer) NodeGetCapabilities(
|
|
|
|
ctx context.Context,
|
|
|
|
req *csi.NodeGetCapabilitiesRequest) (*csi.NodeGetCapabilitiesResponse, error) {
|
2018-07-28 08:24:07 +00:00
|
|
|
return &csi.NodeGetCapabilitiesResponse{
|
|
|
|
Capabilities: []*csi.NodeServiceCapability{
|
|
|
|
{
|
|
|
|
Type: &csi.NodeServiceCapability_Rpc{
|
|
|
|
Rpc: &csi.NodeServiceCapability_RPC{
|
|
|
|
Type: csi.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-25 05:15:06 +00:00
|
|
|
{
|
|
|
|
Type: &csi.NodeServiceCapability_Rpc{
|
|
|
|
Rpc: &csi.NodeServiceCapability_RPC{
|
|
|
|
Type: csi.NodeServiceCapability_RPC_GET_VOLUME_STATS,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-07-28 08:24:07 +00:00
|
|
|
},
|
|
|
|
}, nil
|
2018-03-20 15:14:14 +00:00
|
|
|
}
|
2021-01-11 08:02:41 +00:00
|
|
|
|
|
|
|
// NodeGetVolumeStats returns volume stats.
|
2021-06-25 10:18:59 +00:00
|
|
|
func (ns *NodeServer) NodeGetVolumeStats(
|
|
|
|
ctx context.Context,
|
|
|
|
req *csi.NodeGetVolumeStatsRequest) (*csi.NodeGetVolumeStatsResponse, error) {
|
2021-01-11 08:02:41 +00:00
|
|
|
var err error
|
|
|
|
targetPath := req.GetVolumePath()
|
|
|
|
if targetPath == "" {
|
|
|
|
err = fmt.Errorf("targetpath %v is empty", targetPath)
|
2021-07-22 05:45:17 +00:00
|
|
|
|
2021-01-11 08:02:41 +00:00
|
|
|
return nil, status.Error(codes.InvalidArgument, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
stat, err := os.Stat(targetPath)
|
|
|
|
if err != nil {
|
|
|
|
return nil, status.Errorf(codes.InvalidArgument, "failed to get stat for targetpath %q: %v", targetPath, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if stat.Mode().IsDir() {
|
|
|
|
return csicommon.FilesystemNodeGetVolumeStats(ctx, targetPath)
|
|
|
|
}
|
|
|
|
|
2021-05-31 06:38:01 +00:00
|
|
|
return nil, status.Errorf(codes.InvalidArgument, "targetpath %q is not a directory or device", targetPath)
|
2021-01-11 08:02:41 +00:00
|
|
|
}
|