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>
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>
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>
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>
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>
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>
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>
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
Link function implements ceph_link().
Symlink function implements ceph_symlink().
Readlink function implements ceph_readlink().
To fix https://github.com/ceph/go-ceph/issues/218
Signed-off-by: Mudit Agarwal <muagarwa@redhat.com>
CephFS returns Linux-style struct dirent that has a d_type field.
It appears to properly make use of the field. This change exposes
the field using a DType type and associated constants as well
as a DType() function for the DirEntry.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Negative offsets that are passed through ReadAt/WriteAt to the ceph
calls cause them to behave like Read/Write and this is undesirable
at the go layer. Additionally, the os packages' file functions
reject negative offsets as well.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Add a test case to ensure the behavior of a mixed used [1] of Read
and ReadAt calls is consistent and ReadAt doesn't side effect
the file position used by Read.
1 - Not recommended, but we should not break now or in the future.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Have Read and ReadAt functions return io.EOF when nothing is read
from the file so that it matches the current behavior of file types
in Go standard library.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Now, the close function is idempotent wrt being called multiple times
on a valid file. Additionally, check the state of the file in various
functions to produce sensible errors, matching those cephfs itself
returns, if the object was not constructed properly.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Continue organizing the cephfs functionality by creating new files
for chmod and chown functionality.
Similarly, the dedicated test functions for those items are moved
into a new file as well.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Continue organizing the cephfs functionality by creating new files
for the most basic path management functions:
MakeDir, RemoveDir, ChangeDir, CurrentDir
Similarly, the dedicated test functions for those items are moved into
a new file as well.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Start organizing some of the cephfs functionality into functions grouped
by files by moving the MDS command functions into a new file. Move the
tests dedicated to those functions into a new matching file too.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
The Init functions initializes the connection without mounting the fs.
This function must be called before setting the perms but before
creating the mount.
SetMountPerms accepts a UserPerm object to set the fs ownership info
on the mount. The corresponding tests verifies that the UserPerm
can be applied and it effects the gid of newly created dirs for that
mount.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
To prevent test failures re-reunning the suite against the same fs we
need to make sure tests clean up after themselves.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
The RewindDir is used by List and can be used independently. It
resets the open dir to the "start".
The List function and the accompanying DirEntries type allow one
to simply grab all the dir entries at once. The Names method on the
DirEntries type allows the user to get the most commonly wanted items
from the dir entries in one shot.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Add the Directory type and the OpenDir function to get an open
Directory and a Close function to close/free it.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Previously, calling Release more than once for the same MountInfo would
abort due to a double free in the ceph libs. As this is somewhat user
hostile we add some simple state tracking in our wrapper type such that
one can make redundant calls to Release without crashing the
application.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
The test function that exercises ChangeDir was creating a directory
and leaving it behind. Add some basic cleanup to the test to try
and avoid leaking stuff between test runs.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
In a previous commit we added fsDisconnect to match with fsConnect. For
tests that do not use fsConnect but still acquire resources we need to
free up those resources with direct calls to the appropriate functions.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
For every (most?) call to fsConnect we should pair it with a (deferred)
call to fsDisconnect to close connection and release resources
associated with the mount object we have created for the test.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
The defer function in TestMountWithRoot was always trying to call
unmount before release. This is not correct if the fs was not mounted
so we reorganize this code to more closely match what should be done
in normal practice.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Somehow we managed to introduce extra code into TestCreateMount that
had it create two mounts. This is undesirable for this test so this
change eliminates the extra unwanted invocation.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Previously, the mds name was hardcoded in the tests to match that set up
by "micro-osd.sh". We continue to default to that value, but allow the
test to be supplied a custom value by the environment.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Add a utility function to test cases that expect the cephfs file system
to be mounted locally and accessible.
Add environment vars to configure the location of the mount point as
well whether the function causes the test to be skipped (the default)
or force an early but clear failure.
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>
The existing Mount() method did not provide a way to access the root
path argument to ceph_mount. This new function allows the caller to
specify an alternate root dir for the mount.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Try to improve the doc comments for clarity and less redundancy.
Add "implements" subsections for the three functions.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
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>
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>
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>
In the cephfs tests the setup of the mount/connection was largely being
done as a copy-n-paste. This change adds a common setup function for
most of the test cases that need an active connection.
Similar to other recent changes this also adds a timeout such that
if the test fails to get a connection it will fail quickly rather
than block forever.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Now that cephfs_test.go is part of the cephfs package, the linter is
checking it and finding errors. Fix them.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Convert cephfs packages previously unexposed type to a public one and
replace a bunch of the existing boilerplate error handling with a
convenience function similar to those found ind rbd and rados.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
After discussion we decided to entirely drop logging from the library.
Future users should rely instead of the error types and values the
function calls return.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
This change replaces a couple of functions from the "assert" package
with the corresponding functions from the "require", where the
following code relies on a non-nil object.
Signed-off-by: Sven Anderson <sven@redhat.com>
This commit adds the following cephfs functions:
* Unmount // Unmounting is necessary to cleanup mounts
* Release // Release destroys the cmount ~ end of transaction
* RemoveDir // inverse of MakeDir
* Chown // change ownership of file or directory
* Chmod // change permissions of file or directory
Tests are included for each function.
In addition to these changes modifications to:
.travis.yml, Dockerfile, and Makefile
were made to accomodate tests to mount the ceph volume. Tests use
fuse to mount the volume which requires adding:
--device /dev/fuse --cap-add SYS_ADMIN --security-opt \
apparmor:unconfined
to the docker container (alternatively --privileged works but adds
additional permissions).
Changes to README add the above docker changes as well as point
users to the necessary ceph development libraries.
* CephError uses syscall for string version of error
* Add error logging for every function
* Add RemoveDir() function
* Add Unmount() function
* Add Release() function
* Add Chown() function
* Add Chmod() function