Commit Graph

111 Commits

Author SHA1 Message Date
John Mulligan 9841283344 rbd: add DiffIterate wrapper for rbd_diff_iterate2
The DiffIterate call accepts a data structure argument containing the
parameters of the image to "diff" and a callback function. This callback
is called in the C code, making use of the recently added callbacks
helper.

The callback itself is called with the offset and length of the
differing area in the image as well as a data parameter so that
a common function can distinguish or update different data for
different calls if needed (compare to a void* in C).

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-03-04 08:10:48 -05:00
Niels de Vos d0943906f7 rbd: add minimal support for listing watchers on an RBD image
Checking if there are other clients interested in changes to an RBD
image is important for certain actions. For example, the Ceph-CSI
project would not want to remove an image in case it is still mounted
somewhere.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-02-26 13:04:25 -05:00
Niels de Vos a65e39ca3d rbd/features: add test for FeatureSet
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-02-24 16:28:03 -05:00
Niels de Vos d6a88f65b7 rbd/features: add FeatureSet for mapping features between bits and names
Applications will mostly want to show names of features to their users,
and not just a few bits. With the FeatureSet functions it becomes simple
for applications to map the name of a feature to bits, and the other way
around

Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-02-24 16:28:03 -05:00
Niels de Vos e671d63892 rbd: add support for RBD_FEATURE_MIGRATING in Nautilus
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-02-24 16:28:03 -05:00
Niels de Vos 368ed4d838 rbd: add support for RBD_FEATURE_OPERATIONS in Mimic
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-02-24 16:28:03 -05:00
Niels de Vos 897c4b8683 rbd/features: add test for Image.UpdateFeatures
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-02-24 16:28:03 -05:00
Niels de Vos 6284986e01 rbd/features: add Image.UpdateFeatures()
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-02-24 16:28:03 -05:00
Niels de Vos 20031cf70f rbd/features: add test for Image.GetFeatures()
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-02-24 16:28:03 -05:00
Niels de Vos 8b58ab92c4 rbd: move features to its own file
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>
2020-02-24 16:28:03 -05:00
Sven Anderson d2e8f936b2 rbd: fix some tests that ignore error results.
Signed-off-by: Sven Anderson <sven@redhat.com>
2020-02-21 13:23:47 -05:00
Niels de Vos 80dc7c279b rbd: replace deprecated rbd_list_children() with rbd_list_children3()
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-02-12 13:48:21 -05:00
Niels de Vos 92fc7ac0bf rbd: replace deprecated rbd_get_parent_info() with rbd_get_parent()
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-02-12 13:48:21 -05:00
Niels de Vos efe2f6b97c rbd: replace deprecated rbd_list() with rbd_list2()
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-02-12 13:48:21 -05:00
John Mulligan c662d6fb2e rbd: add CloneImage as a wrapper for rbd_clone3 func
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>
2020-02-12 14:59:47 +01:00
John Mulligan f72828c5b2 rbd: add OpenImageById and OpenImageByIdReadOnly functions
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>
2020-02-11 19:54:58 +01:00
John Mulligan a1f2aefcf9 rbd: add GetId wrapper for rbd_get_id function
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>
2020-02-11 19:54:58 +01:00
John Mulligan dd041586ba rbd: rename error handling helper func to make it private
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>
2020-02-11 10:01:25 +01:00
John Mulligan f1f46a95bf rbd: replace most uses of Create in rbd test suite
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>
2020-01-31 14:32:38 -05:00
John Mulligan bd0b8d5678 rdb: disentangle and update TestImageCopy function
Update the TestImageCopy function to establish clear subsections and use
the new CreateImage and OpenImage functions.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-31 14:32:38 -05:00
John Mulligan 4691e0cb4c rbd: update TestReadAt to use new approach for create & open
Update the TestReadAt function to use the new CreateImage and OpenImage
functions.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-31 14:32:38 -05:00
John Mulligan 1842bd74e6 rbd: in TestRemoveImage ensure options are destroyed
The resources of the rbd image options must be cleaned up or we leak.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-31 14:32:38 -05:00
John Mulligan fc29c7f30a rbd: replace repeated "magic" literal values with vars
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>
2020-01-31 14:32:38 -05:00
John Mulligan 2a74b02c2b rbd: create a standalone RemoveImage function
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>
2020-01-31 14:32:38 -05:00
John Mulligan 635ca3cdb2 rbd: rename Create4 to CreateImage
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>
2020-01-31 14:32:38 -05:00
John Mulligan 13028061e7 rbd: update tests to use new open image functions
Replace uses of the deprecated img.Open(...) pattern with the new open
image functions where applicable.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-31 14:32:38 -05:00
John Mulligan 0239a8469d rbd: update test case for "old" deprecated open
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>
2020-01-31 14:32:38 -05:00
John Mulligan 674d0e4041 rbd: reimplement Image Open function in terms of simpler functions
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-31 14:32:38 -05:00
John Mulligan 20a458a614 rbd: add new more idomatic functions for opening rbd images
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>
2020-01-31 14:32:38 -05:00
Niels de Vos 030eaaa548 rbd/tests: check for io.EOF while testing Read()
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-01-23 08:05:34 +01:00
Niels de Vos 522182cbc3 rbd: Read() should return io.EOF on short reads
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>
2020-01-23 08:05:34 +01:00
Niels de Vos f170634d82 rbd/tests: add special "read 0 bytes" case
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-01-22 16:48:18 +01:00
Niels de Vos a0fcd9202c rbd/tests: add WriteAt() and ReadAt() tests
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-01-22 16:48:18 +01:00
Niels de Vos 508f808017 rbd: WriteAt() should return io.EOF on short reads
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>
2020-01-22 16:48:18 +01:00
Niels de Vos c412600bfd rbd/options: move tests to "rbd" package
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-01-22 10:15:28 +01:00
Niels de Vos a74d34ec0d rbd/options: increase test coverage
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-01-22 10:15:28 +01:00
Niels de Vos f0bfebcac5 rbd/tests: force librbd errors by passing a closed image
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>
2020-01-22 09:31:58 +01:00
Niels de Vos 55108ab4ea rbd: improve doc comments for RbdImageOptions functions
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-01-21 18:51:36 -05:00
John Mulligan 66acf226dc rbd: improve doc comment style for locking functions
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-21 17:21:10 +01:00
John Mulligan 0e3b60b14d rbd: improve doc comment style for ListChildren
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-21 17:21:10 +01:00
John Mulligan f7cfbac80c rbd: improve doc comment style for flatten
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-21 17:21:10 +01:00
John Mulligan 8253568174 rbd: improve doc comment style for copy functions
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-21 17:21:10 +01:00
John Mulligan f671a8f8e5 rbd: improve doc comment style for various image status calls
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-21 17:21:10 +01:00
John Mulligan 98d1543070 rbd: improve doc comment style for resize
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-21 17:21:10 +01:00
John Mulligan 317feb322a rbd: improve doc comment style for close
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-21 17:21:10 +01:00
John Mulligan e63f863edb rbd: improve doc comment style for remove & rename
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-21 17:21:10 +01:00
John Mulligan 7c4bd22ee2 rbd: improve doc comment style for GetImage
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-21 17:21:10 +01:00
John Mulligan f8cbe766a3 rbd: improve doc comment style for clone
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-21 17:21:10 +01:00
John Mulligan b7ea6aafaf rbd: remove reference to non-implemented api function
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-21 17:21:10 +01:00
John Mulligan cde998bb71 rbd: improve doc comment style for various rbd functions
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-21 17:21:10 +01:00