This is a complex test as it requires the pool and an image before it
will return any (non empty) data.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
These are the functions that let one administrate the snapshot schedules
for mirrored pools and images.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Adds types to work with the ceph cluster (the admin type) and a type
to work with the "level spec" - which is unfortunately not well
described in the ceph docs, but I think I worked it out well enough
by reading the ceph sources.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
This package will be used for issuing json commands to the mgr (or
mons, etc) that perform background tasks to administrate rbd pools,
images, etc.
This commit just adds a doc.go as a stub.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
* Add SetMirrorSiteName implementing rbd_mirror_site_name_set
* Add GetMirrorSiteName implementing rbd_mirror_site_name_get
These functions are used to set the name of the site (for an entire
cluster) for rbd mirroring purposes. It's a bit strange that it's
part of rdb and not rados, but such is life.
Tests included.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
The MirrorImageStatusSummary returns a map of image mirroring states to
the number of images in those states or an error.
Tests of both the basic conditions and actual mirrored images are added.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
This change uses slices on top of C allocated array memory in order
to have a simple (no pointer arithmetic) and safe (boundary-checked)
access to its elements.
Signed-off-by: Sven Anderson <sven@redhat.com>
Unless these apis are deprecated in the (far?) future it is safer to say
"not nautilus" rather than explicitly tag all current and future ceph
release codenames.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
With the infrastructure for running two ceph clusters now available,
we add tests to ensure the functionality of GetGlobalMirrorStatus in
the more typical case, when one or more mirroring clusters exist,
Signed-off-by: John Mulligan <jmulligan@redhat.com>
This function can be used to connect to a non-default ceph cluster,
in a simple, convenient way similar to the function we have for
connecting to the default cluster.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
This function is used to "manually" trigger a snapshot for snapshot
based mirroring. It is needed as a pre-req to test actual cross-cluster
mirroring and the full functionality of GetGlobalMirrorStatus.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
This function is added, along with required return types and some helper
functions, to support fetching the global mirroring status component
that makes up a major part of `rbd mirror image status` command's
output.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
* Add GroupSnapRollbackWithProgress implementing rbd_group_snap_rollback_with_progress
This has supporting code basically the same as our other existing
callback functions.
Tests too.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
* Add GroupImageAdd implementing rbd_group_image_add
* Add GroupImageRemove implementing rbd_group_image_remove
* Add GroupImageRemoveByID implementing rbd_group_image_remove_by_id
These functions allow managing the images that are part of a group.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
As per go-ceph issue #427, and a discussion in #399 this change and
test ensure that the cephIoctx helper function, that extracts the
C.rados_ioctx_t from a Go rados.IOContext, never returns a nil/null
C type.
As these are always "programming errors" panicking is reasonable
behavior for this case.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Using WriteSame() to implement a zerofill function is less straight
forward than expected. `rbd_discard_on_zeroed_write_same` is a Ceph
option than affects the behaviour of WriteSame(). By default the option
is enabled, causing WriteSame() to call discard instead of writing
zeros.
Signed-off-by: Niels de Vos <ndevos@redhat.com>
RBD was misspelled as RDB. While I was there I made the comments
for both constants more consistently worded.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Add functions:
* SetMirrorMode implementing rbd_mirror_mode_set
* GetMirrorMode implementing rbd_mirror_mode_get
* MirrorEnable implementing rbd_mirror_image_enable2
* MirrorDisable implementing rbd_mirror_image_disable
* MirrorPromote implementing rbd_mirror_image_promote
* MirrorDemote implementing rbd_mirror_image_demote
* MirrorResync implementing rbd_mirror_image_resync
* MirrorInstanceId implementing rbd_mirror_image_get_instance_id
For now, these mirroring related functions are only supported on octopus
builds. Right now the demand is for snapshot based mirroring, which is
new in octopus. We can always relax this in the future and add the
necessary support for nautilus, for journaling only based mirroring.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Add GroupCreate implementing rbd_group_create
Add GroupRemove implementing rbd_group_remove
Add GroupRename implementing rbd_group_rename
Naming was <noun><verb> to better match other functions in rbd
like NamespaceCreate, etc. even though I don't prefer that
ordering ;-).
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Ceph issue https://tracker.ceph.com/issues/43178 has been fixed for
a while with backports. No reason not to enable these test cases now.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
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>
Although it seems to be stable with the current Go versions,
unsafe.Pointers that are created by applying arithmetic on nil
pointers are explicitly not allowed[1], and could potentially lead to
panics by the garbage collector. To be on the safe side, this change
goes back to minimal inline wrappers for the callback registrations,
which should be zero-cost. For the callbacks themselves fortunately
no wrappers are required, because CGo happily converts void* to
uintptr arguments. The potentially problematic VoidPtr helper is
removed again.
[1] https://golang.org/pkg/unsafe/#Pointer
Signed-off-by: Sven Anderson <sven@redhat.com>
The function is named ListMetadata but returns a map of all
the metadata assigned to the rbd image. It is named ListMetadata to
match the C librbd api call.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
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>
As rbd.go is very long, and the get-/set-/remove- metadata functions in
rbd.go make a nice logical unit, move them to a new metadata.go file.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
GetParentInfo() currently requires the caller to specify the
string length for various attributes it returns. If the
specified string length is less than required, it can return
ERANGE error. Replacing it with a new function which avoids
this.
Signed-off-by: Mudit Agarwal <muagarwa@redhat.com>
The sparsify function can be used to make an image sparse by replacing
runs of zeros with holes. This change adds a wrapper for the basic
rbd_sparsify function and accompanying tests.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Since the index of the registered callbacks is basically only used as
void*/unsafe.Pointer, it makes more sense and code simpler, if
the index type is uintptr instead of a simple int.
Signed-off-by: Sven Anderson <sven@redhat.com>
This patch changes the name to the as-agreed-upon naming from a call.
I forgot to fix this in the original patches before merging things.
Oops.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Previously, the code that set up the callbacks was doing a pretty
direct translation of go-function to c-function. It turns out this
is not needed due to the way we set up the "dynamic" go callbacks
via an integer based callback "registry". Instead, we can stay within
the C layer entirely for the C callback, passing it only the index
value and then return to the go layer through a static C function
that only needs the index value.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Corresponding fields for Parent_pool and Parent_name have been deprecated from
ceph's rbd_image_info_t stuct, removing the same from go-ceph's ImageInfo struct.
Signed-off-by: Mudit Agarwal <muagarwa@redhat.com>
Added pool stat options constants.
Also implemented GetAllPoolStats() function to introduce
the functionality of rbd_pool_stats_option_add_uint64() and rbd_pool_stats_get()
Signed-off-by: Mudit Agarwal <muagarwa@redhat.com>
Added wrappers for rbd_pool_stats_create() and rbd_pool_stats_destroy() functions.
Right now, keeping these unexported.
Signed-off-by: Mudit Agarwal <muagarwa@redhat.com>
RBD_IMAGE_OPTION_CLONE_FORMAT was added in Ceph Mimic but fix for issue #295 added
it only for Ceph Nautilus, moving it to rbd/options_mimic.go
Signed-off-by: Mudit Agarwal <muagarwa@redhat.com>
Added a wrapper for function rbd_snap_get_trash_namespace() which
returns the original name of the snapshot which was moved to Trash.
Signed-off-by: Mudit Agarwal <muagarwa@redhat.com>
Added few constants used for determining snapshot namespace.
Added wrapper for function rbd_snap_get_namespace_type() which returns namespace type for a given snapshot.
Signed-off-by: Mudit Agarwal <muagarwa@redhat.com>
Add UpdateWatch function implementing rbd_update_watch.
Add Unwatch function implementing rbd_update_unwatch.
Add a higher level Watch type to encapsulate watching
the image and the watch handle.
Add basic tests to validate the callback behavior.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
In order to avoid external dependencies on implementation details,
this change replaces RBDError with the unexported rbdError. In case
some application really needs access to the integer value, it can use
the pattern
var errno interface{ Errno() int }
if errors.As(err, errno) { ... errno.Errno() ... }
Signed-off-by: Sven Anderson <sven@redhat.com>
Added wrapper for rbd_namespace_list() function which returns the names of all the namespaces
present for a given IOContext.
Signed-off-by: Mudit Agarwal muagarwa@redhat.com
rbd_namespace_create() function creates namespace for a given iocontext.
rbd_namespace_exists() function checks whether the given namespace exists or not.
rbd_namespace_remove() function removes the given namespace.
Signed-off-by: Mudit Agarwal <muagarwa@redhat.com>
Add wrapper for rbd_pool_metadata_remove() function which removes pool
metadata associated with a given key.
Signed-off-by: Mudit Agarwal <muagarwa@redhat.com>
Add wrapper for rbd_pool_metadata_set() function which sets pool metadata
associated with the given key.
Signed-off-by: Mudit Agarwal <muagarwa@redhat.com>
Add wrapper for rbd_pool_metadata_get() function which returns pool metadata
associated with the given key.
Signed-off-by: Mudit Agarwal <muagarwa@redhat.com>
Previously, the types were named RbdImageOptions and RbdImageOption.
Now they are named ImageOptions and ImageOption.
Type aliases have been added to prevent existing code from
breaking. As these types were new in v0.2, I suspect we can drop
the aliases post-v0.3.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Image option constants are now named ImageOptionX, without an Rbd
prefix. Aliases to the old names are provided and doc comments for both.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
A previous change improved our use of pointers such that go vet no
longer had an issue with these lines but if we ever need to change the
interaction between rbd and rados like that again we can now rely on a
single call site `cephIoctx` that will return our ceph/c type given the
public Go-language level type from the rados pkg.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
The void * is (ab)used in C for passing arbitrary data to the callback,
which in our case is a integer index. However, Go tools can not tell
this is OK and throws an error running go vet. Change the wrapper
function to take a uintptr_t and cast that to void* only in the
(unchecked) C layer.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Moving the errutil pkg to "internal/errutil" makes errutil private-like
and accessible to only other go-ceph packages. The functions it provided
were always meant to be used only by go-ceph, this just makes it more
official. This is a breaking change but it was only available to
outside users for 1 release and it is somewhat doubtful users outside
of go-ceph would have reached for these functions.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
No functionality change. Move various snapshot related functions to
their own file. This helps logically group these related funcs in one
place.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
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>
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>
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>
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>