1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2009-2011 New Dream Network
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
18 #if defined(__linux__)
24 #include <sys/types.h>
25 #include <sys/statvfs.h>
26 #include <sys/socket.h>
32 #include "ceph_ll_client.h"
35 namespace ceph::common
{
38 using CephContext
= ceph::common::CephContext
;
42 #define LIBCEPHFS_VER_MAJOR 10
43 #define LIBCEPHFS_VER_MINOR 0
44 #define LIBCEPHFS_VER_EXTRA 3
46 #define LIBCEPHFS_VERSION(maj, min, extra) ((maj << 16) + (min << 8) + extra)
47 #define LIBCEPHFS_VERSION_CODE LIBCEPHFS_VERSION(LIBCEPHFS_VER_MAJOR, LIBCEPHFS_VER_MINOR, LIBCEPHFS_VER_EXTRA)
50 #define LIBCEPHFS_DEPRECATED __attribute__((deprecated))
51 #pragma GCC diagnostic push
52 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
54 #define LIBCEPHFS_DEPRECATED
58 * If using glibc check that file offset is 64-bit.
60 #if defined(__GLIBC__) && !defined(__USE_FILE_OFFSET64)
61 # error libceph: glibc must define __USE_FILE_OFFSET64 or readdir results will be corrupted
65 * XXXX redeclarations from ceph_fs.h, rados.h, etc. We need more of this
66 * in the interface, but shouldn't be re-typing it (and using different
71 #define CEPH_INO_ROOT 1
72 #define CEPH_NOSNAP ((uint64_t)(-2))
74 struct ceph_file_layout
{
75 /* file -> object mapping */
76 uint32_t fl_stripe_unit
; /* stripe unit, in bytes. must be multiple
78 uint32_t fl_stripe_count
; /* over this many objects */
79 uint32_t fl_object_size
; /* until objects are this big, then move to
81 uint32_t fl_cas_hash
; /* 0 = none; 1 = sha256 */
83 /* pg -> disk layout */
84 uint32_t fl_object_stripe_unit
; /* for per-object parity, if any */
86 /* object -> pg layout */
87 uint32_t fl_pg_preferred
; /* preferred primary for pg (-1 for none) */
88 uint32_t fl_pg_pool
; /* namespace, crush rule, rep level */
89 } __attribute__ ((packed
));
92 #endif /* ! __cplusplus */
95 typedef struct UserPerm UserPerm
;
98 typedef struct Inode Inode
;
100 struct ceph_mount_info
;
101 struct ceph_dir_result
;
103 // user supplied key,value pair to be associated with a snapshot.
104 // callers can supply an array of this struct via ceph_mksnap().
105 struct snap_metadata
{
112 size_t nr_snap_metadata
;
113 struct snap_metadata
*snap_metadata
;
116 struct ceph_snapdiff_entry_t
{
117 struct dirent dir_entry
;
118 uint64_t snapid
; //should be snapid_t but prefer not to exposure it
121 /* setattr mask bits (up to an int in size) */
122 #ifndef CEPH_SETATTR_MODE
123 #define CEPH_SETATTR_MODE (1 << 0)
124 #define CEPH_SETATTR_UID (1 << 1)
125 #define CEPH_SETATTR_GID (1 << 2)
126 #define CEPH_SETATTR_MTIME (1 << 3)
127 #define CEPH_SETATTR_ATIME (1 << 4)
128 #define CEPH_SETATTR_SIZE (1 << 5)
129 #define CEPH_SETATTR_CTIME (1 << 6)
130 #define CEPH_SETATTR_MTIME_NOW (1 << 7)
131 #define CEPH_SETATTR_ATIME_NOW (1 << 8)
132 #define CEPH_SETATTR_BTIME (1 << 9)
133 #define CEPH_SETATTR_KILL_SGUID (1 << 10)
134 #define CEPH_SETATTR_FSCRYPT_AUTH (1 << 11)
135 #define CEPH_SETATTR_FSCRYPT_FILE (1 << 12)
136 #define CEPH_SETATTR_KILL_SUID (1 << 13)
137 #define CEPH_SETATTR_KILL_SGID (1 << 14)
140 /* define error codes for the mount function*/
141 # define CEPHFS_ERROR_MON_MAP_BUILD 1000
142 # define CEPHFS_ERROR_NEW_CLIENT 1002
143 # define CEPHFS_ERROR_MESSENGER_START 1003
146 * Create a UserPerm credential object.
148 * Some calls (most notably, the ceph_ll_* ones), take a credential object
149 * that represents the credentials that the calling program is using. This
150 * function creates a new credential object for this purpose. Returns a
151 * pointer to the object, or NULL if it can't be allocated.
153 * Note that the gidlist array is used directly and is not copied. It must
154 * remain valid over the lifetime of the created UserPerm object.
156 * @param uid uid to be used
157 * @param gid gid to be used
158 * @param ngids number of gids in supplemental grouplist
159 * @param gidlist array of gid_t's in the list of groups
161 UserPerm
*ceph_userperm_new(uid_t uid
, gid_t gid
, int ngids
, gid_t
*gidlist
);
164 * Destroy a UserPerm credential object.
166 * @param perm pointer to object to be destroyed
168 * Currently this just frees the object. Note that the gidlist array is not
169 * freed. The caller must do so if it's necessary.
171 void ceph_userperm_destroy(UserPerm
*perm
);
174 * Get a pointer to the default UserPerm object for the mount.
176 * @param cmount the mount info handle
178 * Every cmount has a default set of credentials. This returns a pointer to
181 * Unlike with ceph_userperm_new, this object should not be freed.
183 struct UserPerm
*ceph_mount_perms(struct ceph_mount_info
*cmount
);
186 * Set cmount's default permissions
188 * @param cmount the mount info handle
189 * @param perm permissions to set to default for mount
191 * Every cmount has a default set of credentials. This does a deep copy of
192 * the given permissions to the ones in the cmount. Must be done after
193 * ceph_init but before ceph_mount.
195 * Returns 0 on success, and -EISCONN if the cmount is already mounted.
197 int ceph_mount_perms_set(struct ceph_mount_info
*cmount
, UserPerm
*perm
);
200 * @defgroup libcephfs_h_init Setup and Teardown
201 * These are the first and last functions that should be called
202 * when using libcephfs.
208 * Get the version of libcephfs.
210 * The version number is major.minor.patch.
212 * @param major where to store the major version number
213 * @param minor where to store the minor version number
214 * @param patch where to store the extra version number
216 const char *ceph_version(int *major
, int *minor
, int *patch
);
219 * Create a mount handle for interacting with Ceph. All libcephfs
220 * functions operate on a mount info handle.
222 * @param cmount the mount info handle to initialize
223 * @param id the id of the client. This can be a unique id that identifies
224 * this client, and will get appended onto "client.". Callers can
225 * pass in NULL, and the id will be the process id of the client.
226 * @returns 0 on success, negative error code on failure
228 int ceph_create(struct ceph_mount_info
**cmount
, const char * const id
);
231 * Create a mount handle from a CephContext, which holds the configuration
232 * for the ceph cluster. A CephContext can be acquired from an existing ceph_mount_info
233 * handle, using the @ref ceph_get_mount_context call. Note that using the same CephContext
234 * for two different mount handles results in the same client entity id being used.
236 * @param cmount the mount info handle to initialize
237 * @param conf reuse this pre-existing CephContext config
238 * @returns 0 on success, negative error code on failure
241 int ceph_create_with_context(struct ceph_mount_info
**cmount
, CephContext
*conf
);
243 int ceph_create_with_context(struct ceph_mount_info
**cmount
, struct CephContext
*conf
);
246 #ifndef VOIDPTR_RADOS_T
247 #define VOIDPTR_RADOS_T
248 typedef void *rados_t
;
249 #endif // VOIDPTR_RADOS_T
252 * Create a mount handle from a rados_t, for using libcephfs in the
253 * same process as librados.
255 * @param cmount the mount info handle to initialize
256 * @param cluster reference to already-initialized librados handle
257 * @returns 0 on success, negative error code on failure
259 int ceph_create_from_rados(struct ceph_mount_info
**cmount
, rados_t cluster
);
262 * Initialize the filesystem client (but do not mount the filesystem yet)
264 * @returns 0 on success, negative error code on failure
266 int ceph_init(struct ceph_mount_info
*cmount
);
269 * Optionally set which filesystem to mount, before calling mount.
271 * An error will be returned if this libcephfs instance is already
272 * mounted. This function is an alternative to setting the global
273 * client_fs setting. Using this function enables multiple libcephfs
274 * instances in the same process to mount different filesystems.
276 * The filesystem name is *not* validated in this function. That happens
277 * during mount(), where an ENOENT error will result if a non-existent
278 * filesystem was specified here.
280 * @param cmount the mount info handle
281 * @returns 0 on success, negative error code on failure
283 int ceph_select_filesystem(struct ceph_mount_info
*cmount
, const char *fs_name
);
287 * Perform a mount using the path for the root of the mount.
289 * It is optional to call ceph_init before this. If ceph_init has
290 * not already been called, it will be called in the course of this operation.
292 * @param cmount the mount info handle
293 * @param root the path for the root of the mount. This can be an existing
294 * directory within the ceph cluster, but most likely it will
295 * be "/". Passing in NULL is equivalent to "/".
296 * @returns 0 on success, negative error code on failure
298 int ceph_mount(struct ceph_mount_info
*cmount
, const char *root
);
301 * Return cluster ID for a mounted ceph filesystem
303 * Every ceph filesystem has a filesystem ID associated with it. This
304 * function returns that value. If the ceph_mount_info does not refer to a
305 * mounted filesystem, this returns a negative error code.
307 int64_t ceph_get_fs_cid(struct ceph_mount_info
*cmount
);
310 * Execute a management command remotely on an MDS.
312 * Must have called ceph_init or ceph_mount before calling this.
314 * @param mds_spec string representing rank, MDS name, GID or '*'
315 * @param cmd array of null-terminated strings
316 * @param cmdlen length of cmd array
317 * @param inbuf non-null-terminated input data to command
318 * @param inbuflen length in octets of inbuf
319 * @param outbuf populated with pointer to buffer (command output data)
320 * @param outbuflen length of allocated outbuf
321 * @param outs populated with pointer to buffer (command error strings)
322 * @param outslen length of allocated outs
324 * @return 0 on success, negative error code on failure
327 int ceph_mds_command(struct ceph_mount_info
*cmount
,
328 const char *mds_spec
,
331 const char *inbuf
, size_t inbuflen
,
332 char **outbuf
, size_t *outbuflen
,
333 char **outs
, size_t *outslen
);
336 * Free a buffer, such as those used for output arrays from ceph_mds_command
338 void ceph_buffer_free(char *buf
);
341 * Unmount a mount handle.
343 * @param cmount the mount handle
344 * @return 0 on success, negative error code on failure
346 int ceph_unmount(struct ceph_mount_info
*cmount
);
349 * Abort mds connections
351 * @param cmount the mount handle
352 * @return 0 on success, negative error code on failure
354 int ceph_abort_conn(struct ceph_mount_info
*cmount
);
357 * Destroy the mount handle.
359 * The handle should not be mounted. This should be called on completion of
360 * all libcephfs functions.
362 * @param cmount the mount handle
363 * @return 0 on success, negative error code on failure.
365 int ceph_release(struct ceph_mount_info
*cmount
);
368 * Deprecated. Unmount and destroy the ceph mount handle. This should be
369 * called on completion of all libcephfs functions.
371 * Equivalent to ceph_unmount() + ceph_release() without error handling.
373 * @param cmount the mount handle to shutdown
375 void ceph_shutdown(struct ceph_mount_info
*cmount
);
378 * Return associated client addresses
380 * @param cmount the mount handle
381 * @param addrs the output addresses
382 * @returns 0 on success, a negative error code on failure
383 * @note the returned addrs should be free by the caller
385 int ceph_getaddrs(struct ceph_mount_info
*cmount
, char** addrs
);
388 * Get a global id for current instance
390 * The handle should not be mounted. This should be called on completion of
391 * all libcephfs functions.
393 * @param cmount the mount handle
394 * @returns instance global id
396 uint64_t ceph_get_instance_id(struct ceph_mount_info
*cmount
);
399 * Extract the CephContext from the mount point handle.
401 * @param cmount the ceph mount handle to get the context from.
402 * @returns the CephContext associated with the mount handle.
405 CephContext
*ceph_get_mount_context(struct ceph_mount_info
*cmount
);
407 struct CephContext
*ceph_get_mount_context(struct ceph_mount_info
*cmount
);
410 * Check mount status.
412 * Return non-zero value if mounted. Otherwise, zero.
414 int ceph_is_mounted(struct ceph_mount_info
*cmount
);
419 * @defgroup libcephfs_h_config Config
420 * Functions for manipulating the Ceph configuration at runtime.
426 * Load the ceph configuration from the specified config file.
428 * @param cmount the mount handle to load the configuration into.
429 * @param path_list the configuration file path
430 * @returns 0 on success, negative error code on failure
432 int ceph_conf_read_file(struct ceph_mount_info
*cmount
, const char *path_list
);
435 * Parse the command line arguments and load the configuration parameters.
437 * @param cmount the mount handle to load the configuration parameters into.
438 * @param argc count of the arguments in argv
439 * @param argv the argument list
440 * @returns 0 on success, negative error code on failure
442 int ceph_conf_parse_argv(struct ceph_mount_info
*cmount
, int argc
, const char **argv
);
445 * Configure the cluster handle based on an environment variable
447 * The contents of the environment variable are parsed as if they were
448 * Ceph command line options. If var is NULL, the CEPH_ARGS
449 * environment variable is used.
451 * @pre ceph_mount() has not been called on the handle
453 * @note BUG: this is not threadsafe - it uses a static buffer
455 * @param cmount handle to configure
456 * @param var name of the environment variable to read
457 * @returns 0 on success, negative error code on failure
459 int ceph_conf_parse_env(struct ceph_mount_info
*cmount
, const char *var
);
461 /** Sets a configuration value from a string.
463 * @param cmount the mount handle to set the configuration value on
464 * @param option the configuration option to set
465 * @param value the value of the configuration option to set
467 * @returns 0 on success, negative error code otherwise.
469 int ceph_conf_set(struct ceph_mount_info
*cmount
, const char *option
, const char *value
);
471 /** Set mount timeout.
473 * @param cmount mount handle to set the configuration value on
474 * @param timeout mount timeout interval
476 * @returns 0 on success, negative error code otherwise.
478 int ceph_set_mount_timeout(struct ceph_mount_info
*cmount
, uint32_t timeout
);
481 * Gets the configuration value as a string.
483 * @param cmount the mount handle to set the configuration value on
484 * @param option the config option to get
485 * @param buf the buffer to fill with the value
486 * @param len the length of the buffer.
487 * @returns the size of the buffer filled in with the value, or negative error code on failure
489 int ceph_conf_get(struct ceph_mount_info
*cmount
, const char *option
, char *buf
, size_t len
);
494 * @defgroup libcephfs_h_fsops File System Operations.
495 * Functions for getting/setting file system wide information specific to a particular
502 * Perform a statfs on the ceph file system. This call fills in file system wide statistics
503 * into the passed in buffer.
505 * @param cmount the ceph mount handle to use for performing the statfs.
506 * @param path can be any path within the mounted filesystem
507 * @param stbuf the file system statistics filled in by this function.
508 * @return 0 on success, negative error code otherwise.
510 int ceph_statfs(struct ceph_mount_info
*cmount
, const char *path
, struct statvfs
*stbuf
);
513 * Synchronize all filesystem data to persistent media.
515 * @param cmount the ceph mount handle to use for performing the sync_fs.
516 * @returns 0 on success or negative error code on failure.
518 int ceph_sync_fs(struct ceph_mount_info
*cmount
);
521 * Get the current working directory.
523 * @param cmount the ceph mount to get the current working directory for.
524 * @returns the path to the current working directory
526 const char* ceph_getcwd(struct ceph_mount_info
*cmount
);
529 * Change the current working directory.
531 * @param cmount the ceph mount to change the current working directory for.
532 * @param path the path to the working directory to change into.
533 * @returns 0 on success, negative error code otherwise.
535 int ceph_chdir(struct ceph_mount_info
*cmount
, const char *path
);
540 * @defgroup libcephfs_h_dir Directory Operations.
541 * Functions for manipulating and listing directories.
547 * Open the given directory.
549 * @param cmount the ceph mount handle to use to open the directory
550 * @param name the path name of the directory to open. Must be either an absolute path
551 * or a path relative to the current working directory.
552 * @param dirpp the directory result pointer structure to fill in.
553 * @returns 0 on success or negative error code otherwise.
555 int ceph_opendir(struct ceph_mount_info
*cmount
, const char *name
, struct ceph_dir_result
**dirpp
);
558 * Open a directory referred to by a file descriptor
560 * @param cmount the ceph mount handle to use to open the directory
561 * @param dirfd open file descriptor for the directory
562 * @param dirpp the directory result pointer structure to fill in
563 * @returns 0 on success or negative error code otherwise
565 int ceph_fdopendir(struct ceph_mount_info
*cmount
, int dirfd
, struct ceph_dir_result
**dirpp
);
568 * Close the open directory.
570 * @param cmount the ceph mount handle to use for closing the directory
571 * @param dirp the directory result pointer (set by ceph_opendir) to close
572 * @returns 0 on success or negative error code on failure.
574 int ceph_closedir(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
);
577 * Get the next entry in an open directory.
579 * @param cmount the ceph mount handle to use for performing the readdir.
580 * @param dirp the directory stream pointer from an opendir holding the state of the
581 * next entry to return.
582 * @returns the next directory entry or NULL if at the end of the directory (or the directory
583 * is empty. This pointer should not be freed by the caller, and is only safe to
584 * access between return and the next call to ceph_readdir or ceph_closedir.
586 struct dirent
* ceph_readdir(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
);
589 * A safe version of ceph_readdir, where the directory entry struct is allocated by the caller.
591 * @param cmount the ceph mount handle to use for performing the readdir.
592 * @param dirp the directory stream pointer from an opendir holding the state of the
593 * next entry to return.
594 * @param de the directory entry pointer filled in with the next directory entry of the dirp state.
595 * @returns 1 if the next entry was filled in, 0 if the end of the directory stream was reached,
596 * and a negative error code on failure.
598 int ceph_readdir_r(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
, struct dirent
*de
);
601 * A safe version of ceph_readdir that also returns the file statistics (readdir+stat).
603 * @param cmount the ceph mount handle to use for performing the readdir_plus_r.
604 * @param dirp the directory stream pointer from an opendir holding the state of the
605 * next entry to return.
606 * @param de the directory entry pointer filled in with the next directory entry of the dirp state.
607 * @param stx the stats of the file/directory of the entry returned
608 * @param want mask showing desired inode attrs for returned entry
609 * @param flags bitmask of flags to use when filling out attributes
610 * @param out optional returned Inode argument. If non-NULL, then a reference will be taken on
611 * the inode and the pointer set on success.
612 * @returns 1 if the next entry was filled in, 0 if the end of the directory stream was reached,
613 * and a negative error code on failure.
615 int ceph_readdirplus_r(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
, struct dirent
*de
,
616 struct ceph_statx
*stx
, unsigned want
, unsigned flags
, struct Inode
**out
);
618 struct ceph_snapdiff_info
620 struct ceph_mount_info
* cmount
;
621 struct ceph_dir_result
* dir1
; // primary dir entry to build snapdiff for.
622 struct ceph_dir_result
* dir_aux
; // aux dir entry to identify the second snapshot.
623 // Can point to the parent dir entry if entry-in-question
624 // doesn't exist in the second snapshot
628 * Opens snapdiff stream to get snapshots delta (aka snapdiff).
630 * @param cmount the ceph mount handle to use for snapdiff retrieval.
631 * @param root_path root path for snapshots-in-question
632 * @param rel_path subpath under the root to build delta for
633 * @param snap1 the first snapshot name
634 * @param snap2 the second snapshot name
635 * @param out resulting snapdiff stream handle to be used for snapdiff results
636 retrieval via ceph_readdir_snapdiff
637 * @returns 0 on success and negative error code otherwise
639 int ceph_open_snapdiff(struct ceph_mount_info
* cmount
,
640 const char* root_path
,
641 const char* rel_path
,
644 struct ceph_snapdiff_info
* out
);
646 * Get the next snapshot delta entry.
648 * @param info snapdiff stream handle opened via ceph_open_snapdiff()
649 * @param out the next snapdiff entry which includes directory entry and the
650 * entry's snapshot id - later one for emerged/existing entry or
651 * former snapshot id for the removed entry.
652 * @returns >0 on success, 0 if no more entries in the stream and negative
653 * error code otherwise
655 int ceph_readdir_snapdiff(struct ceph_snapdiff_info
* snapdiff
,
656 struct ceph_snapdiff_entry_t
* out
);
658 * Close snapdiff stream.
660 * @param info snapdiff stream handle opened via ceph_open_snapdiff()
661 * @returns 0 on success and negative error code otherwise
663 int ceph_close_snapdiff(struct ceph_snapdiff_info
* snapdiff
);
666 * Gets multiple directory entries.
668 * @param cmount the ceph mount handle to use for performing the getdents.
669 * @param dirp the directory stream pointer from an opendir holding the state of the
670 * next entry/entries to return.
671 * @param name an array of struct dirent that gets filled in with the to fill returned directory entries into.
672 * @param buflen the length of the buffer, which should be the number of dirent structs * sizeof(struct dirent).
673 * @returns the length of the buffer that was filled in, will always be multiples of sizeof(struct dirent), or a
674 * negative error code. If the buffer is not large enough for a single entry, -ERANGE is returned.
676 int ceph_getdents(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
, char *name
, int buflen
);
679 * Gets multiple directory names.
681 * @param cmount the ceph mount handle to use for performing the getdents.
682 * @param dirp the directory stream pointer from an opendir holding the state of the
683 * next entry/entries to return.
684 * @param name a buffer to fill in with directory entry names.
685 * @param buflen the length of the buffer that can be filled in.
686 * @returns the length of the buffer filled in with entry names, or a negative error code on failure.
687 * If the buffer isn't large enough for a single entry, -ERANGE is returned.
689 int ceph_getdnames(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
, char *name
, int buflen
);
692 * Rewind the directory stream to the beginning of the directory.
694 * @param cmount the ceph mount handle to use for performing the rewinddir.
695 * @param dirp the directory stream pointer to rewind.
697 void ceph_rewinddir(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
);
700 * Get the current position of a directory stream.
702 * @param cmount the ceph mount handle to use for performing the telldir.
703 * @param dirp the directory stream pointer to get the current position of.
704 * @returns the position of the directory stream. Note that the offsets returned
705 * by ceph_telldir do not have a particular order (cannot be compared with
708 int64_t ceph_telldir(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
);
711 * Move the directory stream to a position specified by the given offset.
713 * @param cmount the ceph mount handle to use for performing the seekdir.
714 * @param dirp the directory stream pointer to move.
715 * @param offset the position to move the directory stream to. This offset should be
716 * a value returned by telldir. Note that this value does not refer to the nth
717 * entry in a directory, and can not be manipulated with plus or minus.
719 void ceph_seekdir(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
, int64_t offset
);
722 * Create a directory.
724 * @param cmount the ceph mount handle to use for making the directory.
725 * @param path the path of the directory to create. This must be either an
726 * absolute path or a relative path off of the current working directory.
727 * @param mode the permissions the directory should have once created.
728 * @returns 0 on success or a negative return code on error.
730 int ceph_mkdir(struct ceph_mount_info
*cmount
, const char *path
, mode_t mode
);
733 * Create a directory relative to a file descriptor
735 * @param cmount the ceph mount handle to use for making the directory.
736 * @param dirfd open file descriptor for a directory (or CEPHFS_AT_FDCWD)
737 * @param relpath the path of the directory to create.
738 * @param mode the permissions the directory should have once created.
739 * @returns 0 on success or a negative return code on error.
741 int ceph_mkdirat(struct ceph_mount_info
*cmount
, int dirfd
, const char *relpath
, mode_t mode
);
746 * @param cmount the ceph mount handle to use for making the directory.
747 * @param path the path of the directory to create snapshot. This must be either an
748 * absolute path or a relative path off of the current working directory.
749 * @param name snapshot name
750 * @param mode the permissions the directory should have once created.
751 * @param snap_metadata array of snap metadata structs
752 * @param nr_snap_metadata number of snap metadata struct entries
753 * @returns 0 on success or a negative return code on error.
755 int ceph_mksnap(struct ceph_mount_info
*cmount
, const char *path
, const char *name
,
756 mode_t mode
, struct snap_metadata
*snap_metadata
, size_t nr_snap_metadata
);
761 * @param cmount the ceph mount handle to use for making the directory.
762 * @param path the path of the directory to create snapshot. This must be either an
763 * absolute path or a relative path off of the current working directory.
764 * @param name snapshot name
765 * @returns 0 on success or a negative return code on error.
767 int ceph_rmsnap(struct ceph_mount_info
*cmount
, const char *path
, const char *name
);
770 * Create multiple directories at once.
772 * @param cmount the ceph mount handle to use for making the directories.
773 * @param path the full path of directories and sub-directories that should
775 * @param mode the permissions the directory should have once created.
776 * @returns 0 on success or a negative return code on error.
778 int ceph_mkdirs(struct ceph_mount_info
*cmount
, const char *path
, mode_t mode
);
781 * Remove a directory.
783 * @param cmount the ceph mount handle to use for removing directories.
784 * @param path the path of the directory to remove.
785 * @returns 0 on success or a negative return code on error.
787 int ceph_rmdir(struct ceph_mount_info
*cmount
, const char *path
);
792 * @defgroup libcephfs_h_links Links and Link Handling.
793 * Functions for creating and manipulating hard links and symbolic inks.
801 * @param cmount the ceph mount handle to use for creating the link.
802 * @param existing the path to the existing file/directory to link to.
803 * @param newname the path to the new file/directory to link from.
804 * @returns 0 on success or a negative return code on error.
806 int ceph_link(struct ceph_mount_info
*cmount
, const char *existing
, const char *newname
);
809 * Read a symbolic link.
811 * @param cmount the ceph mount handle to use for creating the link.
812 * @param path the path to the symlink to read
813 * @param buf the buffer to hold the path of the file that the symlink points to.
814 * @param size the length of the buffer
815 * @returns number of bytes copied on success or negative error code on failure
817 int ceph_readlink(struct ceph_mount_info
*cmount
, const char *path
, char *buf
, int64_t size
);
820 * Read a symbolic link relative to a file descriptor
822 * @param cmount the ceph mount handle to use for creating the link.
823 * @param dirfd open file descriptor (or CEPHFS_AT_FDCWD)
824 * @param relpath the path to the symlink to read
825 * @param buf the buffer to hold the path of the file that the symlink points to.
826 * @param size the length of the buffer
827 * @returns number of bytes copied on success or negative error code on failure
829 int ceph_readlinkat(struct ceph_mount_info
*cmount
, int dirfd
, const char *relpath
, char *buf
,
833 * Creates a symbolic link.
835 * @param cmount the ceph mount handle to use for creating the symbolic link.
836 * @param existing the path to the existing file/directory to link to.
837 * @param newname the path to the new file/directory to link from.
838 * @returns 0 on success or a negative return code on failure.
840 int ceph_symlink(struct ceph_mount_info
*cmount
, const char *existing
, const char *newname
);
843 * Creates a symbolic link relative to a file descriptor
845 * @param cmount the ceph mount handle to use for creating the symbolic link.
846 * @param dirfd open file descriptor (or CEPHFS_AT_FDCWD)
847 * @param existing the path to the existing file/directory to link to.
848 * @param newname the path to the new file/directory to link from.
849 * @returns 0 on success or a negative return code on failure.
851 int ceph_symlinkat(struct ceph_mount_info
*cmount
, const char *existing
, int dirfd
,
852 const char *newname
);
857 * @defgroup libcephfs_h_files File manipulation and handling.
858 * Functions for creating and manipulating files.
865 * Checks if deleting a file, link or directory is allowed.
867 * @param cmount the ceph mount handle to use.
868 * @param path the path of the file, link or directory.
869 * @returns 0 on success or negative error code on failure.
871 int ceph_may_delete(struct ceph_mount_info
*cmount
, const char *path
);
874 * Removes a file, link, or symbolic link. If the file/link has multiple links to it, the
875 * file will not disappear from the namespace until all references to it are removed.
877 * @param cmount the ceph mount handle to use for performing the unlink.
878 * @param path the path of the file or link to unlink.
879 * @returns 0 on success or negative error code on failure.
881 int ceph_unlink(struct ceph_mount_info
*cmount
, const char *path
);
884 * Removes a file, link, or symbolic link relative to a file descriptor.
885 * If the file/link has multiple links to it, the file will not
886 * disappear from the namespace until all references to it are removed.
888 * @param cmount the ceph mount handle to use for performing the unlink.
889 * @param dirfd open file descriptor (or CEPHFS_AT_FDCWD)
890 * @param relpath the path of the file or link to unlink.
891 * @param flags bitfield that can be used to set AT_* modifier flags (only AT_REMOVEDIR)
892 * @returns 0 on success or negative error code on failure.
894 int ceph_unlinkat(struct ceph_mount_info
*cmount
, int dirfd
, const char *relpath
, int flags
);
897 * Rename a file or directory.
899 * @param cmount the ceph mount handle to use for performing the rename.
900 * @param from the path to the existing file or directory.
901 * @param to the new name of the file or directory
902 * @returns 0 on success or negative error code on failure.
904 int ceph_rename(struct ceph_mount_info
*cmount
, const char *from
, const char *to
);
907 * Get an open file's extended statistics and attributes.
909 * @param cmount the ceph mount handle to use for performing the stat.
910 * @param fd the file descriptor of the file to get statistics of.
911 * @param stx the ceph_statx struct that will be filled in with the file's statistics.
912 * @param want bitfield of CEPH_STATX_* flags showing designed attributes
913 * @param flags bitfield that can be used to set AT_* modifier flags (AT_STATX_SYNC_AS_STAT, AT_STATX_FORCE_SYNC, AT_STATX_DONT_SYNC and AT_SYMLINK_NOFOLLOW)
914 * @returns 0 on success or negative error code on failure.
916 int ceph_fstatx(struct ceph_mount_info
*cmount
, int fd
, struct ceph_statx
*stx
,
917 unsigned int want
, unsigned int flags
);
920 * Get attributes of a file relative to a file descriptor
922 * @param cmount the ceph mount handle to use for performing the stat.
923 * @param dirfd open file descriptor (or CEPHFS_AT_FDCWD)
924 * @param relpath to the file/directory to get statistics of
925 * @param stx the ceph_statx struct that will be filled in with the file's statistics.
926 * @param want bitfield of CEPH_STATX_* flags showing designed attributes
927 * @param flags bitfield that can be used to set AT_* modifier flags (AT_STATX_SYNC_AS_STAT, AT_STATX_FORCE_SYNC, AT_STATX_DONT_SYNC and AT_SYMLINK_NOFOLLOW)
928 * @returns 0 on success or negative error code on failure.
930 int ceph_statxat(struct ceph_mount_info
*cmount
, int dirfd
, const char *relpath
,
931 struct ceph_statx
*stx
, unsigned int want
, unsigned int flags
);
934 * Get a file's extended statistics and attributes.
936 * @param cmount the ceph mount handle to use for performing the stat.
937 * @param path the file or directory to get the statistics of.
938 * @param stx the ceph_statx struct that will be filled in with the file's statistics.
939 * @param want bitfield of CEPH_STATX_* flags showing designed attributes
940 * @param flags bitfield that can be used to set AT_* modifier flags (AT_STATX_SYNC_AS_STAT, AT_STATX_FORCE_SYNC, AT_STATX_DONT_SYNC and AT_SYMLINK_NOFOLLOW)
941 * @returns 0 on success or negative error code on failure.
943 int ceph_statx(struct ceph_mount_info
*cmount
, const char *path
, struct ceph_statx
*stx
,
944 unsigned int want
, unsigned int flags
);
947 * Get a file's statistics and attributes.
949 * ceph_stat() is deprecated, use ceph_statx() instead.
951 * @param cmount the ceph mount handle to use for performing the stat.
952 * @param path the file or directory to get the statistics of.
953 * @param stbuf the stat struct that will be filled in with the file's statistics.
954 * @returns 0 on success or negative error code on failure.
956 int ceph_stat(struct ceph_mount_info
*cmount
, const char *path
, struct stat
*stbuf
)
957 LIBCEPHFS_DEPRECATED
;
960 * Get a file's statistics and attributes, without following symlinks.
962 * ceph_lstat() is deprecated, use ceph_statx(.., AT_SYMLINK_NOFOLLOW) instead.
964 * @param cmount the ceph mount handle to use for performing the stat.
965 * @param path the file or directory to get the statistics of.
966 * @param stbuf the stat struct that will be filled in with the file's statistics.
967 * @returns 0 on success or negative error code on failure.
969 int ceph_lstat(struct ceph_mount_info
*cmount
, const char *path
, struct stat
*stbuf
)
970 LIBCEPHFS_DEPRECATED
;
973 * Get the open file's statistics.
975 * ceph_fstat() is deprecated, use ceph_fstatx() instead.
977 * @param cmount the ceph mount handle to use for performing the fstat.
978 * @param fd the file descriptor of the file to get statistics of.
979 * @param stbuf the stat struct of the file's statistics, filled in by the
981 * @returns 0 on success or a negative error code on failure
983 int ceph_fstat(struct ceph_mount_info
*cmount
, int fd
, struct stat
*stbuf
)
984 LIBCEPHFS_DEPRECATED
;
987 * Set a file's attributes.
989 * @param cmount the ceph mount handle to use for performing the setattr.
990 * @param relpath the path to the file/directory to set the attributes of.
991 * @param stx the statx struct that must include attribute values to set on the file.
992 * @param mask a mask of all the CEPH_SETATTR_* values that have been set in the statx struct.
993 * @param flags mask of AT_* flags (only AT_ATTR_NOFOLLOW is respected for now)
994 * @returns 0 on success or negative error code on failure.
996 int ceph_setattrx(struct ceph_mount_info
*cmount
, const char *relpath
, struct ceph_statx
*stx
, int mask
, int flags
);
999 * Set a file's attributes (extended version).
1001 * @param cmount the ceph mount handle to use for performing the setattr.
1002 * @param fd the fd of the open file/directory to set the attributes of.
1003 * @param stx the statx struct that must include attribute values to set on the file.
1004 * @param mask a mask of all the stat values that have been set on the stat struct.
1005 * @returns 0 on success or negative error code on failure.
1007 int ceph_fsetattrx(struct ceph_mount_info
*cmount
, int fd
, struct ceph_statx
*stx
, int mask
);
1010 * Change the mode bits (permissions) of a file/directory.
1012 * @param cmount the ceph mount handle to use for performing the chmod.
1013 * @param path the path to the file/directory to change the mode bits on.
1014 * @param mode the new permissions to set.
1015 * @returns 0 on success or a negative error code on failure.
1017 int ceph_chmod(struct ceph_mount_info
*cmount
, const char *path
, mode_t mode
);
1020 * Change the mode bits (permissions) of a file/directory. If the path is a
1021 * symbolic link, it's not de-referenced.
1023 * @param cmount the ceph mount handle to use for performing the chmod.
1024 * @param path the path of file/directory to change the mode bits on.
1025 * @param mode the new permissions to set.
1026 * @returns 0 on success or a negative error code on failure.
1028 int ceph_lchmod(struct ceph_mount_info
*cmount
, const char *path
, mode_t mode
);
1031 * Change the mode bits (permissions) of an open file.
1033 * @param cmount the ceph mount handle to use for performing the chmod.
1034 * @param fd the open file descriptor to change the mode bits on.
1035 * @param mode the new permissions to set.
1036 * @returns 0 on success or a negative error code on failure.
1038 int ceph_fchmod(struct ceph_mount_info
*cmount
, int fd
, mode_t mode
);
1041 * Change the mode bits (permissions) of a file relative to a file descriptor.
1043 * @param cmount the ceph mount handle to use for performing the chown.
1044 * @param dirfd open file descriptor (or CEPHFS_AT_FDCWD)
1045 * @param relpath the relpath of the file/directory to change the ownership of.
1046 * @param mode the new permissions to set.
1047 * @param flags bitfield that can be used to set AT_* modifier flags (AT_SYMLINK_NOFOLLOW)
1048 * @returns 0 on success or negative error code on failure.
1050 int ceph_chmodat(struct ceph_mount_info
*cmount
, int dirfd
, const char *relpath
,
1051 mode_t mode
, int flags
);
1054 * Change the ownership of a file/directory.
1056 * @param cmount the ceph mount handle to use for performing the chown.
1057 * @param path the path of the file/directory to change the ownership of.
1058 * @param uid the user id to set on the file/directory.
1059 * @param gid the group id to set on the file/directory.
1060 * @returns 0 on success or negative error code on failure.
1062 int ceph_chown(struct ceph_mount_info
*cmount
, const char *path
, int uid
, int gid
);
1065 * Change the ownership of a file from an open file descriptor.
1067 * @param cmount the ceph mount handle to use for performing the chown.
1068 * @param fd the fd of the open file/directory to change the ownership of.
1069 * @param uid the user id to set on the file/directory.
1070 * @param gid the group id to set on the file/directory.
1071 * @returns 0 on success or negative error code on failure.
1073 int ceph_fchown(struct ceph_mount_info
*cmount
, int fd
, int uid
, int gid
);
1076 * Change the ownership of a file/directory, don't follow symlinks.
1078 * @param cmount the ceph mount handle to use for performing the chown.
1079 * @param path the path of the file/directory to change the ownership of.
1080 * @param uid the user id to set on the file/directory.
1081 * @param gid the group id to set on the file/directory.
1082 * @returns 0 on success or negative error code on failure.
1084 int ceph_lchown(struct ceph_mount_info
*cmount
, const char *path
, int uid
, int gid
);
1087 * Change the ownership of a file/directory releative to a file descriptor.
1089 * @param cmount the ceph mount handle to use for performing the chown.
1090 * @param dirfd open file descriptor (or CEPHFS_AT_FDCWD)
1091 * @param relpath the relpath of the file/directory to change the ownership of.
1092 * @param uid the user id to set on the file/directory.
1093 * @param gid the group id to set on the file/directory.
1094 * @param flags bitfield that can be used to set AT_* modifier flags (AT_SYMLINK_NOFOLLOW)
1095 * @returns 0 on success or negative error code on failure.
1097 int ceph_chownat(struct ceph_mount_info
*cmount
, int dirfd
, const char *relpath
,
1098 uid_t uid
, gid_t gid
, int flags
);
1101 * Change file/directory last access and modification times.
1103 * @param cmount the ceph mount handle to use for performing the utime.
1104 * @param path the path to the file/directory to set the time values of.
1105 * @param buf holding the access and modification times to set on the file.
1106 * @returns 0 on success or negative error code on failure.
1108 int ceph_utime(struct ceph_mount_info
*cmount
, const char *path
, struct utimbuf
*buf
);
1111 * Change file/directory last access and modification times.
1113 * @param cmount the ceph mount handle to use for performing the utime.
1114 * @param fd the fd of the open file/directory to set the time values of.
1115 * @param buf holding the access and modification times to set on the file.
1116 * @returns 0 on success or negative error code on failure.
1118 int ceph_futime(struct ceph_mount_info
*cmount
, int fd
, struct utimbuf
*buf
);
1121 * Change file/directory last access and modification times.
1123 * @param cmount the ceph mount handle to use for performing the utime.
1124 * @param path the path to the file/directory to set the time values of.
1125 * @param times holding the access and modification times to set on the file.
1126 * @returns 0 on success or negative error code on failure.
1128 int ceph_utimes(struct ceph_mount_info
*cmount
, const char *path
, struct timeval times
[2]);
1131 * Change file/directory last access and modification times, don't follow symlinks.
1133 * @param cmount the ceph mount handle to use for performing the utime.
1134 * @param path the path to the file/directory to set the time values of.
1135 * @param times holding the access and modification times to set on the file.
1136 * @returns 0 on success or negative error code on failure.
1138 int ceph_lutimes(struct ceph_mount_info
*cmount
, const char *path
, struct timeval times
[2]);
1141 * Change file/directory last access and modification times.
1143 * @param cmount the ceph mount handle to use for performing the utime.
1144 * @param fd the fd of the open file/directory to set the time values of.
1145 * @param times holding the access and modification times to set on the file.
1146 * @returns 0 on success or negative error code on failure.
1148 int ceph_futimes(struct ceph_mount_info
*cmount
, int fd
, struct timeval times
[2]);
1151 * Change file/directory last access and modification times.
1153 * @param cmount the ceph mount handle to use for performing the utime.
1154 * @param fd the fd of the open file/directory to set the time values of.
1155 * @param times holding the access and modification times to set on the file.
1156 * @returns 0 on success or negative error code on failure.
1158 int ceph_futimens(struct ceph_mount_info
*cmount
, int fd
, struct timespec times
[2]);
1161 * Change file/directory last access and modification times relative
1162 * to a file descriptor.
1164 * @param cmount the ceph mount handle to use for performing the utime.
1165 * @param dirfd open file descriptor (or CEPHFS_AT_FDCWD)
1166 * @param relpath the relpath of the file/directory to change the ownership of.
1167 * @param dirfd the fd of the open file/directory to set the time values of.
1168 * @param times holding the access and modification times to set on the file.
1169 * @param flags bitfield that can be used to set AT_* modifier flags (AT_SYMLINK_NOFOLLOW)
1170 * @returns 0 on success or negative error code on failure.
1172 int ceph_utimensat(struct ceph_mount_info
*cmount
, int dirfd
, const char *relpath
,
1173 struct timespec times
[2], int flags
);
1176 * Apply or remove an advisory lock.
1178 * @param cmount the ceph mount handle to use for performing the lock.
1179 * @param fd the open file descriptor to change advisory lock.
1180 * @param operation the advisory lock operation to be performed on the file
1181 * descriptor among LOCK_SH (shared lock), LOCK_EX (exclusive lock),
1182 * or LOCK_UN (remove lock). The LOCK_NB value can be ORed to perform a
1183 * non-blocking operation.
1184 * @param owner the user-supplied owner identifier (an arbitrary integer)
1185 * @returns 0 on success or negative error code on failure.
1187 int ceph_flock(struct ceph_mount_info
*cmount
, int fd
, int operation
,
1191 * Truncate the file to the given size. If this operation causes the
1192 * file to expand, the empty bytes will be filled in with zeros.
1194 * @param cmount the ceph mount handle to use for performing the truncate.
1195 * @param path the path to the file to truncate.
1196 * @param size the new size of the file.
1197 * @returns 0 on success or a negative error code on failure.
1199 int ceph_truncate(struct ceph_mount_info
*cmount
, const char *path
, int64_t size
);
1202 * Make a block or character special file.
1204 * @param cmount the ceph mount handle to use for performing the mknod.
1205 * @param path the path to the special file.
1206 * @param mode the permissions to use and the type of special file. The type can be
1207 * one of S_IFREG, S_IFCHR, S_IFBLK, S_IFIFO.
1208 * @param rdev If the file type is S_IFCHR or S_IFBLK then this parameter specifies the
1209 * major and minor numbers of the newly created device special file. Otherwise,
1211 * @returns 0 on success or negative error code on failure.
1213 int ceph_mknod(struct ceph_mount_info
*cmount
, const char *path
, mode_t mode
, dev_t rdev
);
1215 * Create and/or open a file.
1217 * @param cmount the ceph mount handle to use for performing the open.
1218 * @param path the path of the file to open. If the flags parameter includes O_CREAT,
1219 * the file will first be created before opening.
1220 * @param flags a set of option masks that control how the file is created/opened.
1221 * @param mode the permissions to place on the file if the file does not exist and O_CREAT
1222 * is specified in the flags.
1223 * @returns a non-negative file descriptor number on success or a negative error code on failure.
1225 int ceph_open(struct ceph_mount_info
*cmount
, const char *path
, int flags
, mode_t mode
);
1228 * Create and/or open a file relative to a directory
1230 * @param cmount the ceph mount handle to use for performing the open.
1231 * @param dirfd open file descriptor (or CEPHFS_AT_FDCWD)
1232 * @param relpath the path of the file to open. If the flags parameter includes O_CREAT,
1233 * the file will first be created before opening.
1234 * @param flags a set of option masks that control how the file is created/opened.
1235 * @param mode the permissions to place on the file if the file does not exist and O_CREAT
1236 * is specified in the flags.
1237 * @returns a non-negative file descriptor number on success or a negative error code on failure.
1239 int ceph_openat(struct ceph_mount_info
*cmount
, int dirfd
, const char *relpath
, int flags
, mode_t mode
);
1242 * Create and/or open a file with a specific file layout.
1244 * @param cmount the ceph mount handle to use for performing the open.
1245 * @param path the path of the file to open. If the flags parameter includes O_CREAT,
1246 * the file will first be created before opening.
1247 * @param flags a set of option masks that control how the file is created/opened.
1248 * @param mode the permissions to place on the file if the file does not exist and O_CREAT
1249 * is specified in the flags.
1250 * @param stripe_unit the stripe unit size (option, 0 for default)
1251 * @param stripe_count the stripe count (optional, 0 for default)
1252 * @param object_size the object size (optional, 0 for default)
1253 * @param data_pool name of target data pool name (optional, NULL or empty string for default)
1254 * @returns a non-negative file descriptor number on success or a negative error code on failure.
1256 int ceph_open_layout(struct ceph_mount_info
*cmount
, const char *path
, int flags
,
1257 mode_t mode
, int stripe_unit
, int stripe_count
, int object_size
,
1258 const char *data_pool
);
1261 * Close the open file.
1263 * @param cmount the ceph mount handle to use for performing the close.
1264 * @param fd the file descriptor referring to the open file.
1265 * @returns 0 on success or a negative error code on failure.
1267 int ceph_close(struct ceph_mount_info
*cmount
, int fd
);
1270 * Reposition the open file stream based on the given offset.
1272 * @param cmount the ceph mount handle to use for performing the lseek.
1273 * @param fd the open file descriptor referring to the open file and holding the
1274 * current position of the stream.
1275 * @param offset the offset to set the stream to
1276 * @param whence the flag to indicate what type of seeking to perform:
1277 * SEEK_SET: the offset is set to the given offset in the file.
1278 * SEEK_CUR: the offset is set to the current location plus @e offset bytes.
1279 * SEEK_END: the offset is set to the end of the file plus @e offset bytes.
1280 * @returns 0 on success or a negative error code on failure.
1282 int64_t ceph_lseek(struct ceph_mount_info
*cmount
, int fd
, int64_t offset
, int whence
);
1284 * Read data from the file.
1286 * @param cmount the ceph mount handle to use for performing the read.
1287 * @param fd the file descriptor of the open file to read from.
1288 * @param buf the buffer to read data into
1289 * @param size the initial size of the buffer
1290 * @param offset the offset in the file to read from. If this value is negative, the
1291 * function reads from the current offset of the file descriptor.
1292 * @returns the number of bytes read into buf, or a negative error code on failure.
1294 int ceph_read(struct ceph_mount_info
*cmount
, int fd
, char *buf
, int64_t size
, int64_t offset
);
1297 * Read data from the file.
1298 * @param cmount the ceph mount handle to use for performing the read.
1299 * @param fd the file descriptor of the open file to read from.
1300 * @param iov the iov structure to read data into
1301 * @param iovcnt the number of items that iov includes
1302 * @param offset the offset in the file to read from. If this value is negative, the
1303 * function reads from the current offset of the file descriptor.
1304 * @returns the number of bytes read into buf, or a negative error code on failure.
1306 int ceph_preadv(struct ceph_mount_info
*cmount
, int fd
, const struct iovec
*iov
, int iovcnt
,
1310 * Write data to a file.
1312 * @param cmount the ceph mount handle to use for performing the write.
1313 * @param fd the file descriptor of the open file to write to
1314 * @param buf the bytes to write to the file
1315 * @param size the size of the buf array
1316 * @param offset the offset of the file write into. If this value is negative, the
1317 * function writes to the current offset of the file descriptor.
1318 * @returns the number of bytes written, or a negative error code
1320 int ceph_write(struct ceph_mount_info
*cmount
, int fd
, const char *buf
, int64_t size
,
1324 * Write data to a file.
1326 * @param cmount the ceph mount handle to use for performing the write.
1327 * @param fd the file descriptor of the open file to write to
1328 * @param iov the iov structure to read data into
1329 * @param iovcnt the number of items that iov includes
1330 * @param offset the offset of the file write into. If this value is negative, the
1331 * function writes to the current offset of the file descriptor.
1332 * @returns the number of bytes written, or a negative error code
1334 int ceph_pwritev(struct ceph_mount_info
*cmount
, int fd
, const struct iovec
*iov
, int iovcnt
,
1338 * Truncate a file to the given size.
1340 * @param cmount the ceph mount handle to use for performing the ftruncate.
1341 * @param fd the file descriptor of the file to truncate
1342 * @param size the new size of the file
1343 * @returns 0 on success or a negative error code on failure.
1345 int ceph_ftruncate(struct ceph_mount_info
*cmount
, int fd
, int64_t size
);
1348 * Synchronize an open file to persistent media.
1350 * @param cmount the ceph mount handle to use for performing the fsync.
1351 * @param fd the file descriptor of the file to sync.
1352 * @param syncdataonly a boolean whether to synchronize metadata and data (0)
1354 * @return 0 on success or a negative error code on failure.
1356 int ceph_fsync(struct ceph_mount_info
*cmount
, int fd
, int syncdataonly
);
1359 * Preallocate or release disk space for the file for the byte range.
1361 * @param cmount the ceph mount handle to use for performing the fallocate.
1362 * @param fd the file descriptor of the file to fallocate.
1363 * @param mode the flags determines the operation to be performed on the given range.
1364 * default operation (0) allocate and initialize to zero the file in the byte range,
1365 * and the file size will be changed if offset + length is greater than
1366 * the file size. if the FALLOC_FL_KEEP_SIZE flag is specified in the mode,
1367 * the file size will not be changed. if the FALLOC_FL_PUNCH_HOLE flag is
1368 * specified in the mode, the operation is deallocate space and zero the byte range.
1369 * @param offset the byte range starting.
1370 * @param length the length of the range.
1371 * @return 0 on success or a negative error code on failure.
1373 int ceph_fallocate(struct ceph_mount_info
*cmount
, int fd
, int mode
,
1374 int64_t offset
, int64_t length
);
1377 * Enable/disable lazyio for the file.
1379 * @param cmount the ceph mount handle to use for performing the fsync.
1380 * @param fd the file descriptor of the file to sync.
1381 * @param enable a boolean to enable lazyio or disable lazyio.
1382 * @returns 0 on success or a negative error code on failure.
1384 int ceph_lazyio(struct ceph_mount_info
*cmount
, int fd
, int enable
);
1388 * Flushes the write buffer for the file thereby propogating the buffered write to the file.
1390 * @param cmount the ceph mount handle to use for performing the fsync.
1391 * @param fd the file descriptor of the file to sync.
1392 * @param offset a boolean to enable lazyio or disable lazyio.
1393 * @returns 0 on success or a negative error code on failure.
1395 int ceph_lazyio_propagate(struct ceph_mount_info
*cmount
, int fd
, int64_t offset
, size_t count
);
1399 * Flushes the write buffer for the file and invalidate the read cache. This allows a subsequent read operation to read and cache data directly from the file and hence everyone's propagated writes would be visible.
1401 * @param cmount the ceph mount handle to use for performing the fsync.
1402 * @param fd the file descriptor of the file to sync.
1403 * @param offset a boolean to enable lazyio or disable lazyio.
1404 * @returns 0 on success or a negative error code on failure.
1406 int ceph_lazyio_synchronize(struct ceph_mount_info
*cmount
, int fd
, int64_t offset
, size_t count
);
1411 * @defgroup libcephfs_h_xattr Extended Attribute manipulation and handling.
1412 * Functions for creating and manipulating extended attributes on files.
1418 * Get an extended attribute.
1420 * @param cmount the ceph mount handle to use for performing the getxattr.
1421 * @param path the path to the file
1422 * @param name the name of the extended attribute to get
1423 * @param value a pre-allocated buffer to hold the xattr's value
1424 * @param size the size of the pre-allocated buffer
1425 * @returns the size of the value or a negative error code on failure.
1427 int ceph_getxattr(struct ceph_mount_info
*cmount
, const char *path
, const char *name
,
1428 void *value
, size_t size
);
1431 * Get an extended attribute.
1433 * @param cmount the ceph mount handle to use for performing the getxattr.
1434 * @param fd the open file descriptor referring to the file to get extended attribute from.
1435 * @param name the name of the extended attribute to get
1436 * @param value a pre-allocated buffer to hold the xattr's value
1437 * @param size the size of the pre-allocated buffer
1438 * @returns the size of the value or a negative error code on failure.
1440 int ceph_fgetxattr(struct ceph_mount_info
*cmount
, int fd
, const char *name
,
1441 void *value
, size_t size
);
1444 * Get an extended attribute without following symbolic links. This function is
1445 * identical to ceph_getxattr, but if the path refers to a symbolic link,
1446 * we get the extended attributes of the symlink rather than the attributes
1447 * of the link itself.
1449 * @param cmount the ceph mount handle to use for performing the lgetxattr.
1450 * @param path the path to the file
1451 * @param name the name of the extended attribute to get
1452 * @param value a pre-allocated buffer to hold the xattr's value
1453 * @param size the size of the pre-allocated buffer
1454 * @returns the size of the value or a negative error code on failure.
1456 int ceph_lgetxattr(struct ceph_mount_info
*cmount
, const char *path
, const char *name
,
1457 void *value
, size_t size
);
1460 * List the extended attribute keys on a file.
1462 * @param cmount the ceph mount handle to use for performing the listxattr.
1463 * @param path the path to the file.
1464 * @param list a buffer to be filled in with the list of extended attributes keys.
1465 * @param size the size of the list buffer.
1466 * @returns the size of the resulting list filled in.
1468 int ceph_listxattr(struct ceph_mount_info
*cmount
, const char *path
, char *list
, size_t size
);
1471 * List the extended attribute keys on a file.
1473 * @param cmount the ceph mount handle to use for performing the listxattr.
1474 * @param fd the open file descriptor referring to the file to list extended attributes on.
1475 * @param list a buffer to be filled in with the list of extended attributes keys.
1476 * @param size the size of the list buffer.
1477 * @returns the size of the resulting list filled in.
1479 int ceph_flistxattr(struct ceph_mount_info
*cmount
, int fd
, char *list
, size_t size
);
1482 * Get the list of extended attribute keys on a file, but do not follow symbolic links.
1484 * @param cmount the ceph mount handle to use for performing the llistxattr.
1485 * @param path the path to the file.
1486 * @param list a buffer to be filled in with the list of extended attributes keys.
1487 * @param size the size of the list buffer.
1488 * @returns the size of the resulting list filled in.
1490 int ceph_llistxattr(struct ceph_mount_info
*cmount
, const char *path
, char *list
, size_t size
);
1493 * Remove an extended attribute from a file.
1495 * @param cmount the ceph mount handle to use for performing the removexattr.
1496 * @param path the path to the file.
1497 * @param name the name of the extended attribute to remove.
1498 * @returns 0 on success or a negative error code on failure.
1500 int ceph_removexattr(struct ceph_mount_info
*cmount
, const char *path
, const char *name
);
1503 * Remove an extended attribute from a file.
1505 * @param cmount the ceph mount handle to use for performing the removexattr.
1506 * @param fd the open file descriptor referring to the file to remove extended attribute from.
1507 * @param name the name of the extended attribute to remove.
1508 * @returns 0 on success or a negative error code on failure.
1510 int ceph_fremovexattr(struct ceph_mount_info
*cmount
, int fd
, const char *name
);
1513 * Remove the extended attribute from a file, do not follow symbolic links.
1515 * @param cmount the ceph mount handle to use for performing the lremovexattr.
1516 * @param path the path to the file.
1517 * @param name the name of the extended attribute to remove.
1518 * @returns 0 on success or a negative error code on failure.
1520 int ceph_lremovexattr(struct ceph_mount_info
*cmount
, const char *path
, const char *name
);
1523 * Set an extended attribute on a file.
1525 * @param cmount the ceph mount handle to use for performing the setxattr.
1526 * @param path the path to the file.
1527 * @param name the name of the extended attribute to set.
1528 * @param value the bytes of the extended attribute value
1529 * @param size the size of the extended attribute value
1530 * @param flags the flags can be:
1531 * CEPH_XATTR_CREATE: create the extended attribute. Must not exist.
1532 * CEPH_XATTR_REPLACE: replace the extended attribute, Must already exist.
1533 * @returns 0 on success or a negative error code on failure.
1535 int ceph_setxattr(struct ceph_mount_info
*cmount
, const char *path
, const char *name
,
1536 const void *value
, size_t size
, int flags
);
1539 * Set an extended attribute on a file.
1541 * @param cmount the ceph mount handle to use for performing the setxattr.
1542 * @param fd the open file descriptor referring to the file to set extended attribute on.
1543 * @param name the name of the extended attribute to set.
1544 * @param value the bytes of the extended attribute value
1545 * @param size the size of the extended attribute value
1546 * @param flags the flags can be:
1547 * CEPH_XATTR_CREATE: create the extended attribute. Must not exist.
1548 * CEPH_XATTR_REPLACE: replace the extended attribute, Must already exist.
1549 * @returns 0 on success or a negative error code on failure.
1551 int ceph_fsetxattr(struct ceph_mount_info
*cmount
, int fd
, const char *name
,
1552 const void *value
, size_t size
, int flags
);
1555 * Set an extended attribute on a file, do not follow symbolic links.
1557 * @param cmount the ceph mount handle to use for performing the lsetxattr.
1558 * @param path the path to the file.
1559 * @param name the name of the extended attribute to set.
1560 * @param value the bytes of the extended attribute value
1561 * @param size the size of the extended attribute value
1562 * @param flags the flags can be:
1563 * CEPH_XATTR_CREATE: create the extended attribute. Must not exist.
1564 * CEPH_XATTR_REPLACE: replace the extended attribute, Must already exist.
1565 * @returns 0 on success or a negative error code on failure.
1567 int ceph_lsetxattr(struct ceph_mount_info
*cmount
, const char *path
, const char *name
,
1568 const void *value
, size_t size
, int flags
);
1573 * @defgroup libcephfs_h_filelayout Control File Layout.
1574 * Functions for setting and getting the file layout of existing files.
1580 * Get the file striping unit from an open file descriptor.
1582 * @param cmount the ceph mount handle to use.
1583 * @param fh the open file descriptor referring to the file to get the striping unit of.
1584 * @returns the striping unit of the file or a negative error code on failure.
1586 int ceph_get_file_stripe_unit(struct ceph_mount_info
*cmount
, int fh
);
1589 * Get the file striping unit.
1591 * @param cmount the ceph mount handle to use.
1592 * @param path the path of the file/directory get the striping unit of.
1593 * @returns the striping unit of the file or a negative error code on failure.
1595 int ceph_get_path_stripe_unit(struct ceph_mount_info
*cmount
, const char *path
);
1598 * Get the file striping count from an open file descriptor.
1600 * @param cmount the ceph mount handle to use.
1601 * @param fh the open file descriptor referring to the file to get the striping count of.
1602 * @returns the striping count of the file or a negative error code on failure.
1604 int ceph_get_file_stripe_count(struct ceph_mount_info
*cmount
, int fh
);
1607 * Get the file striping count.
1609 * @param cmount the ceph mount handle to use.
1610 * @param path the path of the file/directory get the striping count of.
1611 * @returns the striping count of the file or a negative error code on failure.
1613 int ceph_get_path_stripe_count(struct ceph_mount_info
*cmount
, const char *path
);
1616 * Get the file object size from an open file descriptor.
1618 * @param cmount the ceph mount handle to use.
1619 * @param fh the open file descriptor referring to the file to get the object size of.
1620 * @returns the object size of the file or a negative error code on failure.
1622 int ceph_get_file_object_size(struct ceph_mount_info
*cmount
, int fh
);
1625 * Get the file object size.
1627 * @param cmount the ceph mount handle to use.
1628 * @param path the path of the file/directory get the object size of.
1629 * @returns the object size of the file or a negative error code on failure.
1631 int ceph_get_path_object_size(struct ceph_mount_info
*cmount
, const char *path
);
1634 * Get the file pool information from an open file descriptor.
1636 * @param cmount the ceph mount handle to use.
1637 * @param fh the open file descriptor referring to the file to get the pool information of.
1638 * @returns the ceph pool id that the file is in
1640 int ceph_get_file_pool(struct ceph_mount_info
*cmount
, int fh
);
1643 * Get the file pool information.
1645 * @param cmount the ceph mount handle to use.
1646 * @param path the path of the file/directory get the pool information of.
1647 * @returns the ceph pool id that the file is in
1649 int ceph_get_path_pool(struct ceph_mount_info
*cmount
, const char *path
);
1652 * Get the name of the pool a opened file is stored in,
1654 * Write the name of the file's pool to the buffer. If buflen is 0, return
1655 * a suggested length for the buffer.
1657 * @param cmount the ceph mount handle to use.
1658 * @param fh the open file descriptor referring to the file
1659 * @param buf buffer to store the name in
1660 * @param buflen size of the buffer
1661 * @returns length in bytes of the pool name, or -ERANGE if the buffer is not large enough.
1663 int ceph_get_file_pool_name(struct ceph_mount_info
*cmount
, int fh
, char *buf
, size_t buflen
);
1666 * get the name of a pool by id
1668 * Given a pool's numeric identifier, get the pool's alphanumeric name.
1670 * @param cmount the ceph mount handle to use
1671 * @param pool the numeric pool id
1672 * @param buf buffer to sore the name in
1673 * @param buflen size of the buffer
1674 * @returns length in bytes of the pool name, or -ERANGE if the buffer is not large enough
1676 int ceph_get_pool_name(struct ceph_mount_info
*cmount
, int pool
, char *buf
, size_t buflen
);
1679 * Get the name of the pool a file is stored in
1681 * Write the name of the file's pool to the buffer. If buflen is 0, return
1682 * a suggested length for the buffer.
1684 * @param cmount the ceph mount handle to use.
1685 * @param path the path of the file/directory
1686 * @param buf buffer to store the name in
1687 * @param buflen size of the buffer
1688 * @returns length in bytes of the pool name, or -ERANGE if the buffer is not large enough.
1690 int ceph_get_path_pool_name(struct ceph_mount_info
*cmount
, const char *path
, char *buf
, size_t buflen
);
1693 * Get the default pool name of cephfs
1694 * Write the name of the default pool to the buffer. If buflen is 0, return
1695 * a suggested length for the buffer.
1696 * @param cmount the ceph mount handle to use.
1697 * @param buf buffer to store the name in
1698 * @param buflen size of the buffer
1699 * @returns length in bytes of the pool name, or -ERANGE if the buffer is not large enough.
1701 int ceph_get_default_data_pool_name(struct ceph_mount_info
*cmount
, char *buf
, size_t buflen
);
1704 * Get the file layout from an open file descriptor.
1706 * @param cmount the ceph mount handle to use.
1707 * @param fh the open file descriptor referring to the file to get the layout of.
1708 * @param stripe_unit where to store the striping unit of the file
1709 * @param stripe_count where to store the striping count of the file
1710 * @param object_size where to store the object size of the file
1711 * @param pg_pool where to store the ceph pool id that the file is in
1712 * @returns 0 on success or a negative error code on failure.
1714 int ceph_get_file_layout(struct ceph_mount_info
*cmount
, int fh
, int *stripe_unit
, int *stripe_count
, int *object_size
, int *pg_pool
);
1717 * Get the file layout.
1719 * @param cmount the ceph mount handle to use.
1720 * @param path the path of the file/directory get the layout of.
1721 * @param stripe_unit where to store the striping unit of the file
1722 * @param stripe_count where to store the striping count of the file
1723 * @param object_size where to store the object size of the file
1724 * @param pg_pool where to store the ceph pool id that the file is in
1725 * @returns 0 on success or a negative error code on failure.
1727 int ceph_get_path_layout(struct ceph_mount_info
*cmount
, const char *path
, int *stripe_unit
, int *stripe_count
, int *object_size
, int *pg_pool
);
1730 * Get the file replication information from an open file descriptor.
1732 * @param cmount the ceph mount handle to use.
1733 * @param fh the open file descriptor referring to the file to get the replication information of.
1734 * @returns the replication factor of the file.
1736 int ceph_get_file_replication(struct ceph_mount_info
*cmount
, int fh
);
1739 * Get the file replication information.
1741 * @param cmount the ceph mount handle to use.
1742 * @param path the path of the file/directory get the replication information of.
1743 * @returns the replication factor of the file.
1745 int ceph_get_path_replication(struct ceph_mount_info
*cmount
, const char *path
);
1748 * Get the id of the named pool.
1750 * @param cmount the ceph mount handle to use.
1751 * @param pool_name the name of the pool.
1752 * @returns the pool id, or a negative error code on failure.
1754 int ceph_get_pool_id(struct ceph_mount_info
*cmount
, const char *pool_name
);
1757 * Get the pool replication factor.
1759 * @param cmount the ceph mount handle to use.
1760 * @param pool_id the pool id to look up
1761 * @returns the replication factor, or a negative error code on failure.
1763 int ceph_get_pool_replication(struct ceph_mount_info
*cmount
, int pool_id
);
1766 * Get the OSD address where the primary copy of a file stripe is located.
1768 * @param cmount the ceph mount handle to use.
1769 * @param fd the open file descriptor referring to the file to get the striping unit of.
1770 * @param offset the offset into the file to specify the stripe. The offset can be
1771 * anywhere within the stripe unit.
1772 * @param addr the address of the OSD holding that stripe
1773 * @param naddr the capacity of the address passed in.
1774 * @returns the size of the addressed filled into the @e addr parameter, or a negative
1775 * error code on failure.
1777 int ceph_get_file_stripe_address(struct ceph_mount_info
*cmount
, int fd
, int64_t offset
,
1778 struct sockaddr_storage
*addr
, int naddr
);
1781 * Get the list of OSDs where the objects containing a file offset are located.
1783 * @param cmount the ceph mount handle to use.
1784 * @param fd the open file descriptor referring to the file.
1785 * @param offset the offset within the file.
1786 * @param length return the number of bytes between the offset and the end of
1787 * the stripe unit (optional).
1788 * @param osds an integer array to hold the OSD ids.
1789 * @param nosds the size of the integer array.
1790 * @returns the number of items stored in the output array, or -ERANGE if the
1791 * array is not large enough.
1793 int ceph_get_file_extent_osds(struct ceph_mount_info
*cmount
, int fd
,
1794 int64_t offset
, int64_t *length
, int *osds
, int nosds
);
1797 * Get the fully qualified CRUSH location of an OSD.
1799 * Returns (type, name) string pairs for each device in the CRUSH bucket
1800 * hierarchy starting from the given osd to the root. Each pair element is
1801 * separated by a NULL character.
1803 * @param cmount the ceph mount handle to use.
1804 * @param osd the OSD id.
1805 * @param path buffer to store location.
1806 * @param len size of buffer.
1807 * @returns the amount of bytes written into the buffer, or -ERANGE if the
1808 * array is not large enough.
1810 int ceph_get_osd_crush_location(struct ceph_mount_info
*cmount
,
1811 int osd
, char *path
, size_t len
);
1814 * Get the network address of an OSD.
1816 * @param cmount the ceph mount handle.
1817 * @param osd the OSD id.
1818 * @param addr the OSD network address.
1819 * @returns zero on success, other returns a negative error code.
1821 int ceph_get_osd_addr(struct ceph_mount_info
*cmount
, int osd
,
1822 struct sockaddr_storage
*addr
);
1825 * Get the file layout stripe unit granularity.
1826 * @param cmount the ceph mount handle.
1827 * @returns the stripe unit granularity or a negative error code on failure.
1829 int ceph_get_stripe_unit_granularity(struct ceph_mount_info
*cmount
);
1831 /** @} filelayout */
1834 * No longer available. Do not use.
1835 * These functions will return -EOPNOTSUPP.
1837 int ceph_set_default_file_stripe_unit(struct ceph_mount_info
*cmount
, int stripe
);
1838 int ceph_set_default_file_stripe_count(struct ceph_mount_info
*cmount
, int count
);
1839 int ceph_set_default_object_size(struct ceph_mount_info
*cmount
, int size
);
1840 int ceph_set_default_preferred_pg(struct ceph_mount_info
*cmount
, int osd
);
1841 int ceph_set_default_file_replication(struct ceph_mount_info
*cmount
, int replication
);
1844 * Read from local replicas when possible.
1846 * @param cmount the ceph mount handle to use.
1847 * @param val a boolean to set (1) or clear (0) the option to favor local objects
1851 int ceph_localize_reads(struct ceph_mount_info
*cmount
, int val
);
1854 * Get the osd id of the local osd (if any)
1856 * @param cmount the ceph mount handle to use.
1857 * @returns the osd (if any) local to the node where this call is made, otherwise
1860 int ceph_get_local_osd(struct ceph_mount_info
*cmount
);
1862 /** @} default_filelayout */
1865 * Get the capabilities currently issued to the client.
1867 * @param cmount the ceph mount handle to use.
1868 * @param fd the file descriptor to get issued
1869 * @returns the current capabilities issued to this client
1872 int ceph_debug_get_fd_caps(struct ceph_mount_info
*cmount
, int fd
);
1875 * Get the capabilities currently issued to the client.
1877 * @param cmount the ceph mount handle to use.
1878 * @param path the path to the file
1879 * @returns the current capabilities issued to this client
1882 int ceph_debug_get_file_caps(struct ceph_mount_info
*cmount
, const char *path
);
1885 struct Inode
*ceph_ll_get_inode(struct ceph_mount_info
*cmount
,
1888 int ceph_ll_lookup_vino(struct ceph_mount_info
*cmount
, vinodeno_t vino
,
1891 int ceph_ll_lookup_inode(
1892 struct ceph_mount_info
*cmount
,
1893 struct inodeno_t ino
,
1897 * Get the root inode of FS. Increase counter of references for root Inode. You must call ceph_ll_forget for it!
1899 * @param cmount the ceph mount handle to use.
1900 * @param parent pointer to pointer to Inode struct. Pointer to root inode will be returned
1901 * @returns 0 if all good
1903 int ceph_ll_lookup_root(struct ceph_mount_info
*cmount
,
1905 int ceph_ll_lookup(struct ceph_mount_info
*cmount
, Inode
*parent
,
1906 const char *name
, Inode
**out
, struct ceph_statx
*stx
,
1907 unsigned want
, unsigned flags
, const UserPerm
*perms
);
1908 int ceph_ll_put(struct ceph_mount_info
*cmount
, struct Inode
*in
);
1909 int ceph_ll_forget(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1911 int ceph_ll_walk(struct ceph_mount_info
*cmount
, const char* name
, Inode
**i
,
1912 struct ceph_statx
*stx
, unsigned int want
, unsigned int flags
,
1913 const UserPerm
*perms
);
1914 int ceph_ll_getattr(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1915 struct ceph_statx
*stx
, unsigned int want
, unsigned int flags
,
1916 const UserPerm
*perms
);
1917 int ceph_ll_setattr(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1918 struct ceph_statx
*stx
, int mask
, const UserPerm
*perms
);
1919 int ceph_ll_open(struct ceph_mount_info
*cmount
, struct Inode
*in
, int flags
,
1920 struct Fh
**fh
, const UserPerm
*perms
);
1921 off_t
ceph_ll_lseek(struct ceph_mount_info
*cmount
, struct Fh
* filehandle
,
1922 off_t offset
, int whence
);
1923 int ceph_ll_read(struct ceph_mount_info
*cmount
, struct Fh
* filehandle
,
1924 int64_t off
, uint64_t len
, char* buf
);
1925 int ceph_ll_fsync(struct ceph_mount_info
*cmount
, struct Fh
*fh
,
1927 int ceph_ll_sync_inode(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1929 int ceph_ll_fallocate(struct ceph_mount_info
*cmount
, struct Fh
*fh
,
1930 int mode
, int64_t offset
, int64_t length
);
1931 int ceph_ll_write(struct ceph_mount_info
*cmount
, struct Fh
* filehandle
,
1932 int64_t off
, uint64_t len
, const char *data
);
1933 int64_t ceph_ll_readv(struct ceph_mount_info
*cmount
, struct Fh
*fh
,
1934 const struct iovec
*iov
, int iovcnt
, int64_t off
);
1935 int64_t ceph_ll_writev(struct ceph_mount_info
*cmount
, struct Fh
*fh
,
1936 const struct iovec
*iov
, int iovcnt
, int64_t off
);
1937 int ceph_ll_close(struct ceph_mount_info
*cmount
, struct Fh
* filehandle
);
1938 int ceph_ll_iclose(struct ceph_mount_info
*cmount
, struct Inode
*in
, int mode
);
1940 * Get xattr value by xattr name.
1942 * @param cmount the ceph mount handle to use.
1943 * @param in file handle
1944 * @param name name of attribute
1945 * @param value pointer to begin buffer
1946 * @param size buffer size
1947 * @param perms pointer to UserPerms object
1948 * @returns size of returned buffer. Negative number in error case
1950 int ceph_ll_getxattr(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1951 const char *name
, void *value
, size_t size
,
1952 const UserPerm
*perms
);
1953 int ceph_ll_setxattr(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1954 const char *name
, const void *value
, size_t size
,
1955 int flags
, const UserPerm
*perms
);
1956 int ceph_ll_listxattr(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1957 char *list
, size_t buf_size
, size_t *list_size
,
1958 const UserPerm
*perms
);
1959 int ceph_ll_removexattr(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1960 const char *name
, const UserPerm
*perms
);
1961 int ceph_ll_create(struct ceph_mount_info
*cmount
, Inode
*parent
,
1962 const char *name
, mode_t mode
, int oflags
, Inode
**outp
,
1963 Fh
**fhp
, struct ceph_statx
*stx
, unsigned want
,
1964 unsigned lflags
, const UserPerm
*perms
);
1965 int ceph_ll_mknod(struct ceph_mount_info
*cmount
, Inode
*parent
,
1966 const char *name
, mode_t mode
, dev_t rdev
, Inode
**out
,
1967 struct ceph_statx
*stx
, unsigned want
, unsigned flags
,
1968 const UserPerm
*perms
);
1969 int ceph_ll_mkdir(struct ceph_mount_info
*cmount
, Inode
*parent
,
1970 const char *name
, mode_t mode
, Inode
**out
,
1971 struct ceph_statx
*stx
, unsigned want
,
1972 unsigned flags
, const UserPerm
*perms
);
1973 int ceph_ll_link(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1974 struct Inode
*newparent
, const char *name
,
1975 const UserPerm
*perms
);
1976 int ceph_ll_opendir(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1977 struct ceph_dir_result
**dirpp
, const UserPerm
*perms
);
1978 int ceph_ll_releasedir(struct ceph_mount_info
*cmount
,
1979 struct ceph_dir_result
* dir
);
1980 int ceph_ll_rename(struct ceph_mount_info
*cmount
, struct Inode
*parent
,
1981 const char *name
, struct Inode
*newparent
,
1982 const char *newname
, const UserPerm
*perms
);
1983 int ceph_ll_unlink(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1984 const char *name
, const UserPerm
*perms
);
1985 int ceph_ll_statfs(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1986 struct statvfs
*stbuf
);
1987 int ceph_ll_readlink(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1988 char *buf
, size_t bufsize
, const UserPerm
*perms
);
1989 int ceph_ll_symlink(struct ceph_mount_info
*cmount
,
1990 Inode
*in
, const char *name
, const char *value
,
1991 Inode
**out
, struct ceph_statx
*stx
,
1992 unsigned want
, unsigned flags
,
1993 const UserPerm
*perms
);
1994 int ceph_ll_rmdir(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1995 const char *name
, const UserPerm
*perms
);
1996 uint32_t ceph_ll_stripe_unit(struct ceph_mount_info
*cmount
,
1998 uint32_t ceph_ll_file_layout(struct ceph_mount_info
*cmount
,
2000 struct ceph_file_layout
*layout
);
2001 uint64_t ceph_ll_snap_seq(struct ceph_mount_info
*cmount
,
2003 int ceph_ll_get_stripe_osd(struct ceph_mount_info
*cmount
,
2006 struct ceph_file_layout
* layout
);
2007 int ceph_ll_num_osds(struct ceph_mount_info
*cmount
);
2008 int ceph_ll_osdaddr(struct ceph_mount_info
*cmount
,
2009 int osd
, uint32_t *addr
);
2010 uint64_t ceph_ll_get_internal_offset(struct ceph_mount_info
*cmount
,
2011 struct Inode
*in
, uint64_t blockno
);
2012 int ceph_ll_read_block(struct ceph_mount_info
*cmount
,
2013 struct Inode
*in
, uint64_t blockid
,
2014 char* bl
, uint64_t offset
, uint64_t length
,
2015 struct ceph_file_layout
* layout
);
2016 int ceph_ll_write_block(struct ceph_mount_info
*cmount
,
2017 struct Inode
*in
, uint64_t blockid
,
2018 char* buf
, uint64_t offset
,
2019 uint64_t length
, struct ceph_file_layout
* layout
,
2020 uint64_t snapseq
, uint32_t sync
);
2021 int ceph_ll_commit_blocks(struct ceph_mount_info
*cmount
,
2022 struct Inode
*in
, uint64_t offset
, uint64_t range
);
2025 int ceph_ll_getlk(struct ceph_mount_info
*cmount
,
2026 Fh
*fh
, struct flock
*fl
, uint64_t owner
);
2027 int ceph_ll_setlk(struct ceph_mount_info
*cmount
,
2028 Fh
*fh
, struct flock
*fl
, uint64_t owner
, int sleep
);
2030 int ceph_ll_lazyio(struct ceph_mount_info
*cmount
, Fh
*fh
, int enable
);
2033 * Delegation support
2035 * Delegations are way for an application to request exclusive or
2036 * semi-exclusive access to an Inode. The client requests the delegation and
2037 * if it's successful it can reliably cache file data and metadata until the
2038 * delegation is recalled.
2040 * Recalls are issued via a callback function, provided by the application.
2041 * Callback functions should act something like signal handlers. You want to
2042 * do as little as possible in the callback. Any major work should be deferred
2043 * in some fashion as it's difficult to predict the context in which this
2044 * function will be called.
2046 * Once the delegation has been recalled, the application should return it as
2047 * soon as possible. The application has client_deleg_timeout seconds to
2048 * return it, after which the cmount structure is forcibly unmounted and
2049 * further calls into it fail.
2051 * The application can set the client_deleg_timeout config option to suit its
2052 * needs, but it should take care to choose a value that allows it to avoid
2053 * forcible eviction from the cluster in the event of an application bug.
2056 /* Commands for manipulating delegation state */
2057 #ifndef CEPH_DELEGATION_NONE
2058 # define CEPH_DELEGATION_NONE 0
2059 # define CEPH_DELEGATION_RD 1
2060 # define CEPH_DELEGATION_WR 2
2064 * Get the amount of time that the client has to return caps
2065 * @param cmount the ceph mount handle to use.
2067 * In the event that a client does not return its caps, the MDS may blocklist
2068 * it after this timeout. Applications should check this value and ensure
2069 * that they set the delegation timeout to a value lower than this.
2071 * This call returns the cap return timeout (in seconds) for this cmount, or
2072 * zero if it's not mounted.
2074 uint32_t ceph_get_cap_return_timeout(struct ceph_mount_info
*cmount
);
2077 * Set the delegation timeout for the mount (thereby enabling delegations)
2078 * @param cmount the ceph mount handle to use.
2079 * @param timeout the delegation timeout (in seconds)
2081 * Since the client could end up blocklisted if it doesn't return delegations
2082 * in time, we mandate that any application wanting to use delegations
2083 * explicitly set the timeout beforehand. Until this call is done on the
2084 * mount, attempts to set a delegation will return -ETIME.
2086 * Once a delegation is recalled, if it is not returned in this amount of
2087 * time, the cmount will be forcibly unmounted and further access attempts
2088 * will fail (usually with -ENOTCONN errors).
2090 * This value is further vetted against the cap return timeout, and this call
2091 * can fail with -EINVAL if the timeout value is too long. Delegations can be
2092 * disabled again by setting the timeout to 0.
2094 int ceph_set_deleg_timeout(struct ceph_mount_info
*cmount
, uint32_t timeout
);
2097 * Request a delegation on an open Fh
2098 * @param cmount the ceph mount handle to use.
2099 * @param fh file handle
2100 * @param cmd CEPH_DELEGATION_* command
2101 * @param cb callback function for recalling delegation
2102 * @param priv opaque token passed back during recalls
2104 * Returns 0 if the delegation was granted, -EAGAIN if there was a conflict
2105 * and other error codes if there is a fatal error of some sort (e.g. -ENOMEM,
2108 int ceph_ll_delegation(struct ceph_mount_info
*cmount
, Fh
*fh
,
2109 unsigned int cmd
, ceph_deleg_cb_t cb
, void *priv
);
2111 mode_t
ceph_umask(struct ceph_mount_info
*cmount
, mode_t mode
);
2114 #define CEPH_RECLAIM_RESET 1
2117 * Set ceph client uuid
2118 * @param cmount the ceph mount handle to use.
2119 * @param uuid the uuid to set
2121 * Must be called before mount.
2123 void ceph_set_uuid(struct ceph_mount_info
*cmount
, const char *uuid
);
2126 * Set ceph client session timeout
2127 * @param cmount the ceph mount handle to use.
2128 * @param timeout the timeout to set
2130 * Must be called before mount.
2132 void ceph_set_session_timeout(struct ceph_mount_info
*cmount
, unsigned timeout
);
2135 * Start to reclaim states of other client
2136 * @param cmount the ceph mount handle to use.
2137 * @param uuid uuid of client whose states need to be reclaimed
2138 * @param flags flags that control how states get reclaimed
2140 * Returns 0 success, -EOPNOTSUPP if mds does not support the operation,
2141 * -ENOENT if CEPH_RECLAIM_RESET is specified and there is no client
2142 * with the given uuid, -ENOTRECOVERABLE in all other error cases.
2144 int ceph_start_reclaim(struct ceph_mount_info
*cmount
,
2145 const char *uuid
, unsigned flags
);
2148 * finish reclaiming states of other client (
2149 * @param cmount the ceph mount handle to use.
2151 void ceph_finish_reclaim(struct ceph_mount_info
*cmount
);
2154 * Register a set of callbacks to be used with this cmount
2156 * This is deprecated, use ceph_ll_register_callbacks2() instead.
2158 * @param cmount the ceph mount handle on which the cb's should be registerd
2159 * @param args callback arguments to register with the cmount
2161 * Any fields set to NULL will be ignored. There currently is no way to
2162 * unregister these callbacks, so this is a one-way change.
2164 void ceph_ll_register_callbacks(struct ceph_mount_info
*cmount
,
2165 struct ceph_client_callback_args
*args
);
2168 * Register a set of callbacks to be used with this cmount
2169 * @param cmount the ceph mount handle on which the cb's should be registerd
2170 * @param args callback arguments to register with the cmount
2172 * Any fields set to NULL will be ignored. There currently is no way to
2173 * unregister these callbacks, so this is a one-way change.
2175 * Returns 0 on success or -EBUSY if the cmount is mounting or already mounted.
2177 int ceph_ll_register_callbacks2(struct ceph_mount_info
*cmount
,
2178 struct ceph_client_callback_args
*args
);
2183 * @param cmount the ceph mount handle to use for making the directory.
2184 * @param path the path of the snapshot. This must be either an
2185 * absolute path or a relative path off of the current working directory.
2186 * @returns 0 on success or a negative return code on error.
2188 int ceph_get_snap_info(struct ceph_mount_info
*cmount
,
2189 const char *path
, struct snap_info
*snap_info
);
2192 * Free snapshot info buffers
2194 * @param snap_info snapshot info struct (fetched via call to ceph_get_snap_info()).
2196 void ceph_free_snap_info_buffer(struct snap_info
*snap_info
);