From 6a5dc0f89794df5eb3ac827cbd301b49a062e3f0 Mon Sep 17 00:00:00 2001 From: Goutham Pacha Ravi Date: Thu, 18 Sep 2025 22:02:34 -0700 Subject: [PATCH] Seed fsName to ceph-csi's node plugin This option is now mandatory to use when there are multiple CephFS file systems in the ceph cluster. Without this, ceph won't be able to find the (sub)volume to mount. --- pkg/csi/manila/nodeserver.go | 1 + pkg/csi/manila/shareadapters/cephfs.go | 36 ++++++++++++++++++++ pkg/csi/manila/shareadapters/shareadapter.go | 3 ++ 3 files changed, 40 insertions(+) diff --git a/pkg/csi/manila/nodeserver.go b/pkg/csi/manila/nodeserver.go index 2787971a70..6a2f8fb080 100644 --- a/pkg/csi/manila/nodeserver.go +++ b/pkg/csi/manila/nodeserver.go @@ -133,6 +133,7 @@ func (ns *nodeServer) buildVolumeContext(ctx context.Context, volID volumeID, sh sa := getShareAdapter(ns.d.shareProto) opts := &shareadapters.VolumeContextArgs{ Locations: availableExportLocations, + Share: share, Options: shareOpts, } volumeContext, err = sa.BuildVolumeContext(opts) diff --git a/pkg/csi/manila/shareadapters/cephfs.go b/pkg/csi/manila/shareadapters/cephfs.go index e64744a2d5..82524d039b 100644 --- a/pkg/csi/manila/shareadapters/cephfs.go +++ b/pkg/csi/manila/shareadapters/cephfs.go @@ -19,6 +19,7 @@ package shareadapters import ( "context" "fmt" + "strings" "time" "github.com/gophercloud/gophercloud/v2" @@ -133,9 +134,44 @@ func (Cephfs) BuildVolumeContext(args *VolumeContextArgs) (volumeContext map[str volCtx["fuseMountOptions"] = args.Options.CephfsFuseMountOptions } + // Extract fs_name from __mount_options metadata if available + if fsName := extractFsNameFromMountOptions(args.Share); fsName != "" { + volCtx["fsName"] = fsName + klog.V(4).Infof("Found fs_name in share metadata: %s", fsName) + } + return volCtx, err } +// extractFsNameFromMountOptions extracts the fs from __mount_options metadata +// The __mount_options metadata contains mount options including fs for CephFS +func extractFsNameFromMountOptions(share *shares.Share) string { + if share == nil || share.Metadata == nil { + return "" + } + + mountOptions, exists := share.Metadata["__mount_options"] + if !exists { + klog.V(4).Infof("No __mount_options metadata found in share %s", share.ID) + return "" + } + + // Parse mount options to extract fs + // Mount options are typically comma-separated key=value pairs + // Example: "fs=myfs,other_option=value" + options := strings.Split(mountOptions, ",") + for _, option := range options { + option = strings.TrimSpace(option) + if strings.HasPrefix(option, "fs=") { + fsName := strings.TrimPrefix(option, "fs=") + return strings.TrimSpace(fsName) + } + } + + klog.V(4).Infof("No fs found in __mount_options metadata for share %s: %s", share.ID, mountOptions) + return "" +} + func (Cephfs) BuildNodeStageSecret(args *SecretArgs) (secret map[string]string, err error) { return map[string]string{ "userID": args.AccessRight.AccessTo, diff --git a/pkg/csi/manila/shareadapters/shareadapter.go b/pkg/csi/manila/shareadapters/shareadapter.go index 2bd28a3b10..e84f1bdfff 100644 --- a/pkg/csi/manila/shareadapters/shareadapter.go +++ b/pkg/csi/manila/shareadapters/shareadapter.go @@ -35,6 +35,9 @@ type VolumeContextArgs struct { // an export location when building a volume context. Locations []shares.ExportLocation + // Share object containing metadata and other share information + Share *shares.Share + Options *options.NodeVolumeContext }