]>
git.proxmox.com Git - ceph.git/blob - ceph/src/include/cephfs/libcephfs.h
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__)
23 #include <sys/types.h>
24 #include <sys/statvfs.h>
25 #include <sys/socket.h>
30 #include "ceph_statx.h"
36 #define LIBCEPHFS_VER_MAJOR 10
37 #define LIBCEPHFS_VER_MINOR 0
38 #define LIBCEPHFS_VER_EXTRA 2
40 #define LIBCEPHFS_VERSION(maj, min, extra) ((maj << 16) + (min << 8) + extra)
41 #define LIBCEPHFS_VERSION_CODE LIBCEPHFS_VERSION(LIBCEPHFS_VER_MAJOR, LIBCEPHFS_VER_MINOR, LIBCEPHFS_VER_EXTRA)
44 * If using glibc check that file offset is 64-bit.
46 #if defined(__GLIBC__) && !defined(__USE_FILE_OFFSET64)
47 # error libceph: glibc must define __USE_FILE_OFFSET64 or readdir results will be corrupted
51 * XXXX redeclarations from ceph_fs.h, rados.h, etc. We need more of this
52 * in the interface, but shouldn't be re-typing it (and using different
57 #define CEPH_INO_ROOT 1
58 #define CEPH_NOSNAP ((uint64_t)(-2))
60 struct ceph_file_layout
{
61 /* file -> object mapping */
62 uint32_t fl_stripe_unit
; /* stripe unit, in bytes. must be multiple
64 uint32_t fl_stripe_count
; /* over this many objects */
65 uint32_t fl_object_size
; /* until objects are this big, then move to
67 uint32_t fl_cas_hash
; /* 0 = none; 1 = sha256 */
69 /* pg -> disk layout */
70 uint32_t fl_object_stripe_unit
; /* for per-object parity, if any */
72 /* object -> pg layout */
73 uint32_t fl_pg_preferred
; /* preferred primary for pg (-1 for none) */
74 uint32_t fl_pg_pool
; /* namespace, crush ruleset, rep level */
75 } __attribute__ ((packed
));
78 typedef struct inodeno_t
{
82 typedef struct _snapid_t
{
86 typedef struct vinodeno_t
{
92 #else /* _cplusplus */
96 typedef struct vinodeno_t vinodeno
;
98 #endif /* ! __cplusplus */
101 typedef struct UserPerm UserPerm
;
104 typedef struct Inode Inode
;
106 struct ceph_mount_info
;
107 struct ceph_dir_result
;
110 /* setattr mask bits */
111 #ifndef CEPH_SETATTR_MODE
112 # define CEPH_SETATTR_MODE 1
113 # define CEPH_SETATTR_UID 2
114 # define CEPH_SETATTR_GID 4
115 # define CEPH_SETATTR_MTIME 8
116 # define CEPH_SETATTR_ATIME 16
117 # define CEPH_SETATTR_SIZE 32
118 # define CEPH_SETATTR_CTIME 64
119 # define CEPH_SETATTR_BTIME 512
122 /* define error codes for the mount function*/
123 # define CEPHFS_ERROR_MON_MAP_BUILD 1000
124 # define CEPHFS_ERROR_NEW_CLIENT 1002
125 # define CEPHFS_ERROR_MESSENGER_START 1003
128 * Create a UserPerm credential object.
130 * Some calls (most notably, the ceph_ll_* ones), take a credential object
131 * that represents the credentials that the calling program is using. This
132 * function creates a new credential object for this purpose. Returns a
133 * pointer to the object, or NULL if it can't be allocated.
135 * Note that the gidlist array is used directly and is not copied. It must
136 * remain valid over the lifetime of the created UserPerm object.
138 * @param uid uid to be used
139 * @param gid gid to be used
140 * @param ngids number of gids in supplemental grouplist
141 * @param gidlist array of gid_t's in the list of groups
143 UserPerm
*ceph_userperm_new(uid_t uid
, gid_t gid
, int ngids
, gid_t
*gidlist
);
146 * Destroy a UserPerm credential object.
148 * @param perm pointer to object to be destroyed
150 * Currently this just frees the object. Note that the gidlist array is not
151 * freed. The caller must do so if it's necessary.
153 void ceph_userperm_destroy(UserPerm
*perm
);
156 * Get a pointer to the default UserPerm object for the mount.
158 * @param cmount the mount info handle
160 * Every cmount has a default set of credentials. This returns a pointer to
163 * Unlike with ceph_userperm_new, this object should not be freed.
165 struct UserPerm
*ceph_mount_perms(struct ceph_mount_info
*cmount
);
168 * @defgroup libcephfs_h_init Setup and Teardown
169 * These are the first and last functions that should be called
170 * when using libcephfs.
176 * Get the version of libcephfs.
178 * The version number is major.minor.patch.
180 * @param major where to store the major version number
181 * @param minor where to store the minor version number
182 * @param patch where to store the extra version number
184 const char *ceph_version(int *major
, int *minor
, int *patch
);
187 * Create a mount handle for interacting with Ceph. All libcephfs
188 * functions operate on a mount info handle.
190 * @param cmount the mount info handle to initialize
191 * @param id the id of the client. This can be a unique id that identifies
192 * this client, and will get appended onto "client.". Callers can
193 * pass in NULL, and the id will be the process id of the client.
194 * @returns 0 on success, negative error code on failure
196 int ceph_create(struct ceph_mount_info
**cmount
, const char * const id
);
199 * Create a mount handle from a CephContext, which holds the configuration
200 * for the ceph cluster. A CephContext can be acquired from an existing ceph_mount_info
201 * handle, using the @ref ceph_get_mount_context call. Note that using the same CephContext
202 * for two different mount handles results in the same client entity id being used.
204 * @param cmount the mount info handle to initialize
205 * @param conf reuse this pre-existing CephContext config
206 * @returns 0 on success, negative error code on failure
208 int ceph_create_with_context(struct ceph_mount_info
**cmount
, struct CephContext
*conf
);
211 #ifndef VOIDPTR_RADOS_T
212 #define VOIDPTR_RADOS_T
213 typedef void *rados_t
;
214 #endif // VOIDPTR_RADOS_T
217 * Create a mount handle from a rados_t, for using libcephfs in the
218 * same process as librados.
220 * @param cmount the mount info handle to initialize
221 * @param cluster reference to already-initialized librados handle
222 * @returns 0 on success, negative error code on failure
224 int ceph_create_from_rados(struct ceph_mount_info
**cmount
, rados_t cluster
);
227 * Initialize the filesystem client (but do not mount the filesystem yet)
229 * @returns 0 on success, negative error code on failure
231 int ceph_init(struct ceph_mount_info
*cmount
);
235 * Perform a mount using the path for the root of the mount.
237 * It is optional to call ceph_init before this. If ceph_init has
238 * not already been called, it will be called in the course of this operation.
240 * @param cmount the mount info handle
241 * @param root the path for the root of the mount. This can be an existing
242 * directory within the ceph cluster, but most likely it will
243 * be "/". Passing in NULL is equivalent to "/".
244 * @returns 0 on success, negative error code on failure
246 int ceph_mount(struct ceph_mount_info
*cmount
, const char *root
);
249 * Execute a management command remotely on an MDS.
251 * Must have called ceph_init or ceph_mount before calling this.
253 * @param mds_spec string representing rank, MDS name, GID or '*'
254 * @param cmd array of null-terminated strings
255 * @param cmdlen length of cmd array
256 * @param inbuf non-null-terminated input data to command
257 * @param inbuflen length in octets of inbuf
258 * @param outbuf populated with pointer to buffer (command output data)
259 * @param outbuflen length of allocated outbuf
260 * @param outs populated with pointer to buffer (command error strings)
261 * @param outslen length of allocated outs
263 * @return 0 on success, negative error code on failure
266 int ceph_mds_command(struct ceph_mount_info
*cmount
,
267 const char *mds_spec
,
270 const char *inbuf
, size_t inbuflen
,
271 char **outbuf
, size_t *outbuflen
,
272 char **outs
, size_t *outslen
);
275 * Free a buffer, such as those used for output arrays from ceph_mds_command
277 void ceph_buffer_free(char *buf
);
280 * Unmount a mount handle.
282 * @param cmount the mount handle
283 * @return 0 on success, negative error code on failure
285 int ceph_unmount(struct ceph_mount_info
*cmount
);
288 * Destroy the mount handle.
290 * The handle should not be mounted. This should be called on completion of
291 * all libcephfs functions.
293 * @param cmount the mount handle
294 * @return 0 on success, negative error code on failure.
296 int ceph_release(struct ceph_mount_info
*cmount
);
299 * Deprecated. Unmount and destroy the ceph mount handle. This should be
300 * called on completion of all libcephfs functions.
302 * Equivalent to ceph_unmount() + ceph_release() without error handling.
304 * @param cmount the mount handle to shutdown
306 void ceph_shutdown(struct ceph_mount_info
*cmount
);
309 * Extract the CephContext from the mount point handle.
311 * @param cmount the ceph mount handle to get the context from.
312 * @returns the CephContext associated with the mount handle.
314 struct CephContext
*ceph_get_mount_context(struct ceph_mount_info
*cmount
);
317 * Check mount status.
319 * Return non-zero value if mounted. Otherwise, zero.
321 int ceph_is_mounted(struct ceph_mount_info
*cmount
);
326 * @defgroup libcephfs_h_config Config
327 * Functions for manipulating the Ceph configuration at runtime.
333 * Load the ceph configuration from the specified config file.
335 * @param cmount the mount handle to load the configuration into.
336 * @param path_list the configuration file path
337 * @returns 0 on success, negative error code on failure
339 int ceph_conf_read_file(struct ceph_mount_info
*cmount
, const char *path_list
);
342 * Parse the command line arguments and load the configuration parameters.
344 * @param cmount the mount handle to load the configuration parameters into.
345 * @param argc count of the arguments in argv
346 * @param argv the argument list
347 * @returns 0 on success, negative error code on failure
349 int ceph_conf_parse_argv(struct ceph_mount_info
*cmount
, int argc
, const char **argv
);
352 * Configure the cluster handle based on an environment variable
354 * The contents of the environment variable are parsed as if they were
355 * Ceph command line options. If var is NULL, the CEPH_ARGS
356 * environment variable is used.
358 * @pre ceph_mount() has not been called on the handle
360 * @note BUG: this is not threadsafe - it uses a static buffer
362 * @param cmount handle to configure
363 * @param var name of the environment variable to read
364 * @returns 0 on success, negative error code on failure
366 int ceph_conf_parse_env(struct ceph_mount_info
*cmount
, const char *var
);
368 /** Sets a configuration value from a string.
370 * @param cmount the mount handle to set the configuration value on
371 * @param option the configuration option to set
372 * @param value the value of the configuration option to set
374 * @returns 0 on success, negative error code otherwise.
376 int ceph_conf_set(struct ceph_mount_info
*cmount
, const char *option
, const char *value
);
379 * Gets the configuration value as a string.
381 * @param cmount the mount handle to set the configuration value on
382 * @param option the config option to get
383 * @param buf the buffer to fill with the value
384 * @param len the length of the buffer.
385 * @returns the size of the buffer filled in with the value, or negative error code on failure
387 int ceph_conf_get(struct ceph_mount_info
*cmount
, const char *option
, char *buf
, size_t len
);
392 * @defgroup libcephfs_h_fsops File System Operations.
393 * Functions for getting/setting file system wide information specific to a particular
400 * Perform a statfs on the ceph file system. This call fills in file system wide statistics
401 * into the passed in buffer.
403 * @param cmount the ceph mount handle to use for performing the statfs.
404 * @param path can be any path within the mounted filesystem
405 * @param stbuf the file system statistics filled in by this function.
406 * @return 0 on success, negative error code otherwise.
408 int ceph_statfs(struct ceph_mount_info
*cmount
, const char *path
, struct statvfs
*stbuf
);
411 * Synchronize all filesystem data to persistent media.
413 * @param cmount the ceph mount handle to use for performing the sync_fs.
414 * @returns 0 on success or negative error code on failure.
416 int ceph_sync_fs(struct ceph_mount_info
*cmount
);
419 * Get the current working directory.
421 * @param cmount the ceph mount to get the current working directory for.
422 * @returns the path to the current working directory
424 const char* ceph_getcwd(struct ceph_mount_info
*cmount
);
427 * Change the current working directory.
429 * @param cmount the ceph mount to change the current working directory for.
430 * @param path the path to the working directory to change into.
431 * @returns 0 on success, negative error code otherwise.
433 int ceph_chdir(struct ceph_mount_info
*cmount
, const char *path
);
438 * @defgroup libcephfs_h_dir Directory Operations.
439 * Functions for manipulating and listing directories.
445 * Open the given directory.
447 * @param cmount the ceph mount handle to use to open the directory
448 * @param name the path name of the directory to open. Must be either an absolute path
449 * or a path relative to the current working directory.
450 * @param dirpp the directory result pointer structure to fill in.
451 * @returns 0 on success or negative error code otherwise.
453 int ceph_opendir(struct ceph_mount_info
*cmount
, const char *name
, struct ceph_dir_result
**dirpp
);
456 * Close the open directory.
458 * @param cmount the ceph mount handle to use for closing the directory
459 * @param dirp the directory result pointer (set by ceph_opendir) to close
460 * @returns 0 on success or negative error code on failure.
462 int ceph_closedir(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
);
465 * Get the next entry in an open directory.
467 * @param cmount the ceph mount handle to use for performing the readdir.
468 * @param dirp the directory stream pointer from an opendir holding the state of the
469 * next entry to return.
470 * @returns the next directory entry or NULL if at the end of the directory (or the directory
471 * is empty. This pointer should not be freed by the caller, and is only safe to
472 * access between return and the next call to ceph_readdir or ceph_closedir.
474 struct dirent
* ceph_readdir(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
);
477 * A safe version of ceph_readdir, where the directory entry struct is allocated by the caller.
479 * @param cmount the ceph mount handle to use for performing the readdir.
480 * @param dirp the directory stream pointer from an opendir holding the state of the
481 * next entry to return.
482 * @param de the directory entry pointer filled in with the next directory entry of the dirp state.
483 * @returns 1 if the next entry was filled in, 0 if the end of the directory stream was reached,
484 * and a negative error code on failure.
486 int ceph_readdir_r(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
, struct dirent
*de
);
489 * A safe version of ceph_readdir that also returns the file statistics (readdir+stat).
491 * @param cmount the ceph mount handle to use for performing the readdir_plus_r.
492 * @param dirp the directory stream pointer from an opendir holding the state of the
493 * next entry to return.
494 * @param de the directory entry pointer filled in with the next directory entry of the dirp state.
495 * @param stx the stats of the file/directory of the entry returned
496 * @param want mask showing desired inode attrs for returned entry
497 * @param flags bitmask of flags to use when filling out attributes
498 * @param out optional returned Inode argument. If non-NULL, then a reference will be taken on
499 * the inode and the pointer set on success.
500 * @returns 1 if the next entry was filled in, 0 if the end of the directory stream was reached,
501 * and a negative error code on failure.
503 int ceph_readdirplus_r(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
, struct dirent
*de
,
504 struct ceph_statx
*stx
, unsigned want
, unsigned flags
, struct Inode
**out
);
507 * Gets multiple directory entries.
509 * @param cmount the ceph mount handle to use for performing the getdents.
510 * @param dirp the directory stream pointer from an opendir holding the state of the
511 * next entry/entries to return.
512 * @param name an array of struct dirent that gets filled in with the to fill returned directory entries into.
513 * @param buflen the length of the buffer, which should be the number of dirent structs * sizeof(struct dirent).
514 * @returns the length of the buffer that was filled in, will always be multiples of sizeof(struct dirent), or a
515 * negative error code. If the buffer is not large enough for a single entry, -ERANGE is returned.
517 int ceph_getdents(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
, char *name
, int buflen
);
520 * Gets multiple directory names.
522 * @param cmount the ceph mount handle to use for performing the getdents.
523 * @param dirp the directory stream pointer from an opendir holding the state of the
524 * next entry/entries to return.
525 * @param name a buffer to fill in with directory entry names.
526 * @param buflen the length of the buffer that can be filled in.
527 * @returns the length of the buffer filled in with entry names, or a negative error code on failure.
528 * If the buffer isn't large enough for a single entry, -ERANGE is returned.
530 int ceph_getdnames(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
, char *name
, int buflen
);
533 * Rewind the directory stream to the beginning of the directory.
535 * @param cmount the ceph mount handle to use for performing the rewinddir.
536 * @param dirp the directory stream pointer to rewind.
538 void ceph_rewinddir(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
);
541 * Get the current position of a directory stream.
543 * @param cmount the ceph mount handle to use for performing the telldir.
544 * @param dirp the directory stream pointer to get the current position of.
545 * @returns the position of the directory stream. Note that the offsets returned
546 * by ceph_telldir do not have a particular order (cannot be compared with
549 int64_t ceph_telldir(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
);
552 * Move the directory stream to a position specified by the given offset.
554 * @param cmount the ceph mount handle to use for performing the seekdir.
555 * @param dirp the directory stream pointer to move.
556 * @param offset the position to move the directory stream to. This offset should be
557 * a value returned by seekdir. Note that this value does not refer to the nth
558 * entry in a directory, and can not be manipulated with plus or minus.
560 void ceph_seekdir(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
, int64_t offset
);
563 * Create a directory.
565 * @param cmount the ceph mount handle to use for making the directory.
566 * @param path the path of the directory to create. This must be either an
567 * absolute path or a relative path off of the current working directory.
568 * @param mode the permissions the directory should have once created.
569 * @returns 0 on success or a negative return code on error.
571 int ceph_mkdir(struct ceph_mount_info
*cmount
, const char *path
, mode_t mode
);
574 * Create multiple directories at once.
576 * @param cmount the ceph mount handle to use for making the directories.
577 * @param path the full path of directories and sub-directories that should
579 * @param mode the permissions the directory should have once created.
580 * @returns 0 on success or a negative return code on error.
582 int ceph_mkdirs(struct ceph_mount_info
*cmount
, const char *path
, mode_t mode
);
585 * Remove a directory.
587 * @param cmount the ceph mount handle to use for removing directories.
588 * @param path the path of the directory to remove.
589 * @returns 0 on success or a negative return code on error.
591 int ceph_rmdir(struct ceph_mount_info
*cmount
, const char *path
);
596 * @defgroup libcephfs_h_links Links and Link Handling.
597 * Functions for creating and manipulating hard links and symbolic inks.
605 * @param cmount the ceph mount handle to use for creating the link.
606 * @param existing the path to the existing file/directory to link to.
607 * @param newname the path to the new file/directory to link from.
608 * @returns 0 on success or a negative return code on error.
610 int ceph_link(struct ceph_mount_info
*cmount
, const char *existing
, const char *newname
);
613 * Read a symbolic link.
615 * @param cmount the ceph mount handle to use for creating the link.
616 * @param path the path to the symlink to read
617 * @param buf the buffer to hold the path of the file that the symlink points to.
618 * @param size the length of the buffer
619 * @returns number of bytes copied on success or negative error code on failure
621 int ceph_readlink(struct ceph_mount_info
*cmount
, const char *path
, char *buf
, int64_t size
);
624 * Creates a symbolic link.
626 * @param cmount the ceph mount handle to use for creating the symbolic link.
627 * @param existing the path to the existing file/directory to link to.
628 * @param newname the path to the new file/directory to link from.
629 * @returns 0 on success or a negative return code on failure.
631 int ceph_symlink(struct ceph_mount_info
*cmount
, const char *existing
, const char *newname
);
636 * @defgroup libcephfs_h_files File manipulation and handling.
637 * Functions for creating and manipulating files.
643 * Removes a file, link, or symbolic link. If the file/link has multiple links to it, the
644 * file will not disappear from the namespace until all references to it are removed.
646 * @param cmount the ceph mount handle to use for performing the unlink.
647 * @param path the path of the file or link to unlink.
648 * @returns 0 on success or negative error code on failure.
650 int ceph_unlink(struct ceph_mount_info
*cmount
, const char *path
);
653 * Rename a file or directory.
655 * @param cmount the ceph mount handle to use for performing the rename.
656 * @param from the path to the existing file or directory.
657 * @param to the new name of the file or directory
658 * @returns 0 on success or negative error code on failure.
660 int ceph_rename(struct ceph_mount_info
*cmount
, const char *from
, const char *to
);
663 * Get an open file's extended statistics and attributes.
665 * @param cmount the ceph mount handle to use for performing the stat.
666 * @param fd the file descriptor of the file to get statistics of.
667 * @param stx the ceph_statx struct that will be filled in with the file's statistics.
668 * @param want bitfield of CEPH_STATX_* flags showing designed attributes
669 * @param flags bitfield that can be used to set AT_* modifier flags (only AT_NO_ATTR_SYNC and AT_SYMLINK_NOFOLLOW)
670 * @returns 0 on success or negative error code on failure.
672 int ceph_fstatx(struct ceph_mount_info
*cmount
, int fd
, struct ceph_statx
*stx
,
673 unsigned int want
, unsigned int flags
);
676 * Get a file's extended statistics and attributes.
678 * @param cmount the ceph mount handle to use for performing the stat.
679 * @param path the file or directory to get the statistics of.
680 * @param stx the ceph_statx struct that will be filled in with the file's statistics.
681 * @param want bitfield of CEPH_STATX_* flags showing designed attributes
682 * @param flags bitfield that can be used to set AT_* modifier flags (only AT_NO_ATTR_SYNC and AT_SYMLINK_NOFOLLOW)
683 * @returns 0 on success or negative error code on failure.
685 int ceph_statx(struct ceph_mount_info
*cmount
, const char *path
, struct ceph_statx
*stx
,
686 unsigned int want
, unsigned int flags
);
689 * Set a file's attributes.
691 * @param cmount the ceph mount handle to use for performing the setattr.
692 * @param relpath the path to the file/directory to set the attributes of.
693 * @param stx the statx struct that must include attribute values to set on the file.
694 * @param mask a mask of all the CEPH_SETATTR_* values that have been set in the statx struct.
695 * @param flags mask of AT_* flags (only AT_ATTR_NOFOLLOW is respected for now)
696 * @returns 0 on success or negative error code on failure.
698 int ceph_setattrx(struct ceph_mount_info
*cmount
, const char *relpath
, struct ceph_statx
*stx
, int mask
, int flags
);
701 * Set a file's attributes (extended version).
703 * @param cmount the ceph mount handle to use for performing the setattr.
704 * @param fd the fd of the open file/directory to set the attributes of.
705 * @param stx the statx struct that must include attribute values to set on the file.
706 * @param mask a mask of all the stat values that have been set on the stat struct.
707 * @returns 0 on success or negative error code on failure.
709 int ceph_fsetattrx(struct ceph_mount_info
*cmount
, int fd
, struct ceph_statx
*stx
, int mask
);
712 * Change the mode bits (permissions) of a file/directory.
714 * @param cmount the ceph mount handle to use for performing the chmod.
715 * @param path the path to the file/directory to change the mode bits on.
716 * @param mode the new permissions to set.
717 * @returns 0 on success or a negative error code on failure.
719 int ceph_chmod(struct ceph_mount_info
*cmount
, const char *path
, mode_t mode
);
722 * Change the mode bits (permissions) of an open file.
724 * @param cmount the ceph mount handle to use for performing the chmod.
725 * @param fd the open file descriptor to change the mode bits on.
726 * @param mode the new permissions to set.
727 * @returns 0 on success or a negative error code on failure.
729 int ceph_fchmod(struct ceph_mount_info
*cmount
, int fd
, mode_t mode
);
732 * Change the ownership of a file/directory.
734 * @param cmount the ceph mount handle to use for performing the chown.
735 * @param path the path of the file/directory to change the ownership of.
736 * @param uid the user id to set on the file/directory.
737 * @param gid the group id to set on the file/directory.
738 * @returns 0 on success or negative error code on failure.
740 int ceph_chown(struct ceph_mount_info
*cmount
, const char *path
, int uid
, int gid
);
743 * Change the ownership of a file from an open file descriptor.
745 * @param cmount the ceph mount handle to use for performing the chown.
746 * @param fd the fd of the open file/directory to change the ownership of.
747 * @param uid the user id to set on the file/directory.
748 * @param gid the group id to set on the file/directory.
749 * @returns 0 on success or negative error code on failure.
751 int ceph_fchown(struct ceph_mount_info
*cmount
, int fd
, int uid
, int gid
);
754 * Change the ownership of a file/directory, don't follow symlinks.
756 * @param cmount the ceph mount handle to use for performing the chown.
757 * @param path the path of the file/directory to change the ownership of.
758 * @param uid the user id to set on the file/directory.
759 * @param gid the group id to set on the file/directory.
760 * @returns 0 on success or negative error code on failure.
762 int ceph_lchown(struct ceph_mount_info
*cmount
, const char *path
, int uid
, int gid
);
765 * Change file/directory last access and modification times.
767 * @param cmount the ceph mount handle to use for performing the utime.
768 * @param path the path to the file/directory to set the time values of.
769 * @param buf holding the access and modification times to set on the file.
770 * @returns 0 on success or negative error code on failure.
772 int ceph_utime(struct ceph_mount_info
*cmount
, const char *path
, struct utimbuf
*buf
);
775 * Apply or remove an advisory lock.
777 * @param cmount the ceph mount handle to use for performing the lock.
778 * @param fd the open file descriptor to change advisory lock.
779 * @param operation the advisory lock operation to be performed on the file
780 * descriptor among LOCK_SH (shared lock), LOCK_EX (exclusive lock),
781 * or LOCK_UN (remove lock). The LOCK_NB value can be ORed to perform a
782 * non-blocking operation.
783 * @param owner the user-supplied owner identifier (an arbitrary integer)
784 * @returns 0 on success or negative error code on failure.
786 int ceph_flock(struct ceph_mount_info
*cmount
, int fd
, int operation
,
790 * Truncate the file to the given size. If this operation causes the
791 * file to expand, the empty bytes will be filled in with zeros.
793 * @param cmount the ceph mount handle to use for performing the truncate.
794 * @param path the path to the file to truncate.
795 * @param size the new size of the file.
796 * @returns 0 on success or a negative error code on failure.
798 int ceph_truncate(struct ceph_mount_info
*cmount
, const char *path
, int64_t size
);
801 * Make a block or character special file.
803 * @param cmount the ceph mount handle to use for performing the mknod.
804 * @param path the path to the special file.
805 * @param mode the permissions to use and the type of special file. The type can be
806 * one of S_IFREG, S_IFCHR, S_IFBLK, S_IFIFO.
807 * @param rdev If the file type is S_IFCHR or S_IFBLK then this parameter specifies the
808 * major and minor numbers of the newly created device special file. Otherwise,
810 * @returns 0 on success or negative error code on failure.
812 int ceph_mknod(struct ceph_mount_info
*cmount
, const char *path
, mode_t mode
, dev_t rdev
);
814 * Create and/or open a file.
816 * @param cmount the ceph mount handle to use for performing the open.
817 * @param path the path of the file to open. If the flags parameter includes O_CREAT,
818 * the file will first be created before opening.
819 * @param flags a set of option masks that control how the file is created/opened.
820 * @param mode the permissions to place on the file if the file does not exist and O_CREAT
821 * is specified in the flags.
822 * @returns a non-negative file descriptor number on success or a negative error code on failure.
824 int ceph_open(struct ceph_mount_info
*cmount
, const char *path
, int flags
, mode_t mode
);
827 * Create and/or open a file with a specific file layout.
829 * @param cmount the ceph mount handle to use for performing the open.
830 * @param path the path of the file to open. If the flags parameter includes O_CREAT,
831 * the file will first be created before opening.
832 * @param flags a set of option masks that control how the file is created/opened.
833 * @param mode the permissions to place on the file if the file does not exist and O_CREAT
834 * is specified in the flags.
835 * @param stripe_unit the stripe unit size (option, 0 for default)
836 * @param stripe_count the stripe count (optional, 0 for default)
837 * @param object_size the object size (optional, 0 for default)
838 * @param data_pool name of target data pool name (optional, NULL or empty string for default)
839 * @returns a non-negative file descriptor number on success or a negative error code on failure.
841 int ceph_open_layout(struct ceph_mount_info
*cmount
, const char *path
, int flags
,
842 mode_t mode
, int stripe_unit
, int stripe_count
, int object_size
,
843 const char *data_pool
);
846 * Close the open file.
848 * @param cmount the ceph mount handle to use for performing the close.
849 * @param fd the file descriptor referring to the open file.
850 * @returns 0 on success or a negative error code on failure.
852 int ceph_close(struct ceph_mount_info
*cmount
, int fd
);
855 * Reposition the open file stream based on the given offset.
857 * @param cmount the ceph mount handle to use for performing the lseek.
858 * @param fd the open file descriptor referring to the open file and holding the
859 * current position of the stream.
860 * @param offset the offset to set the stream to
861 * @param whence the flag to indicate what type of seeking to perform:
862 * SEEK_SET: the offset is set to the given offset in the file.
863 * SEEK_CUR: the offset is set to the current location plus @e offset bytes.
864 * SEEK_END: the offset is set to the end of the file plus @e offset bytes.
865 * @returns 0 on success or a negative error code on failure.
867 int64_t ceph_lseek(struct ceph_mount_info
*cmount
, int fd
, int64_t offset
, int whence
);
869 * Read data from the file.
871 * @param cmount the ceph mount handle to use for performing the read.
872 * @param fd the file descriptor of the open file to read from.
873 * @param buf the buffer to read data into
874 * @param size the initial size of the buffer
875 * @param offset the offset in the file to read from. If this value is negative, the
876 * function reads from the current offset of the file descriptor.
877 * @returns the number of bytes read into buf, or a negative error code on failure.
879 int ceph_read(struct ceph_mount_info
*cmount
, int fd
, char *buf
, int64_t size
, int64_t offset
);
882 * Read data from the file.
883 * @param cmount the ceph mount handle to use for performing the read.
884 * @param fd the file descriptor of the open file to read from.
885 * @param iov the iov structure to read data into
886 * @param iovcnt the number of items that iov includes
887 * @param offset the offset in the file to read from. If this value is negative, the
888 * function reads from the current offset of the file descriptor.
889 * @returns the number of bytes read into buf, or a negative error code on failure.
891 int ceph_preadv(struct ceph_mount_info
*cmount
, int fd
, const struct iovec
*iov
, int iovcnt
,
895 * Write data to a file.
897 * @param cmount the ceph mount handle to use for performing the write.
898 * @param fd the file descriptor of the open file to write to
899 * @param buf the bytes to write to the file
900 * @param size the size of the buf array
901 * @param offset the offset of the file write into. If this value is negative, the
902 * function writes to the current offset of the file descriptor.
903 * @returns the number of bytes written, or a negative error code
905 int ceph_write(struct ceph_mount_info
*cmount
, int fd
, const char *buf
, int64_t size
,
909 * Write data to a file.
911 * @param cmount the ceph mount handle to use for performing the write.
912 * @param fd the file descriptor of the open file to write to
913 * @param iov the iov structure to read data into
914 * @param iovcnt the number of items that iov includes
915 * @param offset the offset of the file write into. If this value is negative, the
916 * function writes to the current offset of the file descriptor.
917 * @returns the number of bytes written, or a negative error code
919 int ceph_pwritev(struct ceph_mount_info
*cmount
, int fd
, const struct iovec
*iov
, int iovcnt
,
923 * Truncate a file to the given size.
925 * @param cmount the ceph mount handle to use for performing the ftruncate.
926 * @param fd the file descriptor of the file to truncate
927 * @param size the new size of the file
928 * @returns 0 on success or a negative error code on failure.
930 int ceph_ftruncate(struct ceph_mount_info
*cmount
, int fd
, int64_t size
);
933 * Synchronize an open file to persistent media.
935 * @param cmount the ceph mount handle to use for performing the fsync.
936 * @param fd the file descriptor of the file to sync.
937 * @param syncdataonly a boolean whether to synchronize metadata and data (0)
939 * @return 0 on success or a negative error code on failure.
941 int ceph_fsync(struct ceph_mount_info
*cmount
, int fd
, int syncdataonly
);
944 * Preallocate or release disk space for the file for the byte range.
946 * @param cmount the ceph mount handle to use for performing the fallocate.
947 * @param fd the file descriptor of the file to fallocate.
948 * @param mode the flags determines the operation to be performed on the given range.
949 * default operation (0) allocate and initialize to zero the file in the byte range,
950 * and the file size will be changed if offset + length is greater than
951 * the file size. if the FALLOC_FL_KEEP_SIZE flag is specified in the mode,
952 * the file size will not be changed. if the FALLOC_FL_PUNCH_HOLE flag is
953 * specified in the mode, the operation is deallocate space and zero the byte range.
954 * @param offset the byte range starting.
955 * @param length the length of the range.
956 * @return 0 on success or a negative error code on failure.
958 int ceph_fallocate(struct ceph_mount_info
*cmount
, int fd
, int mode
,
959 int64_t offset
, int64_t length
);
964 * @defgroup libcephfs_h_xattr Extended Attribute manipulation and handling.
965 * Functions for creating and manipulating extended attributes on files.
971 * Get an extended attribute.
973 * @param cmount the ceph mount handle to use for performing the getxattr.
974 * @param path the path to the file
975 * @param name the name of the extended attribute to get
976 * @param value a pre-allocated buffer to hold the xattr's value
977 * @param size the size of the pre-allocated buffer
978 * @returns the size of the value or a negative error code on failure.
980 int ceph_getxattr(struct ceph_mount_info
*cmount
, const char *path
, const char *name
,
981 void *value
, size_t size
);
984 * Get an extended attribute.
986 * @param cmount the ceph mount handle to use for performing the getxattr.
987 * @param fd the open file descriptor referring to the file to get extended attribute from.
988 * @param name the name of the extended attribute to get
989 * @param value a pre-allocated buffer to hold the xattr's value
990 * @param size the size of the pre-allocated buffer
991 * @returns the size of the value or a negative error code on failure.
993 int ceph_fgetxattr(struct ceph_mount_info
*cmount
, int fd
, const char *name
,
994 void *value
, size_t size
);
997 * Get an extended attribute without following symbolic links. This function is
998 * identical to ceph_getxattr, but if the path refers to a symbolic link,
999 * we get the extended attributes of the symlink rather than the attributes
1000 * of the link itself.
1002 * @param cmount the ceph mount handle to use for performing the lgetxattr.
1003 * @param path the path to the file
1004 * @param name the name of the extended attribute to get
1005 * @param value a pre-allocated buffer to hold the xattr's value
1006 * @param size the size of the pre-allocated buffer
1007 * @returns the size of the value or a negative error code on failure.
1009 int ceph_lgetxattr(struct ceph_mount_info
*cmount
, const char *path
, const char *name
,
1010 void *value
, size_t size
);
1013 * List the extended attribute keys on a file.
1015 * @param cmount the ceph mount handle to use for performing the listxattr.
1016 * @param path the path to the file.
1017 * @param list a buffer to be filled in with the list of extended attributes keys.
1018 * @param size the size of the list buffer.
1019 * @returns the size of the resulting list filled in.
1021 int ceph_listxattr(struct ceph_mount_info
*cmount
, const char *path
, char *list
, size_t size
);
1024 * List the extended attribute keys on a file.
1026 * @param cmount the ceph mount handle to use for performing the listxattr.
1027 * @param fd the open file descriptor referring to the file to list extended attributes on.
1028 * @param list a buffer to be filled in with the list of extended attributes keys.
1029 * @param size the size of the list buffer.
1030 * @returns the size of the resulting list filled in.
1032 int ceph_flistxattr(struct ceph_mount_info
*cmount
, int fd
, char *list
, size_t size
);
1035 * Get the list of extended attribute keys on a file, but do not follow symbolic links.
1037 * @param cmount the ceph mount handle to use for performing the llistxattr.
1038 * @param path the path to the file.
1039 * @param list a buffer to be filled in with the list of extended attributes keys.
1040 * @param size the size of the list buffer.
1041 * @returns the size of the resulting list filled in.
1043 int ceph_llistxattr(struct ceph_mount_info
*cmount
, const char *path
, char *list
, size_t size
);
1046 * Remove an extended attribute from a file.
1048 * @param cmount the ceph mount handle to use for performing the removexattr.
1049 * @param path the path to the file.
1050 * @param name the name of the extended attribute to remove.
1051 * @returns 0 on success or a negative error code on failure.
1053 int ceph_removexattr(struct ceph_mount_info
*cmount
, const char *path
, const char *name
);
1056 * Remove an extended attribute from a file.
1058 * @param cmount the ceph mount handle to use for performing the removexattr.
1059 * @param fd the open file descriptor referring to the file to remove extended attribute from.
1060 * @param name the name of the extended attribute to remove.
1061 * @returns 0 on success or a negative error code on failure.
1063 int ceph_fremovexattr(struct ceph_mount_info
*cmount
, int fd
, const char *name
);
1066 * Remove the extended attribute from a file, do not follow symbolic links.
1068 * @param cmount the ceph mount handle to use for performing the lremovexattr.
1069 * @param path the path to the file.
1070 * @param name the name of the extended attribute to remove.
1071 * @returns 0 on success or a negative error code on failure.
1073 int ceph_lremovexattr(struct ceph_mount_info
*cmount
, const char *path
, const char *name
);
1076 * Set an extended attribute on a file.
1078 * @param cmount the ceph mount handle to use for performing the setxattr.
1079 * @param path the path to the file.
1080 * @param name the name of the extended attribute to set.
1081 * @param value the bytes of the extended attribute value
1082 * @param size the size of the extended attribute value
1083 * @param flags the flags can be:
1084 * CEPH_XATTR_CREATE: create the extended attribute. Must not exist.
1085 * CEPH_XATTR_REPLACE: replace the extended attribute, Must already exist.
1086 * @returns 0 on success or a negative error code on failure.
1088 int ceph_setxattr(struct ceph_mount_info
*cmount
, const char *path
, const char *name
,
1089 const void *value
, size_t size
, int flags
);
1092 * Set an extended attribute on a file.
1094 * @param cmount the ceph mount handle to use for performing the setxattr.
1095 * @param fd the open file descriptor referring to the file to set extended attribute on.
1096 * @param name the name of the extended attribute to set.
1097 * @param value the bytes of the extended attribute value
1098 * @param size the size of the extended attribute value
1099 * @param flags the flags can be:
1100 * CEPH_XATTR_CREATE: create the extended attribute. Must not exist.
1101 * CEPH_XATTR_REPLACE: replace the extended attribute, Must already exist.
1102 * @returns 0 on success or a negative error code on failure.
1104 int ceph_fsetxattr(struct ceph_mount_info
*cmount
, int fd
, const char *name
,
1105 const void *value
, size_t size
, int flags
);
1108 * Set an extended attribute on a file, do not follow symbolic links.
1110 * @param cmount the ceph mount handle to use for performing the lsetxattr.
1111 * @param path the path to the file.
1112 * @param name the name of the extended attribute to set.
1113 * @param value the bytes of the extended attribute value
1114 * @param size the size of the extended attribute value
1115 * @param flags the flags can be:
1116 * CEPH_XATTR_CREATE: create the extended attribute. Must not exist.
1117 * CEPH_XATTR_REPLACE: replace the extended attribute, Must already exist.
1118 * @returns 0 on success or a negative error code on failure.
1120 int ceph_lsetxattr(struct ceph_mount_info
*cmount
, const char *path
, const char *name
,
1121 const void *value
, size_t size
, int flags
);
1126 * @defgroup libcephfs_h_filelayout Control File Layout.
1127 * Functions for setting and getting the file layout of existing files.
1133 * Get the file striping unit from an open file descriptor.
1135 * @param cmount the ceph mount handle to use.
1136 * @param fh the open file descriptor referring to the file to get the striping unit of.
1137 * @returns the striping unit of the file or a negative error code on failure.
1139 int ceph_get_file_stripe_unit(struct ceph_mount_info
*cmount
, int fh
);
1142 * Get the file striping unit.
1144 * @param cmount the ceph mount handle to use.
1145 * @param path the path of the file/directory get the striping unit of.
1146 * @returns the striping unit of the file or a negative error code on failure.
1148 int ceph_get_path_stripe_unit(struct ceph_mount_info
*cmount
, const char *path
);
1151 * Get the file striping count from an open file descriptor.
1153 * @param cmount the ceph mount handle to use.
1154 * @param fh the open file descriptor referring to the file to get the striping count of.
1155 * @returns the striping count of the file or a negative error code on failure.
1157 int ceph_get_file_stripe_count(struct ceph_mount_info
*cmount
, int fh
);
1160 * Get the file striping count.
1162 * @param cmount the ceph mount handle to use.
1163 * @param path the path of the file/directory get the striping count of.
1164 * @returns the striping count of the file or a negative error code on failure.
1166 int ceph_get_path_stripe_count(struct ceph_mount_info
*cmount
, const char *path
);
1169 * Get the file object size from an open file descriptor.
1171 * @param cmount the ceph mount handle to use.
1172 * @param fh the open file descriptor referring to the file to get the object size of.
1173 * @returns the object size of the file or a negative error code on failure.
1175 int ceph_get_file_object_size(struct ceph_mount_info
*cmount
, int fh
);
1178 * Get the file object size.
1180 * @param cmount the ceph mount handle to use.
1181 * @param path the path of the file/directory get the object size of.
1182 * @returns the object size of the file or a negative error code on failure.
1184 int ceph_get_path_object_size(struct ceph_mount_info
*cmount
, const char *path
);
1187 * Get the file pool information from an open file descriptor.
1189 * @param cmount the ceph mount handle to use.
1190 * @param fh the open file descriptor referring to the file to get the pool information of.
1191 * @returns the ceph pool id that the file is in
1193 int ceph_get_file_pool(struct ceph_mount_info
*cmount
, int fh
);
1196 * Get the file pool information.
1198 * @param cmount the ceph mount handle to use.
1199 * @param path the path of the file/directory get the pool information of.
1200 * @returns the ceph pool id that the file is in
1202 int ceph_get_path_pool(struct ceph_mount_info
*cmount
, const char *path
);
1205 * Get the name of the pool a opened file is stored in,
1207 * Write the name of the file's pool to the buffer. If buflen is 0, return
1208 * a suggested length for the buffer.
1210 * @param cmount the ceph mount handle to use.
1211 * @param fh the open file descriptor referring to the file
1212 * @param buf buffer to store the name in
1213 * @param buflen size of the buffer
1214 * @returns length in bytes of the pool name, or -ERANGE if the buffer is not large enough.
1216 int ceph_get_file_pool_name(struct ceph_mount_info
*cmount
, int fh
, char *buf
, size_t buflen
);
1219 * get the name of a pool by id
1221 * Given a pool's numeric identifier, get the pool's alphanumeric name.
1223 * @param cmount the ceph mount handle to use
1224 * @param pool the numeric pool id
1225 * @param buf buffer to sore the name in
1226 * @param buflen size of the buffer
1227 * @returns length in bytes of the pool name, or -ERANGE if the buffer is not large enough
1229 int ceph_get_pool_name(struct ceph_mount_info
*cmount
, int pool
, char *buf
, size_t buflen
);
1232 * Get the name of the pool a file is stored in
1234 * Write the name of the file's pool to the buffer. If buflen is 0, return
1235 * a suggested length for the buffer.
1237 * @param cmount the ceph mount handle to use.
1238 * @param path the path of the file/directory
1239 * @param buf buffer to store the name in
1240 * @param buflen size of the buffer
1241 * @returns length in bytes of the pool name, or -ERANGE if the buffer is not large enough.
1243 int ceph_get_path_pool_name(struct ceph_mount_info
*cmount
, const char *path
, char *buf
, size_t buflen
);
1246 * Get the default pool name of cephfs
1247 * Write the name of the default pool to the buffer. If buflen is 0, return
1248 * a suggested length for the buffer.
1249 * @param cmount the ceph mount handle to use.
1250 * @param buf buffer to store the name in
1251 * @param buflen size of the buffer
1252 * @returns length in bytes of the pool name, or -ERANGE if the buffer is not large enough.
1254 int ceph_get_default_data_pool_name(struct ceph_mount_info
*cmount
, char *buf
, size_t buflen
);
1257 * Get the file layout from an open file descriptor.
1259 * @param cmount the ceph mount handle to use.
1260 * @param fh the open file descriptor referring to the file to get the layout of.
1261 * @param stripe_unit where to store the striping unit of the file
1262 * @param stripe_count where to store the striping count of the file
1263 * @param object_size where to store the object size of the file
1264 * @param pg_pool where to store the ceph pool id that the file is in
1265 * @returns 0 on success or a negative error code on failure.
1267 int ceph_get_file_layout(struct ceph_mount_info
*cmount
, int fh
, int *stripe_unit
, int *stripe_count
, int *object_size
, int *pg_pool
);
1270 * Get the file layout.
1272 * @param cmount the ceph mount handle to use.
1273 * @param path the path of the file/directory get the layout of.
1274 * @param stripe_unit where to store the striping unit of the file
1275 * @param stripe_count where to store the striping count of the file
1276 * @param object_size where to store the object size of the file
1277 * @param pg_pool where to store the ceph pool id that the file is in
1278 * @returns 0 on success or a negative error code on failure.
1280 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
);
1283 * Get the file replication information from an open file descriptor.
1285 * @param cmount the ceph mount handle to use.
1286 * @param fh the open file descriptor referring to the file to get the replication information of.
1287 * @returns the replication factor of the file.
1289 int ceph_get_file_replication(struct ceph_mount_info
*cmount
, int fh
);
1292 * Get the file replication information.
1294 * @param cmount the ceph mount handle to use.
1295 * @param path the path of the file/directory get the replication information of.
1296 * @returns the replication factor of the file.
1298 int ceph_get_path_replication(struct ceph_mount_info
*cmount
, const char *path
);
1301 * Get the id of the named pool.
1303 * @param cmount the ceph mount handle to use.
1304 * @param pool_name the name of the pool.
1305 * @returns the pool id, or a negative error code on failure.
1307 int ceph_get_pool_id(struct ceph_mount_info
*cmount
, const char *pool_name
);
1310 * Get the pool replication factor.
1312 * @param cmount the ceph mount handle to use.
1313 * @param pool_id the pool id to look up
1314 * @returns the replication factor, or a negative error code on failure.
1316 int ceph_get_pool_replication(struct ceph_mount_info
*cmount
, int pool_id
);
1319 * Get the OSD address where the primary copy of a file stripe is located.
1321 * @param cmount the ceph mount handle to use.
1322 * @param fd the open file descriptor referring to the file to get the striping unit of.
1323 * @param offset the offset into the file to specify the stripe. The offset can be
1324 * anywhere within the stripe unit.
1325 * @param addr the address of the OSD holding that stripe
1326 * @param naddr the capacity of the address passed in.
1327 * @returns the size of the addressed filled into the @e addr parameter, or a negative
1328 * error code on failure.
1330 int ceph_get_file_stripe_address(struct ceph_mount_info
*cmount
, int fd
, int64_t offset
,
1331 struct sockaddr_storage
*addr
, int naddr
);
1334 * Get the list of OSDs where the objects containing a file offset are located.
1336 * @param cmount the ceph mount handle to use.
1337 * @param fd the open file descriptor referring to the file.
1338 * @param offset the offset within the file.
1339 * @param length return the number of bytes between the offset and the end of
1340 * the stripe unit (optional).
1341 * @param osds an integer array to hold the OSD ids.
1342 * @param nosds the size of the integer array.
1343 * @returns the number of items stored in the output array, or -ERANGE if the
1344 * array is not large enough.
1346 int ceph_get_file_extent_osds(struct ceph_mount_info
*cmount
, int fd
,
1347 int64_t offset
, int64_t *length
, int *osds
, int nosds
);
1350 * Get the fully qualified CRUSH location of an OSD.
1352 * Returns (type, name) string pairs for each device in the CRUSH bucket
1353 * hierarchy starting from the given osd to the root. Each pair element is
1354 * separated by a NULL character.
1356 * @param cmount the ceph mount handle to use.
1357 * @param osd the OSD id.
1358 * @param path buffer to store location.
1359 * @param len size of buffer.
1360 * @returns the amount of bytes written into the buffer, or -ERANGE if the
1361 * array is not large enough.
1363 int ceph_get_osd_crush_location(struct ceph_mount_info
*cmount
,
1364 int osd
, char *path
, size_t len
);
1367 * Get the network address of an OSD.
1369 * @param cmount the ceph mount handle.
1370 * @param osd the OSD id.
1371 * @param addr the OSD network address.
1372 * @returns zero on success, other returns a negative error code.
1374 int ceph_get_osd_addr(struct ceph_mount_info
*cmount
, int osd
,
1375 struct sockaddr_storage
*addr
);
1378 * Get the file layout stripe unit granularity.
1379 * @param cmount the ceph mount handle.
1380 * @returns the stripe unit granularity or a negative error code on failure.
1382 int ceph_get_stripe_unit_granularity(struct ceph_mount_info
*cmount
);
1384 /** @} filelayout */
1387 * No longer available. Do not use.
1388 * These functions will return -EOPNOTSUPP.
1390 int ceph_set_default_file_stripe_unit(struct ceph_mount_info
*cmount
, int stripe
);
1391 int ceph_set_default_file_stripe_count(struct ceph_mount_info
*cmount
, int count
);
1392 int ceph_set_default_object_size(struct ceph_mount_info
*cmount
, int size
);
1393 int ceph_set_default_preferred_pg(struct ceph_mount_info
*cmount
, int osd
);
1394 int ceph_set_default_file_replication(struct ceph_mount_info
*cmount
, int replication
);
1397 * Read from local replicas when possible.
1399 * @param cmount the ceph mount handle to use.
1400 * @param val a boolean to set (1) or clear (0) the option to favor local objects
1404 int ceph_localize_reads(struct ceph_mount_info
*cmount
, int val
);
1407 * Get the osd id of the local osd (if any)
1409 * @param cmount the ceph mount handle to use.
1410 * @returns the osd (if any) local to the node where this call is made, otherwise
1413 int ceph_get_local_osd(struct ceph_mount_info
*cmount
);
1415 /** @} default_filelayout */
1418 * Get the capabilities currently issued to the client.
1420 * @param cmount the ceph mount handle to use.
1421 * @param fd the file descriptor to get issued
1422 * @returns the current capabilities issued to this client
1425 int ceph_debug_get_fd_caps(struct ceph_mount_info
*cmount
, int fd
);
1428 * Get the capabilities currently issued to the client.
1430 * @param cmount the ceph mount handle to use.
1431 * @param path the path to the file
1432 * @returns the current capabilities issued to this client
1435 int ceph_debug_get_file_caps(struct ceph_mount_info
*cmount
, const char *path
);
1438 struct Inode
*ceph_ll_get_inode(struct ceph_mount_info
*cmount
,
1440 int ceph_ll_lookup_inode(
1441 struct ceph_mount_info
*cmount
,
1442 struct inodeno_t ino
,
1446 * Get the root inode of FS. Increase counter of references for root Inode. You must call ceph_ll_forget for it!
1448 * @param cmount the ceph mount handle to use.
1449 * @param parent pointer to pointer to Inode struct. Pointer to root inode will be returned
1450 * @returns 0 if all good
1452 int ceph_ll_lookup_root(struct ceph_mount_info
*cmount
,
1454 int ceph_ll_lookup(struct ceph_mount_info
*cmount
, Inode
*parent
,
1455 const char *name
, Inode
**out
, struct ceph_statx
*stx
,
1456 unsigned want
, unsigned flags
, const UserPerm
*perms
);
1457 int ceph_ll_put(struct ceph_mount_info
*cmount
, struct Inode
*in
);
1458 int ceph_ll_forget(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1460 int ceph_ll_walk(struct ceph_mount_info
*cmount
, const char* name
, Inode
**i
,
1461 struct ceph_statx
*stx
, unsigned int want
, unsigned int flags
,
1462 const UserPerm
*perms
);
1463 int ceph_ll_getattr(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1464 struct ceph_statx
*stx
, unsigned int want
, unsigned int flags
,
1465 const UserPerm
*perms
);
1466 int ceph_ll_setattr(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1467 struct ceph_statx
*stx
, int mask
, const UserPerm
*perms
);
1468 int ceph_ll_open(struct ceph_mount_info
*cmount
, struct Inode
*in
, int flags
,
1469 struct Fh
**fh
, const UserPerm
*perms
);
1470 off_t
ceph_ll_lseek(struct ceph_mount_info
*cmount
, struct Fh
* filehandle
,
1471 off_t offset
, int whence
);
1472 int ceph_ll_read(struct ceph_mount_info
*cmount
, struct Fh
* filehandle
,
1473 int64_t off
, uint64_t len
, char* buf
);
1474 int ceph_ll_fsync(struct ceph_mount_info
*cmount
, struct Fh
*fh
,
1476 int ceph_ll_write(struct ceph_mount_info
*cmount
, struct Fh
* filehandle
,
1477 int64_t off
, uint64_t len
, const char *data
);
1478 int64_t ceph_ll_readv(struct ceph_mount_info
*cmount
, struct Fh
*fh
,
1479 const struct iovec
*iov
, int iovcnt
, int64_t off
);
1480 int64_t ceph_ll_writev(struct ceph_mount_info
*cmount
, struct Fh
*fh
,
1481 const struct iovec
*iov
, int iovcnt
, int64_t off
);
1482 int ceph_ll_close(struct ceph_mount_info
*cmount
, struct Fh
* filehandle
);
1483 int ceph_ll_iclose(struct ceph_mount_info
*cmount
, struct Inode
*in
, int mode
);
1485 * Get xattr value by xattr name.
1487 * @param cmount the ceph mount handle to use.
1488 * @param in file handle
1489 * @param name name of attribute
1490 * @param value pointer to begin buffer
1491 * @param size buffer size
1492 * @param perms pointer to UserPerms object
1493 * @returns size of returned buffer. Negative number in error case
1495 int ceph_ll_getxattr(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1496 const char *name
, void *value
, size_t size
,
1497 const UserPerm
*perms
);
1498 int ceph_ll_setxattr(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1499 const char *name
, const void *value
, size_t size
,
1500 int flags
, const UserPerm
*perms
);
1501 int ceph_ll_listxattr(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1502 char *list
, size_t buf_size
, size_t *list_size
,
1503 const UserPerm
*perms
);
1504 int ceph_ll_removexattr(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1505 const char *name
, const UserPerm
*perms
);
1506 int ceph_ll_create(struct ceph_mount_info
*cmount
, Inode
*parent
,
1507 const char *name
, mode_t mode
, int oflags
, Inode
**outp
,
1508 Fh
**fhp
, struct ceph_statx
*stx
, unsigned want
,
1509 unsigned lflags
, const UserPerm
*perms
);
1510 int ceph_ll_mknod(struct ceph_mount_info
*cmount
, Inode
*parent
,
1511 const char *name
, mode_t mode
, dev_t rdev
, Inode
**out
,
1512 struct ceph_statx
*stx
, unsigned want
, unsigned flags
,
1513 const UserPerm
*perms
);
1514 int ceph_ll_mkdir(struct ceph_mount_info
*cmount
, Inode
*parent
,
1515 const char *name
, mode_t mode
, Inode
**out
,
1516 struct ceph_statx
*stx
, unsigned want
,
1517 unsigned flags
, const UserPerm
*perms
);
1518 int ceph_ll_link(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1519 struct Inode
*newparent
, const char *name
,
1520 const UserPerm
*perms
);
1521 int ceph_ll_opendir(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1522 struct ceph_dir_result
**dirpp
, const UserPerm
*perms
);
1523 int ceph_ll_releasedir(struct ceph_mount_info
*cmount
,
1524 struct ceph_dir_result
* dir
);
1525 int ceph_ll_rename(struct ceph_mount_info
*cmount
, struct Inode
*parent
,
1526 const char *name
, struct Inode
*newparent
,
1527 const char *newname
, const UserPerm
*perms
);
1528 int ceph_ll_unlink(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1529 const char *name
, const UserPerm
*perms
);
1530 int ceph_ll_statfs(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1531 struct statvfs
*stbuf
);
1532 int ceph_ll_readlink(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1533 char *buf
, size_t bufsize
, const UserPerm
*perms
);
1534 int ceph_ll_symlink(struct ceph_mount_info
*cmount
,
1535 Inode
*in
, const char *name
, const char *value
,
1536 Inode
**out
, struct ceph_statx
*stx
,
1537 unsigned want
, unsigned flags
,
1538 const UserPerm
*perms
);
1539 int ceph_ll_rmdir(struct ceph_mount_info
*cmount
, struct Inode
*in
,
1540 const char *name
, const UserPerm
*perms
);
1541 uint32_t ceph_ll_stripe_unit(struct ceph_mount_info
*cmount
,
1543 uint32_t ceph_ll_file_layout(struct ceph_mount_info
*cmount
,
1545 struct ceph_file_layout
*layout
);
1546 uint64_t ceph_ll_snap_seq(struct ceph_mount_info
*cmount
,
1548 int ceph_ll_get_stripe_osd(struct ceph_mount_info
*cmount
,
1551 struct ceph_file_layout
* layout
);
1552 int ceph_ll_num_osds(struct ceph_mount_info
*cmount
);
1553 int ceph_ll_osdaddr(struct ceph_mount_info
*cmount
,
1554 int osd
, uint32_t *addr
);
1555 uint64_t ceph_ll_get_internal_offset(struct ceph_mount_info
*cmount
,
1556 struct Inode
*in
, uint64_t blockno
);
1557 int ceph_ll_read_block(struct ceph_mount_info
*cmount
,
1558 struct Inode
*in
, uint64_t blockid
,
1559 char* bl
, uint64_t offset
, uint64_t length
,
1560 struct ceph_file_layout
* layout
);
1561 int ceph_ll_write_block(struct ceph_mount_info
*cmount
,
1562 struct Inode
*in
, uint64_t blockid
,
1563 char* buf
, uint64_t offset
,
1564 uint64_t length
, struct ceph_file_layout
* layout
,
1565 uint64_t snapseq
, uint32_t sync
);
1566 int ceph_ll_commit_blocks(struct ceph_mount_info
*cmount
,
1567 struct Inode
*in
, uint64_t offset
, uint64_t range
);
1570 int ceph_ll_getlk(struct ceph_mount_info
*cmount
,
1571 Fh
*fh
, struct flock
*fl
, uint64_t owner
);
1572 int ceph_ll_setlk(struct ceph_mount_info
*cmount
,
1573 Fh
*fh
, struct flock
*fl
, uint64_t owner
, int sleep
);
1576 * Delegation support
1578 * Delegations are way for an application to request exclusive or
1579 * semi-exclusive access to an Inode. The client requests the delegation and
1580 * if it's successful it can reliably cache file data and metadata until the
1581 * delegation is recalled.
1583 * Recalls are issued via a callback function, provided by the application.
1584 * Callback functions should act something like signal handlers. You want to
1585 * do as little as possible in the callback. Any major work should be deferred
1586 * in some fashion as it's difficult to predict the context in which this
1587 * function will be called.
1589 * Once the delegation has been recalled, the application should return it as
1590 * soon as possible. The application has client_deleg_timeout seconds to
1591 * return it, after which the cmount structure is forcibly unmounted and
1592 * further calls into it fail.
1594 * The application can set the client_deleg_timeout config option to suit its
1595 * needs, but it should take care to choose a value that allows it to avoid
1596 * forcible eviction from the cluster in the event of an application bug.
1598 typedef void (*ceph_deleg_cb_t
)(struct Fh
*fh
, void *priv
);
1600 /* Commands for manipulating delegation state */
1601 #ifndef CEPH_DELEGATION_NONE
1602 # define CEPH_DELEGATION_NONE 0
1603 # define CEPH_DELEGATION_RD 1
1604 # define CEPH_DELEGATION_WR 2
1608 * Get the amount of time that the client has to return caps
1609 * @param cmount the ceph mount handle to use.
1611 * In the event that a client does not return its caps, the MDS may blacklist
1612 * it after this timeout. Applications should check this value and ensure
1613 * that they set the delegation timeout to a value lower than this.
1615 * This call returns the cap return timeout (in seconds) for this cmount, or
1616 * zero if it's not mounted.
1618 uint32_t ceph_get_cap_return_timeout(struct ceph_mount_info
*cmount
);
1621 * Set the delegation timeout for the mount (thereby enabling delegations)
1622 * @param cmount the ceph mount handle to use.
1623 * @param timeout the delegation timeout (in seconds)
1625 * Since the client could end up blacklisted if it doesn't return delegations
1626 * in time, we mandate that any application wanting to use delegations
1627 * explicitly set the timeout beforehand. Until this call is done on the
1628 * mount, attempts to set a delegation will return -ETIME.
1630 * Once a delegation is recalled, if it is not returned in this amount of
1631 * time, the cmount will be forcibly unmounted and further access attempts
1632 * will fail (usually with -ENOTCONN errors).
1634 * This value is further vetted against the cap return timeout, and this call
1635 * can fail with -EINVAL if the timeout value is too long. Delegations can be
1636 * disabled again by setting the timeout to 0.
1638 int ceph_set_deleg_timeout(struct ceph_mount_info
*cmount
, uint32_t timeout
);
1641 * Request a delegation on an open Fh
1642 * @param cmount the ceph mount handle to use.
1643 * @param fh file handle
1644 * @param cmd CEPH_DELEGATION_* command
1645 * @param cb callback function for recalling delegation
1646 * @param priv opaque token passed back during recalls
1648 * Returns 0 if the delegation was granted, -EAGAIN if there was a conflict
1649 * and other error codes if there is a fatal error of some sort (e.g. -ENOMEM,
1652 int ceph_ll_delegation(struct ceph_mount_info
*cmount
, Fh
*fh
,
1653 unsigned int cmd
, ceph_deleg_cb_t cb
, void *priv
);