Commit Graph

66 Commits

Author SHA1 Message Date
Niels de Vos 0afcf98b34 Add rbd_writesame()
In order to provide the ability to do thick provisioning of RBD images,
Image.WriteSame() can be used. The `rbd` commandline utility calls the
rbd_writesame() function when an image is created with the
`--thick-provision` option.

See-also: ceph/ceph-csi#1675
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-11-12 12:50:03 +00:00
John Mulligan 6bc6c7c3b1 rbd: move TestImageMetadata function to a new test file
Like the metadata functions were recently moved to a separate file,
move TestImageMetadata to a matching metadata_test.go file.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-11-04 14:01:51 +00:00
Niels de Vos ec822aa3a9 rbd: add error checking in CreateImage()
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-06-11 10:42:57 -04:00
Niels de Vos 3fc893bc0f rbd: add error checking in RemoveImage()
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-06-11 10:42:57 -04:00
Niels de Vos 9e7a1c444f rbd: add error checking in OpenImage*() functions
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-06-11 10:42:57 -04:00
Sven Anderson 217e502afa rbd: add better error when attempting to remove opened images
Signed-off-by: Sven Anderson <sven@redhat.com>
2020-05-28 08:49:35 -04:00
John Mulligan 0faccb56e8 rbd: check that encode calls dont return error
Don't ignore the error returned by json encode func call.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-04-09 13:11:05 -04:00
John Mulligan 054ae8ddff rbd: consolidate error types & values in an errors.go file
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-04-06 17:10:09 -04:00
John Mulligan 51827ead4e rbd: convert uses of RbdImageOptionX to ImageOptionX
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-03-23 10:09:25 -04:00
John Mulligan 4fc730ad39 rbd: move snapshot test funcs to a new file
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-03-10 07:47:59 +01: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
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 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 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 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
John Mulligan 3ec0541977 rbd: replace tests conn setup boilerplate with func
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>
2020-01-20 16:52:45 +01:00
Anthony ARNAUD 777e79c046 rbd: add metadata functions on image to get, set, remove metadata
Signed-off-by: Anthony ARNAUD <github@anthony-arnaud.fr>
2019-12-16 18:10:18 +01:00
Niels de Vos 2b2fcc121d rbd: fix broken Image.Copy() and add an exhaustive test for it
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>
2019-12-16 11:27:18 -05:00
John Mulligan 811f851c99 rbd: convert to common errno handling
Use the errno handling function originally created for rbd and
then made common in rbd package.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2019-12-16 16:59:25 +01:00
Niels de Vos f15486e0a2 test/rbd: check for expected errors with Image.Clone()
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2019-12-16 10:12:51 -05:00
Niels de Vos f611d4a986 test/rbd: check for expected errors with Image.Open()
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2019-12-16 10:12:51 -05:00
Niels de Vos 22c15e5a37 rbd: fix problems with Image.Discard()
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>
2019-12-16 10:12:51 -05:00
Niels de Vos 9381485fac test/rbd: Add tests for Image.Seek()
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2019-12-16 10:12:51 -05:00
Niels de Vos 2faaf93287 test/rbd: add test for opening an Image read-only
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2019-12-16 10:12:51 -05:00
Niels de Vos 30fdf64bdc test/rbd: add test for Image.Resize()
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2019-12-16 10:12:51 -05:00
Niels de Vos a5cc9ff302 test/rbd: add tests for getting image properties
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2019-12-16 10:12:51 -05:00
Niels de Vos 0b8f4eb7e5 test/rbd: add test for Image.Rename()
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2019-12-16 10:12:51 -05:00
Niels de Vos 65d1e9c763 rbd: include rbd_test.go in rbd package
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>
2019-12-16 10:12:51 -05:00
John Mulligan 7c1e4f2ca9 rbd: convert test to use errors with conventional names
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>
2019-12-16 11:32:21 +01:00
John Mulligan 36fc3510d8 rbd: use conventional naming style for errors
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>
2019-12-16 11:32:21 +01:00
Niels de Vos a713db983a rbd: return more useful error messages
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>
2019-12-12 13:56:53 -05:00
Niels de Vos 2d52744470 rbd: improve error checking
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>
2019-12-11 19:47:21 -05:00
Niels de Vos b86563db7e rbd: add Create4() for more advanced RBD Image creation
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>
2019-12-11 13:43:58 -05:00
Niels de Vos 6a17d59988 rbd: split Create() off into Create2() ad Create3() following librbd.h
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>
2019-12-11 09:09:54 -05:00
John Mulligan fa319f99bb rbd: use uuid library, rather than shelling out, in rbd test
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>
2019-12-06 11:23:03 -05:00