Commit Graph

105 Commits

Author SHA1 Message Date
John Mulligan b66dcaf565 cephfs admin: add a SubVolumePath function
The SubVolumePath function maps the subvolume to a path from the root
of the cephfs, and works like `ceph fs subvolume getpath ...`.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-09-25 13:39:31 -04:00
John Mulligan c4e1292da1 cephfs admin: add EnumerateVolumes function
The EnumerateVolumes function returns a list of Name & ID pairs,
to identify the file systems in the cluster. The enumeration is based
on `ceph fs dump` like JSON, but for implementation only. The dump
feature itself is not currently exported in a raw form.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-09-24 15:50:51 -04:00
John Mulligan 3afac0b0b8 cephfs admin: add support for running MON commands
Some of the queries we need to make are not mgr commands but (still?)
mon commands. Extend the interface and helper funcs to support issuing
mon commands.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-09-24 15:50:51 -04:00
John Mulligan c362706640 cephfs admin: add "Similar To" doc comments
Removes some old reminder comments.
Adds doc comments with the keyword "Similar To" followed by block quoted
text that shows a cli command the function will behave similarly to.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-08-31 10:38:38 -04:00
John Mulligan 7d18596d9d cephfs admin: use strconv to parse env var content
The environment variable to turn on tracing will now be parsed using
strconv.ParseBool rather than just a quick-n-dirty str compare.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-08-31 10:38:38 -04:00
John Mulligan d327bf4f3e cephfs admin: move volume status to octopus specific files
The volume status command does not appear to be able to return JSON
on nautilus. Disable it on anything other than octopus for now.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-08-31 10:38:38 -04:00
John Mulligan c1ff3a6b18 cephfs admin: in the test setup code, delay a bit to fetch mgr map
When the ceph client code has not yet (asynchronously) gotten the mgr
map, it can return -EACCES when we run the MgrCommand function.  We
before continuing with the test function to get the fsadmin we delay a
bit so that we are more likely to have the mgr map before continuing.
This change also fixes the caching of the fs admin.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-08-31 10:38:38 -04:00
John Mulligan f9e1ec5d2a cephfs admin: disable package on 'luminous' and 'mimic'
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-08-31 10:38:38 -04:00
John Mulligan caac65de71 cephfs admin: add ResizeSubVolume and supporting types
Add a function for resizing a subvolume as well as types needed to
create the JSON command and parse the response JSON. The newSize
argument can be passed a numeric value (as a ByteCount) or the special
constant `Infinite` much like the ceph cli command. This is accomplished
using the interface type `NewSize`.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-08-31 10:38:38 -04:00
John Mulligan a120c62623 cephfs admin: add optional debug tracing to the tests
Allow the environment variable GO_CEPH_TEST_DEBUG_TRACE=yes to enable
tracing of the input & output json from the manager commands. This is
both useful for debugging the tests themselves and demonstrates the use
of something other than rados.Conn meeting the interface required by
FSAdmin.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-08-31 10:38:38 -04:00
John Mulligan 272d34a9dd cephfs admin: parse pools info from volume status func
Add type to parse the pool info from the volume status response.
Use new general response unmarshal function.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-08-31 10:38:38 -04:00
John Mulligan 4e5424dbfb cephfs admin: make a common func for unmarshaling json responses
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-08-31 10:38:38 -04:00
John Mulligan fd10d9b756 cephfs admin: add functions to create, list, & remove subvolumes
Adds functions and tests for:
* CreateSubVolume
* ListSubVolumes
* RemoveSubVolume

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-08-31 10:38:38 -04:00
John Mulligan 5e6eec6a1a cephfs admin: add functions to create, list, & delete subvolumegroups
Adds functions and tests for:
* CreateSubVolumeGroup
* ListSubVolumeGroups
* RemoveSubVolumeGroup

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-08-31 10:38:38 -04:00
John Mulligan 198541cccd cephfs admin: add core functionality and volume functions
Adds the central admin type `FSAdmin` and some helper functions.
Adds basic volume list and info functions.
Adds tests for the volume functions and common fsadmin functions.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-08-31 10:38:38 -04:00
John Mulligan ea1073dc1d cephfs admin: start a package for convenient administration of cephfs
These functions are not part of the cephfs APIs but will be based on the
various command-json features of the 'ceph' command line tool.
This change only adds a doc.go to stub in the package.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-08-31 10:38:38 -04:00
John Mulligan b24fa281df cephfs: clarify the behavior of the EOF case and short read in Preadv
Extend the Preadv/Pwritev test cases by adding assertions for the
behavior of the call in the end-of-file condition, and add another
test case to clarify the behavior in an explicit short-read test.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-08-28 10:07:34 -04:00
John Mulligan f3d14f90b3 cephfs: change the permissions of open files in file_test.go
As pointed out in a review of Pwritev/Preadv functions, someone could
be using the tests as example code and not realize the "wide open"
permissions used in the test. Because it doesn't actually impact the
behavior of the test there's no reason not use use more restricted
permissions.
This change makes the older functions in the file use the restricted
perms too.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-08-28 10:07:34 -04:00
John Mulligan 9c1ed2dfc2 cephfs: implement Preadv and Pwritev File methods
Add Preadv implementing ceph_preadv.
Add Pwritev implementing ceph_pwritev.
These calls act similarly to ReadAt and WriteAt but take multiple
buffers at once.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-08-28 10:07:34 -04:00
John Mulligan 33e84bc9c5 cephfs: use FormatErrorCode for formatting cephfs errors
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-08-10 13:03:24 -04:00
John Mulligan 1ecac966de cephfs: rename error types Errno method to ErrorCode
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-08-10 13:03:24 -04:00
John Mulligan 4a58616b96 cephfs: fix a typo in the ListXattr doc comment
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-08-04 13:35:35 -04:00
John Mulligan f020a3ffac cephfs: add path-based xattr functions
This change adds wrappers for:

