mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-17 20:00:23 +00:00
cephfs: implement getFscID() with go-ceph
Fixes: #1550 Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
parent
b28ff63a29
commit
f646840779
@ -34,23 +34,27 @@ type CephFilesystemDetails struct {
|
|||||||
MDSMap MDSMap `json:"mdsmap"`
|
MDSMap MDSMap `json:"mdsmap"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vo *volumeOptions) getFscID(ctx context.Context, cr *util.Credentials) (int64, error) {
|
func (vo *volumeOptions) getFscID(ctx context.Context) (int64, error) {
|
||||||
// ceph fs get myfs --format=json
|
fsa, err := vo.conn.GetFSAdmin()
|
||||||
// {"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",
|
|
||||||
)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
util.ErrorLog(ctx, "could not get FSAdmin, can not fetch filesystem ID for %s:", vo.FsName, err)
|
||||||
return 0, 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'.
|
// CephFilesystem is a representation of the json structure returned by 'ceph fs ls'.
|
||||||
|
@ -215,7 +215,7 @@ func newVolumeOptions(ctx context.Context, requestName string, req *csi.CreateVo
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.FscID, err = opts.getFscID(ctx, cr)
|
opts.FscID, err = opts.getFscID(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user