Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / 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
3 /*
4  * Ceph - scalable distributed file system
5  *
6  * Copyright (C) 2009-2011 New Dream Network
7  *
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.
12  *
13  */
14
15 #ifndef CEPH_LIB_H
16 #define CEPH_LIB_H
17
18 #if defined(__linux__)
19 #include <features.h>
20 #endif
21 #include <utime.h>
22 #include <sys/stat.h>
23 #include <sys/types.h>
24 #include <sys/statvfs.h>
25 #include <sys/socket.h>
26 #include <stdint.h>
27 #include <stdbool.h>
28 #include <fcntl.h>
29
30 #include "ceph_statx.h"
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 #define LIBCEPHFS_VER_MAJOR 10
37 #define LIBCEPHFS_VER_MINOR 0
38 #define LIBCEPHFS_VER_EXTRA 2
39
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)
42
43 /*
44  * If using glibc check that file offset is 64-bit.
45  */
46 #if defined(__GLIBC__) && !defined(__USE_FILE_OFFSET64)
47 # error libceph: glibc must define __USE_FILE_OFFSET64 or readdir results will be corrupted
48 #endif
49
50 /*
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
53  * C data types).
54  */
55 #ifndef __cplusplus
56
57 #define CEPH_INO_ROOT  1
58 #define CEPH_NOSNAP  ((uint64_t)(-2))
59
60 struct ceph_file_layout {
61         /* file -> object mapping */
62         uint32_t fl_stripe_unit;     /* stripe unit, in bytes.  must be multiple
63                                       of page size. */
64         uint32_t fl_stripe_count;    /* over this many objects */
65         uint32_t fl_object_size;     /* until objects are this big, then move to
66                                       new objects */
67         uint32_t fl_cas_hash;        /* 0 = none; 1 = sha256 */
68
69         /* pg -> disk layout */
70         uint32_t fl_object_stripe_unit;  /* for per-object parity, if any */
71
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));
76
77
78 typedef struct inodeno_t {
79   uint64_t val;
80 } inodeno_t;
81
82 typedef struct _snapid_t {
83   uint64_t val;
84 } snapid_t;
85
86 typedef struct vinodeno_t {
87   inodeno_t ino;
88   snapid_t snapid;
89 } vinodeno_t;
90
91 typedef struct Fh Fh;
92 #else /* _cplusplus */
93
94 struct inodeno_t;
95 struct vinodeno_t;
96 typedef struct vinodeno_t vinodeno;
97
98 #endif /* ! __cplusplus */
99
100 struct UserPerm;
101 typedef struct UserPerm UserPerm;
102
103 struct Inode;
104 typedef struct Inode Inode;
105
106 struct ceph_mount_info;
107 struct ceph_dir_result;
108 struct CephContext;
109
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
120 #endif
121
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
126
127 /**
128  * Create a UserPerm credential object.
129  *
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.
134  *
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.
137  *
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
142  */
143 UserPerm *ceph_userperm_new(uid_t uid, gid_t gid, int ngids, gid_t *gidlist);
144
145 /**
146  * Destroy a UserPerm credential object.
147  *
148  * @param perm pointer to object to be destroyed
149  *
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.
152  */
153 void ceph_userperm_destroy(UserPerm *perm);
154
155 /**
156  * Get a pointer to the default UserPerm object for the mount.
157  *
158  * @param cmount the mount info handle
159  *
160  * Every cmount has a default set of credentials. This returns a pointer to
161  * that object.
162  *
163  * Unlike with ceph_userperm_new, this object should not be freed.
164  */
165 struct UserPerm *ceph_mount_perms(struct ceph_mount_info *cmount);
166
167 /**
168  * @defgroup libcephfs_h_init Setup and Teardown
169  * These are the first and last functions that should be called
170  * when using libcephfs.
171  *
172  * @{
173  */
174
175 /**
176  * Get the version of libcephfs.
177  *
178  * The version number is major.minor.patch.
179  *
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
183  */
184 const char *ceph_version(int *major, int *minor, int *patch);
185
186 /**
187  * Create a mount handle for interacting with Ceph.  All libcephfs
188  * functions operate on a mount info handle.
189  *
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
195  */
196 int ceph_create(struct ceph_mount_info **cmount, const char * const id);
197
198 /**
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.
203  *
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
207  */
208 int ceph_create_with_context(struct ceph_mount_info **cmount, struct CephContext *conf);
209
210
211 #ifndef VOIDPTR_RADOS_T
212 #define VOIDPTR_RADOS_T
213 typedef void *rados_t;
214 #endif // VOIDPTR_RADOS_T
215
216 /**
217  * Create a mount handle from a rados_t, for using libcephfs in the
218  * same process as librados.
219  *
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
223  */
224 int ceph_create_from_rados(struct ceph_mount_info **cmount, rados_t cluster);
225
226 /**
227  * Initialize the filesystem client (but do not mount the filesystem yet)
228  *
229  * @returns 0 on success, negative error code on failure
230  */
231 int ceph_init(struct ceph_mount_info *cmount);
232
233
234 /**
235  * Perform a mount using the path for the root of the mount.
236  *
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.
239  *
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
245  */
246 int ceph_mount(struct ceph_mount_info *cmount, const char *root);
247
248 /**
249  * Execute a management command remotely on an MDS.
250  *
251  * Must have called ceph_init or ceph_mount before calling this.
252  *
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
262  *
263  * @return 0 on success, negative error code on failure
264  *
265  */
266 int ceph_mds_command(struct ceph_mount_info *cmount,
267     const char *mds_spec,
268     const char **cmd,
269     size_t cmdlen,
270     const char *inbuf, size_t inbuflen,
271     char **outbuf, size_t *outbuflen,
272     char **outs, size_t *outslen);
273
274 /**
275  * Free a buffer, such as those used for output arrays from ceph_mds_command
276  */
277 void ceph_buffer_free(char *buf);
278
279 /**
280  * Unmount a mount handle.
281  *
282  * @param cmount the mount handle
283  * @return 0 on success, negative error code on failure
284  */
285 int ceph_unmount(struct ceph_mount_info *cmount);
286
287 /**
288  * Destroy the mount handle.
289  *
290  * The handle should not be mounted. This should be called on completion of
291  * all libcephfs functions.
292  *
293  * @param cmount the mount handle
294  * @return 0 on success, negative error code on failure.
295  */
296 int ceph_release(struct ceph_mount_info *cmount);
297
298 /**
299  * Deprecated. Unmount and destroy the ceph mount handle. This should be
300  * called on completion of all libcephfs functions.
301  *
302  * Equivalent to ceph_unmount() + ceph_release() without error handling.
303  *
304  * @param cmount the mount handle to shutdown
305  */
306 void ceph_shutdown(struct ceph_mount_info *cmount);
307
308 /**
309  * Extract the CephContext from the mount point handle.
310  *
311  * @param cmount the ceph mount handle to get the context from.
312  * @returns the CephContext associated with the mount handle.
313  */
314 struct CephContext *ceph_get_mount_context(struct ceph_mount_info *cmount);
315
316 /*
317  * Check mount status.
318  *
319  * Return non-zero value if mounted. Otherwise, zero.
320  */
321 int ceph_is_mounted(struct ceph_mount_info *cmount);
322
323 /** @} init */
324
325 /**
326  * @defgroup libcephfs_h_config Config
327  * Functions for manipulating the Ceph configuration at runtime.
328  *
329  * @{
330  */
331
332 /**
333  * Load the ceph configuration from the specified config file.
334  *
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
338  */
339 int ceph_conf_read_file(struct ceph_mount_info *cmount, const char *path_list);
340
341 /**
342  * Parse the command line arguments and load the configuration parameters.
343  *
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
348  */
349 int ceph_conf_parse_argv(struct ceph_mount_info *cmount, int argc, const char **argv);
350
351 /**
352  * Configure the cluster handle based on an environment variable
353  *
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.
357  *
358  * @pre ceph_mount() has not been called on the handle
359  *
360  * @note BUG: this is not threadsafe - it uses a static buffer
361  *
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
365  */
366 int ceph_conf_parse_env(struct ceph_mount_info *cmount, const char *var);
367
368 /** Sets a configuration value from a string.
369  *
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
373  * 
374  * @returns 0 on success, negative error code otherwise.
375  */
376 int ceph_conf_set(struct ceph_mount_info *cmount, const char *option, const char *value);
377
378 /**
379  * Gets the configuration value as a string.
380  *
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
386  */
387 int ceph_conf_get(struct ceph_mount_info *cmount, const char *option, char *buf, size_t len);
388
389 /** @} config */
390
391 /**
392  * @defgroup libcephfs_h_fsops File System Operations.
393  * Functions for getting/setting file system wide information specific to a particular
394  * mount handle.
395  *
396  * @{
397  */
398
399 /**
400  * Perform a statfs on the ceph file system.  This call fills in file system wide statistics
401  * into the passed in buffer.
402  *
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.
407  */
408 int ceph_statfs(struct ceph_mount_info *cmount, const char *path, struct statvfs *stbuf);
409
410 /**
411  * Synchronize all filesystem data to persistent media.
412  *
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.
415  */
416 int ceph_sync_fs(struct ceph_mount_info *cmount);
417
418 /**
419  * Get the current working directory.
420  *
421  * @param cmount the ceph mount to get the current working directory for.
422  * @returns the path to the current working directory
423  */
424 const char* ceph_getcwd(struct ceph_mount_info *cmount);
425
426 /**
427  * Change the current working directory.
428  *
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.
432  */
433 int ceph_chdir(struct ceph_mount_info *cmount, const char *path);
434
435 /** @} fsops */
436
437 /**
438  * @defgroup libcephfs_h_dir Directory Operations.
439  * Functions for manipulating and listing directories.
440  *
441  * @{
442  */
443
444 /**
445  * Open the given directory.
446  *
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.
452  */
453 int ceph_opendir(struct ceph_mount_info *cmount, const char *name, struct ceph_dir_result **dirpp);
454
455 /**
456  * Close the open directory.
457  *
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.
461  */
462 int ceph_closedir(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp);
463
464 /**
465  * Get the next entry in an open directory.
466  *
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.
473  */
474 struct dirent * ceph_readdir(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp);
475
476 /**
477  * A safe version of ceph_readdir, where the directory entry struct is allocated by the caller.
478  *
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.
485  */
486 int ceph_readdir_r(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp, struct dirent *de);
487
488 /**
489  * A safe version of ceph_readdir that also returns the file statistics (readdir+stat).
490  *
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.
502  */
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);
505
506 /**
507  * Gets multiple directory entries.
508  *
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.
516  */
517 int ceph_getdents(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp, char *name, int buflen);
518
519 /**
520  * Gets multiple directory names.
521  * 
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.
529  */
530 int ceph_getdnames(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp, char *name, int buflen);
531
532 /**
533  * Rewind the directory stream to the beginning of the directory.
534  *
535  * @param cmount the ceph mount handle to use for performing the rewinddir.
536  * @param dirp the directory stream pointer to rewind.
537  */
538 void ceph_rewinddir(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp);
539
540 /**
541  * Get the current position of a directory stream.
542  *
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
547  *          inequality).
548  */
549 int64_t ceph_telldir(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp);
550
551 /**
552  * Move the directory stream to a position specified by the given offset.
553  *
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.
559  */
560 void ceph_seekdir(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp, int64_t offset);
561
562 /**
563  * Create a directory.
564  *
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.
570  */
571 int ceph_mkdir(struct ceph_mount_info *cmount, const char *path, mode_t mode);
572
573 /**
574  * Create multiple directories at once.
575  *
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
578  *        be created.
579  * @param mode the permissions the directory should have once created.
580  * @returns 0 on success or a negative return code on error.
581  */
582 int ceph_mkdirs(struct ceph_mount_info *cmount, const char *path, mode_t mode);
583
584 /**
585  * Remove a directory.
586  *
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.
590  */
591 int ceph_rmdir(struct ceph_mount_info *cmount, const char *path);
592
593 /** @} dir */
594
595 /**
596  * @defgroup libcephfs_h_links Links and Link Handling.
597  * Functions for creating and manipulating hard links and symbolic inks.
598  *
599  * @{
600  */
601
602 /**
603  * Create a link.
604  *
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.
609  */
610 int ceph_link(struct ceph_mount_info *cmount, const char *existing, const char *newname);
611
612 /**
613  * Read a symbolic link.
614  *
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
620  */
621 int ceph_readlink(struct ceph_mount_info *cmount, const char *path, char *buf, int64_t size);
622
623 /**
624  * Creates a symbolic link.
625  *
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.
630  */
631 int ceph_symlink(struct ceph_mount_info *cmount, const char *existing, const char *newname);
632
633 /** @} links */
634
635 /**
636  * @defgroup libcephfs_h_files File manipulation and handling.
637  * Functions for creating and manipulating files.
638  *
639  * @{
640  */
641
642 /**
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.
645  * 
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.
649  */
650 int ceph_unlink(struct ceph_mount_info *cmount, const char *path);
651
652 /**
653  * Rename a file or directory.
654  *
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.
659  */
660 int ceph_rename(struct ceph_mount_info *cmount, const char *from, const char *to);
661
662 /**
663  * Get an open file's extended statistics and attributes.
664  *
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.
671  */
672 int ceph_fstatx(struct ceph_mount_info *cmount, int fd, struct ceph_statx *stx,
673                 unsigned int want, unsigned int flags);
674
675 /**
676  * Get a file's extended statistics and attributes.
677  *
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.
684  */
685 int ceph_statx(struct ceph_mount_info *cmount, const char *path, struct ceph_statx *stx,
686                unsigned int want, unsigned int flags);
687
688 /**
689  * Set a file's attributes.
690  *
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.
697  */
698 int ceph_setattrx(struct ceph_mount_info *cmount, const char *relpath, struct ceph_statx *stx, int mask, int flags);
699
700 /**
701  * Set a file's attributes (extended version).
702  * 
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.
708  */
709 int ceph_fsetattrx(struct ceph_mount_info *cmount, int fd, struct ceph_statx *stx, int mask);
710
711 /**
712  * Change the mode bits (permissions) of a file/directory.
713  *
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.
718  */
719 int ceph_chmod(struct ceph_mount_info *cmount, const char *path, mode_t mode);
720
721 /**
722  * Change the mode bits (permissions) of an open file.
723  *
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.
728  */
729 int ceph_fchmod(struct ceph_mount_info *cmount, int fd, mode_t mode);
730
731 /**
732  * Change the ownership of a file/directory.
733  * 
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.
739  */
740 int ceph_chown(struct ceph_mount_info *cmount, const char *path, int uid, int gid);
741
742 /**
743  * Change the ownership of a file from an open file descriptor.
744  *
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.
750  */
751 int ceph_fchown(struct ceph_mount_info *cmount, int fd, int uid, int gid);
752
753 /**
754  * Change the ownership of a file/directory, don't follow symlinks.
755  * 
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.
761  */
762 int ceph_lchown(struct ceph_mount_info *cmount, const char *path, int uid, int gid);
763
764 /**
765  * Change file/directory last access and modification times.
766  *
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.
771  */
772 int ceph_utime(struct ceph_mount_info *cmount, const char *path, struct utimbuf *buf);
773
774 /**
775  * Apply or remove an advisory lock.
776  *
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.
785  */
786 int ceph_flock(struct ceph_mount_info *cmount, int fd, int operation,
787                uint64_t owner);
788
789 /**
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.
792  *
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.
797  */
798 int ceph_truncate(struct ceph_mount_info *cmount, const char *path, int64_t size);
799
800 /**
801  * Make a block or character special file.
802  *
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, 
809  *        it is ignored.
810  * @returns 0 on success or negative error code on failure.
811  */
812 int ceph_mknod(struct ceph_mount_info *cmount, const char *path, mode_t mode, dev_t rdev);
813 /**
814  * Create and/or open a file.
815  *
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.
823  */
824 int ceph_open(struct ceph_mount_info *cmount, const char *path, int flags, mode_t mode);
825
826 /**
827  * Create and/or open a file with a specific file layout.
828  *
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.
840  */
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);
844
845 /**
846  * Close the open file.
847  *
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.
851  */
852 int ceph_close(struct ceph_mount_info *cmount, int fd);
853
854 /**
855  * Reposition the open file stream based on the given offset.
856  *
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.
866  */
867 int64_t ceph_lseek(struct ceph_mount_info *cmount, int fd, int64_t offset, int whence);
868 /**
869  * Read data from the file.
870  *
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.
878  */
879 int ceph_read(struct ceph_mount_info *cmount, int fd, char *buf, int64_t size, int64_t offset);
880
881 /**
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.
890  */
891 int ceph_preadv(struct ceph_mount_info *cmount, int fd, const struct iovec *iov, int iovcnt,
892            int64_t offset);
893
894 /**
895  * Write data to a file.
896  *
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
904  */
905 int ceph_write(struct ceph_mount_info *cmount, int fd, const char *buf, int64_t size,
906                int64_t offset);
907
908 /**
909  * Write data to a file.
910  *
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
918  */
919 int ceph_pwritev(struct ceph_mount_info *cmount, int fd, const struct iovec *iov, int iovcnt,
920            int64_t offset);
921
922 /**
923  * Truncate a file to the given size.
924  *
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.
929  */
930 int ceph_ftruncate(struct ceph_mount_info *cmount, int fd, int64_t size);
931
932 /**
933  * Synchronize an open file to persistent media.
934  *
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)
938  *        or just data (1).
939  * @return 0 on success or a negative error code on failure.
940  */
941 int ceph_fsync(struct ceph_mount_info *cmount, int fd, int syncdataonly);
942
943 /**
944  * Preallocate or release disk space for the file for the byte range.
945  *
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.
957  */
958 int ceph_fallocate(struct ceph_mount_info *cmount, int fd, int mode,
959                               int64_t offset, int64_t length);
960
961 /** @} file */
962
963 /**
964  * @defgroup libcephfs_h_xattr Extended Attribute manipulation and handling.
965  * Functions for creating and manipulating extended attributes on files.
966  *
967  * @{
968  */
969
970 /**
971  * Get an extended attribute.
972  *
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.
979  */
980 int ceph_getxattr(struct ceph_mount_info *cmount, const char *path, const char *name, 
981         void *value, size_t size);
982
983 /**
984  * Get an extended attribute.
985  *
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.
992  */
993 int ceph_fgetxattr(struct ceph_mount_info *cmount, int fd, const char *name,
994         void *value, size_t size);
995
996 /**
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.
1001  *
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.
1008  */
1009 int ceph_lgetxattr(struct ceph_mount_info *cmount, const char *path, const char *name, 
1010         void *value, size_t size);
1011
1012 /**
1013  * List the extended attribute keys on a file.
1014  *
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.
1020  */
1021 int ceph_listxattr(struct ceph_mount_info *cmount, const char *path, char *list, size_t size);
1022
1023 /**
1024  * List the extended attribute keys on a file.
1025  *
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.
1031  */
1032 int ceph_flistxattr(struct ceph_mount_info *cmount, int fd, char *list, size_t size);
1033
1034 /**
1035  * Get the list of extended attribute keys on a file, but do not follow symbolic links.
1036  *
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.
1042  */
1043 int ceph_llistxattr(struct ceph_mount_info *cmount, const char *path, char *list, size_t size);
1044
1045 /**
1046  * Remove an extended attribute from a file.
1047  *
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.
1052  */
1053 int ceph_removexattr(struct ceph_mount_info *cmount, const char *path, const char *name);
1054
1055 /**
1056  * Remove an extended attribute from a file.
1057  *
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.
1062  */
1063 int ceph_fremovexattr(struct ceph_mount_info *cmount, int fd, const char *name);
1064
1065 /**
1066  * Remove the extended attribute from a file, do not follow symbolic links.
1067  *
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.
1072  */
1073 int ceph_lremovexattr(struct ceph_mount_info *cmount, const char *path, const char *name);
1074
1075 /**
1076  * Set an extended attribute on a file.
1077  *
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.
1087  */
1088 int ceph_setxattr(struct ceph_mount_info *cmount, const char *path, const char *name, 
1089         const void *value, size_t size, int flags);
1090
1091 /**
1092  * Set an extended attribute on a file.
1093  *
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.
1103  */
1104 int ceph_fsetxattr(struct ceph_mount_info *cmount, int fd, const char *name,
1105         const void *value, size_t size, int flags);
1106
1107 /**
1108  * Set an extended attribute on a file, do not follow symbolic links.
1109  *
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.
1119  */
1120 int ceph_lsetxattr(struct ceph_mount_info *cmount, const char *path, const char *name, 
1121         const void *value, size_t size, int flags);
1122
1123 /** @} xattr */
1124
1125 /**
1126  * @defgroup libcephfs_h_filelayout Control File Layout.
1127  * Functions for setting and getting the file layout of existing files.
1128  *
1129  * @{
1130  */
1131
1132 /**
1133  * Get the file striping unit from an open file descriptor.
1134  *
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.
1138  */
1139 int ceph_get_file_stripe_unit(struct ceph_mount_info *cmount, int fh);
1140
1141 /**
1142  * Get the file striping unit.
1143  *
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.
1147  */
1148 int ceph_get_path_stripe_unit(struct ceph_mount_info *cmount, const char *path);
1149
1150 /**
1151  * Get the file striping count from an open file descriptor.
1152  *
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.
1156  */
1157 int ceph_get_file_stripe_count(struct ceph_mount_info *cmount, int fh);
1158
1159 /**
1160  * Get the file striping count.
1161  *
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.
1165  */
1166 int ceph_get_path_stripe_count(struct ceph_mount_info *cmount, const char *path);
1167
1168 /**
1169  * Get the file object size from an open file descriptor.
1170  *
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.
1174  */
1175 int ceph_get_file_object_size(struct ceph_mount_info *cmount, int fh);
1176
1177 /**
1178  * Get the file object size.
1179  *
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.
1183  */
1184 int ceph_get_path_object_size(struct ceph_mount_info *cmount, const char *path);
1185
1186 /**
1187  * Get the file pool information from an open file descriptor.
1188  *
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
1192  */
1193 int ceph_get_file_pool(struct ceph_mount_info *cmount, int fh);
1194
1195 /**
1196  * Get the file pool information.
1197  *
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
1201  */
1202 int ceph_get_path_pool(struct ceph_mount_info *cmount, const char *path);
1203
1204 /**
1205  * Get the name of the pool a opened file is stored in,
1206  *
1207  * Write the name of the file's pool to the buffer.  If buflen is 0, return
1208  * a suggested length for the buffer.
1209  *
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.
1215  */
1216 int ceph_get_file_pool_name(struct ceph_mount_info *cmount, int fh, char *buf, size_t buflen);
1217
1218 /**
1219  * get the name of a pool by id
1220  *
1221  * Given a pool's numeric identifier, get the pool's alphanumeric name.
1222  *
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
1228  */
1229 int ceph_get_pool_name(struct ceph_mount_info *cmount, int pool, char *buf, size_t buflen);
1230
1231 /**
1232  * Get the name of the pool a file is stored in
1233  *
1234  * Write the name of the file's pool to the buffer.  If buflen is 0, return
1235  * a suggested length for the buffer.
1236  *
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.
1242  */
1243 int ceph_get_path_pool_name(struct ceph_mount_info *cmount, const char *path, char *buf, size_t buflen);
1244
1245 /**
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.
1253  */
1254 int ceph_get_default_data_pool_name(struct ceph_mount_info *cmount, char *buf, size_t buflen);
1255
1256 /**
1257  * Get the file layout from an open file descriptor.
1258  *
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.
1266  */
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);
1268
1269 /**
1270  * Get the file layout.
1271  *
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.
1279  */
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);
1281
1282 /**
1283  * Get the file replication information from an open file descriptor.
1284  *
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.
1288  */
1289 int ceph_get_file_replication(struct ceph_mount_info *cmount, int fh);
1290
1291 /**
1292  * Get the file replication information.
1293  *
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.
1297  */
1298 int ceph_get_path_replication(struct ceph_mount_info *cmount, const char *path);
1299
1300 /**
1301  * Get the id of the named pool.
1302  *
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.
1306  */
1307 int ceph_get_pool_id(struct ceph_mount_info *cmount, const char *pool_name);
1308
1309 /**
1310  * Get the pool replication factor.
1311  *
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.
1315  */
1316 int ceph_get_pool_replication(struct ceph_mount_info *cmount, int pool_id);
1317
1318 /**
1319  * Get the OSD address where the primary copy of a file stripe is located.
1320  *
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.
1329  */
1330 int ceph_get_file_stripe_address(struct ceph_mount_info *cmount, int fd, int64_t offset,
1331                                  struct sockaddr_storage *addr, int naddr);
1332
1333 /**
1334  * Get the list of OSDs where the objects containing a file offset are located.
1335  *
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.
1345  */
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);
1348
1349 /**
1350  * Get the fully qualified CRUSH location of an OSD.
1351  *
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.
1355  *
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.
1362  */
1363 int ceph_get_osd_crush_location(struct ceph_mount_info *cmount,
1364     int osd, char *path, size_t len);
1365
1366 /**
1367  * Get the network address of an OSD.
1368  *
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.
1373  */
1374 int ceph_get_osd_addr(struct ceph_mount_info *cmount, int osd,
1375     struct sockaddr_storage *addr);
1376
1377 /**
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.
1381  */
1382 int ceph_get_stripe_unit_granularity(struct ceph_mount_info *cmount);
1383
1384 /** @} filelayout */
1385
1386 /**
1387  * No longer available.  Do not use.
1388  * These functions will return -EOPNOTSUPP.
1389  */
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);
1395
1396 /**
1397  * Read from local replicas when possible.
1398  *
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
1401  *     for reads.
1402  * @returns 0
1403  */
1404 int ceph_localize_reads(struct ceph_mount_info *cmount, int val);
1405
1406 /**
1407  * Get the osd id of the local osd (if any)
1408  *
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
1411  *      -1 is returned.
1412  */
1413 int ceph_get_local_osd(struct ceph_mount_info *cmount);
1414
1415 /** @} default_filelayout */
1416
1417 /**
1418  * Get the capabilities currently issued to the client.
1419  *
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
1423  *       for the open file
1424  */
1425 int ceph_debug_get_fd_caps(struct ceph_mount_info *cmount, int fd);
1426
1427 /**
1428  * Get the capabilities currently issued to the client.
1429  *
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
1433  *       for the file
1434  */
1435 int ceph_debug_get_file_caps(struct ceph_mount_info *cmount, const char *path);
1436
1437 /* Low Level */
1438 struct Inode *ceph_ll_get_inode(struct ceph_mount_info *cmount,
1439                                 vinodeno_t vino);
1440 int ceph_ll_lookup_inode(
1441     struct ceph_mount_info *cmount,
1442     struct inodeno_t ino,
1443     Inode **inode);
1444
1445 /**
1446  * Get the root inode of FS. Increase counter of references for root Inode. You must call ceph_ll_forget for it!
1447  *
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
1451  */
1452 int ceph_ll_lookup_root(struct ceph_mount_info *cmount,
1453                   Inode **parent);
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,
1459                    int count);
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,
1475                   int syncdataonly);
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);
1484 /**
1485  * Get xattr value by xattr name.
1486  *
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
1494  */
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,
1542                              struct Inode *in);
1543 uint32_t ceph_ll_file_layout(struct ceph_mount_info *cmount,
1544                              struct Inode *in,
1545                              struct ceph_file_layout *layout);
1546 uint64_t ceph_ll_snap_seq(struct ceph_mount_info *cmount,
1547                           struct Inode *in);
1548 int ceph_ll_get_stripe_osd(struct ceph_mount_info *cmount,
1549                            struct Inode *in,
1550                            uint64_t blockno,
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);
1568
1569
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);
1574
1575 #ifdef __cplusplus
1576 }
1577 #endif
1578
1579 #endif