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