* ceph_getxattr
* ceph_listxattr
* ceph_removexattr
* ceph_setxattr

As well as:
* ceph_lgetxattr
* ceph_llistxattr
* ceph_lremovexattr
* ceph_lsetxattr

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-08-04 13:35:35 -04:00
John Mulligan 80ce962b68 cephfs: give xattr test samples a better name
The name "samples" was too generic. Rename it to "xattrSamples".
This variable will be used outside of this file in a future change.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-08-04 13:35:35 -04:00
Sven Anderson 085e2049b3 tests: add tests for the Errno() methods of numeric error types
Signed-off-by: Sven Anderson <sven@redhat.com>
2020-07-24 23:14:20 +02:00
John Mulligan d044f177c3 cephfs: use new SplitSparseBuffer call in ListXattr function
Use the newly added SplitSparseBuffer cutil function to break the buffer
cephfs returns into a slice of strings with xattr names.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-07-24 13:42:35 -04:00
John Mulligan 1bbd6edb4b cephfs: add a pointer in the docs for no-value issue
Add a section to the doc comment for SetXattr that notes the behavior
I observed while working on the tests: that passing an empty value
(or null on the C side) causes the xattr to be removed rather than
set with an "empty" value. This issue has been reported in the
ceph tracker (see link in comment).

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-07-24 13:42:35 -04:00
John Mulligan 5f41e2d8d2 cephfs: add file method RemoveXattr implementing ceph_fremovexattr
Add RemoveXattr implementing ceph_fremovexattr as well as a test for it.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-07-24 13:42:35 -04:00
John Mulligan 04bf7a4d0e cephfs: add file method ListXattr implementing ceph_flistxattr
Add ListXattr implementing ceph_flistxattr. Add a test for the function.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-07-24 13:42:35 -04:00
John Mulligan a9738e7d45 cephfs: add file SetXattr and GetXattr functions
Add SetXattr implementing ceph_fsetxattr.
Add GetXattr implementing ceph_fgetxattr.
Add test function to exercise both.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-07-24 13:42:35 -04:00
John Mulligan 65227dd4d4 cephfs: add a getErrorIfNegative helper func
Works like the ones already in the other packages.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-07-24 13:42:35 -04:00
John Mulligan 7dea1f728f cephfs: add function ParseDefaultConfigEnv to set ceph config from env
Similar to the rados function of the same name, ParseDefaultConfigEnv
uses the environment to configure the cephfs mount.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-07-24 09:54:04 -04:00
John Mulligan c34501fc6a cephfs: add a ParseConfigArgv function
The ParseConfigArgv behaves similarly to the same named function in
rados. The command line argv value is parsed by ceph libs and used to
configure the mount object.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-07-24 09:54:04 -04:00
John Mulligan bf0e4723e2 cephfs: add error for function args that must have data
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-07-24 09:54:04 -04:00
John Mulligan d3f8f0cf70 cephfs: add StatFS implementing ceph_statfs
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-07-20 13:36:53 -04:00
Sven Anderson 8b45a01b7d cephfs: make CephFSError type unexported
In order to avoid external dependencies on implementation details,
this change replaces CephFSError with the unexported cephFSError. 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>
2020-07-17 13:47:32 -04:00
Niels de Vos c4714165a6 timespec: move to internal pkg
There are functions from librbd that can use the Timespec type too.
Instead of consuming 'cephfs.Timespec' in the rbd package, create an
internal type that can be exposed through both packages.

