Commit Graph

297 Commits

Author SHA1 Message Date
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
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 dbfc54d61e rbd: RbdFeature* constants should be uint64
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>
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
John Mulligan a2d1c64180 rbd: separate standard lib imports from pkg imports
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>
2019-12-16 10:03:58 +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
John Mulligan dcfe969b09 rbd: use correct style for package doc comment
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2019-12-12 11:34:51 -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 c06593eef7 rbd: add support for RbdImageOptions
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>
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
zhangyue de3bd20fe3 bugfix: use GetError instead of RDBError to return
Signed-off-by: zhangyue <zy675793960@yeah.net>
2019-12-11 08:44:00 -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
Sven Anderson 472f6dd5bb Tests: avoid segmentation faults in tests
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>
2019-12-06 11:12:34 -05:00
Daniel Swarbrick 951118e855
Drop unnecessary typecasts
Signed-off-by: Daniel Swarbrick <daniel.swarbrick@gmail.com>
2018-09-18 11:12:32 +02:00
Daniel Swarbrick 3023eb281d
Go style cleanups
- Use C errno constants in place of hardcoded ints
- Use type inference where possible (especially C.CString
- Don't explicitly specify zero values where value would be default anway
- Rewrap some unnecessarily wrapped short lines
- Use if/else one-liners where value is not needed afterwards

Signed-off-by: Daniel Swarbrick <daniel.swarbrick@gmail.com>
2018-09-18 11:03:41 +02:00
Noah Watkins 208695a8c1 fmt: apply gofmt updates
Signed-off-by: Noah Watkins <nwatkins@redhat.com>
2018-09-17 15:57:31 -07:00
Daniel Swarbrick bdc1c100fe
Force trash remove to override deferment time
Signed-off-by: Daniel Swarbrick <daniel.swarbrick@gmail.com>
2018-09-17 23:33:23 +02:00
Daniel Swarbrick 837181cb94
Add unit test for rbd_trash functionality
Signed-off-by: Daniel Swarbrick <daniel.swarbrick@gmail.com>
2018-09-17 23:07:18 +02:00
Daniel Swarbrick 4a88b5da12
Implement wrappers around rbd_trash_* functions
Signed-off-by: Daniel Swarbrick <daniel.swarbrick@gmail.com>
2018-09-17 20:46:23 +02:00
Daniel Swarbrick 9d12f2ecd1
Merge branch 'master' into feature-consts 2018-09-14 23:53:47 +02:00
Daniel Swarbrick 1623e77d20
Wrap feature macros from rbd/features.h 2018-09-14 23:52:24 +02:00
Daniel Swarbrick 3a8c38ca41 Add RBD feature flag sets as per Python rbd module 2018-09-14 16:59:08 +02:00
Daniel Swarbrick 340e124452 Convert RBD feature flags to constants with iota 2018-09-14 16:38:01 +02:00
Daniel Swarbrick df4109f4b7 Check that parent image has been opened before attempting snapshot operations 2018-09-14 16:02:11 +02:00
Vicente Cheng d6ed102905 rbd: add test cases about create image for rbd_create, rbd_create2, rbd_create3
Signed-off-by: Vicente Cheng <freeze.bilsted@gmail.com>
2016-12-23 00:24:13 +08:00
Vicente Cheng 19439f3958 rbd: the length of args on create_v3 should be 3 instead of 2
Signed-off-by: Vicente Cheng <freeze.bilsted@gmail.com>
2016-12-20 19:24:31 +08:00
Noah Watkins 1cbeb759e2 Merge pull request #22 from david-z/wip-fix-list-lockers-crash
Fix rbd list lockers crashing
2016-05-20 07:34:18 -07:00
Noah Watkins 62e94854a4 Merge pull request #19 from abligh/fix-read-at-write-at-race
Replace ReadAt and WriteAt with thread-safe versions
2016-05-20 07:34:10 -07:00
Zhi Zhang b68bd88243 Fix rbd list lockers crashing
Signed-off-by: Zhi Zhang <zhangz.david@outlook.com>
2016-05-20 17:26:29 +08:00
Alex Bligh 38c3c12b50 Replace ReadAt and WriteAt with thread-safe versions
ReadAt and WriteAt should not rely on image.offset as this
prevents the from working in a thread-safe manner.

Signed-off-by: Alex Bligh <alex@alex.org.uk>
2016-04-29 14:36:01 +01:00
Ryan Roemmich 777d9c72ab continue after -ERANGE in retval of rbd_list_children. fix out of range on zero children 2016-04-05 10:23:09 -06:00
Crazykev ee740834a2 add param 'order' to Create() and Image.Clone(), and upgrade ci ceph version to hammer
Signed-off-by: Crazykev <crazykev@zju.edu.cn>
2016-03-03 21:59:09 -05:00
Noah Watkins 3f52ea219a repo: update new repo path
noahdesu -> ceph

Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
2015-08-31 07:34:42 -07:00
Ye Yin 5c2d42ef5a Change return new error for rados and rbd
Signed-off-by: Ye Yin <eyniy@qq.com>
2015-07-24 11:34:18 +08:00
Ye Yin 193dbacdb0 Convert some C error code to Go code, for convenient Golang code to handle error.
Define some Rbd constant variables, to pass to librbd API.
Add test unit for RbdErrorNotFound

Signed-off-by: Ye Yin <eyniy@qq.com>
2015-07-23 15:33:34 +08:00
Ye Yin 80e3e9ea7f Add rbd_get_parent_info
Signed-off-by: Ye Yin <eyniy@qq.com>
2015-07-20 11:34:47 +08:00
Kai Storbeck 0c6bdf8d59 run gofmt on all sources 2015-02-11 22:21:05 +01:00
Noah Watkins 0d62c1455a rbd: remove buggy aio interface
The AIO interface is not thread safe. There is an example of how to use
non-Go threads to make callback into Go found in the zookeepr api go
bindings.

Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
2015-02-09 10:54:19 -08:00
Sylvain Baubeau edd909006b rbd: add tests for read/write and snapshots 2015-01-15 15:19:20 +01:00
Sylvain Baubeau 5671536b12 rbd: clean images and pools in tests 2015-01-15 15:18:18 +01:00
Sylvain Baubeau 75e9c455a6 rbd: fix error handling for write, seek and flush 2015-01-15 15:15:31 +01:00
Sylvain Baubeau 921a14b17f rbd: fix calls to wrong C functions 2015-01-15 15:13:53 +01:00
Noah Watkins 6fb5e09394 rbd: fix test
Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
2015-01-14 17:36:56 -08:00
Noah Watkins 9a1b29d02e Merge remote-tracking branch 'lb/newrbd'
Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
2015-01-14 17:32:51 -08:00
Noah Watkins f5bfcec122 fix go-rados -> go-ceph renames
Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
2015-01-14 17:30:46 -08:00
Sylvain Baubeau e00f9bf1a8 lib: add full support for RADOS block devices 2015-01-15 00:44:26 +01:00
Noah Watkins d58cbadae5 doc: update doc layouts
Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
2015-01-13 07:27:06 -08:00
Noah Watkins 44c15bf439 rbd: add rbd package
Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
2015-01-12 22:15:32 -08:00