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>
31 #include "ceph_ll_client.h"
34 namespace ceph::common
{
37 using CephContext
= ceph::common::CephContext
;
41 #define LIBCEPHFS_VER_MAJOR 10
42 #define LIBCEPHFS_VER_MINOR 0
43 #define LIBCEPHFS_VER_EXTRA 3
45 #define LIBCEPHFS_VERSION(maj, min, extra) ((maj << 16) + (min << 8) + extra)
46 #define LIBCEPHFS_VERSION_CODE LIBCEPHFS_VERSION(LIBCEPHFS_VER_MAJOR, LIBCEPHFS_VER_MINOR, LIBCEPHFS_VER_EXTRA)
49 #define LIBCEPHFS_DEPRECATED __attribute__((deprecated))
50 #pragma GCC diagnostic push
51 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
53 #define LIBCEPHFS_DEPRECATED
57 * If using glibc check that file offset is 64-bit.
59 #if defined(__GLIBC__) && !defined(__USE_FILE_OFFSET64)
60 # error libceph: glibc must define __USE_FILE_OFFSET64 or readdir results will be corrupted
64 * XXXX redeclarations from ceph_fs.h, rados.h, etc. We need more of this
65 * in the interface, but shouldn't be re-typing it (and using different
70 #define CEPH_INO_ROOT 1
71 #define CEPH_NOSNAP ((uint64_t)(-2))
73 struct ceph_file_layout
{
74 /* file -> object mapping */
75 uint32_t fl_stripe_unit
; /* stripe unit, in bytes. must be multiple
77 uint32_t fl_stripe_count
; /* over this many objects */
78 uint32_t fl_object_size
; /* until objects are this big, then move to
80 uint32_t fl_cas_hash
; /* 0 = none; 1 = sha256 */
82 /* pg -> disk layout */
83 uint32_t fl_object_stripe_unit
; /* for per-object parity, if any */
85 /* object -> pg layout */
86 uint32_t fl_pg_preferred
; /* preferred primary for pg (-1 for none) */
87 uint32_t fl_pg_pool
; /* namespace, crush rule, rep level */
88 } __attribute__ ((packed
));
91 #endif /* ! __cplusplus */
94 typedef struct UserPerm UserPerm
;
97 typedef struct Inode Inode
;
99 struct ceph_mount_info
;
100 struct ceph_dir_result
;
102 // user supplied key,value pair to be associated with a snapshot.
103 // callers can supply an array of this struct via ceph_mksnap().
104 struct snap_metadata
{
111 size_t nr_snap_metadata
;
112 struct snap_metadata
*snap_metadata
;
115 /* setattr mask bits */
116 #ifndef CEPH_SETATTR_MODE
117 # define CEPH_SETATTR_MODE 1
118 # define CEPH_SETATTR_UID 2
119 # define CEPH_SETATTR_GID 4
120 # define CEPH_SETATTR_MTIME 8
121 # define CEPH_SETATTR_ATIME 16
122 # define CEPH_SETATTR_SIZE 32
123 # define CEPH_SETATTR_CTIME 64
124 # define CEPH_SETATTR_MTIME_NOW 128
125 # define CEPH_SETATTR_ATIME_NOW 256
126 # define CEPH_SETATTR_BTIME 512
129 /* define error codes for the mount function*/
130 # define CEPHFS_ERROR_MON_MAP_BUILD 1000
131 # define CEPHFS_ERROR_NEW_CLIENT 1002
132 # define CEPHFS_ERROR_MESSENGER_START 1003
135 * Create a UserPerm credential object.
137 * Some calls (most notably, the ceph_ll_* ones), take a credential object
138 * that represents the credentials that the calling program is using. This
139 * function creates a new credential object for this purpose. Returns a
140 * pointer to the object, or NULL if it can't be allocated.
142 * Note that the gidlist array is used directly and is not copied. It must
143 * remain valid over the lifetime of the created UserPerm object.
145 * @param uid uid to be used
146 * @param gid gid to be used
147 * @param ngids number of gids in supplemental grouplist
148 * @param gidlist array of gid_t's in the list of groups
150 UserPerm
*ceph_userperm_new(uid_t uid
, gid_t gid
, int ngids
, gid_t
*gidlist
);
153 * Destroy a UserPerm credential object.
155 * @param perm pointer to object to be destroyed
157 * Currently this just frees the object. Note that the gidlist array is not
158 * freed. The caller must do so if it's necessary.
160 void ceph_userperm_destroy(UserPerm
*perm
);
163 * Get a pointer to the default UserPerm object for the mount.
165 * @param cmount the mount info handle
167 * Every cmount has a default set of credentials. This returns a pointer to
170 * Unlike with ceph_userperm_new, this object should not be freed.
172 struct UserPerm
*ceph_mount_perms(struct ceph_mount_info
*cmount
);
175 * Set cmount's default permissions
177 * @param cmount the mount info handle
178 * @param perm permissions to set to default for mount
180 * Every cmount has a default set of credentials. This does a deep copy of
181 * the given permissions to the ones in the cmount. Must be done after
182 * ceph_init but before ceph_mount.
184 * Returns 0 on success, and -EISCONN if the cmount is already mounted.
186 int ceph_mount_perms_set(struct ceph_mount_info
*cmount
, UserPerm
*perm
);
189 * @defgroup libcephfs_h_init Setup and Teardown
190 * These are the first and last functions that should be called
191 * when using libcephfs.
197 * Get the version of libcephfs.
199 * The version number is major.minor.patch.
201 * @param major where to store the major version number
202 * @param minor where to store the minor version number
203 * @param patch where to store the extra version number
205 const char *ceph_version(int *major
, int *minor
, int *patch
);
208 * Create a mount handle for interacting with Ceph. All libcephfs
209 * functions operate on a mount info handle.
211 * @param cmount the mount info handle to initialize
212 * @param id the id of the client. This can be a unique id that identifies
213 * this client, and will get appended onto "client.". Callers can
214 * pass in NULL, and the id will be the process id of the client.
215 * @returns 0 on success, negative error code on failure
217 int ceph_create(struct ceph_mount_info
**cmount
, const char * const id
);
220 * Create a mount handle from a CephContext, which holds the configuration
221 * for the ceph cluster. A CephContext can be acquired from an existing ceph_mount_info
222 * handle, using the @ref ceph_get_mount_context call. Note that using the same CephContext
223 * for two different mount handles results in the same client entity id being used.
225 * @param cmount the mount info handle to initialize
226 * @param conf reuse this pre-existing CephContext config
227 * @returns 0 on success, negative error code on failure
230 int ceph_create_with_context(struct ceph_mount_info
**cmount
, CephContext
*conf
);
232 int ceph_create_with_context(struct ceph_mount_info
**cmount
, struct CephContext
*conf
);
235 #ifndef VOIDPTR_RADOS_T
236 #define VOIDPTR_RADOS_T
237 typedef void *rados_t
;
238 #endif // VOIDPTR_RADOS_T
241 * Create a mount handle from a rados_t, for using libcephfs in the
242 * same process as librados.
244 * @param cmount the mount info handle to initialize
245 * @param cluster reference to already-initialized librados handle
246 * @returns 0 on success, negative error code on failure
248 int ceph_create_from_rados(struct ceph_mount_info
**cmount
, rados_t cluster
);
251 * Initialize the filesystem client (but do not mount the filesystem yet)
253 * @returns 0 on success, negative error code on failure
255 int ceph_init(struct ceph_mount_info
*cmount
);
258 * Optionally set which filesystem to mount, before calling mount.
260 * An error will be returned if this libcephfs instance is already
261 * mounted. This function is an alternative to setting the global
262 * client_fs setting. Using this function enables multiple libcephfs
263 * instances in the same process to mount different filesystems.
265 * The filesystem name is *not* validated in this function. That happens
266 * during mount(), where an ENOENT error will result if a non-existent
267 * filesystem was specified here.
269 * @param cmount the mount info handle
270 * @returns 0 on success, negative error code on failure
272 int ceph_select_filesystem(struct ceph_mount_info
*cmount
, const char *fs_name
);
276 * Perform a mount using the path for the root of the mount.
278 * It is optional to call ceph_init before this. If ceph_init has
279 * not already been called, it will be called in the course of this operation.
281 * @param cmount the mount info handle
282 * @param root the path for the root of the mount. This can be an existing
283 * directory within the ceph cluster, but most likely it will
284 * be "/". Passing in NULL is equivalent to "/".
285 * @returns 0 on success, negative error code on failure
287 int ceph_mount(struct ceph_mount_info
*cmount
, const char *root
);
290 * Return cluster ID for a mounted ceph filesystem
292 * Every ceph filesystem has a filesystem ID associated with it. This
293 * function returns that value. If the ceph_mount_info does not refer to a
294 * mounted filesystem, this returns a negative error code.
296 int64_t ceph_get_fs_cid(struct ceph_mount_info
*cmount
);
299 * Execute a management command remotely on an MDS.
301 * Must have called ceph_init or ceph_mount before calling this.
303 * @param mds_spec string representing rank, MDS name, GID or '*'
304 * @param cmd array of null-terminated strings
305 * @param cmdlen length of cmd array
306 * @param inbuf non-null-terminated input data to command
307 * @param inbuflen length in octets of inbuf
308 * @param outbuf populated with pointer to buffer (command output data)
309 * @param outbuflen length of allocated outbuf
310 * @param outs populated with pointer to buffer (command error strings)
311 * @param outslen length of allocated outs
313 * @return 0 on success, negative error code on failure
316 int ceph_mds_command(struct ceph_mount_info
*cmount
,
317 const char *mds_spec
,
320 const char *inbuf
, size_t inbuflen
,
321 char **outbuf
, size_t *outbuflen
,
322 char **outs
, size_t *outslen
);
325 * Free a buffer, such as those used for output arrays from ceph_mds_command
327 void ceph_buffer_free(char *buf
);
330 * Unmount a mount handle.
332 * @param cmount the mount handle
333 * @return 0 on success, negative error code on failure
335 int ceph_unmount(struct ceph_mount_info
*cmount
);
338 * Abort mds connections
340 * @param cmount the mount handle
341 * @return 0 on success, negative error code on failure
343 int ceph_abort_conn(struct ceph_mount_info
*cmount
);
346 * Destroy the mount handle.
348 * The handle should not be mounted. This should be called on completion of
349 * all libcephfs functions.
351 * @param cmount the mount handle
352 * @return 0 on success, negative error code on failure.
354 int ceph_release(struct ceph_mount_info
*cmount
);
357 * Deprecated. Unmount and destroy the ceph mount handle. This should be
358 * called on completion of all libcephfs functions.
360 * Equivalent to ceph_unmount() + ceph_release() without error handling.
362 * @param cmount the mount handle to shutdown
364 void ceph_shutdown(struct ceph_mount_info
*cmount
);
367 * Return associated client addresses
369 * @param cmount the mount handle
370 * @param addrs the output addresses
371 * @returns 0 on success, a negative error code on failure
372 * @note the returned addrs should be free by the caller
374 int ceph_getaddrs(struct ceph_mount_info
*cmount
, char** addrs
);
377 * Get a global id for current instance
379 * The handle should not be mounted. This should be called on completion of
380 * all libcephfs functions.
382 * @param cmount the mount handle
383 * @returns instance global id
385 uint64_t ceph_get_instance_id(struct ceph_mount_info
*cmount
);
388 * Extract the CephContext from the mount point handle.
390 * @param cmount the ceph mount handle to get the context from.
391 * @returns the CephContext associated with the mount handle.
394 CephContext
*ceph_get_mount_context(struct ceph_mount_info
*cmount
);
396 struct CephContext
*ceph_get_mount_context(struct ceph_mount_info
*cmount
);
399 * Check mount status.
401 * Return non-zero value if mounted. Otherwise, zero.
403 int ceph_is_mounted(struct ceph_mount_info
*cmount
);
408 * @defgroup libcephfs_h_config Config
409 * Functions for manipulating the Ceph configuration at runtime.
415 * Load the ceph configuration from the specified config file.
417 * @param cmount the mount handle to load the configuration into.
418 * @param path_list the configuration file path
419 * @returns 0 on success, negative error code on failure
421 int ceph_conf_read_file(struct ceph_mount_info
*cmount
, const char *path_list
);
424 * Parse the command line arguments and load the configuration parameters.
426 * @param cmount the mount handle to load the configuration parameters into.
427 * @param argc count of the arguments in argv
428 * @param argv the argument list
429 * @returns 0 on success, negative error code on failure
431 int ceph_conf_parse_argv(struct ceph_mount_info
*cmount
, int argc
, const char **argv
);
434 * Configure the cluster handle based on an environment variable
436 * The contents of the environment variable are parsed as if they were
437 * Ceph command line options. If var is NULL, the CEPH_ARGS
438 * environment variable is used.
440 * @pre ceph_mount() has not been called on the handle
442 * @note BUG: this is not threadsafe - it uses a static buffer
444 * @param cmount handle to configure
445 * @param var name of the environment variable to read
446 * @returns 0 on success, negative error code on failure
448 int ceph_conf_parse_env(struct ceph_mount_info
*cmount
, const char *var
);
450 /** Sets a configuration value from a string.
452 * @param cmount the mount handle to set the configuration value on
453 * @param option the configuration option to set
454 * @param value the value of the configuration option to set
456 * @returns 0 on success, negative error code otherwise.
458 int ceph_conf_set(struct ceph_mount_info
*cmount
, const char *option
, const char *value
);
460 /** Set mount timeout.
462 * @param cmount mount handle to set the configuration value on
463 * @param timeout mount timeout interval
465 * @returns 0 on success, negative error code otherwise.
467 int ceph_set_mount_timeout(struct ceph_mount_info
*cmount
, uint32_t timeout
);
470 * Gets the configuration value as a string.
472 * @param cmount the mount handle to set the configuration value on
473 * @param option the config option to get
474 * @param buf the buffer to fill with the value
475 * @param len the length of the buffer.
476 * @returns the size of the buffer filled in with the value, or negative error code on failure
478 int ceph_conf_get(struct ceph_mount_info
*cmount
, const char *option
, char *buf
, size_t len
);
483 * @defgroup libcephfs_h_fsops File System Operations.
484 * Functions for getting/setting file system wide information specific to a particular
491 * Perform a statfs on the ceph file system. This call fills in file system wide statistics
492 * into the passed in buffer.
494 * @param cmount the ceph mount handle to use for performing the statfs.
495 * @param path can be any path within the mounted filesystem
496 * @param stbuf the file system statistics filled in by this function.
497 * @return 0 on success, negative error code otherwise.
499 int ceph_statfs(struct ceph_mount_info
*cmount
, const char *path
, struct statvfs
*stbuf
);
502 * Synchronize all filesystem data to persistent media.
504 * @param cmount the ceph mount handle to use for performing the sync_fs.
505 * @returns 0 on success or negative error code on failure.
507 int ceph_sync_fs(struct ceph_mount_info
*cmount
);
510 * Get the current working directory.
512 * @param cmount the ceph mount to get the current working directory for.
513 * @returns the path to the current working directory
515 const char* ceph_getcwd(struct ceph_mount_info
*cmount
);
518 * Change the current working directory.
520 * @param cmount the ceph mount to change the current working directory for.
521 * @param path the path to the working directory to change into.
522 * @returns 0 on success, negative error code otherwise.
524 int ceph_chdir(struct ceph_mount_info
*cmount
, const char *path
);
529 * @defgroup libcephfs_h_dir Directory Operations.
530 * Functions for manipulating and listing directories.
536 * Open the given directory.
538 * @param cmount the ceph mount handle to use to open the directory
539 * @param name the path name of the directory to open. Must be either an absolute path
540 * or a path relative to the current working directory.
541 * @param dirpp the directory result pointer structure to fill in.
542 * @returns 0 on success or negative error code otherwise.
544 int ceph_opendir(struct ceph_mount_info
*cmount
, const char *name
, struct ceph_dir_result
**dirpp
);
547 * Open a directory referred to by a file descriptor
549 * @param cmount the ceph mount handle to use to open the directory
550 * @param dirfd open file descriptor for the directory
551 * @param dirpp the directory result pointer structure to fill in
552 * @returns 0 on success or negative error code otherwise
554 int ceph_fdopendir(struct ceph_mount_info
*cmount
, int dirfd
, struct ceph_dir_result
**dirpp
);
557 * Close the open directory.
559 * @param cmount the ceph mount handle to use for closing the directory
560 * @param dirp the directory result pointer (set by ceph_opendir) to close
561 * @returns 0 on success or negative error code on failure.
563 int ceph_closedir(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
);
566 * Get the next entry in an open directory.
568 * @param cmount the ceph mount handle to use for performing the readdir.
569 * @param dirp the directory stream pointer from an opendir holding the state of the
570 * next entry to return.
571 * @returns the next directory entry or NULL if at the end of the directory (or the directory
572 * is empty. This pointer should not be freed by the caller, and is only safe to
573 * access between return and the next call to ceph_readdir or ceph_closedir.
575 struct dirent
* ceph_readdir(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
);
578 * A safe version of ceph_readdir, where the directory entry struct is allocated by the caller.
580 * @param cmount the ceph mount handle to use for performing the readdir.
581 * @param dirp the directory stream pointer from an opendir holding the state of the
582 * next entry to return.
583 * @param de the directory entry pointer filled in with the next directory entry of the dirp state.
584 * @returns 1 if the next entry was filled in, 0 if the end of the directory stream was reached,
585 * and a negative error code on failure.
587 int ceph_readdir_r(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
, struct dirent
*de
);
590 * A safe version of ceph_readdir that also returns the file statistics (readdir+stat).
592 * @param cmount the ceph mount handle to use for performing the readdir_plus_r.
593 * @param dirp the directory stream pointer from an opendir holding the state of the
594 * next entry to return.
595 * @param de the directory entry pointer filled in with the next directory entry of the dirp state.
596 * @param stx the stats of the file/directory of the entry returned
597 * @param want mask showing desired inode attrs for returned entry
598 * @param flags bitmask of flags to use when filling out attributes
599 * @param out optional returned Inode argument. If non-NULL, then a reference will be taken on
600 * the inode and the pointer set on success.
601 * @returns 1 if the next entry was filled in, 0 if the end of the directory stream was reached,
602 * and a negative error code on failure.
604 int ceph_readdirplus_r(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
, struct dirent
*de
,
605 struct ceph_statx
*stx
, unsigned want
, unsigned flags
, struct Inode
**out
);
608 * Gets multiple directory entries.
610 * @param cmount the ceph mount handle to use for performing the getdents.
611 * @param dirp the directory stream pointer from an opendir holding the state of the
612 * next entry/entries to return.
613 * @param name an array of struct dirent that gets filled in with the to fill returned directory entries into.
614 * @param buflen the length of the buffer, which should be the number of dirent structs * sizeof(struct dirent).
615 * @returns the length of the buffer that was filled in, will always be multiples of sizeof(struct dirent), or a
616 * negative error code. If the buffer is not large enough for a single entry, -ERANGE is returned.
618 int ceph_getdents(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
, char *name
, int buflen
);
621 * Gets multiple directory names.
623 * @param cmount the ceph mount handle to use for performing the getdents.
624 * @param dirp the directory stream pointer from an opendir holding the state of the
625 * next entry/entries to return.
626 * @param name a buffer to fill in with directory entry names.
627 * @param buflen the length of the buffer that can be filled in.
628 * @returns the length of the buffer filled in with entry names, or a negative error code on failure.
629 * If the buffer isn't large enough for a single entry, -ERANGE is returned.
631 int ceph_getdnames(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
, char *name
, int buflen
);
634 * Rewind the directory stream to the beginning of the directory.
636 * @param cmount the ceph mount handle to use for performing the rewinddir.
637 * @param dirp the directory stream pointer to rewind.
639 void ceph_rewinddir(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
);
642 * Get the current position of a directory stream.
644 * @param cmount the ceph mount handle to use for performing the telldir.
645 * @param dirp the directory stream pointer to get the current position of.
646 * @returns the position of the directory stream. Note that the offsets returned
647 * by ceph_telldir do not have a particular order (cannot be compared with
650 int64_t ceph_telldir(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
);
653 * Move the directory stream to a position specified by the given offset.
655 * @param cmount the ceph mount handle to use for performing the seekdir.
656 * @param dirp the directory stream pointer to move.
657 * @param offset the position to move the directory stream to. This offset should be
658 * a value returned by telldir. Note that this value does not refer to the nth
659 * entry in a directory, and can not be manipulated with plus or minus.
661 void ceph_seekdir(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
, int64_t offset
);
664 * Create a directory.
666 * @param cmount the ceph mount handle to use for making the directory.
667 * @param path the path of the directory to create. This must be either an
668 * absolute path or a relative path off of the current working directory.
669 * @param mode the permissions the directory should have once created.
670 * @returns 0 on success or a negative return code on error.
672 int ceph_mkdir(struct ceph_mount_info
*cmount
, const char *path
, mode_t mode
);
675 * Create a directory relative to a file descriptor
677 * @param cmount the ceph mount handle to use for making the directory.
678 * @param dirfd open file descriptor for a directory (or CEPHFS_AT_FDCWD)
679 * @param relpath the path of the directory to create.
680 * @param mode the permissions the directory should have once created.
681 * @returns 0 on success or a negative return code on error.
683 int ceph_mkdirat(struct ceph_mount_info
*cmount
, int dirfd
, const char *relpath
, mode_t mode
);
688 * @param cmount the ceph mount handle to use for making the directory.
689 * @param path the path of the directory to create snapshot. This must be either an
690 * absolute path or a relative path off of the current working directory.
691 * @param name snapshot name
692 * @param mode the permissions the directory should have once created.
693 * @param snap_metadata array of snap metadata structs
694 * @param nr_snap_metadata number of snap metadata struct entries
695 * @returns 0 on success or a negative return code on error.
697 int ceph_mksnap(struct ceph_mount_info
*cmount
, const char *path
, const char *name
,
698 mode_t mode
, struct snap_metadata
*snap_metadata
, size_t nr_snap_metadata
);
703 * @param cmount the ceph mount handle to use for making the directory.
704 * @param path the path of the directory to create snapshot. This must be either an
705 * absolute path or a relative path off of the current working directory.
706 * @param name snapshot name
707 * @returns 0 on success or a negative return code on error.
709 int ceph_rmsnap(struct ceph_mount_info
*cmount
, const char *path
, const char *name
);
712 * Create multiple directories at once.
714 * @param cmount the ceph mount handle to use for making the directories.
715 * @param path the full path of directories and sub-directories that should
717 * @param mode the permissions the directory should have once created.
718 * @returns 0 on success or a negative return code on error.
720 int ceph_mkdirs(struct ceph_mount_info
*cmount
, const char *path
, mode_t mode
);
723 * Remove a directory.
725 * @param cmount the ceph mount handle to use for removing directories.
726 * @param path the path of the directory to remove.
727 * @returns 0 on success or a negative return code on error.
729 int ceph_rmdir(struct ceph_mount_info
*cmount
, const char *path
);
734 * @defgroup libcephfs_h_links Links and Link Handling.
735 * Functions for creating and manipulating hard links and symbolic inks.
743 * @param cmount the ceph mount handle to use for creating the link.
744 * @param existing the path to the existing file/directory to link to.
745 * @param newname the path to the new file/directory to link from.
746 * @returns 0 on success or a negative return code on error.
748 int ceph_link(struct ceph_mount_info
*cmount
, const char *existing
, const char *newname
);
751 * Read a symbolic link.
753 * @param cmount the ceph mount handle to use for creating the link.
754 * @param path the path to the symlink to read
755 * @param buf the buffer to hold the path of the file that the symlink points to.
756 * @param size the length of the buffer
757 * @returns number of bytes copied on success or negative error code on failure
759 int ceph_readlink(struct ceph_mount_info
*cmount
, const char *path
, char *buf
, int64_t size
);
762 * Read a symbolic link relative to a file descriptor
764 * @param cmount the ceph mount handle to use for creating the link.
765 * @param dirfd open file descriptor (or CEPHFS_AT_FDCWD)
766 * @param relpath the path to the symlink to read
767 * @param buf the buffer to hold the path of the file that the symlink points to.
768 * @param size the length of the buffer
769 * @returns number of bytes copied on success or negative error code on failure
771 int ceph_readlinkat(struct ceph_mount_info
*cmount
, int dirfd
, const char *relpath
, char *buf
,
775 * Creates a symbolic link.
777 * @param cmount the ceph mount handle to use for creating the symbolic link.
778 * @param existing the path to the existing file/directory to link to.
779 * @param newname the path to the new file/directory to link from.
780 * @returns 0 on success or a negative return code on failure.
782 int ceph_symlink(struct ceph_mount_info
*cmount
, const char *existing
, const char *newname
);
785 * Creates a symbolic link relative to a file descriptor
787 * @param cmount the ceph mount handle to use for creating the symbolic link.
788 * @param dirfd open file descriptor (or CEPHFS_AT_FDCWD)
789 * @param existing the path to the existing file/directory to link to.
790 * @param newname the path to the new file/directory to link from.
791 * @returns 0 on success or a negative return code on failure.
793 int ceph_symlinkat(struct ceph_mount_info
*cmount
, const char *existing
, int dirfd
,
794 const char *newname
);
799 * @defgroup libcephfs_h_files File manipulation and handling.
800 * Functions for creating and manipulating files.
807 * Checks if deleting a file, link or directory is allowed.
809 * @param cmount the ceph mount handle to use.
810 * @param path the path of the file, link or directory.
811 * @returns 0 on success or negative error code on failure.
813 int ceph_may_delete(struct ceph_mount_info
*cmount
, const char *path
);
816 * Removes a file, link, or symbolic link. If the file/link has multiple links to it, the
817 * file will not disappear from the namespace until all references to it are removed.
819 * @param cmount the ceph mount handle to use for performing the unlink.
820 * @param path the path of the file or link to unlink.
821 * @returns 0 on success or negative error code on failure.
823 int ceph_unlink(struct ceph_mount_info
*cmount
, const char *path
);
826 * Removes a file, link, or symbolic link relative to a file descriptor.
827 * If the file/link has multiple links to it, the file will not
828 * disappear from the namespace until all references to it are removed.
830 * @param cmount the ceph mount handle to use for performing the unlink.
831 * @param dirfd open file descriptor (or CEPHFS_AT_FDCWD)
832 * @param relpath the path of the file or link to unlink.
833 * @param flags bitfield that can be used to set AT_* modifier flags (only AT_REMOVEDIR)
834 * @returns 0 on success or negative error code on failure.
836 int ceph_unlinkat(struct ceph_mount_info
*cmount
, int dirfd
, const char *relpath
, int flags
);
839 * Rename a file or directory.
841 * @param cmount the ceph mount handle to use for performing the rename.
842 * @param from the path to the existing file or directory.
843 * @param to the new name of the file or directory
844 * @returns 0 on success or negative error code on failure.
846 int ceph_rename(struct ceph_mount_info
*cmount
, const char *from
, const char *to
);
849 * Get an open file's extended statistics and attributes.
851 * @param cmount the ceph mount handle to use for performing the stat.
852 * @param fd the file descriptor of the file to get statistics of.
853 * @param stx the ceph_statx struct that will be filled in with the file's statistics.
854 * @param want bitfield of CEPH_STATX_* flags showing designed attributes
855 * @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)
856 * @returns 0 on success or negative error code on failure.
858 int ceph_fstatx(struct ceph_mount_info
*cmount
, int fd
, struct ceph_statx
*stx
,
859 unsigned int want
, unsigned int flags
);
862 * Get attributes of a file relative to a file descriptor
864 * @param cmount the ceph mount handle to use for performing the stat.
865 * @param dirfd open file descriptor (or CEPHFS_AT_FDCWD)
866 * @param relpath to the file/directory to get statistics of
867 * @param stx the ceph_statx struct that will be filled in with the file's statistics.
868 * @param want bitfield of CEPH_STATX_* flags showing designed attributes
869 * @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)
870 * @returns 0 on success or negative error code on failure.
872 int ceph_statxat(struct ceph_mount_info
*cmount
, int dirfd
, const char *relpath
,
873 struct ceph_statx
*stx
, unsigned int want
, unsigned int flags
);
876 * Get a file's extended statistics and attributes.
878 * @param cmount the ceph mount handle to use for performing the stat.
879 * @param path the file or directory to get the statistics of.
880 * @param stx the ceph_statx struct that will be filled in with the file's statistics.
881 * @param want bitfield of CEPH_STATX_* flags showing designed attributes
882 * @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)
883 * @returns 0 on success or negative error code on failure.
885 int ceph_statx(struct ceph_mount_info
*cmount
, const char *path
, struct ceph_statx
*stx
,
886 unsigned int want
, unsigned int flags
);
889 * Get a file's statistics and attributes.
891 * ceph_stat() is deprecated, use ceph_statx() instead.
893 * @param cmount the ceph mount handle to use for performing the stat.
894 * @param path the file or directory to get the statistics of.
895 * @param stbuf the stat struct that will be filled in with the file's statistics.
896 * @returns 0 on success or negative error code on failure.
898 int ceph_stat(struct ceph_mount_info
*cmount
, const char *path
, struct stat
*stbuf
)
899 LIBCEPHFS_DEPRECATED
;
902 * Get a file's statistics and attributes, without following symlinks.
904 * ceph_lstat() is deprecated, use ceph_statx(.., AT_SYMLINK_NOFOLLOW) instead.
906 * @param cmount the ceph mount handle to use for performing the stat.
907 * @param path the file or directory to get the statistics of.
908 * @param stbuf the stat struct that will be filled in with the file's statistics.
909 * @returns 0 on success or negative error code on failure.
911 int ceph_lstat(struct ceph_mount_info
*cmount
, const char *path
, struct stat
*stbuf
)
912 LIBCEPHFS_DEPRECATED
;
915 * Get the open file's statistics.
917 * ceph_fstat() is deprecated, use ceph_fstatx() instead.
919 * @param cmount the ceph mount handle to use for performing the fstat.
920 * @param fd the file descriptor of the file to get statistics of.
921 * @param stbuf the stat struct of the file's statistics, filled in by the
923 * @returns 0 on success or a negative error code on failure
925 int ceph_fstat(struct ceph_mount_info
*cmount
, int fd
, struct stat
*stbuf
)
926 LIBCEPHFS_DEPRECATED
;
929 * Set a file's attributes.
931 * @param cmount the ceph mount handle to use for performing the setattr.
932 * @param relpath the path to the file/directory to set the attributes of.
933 * @param stx the statx struct that must include attribute values to set on the file.
934 * @param mask a mask of all the CEPH_SETATTR_* values that have been set in the statx struct.
935 * @param flags mask of AT_* flags (only AT_ATTR_NOFOLLOW is respected for now)
936 * @returns 0 on success or negative error code on failure.
938 int ceph_setattrx(struct ceph_mount_info
*cmount
, const char *relpath
, struct ceph_statx
*stx
, int mask
, int flags
);
941 * Set a file's attributes (extended version).
943 * @param cmount the ceph mount handle to use for performing the setattr.
944 * @param fd the fd of the open file/directory to set the attributes of.
945 * @param stx the statx struct that must include attribute values to set on the file.
946 * @param mask a mask of all the stat values that have been set on the stat struct.
947 * @returns 0 on success or negative error code on failure.
949 int ceph_fsetattrx(struct ceph_mount_info
*cmount
, int fd
, struct ceph_statx
*stx
, int mask
);
952 * Change the mode bits (permissions) of a file/directory.
954 * @param cmount the ceph mount handle to use for performing the chmod.
955 * @param path the path to the file/directory to change the mode bits on.
956 * @param mode the new permissions to set.
957 * @returns 0 on success or a negative error code on failure.
959 int ceph_chmod(struct ceph_mount_info
*cmount
, const char *path
, mode_t mode
);
962 * Change the mode bits (permissions) of a file/directory. If the path is a
963 * symbolic link, it's not de-referenced.
965 * @param cmount the ceph mount handle to use for performing the chmod.
966 * @param path the path of file/directory to change the mode bits on.
967 * @param mode the new permissions to set.
968 * @returns 0 on success or a negative error code on failure.
970 int ceph_lchmod(struct ceph_mount_info
*cmount
, const char *path
, mode_t mode
);
973 * Change the mode bits (permissions) of an open file.
975 * @param cmount the ceph mount handle to use for performing the chmod.
976 * @param fd the open file descriptor to change the mode bits on.
977 * @param mode the new permissions to set.
978 * @returns 0 on success or a negative error code on failure.
980 int ceph_fchmod(struct ceph_mount_info
*cmount
, int fd
, mode_t mode
);
983 * Change the mode bits (permissions) of a file relative to a file descriptor.
985 * @param cmount the ceph mount handle to use for performing the chown.
986 * @param dirfd open file descriptor (or CEPHFS_AT_FDCWD)
987 * @param relpath the relpath of the file/directory to change the ownership of.
988 * @param mode the new permissions to set.
989 * @param flags bitfield that can be used to set AT_* modifier flags (AT_SYMLINK_NOFOLLOW)
990 * @returns 0 on success or negative error code on failure.
992 int ceph_chmodat(struct ceph_mount_info
*cmount
, int dirfd
, const char *relpath
,
993 mode_t mode
, int flags
);
996 * Change the ownership of a file/directory.
998 * @param cmount the ceph mount handle to use for performing the chown.
999 * @param path the path of the file/directory to change the ownership of.
1000 * @param uid the user id to set on the file/directory.
1001 * @param gid the group id to set on the file/directory.
1002 * @returns 0 on success or negative error code on failure.
1004 int ceph_chown(struct ceph_mount_info
*cmount
, const char *path
, int uid
, int gid
);
1007 * Change the ownership of a file from an open file descriptor.
1009 * @param cmount the ceph mount handle to use for performing the chown.
1010 * @param fd the fd of the open file/directory to change the ownership of.
1011 * @param uid the user id to set on the file/directory.
1012 * @param gid the group id to set on the file/directory.
1013 * @returns 0 on success or negative error code on failure.
1015 int ceph_fchown(struct ceph_mount_info
*cmount
, int fd
, int uid
, int gid
);
1018 * Change the ownership of a file/directory, don't follow symlinks.
1020 * @param cmount the ceph mount handle to use for performing the chown.
1021 * @param path the path of the file/directory to change the ownership of.
1022 * @param uid the user id to set on the file/directory.
1023 * @param gid the group id to set on the file/directory.
1024 * @returns 0 on success or negative error code on failure.
1026 int ceph_lchown(struct ceph_mount_info
*cmount
, const char *path
, int uid
, int gid
);
1029 * Change the ownership of a file/directory releative to a file descriptor.
1031 * @param cmount the ceph mount handle to use for performing the chown.
1032 * @param dirfd open file descriptor (or CEPHFS_AT_FDCWD)
1033 * @param relpath the relpath of the file/directory to change the ownership of.
1034 * @param uid the user id to set on the file/directory.
1035 * @param gid the group id to set on the file/directory.
1036 * @param flags bitfield that can be used to set AT_* modifier flags (AT_SYMLINK_NOFOLLOW)
1037 * @returns 0 on success or negative error code on failure.
1039 int ceph_chownat(struct ceph_mount_info
*cmount
, int dirfd
, const char *relpath
,
1040 uid_t uid
, gid_t gid
, int flags
);
1043 * Change file/directory last access and modification times.
1045 * @param cmount the ceph mount handle to use for performing the utime.
1046 * @param path the path to the file/directory to set the time values of.
1047 * @param buf holding the access and modification times to set on the file.
1048 * @returns 0 on success or negative error code on failure.
1050 int ceph_utime(struct ceph_mount_info
*cmount
, const char *path
, struct utimbuf
*buf
);
1053 * Change file/directory last access and modification times.
1055 * @param cmount the ceph mount handle to use for performing the utime.
1056 * @param fd the fd of the open file/directory to set the time values of.
1057 * @param buf holding the access and modification times to set on the file.
1058 * @returns 0 on success or negative error code on failure.
1060 int ceph_futime(struct ceph_mount_info
*cmount
, int fd
, struct utimbuf
*buf
);
1063 * Change file/directory last access and modification times.
1065 * @param cmount the ceph mount handle to use for performing the utime.
1066 * @param path the path to the file/directory to set the time values of.
1067 * @param times holding the access and modification times to set on the file.
1068 * @returns 0 on success or negative error code on failure.
1070 int ceph_utimes(struct ceph_mount_info
*cmount
, const char *path
, struct timeval times
[2]);
1073 * Change file/directory last access and modification times, don't follow symlinks.
1075 * @param cmount the ceph mount handle to use for performing the utime.
1076 * @param path the path to the file/directory to set the time values of.
1077 * @param times holding the access and modification times to set on the file.
1078 * @returns 0 on success or negative error code on failure.
1080 int ceph_lutimes(struct ceph_mount_info
*cmount
, const char *path
, struct timeval times
[2]);
1083 * Change file/directory last access and modification times.
1085 * @param cmount the ceph mount handle to use for performing the utime.
1086 * @param fd the fd of the open file/directory to set the time values of.
1087 * @param times holding the access and modification times to set on the file.
1088 * @returns 0 on success or negative error code on failure.
1090 int ceph_futimes(struct ceph_mount_info
*cmount
, int fd
, struct timeval times
[2]);
1093 * Change file/directory last access and modification times.
1095 * @param cmount the ceph mount handle to use for performing the utime.
1096 * @param fd the fd of the open file/directory to set the time values of.
1097 * @param times holding the access and modification times to set on the file.
1098 * @returns 0 on success or negative error code on failure.
1100 int ceph_futimens(struct ceph_mount_info
*cmount
, int fd
, struct timespec times
[2]);
1103 * Change file/directory last access and modification times relative
1104 * to a file descriptor.
1106 * @param cmount the ceph mount handle to use for performing the utime.
1107 * @param dirfd open file descriptor (or CEPHFS_AT_FDCWD)
1108 * @param relpath the relpath of the file/directory to change the ownership of.
1109 * @param dirfd the fd of the open file/directory to set the time values of.
1110 * @param times holding the access and modification times to set on the file.
1111 * @param flags bitfield that can be used to set AT_* modifier flags (AT_SYMLINK_NOFOLLOW)
1112 * @returns 0 on success or negative error code on failure.
1114 int ceph_utimensat(struct ceph_mount_info
*cmount
, int dirfd
, const char *relpath
,
1115 struct timespec times
[2], int flags
);
1118 * Apply or remove an advisory lock.
1120 * @param cmount the ceph mount handle to use for performing the lock.
1121 * @param fd the open file descriptor to change advisory lock.
1122 * @param operation the advisory lock operation to be performed on the file
1123 * descriptor among LOCK_SH (shared lock), LOCK_EX (exclusive lock),
1124 * or LOCK_UN (remove lock). The LOCK_NB value can be ORed to perform a
1125 * non-blocking operation.
1126 * @param owner the user-supplied owner identifier (an arbitrary integer)
1127 * @returns 0 on success or negative error code on failure.
1129 int ceph_flock(struct ceph_mount_info
*cmount
, int fd
, int operation
,
1133 * Truncate the file to the given size. If this operation causes the
1134 * file to expand, the empty bytes will be filled in with zeros.
1136 * @param cmount the ceph mount handle to use for performing the truncate.
1137 * @param path the path to the file to truncate.
1138 * @param size the new size of the file.
1139 * @returns 0 on success or a negative error code on failure.
1141 int ceph_truncate(struct ceph_mount_info
*cmount
, const char *path
, int64_t size
);
1144 * Make a block or character special file.
1146 * @param cmount the ceph mount handle to use for performing the mknod.
1147 * @param path the path to the special file.
1148 * @param mode the permissions to use and the type of special file. The type can be
1149 * one of S_IFREG, S_IFCHR, S_IFBLK, S_IFIFO.
1150 * @param rdev If the file type is S_IFCHR or S_IFBLK then this parameter specifies the
1151 * major and minor numbers of the newly created device special file. Otherwise,
1153 * @returns 0 on success or negative error code on failure.
1155 int ceph_mknod(struct ceph_mount_info
*cmount
, const char *path
, mode_t mode
, dev_t rdev
);
1157 * Create and/or open a file.
1159 * @param cmount the ceph mount handle to use for performing the open.
1160 * @param path the path of the file to open. If the flags parameter includes O_CREAT,
1161 * the file will first be created before opening.
1162 * @param flags a set of option masks that control how the file is created/opened.
1163 * @param mode the permissions to place on the file if the file does not exist and O_CREAT
1164 * is specified in the flags.
1165 * @returns a non-negative file descriptor number on success or a negative error code on failure.
1167 int ceph_open(struct ceph_mount_info
*cmount
, const char *path
, int flags
, mode_t mode
);
1170 * Create and/or open a file relative to a directory
1172 * @param cmount the ceph mount handle to use for performing the open.
1173 * @param dirfd open file descriptor (or CEPHFS_AT_FDCWD)
1174 * @param relpath the path of the file to open. If the flags parameter includes O_CREAT,
1175 * the file will first be created before opening.
1176 * @param flags a set of option masks that control how the file is created/opened.
1177 * @param mode the permissions to place on the file if the file does not exist and O_CREAT
1178 * is specified in the flags.
1179 * @returns a non-negative file descriptor number on success or a negative error code on failure.
1181 int ceph_openat(struct ceph_mount_info
*cmount
, int dirfd
, const char *relpath
, int flags
, mode_t mode
);
1184 * Create and/or open a file with a specific file layout.
1186 * @param cmount the ceph mount handle to use for performing the open.
1187 * @param path the path of the file to open. If the flags parameter includes O_CREAT,
1188 * the file will first be created before opening.
1189 * @param flags a set of option masks that control how the file is created/opened.
1190 * @param mode the permissions to place on the file if the file does not exist and O_CREAT
1191 * is specified in the flags.
1192 * @param stripe_unit the stripe unit size (option, 0 for default)
1193 * @param stripe_count the stripe count (optional, 0 for default)
1194 * @param object_size the object size (optional, 0 for default)
1195 * @param data_pool name of target data pool name (optional, NULL or empty string for default)
1196 * @returns a non-negative file descriptor number on success or a negative error code on failure.
1198 int ceph_open_layout(struct ceph_mount_info
*cmount
, const char *path
, int flags
,
1199 mode_t mode
, int stripe_unit
, int stripe_count
, int object_size
,
1200 const char *data_pool
);
1203 * Close the open file.
1205 * @param cmount the ceph mount handle to use for performing the close.
1206 * @param fd the file descriptor referring to the open file.
1207 * @returns 0 on success or a negative error code on failure.
1209 int ceph_close(struct ceph_mount_info
*cmount
, int fd
);
1212 * Reposition the open file stream based on the given offset.
1214 * @param cmount the ceph mount handle to use for performing the lseek.
1215 * @param fd the open file descriptor referring to the open file and holding the
1216 * current position of the stream.
1217 * @param offset the offset to set the stream to
1218 * @param whence the flag to indicate what type of seeking to perform:
1219 * SEEK_SET: the offset is set to the given offset in the file.
1220 * SEEK_CUR: the offset is set to the current location plus @e offset bytes.
1221 * SEEK_END: the offset is set to the end of the file plus @e offset bytes.
1222 * @returns 0 on success or a negative error code on failure.
1224 int64_t ceph_lseek(struct ceph_mount_info
*cmount
, int fd
, int64_t offset
, int whence
);
1226 * Read data from the file.
1228 * @param cmount the ceph mount handle to use for performing the read.
1229 * @param fd the file descriptor of the open file to read from.
1230 * @param buf the buffer to read data into
1231 * @param size the initial size of the buffer
1232 * @param offset the offset in the file to read from. If this value is negative, the
1233 * function reads from the current offset of the file descriptor.
1234 * @returns the number of bytes read into buf, or a negative error code on failure.
1236 int ceph_read(struct ceph_mount_info
*cmount
, int fd
, char *buf
, int64_t size
, int64_t offset
);
1239 * Read data from the file.
1240 * @param cmount the ceph mount handle to use for performing the read.
1241 * @param fd the file descriptor of the open file to read from.
1242 * @param iov the iov structure to read data into
1243 * @param iovcnt the number of items that iov includes
1244 * @param offset the offset in the file to read from. If this value is negative, the
1245 * function reads from the current offset of the file descriptor.
1246 * @returns the number of bytes read into buf, or a negative error code on failure.
1248 int ceph_preadv(struct ceph_mount_info
*cmount
, int fd
, const struct iovec
*iov
, int iovcnt
,
1252 * Write data to a file.
1254 * @param cmount the ceph mount handle to use for performing the write.
1255 * @param fd the file descriptor of the open file to write to
1256 * @param buf the bytes to write to the file
1257 * @param size the size of the buf array
1258 * @param offset the offset of the file write into. If this value is negative, the
1259 * function writes to the current offset of the file descriptor.
1260 * @returns the number of bytes written, or a negative error code
1262 int ceph_write(struct ceph_mount_info
*cmount
, int fd
, const char *buf
, int64_t size
,
1266 * Write data to a file.
1268 * @param cmount the ceph mount handle to use for performing the write.
1269 * @param fd the file descriptor of the open file to write to
1270 * @param iov the iov structure to read data into
1271 * @param iovcnt the number of items that iov includes
1272 * @param offset the offset of the file write into. If this value is negative, the
1273 * function writes to the current offset of the file descriptor.
1274 * @returns the number of bytes written, or a negative error code
1276 int ceph_pwritev(struct ceph_mount_info
*cmount
, int fd
, const struct iovec
*iov
, int iovcnt
,
1280 * Truncate a file to the given size.
1282 * @param cmount the ceph mount handle to use for performing the ftruncate.
1283 * @param fd the file descriptor of the file to truncate
1284 * @param size the new size of the file
1285 * @returns 0 on success or a negative error code on failure.
1287 int ceph_ftruncate(struct ceph_mount_info
*cmount
, int fd
, int64_t size
);
1290 * Synchronize an open file to persistent media.
1292 * @param cmount the ceph mount handle to use for performing the fsync.
1293 * @param fd the file descriptor of the file to sync.
1294 * @param syncdataonly a boolean whether to synchronize metadata and data (0)
1296 * @return 0 on success or a negative error code on failure.
1298 int ceph_fsync(struct ceph_mount_info
*cmount
, int fd
, int syncdataonly
);
1301 * Preallocate or release disk space for the file for the byte range.
1303 * @param cmount the ceph mount handle to use for performing the fallocate.
1304 * @param fd the file descriptor of the file to fallocate.
1305 * @param mode the flags determines the operation to be performed on the given range.
1306 * default operation (0) allocate and initialize to zero the file in the byte range,
1307 * and the file size will be changed if offset + length is greater than
1308 * the file size. if the FALLOC_FL_KEEP_SIZE flag is specified in the mode,
1309 * the file size will not be changed. if the FALLOC_FL_PUNCH_HOLE flag is
1310 * specified in the mode, the operation is deallocate space and zero the byte range.
1311 * @param offset the byte range starting.
1312 * @param length the length of the range.
1313 * @return 0 on success or a negative error code on failure.
1315 int ceph_fallocate(struct ceph_mount_info
*cmount
, int fd
, int mode
,
1316 int64_t offset
, int64_t length
);
1319 * Enable/disable lazyio for the file.
1321 * @param cmount the ceph mount handle to use for performing the fsync.
1322 * @param fd the file descriptor of the file to sync.
1323 * @param enable a boolean to enable lazyio or disable lazyio.
1324 * @returns 0 on success or a negative error code on failure.
1326 int ceph_lazyio(struct ceph_mount_info
*cmount
, int fd
, int enable
);
1330 * Flushes the write buffer for the file thereby propogating the buffered write to the file.
1332 * @param cmount the ceph mount handle to use for performing the fsync.
1333 * @param fd the file descriptor of the file to sync.
1334 * @param offset a boolean to enable lazyio or disable lazyio.
1335 * @returns 0 on success or a negative error code on failure.
1337 int ceph_lazyio_propagate(struct ceph_mount_info
*cmount
, int fd
, int64_t offset
, size_t count
);
1341 * 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.
1343 * @param cmount the ceph mount handle to use for performing the fsync.
1344 * @param fd the file descriptor of the file to sync.
1345 * @param offset a boolean to enable lazyio or disable lazyio.
1346 * @returns 0 on success or a negative error code on failure.
1348 int ceph_lazyio_synchronize(struct ceph_mount_info
*cmount
, int fd
, int64_t offset
, size_t count
);
1353 * @defgroup libcephfs_h_xattr Extended Attribute manipulation and handling.
1354 * Functions for creating and manipulating extended attributes on files.
1360 * Get an extended attribute.
1362 * @param cmount the ceph mount handle to use for performing the getxattr.
1363 * @param path the path to the file
1364 * @param name the name of the extended attribute to get
1365 * @param value a pre-allocated buffer to hold the xattr's value
1366 * @param size the size of the pre-allocated buffer
1367 * @returns the size of the value or a negative error code on failure.
1369 int ceph_getxattr(struct ceph_mount_info
*cmount
, const char *path
, const char *name
,
1370 void *value
, size_t size
);
1373 * Get an extended attribute.
1375 * @param cmount the ceph mount handle to use for performing the getxattr.
1376 * @param fd the open file descriptor referring to the file to get extended attribute from.
1377 * @param name the name of the extended attribute to get
1378 * @param value a pre-allocated buffer to hold the xattr's value
1379 * @param size the size of the pre-allocated buffer
1380 * @returns the size of the value or a negative error code on failure.
1382 int ceph_fgetxattr(struct ceph_mount_info
*cmount
, int fd
, const char *name
,
1383 void *value
, size_t size
);
1386 * Get an extended attribute without following symbolic links. This function is
1387 * identical to ceph_getxattr, but if the path refers to a symbolic link,
1388 * we get the extended attributes of the symlink rather than the attributes
1389 * of the link itself.
1391 * @param cmount the ceph mount handle to use for performing the lgetxattr.
1392 * @param path the path to the file
1393 * @param name the name of the extended attribute to get
1394 * @param value a pre-allocated buffer to hold the xattr's value
1395 * @param size the size of the pre-allocated buffer
1396 * @returns the size of the value or a negative error code on failure.
1398 int ceph_lgetxattr(struct ceph_mount_info
*cmount
, const char *path
, const char *name
,
1399 void *value
, size_t size
);
1402 * List the extended attribute keys on a file.
1404 * @param cmount the ceph mount handle to use for performing the listxattr.
1405 * @param path the path to the file.
1406 * @param list a buffer to be filled in with the list of extended attributes keys.
1407 * @param size the size of the list buffer.
1408 * @returns the size of the resulting list filled in.
1410 int ceph_listxattr(struct ceph_mount_info
*cmount
, const char *path
, char *list
, size_t size
);
1413 * List the extended attribute keys on a file.
1415 * @param cmount the ceph mount handle to use for performing the listxattr.
1416 * @param fd the open file descriptor referring to the file to list extended attributes on.
1417 * @param list a buffer to be filled in with the list of extended attributes keys.
1418 * @param size the size of the list buffer.
1419 * @returns the size of the resulting list filled in.
1421 int ceph_flistxattr(struct ceph_mount_info
*cmount
, int fd
, char *list
, size_t size
);
1424 * Get the list of extended attribute keys on a file, but do not follow symbolic links.
1426 * @param cmount the ceph mount handle to use for performing the llistxattr.
1427 * @param path the path to the file.
1428 * @param list a buffer to be filled in with the list of extended attributes keys.
1429 * @param size the size of the list buffer.
1430 * @returns the size of the resulting list filled in.
1432 int ceph_llistxattr(struct ceph_mount_info
*cmount
, const char *path
, char *list
, size_t size
);
1435 * Remove an extended attribute from a file.
1437 * @param cmount the ceph mount handle to use for performing the removexattr.
1438 * @param path the path to the file.
1439 * @param name the name of the extended attribute to remove.
1440 * @returns 0 on success or a negative error code on failure.
1442 int ceph_removexattr(struct ceph_mount_info
*cmount
, const char *path
, const char *name
);
1445 * Remove an extended attribute from a file.
1447 * @param cmount the ceph mount handle to use for performing the removexattr.
1448 * @param fd the open file descriptor referring to the file to remove extended attribute from.
1449 * @param name the name of the extended attribute to remove.
1450 * @returns 0 on success or a negative error code on failure.
1452 int ceph_fremovexattr(struct ceph_mount_info
*cmount
, int fd
, const char *name
);
1455 * Remove the extended attribute from a file, do not follow symbolic links.
1457 * @param cmount the ceph mount handle to use for performing the lremovexattr.
1458 * @param path the path to the file.
1459 * @param name the name of the extended attribute to remove.
1460 * @returns 0 on success or a negative error code on failure.
1462 int ceph_lremovexattr(struct ceph_mount_info
*cmount
, const char *path
, const char *name
);
1465 * Set an extended attribute on a file.
1467 * @param cmount the ceph mount handle to use for performing the setxattr.
1468 * @param path the path to the file.
1469 * @param name the name of the extended attribute to set.
1470 * @param value the bytes of the extended attribute value
1471 * @param size the size of the extended attribute value
1472 * @param flags the flags can be:
1473 * CEPH_XATTR_CREATE: create the extended attribute. Must not exist.
1474 * CEPH_XATTR_REPLACE: replace the extended attribute, Must already exist.
1475 * @returns 0 on success or a negative error code on failure.
1477 int ceph_setxattr(struct ceph_mount_info
*cmount
, const char *path
, const char *name
,
1478 const void *value
, size_t size
, int flags
);
1481 * Set an extended attribute on a file.
1483 * @param cmount the ceph mount handle to use for performing the setxattr.
1484 * @param fd the open file descriptor referring to the file to set extended attribute on.
1485 * @param name the name of the extended attribute to set.
1486 * @param value the bytes of the extended attribute value
1487 * @param size the size of the extended attribute value
1488 * @param flags the flags can be:
1489 * CEPH_XATTR_CREATE: create the extended attribute. Must not exist.
1490 * CEPH_XATTR_REPLACE: replace the extended attribute, Must already exist.
1491 * @returns 0 on success or a negative error code on failure.
1493 int ceph_fsetxattr(struct ceph_mount_info
*cmount
, int fd
, const char *name
,
1494 const void *value
, size_t size
, int flags
);
1497 * Set an extended attribute on a file, do not follow symbolic links.
1499 * @param cmount the ceph mount handle to use for performing the lsetxattr.
1500 * @param path the path to the file.
1501 * @param name the name of the extended attribute to set.
1502 * @param value the bytes of the extended attribute value
1503 * @param size the size of the extended attribute value
1504 * @param flags the flags can be:
1505 * CEPH_XATTR_CREATE: create the extended attribute. Must not exist.
1506 * CEPH_XATTR_REPLACE: replace the extended attribute, Must already exist.
1507 * @returns 0 on success or a negative error code on failure.
1509 int ceph_lsetxattr(struct ceph_mount_info
*cmount
, const char *path
, const char *name
,
1510 const void *value
, size_t size
, int flags
);
1515 * @defgroup libcephfs_h_filelayout Control File Layout.
1516 * Functions for setting and getting the file layout of existing files.
1522 * Get the file striping unit from an open file descriptor.
1524 * @param cmount the ceph mount handle to use.
1525 * @param fh the open file descriptor referring to the file to get the striping unit of.
1526 * @returns the striping unit of the file or a negative error code on failure.
1528 int ceph_get_file_stripe_unit(struct ceph_mount_info
*cmount
, int fh
);
1531 * Get the file striping unit.
1533 * @param cmount the ceph mount handle to use.
1534 * @param path the path of the file/directory get the striping unit of.
1535 * @returns the striping unit of the file or a negative error code on failure.
1537 int ceph_get_path_stripe_unit(struct ceph_mount_info
*cmount
, const char *path
);
1540 * Get the file striping count from an open file descriptor.
1542 * @param cmount the ceph mount handle to use.
1543 * @param fh the open file descriptor referring to the file to get the striping count of.
1544 * @returns the striping count of the file or a negative error code on failure.
1546 int ceph_get_file_stripe_count(struct ceph_mount_info
*cmount
, int fh
);
1549 * Get the file striping count.
1551 * @param cmount the ceph mount handle to use.
1552 * @param path the path of the file/directory get the striping count of.
1553 * @returns the striping count of the file or a negative error code on failure.
1555 int ceph_get_path_stripe_count(struct ceph_mount_info
*cmount
, const char *path
);
1558 * Get the file object size from an open file descriptor.
1560 * @param cmount the ceph mount handle to use.
1561 * @param fh the open file descriptor referring to the file to get the object size of.
1562 * @returns the object size of the file or a negative error code on failure.
1564 int ceph_get_file_object_size(struct ceph_mount_info
*cmount
, int fh
);
1567 * Get the file object size.
1569 * @param cmount the ceph mount handle to use.
1570 * @param path the path of the file/directory get the object size of.
1571 * @returns the object size of the file or a negative error code on failure.
1573 int ceph_get_path_object_size(struct ceph_mount_info
*cmount
, const char *path
);
1576 * Get the file pool information from an open file descriptor.
1578 * @param cmount the ceph mount handle to use.
1579 * @param fh the open file descriptor referring to the file to get the pool information of.
1580 * @returns the ceph pool id that the file is in
1582 int ceph_get_file_pool(struct ceph_mount_info
*cmount
, int fh
);
1585 * Get the file pool information.
1587 * @param cmount the ceph mount handle to use.
1588 * @param path the path of the file/directory get the pool information of.
1589 * @returns the ceph pool id that the file is in
1591 int ceph_get_path_pool(struct ceph_mount_info
*cmount
, const char *path
);
1594 * Get the name of the pool a opened file is stored in,
1596 * Write the name of the file's pool to the buffer. If buflen is 0, return
1597 * a suggested length for the buffer.
1599 * @param cmount the ceph mount handle to use.
1600 * @param fh the open file descriptor referring to the file
1601 * @param buf buffer to store the name in
1602 * @param buflen size of the buffer
1603 * @returns length in bytes of the pool name, or -ERANGE if the buffer is not large enough.
1605 int ceph_get_file_pool_name(struct ceph_mount_info
*cmount
, int fh
, char *buf
, size_t buflen
);
1608 * get the name of a pool by id
1610 * Given a pool's numeric identifier, get the pool's alphanumeric name.
1612 * @param cmount the ceph mount handle to use
1613 * @param pool the numeric pool id
1614 * @param buf buffer to sore the name in
1615 * @param buflen size of the buffer
1616 * @returns length in bytes of the pool name, or -ERANGE if the buffer is not large enough
1618 int ceph_get_pool_name(struct ceph_mount_info
*cmount
, int pool
, char *buf
, size_t buflen
);
1621 * Get the name of the pool a file is stored in
1623 * Write the name of the file's pool to the buffer. If buflen is 0, return
1624 * a suggested length for the buffer.
1626 * @param cmount the ceph mount handle to use.
1627 * @param path the path of the file/directory
1628 * @param buf buffer to store the name in
1629 * @param buflen size of the buffer
1630 * @returns length in bytes of the pool name, or -ERANGE if the buffer is not large enough.
1632 int ceph_get_path_pool_name(struct ceph_mount_info
*cmount
, const char *path
, char *buf
, size_t buflen
);
1635 * Get the default pool name of cephfs
1636 * Write the name of the default pool to the buffer. If buflen is 0, return
1637 * a suggested length for the buffer.
1638 * @param cmount the ceph mount handle to use.
1639 * @param buf buffer to store the name in
1640 * @param buflen size of the buffer
1641 * @returns length in bytes of the pool name, or -ERANGE if the buffer is not large enough.
1643 int ceph_get_default_data_pool_name(struct ceph_mount_info
*cmount
, char *buf
, size_t buflen
);
1646 * Get the file layout from an open file descriptor.
1648 * @param cmount the ceph mount handle to use.
1649 * @param fh the open file descriptor referring to the file to get the layout of.
1650 * @param stripe_unit where to store the striping unit of the file
1651 * @param stripe_count where to store the striping count of the file
1652 * @param object_size where to store the object size of the file
1653 * @param pg_pool where to store the ceph pool id that the file is in
1654 * @returns 0 on success or a negative error code on failure.
1656 int ceph_get_file_layout(struct ceph_mount_info
*cmount
, int fh
, int *stripe_unit
, int *stripe_count
, int *object_size
, int *pg_pool
);
1659 * Get the file layout.
1661 * @param cmount the ceph mount handle to use.
1662 * @param path the path of the file/directory get the layout of.
1663 * @param stripe_unit where to store the striping unit of the file
1664 * @param stripe_count where to store the striping count of the file
1665 * @param object_size where to store the object size of the file
1666 * @param pg_pool where to store the ceph pool id that the file is in
1667 * @returns 0 on success or a negative error code on failure.
1669 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
);
1672 * Get the file replication information from an open file descriptor.
1674 * @param cmount the ceph mount handle to use.
1675 * @param fh the open file descriptor referring to the file to get the replication information of.
1676 * @returns the replication factor of the file.
1678 int ceph_get_file_replication(struct ceph_mount_info
*cmount
, int fh
);
1681 * Get the file replication information.
1683 * @param cmount the ceph mount handle to use.
1684 * @param path the path of the file/directory get the replication information of.
1685 * @returns the replication factor of the file.
1687 int ceph_get_path_replication(struct ceph_mount_info
*cmount
, const char *path
);
1690 * Get the id of the named pool.
1692 * @param cmount the ceph mount handle to use.
1693 * @param pool_name the name of the pool.
1694 * @returns the pool id, or a negative error code on failure.
1696 int ceph_get_pool_id(struct ceph_mount_info
*cmount
, const char *pool_name
);
1699 * Get the pool replication factor.
1701 * @param cmount the ceph mount handle to use.
1702 * @param pool_id the pool id to look up
1703 * @returns the replication factor, or a negative error code on failure.
1705 int ceph_get_pool_replication(struct ceph_mount_info
*cmount
, int pool_id
);
1708 * Get the OSD address where the primary copy of a file stripe is located.
1710 * @param cmount the ceph mount handle to use.
1711 * @param fd the open file descriptor referring to the file to get the striping unit of.
1712 * @param offset the offset into the file to specify the stripe. The offset can be
1713 * anywhere within the stripe unit.
1714 * @param addr the address of the OSD holding that stripe
1715 * @param naddr the capacity of the address passed in.
1716 * @returns the size of the addressed filled into the @e addr parameter, or a negative
1717 * error code on failure.
1719 int ceph_get_file_stripe_address(struct ceph_mount_info
*cmount
, int fd
, int64_t offset
,
1720 struct sockaddr_storage
*addr
, int naddr
);
1723 * Get the list of OSDs where the objects containing a file offset are located.
1725 * @param cmount the ceph mount handle to use.
1726 * @param fd the open file descriptor referring to the file.
1727 * @param offset the offset within the file.
1728 * @param length return the number of bytes between the offset and the end of
1729 * the stripe unit (optional).
1730 * @param osds an integer array to hold the OSD ids.
1731 * @param nosds the size of the integer array.
1732 * @returns the number of items stored in the output array, or -ERANGE if the
1733 * array is not large enough.
1735 int ceph_get_file_extent_osds(struct ceph_mount_info
*cmount
, int fd
,
1736 int64_t offset
, int64_t *length
, int *osds
, int nosds
);
1739 * Get the fully qualified CRUSH location of an OSD.
1741 * Returns (type, name) string pairs for each device in the CRUSH bucket
1742 * hierarchy starting from the given osd to the root. Each pair element is
1743 * separated by a NULL character.
1745 * @param cmount the ceph mount handle to use.
1746 * @param osd the OSD id.
1747 * @param path buffer to store location.
1748 * @param len size of buffer.
1749 * @returns the amount of bytes written into the buffer, or -ERANGE if the
1750 * array is not large enough.
1752 int ceph_get_osd_crush_location(struct ceph_mount_info
*cmount
,
1753 int osd
, char *path
, size_t len
);
1756 * Get the network address of an OSD.
1758 * @param cmount the ceph mount handle.
1759 * @param osd the OSD id.
1760 * @param addr the OSD network address.
1761 * @returns zero on success, other returns a negative error code.
1763 int ceph_get_osd_addr(struct ceph_mount_info
*cmount
, int osd
,
1764 struct sockaddr_storage
*addr
);
1767 * Get the file layout stripe unit granularity.
1768 * @param cmount the ceph mount handle.
1769 * @returns the stripe unit granularity or a negative error code on failure.
1771 int ceph_get_stripe_unit_granularity(struct ceph_mount_info
*cmount
);
1773 /** @} filelayout */
1776 * No longer available. Do not use.
1777 * These functions will return -EOPNOTSUPP.
1779 int ceph_set_default_file_stripe_unit(struct ceph_mount_info
*cmount
, int stripe
);
1780 int ceph_set_default_file_stripe_count(struct ceph_mount_info
*cmount
, int count
);
1781 int ceph_set_default_object_size(struct ceph_mount_info
*cmount
, int size
);
1782 int ceph_set_default_preferred_pg(struct ceph_mount_info
*cmount
, int osd
);
1783 int ceph_set_default_file_replication(struct ceph_mount_info
*cmount
, int replication
);
1786 * Read from local replicas when possible.
1788 * @param cmount the ceph mount handle to use.
1789 * @param val a boolean to set (1) or clear (0) the option to favor local objects
1793 int ceph_localize_reads(struct ceph_mount_info
*cmount
, int val
);
1796 * Get the osd id of the local osd (if any)
1798 * @param cmount the ceph mount handle to use.
1799 * @returns the osd (if any) local to the node where this call is made, otherwise
1802 int ceph_get_local_osd(struct ceph_mount_info
*cmount
);
1804 /** @} default_filelayout */
1807 * Get the capabilities currently issued to the client.
1809 * @param cmount the ceph mount handle to use.
1810 * @param fd the file descriptor to get issued
1811 * @returns the current capabilities issued to this client
1814 int ceph_debug_get_fd_caps(struct ceph_mount_info
*cmount
, int fd
);
1817 * Get the capabilities currently issued to the client.
1819 * @param cmount the ceph mount handle to use.
1820 * @param path the path to the file
1821 * @returns the current capabilities issued to this client
1824 int ceph_debug_get_file_caps(struct ceph_mount_info
*cmount
, const char *path
);
1827 struct Inode
*ceph_ll_get_inode(struct ceph_mount_info
*cmount
,
1830 int ceph_ll_lookup_vino(struct ceph_mount_info
*cmount
, vinodeno_t vino
,
1833 int ceph_ll_lookup_inode(
1834 struct ceph_mount_info
*cmount
,
1835 struct inodeno_t ino
,
1839 * Get the root inode of FS. Increase counter of references for root Inode. You must call ceph_ll_forget for it!
1841 * @param cmount the ceph mount handle to use.
1842 * @param parent pointer to pointer to Inode struct. Pointer to root inode will be returned
1843 * @returns 0 if all good
1845 int ceph_ll_lookup_root(struct ceph_mount_info
*cmount
,
1847 int ceph_ll_lookup(struct ceph_mount_info
*cmount
, Inode
*parent
,
1848 const char *name
, Inode
**out
, struct ceph_statx
*stx
,
1849 unsigned want
, unsigned flags
, const UserPerm
*perms
);
1850 int ceph_ll_put(struct ceph_mount_info
*cmount
, struct Inode
*in
);
1851 int ceph_ll_forget(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1853 int ceph_ll_walk(struct ceph_mount_info
*cmount
, const char* name
, Inode
**i
,
1854 struct ceph_statx
*stx
, unsigned int want
, unsigned int flags
,
1855 const UserPerm
*perms
);
1856 int ceph_ll_getattr(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1857 struct ceph_statx
*stx
, unsigned int want
, unsigned int flags
,
1858 const UserPerm
*perms
);
1859 int ceph_ll_setattr(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1860 struct ceph_statx
*stx
, int mask
, const UserPerm
*perms
);
1861 int ceph_ll_open(struct ceph_mount_info
*cmount
, struct Inode
*in
, int flags
,
1862 struct Fh
**fh
, const UserPerm
*perms
);
1863 off_t
ceph_ll_lseek(struct ceph_mount_info
*cmount
, struct Fh
* filehandle
,
1864 off_t offset
, int whence
);
1865 int ceph_ll_read(struct ceph_mount_info
*cmount
, struct Fh
* filehandle
,
1866 int64_t off
, uint64_t len
, char* buf
);
1867 int ceph_ll_fsync(struct ceph_mount_info
*cmount
, struct Fh
*fh
,
1869 int ceph_ll_sync_inode(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1871 int ceph_ll_fallocate(struct ceph_mount_info
*cmount
, struct Fh
*fh
,
1872 int mode
, int64_t offset
, int64_t length
);
1873 int ceph_ll_write(struct ceph_mount_info
*cmount
, struct Fh
* filehandle
,
1874 int64_t off
, uint64_t len
, const char *data
);
1875 int64_t ceph_ll_readv(struct ceph_mount_info
*cmount
, struct Fh
*fh
,
1876 const struct iovec
*iov
, int iovcnt
, int64_t off
);
1877 int64_t ceph_ll_writev(struct ceph_mount_info
*cmount
, struct Fh
*fh
,
1878 const struct iovec
*iov
, int iovcnt
, int64_t off
);
1879 int ceph_ll_close(struct ceph_mount_info
*cmount
, struct Fh
* filehandle
);
1880 int ceph_ll_iclose(struct ceph_mount_info
*cmount
, struct Inode
*in
, int mode
);
1882 * Get xattr value by xattr name.
1884 * @param cmount the ceph mount handle to use.
1885 * @param in file handle
1886 * @param name name of attribute
1887 * @param value pointer to begin buffer
1888 * @param size buffer size
1889 * @param perms pointer to UserPerms object
1890 * @returns size of returned buffer. Negative number in error case
1892 int ceph_ll_getxattr(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1893 const char *name
, void *value
, size_t size
,
1894 const UserPerm
*perms
);
1895 int ceph_ll_setxattr(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1896 const char *name
, const void *value
, size_t size
,
1897 int flags
, const UserPerm
*perms
);
1898 int ceph_ll_listxattr(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1899 char *list
, size_t buf_size
, size_t *list_size
,
1900 const UserPerm
*perms
);
1901 int ceph_ll_removexattr(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1902 const char *name
, const UserPerm
*perms
);
1903 int ceph_ll_create(struct ceph_mount_info
*cmount
, Inode
*parent
,
1904 const char *name
, mode_t mode
, int oflags
, Inode
**outp
,
1905 Fh
**fhp
, struct ceph_statx
*stx
, unsigned want
,
1906 unsigned lflags
, const UserPerm
*perms
);
1907 int ceph_ll_mknod(struct ceph_mount_info
*cmount
, Inode
*parent
,
1908 const char *name
, mode_t mode
, dev_t rdev
, Inode
**out
,
1909 struct ceph_statx
*stx
, unsigned want
, unsigned flags
,
1910 const UserPerm
*perms
);
1911 int ceph_ll_mkdir(struct ceph_mount_info
*cmount
, Inode
*parent
,
1912 const char *name
, mode_t mode
, Inode
**out
,
1913 struct ceph_statx
*stx
, unsigned want
,
1914 unsigned flags
, const UserPerm
*perms
);
1915 int ceph_ll_link(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1916 struct Inode
*newparent
, const char *name
,
1917 const UserPerm
*perms
);
1918 int ceph_ll_opendir(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1919 struct ceph_dir_result
**dirpp
, const UserPerm
*perms
);
1920 int ceph_ll_releasedir(struct ceph_mount_info
*cmount
,
1921 struct ceph_dir_result
* dir
);
1922 int ceph_ll_rename(struct ceph_mount_info
*cmount
, struct Inode
*parent
,
1923 const char *name
, struct Inode
*newparent
,
1924 const char *newname
, const UserPerm
*perms
);
1925 int ceph_ll_unlink(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1926 const char *name
, const UserPerm
*perms
);
1927 int ceph_ll_statfs(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1928 struct statvfs
*stbuf
);
1929 int ceph_ll_readlink(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1930 char *buf
, size_t bufsize
, const UserPerm
*perms
);
1931 int ceph_ll_symlink(struct ceph_mount_info
*cmount
,
1932 Inode
*in
, const char *name
, const char *value
,
1933 Inode
**out
, struct ceph_statx
*stx
,
1934 unsigned want
, unsigned flags
,
1935 const UserPerm
*perms
);
1936 int ceph_ll_rmdir(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1937 const char *name
, const UserPerm
*perms
);
1938 uint32_t ceph_ll_stripe_unit(struct ceph_mount_info
*cmount
,
1940 uint32_t ceph_ll_file_layout(struct ceph_mount_info
*cmount
,
1942 struct ceph_file_layout
*layout
);
1943 uint64_t ceph_ll_snap_seq(struct ceph_mount_info
*cmount
,
1945 int ceph_ll_get_stripe_osd(struct ceph_mount_info
*cmount
,
1948 struct ceph_file_layout
* layout
);
1949 int ceph_ll_num_osds(struct ceph_mount_info
*cmount
);
1950 int ceph_ll_osdaddr(struct ceph_mount_info
*cmount
,
1951 int osd
, uint32_t *addr
);
1952 uint64_t ceph_ll_get_internal_offset(struct ceph_mount_info
*cmount
,
1953 struct Inode
*in
, uint64_t blockno
);
1954 int ceph_ll_read_block(struct ceph_mount_info
*cmount
,
1955 struct Inode
*in
, uint64_t blockid
,
1956 char* bl
, uint64_t offset
, uint64_t length
,
1957 struct ceph_file_layout
* layout
);
1958 int ceph_ll_write_block(struct ceph_mount_info
*cmount
,
1959 struct Inode
*in
, uint64_t blockid
,
1960 char* buf
, uint64_t offset
,
1961 uint64_t length
, struct ceph_file_layout
* layout
,
1962 uint64_t snapseq
, uint32_t sync
);
1963 int ceph_ll_commit_blocks(struct ceph_mount_info
*cmount
,
1964 struct Inode
*in
, uint64_t offset
, uint64_t range
);
1967 int ceph_ll_getlk(struct ceph_mount_info
*cmount
,
1968 Fh
*fh
, struct flock
*fl
, uint64_t owner
);
1969 int ceph_ll_setlk(struct ceph_mount_info
*cmount
,
1970 Fh
*fh
, struct flock
*fl
, uint64_t owner
, int sleep
);
1972 int ceph_ll_lazyio(struct ceph_mount_info
*cmount
, Fh
*fh
, int enable
);
1975 * Delegation support
1977 * Delegations are way for an application to request exclusive or
1978 * semi-exclusive access to an Inode. The client requests the delegation and
1979 * if it's successful it can reliably cache file data and metadata until the
1980 * delegation is recalled.
1982 * Recalls are issued via a callback function, provided by the application.
1983 * Callback functions should act something like signal handlers. You want to
1984 * do as little as possible in the callback. Any major work should be deferred
1985 * in some fashion as it's difficult to predict the context in which this
1986 * function will be called.
1988 * Once the delegation has been recalled, the application should return it as
1989 * soon as possible. The application has client_deleg_timeout seconds to
1990 * return it, after which the cmount structure is forcibly unmounted and
1991 * further calls into it fail.
1993 * The application can set the client_deleg_timeout config option to suit its
1994 * needs, but it should take care to choose a value that allows it to avoid
1995 * forcible eviction from the cluster in the event of an application bug.
1998 /* Commands for manipulating delegation state */
1999 #ifndef CEPH_DELEGATION_NONE
2000 # define CEPH_DELEGATION_NONE 0
2001 # define CEPH_DELEGATION_RD 1
2002 # define CEPH_DELEGATION_WR 2
2006 * Get the amount of time that the client has to return caps
2007 * @param cmount the ceph mount handle to use.
2009 * In the event that a client does not return its caps, the MDS may blocklist
2010 * it after this timeout. Applications should check this value and ensure
2011 * that they set the delegation timeout to a value lower than this.
2013 * This call returns the cap return timeout (in seconds) for this cmount, or
2014 * zero if it's not mounted.
2016 uint32_t ceph_get_cap_return_timeout(struct ceph_mount_info
*cmount
);
2019 * Set the delegation timeout for the mount (thereby enabling delegations)
2020 * @param cmount the ceph mount handle to use.
2021 * @param timeout the delegation timeout (in seconds)
2023 * Since the client could end up blocklisted if it doesn't return delegations
2024 * in time, we mandate that any application wanting to use delegations
2025 * explicitly set the timeout beforehand. Until this call is done on the
2026 * mount, attempts to set a delegation will return -ETIME.
2028 * Once a delegation is recalled, if it is not returned in this amount of
2029 * time, the cmount will be forcibly unmounted and further access attempts
2030 * will fail (usually with -ENOTCONN errors).
2032 * This value is further vetted against the cap return timeout, and this call
2033 * can fail with -EINVAL if the timeout value is too long. Delegations can be
2034 * disabled again by setting the timeout to 0.
2036 int ceph_set_deleg_timeout(struct ceph_mount_info
*cmount
, uint32_t timeout
);
2039 * Request a delegation on an open Fh
2040 * @param cmount the ceph mount handle to use.
2041 * @param fh file handle
2042 * @param cmd CEPH_DELEGATION_* command
2043 * @param cb callback function for recalling delegation
2044 * @param priv opaque token passed back during recalls
2046 * Returns 0 if the delegation was granted, -EAGAIN if there was a conflict
2047 * and other error codes if there is a fatal error of some sort (e.g. -ENOMEM,
2050 int ceph_ll_delegation(struct ceph_mount_info
*cmount
, Fh
*fh
,
2051 unsigned int cmd
, ceph_deleg_cb_t cb
, void *priv
);
2053 mode_t
ceph_umask(struct ceph_mount_info
*cmount
, mode_t mode
);
2056 #define CEPH_RECLAIM_RESET 1
2059 * Set ceph client uuid
2060 * @param cmount the ceph mount handle to use.
2061 * @param uuid the uuid to set
2063 * Must be called before mount.
2065 void ceph_set_uuid(struct ceph_mount_info
*cmount
, const char *uuid
);
2068 * Set ceph client session timeout
2069 * @param cmount the ceph mount handle to use.
2070 * @param timeout the timeout to set
2072 * Must be called before mount.
2074 void ceph_set_session_timeout(struct ceph_mount_info
*cmount
, unsigned timeout
);
2077 * Start to reclaim states of other client
2078 * @param cmount the ceph mount handle to use.
2079 * @param uuid uuid of client whose states need to be reclaimed
2080 * @param flags flags that control how states get reclaimed
2082 * Returns 0 success, -EOPNOTSUPP if mds does not support the operation,
2083 * -ENOENT if CEPH_RECLAIM_RESET is specified and there is no client
2084 * with the given uuid, -ENOTRECOVERABLE in all other error cases.
2086 int ceph_start_reclaim(struct ceph_mount_info
*cmount
,
2087 const char *uuid
, unsigned flags
);
2090 * finish reclaiming states of other client (
2091 * @param cmount the ceph mount handle to use.
2093 void ceph_finish_reclaim(struct ceph_mount_info
*cmount
);
2096 * Register a set of callbacks to be used with this cmount
2098 * This is deprecated, use ceph_ll_register_callbacks2() instead.
2100 * @param cmount the ceph mount handle on which the cb's should be registerd
2101 * @param args callback arguments to register with the cmount
2103 * Any fields set to NULL will be ignored. There currently is no way to
2104 * unregister these callbacks, so this is a one-way change.
2106 void ceph_ll_register_callbacks(struct ceph_mount_info
*cmount
,
2107 struct ceph_client_callback_args
*args
);
2110 * Register a set of callbacks to be used with this cmount
2111 * @param cmount the ceph mount handle on which the cb's should be registerd
2112 * @param args callback arguments to register with the cmount
2114 * Any fields set to NULL will be ignored. There currently is no way to
2115 * unregister these callbacks, so this is a one-way change.
2117 * Returns 0 on success or -EBUSY if the cmount is mounting or already mounted.
2119 int ceph_ll_register_callbacks2(struct ceph_mount_info
*cmount
,
2120 struct ceph_client_callback_args
*args
);
2125 * @param cmount the ceph mount handle to use for making the directory.
2126 * @param path the path of the snapshot. This must be either an
2127 * absolute path or a relative path off of the current working directory.
2128 * @returns 0 on success or a negative return code on error.
2130 int ceph_get_snap_info(struct ceph_mount_info
*cmount
,
2131 const char *path
, struct snap_info
*snap_info
);
2134 * Free snapshot info buffers
2136 * @param snap_info snapshot info struct (fetched via call to ceph_get_snap_info()).
2138 void ceph_free_snap_info_buffer(struct snap_info
*snap_info
);