This looks a bit like duplication, but it does not break the current
users of Timespec in the cephfs package.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-06-22 09:22:18 -04:00
John Mulligan 3a561218d4 cephfs: add Rename function
Rename, it does what it says on the tin. Tests included.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-06-15 13:59:27 -04:00
John Mulligan 624230cdbd cephfs: add Fsync and Sync calls for open files
Add wrappers for ceph_fsync. The Fsync call directly wraps ceph_fsync
which provides options to behave more like fsync or more like fdatasync.
Add Sync, a simpler wrapper over Fsync, to match any interfaces that
make use of `File.Sync` from Go's os package.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-06-11 11:21:11 -04:00
Mudit Agarwal 092c0b7832 cephfs: add ceph_flock() function
Added ceph_flock() function which applies or removes an advisory lock on an open file.

Fixes: https://github.com/ceph/go-ceph/issues/248

Signed-off-by: Mudit Agarwal muagarwa@redhat.com
2020-05-27 10:40:52 -04:00
Mudit Agarwal 1d30b636ff cephfs: add ceph_fallocate() function
Added ceph_fallocate() which  preallocates or releases disk space
for the file for the given byte range.

Fixes: https://github.com/ceph/go-ceph/issues/246

Signed-off-by: Mudit Agarwal muagarwa@redhat.com
2020-05-20 13:12:55 -04:00
John Mulligan 80833a6789 cephfs: add Fstatx function to file type
Use the CephStatx type previously added to the library to implement a
wrapper for the ceph_fstatx function.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-05-19 17:06:44 -04:00
John Mulligan 807eafb9d5 cephfs: add ReadDirPlus function and associated types
Add the ReadDirPlus function call, wrapping ceph_readdirplus_r. Add
DirEntryPlus which is a DirEntry plus a getter for the statx field.
Add a test similar to the ReadDir test and (since it is possible to
induce an error with ceph_readdirplus_r) a test for the error handling
path to improve code coverage.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-05-19 16:35:58 -04:00
John Mulligan ce8e45541b cephfs: add test coverage for invalid file state in Fchown
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-05-14 09:27:39 -04:00
John Mulligan 92a85b4385 cephfs: add test coverage for invalid file state in Fchmod
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-05-14 09:27:39 -04:00
John Mulligan e2a78eec02 cutil: allow passing free functions to command output type
The *_command functions in librados and libcephfs document the use
of specific free functions for data allocated. These functions are
currently just wrappers around C's free() function. However, to be
more strictly compliant this change adds a free-function callback
to the CommandOutput type and the specific free functions are now
used outside the unit tests.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-05-12 17:18:08 -04:00
John Mulligan f2d0bb4692 cephfs: replace copy-n-paste *_command functions argument handling
Similar to the functions in the rados pkg, cephfs package has a function
MdsCommand that is mostly boilerplate that to set up the C function's
arguments. Replace it with the types from the new cutil internal
package.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-05-12 17:18:08 -04:00
John Mulligan d4079e3949 cephfs: add path based Statx function implmenting ceph_statx
Add a Statx wrapper for ceph_statx.
Add a type wrapping the statx status info that exposes the various
fields from the C-struct.
Add a type wrapping struct timespec, based on golang's x/sys, for the
time fields in the struct.
Note that the ceph struct is not the same as the linux statx struct.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-05-07 13:44:19 -04:00
muagarwa 27a1824ca0 cephfs: implement wrappers for fchmod and fchown
Fchmod() implemenets ceph_fchmod()
Fchown() implements ceph_fchown()
To fix: https://github.com/ceph/go-ceph/issues/240

Signed-off-by: Mudit Agarwal muagarwa@redhat.com
2020-05-07 09:43:05 +02:00
muagarwa fa7300fff8 cephfs: Validate mount.mount usage in cephfs/path.go
ceph MountInfo pointer is being passed in the functions without a validation check, if it is nil there may be a crash. Fixed the functions to first validate mount.mount

Signed-off-by: Mudit Agarwal muagarwa@redhat.com
2020-05-06 10:04:43 -04:00