rbd: add rbdVolume.open() to get access to an image

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2020-05-08 16:10:18 +02:00 committed by mergify[bot]
parent 3482cb7091
commit 7a18e68a6e
2 changed files with 28 additions and 1 deletions

View File

@ -200,6 +200,27 @@ func createImage(ctx context.Context, pOpts *rbdVolume, cr *util.Credentials) er
return nil return nil
} }
// open the rbdVolume after it has been connected.
// ErrPoolNotFound or ErrImageNotFound are returned in case the pool or image
// can not be found, other errors will contain more details about other issues
// (permission denied, ...) and are expected to relate to configuration issues.
func (rv *rbdVolume) open() (*librbd.Image, error) {
ioctx, err := rv.conn.GetIoctx(rv.Pool)
if err != nil {
// GetIoctx() can return util.ErrPoolNotFound
return nil, err
}
image, err := librbd.OpenImage(ioctx, rv.RbdImageName, librbd.NoSnapshot)
if err != nil {
if err == librbd.ErrNotFound {
err = ErrImageNotFound{rv.RbdImageName, err}
}
return nil, err
}
return image, nil
}
// rbdStatus checks if there is watcher on the image. // rbdStatus checks if there is watcher on the image.
// It returns true if there is a watcher on the image, otherwise returns false. // It returns true if there is a watcher on the image, otherwise returns false.
func rbdStatus(ctx context.Context, pOpts *rbdVolume, cr *util.Credentials) (bool, string, error) { func rbdStatus(ctx context.Context, pOpts *rbdVolume, cr *util.Credentials) (bool, string, error) {

View File

@ -71,7 +71,13 @@ func (cc *ClusterConnection) GetIoctx(pool string) (*rados.IOContext, error) {
ioctx, err := cc.conn.OpenIOContext(pool) ioctx, err := cc.conn.OpenIOContext(pool)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to open IOContext for pool %s", pool) // ErrNotFound indicates the Pool was not found
if err == rados.ErrNotFound {
err = ErrPoolNotFound{pool, err}
} else {
err = errors.Wrapf(err, "failed to open IOContext for pool %s", pool)
}
return nil, err
} }
return ioctx, nil return ioctx, nil