diff --git a/internal/cephfs/cephfs_util.go b/internal/cephfs/cephfs_util.go index 247e2767e..60754caf1 100644 --- a/internal/cephfs/cephfs_util.go +++ b/internal/cephfs/cephfs_util.go @@ -23,17 +23,6 @@ import ( "github.com/ceph/ceph-csi/internal/util" ) -// MDSMap is a representation of the mds map sub-structure returned by 'ceph fs get'. -type MDSMap struct { - FilesystemName string `json:"fs_name"` -} - -// CephFilesystemDetails is a representation of the main json structure returned by 'ceph fs get'. -type CephFilesystemDetails struct { - ID int64 `json:"id"` - MDSMap MDSMap `json:"mdsmap"` -} - func (vo *volumeOptions) getFscID(ctx context.Context) (int64, error) { fsa, err := vo.conn.GetFSAdmin() if err != nil { @@ -91,30 +80,22 @@ func getMetadataPool(ctx context.Context, monitors string, cr *util.Credentials, return "", fmt.Errorf("%w: fsName (%s) not found in Ceph cluster", util.ErrPoolNotFound, fsName) } -// CephFilesystemDump is a representation of the main json structure returned by 'ceph fs dump'. -type CephFilesystemDump struct { - Filesystems []CephFilesystemDetails `json:"filesystems"` -} - -func (vo *volumeOptions) getFsName(ctx context.Context, cr *util.Credentials) (string, error) { - // ./tbox ceph fs dump --format=json - // JSON: {...,"filesystems":[{"mdsmap":{},"id":},...],...} - var fsDump CephFilesystemDump - err := execCommandJSON(ctx, &fsDump, - "ceph", - "-m", vo.Monitors, - "--id", cr.ID, - "--keyfile="+cr.KeyFile, - "-c", util.CephConfigPath, - "fs", "dump", "--format=json", - ) +func (vo *volumeOptions) getFsName(ctx context.Context) (string, error) { + fsa, err := vo.conn.GetFSAdmin() if err != nil { + util.ErrorLog(ctx, "could not get FSAdmin, can not fetch filesystem name for ID %d:", vo.FscID, err) return "", err } - for _, fs := range fsDump.Filesystems { - if fs.ID == vo.FscID { - return fs.MDSMap.FilesystemName, nil + volumes, err := fsa.EnumerateVolumes() + if err != nil { + util.ErrorLog(ctx, "could not list volumes, can not fetch filesystem name for ID %d:", vo.FscID, err) + return "", err + } + + for _, vol := range volumes { + if vol.ID == vo.FscID { + return vol.Name, nil } } diff --git a/internal/cephfs/volumeoptions.go b/internal/cephfs/volumeoptions.go index 37ad20f04..a0b5a82f1 100644 --- a/internal/cephfs/volumeoptions.go +++ b/internal/cephfs/volumeoptions.go @@ -283,7 +283,7 @@ func newVolumeOptionsFromVolID(ctx context.Context, volID string, volOpt, secret return nil, nil, err } - volOptions.FsName, err = volOptions.getFsName(ctx, cr) + volOptions.FsName, err = volOptions.getFsName(ctx) if err != nil { return nil, nil, err } @@ -478,7 +478,7 @@ func newSnapshotOptionsFromID(ctx context.Context, snapID string, cr *util.Crede return &volOptions, nil, &sid, fmt.Errorf("failed to fetch subvolumegroup list using clusterID (%s): %w", vi.ClusterID, err) } - volOptions.FsName, err = volOptions.getFsName(ctx, cr) + volOptions.FsName, err = volOptions.getFsName(ctx) if err != nil { return &volOptions, nil, &sid, err }