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