Commit Graph

383 Commits

Author SHA1 Message Date
John Mulligan 0c1b895566 cephfs: add doc comments to error type and func
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-02-17 08:22:04 +01:00
John Mulligan dc289754c8 readme: update doc link to pkg.go.dev
The older godoc.org encourages the user to use pkg.go.dev instead.
Change our link to point directly there (and use https).

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-02-13 07:28:33 +01: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
Niels de Vos 58b4237aa9 travis: pass CEPH_VERSION as argument to 'docker build'
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-02-12 13:48:21 -05:00
Niels de Vos 86a3a66849 tests: parameterize Ceph version for container build and build-tags
Pass `CEPH_VERSION=minic` (or 'luminous') on the `make test-docker`
command to select building a container with a different Ceph version and
running the tests in it.

This passes the given CEPH_VERSION on to the `docker build` command as a
--build-arg, which gets used for selecting the Ceph repository during
container build.

It also sets the environment variable CEPH_VERSION, which in turn is
consumed by `entrypoint.sh` to set the `go build -tags ${CEPH_VERSION}`
option that includes/excludes certain *.go files.

See-also: https://golang.org/pkg/go/build/#hdr-Build_Constraints
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-02-12 13:48:21 -05:00
Niels de Vos 7e3a5850f3 README: add requirement for build-tags when using non-current Ceph libraries
In order to selectively exclude/include certain .go files while building
and testing with the standard `go` tools, build-tags can be used.
Because go-ceph aims to support multiple Ceph versions, some functions
might not be available in the C libraries, or have been marked
deprecated in the header files. By selectively excluding/including some
of the .go files, warnings and errors can be prevented.

See-also: https://golang.org/pkg/go/build/#hdr-Build_Constraints
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 ea016c420a makefile: add targets for test binaries
The go test command's -c switch builds the test binary but does not
execute it. It is convenient to do quick compile checks of the libraries
and test code at once without having to bring up the ceph instance in
the test container. This change allows one to run 'make test-bins' or
'make rbd.test' to compile but not run the test & library code.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-02-12 08:35:22 +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 2240c56614 cephfs: update TestCreateMountWithId to check custom id is used
Now that we have mds command function, we can use it to check for the id
we passed to CreateMountWithId appears in the session list.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-02-11 14:01:33 +01:00
John Mulligan 34f1507992 cephfs: add wrapper funcs for ceph_mds_command
Adding a wrapper for ceph_mds_command allows the client to make
queries against the mds server.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-02-11 14:01:33 +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 2f7493bed1 entrypoint: make var references consistently use curly braces
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-02-11 09:22:03 +01:00
John Mulligan ee2c26906e entrypoint: support disabling code coverage
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-02-11 09:22:03 +01:00
John Mulligan b7ea1de2e2 entrypoint: add options to run cpu and mem profiling on tests
Add options --cpuprofile and --memprofile which enables the respective
profile options for the go test command.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-02-11 09:22:03 +01:00
John Mulligan 7d12f0bbcd entrypoint: highlight important commands in script output
Add a small wrapper function 'show' that prints a prefix and the
command that will be run. Helps the reader jump to important parts of
the script output.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-02-11 09:22:03 +01:00
John Mulligan 7790594ee4 entrypoint: fix pausing after test failure
The --pause option for the entrypoint script is useful for interactive
debugging after a test failure, but the script was not pausing if the
test suite failed. Add code to explicitly handle test failures including
pausing.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-02-11 09:22:03 +01:00
John Mulligan 691cd8d99b entrypoint: move pre- and post- test code into functions
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-02-11 09:22:03 +01:00
John Mulligan 3ca24f63c5 entrypoint: move go test setup an invocation into a function
A little refactoring to move the setup of the pkg test calls into a
function to ease future changes.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-02-11 09:22:03 +01:00
John Mulligan 25bd9f0bed entrypoint: wrap main code in a function
As preparation for upcoming changes, move the main code of entrypoint.sh
into functions. Best viewed by ignore whitespace.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-02-11 09:22:03 +01:00
John Mulligan 176e6cc198 rados: fix doc comments for object iter related functions
This is a minor cleanup that only stops the checker from complaining
rather than actually improving the documentation.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-02-11 08:51:07 +01:00
John Mulligan 9efbfd8518 rados: move object iter(ation) related functions into their own file
Create an object_iter.go from the Iter related functions that were
formerly in ioctx.go. This makes ioctx a little less of a giant wall of
code as well as making things easier to work on in the future.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-02-11 08:51:07 +01:00
John Mulligan 970300d25a rados: fix doc comments for omap related functions
This is a minor cleanup that only stops the checker from complaining
rather than actually improving the documentation.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-02-11 08:51:07 +01:00
John Mulligan f29d760894 rados: move omap related functions into their own file
Create an omap.go from the omap functions that were formerly in
ioctx.go. This makes ioctx a little less of a giant wall of code
as well as making things easier to work on in the future.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-02-11 08:51:07 +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
John Mulligan 09813739ed testing: use Go 1.12 from go upstream in ci container
When building the container image for running tests take the older of
the two current releases from Go upstream. We use the older version
in order to make sure we are testing with something supported but maybe
not everyone is on 1.13 yet.
This also enables the use of go modules to ensure we get the proper
versions of dependencies.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-30 07:46:18 +01:00
Niels de Vos 5adb04909d rados: standardize error naming
RadosError-prefixes are not recommended, instead just Err as prefix is
used.

Also, errors are constants, not variables.

For existing users, backwards compatible constants are available. These
will need to be removed in a future go-ceph release.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-01-29 16:51:49 +01:00
Niels de Vos c6b65af9ec rados: add Create() function to create new objects
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-01-29 16:51:49 +01:00
John Mulligan 15a55c9000 cephfs: add a doc.go file documenting the package
The minimal doc.go file matches the style currently used for rados and
rbd.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-28 16:10:39 +01:00
John Mulligan d0cf66be62 errutil: add a package level doc comment
Currently, errutil is a single file package (not counting tests) so we
add a doc comment for the package to the existing file.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-28 16:10:39 +01:00
John Mulligan c433abf787 cephfs: allow creating mount with an id
The ceph api function supports passing a string to identify the
client doing the mount. Expose that aspect of the api with a
new function CreateMountWithId.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-28 08:52:51 +01:00
John Mulligan dfabc3db54 go-ceph: fix typo in doc.go
It's 'rbd' not 'rdb'.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-28 08:38:59 +01:00
John Mulligan 296c551613 cephfs: test creating a cephfs mount from a rados Conn
Verify the cephfs CreateFromRados function.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-27 18:30:10 +01:00
John Mulligan 9929f63b13 cephfs: wrap ceph_create_from_rados function
Support creating a cephfs 'mount' from an existing rados connection
using the ceph_create_from_rados function.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-27 18:30:10 +01:00
John Mulligan 46ed646e03 rados: support fetching the cluster from the Conn
The cephfs function ceph_create_from_rados requires the cluster_t
value, which is current private to the Conn type. Alias the cluster_t
type and allow other pkgs to get it if needed.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-27 18:30:10 +01:00
John Mulligan 7ccc2a2d9b go-ceph: publish library as a go module
Establish a go.mod (and go.sum) file such that this library can be
handled as a Go module. This has the added benefit of now being
useful outside of gopath.
I do not believe we need to release to provide/use module support but
we should possibly start considering creating v0 tags soonish.

See also: https://blog.golang.org/publishing-go-modules

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-27 17:53:38 +01:00
John Mulligan 5cf2b02a6c rados: clean up var lines in rados.go and add doc comments
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-23 08:09:36 -05:00