Commit Graph

65 Commits

Author SHA1 Message Date
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
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 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 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 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 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
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
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 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 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
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
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
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
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 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 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