]> git.proxmox.com Git - ceph.git/blob - ceph/src/include/cephfs/libcephfs.h
import 15.2.4
[ceph.git] / 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_ll_client.h"
31
32 #ifdef __cplusplus
33 namespace ceph::common {
34 class CephContext;
35 }
36 using CephContext = ceph::common::CephContext;
37 extern "C" {
38 #endif
39
40 #define LIBCEPHFS_VER_MAJOR 10
41 #define LIBCEPHFS_VER_MINOR 0
42 #define LIBCEPHFS_VER_EXTRA 2
43
44 #define LIBCEPHFS_VERSION(maj, min, extra) ((maj << 16) + (min << 8) + extra)
45 #define LIBCEPHFS_VERSION_CODE LIBCEPHFS_VERSION(LIBCEPHFS_VER_MAJOR, LIBCEPHFS_VER_MINOR, LIBCEPHFS_VER_EXTRA)
46
47 /*
48 * If using glibc check that file offset is 64-bit.
49 */
50 #if defined(__GLIBC__) && !defined(__USE_FILE_OFFSET64)
51 # error libceph: glibc must define __USE_FILE_OFFSET64 or readdir results will be corrupted
52 #endif
53
54 /*
55 * XXXX redeclarations from ceph_fs.h, rados.h, etc. We need more of this
56 * in the interface, but shouldn't be re-typing it (and using different
57 * C data types).
58 */
59 #ifndef __cplusplus
60
61 #define CEPH_INO_ROOT 1
62 #define CEPH_NOSNAP ((uint64_t)(-2))
63
64 struct ceph_file_layout {
65 /* file -> object mapping */
66 uint32_t fl_stripe_unit; /* stripe unit, in bytes. must be multiple
67 of page size. */
68 uint32_t fl_stripe_count; /* over this many objects */
69 uint32_t fl_object_size; /* until objects are this big, then move to
70 new objects */
71 uint32_t fl_cas_hash; /* 0 = none; 1 = sha256 */
72
73 /* pg -> disk layout */
74 uint32_t fl_object_stripe_unit; /* for per-object parity, if any */
75
76 /* object -> pg layout */
77 uint32_t fl_pg_preferred; /* preferred primary for pg (-1 for none) */
78 uint32_t fl_pg_pool; /* namespace, crush ruleset, rep level */
79 } __attribute__ ((packed));
80
81 struct CephContext;
82 #endif /* ! __cplusplus */
83
84 struct UserPerm;
85 typedef struct UserPerm UserPerm;
86
87 struct Inode;
88 typedef struct Inode Inode;
89
90 struct ceph_mount_info;
91 struct ceph_dir_result;
92
93 /* setattr mask bits */
94 #ifndef CEPH_SETATTR_MODE
95 # define CEPH_SETATTR_MODE 1
96 # define CEPH_SETATTR_UID 2
97 # define CEPH_SETATTR_GID 4
98 # define CEPH_SETATTR_MTIME 8
99 # define CEPH_SETATTR_ATIME 16
100 # define CEPH_SETATTR_SIZE 32
101 # define CEPH_SETATTR_CTIME 64
102 # define CEPH_SETATTR_MTIME_NOW 128
103 # define CEPH_SETATTR_ATIME_NOW 256
104 # define CEPH_SETATTR_BTIME 512
105 #endif
106
107 /* define error codes for the mount function*/
108 # define CEPHFS_ERROR_MON_MAP_BUILD 1000
109 # define CEPHFS_ERROR_NEW_CLIENT 1002
110 # define CEPHFS_ERROR_MESSENGER_START 1003
111
112 /**
113 * Create a UserPerm credential object.
114 *
115 * Some calls (most notably, the ceph_ll_* ones), take a credential object
116 * that represents the credentials that the calling program is using. This
117 * function creates a new credential object for this purpose. Returns a
118 * pointer to the object, or NULL if it can't be allocated.
119 *
120 * Note that the gidlist array is used directly and is not copied. It must
121 * remain valid over the lifetime of the created UserPerm object.
122 *
123 * @param uid uid to be used
124 * @param gid gid to be used
125 * @param ngids number of gids in supplemental grouplist
126 * @param gidlist array of gid_t's in the list of groups
127 */
128 UserPerm *ceph_userperm_new(uid_t uid, gid_t gid, int ngids, gid_t *gidlist);
129
130 /**
131 * Destroy a UserPerm credential object.
132 *
133 * @param perm pointer to object to be destroyed
134 *
135 * Currently this just frees the object. Note that the gidlist array is not
136 * freed. The caller must do so if it's necessary.
137 */
138 void ceph_userperm_destroy(UserPerm *perm);
139
140 /**
141 * Get a pointer to the default UserPerm object for the mount.
142 *
143 * @param cmount the mount info handle
144 *
145 * Every cmount has a default set of credentials. This returns a pointer to
146 * that object.
147 *
148 * Unlike with ceph_userperm_new, this object should not be freed.
149 */
150 struct UserPerm *ceph_mount_perms(struct ceph_mount_info *cmount);
151
152 /**
153 * Set cmount's default permissions
154 *
155 * @param cmount the mount info handle
156 * @param perm permissions to set to default for mount
157 *
158 * Every cmount has a default set of credentials. This does a deep copy of
159 * the given permissions to the ones in the cmount. Must be done after
160 * ceph_init but before ceph_mount.
161 *
162 * Returns 0 on success, and -EISCONN if the cmount is already mounted.
163 */
164 int ceph_mount_perms_set(struct ceph_mount_info *cmount, UserPerm *perm);
165
166 /**
167 * @defgroup libcephfs_h_init Setup and Teardown
168 * These are the first and last functions that should be called
169 * when using libcephfs.
170 *
171 * @{
172 */
173
174 /**
175 * Get the version of libcephfs.
176 *
177 * The version number is major.minor.patch.
178 *
179 * @param major where to store the major version number
180 * @param minor where to store the minor version number
181 * @param patch where to store the extra version number
182 */
183 const char *ceph_version(int *major, int *minor, int *patch);
184
185 /**
186 * Create a mount handle for interacting with Ceph. All libcephfs
187 * functions operate on a mount info handle.
188 *
189 * @param cmount the mount info handle to initialize
190 * @param id the id of the client. This can be a unique id that identifies
191 * this client, and will get appended onto "client.". Callers can
192 * pass in NULL, and the id will be the process id of the client.
193 * @returns 0 on success, negative error code on failure
194 */
195 int ceph_create(struct ceph_mount_info **cmount, const char * const id);
196
197 /**
198 * Create a mount handle from a CephContext, which holds the configuration
199 * for the ceph cluster. A CephContext can be acquired from an existing ceph_mount_info
200 * handle, using the @ref ceph_get_mount_context call. Note that using the same CephContext
201 * for two different mount handles results in the same client entity id being used.
202 *
203 * @param cmount the mount info handle to initialize
204 * @param conf reuse this pre-existing CephContext config
205 * @returns 0 on success, negative error code on failure
206 */
207 #ifdef __cplusplus
208 int ceph_create_with_context(struct ceph_mount_info **cmount, CephContext *conf);
209 #else
210 int ceph_create_with_context(struct ceph_mount_info **cmount, struct CephContext *conf);
211 #endif
212
213 #ifndef VOIDPTR_RADOS_T
214 #define VOIDPTR_RADOS_T
215 typedef void *rados_t;
216 #endif // VOIDPTR_RADOS_T
217
218 /**
219 * Create a mount handle from a rados_t, for using libcephfs in the
220 * same process as librados.
221 *
222 * @param cmount the mount info handle to initialize
223 * @param cluster reference to already-initialized librados handle
224 * @returns 0 on success, negative error code on failure
225 */
226 int ceph_create_from_rados(struct ceph_mount_info **cmount, rados_t cluster);
227
228 /**
229 * Initialize the filesystem client (but do not mount the filesystem yet)
230 *
231 * @returns 0 on success, negative error code on failure
232 */
233 int ceph_init(struct ceph_mount_info *cmount);
234
235 /**
236 * Optionally set which filesystem to mount, before calling mount.
237 *
238 * An error will be returned if this libcephfs instance is already
239 * mounted. This function is an alternative to setting the global
240 * client_fs setting. Using this function enables multiple libcephfs
241 * instances in the same process to mount different filesystems.
242 *
243 * The filesystem name is *not* validated in this function. That happens
244 * during mount(), where an ENOENT error will result if a non-existent
245 * filesystem was specified here.
246 *
247 * @param cmount the mount info handle
248 * @returns 0 on success, negative error code on failure
249 */
250 int ceph_select_filesystem(struct ceph_mount_info *cmount, const char *fs_name);
251
252
253 /**
254 * Perform a mount using the path for the root of the mount.
255 *
256 * It is optional to call ceph_init before this. If ceph_init has
257 * not already been called, it will be called in the course of this operation.
258 *
259 * @param cmount the mount info handle
260 * @param root the path for the root of the mount. This can be an existing
261 * directory within the ceph cluster, but most likely it will
262 * be "/". Passing in NULL is equivalent to "/".
263 * @returns 0 on success, negative error code on failure
264 */
265 int ceph_mount(struct ceph_mount_info *cmount, const char *root);
266
267 /**
268 * Return cluster ID for a mounted ceph filesystem
269 *
270 * Every ceph filesystem has a filesystem ID associated with it. This
271 * function returns that value. If the ceph_mount_info does not refer to a
272 * mounted filesystem, this returns a negative error code.
273 */
274 int64_t ceph_get_fs_cid(struct ceph_mount_info *cmount);
275
276 /**
277 * Execute a management command remotely on an MDS.
278 *
279 * Must have called ceph_init or ceph_mount before calling this.
280 *
281 * @param mds_spec string representing rank, MDS name, GID or '*'
282 * @param cmd array of null-terminated strings
283 * @param cmdlen length of cmd array
284 * @param inbuf non-null-terminated input data to command
285 * @param inbuflen length in octets of inbuf
286 * @param outbuf populated with pointer to buffer (command output data)
287 * @param outbuflen length of allocated outbuf
288 * @param outs populated with pointer to buffer (command error strings)
289 * @param outslen length of allocated outs
290 *
291 * @return 0 on success, negative error code on failure
292 *
293 */
294 int ceph_mds_command(struct ceph_mount_info *cmount,
295 const char *mds_spec,
296 const char **cmd,
297 size_t cmdlen,
298 const char *inbuf, size_t inbuflen,
299 char **outbuf, size_t *outbuflen,
300 char **outs, size_t *outslen);
301
302 /**
303 * Free a buffer, such as those used for output arrays from ceph_mds_command
304 */
305 void ceph_buffer_free(char *buf);
306
307 /**
308 * Unmount a mount handle.
309 *
310 * @param cmount the mount handle
311 * @return 0 on success, negative error code on failure
312 */
313 int ceph_unmount(struct ceph_mount_info *cmount);
314
315 /**
316 * Abort mds connections
317 *
318 * @param cmount the mount handle
319 * @return 0 on success, negative error code on failure
320 */
321 int ceph_abort_conn(struct ceph_mount_info *cmount);
322
323 /**
324 * Destroy the mount handle.
325 *
326 * The handle should not be mounted. This should be called on completion of
327 * all libcephfs functions.
328 *
329 * @param cmount the mount handle
330 * @return 0 on success, negative error code on failure.
331 */
332 int ceph_release(struct ceph_mount_info *cmount);
333
334 /**
335 * Deprecated. Unmount and destroy the ceph mount handle. This should be
336 * called on completion of all libcephfs functions.
337 *
338 * Equivalent to ceph_unmount() + ceph_release() without error handling.
339 *
340 * @param cmount the mount handle to shutdown
341 */
342 void ceph_shutdown(struct ceph_mount_info *cmount);
343
344 /**
345 * Return associated client addresses
346 *
347 * @param cmount the mount handle
348 * @param addrs the output addresses
349 * @returns 0 on success, a negative error code on failure
350 * @note the returned addrs should be free by the caller
351 */
352 int ceph_getaddrs(struct ceph_mount_info *cmount, char** addrs);
353
354 /**
355 * Get a global id for current instance
356 *
357 * The handle should not be mounted. This should be called on completion of
358 * all libcephfs functions.
359 *
360 * @param cmount the mount handle
361 * @returns instance global id
362 */
363 uint64_t ceph_get_instance_id(struct ceph_mount_info *cmount);
364
365 /**
366 * Extract the CephContext from the mount point handle.
367 *
368 * @param cmount the ceph mount handle to get the context from.
369 * @returns the CephContext associated with the mount handle.
370 */
371 #ifdef __cplusplus
372 CephContext *ceph_get_mount_context(struct ceph_mount_info *cmount);
373 #else
374 struct CephContext *ceph_get_mount_context(struct ceph_mount_info *cmount);
375 #endif
376 /*
377 * Check mount status.
378 *
379 * Return non-zero value if mounted. Otherwise, zero.
380 */
381 int ceph_is_mounted(struct ceph_mount_info *cmount);
382
383 /** @} init */
384
385 /**
386 * @defgroup libcephfs_h_config Config
387 * Functions for manipulating the Ceph configuration at runtime.
388 *
389 * @{
390 */
391
392 /**
393 * Load the ceph configuration from the specified config file.
394 *
395 * @param cmount the mount handle to load the configuration into.
396 * @param path_list the configuration file path
397 * @returns 0 on success, negative error code on failure
398 */
399 int ceph_conf_read_file(struct ceph_mount_info *cmount, const char *path_list);
400
401 /**
402 * Parse the command line arguments and load the configuration parameters.
403 *
404 * @param cmount the mount handle to load the configuration parameters into.
405 * @param argc count of the arguments in argv
406 * @param argv the argument list
407 * @returns 0 on success, negative error code on failure
408 */
409 int ceph_conf_parse_argv(struct ceph_mount_info *cmount, int argc, const char **argv);
410
411 /**
412 * Configure the cluster handle based on an environment variable
413 *
414 * The contents of the environment variable are parsed as if they were
415 * Ceph command line options. If var is NULL, the CEPH_ARGS
416 * environment variable is used.
417 *
418 * @pre ceph_mount() has not been called on the handle
419 *
420 * @note BUG: this is not threadsafe - it uses a static buffer
421 *
422 * @param cmount handle to configure
423 * @param var name of the environment variable to read
424 * @returns 0 on success, negative error code on failure
425 */
426 int ceph_conf_parse_env(struct ceph_mount_info *cmount, const char *var);
427
428 /** Sets a configuration value from a string.
429 *
430 * @param cmount the mount handle to set the configuration value on
431 * @param option the configuration option to set
432 * @param value the value of the configuration option to set
433 *
434 * @returns 0 on success, negative error code otherwise.
435 */
436 int ceph_conf_set(struct ceph_mount_info *cmount, const char *option, const char *value);
437
438 /**
439 * Gets the configuration value as a string.
440 *
441 * @param cmount the mount handle to set the configuration value on
442 * @param option the config option to get
443 * @param buf the buffer to fill with the value
444 * @param len the length of the buffer.
445 * @returns the size of the buffer filled in with the value, or negative error code on failure
446 */
447 int ceph_conf_get(struct ceph_mount_info *cmount, const char *option, char *buf, size_t len);
448
449 /** @} config */
450
451 /**
452 * @defgroup libcephfs_h_fsops File System Operations.
453 * Functions for getting/setting file system wide information specific to a particular
454 * mount handle.
455 *
456 * @{
457 */
458
459 /**
460 * Perform a statfs on the ceph file system. This call fills in file system wide statistics
461 * into the passed in buffer.
462 *
463 * @param cmount the ceph mount handle to use for performing the statfs.
464 * @param path can be any path within the mounted filesystem
465 * @param stbuf the file system statistics filled in by this function.
466 * @return 0 on success, negative error code otherwise.
467 */
468 int ceph_statfs(struct ceph_mount_info *cmount, const char *path, struct statvfs *stbuf);
469
470 /**
471 * Synchronize all filesystem data to persistent media.
472 *
473 * @param cmount the ceph mount handle to use for performing the sync_fs.
474 * @returns 0 on success or negative error code on failure.
475 */
476 int ceph_sync_fs(struct ceph_mount_info *cmount);
477
478 /**
479 * Get the current working directory.
480 *
481 * @param cmount the ceph mount to get the current working directory for.
482 * @returns the path to the current working directory
483 */
484 const char* ceph_getcwd(struct ceph_mount_info *cmount);
485
486 /**
487 * Change the current working directory.
488 *
489 * @param cmount the ceph mount to change the current working directory for.
490 * @param path the path to the working directory to change into.
491 * @returns 0 on success, negative error code otherwise.
492 */
493 int ceph_chdir(struct ceph_mount_info *cmount, const char *path);
494
495 /** @} fsops */
496
497 /**
498 * @defgroup libcephfs_h_dir Directory Operations.
499 * Functions for manipulating and listing directories.
500 *
501 * @{
502 */
503
504 /**
505 * Open the given directory.
506 *
507 * @param cmount the ceph mount handle to use to open the directory
508 * @param name the path name of the directory to open. Must be either an absolute path
509 * or a path relative to the current working directory.
510 * @param dirpp the directory result pointer structure to fill in.
511 * @returns 0 on success or negative error code otherwise.
512 */
513 int ceph_opendir(struct ceph_mount_info *cmount, const char *name, struct ceph_dir_result **dirpp);
514
515 /**
516 * Close the open directory.
517 *
518 * @param cmount the ceph mount handle to use for closing the directory
519 * @param dirp the directory result pointer (set by ceph_opendir) to close
520 * @returns 0 on success or negative error code on failure.
521 */
522 int ceph_closedir(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp);
523
524 /**
525 * Get the next entry in an open directory.
526 *
527 * @param cmount the ceph mount handle to use for performing the readdir.
528 * @param dirp the directory stream pointer from an opendir holding the state of the
529 * next entry to return.
530 * @returns the next directory entry or NULL if at the end of the directory (or the directory
531 * is empty. This pointer should not be freed by the caller, and is only safe to
532 * access between return and the next call to ceph_readdir or ceph_closedir.
533 */
534 struct dirent * ceph_readdir(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp);
535
536 /**
537 * A safe version of ceph_readdir, where the directory entry struct is allocated by the caller.
538 *
539 * @param cmount the ceph mount handle to use for performing the readdir.
540 * @param dirp the directory stream pointer from an opendir holding the state of the
541 * next entry to return.
542 * @param de the directory entry pointer filled in with the next directory entry of the dirp state.
543 * @returns 1 if the next entry was filled in, 0 if the end of the directory stream was reached,
544 * and a negative error code on failure.
545 */
546 int ceph_readdir_r(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp, struct dirent *de);
547
548 /**
549 * A safe version of ceph_readdir that also returns the file statistics (readdir+stat).
550 *
551 * @param cmount the ceph mount handle to use for performing the readdir_plus_r.
552 * @param dirp the directory stream pointer from an opendir holding the state of the
553 * next entry to return.
554 * @param de the directory entry pointer filled in with the next directory entry of the dirp state.
555 * @param stx the stats of the file/directory of the entry returned
556 * @param want mask showing desired inode attrs for returned entry
557 * @param flags bitmask of flags to use when filling out attributes
558 * @param out optional returned Inode argument. If non-NULL, then a reference will be taken on
559 * the inode and the pointer set on success.
560 * @returns 1 if the next entry was filled in, 0 if the end of the directory stream was reached,
561 * and a negative error code on failure.
562 */
563 int ceph_readdirplus_r(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp, struct dirent *de,
564 struct ceph_statx *stx, unsigned want, unsigned flags, struct Inode **out);
565
566 /**
567 * Gets multiple directory entries.
568 *
569 * @param cmount the ceph mount handle to use for performing the getdents.
570 * @param dirp the directory stream pointer from an opendir holding the state of the
571 * next entry/entries to return.
572 * @param name an array of struct dirent that gets filled in with the to fill returned directory entries into.
573 * @param buflen the length of the buffer, which should be the number of dirent structs * sizeof(struct dirent).
574 * @returns the length of the buffer that was filled in, will always be multiples of sizeof(struct dirent), or a
575 * negative error code. If the buffer is not large enough for a single entry, -ERANGE is returned.
576 */
577 int ceph_getdents(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp, char *name, int buflen);
578
579 /**
580 * Gets multiple directory names.
581 *
582 * @param cmount the ceph mount handle to use for performing the getdents.
583 * @param dirp the directory stream pointer from an opendir holding the state of the
584 * next entry/entries to return.
585 * @param name a buffer to fill in with directory entry names.
586 * @param buflen the length of the buffer that can be filled in.
587 * @returns the length of the buffer filled in with entry names, or a negative error code on failure.
588 * If the buffer isn't large enough for a single entry, -ERANGE is returned.
589 */
590 int ceph_getdnames(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp, char *name, int buflen);
591
592 /**
593 * Rewind the directory stream to the beginning of the directory.
594 *
595 * @param cmount the ceph mount handle to use for performing the rewinddir.
596 * @param dirp the directory stream pointer to rewind.
597 */
598 void ceph_rewinddir(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp);
599
600 /**
601 * Get the current position of a directory stream.
602 *
603 * @param cmount the ceph mount handle to use for performing the telldir.
604 * @param dirp the directory stream pointer to get the current position of.
605 * @returns the position of the directory stream. Note that the offsets returned
606 * by ceph_telldir do not have a particular order (cannot be compared with
607 * inequality).
608 */
609 int64_t ceph_telldir(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp);
610
611 /**
612 * Move the directory stream to a position specified by the given offset.
613 *
614 * @param cmount the ceph mount handle to use for performing the seekdir.
615 * @param dirp the directory stream pointer to move.
616 * @param offset the position to move the directory stream to. This offset should be
617 * a value returned by telldir. Note that this value does not refer to the nth
618 * entry in a directory, and can not be manipulated with plus or minus.
619 */
620 void ceph_seekdir(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp, int64_t offset);
621
622 /**
623 * Create a directory.
624 *
625 * @param cmount the ceph mount handle to use for making the directory.
626 * @param path the path of the directory to create. This must be either an
627 * absolute path or a relative path off of the current working directory.
628 * @param mode the permissions the directory should have once created.
629 * @returns 0 on success or a negative return code on error.
630 */
631 int ceph_mkdir(struct ceph_mount_info *cmount, const char *path, mode_t mode);
632
633 /**
634 * Create multiple directories at once.
635 *
636 * @param cmount the ceph mount handle to use for making the directories.
637 * @param path the full path of directories and sub-directories that should
638 * be created.
639 * @param mode the permissions the directory should have once created.
640 * @returns 0 on success or a negative return code on error.
641 */
642 int ceph_mkdirs(struct ceph_mount_info *cmount, const char *path, mode_t mode);
643
644 /**
645 * Remove a directory.
646 *
647 * @param cmount the ceph mount handle to use for removing directories.
648 * @param path the path of the directory to remove.
649 * @returns 0 on success or a negative return code on error.
650 */
651 int ceph_rmdir(struct ceph_mount_info *cmount, const char *path);
652
653 /** @} dir */
654
655 /**
656 * @defgroup libcephfs_h_links Links and Link Handling.
657 * Functions for creating and manipulating hard links and symbolic inks.
658 *
659 * @{
660 */
661
662 /**
663 * Create a link.
664 *
665 * @param cmount the ceph mount handle to use for creating the link.
666 * @param existing the path to the existing file/directory to link to.
667 * @param newname the path to the new file/directory to link from.
668 * @returns 0 on success or a negative return code on error.
669 */
670 int ceph_link(struct ceph_mount_info *cmount, const char *existing, const char *newname);
671
672 /**
673 * Read a symbolic link.
674 *
675 * @param cmount the ceph mount handle to use for creating the link.
676 * @param path the path to the symlink to read
677 * @param buf the buffer to hold the path of the file that the symlink points to.
678 * @param size the length of the buffer
679 * @returns number of bytes copied on success or negative error code on failure
680 */
681 int ceph_readlink(struct ceph_mount_info *cmount, const char *path, char *buf, int64_t size);
682
683 /**
684 * Creates a symbolic link.
685 *
686 * @param cmount the ceph mount handle to use for creating the symbolic link.
687 * @param existing the path to the existing file/directory to link to.
688 * @param newname the path to the new file/directory to link from.
689 * @returns 0 on success or a negative return code on failure.
690 */
691 int ceph_symlink(struct ceph_mount_info *cmount, const char *existing, const char *newname);
692
693 /** @} links */
694
695 /**
696 * @defgroup libcephfs_h_files File manipulation and handling.
697 * Functions for creating and manipulating files.
698 *
699 * @{
700 */
701
702 /**
703 * Removes a file, link, or symbolic link. If the file/link has multiple links to it, the
704 * file will not disappear from the namespace until all references to it are removed.
705 *
706 * @param cmount the ceph mount handle to use for performing the unlink.
707 * @param path the path of the file or link to unlink.
708 * @returns 0 on success or negative error code on failure.
709 */
710 int ceph_unlink(struct ceph_mount_info *cmount, const char *path);
711
712 /**
713 * Rename a file or directory.
714 *
715 * @param cmount the ceph mount handle to use for performing the rename.
716 * @param from the path to the existing file or directory.
717 * @param to the new name of the file or directory
718 * @returns 0 on success or negative error code on failure.
719 */
720 int ceph_rename(struct ceph_mount_info *cmount, const char *from, const char *to);
721
722 /**
723 * Get an open file's extended statistics and attributes.
724 *
725 * @param cmount the ceph mount handle to use for performing the stat.
726 * @param fd the file descriptor of the file to get statistics of.
727 * @param stx the ceph_statx struct that will be filled in with the file's statistics.
728 * @param want bitfield of CEPH_STATX_* flags showing designed attributes
729 * @param flags bitfield that can be used to set AT_* modifier flags (only AT_NO_ATTR_SYNC and AT_SYMLINK_NOFOLLOW)
730 * @returns 0 on success or negative error code on failure.
731 */
732 int ceph_fstatx(struct ceph_mount_info *cmount, int fd, struct ceph_statx *stx,
733 unsigned int want, unsigned int flags);
734
735 /**
736 * Get a file's extended statistics and attributes.
737 *
738 * @param cmount the ceph mount handle to use for performing the stat.
739 * @param path the file or directory to get the statistics of.
740 * @param stx the ceph_statx struct that will be filled in with the file's statistics.
741 * @param want bitfield of CEPH_STATX_* flags showing designed attributes
742 * @param flags bitfield that can be used to set AT_* modifier flags (only AT_NO_ATTR_SYNC and AT_SYMLINK_NOFOLLOW)
743 * @returns 0 on success or negative error code on failure.
744 */
745 int ceph_statx(struct ceph_mount_info *cmount, const char *path, struct ceph_statx *stx,
746 unsigned int want, unsigned int flags);
747
748 /**
749 * Get a file's statistics and attributes.
750 *
751 * @param cmount the ceph mount handle to use for performing the stat.
752 * @param path the file or directory to get the statistics of.
753 * @param stbuf the stat struct that will be filled in with the file's statistics.
754 * @returns 0 on success or negative error code on failure.
755 */
756 int ceph_stat(struct ceph_mount_info *cmount, const char *path, struct stat *stbuf);
757
758 /**
759 * Get a file's statistics and attributes, without following symlinks.
760 *
761 * @param cmount the ceph mount handle to use for performing the stat.
762 * @param path the file or directory to get the statistics of.
763 * @param stbuf the stat struct that will be filled in with the file's statistics.
764 * @returns 0 on success or negative error code on failure.
765 */
766 int ceph_lstat(struct ceph_mount_info *cmount, const char *path, struct stat *stbuf);
767
768 /**
769 * Get the open file's statistics.
770 *
771 * @param cmount the ceph mount handle to use for performing the fstat.
772 * @param fd the file descriptor of the file to get statistics of.
773 * @param stbuf the stat struct of the file's statistics, filled in by the
774 * function.
775 * @returns 0 on success or a negative error code on failure
776 */
777 int ceph_fstat(struct ceph_mount_info *cmount, int fd, struct stat *stbuf);
778
779 /**
780 * Set a file's attributes.
781 *
782 * @param cmount the ceph mount handle to use for performing the setattr.
783 * @param relpath the path to the file/directory to set the attributes of.
784 * @param stx the statx struct that must include attribute values to set on the file.
785 * @param mask a mask of all the CEPH_SETATTR_* values that have been set in the statx struct.
786 * @param flags mask of AT_* flags (only AT_ATTR_NOFOLLOW is respected for now)
787 * @returns 0 on success or negative error code on failure.
788 */
789 int ceph_setattrx(struct ceph_mount_info *cmount, const char *relpath, struct ceph_statx *stx, int mask, int flags);
790
791 /**
792 * Set a file's attributes (extended version).
793 *
794 * @param cmount the ceph mount handle to use for performing the setattr.
795 * @param fd the fd of the open file/directory to set the attributes of.
796 * @param stx the statx struct that must include attribute values to set on the file.
797 * @param mask a mask of all the stat values that have been set on the stat struct.
798 * @returns 0 on success or negative error code on failure.
799 */
800 int ceph_fsetattrx(struct ceph_mount_info *cmount, int fd, struct ceph_statx *stx, int mask);
801
802 /**
803 * Change the mode bits (permissions) of a file/directory.
804 *
805 * @param cmount the ceph mount handle to use for performing the chmod.
806 * @param path the path to the file/directory to change the mode bits on.
807 * @param mode the new permissions to set.
808 * @returns 0 on success or a negative error code on failure.
809 */
810 int ceph_chmod(struct ceph_mount_info *cmount, const char *path, mode_t mode);
811
812 /**
813 * Change the mode bits (permissions) of an open file.
814 *
815 * @param cmount the ceph mount handle to use for performing the chmod.
816 * @param fd the open file descriptor to change the mode bits on.
817 * @param mode the new permissions to set.
818 * @returns 0 on success or a negative error code on failure.
819 */
820 int ceph_fchmod(struct ceph_mount_info *cmount, int fd, mode_t mode);
821
822 /**
823 * Change the ownership of a file/directory.
824 *
825 * @param cmount the ceph mount handle to use for performing the chown.
826 * @param path the path of the file/directory to change the ownership of.
827 * @param uid the user id to set on the file/directory.
828 * @param gid the group id to set on the file/directory.
829 * @returns 0 on success or negative error code on failure.
830 */
831 int ceph_chown(struct ceph_mount_info *cmount, const char *path, int uid, int gid);
832
833 /**
834 * Change the ownership of a file from an open file descriptor.
835 *
836 * @param cmount the ceph mount handle to use for performing the chown.
837 * @param fd the fd of the open file/directory to change the ownership of.
838 * @param uid the user id to set on the file/directory.
839 * @param gid the group id to set on the file/directory.
840 * @returns 0 on success or negative error code on failure.
841 */
842 int ceph_fchown(struct ceph_mount_info *cmount, int fd, int uid, int gid);
843
844 /**
845 * Change the ownership of a file/directory, don't follow symlinks.
846 *
847 * @param cmount the ceph mount handle to use for performing the chown.
848 * @param path the path of the file/directory to change the ownership of.
849 * @param uid the user id to set on the file/directory.
850 * @param gid the group id to set on the file/directory.
851 * @returns 0 on success or negative error code on failure.
852 */
853 int ceph_lchown(struct ceph_mount_info *cmount, const char *path, int uid, int gid);
854
855 /**
856 * Change file/directory last access and modification times.
857 *
858 * @param cmount the ceph mount handle to use for performing the utime.
859 * @param path the path to the file/directory to set the time values of.
860 * @param buf holding the access and modification times to set on the file.
861 * @returns 0 on success or negative error code on failure.
862 */
863 int ceph_utime(struct ceph_mount_info *cmount, const char *path, struct utimbuf *buf);
864
865 /**
866 * Change file/directory last access and modification times.
867 *
868 * @param cmount the ceph mount handle to use for performing the utime.
869 * @param fd the fd of the open file/directory to set the time values of.
870 * @param buf holding the access and modification times to set on the file.
871 * @returns 0 on success or negative error code on failure.
872 */
873 int ceph_futime(struct ceph_mount_info *cmount, int fd, struct utimbuf *buf);
874
875 /**
876 * Change file/directory last access and modification times.
877 *
878 * @param cmount the ceph mount handle to use for performing the utime.
879 * @param path the path to the file/directory to set the time values of.
880 * @param times holding the access and modification times to set on the file.
881 * @returns 0 on success or negative error code on failure.
882 */
883 int ceph_utimes(struct ceph_mount_info *cmount, const char *path, struct timeval times[2]);
884
885 /**
886 * Change file/directory last access and modification times, don't follow symlinks.
887 *
888 * @param cmount the ceph mount handle to use for performing the utime.
889 * @param path the path to the file/directory to set the time values of.
890 * @param times holding the access and modification times to set on the file.
891 * @returns 0 on success or negative error code on failure.
892 */
893 int ceph_lutimes(struct ceph_mount_info *cmount, const char *path, struct timeval times[2]);
894
895 /**
896 * Change file/directory last access and modification times.
897 *
898 * @param cmount the ceph mount handle to use for performing the utime.
899 * @param fd the fd of the open file/directory to set the time values of.
900 * @param times holding the access and modification times to set on the file.
901 * @returns 0 on success or negative error code on failure.
902 */
903 int ceph_futimes(struct ceph_mount_info *cmount, int fd, struct timeval times[2]);
904
905 /**
906 * Change file/directory last access and modification times.
907 *
908 * @param cmount the ceph mount handle to use for performing the utime.
909 * @param fd the fd of the open file/directory to set the time values of.
910 * @param times holding the access and modification times to set on the file.
911 * @returns 0 on success or negative error code on failure.
912 */
913 int ceph_futimens(struct ceph_mount_info *cmount, int fd, struct timespec times[2]);
914
915 /**
916 * Apply or remove an advisory lock.
917 *
918 * @param cmount the ceph mount handle to use for performing the lock.
919 * @param fd the open file descriptor to change advisory lock.
920 * @param operation the advisory lock operation to be performed on the file
921 * descriptor among LOCK_SH (shared lock), LOCK_EX (exclusive lock),
922 * or LOCK_UN (remove lock). The LOCK_NB value can be ORed to perform a
923 * non-blocking operation.
924 * @param owner the user-supplied owner identifier (an arbitrary integer)
925 * @returns 0 on success or negative error code on failure.
926 */
927 int ceph_flock(struct ceph_mount_info *cmount, int fd, int operation,
928 uint64_t owner);
929
930 /**
931 * Truncate the file to the given size. If this operation causes the
932 * file to expand, the empty bytes will be filled in with zeros.
933 *
934 * @param cmount the ceph mount handle to use for performing the truncate.
935 * @param path the path to the file to truncate.
936 * @param size the new size of the file.
937 * @returns 0 on success or a negative error code on failure.
938 */
939 int ceph_truncate(struct ceph_mount_info *cmount, const char *path, int64_t size);
940
941 /**
942 * Make a block or character special file.
943 *
944 * @param cmount the ceph mount handle to use for performing the mknod.
945 * @param path the path to the special file.
946 * @param mode the permissions to use and the type of special file. The type can be
947 * one of S_IFREG, S_IFCHR, S_IFBLK, S_IFIFO.
948 * @param rdev If the file type is S_IFCHR or S_IFBLK then this parameter specifies the
949 * major and minor numbers of the newly created device special file. Otherwise,
950 * it is ignored.
951 * @returns 0 on success or negative error code on failure.
952 */
953 int ceph_mknod(struct ceph_mount_info *cmount, const char *path, mode_t mode, dev_t rdev);
954 /**
955 * Create and/or open a file.
956 *
957 * @param cmount the ceph mount handle to use for performing the open.
958 * @param path the path of the file to open. If the flags parameter includes O_CREAT,
959 * the file will first be created before opening.
960 * @param flags a set of option masks that control how the file is created/opened.
961 * @param mode the permissions to place on the file if the file does not exist and O_CREAT
962 * is specified in the flags.
963 * @returns a non-negative file descriptor number on success or a negative error code on failure.
964 */
965 int ceph_open(struct ceph_mount_info *cmount, const char *path, int flags, mode_t mode);
966
967 /**
968 * Create and/or open a file with a specific file layout.
969 *
970 * @param cmount the ceph mount handle to use for performing the open.
971 * @param path the path of the file to open. If the flags parameter includes O_CREAT,
972 * the file will first be created before opening.
973 * @param flags a set of option masks that control how the file is created/opened.
974 * @param mode the permissions to place on the file if the file does not exist and O_CREAT
975 * is specified in the flags.
976 * @param stripe_unit the stripe unit size (option, 0 for default)
977 * @param stripe_count the stripe count (optional, 0 for default)
978 * @param object_size the object size (optional, 0 for default)
979 * @param data_pool name of target data pool name (optional, NULL or empty string for default)
980 * @returns a non-negative file descriptor number on success or a negative error code on failure.
981 */
982 int ceph_open_layout(struct ceph_mount_info *cmount, const char *path, int flags,
983 mode_t mode, int stripe_unit, int stripe_count, int object_size,
984 const char *data_pool);
985
986 /**
987 * Close the open file.
988 *
989 * @param cmount the ceph mount handle to use for performing the close.
990 * @param fd the file descriptor referring to the open file.
991 * @returns 0 on success or a negative error code on failure.
992 */
993 int ceph_close(struct ceph_mount_info *cmount, int fd);
994
995 /**
996 * Reposition the open file stream based on the given offset.
997 *
998 * @param cmount the ceph mount handle to use for performing the lseek.
999 * @param fd the open file descriptor referring to the open file and holding the
1000 * current position of the stream.
1001 * @param offset the offset to set the stream to
1002 * @param whence the flag to indicate what type of seeking to perform:
1003 * SEEK_SET: the offset is set to the given offset in the file.
1004 * SEEK_CUR: the offset is set to the current location plus @e offset bytes.
1005 * SEEK_END: the offset is set to the end of the file plus @e offset bytes.
1006 * @returns 0 on success or a negative error code on failure.
1007 */
1008 int64_t ceph_lseek(struct ceph_mount_info *cmount, int fd, int64_t offset, int whence);
1009 /**
1010 * Read data from the file.
1011 *
1012 * @param cmount the ceph mount handle to use for performing the read.
1013 * @param fd the file descriptor of the open file to read from.
1014 * @param buf the buffer to read data into
1015 * @param size the initial size of the buffer
1016 * @param offset the offset in the file to read from. If this value is negative, the
1017 * function reads from the current offset of the file descriptor.
1018 * @returns the number of bytes read into buf, or a negative error code on failure.
1019 */
1020 int ceph_read(struct ceph_mount_info *cmount, int fd, char *buf, int64_t size, int64_t offset);
1021
1022 /**
1023 * Read data from the file.
1024 * @param cmount the ceph mount handle to use for performing the read.
1025 * @param fd the file descriptor of the open file to read from.
1026 * @param iov the iov structure to read data into
1027 * @param iovcnt the number of items that iov includes
1028 * @param offset the offset in the file to read from. If this value is negative, the
1029 * function reads from the current offset of the file descriptor.
1030 * @returns the number of bytes read into buf, or a negative error code on failure.
1031 */
1032 int ceph_preadv(struct ceph_mount_info *cmount, int fd, const struct iovec *iov, int iovcnt,
1033 int64_t offset);
1034
1035 /**
1036 * Write data to a file.
1037 *
1038 * @param cmount the ceph mount handle to use for performing the write.
1039 * @param fd the file descriptor of the open file to write to
1040 * @param buf the bytes to write to the file
1041 * @param size the size of the buf array
1042 * @param offset the offset of the file write into. If this value is negative, the
1043 * function writes to the current offset of the file descriptor.
1044 * @returns the number of bytes written, or a negative error code
1045 */
1046 int ceph_write(struct ceph_mount_info *cmount, int fd, const char *buf, int64_t size,
1047 int64_t offset);
1048
1049 /**
1050 * Write data to a file.
1051 *
1052 * @param cmount the ceph mount handle to use for performing the write.
1053 * @param fd the file descriptor of the open file to write to
1054 * @param iov the iov structure to read data into
1055 * @param iovcnt the number of items that iov includes
1056 * @param offset the offset of the file write into. If this value is negative, the
1057 * function writes to the current offset of the file descriptor.
1058 * @returns the number of bytes written, or a negative error code
1059 */
1060 int ceph_pwritev(struct ceph_mount_info *cmount, int fd, const struct iovec *iov, int iovcnt,
1061 int64_t offset);
1062
1063 /**
1064 * Truncate a file to the given size.
1065 *
1066 * @param cmount the ceph mount handle to use for performing the ftruncate.
1067 * @param fd the file descriptor of the file to truncate
1068 * @param size the new size of the file
1069 * @returns 0 on success or a negative error code on failure.
1070 */
1071 int ceph_ftruncate(struct ceph_mount_info *cmount, int fd, int64_t size);
1072
1073 /**
1074 * Synchronize an open file to persistent media.
1075 *
1076 * @param cmount the ceph mount handle to use for performing the fsync.
1077 * @param fd the file descriptor of the file to sync.
1078 * @param syncdataonly a boolean whether to synchronize metadata and data (0)
1079 * or just data (1).
1080 * @return 0 on success or a negative error code on failure.
1081 */
1082 int ceph_fsync(struct ceph_mount_info *cmount, int fd, int syncdataonly);
1083
1084 /**
1085 * Preallocate or release disk space for the file for the byte range.
1086 *
1087 * @param cmount the ceph mount handle to use for performing the fallocate.
1088 * @param fd the file descriptor of the file to fallocate.
1089 * @param mode the flags determines the operation to be performed on the given range.
1090 * default operation (0) allocate and initialize to zero the file in the byte range,
1091 * and the file size will be changed if offset + length is greater than
1092 * the file size. if the FALLOC_FL_KEEP_SIZE flag is specified in the mode,
1093 * the file size will not be changed. if the FALLOC_FL_PUNCH_HOLE flag is
1094 * specified in the mode, the operation is deallocate space and zero the byte range.
1095 * @param offset the byte range starting.
1096 * @param length the length of the range.
1097 * @return 0 on success or a negative error code on failure.
1098 */
1099 int ceph_fallocate(struct ceph_mount_info *cmount, int fd, int mode,
1100 int64_t offset, int64_t length);
1101
1102 /**
1103 * Enable/disable lazyio for the file.
1104 *
1105 * @param cmount the ceph mount handle to use for performing the fsync.
1106 * @param fd the file descriptor of the file to sync.
1107 * @param enable a boolean to enable lazyio or disable lazyio.
1108 * @returns 0 on success or a negative error code on failure.
1109 */
1110 int ceph_lazyio(struct ceph_mount_info *cmount, int fd, int enable);
1111
1112
1113 /**
1114 * Flushes the write buffer for the file thereby propogating the buffered write to the file.
1115 *
1116 * @param cmount the ceph mount handle to use for performing the fsync.
1117 * @param fd the file descriptor of the file to sync.
1118 * @param offset a boolean to enable lazyio or disable lazyio.
1119 * @returns 0 on success or a negative error code on failure.
1120 */
1121 int ceph_lazyio_propagate(struct ceph_mount_info *cmount, int fd, int64_t offset, size_t count);
1122
1123
1124 /**
1125 * Flushes the write buffer for the file and invalidate the read cache. This allows a subsequent read operation to read and cache data directly from the file and hence everyone's propagated writes would be visible.
1126 *
1127 * @param cmount the ceph mount handle to use for performing the fsync.
1128 * @param fd the file descriptor of the file to sync.
1129 * @param offset a boolean to enable lazyio or disable lazyio.
1130 * @returns 0 on success or a negative error code on failure.
1131 */
1132 int ceph_lazyio_synchronize(struct ceph_mount_info *cmount, int fd, int64_t offset, size_t count);
1133
1134 /** @} file */
1135
1136 /**
1137 * @defgroup libcephfs_h_xattr Extended Attribute manipulation and handling.
1138 * Functions for creating and manipulating extended attributes on files.
1139 *
1140 * @{
1141 */
1142
1143 /**
1144 * Get an extended attribute.
1145 *
1146 * @param cmount the ceph mount handle to use for performing the getxattr.
1147 * @param path the path to the file
1148 * @param name the name of the extended attribute to get
1149 * @param value a pre-allocated buffer to hold the xattr's value
1150 * @param size the size of the pre-allocated buffer
1151 * @returns the size of the value or a negative error code on failure.
1152 */
1153 int ceph_getxattr(struct ceph_mount_info *cmount, const char *path, const char *name,
1154 void *value, size_t size);
1155
1156 /**
1157 * Get an extended attribute.
1158 *
1159 * @param cmount the ceph mount handle to use for performing the getxattr.
1160 * @param fd the open file descriptor referring to the file to get extended attribute from.
1161 * @param name the name of the extended attribute to get
1162 * @param value a pre-allocated buffer to hold the xattr's value
1163 * @param size the size of the pre-allocated buffer
1164 * @returns the size of the value or a negative error code on failure.
1165 */
1166 int ceph_fgetxattr(struct ceph_mount_info *cmount, int fd, const char *name,
1167 void *value, size_t size);
1168
1169 /**
1170 * Get an extended attribute without following symbolic links. This function is
1171 * identical to ceph_getxattr, but if the path refers to a symbolic link,
1172 * we get the extended attributes of the symlink rather than the attributes
1173 * of the link itself.
1174 *
1175 * @param cmount the ceph mount handle to use for performing the lgetxattr.
1176 * @param path the path to the file
1177 * @param name the name of the extended attribute to get
1178 * @param value a pre-allocated buffer to hold the xattr's value
1179 * @param size the size of the pre-allocated buffer
1180 * @returns the size of the value or a negative error code on failure.
1181 */
1182 int ceph_lgetxattr(struct ceph_mount_info *cmount, const char *path, const char *name,
1183 void *value, size_t size);
1184
1185 /**
1186 * List the extended attribute keys on a file.
1187 *
1188 * @param cmount the ceph mount handle to use for performing the listxattr.
1189 * @param path the path to the file.
1190 * @param list a buffer to be filled in with the list of extended attributes keys.
1191 * @param size the size of the list buffer.
1192 * @returns the size of the resulting list filled in.
1193 */
1194 int ceph_listxattr(struct ceph_mount_info *cmount, const char *path, char *list, size_t size);
1195
1196 /**
1197 * List the extended attribute keys on a file.
1198 *
1199 * @param cmount the ceph mount handle to use for performing the listxattr.
1200 * @param fd the open file descriptor referring to the file to list extended attributes on.
1201 * @param list a buffer to be filled in with the list of extended attributes keys.
1202 * @param size the size of the list buffer.
1203 * @returns the size of the resulting list filled in.
1204 */
1205 int ceph_flistxattr(struct ceph_mount_info *cmount, int fd, char *list, size_t size);
1206
1207 /**
1208 * Get the list of extended attribute keys on a file, but do not follow symbolic links.
1209 *
1210 * @param cmount the ceph mount handle to use for performing the llistxattr.
1211 * @param path the path to the file.
1212 * @param list a buffer to be filled in with the list of extended attributes keys.
1213 * @param size the size of the list buffer.
1214 * @returns the size of the resulting list filled in.
1215 */
1216 int ceph_llistxattr(struct ceph_mount_info *cmount, const char *path, char *list, size_t size);
1217
1218 /**
1219 * Remove an extended attribute from a file.
1220 *
1221 * @param cmount the ceph mount handle to use for performing the removexattr.
1222 * @param path the path to the file.
1223 * @param name the name of the extended attribute to remove.
1224 * @returns 0 on success or a negative error code on failure.
1225 */
1226 int ceph_removexattr(struct ceph_mount_info *cmount, const char *path, const char *name);
1227
1228 /**
1229 * Remove an extended attribute from a file.
1230 *
1231 * @param cmount the ceph mount handle to use for performing the removexattr.
1232 * @param fd the open file descriptor referring to the file to remove extended attribute from.
1233 * @param name the name of the extended attribute to remove.
1234 * @returns 0 on success or a negative error code on failure.
1235 */
1236 int ceph_fremovexattr(struct ceph_mount_info *cmount, int fd, const char *name);
1237
1238 /**
1239 * Remove the extended attribute from a file, do not follow symbolic links.
1240 *
1241 * @param cmount the ceph mount handle to use for performing the lremovexattr.
1242 * @param path the path to the file.
1243 * @param name the name of the extended attribute to remove.
1244 * @returns 0 on success or a negative error code on failure.
1245 */
1246 int ceph_lremovexattr(struct ceph_mount_info *cmount, const char *path, const char *name);
1247
1248 /**
1249 * Set an extended attribute on a file.
1250 *
1251 * @param cmount the ceph mount handle to use for performing the setxattr.
1252 * @param path the path to the file.
1253 * @param name the name of the extended attribute to set.
1254 * @param value the bytes of the extended attribute value
1255 * @param size the size of the extended attribute value
1256 * @param flags the flags can be:
1257 * CEPH_XATTR_CREATE: create the extended attribute. Must not exist.
1258 * CEPH_XATTR_REPLACE: replace the extended attribute, Must already exist.
1259 * @returns 0 on success or a negative error code on failure.
1260 */
1261 int ceph_setxattr(struct ceph_mount_info *cmount, const char *path, const char *name,
1262 const void *value, size_t size, int flags);
1263
1264 /**
1265 * Set an extended attribute on a file.
1266 *
1267 * @param cmount the ceph mount handle to use for performing the setxattr.
1268 * @param fd the open file descriptor referring to the file to set extended attribute on.
1269 * @param name the name of the extended attribute to set.
1270 * @param value the bytes of the extended attribute value
1271 * @param size the size of the extended attribute value
1272 * @param flags the flags can be:
1273 * CEPH_XATTR_CREATE: create the extended attribute. Must not exist.
1274 * CEPH_XATTR_REPLACE: replace the extended attribute, Must already exist.
1275 * @returns 0 on success or a negative error code on failure.
1276 */
1277 int ceph_fsetxattr(struct ceph_mount_info *cmount, int fd, const char *name,
1278 const void *value, size_t size, int flags);
1279
1280 /**
1281 * Set an extended attribute on a file, do not follow symbolic links.
1282 *
1283 * @param cmount the ceph mount handle to use for performing the lsetxattr.
1284 * @param path the path to the file.
1285 * @param name the name of the extended attribute to set.
1286 * @param value the bytes of the extended attribute value
1287 * @param size the size of the extended attribute value
1288 * @param flags the flags can be:
1289 * CEPH_XATTR_CREATE: create the extended attribute. Must not exist.
1290 * CEPH_XATTR_REPLACE: replace the extended attribute, Must already exist.
1291 * @returns 0 on success or a negative error code on failure.
1292 */
1293 int ceph_lsetxattr(struct ceph_mount_info *cmount, const char *path, const char *name,
1294 const void *value, size_t size, int flags);
1295
1296 /** @} xattr */
1297
1298 /**
1299 * @defgroup libcephfs_h_filelayout Control File Layout.
1300 * Functions for setting and getting the file layout of existing files.
1301 *
1302 * @{
1303 */
1304
1305 /**
1306 * Get the file striping unit from an open file descriptor.
1307 *
1308 * @param cmount the ceph mount handle to use.
1309 * @param fh the open file descriptor referring to the file to get the striping unit of.
1310 * @returns the striping unit of the file or a negative error code on failure.
1311 */
1312 int ceph_get_file_stripe_unit(struct ceph_mount_info *cmount, int fh);
1313
1314 /**
1315 * Get the file striping unit.
1316 *
1317 * @param cmount the ceph mount handle to use.
1318 * @param path the path of the file/directory get the striping unit of.
1319 * @returns the striping unit of the file or a negative error code on failure.
1320 */
1321 int ceph_get_path_stripe_unit(struct ceph_mount_info *cmount, const char *path);
1322
1323 /**
1324 * Get the file striping count from an open file descriptor.
1325 *
1326 * @param cmount the ceph mount handle to use.
1327 * @param fh the open file descriptor referring to the file to get the striping count of.
1328 * @returns the striping count of the file or a negative error code on failure.
1329 */
1330 int ceph_get_file_stripe_count(struct ceph_mount_info *cmount, int fh);
1331
1332 /**
1333 * Get the file striping count.
1334 *
1335 * @param cmount the ceph mount handle to use.
1336 * @param path the path of the file/directory get the striping count of.
1337 * @returns the striping count of the file or a negative error code on failure.
1338 */
1339 int ceph_get_path_stripe_count(struct ceph_mount_info *cmount, const char *path);
1340
1341 /**
1342 * Get the file object size from an open file descriptor.
1343 *
1344 * @param cmount the ceph mount handle to use.
1345 * @param fh the open file descriptor referring to the file to get the object size of.
1346 * @returns the object size of the file or a negative error code on failure.
1347 */
1348 int ceph_get_file_object_size(struct ceph_mount_info *cmount, int fh);
1349
1350 /**
1351 * Get the file object size.
1352 *
1353 * @param cmount the ceph mount handle to use.
1354 * @param path the path of the file/directory get the object size of.
1355 * @returns the object size of the file or a negative error code on failure.
1356 */
1357 int ceph_get_path_object_size(struct ceph_mount_info *cmount, const char *path);
1358
1359 /**
1360 * Get the file pool information from an open file descriptor.
1361 *
1362 * @param cmount the ceph mount handle to use.
1363 * @param fh the open file descriptor referring to the file to get the pool information of.
1364 * @returns the ceph pool id that the file is in
1365 */
1366 int ceph_get_file_pool(struct ceph_mount_info *cmount, int fh);
1367
1368 /**
1369 * Get the file pool information.
1370 *
1371 * @param cmount the ceph mount handle to use.
1372 * @param path the path of the file/directory get the pool information of.
1373 * @returns the ceph pool id that the file is in
1374 */
1375 int ceph_get_path_pool(struct ceph_mount_info *cmount, const char *path);
1376
1377 /**
1378 * Get the name of the pool a opened file is stored in,
1379 *
1380 * Write the name of the file's pool to the buffer. If buflen is 0, return
1381 * a suggested length for the buffer.
1382 *
1383 * @param cmount the ceph mount handle to use.
1384 * @param fh the open file descriptor referring to the file
1385 * @param buf buffer to store the name in
1386 * @param buflen size of the buffer
1387 * @returns length in bytes of the pool name, or -ERANGE if the buffer is not large enough.
1388 */
1389 int ceph_get_file_pool_name(struct ceph_mount_info *cmount, int fh, char *buf, size_t buflen);
1390
1391 /**
1392 * get the name of a pool by id
1393 *
1394 * Given a pool's numeric identifier, get the pool's alphanumeric name.
1395 *
1396 * @param cmount the ceph mount handle to use
1397 * @param pool the numeric pool id
1398 * @param buf buffer to sore the name in
1399 * @param buflen size of the buffer
1400 * @returns length in bytes of the pool name, or -ERANGE if the buffer is not large enough
1401 */
1402 int ceph_get_pool_name(struct ceph_mount_info *cmount, int pool, char *buf, size_t buflen);
1403
1404 /**
1405 * Get the name of the pool a file is stored in
1406 *
1407 * Write the name of the file's pool to the buffer. If buflen is 0, return
1408 * a suggested length for the buffer.
1409 *
1410 * @param cmount the ceph mount handle to use.
1411 * @param path the path of the file/directory
1412 * @param buf buffer to store the name in
1413 * @param buflen size of the buffer
1414 * @returns length in bytes of the pool name, or -ERANGE if the buffer is not large enough.
1415 */
1416 int ceph_get_path_pool_name(struct ceph_mount_info *cmount, const char *path, char *buf, size_t buflen);
1417
1418 /**
1419 * Get the default pool name of cephfs
1420 * Write the name of the default pool to the buffer. If buflen is 0, return
1421 * a suggested length for the buffer.
1422 * @param cmount the ceph mount handle to use.
1423 * @param buf buffer to store the name in
1424 * @param buflen size of the buffer
1425 * @returns length in bytes of the pool name, or -ERANGE if the buffer is not large enough.
1426 */
1427 int ceph_get_default_data_pool_name(struct ceph_mount_info *cmount, char *buf, size_t buflen);
1428
1429 /**
1430 * Get the file layout from an open file descriptor.
1431 *
1432 * @param cmount the ceph mount handle to use.
1433 * @param fh the open file descriptor referring to the file to get the layout of.
1434 * @param stripe_unit where to store the striping unit of the file
1435 * @param stripe_count where to store the striping count of the file
1436 * @param object_size where to store the object size of the file
1437 * @param pg_pool where to store the ceph pool id that the file is in
1438 * @returns 0 on success or a negative error code on failure.
1439 */
1440 int ceph_get_file_layout(struct ceph_mount_info *cmount, int fh, int *stripe_unit, int *stripe_count, int *object_size, int *pg_pool);
1441
1442 /**
1443 * Get the file layout.
1444 *
1445 * @param cmount the ceph mount handle to use.
1446 * @param path the path of the file/directory get the layout of.
1447 * @param stripe_unit where to store the striping unit of the file
1448 * @param stripe_count where to store the striping count of the file
1449 * @param object_size where to store the object size of the file
1450 * @param pg_pool where to store the ceph pool id that the file is in
1451 * @returns 0 on success or a negative error code on failure.
1452 */
1453 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);
1454
1455 /**
1456 * Get the file replication information from an open file descriptor.
1457 *
1458 * @param cmount the ceph mount handle to use.
1459 * @param fh the open file descriptor referring to the file to get the replication information of.
1460 * @returns the replication factor of the file.
1461 */
1462 int ceph_get_file_replication(struct ceph_mount_info *cmount, int fh);
1463
1464 /**
1465 * Get the file replication information.
1466 *
1467 * @param cmount the ceph mount handle to use.
1468 * @param path the path of the file/directory get the replication information of.
1469 * @returns the replication factor of the file.
1470 */
1471 int ceph_get_path_replication(struct ceph_mount_info *cmount, const char *path);
1472
1473 /**
1474 * Get the id of the named pool.
1475 *
1476 * @param cmount the ceph mount handle to use.
1477 * @param pool_name the name of the pool.
1478 * @returns the pool id, or a negative error code on failure.
1479 */
1480 int ceph_get_pool_id(struct ceph_mount_info *cmount, const char *pool_name);
1481
1482 /**
1483 * Get the pool replication factor.
1484 *
1485 * @param cmount the ceph mount handle to use.
1486 * @param pool_id the pool id to look up
1487 * @returns the replication factor, or a negative error code on failure.
1488 */
1489 int ceph_get_pool_replication(struct ceph_mount_info *cmount, int pool_id);
1490
1491 /**
1492 * Get the OSD address where the primary copy of a file stripe is located.
1493 *
1494 * @param cmount the ceph mount handle to use.
1495 * @param fd the open file descriptor referring to the file to get the striping unit of.
1496 * @param offset the offset into the file to specify the stripe. The offset can be
1497 * anywhere within the stripe unit.
1498 * @param addr the address of the OSD holding that stripe
1499 * @param naddr the capacity of the address passed in.
1500 * @returns the size of the addressed filled into the @e addr parameter, or a negative
1501 * error code on failure.
1502 */
1503 int ceph_get_file_stripe_address(struct ceph_mount_info *cmount, int fd, int64_t offset,
1504 struct sockaddr_storage *addr, int naddr);
1505
1506 /**
1507 * Get the list of OSDs where the objects containing a file offset are located.
1508 *
1509 * @param cmount the ceph mount handle to use.
1510 * @param fd the open file descriptor referring to the file.
1511 * @param offset the offset within the file.
1512 * @param length return the number of bytes between the offset and the end of
1513 * the stripe unit (optional).
1514 * @param osds an integer array to hold the OSD ids.
1515 * @param nosds the size of the integer array.
1516 * @returns the number of items stored in the output array, or -ERANGE if the
1517 * array is not large enough.
1518 */
1519 int ceph_get_file_extent_osds(struct ceph_mount_info *cmount, int fd,
1520 int64_t offset, int64_t *length, int *osds, int nosds);
1521
1522 /**
1523 * Get the fully qualified CRUSH location of an OSD.
1524 *
1525 * Returns (type, name) string pairs for each device in the CRUSH bucket
1526 * hierarchy starting from the given osd to the root. Each pair element is
1527 * separated by a NULL character.
1528 *
1529 * @param cmount the ceph mount handle to use.
1530 * @param osd the OSD id.
1531 * @param path buffer to store location.
1532 * @param len size of buffer.
1533 * @returns the amount of bytes written into the buffer, or -ERANGE if the
1534 * array is not large enough.
1535 */
1536 int ceph_get_osd_crush_location(struct ceph_mount_info *cmount,
1537 int osd, char *path, size_t len);
1538
1539 /**
1540 * Get the network address of an OSD.
1541 *
1542 * @param cmount the ceph mount handle.
1543 * @param osd the OSD id.
1544 * @param addr the OSD network address.
1545 * @returns zero on success, other returns a negative error code.
1546 */
1547 int ceph_get_osd_addr(struct ceph_mount_info *cmount, int osd,
1548 struct sockaddr_storage *addr);
1549
1550 /**
1551 * Get the file layout stripe unit granularity.
1552 * @param cmount the ceph mount handle.
1553 * @returns the stripe unit granularity or a negative error code on failure.
1554 */
1555 int ceph_get_stripe_unit_granularity(struct ceph_mount_info *cmount);
1556
1557 /** @} filelayout */
1558
1559 /**
1560 * No longer available. Do not use.
1561 * These functions will return -EOPNOTSUPP.
1562 */
1563 int ceph_set_default_file_stripe_unit(struct ceph_mount_info *cmount, int stripe);
1564 int ceph_set_default_file_stripe_count(struct ceph_mount_info *cmount, int count);
1565 int ceph_set_default_object_size(struct ceph_mount_info *cmount, int size);
1566 int ceph_set_default_preferred_pg(struct ceph_mount_info *cmount, int osd);
1567 int ceph_set_default_file_replication(struct ceph_mount_info *cmount, int replication);
1568
1569 /**
1570 * Read from local replicas when possible.
1571 *
1572 * @param cmount the ceph mount handle to use.
1573 * @param val a boolean to set (1) or clear (0) the option to favor local objects
1574 * for reads.
1575 * @returns 0
1576 */
1577 int ceph_localize_reads(struct ceph_mount_info *cmount, int val);
1578
1579 /**
1580 * Get the osd id of the local osd (if any)
1581 *
1582 * @param cmount the ceph mount handle to use.
1583 * @returns the osd (if any) local to the node where this call is made, otherwise
1584 * -1 is returned.
1585 */
1586 int ceph_get_local_osd(struct ceph_mount_info *cmount);
1587
1588 /** @} default_filelayout */
1589
1590 /**
1591 * Get the capabilities currently issued to the client.
1592 *
1593 * @param cmount the ceph mount handle to use.
1594 * @param fd the file descriptor to get issued
1595 * @returns the current capabilities issued to this client
1596 * for the open file
1597 */
1598 int ceph_debug_get_fd_caps(struct ceph_mount_info *cmount, int fd);
1599
1600 /**
1601 * Get the capabilities currently issued to the client.
1602 *
1603 * @param cmount the ceph mount handle to use.
1604 * @param path the path to the file
1605 * @returns the current capabilities issued to this client
1606 * for the file
1607 */
1608 int ceph_debug_get_file_caps(struct ceph_mount_info *cmount, const char *path);
1609
1610 /* Low Level */
1611 struct Inode *ceph_ll_get_inode(struct ceph_mount_info *cmount,
1612 vinodeno_t vino);
1613 int ceph_ll_lookup_inode(
1614 struct ceph_mount_info *cmount,
1615 struct inodeno_t ino,
1616 Inode **inode);
1617
1618 /**
1619 * Get the root inode of FS. Increase counter of references for root Inode. You must call ceph_ll_forget for it!
1620 *
1621 * @param cmount the ceph mount handle to use.
1622 * @param parent pointer to pointer to Inode struct. Pointer to root inode will be returned
1623 * @returns 0 if all good
1624 */
1625 int ceph_ll_lookup_root(struct ceph_mount_info *cmount,
1626 Inode **parent);
1627 int ceph_ll_lookup(struct ceph_mount_info *cmount, Inode *parent,
1628 const char *name, Inode **out, struct ceph_statx *stx,
1629 unsigned want, unsigned flags, const UserPerm *perms);
1630 int ceph_ll_put(struct ceph_mount_info *cmount, struct Inode *in);
1631 int ceph_ll_forget(struct ceph_mount_info *cmount, struct Inode *in,
1632 int count);
1633 int ceph_ll_walk(struct ceph_mount_info *cmount, const char* name, Inode **i,
1634 struct ceph_statx *stx, unsigned int want, unsigned int flags,
1635 const UserPerm *perms);
1636 int ceph_ll_getattr(struct ceph_mount_info *cmount, struct Inode *in,
1637 struct ceph_statx *stx, unsigned int want, unsigned int flags,
1638 const UserPerm *perms);
1639 int ceph_ll_setattr(struct ceph_mount_info *cmount, struct Inode *in,
1640 struct ceph_statx *stx, int mask, const UserPerm *perms);
1641 int ceph_ll_open(struct ceph_mount_info *cmount, struct Inode *in, int flags,
1642 struct Fh **fh, const UserPerm *perms);
1643 off_t ceph_ll_lseek(struct ceph_mount_info *cmount, struct Fh* filehandle,
1644 off_t offset, int whence);
1645 int ceph_ll_read(struct ceph_mount_info *cmount, struct Fh* filehandle,
1646 int64_t off, uint64_t len, char* buf);
1647 int ceph_ll_fsync(struct ceph_mount_info *cmount, struct Fh *fh,
1648 int syncdataonly);
1649 int ceph_ll_sync_inode(struct ceph_mount_info *cmount, struct Inode *in,
1650 int syncdataonly);
1651 int ceph_ll_fallocate(struct ceph_mount_info *cmount, struct Fh *fh,
1652 int mode, int64_t offset, int64_t length);
1653 int ceph_ll_write(struct ceph_mount_info *cmount, struct Fh* filehandle,
1654 int64_t off, uint64_t len, const char *data);
1655 int64_t ceph_ll_readv(struct ceph_mount_info *cmount, struct Fh *fh,
1656 const struct iovec *iov, int iovcnt, int64_t off);
1657 int64_t ceph_ll_writev(struct ceph_mount_info *cmount, struct Fh *fh,
1658 const struct iovec *iov, int iovcnt, int64_t off);
1659 int ceph_ll_close(struct ceph_mount_info *cmount, struct Fh* filehandle);
1660 int ceph_ll_iclose(struct ceph_mount_info *cmount, struct Inode *in, int mode);
1661 /**
1662 * Get xattr value by xattr name.
1663 *
1664 * @param cmount the ceph mount handle to use.
1665 * @param in file handle
1666 * @param name name of attribute
1667 * @param value pointer to begin buffer
1668 * @param size buffer size
1669 * @param perms pointer to UserPerms object
1670 * @returns size of returned buffer. Negative number in error case
1671 */
1672 int ceph_ll_getxattr(struct ceph_mount_info *cmount, struct Inode *in,
1673 const char *name, void *value, size_t size,
1674 const UserPerm *perms);
1675 int ceph_ll_setxattr(struct ceph_mount_info *cmount, struct Inode *in,
1676 const char *name, const void *value, size_t size,
1677 int flags, const UserPerm *perms);
1678 int ceph_ll_listxattr(struct ceph_mount_info *cmount, struct Inode *in,
1679 char *list, size_t buf_size, size_t *list_size,
1680 const UserPerm *perms);
1681 int ceph_ll_removexattr(struct ceph_mount_info *cmount, struct Inode *in,
1682 const char *name, const UserPerm *perms);
1683 int ceph_ll_create(struct ceph_mount_info *cmount, Inode *parent,
1684 const char *name, mode_t mode, int oflags, Inode **outp,
1685 Fh **fhp, struct ceph_statx *stx, unsigned want,
1686 unsigned lflags, const UserPerm *perms);
1687 int ceph_ll_mknod(struct ceph_mount_info *cmount, Inode *parent,
1688 const char *name, mode_t mode, dev_t rdev, Inode **out,
1689 struct ceph_statx *stx, unsigned want, unsigned flags,
1690 const UserPerm *perms);
1691 int ceph_ll_mkdir(struct ceph_mount_info *cmount, Inode *parent,
1692 const char *name, mode_t mode, Inode **out,
1693 struct ceph_statx *stx, unsigned want,
1694 unsigned flags, const UserPerm *perms);
1695 int ceph_ll_link(struct ceph_mount_info *cmount, struct Inode *in,
1696 struct Inode *newparent, const char *name,
1697 const UserPerm *perms);
1698 int ceph_ll_opendir(struct ceph_mount_info *cmount, struct Inode *in,
1699 struct ceph_dir_result **dirpp, const UserPerm *perms);
1700 int ceph_ll_releasedir(struct ceph_mount_info *cmount,
1701 struct ceph_dir_result* dir);
1702 int ceph_ll_rename(struct ceph_mount_info *cmount, struct Inode *parent,
1703 const char *name, struct Inode *newparent,
1704 const char *newname, const UserPerm *perms);
1705 int ceph_ll_unlink(struct ceph_mount_info *cmount, struct Inode *in,
1706 const char *name, const UserPerm *perms);
1707 int ceph_ll_statfs(struct ceph_mount_info *cmount, struct Inode *in,
1708 struct statvfs *stbuf);
1709 int ceph_ll_readlink(struct ceph_mount_info *cmount, struct Inode *in,
1710 char *buf, size_t bufsize, const UserPerm *perms);
1711 int ceph_ll_symlink(struct ceph_mount_info *cmount,
1712 Inode *in, const char *name, const char *value,
1713 Inode **out, struct ceph_statx *stx,
1714 unsigned want, unsigned flags,
1715 const UserPerm *perms);
1716 int ceph_ll_rmdir(struct ceph_mount_info *cmount, struct Inode *in,
1717 const char *name, const UserPerm *perms);
1718 uint32_t ceph_ll_stripe_unit(struct ceph_mount_info *cmount,
1719 struct Inode *in);
1720 uint32_t ceph_ll_file_layout(struct ceph_mount_info *cmount,
1721 struct Inode *in,
1722 struct ceph_file_layout *layout);
1723 uint64_t ceph_ll_snap_seq(struct ceph_mount_info *cmount,
1724 struct Inode *in);
1725 int ceph_ll_get_stripe_osd(struct ceph_mount_info *cmount,
1726 struct Inode *in,
1727 uint64_t blockno,
1728 struct ceph_file_layout* layout);
1729 int ceph_ll_num_osds(struct ceph_mount_info *cmount);
1730 int ceph_ll_osdaddr(struct ceph_mount_info *cmount,
1731 int osd, uint32_t *addr);
1732 uint64_t ceph_ll_get_internal_offset(struct ceph_mount_info *cmount,
1733 struct Inode *in, uint64_t blockno);
1734 int ceph_ll_read_block(struct ceph_mount_info *cmount,
1735 struct Inode *in, uint64_t blockid,
1736 char* bl, uint64_t offset, uint64_t length,
1737 struct ceph_file_layout* layout);
1738 int ceph_ll_write_block(struct ceph_mount_info *cmount,
1739 struct Inode *in, uint64_t blockid,
1740 char* buf, uint64_t offset,
1741 uint64_t length, struct ceph_file_layout* layout,
1742 uint64_t snapseq, uint32_t sync);
1743 int ceph_ll_commit_blocks(struct ceph_mount_info *cmount,
1744 struct Inode *in, uint64_t offset, uint64_t range);
1745
1746
1747 int ceph_ll_getlk(struct ceph_mount_info *cmount,
1748 Fh *fh, struct flock *fl, uint64_t owner);
1749 int ceph_ll_setlk(struct ceph_mount_info *cmount,
1750 Fh *fh, struct flock *fl, uint64_t owner, int sleep);
1751
1752 int ceph_ll_lazyio(struct ceph_mount_info *cmount, Fh *fh, int enable);
1753
1754 /*
1755 * Delegation support
1756 *
1757 * Delegations are way for an application to request exclusive or
1758 * semi-exclusive access to an Inode. The client requests the delegation and
1759 * if it's successful it can reliably cache file data and metadata until the
1760 * delegation is recalled.
1761 *
1762 * Recalls are issued via a callback function, provided by the application.
1763 * Callback functions should act something like signal handlers. You want to
1764 * do as little as possible in the callback. Any major work should be deferred
1765 * in some fashion as it's difficult to predict the context in which this
1766 * function will be called.
1767 *
1768 * Once the delegation has been recalled, the application should return it as
1769 * soon as possible. The application has client_deleg_timeout seconds to
1770 * return it, after which the cmount structure is forcibly unmounted and
1771 * further calls into it fail.
1772 *
1773 * The application can set the client_deleg_timeout config option to suit its
1774 * needs, but it should take care to choose a value that allows it to avoid
1775 * forcible eviction from the cluster in the event of an application bug.
1776 */
1777
1778 /* Commands for manipulating delegation state */
1779 #ifndef CEPH_DELEGATION_NONE
1780 # define CEPH_DELEGATION_NONE 0
1781 # define CEPH_DELEGATION_RD 1
1782 # define CEPH_DELEGATION_WR 2
1783 #endif
1784
1785 /**
1786 * Get the amount of time that the client has to return caps
1787 * @param cmount the ceph mount handle to use.
1788 *
1789 * In the event that a client does not return its caps, the MDS may blacklist
1790 * it after this timeout. Applications should check this value and ensure
1791 * that they set the delegation timeout to a value lower than this.
1792 *
1793 * This call returns the cap return timeout (in seconds) for this cmount, or
1794 * zero if it's not mounted.
1795 */
1796 uint32_t ceph_get_cap_return_timeout(struct ceph_mount_info *cmount);
1797
1798 /**
1799 * Set the delegation timeout for the mount (thereby enabling delegations)
1800 * @param cmount the ceph mount handle to use.
1801 * @param timeout the delegation timeout (in seconds)
1802 *
1803 * Since the client could end up blacklisted if it doesn't return delegations
1804 * in time, we mandate that any application wanting to use delegations
1805 * explicitly set the timeout beforehand. Until this call is done on the
1806 * mount, attempts to set a delegation will return -ETIME.
1807 *
1808 * Once a delegation is recalled, if it is not returned in this amount of
1809 * time, the cmount will be forcibly unmounted and further access attempts
1810 * will fail (usually with -ENOTCONN errors).
1811 *
1812 * This value is further vetted against the cap return timeout, and this call
1813 * can fail with -EINVAL if the timeout value is too long. Delegations can be
1814 * disabled again by setting the timeout to 0.
1815 */
1816 int ceph_set_deleg_timeout(struct ceph_mount_info *cmount, uint32_t timeout);
1817
1818 /**
1819 * Request a delegation on an open Fh
1820 * @param cmount the ceph mount handle to use.
1821 * @param fh file handle
1822 * @param cmd CEPH_DELEGATION_* command
1823 * @param cb callback function for recalling delegation
1824 * @param priv opaque token passed back during recalls
1825 *
1826 * Returns 0 if the delegation was granted, -EAGAIN if there was a conflict
1827 * and other error codes if there is a fatal error of some sort (e.g. -ENOMEM,
1828 * -ETIME)
1829 */
1830 int ceph_ll_delegation(struct ceph_mount_info *cmount, Fh *fh,
1831 unsigned int cmd, ceph_deleg_cb_t cb, void *priv);
1832
1833 mode_t ceph_umask(struct ceph_mount_info *cmount, mode_t mode);
1834
1835 /* state reclaim */
1836 #define CEPH_RECLAIM_RESET 1
1837
1838 /**
1839 * Set ceph client uuid
1840 * @param cmount the ceph mount handle to use.
1841 * @param uuid the uuid to set
1842 *
1843 * Must be called before mount.
1844 */
1845 void ceph_set_uuid(struct ceph_mount_info *cmount, const char *uuid);
1846
1847 /**
1848 * Set ceph client session timeout
1849 * @param cmount the ceph mount handle to use.
1850 * @param timeout the timeout to set
1851 *
1852 * Must be called before mount.
1853 */
1854 void ceph_set_session_timeout(struct ceph_mount_info *cmount, unsigned timeout);
1855
1856 /**
1857 * Start to reclaim states of other client
1858 * @param cmount the ceph mount handle to use.
1859 * @param uuid uuid of client whose states need to be reclaimed
1860 * @param flags flags that control how states get reclaimed
1861 *
1862 * Returns 0 success, -EOPNOTSUPP if mds does not support the operation,
1863 * -ENOENT if CEPH_RECLAIM_RESET is specified and there is no client
1864 * with the given uuid, -ENOTRECOVERABLE in all other error cases.
1865 */
1866 int ceph_start_reclaim(struct ceph_mount_info *cmount,
1867 const char *uuid, unsigned flags);
1868
1869 /**
1870 * finish reclaiming states of other client (
1871 * @param cmount the ceph mount handle to use.
1872 */
1873 void ceph_finish_reclaim(struct ceph_mount_info *cmount);
1874
1875 /**
1876 * Register a set of callbacks to be used with this cmount
1877 * @param cmount the ceph mount handle on which the cb's should be registerd
1878 * @param args callback arguments to register with the cmount
1879 *
1880 * Any fields set to NULL will be ignored. There currently is no way to
1881 * unregister these callbacks, so this is a one-way change.
1882 */
1883 void ceph_ll_register_callbacks(struct ceph_mount_info *cmount,
1884 struct ceph_client_callback_args *args);
1885 #ifdef __cplusplus
1886 }
1887 #endif
1888
1889 #endif