mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-18 11:00:25 +00:00
cephfs: implement getMetadataPool() with go-ceph
Fixes: #1554 Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
parent
cabdac4913
commit
eb2584095b
@ -46,38 +46,26 @@ func (vo *volumeOptions) getFscID(ctx context.Context) (int64, error) {
|
|||||||
return 0, ErrVolumeNotFound
|
return 0, ErrVolumeNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
// CephFilesystem is a representation of the json structure returned by 'ceph fs ls'.
|
func (vo *volumeOptions) getMetadataPool(ctx context.Context) (string, error) {
|
||||||
type CephFilesystem struct {
|
fsa, err := vo.conn.GetFSAdmin()
|
||||||
Name string `json:"name"`
|
|
||||||
MetadataPool string `json:"metadata_pool"`
|
|
||||||
MetadataPoolID int `json:"metadata_pool_id"`
|
|
||||||
DataPools []string `json:"data_pools"`
|
|
||||||
DataPoolIDs []int `json:"data_pool_ids"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (vo *volumeOptions) getMetadataPool(ctx context.Context, cr *util.Credentials) (string, error) {
|
|
||||||
// ./tbox ceph fs ls --format=json
|
|
||||||
// [{"name":"myfs","metadata_pool":"myfs-metadata","metadata_pool_id":4,...},...]
|
|
||||||
var filesystems []CephFilesystem
|
|
||||||
err := execCommandJSON(ctx, &filesystems,
|
|
||||||
"ceph",
|
|
||||||
"-m", vo.Monitors,
|
|
||||||
"--id", cr.ID,
|
|
||||||
"--keyfile="+cr.KeyFile,
|
|
||||||
"-c", util.CephConfigPath,
|
|
||||||
"fs", "ls", "--format=json",
|
|
||||||
)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
util.ErrorLog(ctx, "could not get FSAdmin, can not fetch metadata pool for %s:", vo.FsName, err)
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, fs := range filesystems {
|
fsPoolInfos, err := fsa.ListFileSystems()
|
||||||
if fs.Name == vo.FsName {
|
if err != nil {
|
||||||
return fs.MetadataPool, nil
|
util.ErrorLog(ctx, "could not list filesystems, can not fetch metadata pool for %s:", vo.FsName, err)
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, fspi := range fsPoolInfos {
|
||||||
|
if fspi.Name == vo.FsName {
|
||||||
|
return fspi.MetadataPool, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return "", fmt.Errorf("%w: fsName (%s) not found in Ceph cluster", util.ErrPoolNotFound, vo.FsName)
|
return "", fmt.Errorf("%w: could not find metadata pool for %s", util.ErrPoolNotFound, vo.FsName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vo *volumeOptions) getFsName(ctx context.Context) (string, error) {
|
func (vo *volumeOptions) getFsName(ctx context.Context) (string, error) {
|
||||||
|
@ -220,7 +220,7 @@ func newVolumeOptions(ctx context.Context, requestName string, req *csi.CreateVo
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.MetadataPool, err = opts.getMetadataPool(ctx, cr)
|
opts.MetadataPool, err = opts.getMetadataPool(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -295,7 +295,7 @@ func newVolumeOptionsFromVolID(ctx context.Context, volID string, volOpt, secret
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
volOptions.MetadataPool, err = volOptions.getMetadataPool(ctx, cr)
|
volOptions.MetadataPool, err = volOptions.getMetadataPool(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
@ -503,7 +503,7 @@ func newSnapshotOptionsFromID(ctx context.Context, snapID string, cr *util.Crede
|
|||||||
return &volOptions, nil, &sid, err
|
return &volOptions, nil, &sid, err
|
||||||
}
|
}
|
||||||
|
|
||||||
volOptions.MetadataPool, err = volOptions.getMetadataPool(ctx, cr)
|
volOptions.MetadataPool, err = volOptions.getMetadataPool(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &volOptions, nil, &sid, err
|
return &volOptions, nil, &sid, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user