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>
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>
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>
Add SetXattr implementing ceph_fsetxattr.
Add GetXattr implementing ceph_fgetxattr.
Add test function to exercise both.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
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>
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>
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>
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>