Currently, the code only provides a .Remove function on the Image type.
But this is unnecessary as the underlying api only requires an io
context and name. Make a function that matches the underlying api
better.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
In the future, CreateImage should be the canonical way one creates an
rbd image. Like the underlying ceph apis CreateImage does not return an
Image, only an error code. Open image handles should be acquired through
the OpenImage functions.
Because Create4 was fairly recently added to library there should not be
consumers in the wild. Thus we don't retain the current version for
backwards compatibility.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Replace uses of the deprecated img.Open(...) pattern with the new open
image functions where applicable.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Rename test case to mark the "old" deprecated open func as such.
This also adds a missing bit of coverage to the test.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Create new OpenImage & OpenImageReadOnly functions to replace the use of
Open() on image types. This function more closely matches the underlying
of the librbd function calls.
The third argument to the functions is a snapshot name but we also
create a new constant to clearly indicate that an image should be opened
w/o a snapshot. Internally, this also ensures that a null string is
passed to the C api.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
The case of a short read is not detected correctly. This causes Read()
to not return io.EOF where it is expected.
By comparing 'len(data)' instead of unassigned 'n' (set to 0), the
number of bytes that have been read can be compared to the number of
bytes that were requested.
Signed-off-by: Niels de Vos <ndevos@redhat.com>
The case of a short read is not detected correctly. This causes ReadAt()
to not return io.EOF where it is expected.
By comparing 'len(data)' instead of unassigned 'n' (set to 0), the
number of bytes that have been read can be compared to the number of
bytes that were requested.
Signed-off-by: Niels de Vos <ndevos@redhat.com>
In order to get a higher test coverage for rbd/rbd.go, there is a need
to trigger errors for the librbd functions. This makes it possible to
test the error path. The new TestClosedImage() function tricks
RbdImage.validate() into accepting an image that is closed, but still
references the closed image.
librbd is expected to return an error when the image is closed. However,
passing a closed image does not result in stable behavior. Sometimes
librbd causes a panic, at other times there will be a hang and the test
will time-out.
The TestClosedImage() function is disabled, it will skip all testing but
remains available so that it could be enabled in the future.
Signed-off-by: Niels de Vos <ndevos@redhat.com>
In the rbd tests the setup of the rados connection was essentially copy
and paste with very little proper error checking.
This change adds a common setup function that checks all error
conditions as well as prevents the tests from blocking forever if
something is wrong with the ability of the tests to connect.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
The arguments passed to Copy() would normally be pointers, just like it
is done with other similar functions. This never worked correctly, as
the arguments were not validated correctly (not recognized) and the
error "Must specify either destination pool or destination image" always
got returned.
Modifying Image.Copy() into something usable would result in a complete
rewrite. Instead of a single Image.Copy() function that tries to cover
rbd_copy() and rbd_copy2(), provide Image.Copy() and Image.Copy2() so
that the API matches the librbd.so interface.
Signed-off-by: Niels de Vos <ndevos@redhat.com>
The return value of rbd_discard() is the number of bytes that have been
discarded, or in case of an error, a negative errno value.
It seems Image.Discard() never can have worked as intended, unless the
error was disregarded. Just like Image.Write(), Image.Discard() should
return a tuple of the number of bytes discarded and an error.
Fixes: ceph/go-ceph#123
Signed-off-by: Niels de Vos <ndevos@redhat.com>
rbd_get_features() returns a uint64_t with the features that are set in
the image. That means combining (with logical OR) features should result
in a uint64 too. Marking all features explicitly uint64 makes it easier
and cleaner to set/test features.
Signed-off-by: Niels de Vos <ndevos@redhat.com>
Keeping the _test.go code in the same package allows for the testing
of private functions. AFAWK it is more conventional as well.
See-also: ceph/go-ceph#135
Signed-off-by: Niels de Vos <ndevos@redhat.com>
We recently created errors in the rbd that match the golang convention
but left aliases for external code. Switch the test code to use the
newer more standard form instead of the "aliases."
Signed-off-by: John Mulligan <jmulligan@redhat.com>
A recent PR added new error values that were similar to the existing
naming convention but were not the normal go convention. Change all the
errors to match typical convention but leave the older names as aliases
such that older code will continue to work (for now).
Signed-off-by: John Mulligan <jmulligan@redhat.com>
By convention many projects are separating the golang stdlib imports
from other imports. Do that as well for rbd.go.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Translate the return value (errno) from the C rbd_*() functions into the
standardized strerror() error message.
Signed-off-by: Niels de Vos <ndevos@redhat.com>
Make it possible to easily validate the *Image and *Snapshot objects
before using them. This makes the use of go-ceph for RBD functions more
stable, and it is less likely that incorrect use causes Go panics.
Signed-off-by: Niels de Vos <ndevos@redhat.com>
This allows to set additional options while creating RBD images.
Ceph-CSI will initially consume this to configure an optionally
different pool for data.
Signed-off-by: Niels de Vos <ndevos@redhat.com>
There are several RbdImageOptions that can be used to configure features
of an RBD image while creating, cloning, migrating and copying. A
follow-up patch will add Create4() where the RbdImageOptions can be
used.
Signed-off-by: Niels de Vos <ndevos@redhat.com>
The C library offers rbd_create2() and rbd_create3() and does not try to
cover all options with rbd_create(). For users that are familiar with
the C API, the Create2() and Create3() functions have been added.
The existing Create() API still handles the complete set of
rbd_create*() functions, so backwards compatibility is covered.
Signed-off-by: Niels de Vos <ndevos@redhat.com>