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>
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>
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>
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>