By splitting up the features from the main rbd.go file, it becomes
easier to support new features added by newer versions of Ceph.
This also drops the Rbd-prefix from the constants, and adds backwards
compatible references.
Signed-off-by: Niels de Vos <ndevos@redhat.com>
Add a new CloneImage that makes use of rbd_clone3 and thus behaves like
the new CreateImage function.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Add OpenImageById and OpenImageByIdReadOnly that wrap rbd_open_by_id and
rbd_open_by_id_read_only respectively.
The added test case can not currently test trivial error conditions due
to a known bug in ceph, these tests are skipped for meanwhile.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Add a GetId function to the Image type that will fetch the id of the rdb
image. Comes with a test case.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Similar to recent changes for rados (df46476e) there is no good reason
for the errorno to go-style error function to be exported from the
package. Decapitalize it.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Replace most uses of Create() in the rbd test suite with a wrapper
around CreateImage named quickCreate. quickCreate retains most of
the argument signature of Create for easier refactoring of the tests
over time. New uses of quickCreate should not be added to the suite if
you can help it.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Update the TestImageCopy function to establish clear subsections and use
the new CreateImage and OpenImage functions.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Throughout rbd_test.go the values of 1<<22 and 22 are repeated when
created rbd images. For the common cases, replace these with variables.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
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>
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>
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>
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>
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>
Previously, the tests were shelling out to run 'uuidgen' which
is not particularly efficient and a bit ugly. Switch this test
to use the same uuid library already in use by the rados test code.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
This change replaces a couple of functions from the "assert" package
with the corresponding functions from the "require", where the
following code relies on a non-nil object.
Signed-off-by: Sven Anderson <sven@redhat.com>