diff --git a/internal/cephfs/cephfs_util.go b/internal/cephfs/cephfs_util.go index 68abbd704..7cb987e80 100644 --- a/internal/cephfs/cephfs_util.go +++ b/internal/cephfs/cephfs_util.go @@ -34,23 +34,27 @@ type CephFilesystemDetails struct { MDSMap MDSMap `json:"mdsmap"` } -func (vo *volumeOptions) getFscID(ctx context.Context, cr *util.Credentials) (int64, error) { - // ceph fs get myfs --format=json - // {"mdsmap":{...},"id":2} - var fsDetails CephFilesystemDetails - err := execCommandJSON(ctx, &fsDetails, - "ceph", - "-m", vo.Monitors, - "--id", cr.ID, - "--keyfile="+cr.KeyFile, - "-c", util.CephConfigPath, - "fs", "get", vo.FsName, "--format=json", - ) +func (vo *volumeOptions) getFscID(ctx context.Context) (int64, error) { + fsa, err := vo.conn.GetFSAdmin() if err != nil { + util.ErrorLog(ctx, "could not get FSAdmin, can not fetch filesystem ID for %s:", vo.FsName, err) return 0, err } - return fsDetails.ID, nil + volumes, err := fsa.EnumerateVolumes() + if err != nil { + util.ErrorLog(ctx, "could not list volumes, can not fetch filesystem ID for %s:", vo.FsName, err) + return 0, err + } + + for _, vol := range volumes { + if vol.Name == vo.FsName { + return vol.ID, nil + } + } + + util.ErrorLog(ctx, "failed to list volume %s", vo.FsName) + return 0, ErrVolumeNotFound } // CephFilesystem is a representation of the json structure returned by 'ceph fs ls'. diff --git a/internal/cephfs/volumeoptions.go b/internal/cephfs/volumeoptions.go index 54db90657..c80181a82 100644 --- a/internal/cephfs/volumeoptions.go +++ b/internal/cephfs/volumeoptions.go @@ -215,7 +215,7 @@ func newVolumeOptions(ctx context.Context, requestName string, req *csi.CreateVo return nil, err } - opts.FscID, err = opts.getFscID(ctx, cr) + opts.FscID, err = opts.getFscID(ctx) if err != nil { return nil, err }