mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-17 20:00:23 +00:00
rbd: add rbdVolume.open() to get access to an image
Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
parent
3482cb7091
commit
7a18e68a6e
@ -200,6 +200,27 @@ func createImage(ctx context.Context, pOpts *rbdVolume, cr *util.Credentials) er
|
||||
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.
|
||||
// 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) {
|
||||
|
@ -71,7 +71,13 @@ func (cc *ClusterConnection) GetIoctx(pool string) (*rados.IOContext, error) {
|
||||
|
||||
ioctx, err := cc.conn.OpenIOContext(pool)
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user