]> git.proxmox.com Git - ceph.git/blame - ceph/src/include/cephfs/libcephfs.h
update dh_systemd restart patch for pacific
[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
459/**
460 * Gets the configuration value as a string.
461 *
462 * @param cmount the mount handle to set the configuration value on
463 * @param option the config option to get
464 * @param buf the buffer to fill with the value
465 * @param len the length of the buffer.
466 * @returns the size of the buffer filled in with the value, or negative error code on failure
467 */
468int ceph_conf_get(struct ceph_mount_info *cmount, const char *option, char *buf, size_t len);
469
470/** @} config */
471
472/**
473 * @defgroup libcephfs_h_fsops File System Operations.
474 * Functions for getting/setting file system wide information specific to a particular
475 * mount handle.
476 *
477 * @{
478 */
479
480/**
481 * Perform a statfs on the ceph file system. This call fills in file system wide statistics
482 * into the passed in buffer.
483 *
484 * @param cmount the ceph mount handle to use for performing the statfs.
485 * @param path can be any path within the mounted filesystem
486 * @param stbuf the file system statistics filled in by this function.
487 * @return 0 on success, negative error code otherwise.
488 */
489int ceph_statfs(struct ceph_mount_info *cmount, const char *path, struct statvfs *stbuf);
490
491/**
492 * Synchronize all filesystem data to persistent media.
493 *
494 * @param cmount the ceph mount handle to use for performing the sync_fs.
495 * @returns 0 on success or negative error code on failure.
496 */
497int ceph_sync_fs(struct ceph_mount_info *cmount);
498
499/**
500 * Get the current working directory.
501 *
502 * @param cmount the ceph mount to get the current working directory for.
503 * @returns the path to the current working directory
504 */
505const char* ceph_getcwd(struct ceph_mount_info *cmount);
506
507/**
508 * Change the current working directory.
509 *
510 * @param cmount the ceph mount to change the current working directory for.
511 * @param path the path to the working directory to change into.
512 * @returns 0 on success, negative error code otherwise.
513 */
514int ceph_chdir(struct ceph_mount_info *cmount, const char *path);
515
516/** @} fsops */
517
518/**
519 * @defgroup libcephfs_h_dir Directory Operations.
520 * Functions for manipulating and listing directories.
521 *
522 * @{
523 */
524
525/**
526 * Open the given directory.
527 *
528 * @param cmount the ceph mount handle to use to open the directory
529 * @param name the path name of the directory to open. Must be either an absolute path
530 * or a path relative to the current working directory.
531 * @param dirpp the directory result pointer structure to fill in.
532 * @returns 0 on success or negative error code otherwise.
533 */
534int ceph_opendir(struct ceph_mount_info *cmount, const char *name, struct ceph_dir_result **dirpp);
535
536/**
537 * Close the open directory.
538 *
539 * @param cmount the ceph mount handle to use for closing the directory
540 * @param dirp the directory result pointer (set by ceph_opendir) to close
541 * @returns 0 on success or negative error code on failure.
542 */
543int ceph_closedir(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp);
544
545/**
546 * Get the next entry in an open directory.
547 *
548 * @param cmount the ceph mount handle to use for performing the readdir.
549 * @param dirp the directory stream pointer from an opendir holding the state of the
550 * next entry to return.
551 * @returns the next directory entry or NULL if at the end of the directory (or the directory
552 * is empty. This pointer should not be freed by the caller, and is only safe to
553 * access between return and the next call to ceph_readdir or ceph_closedir.
554 */
555struct dirent * ceph_readdir(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp);
556
557/**
558 * A safe version of ceph_readdir, where the directory entry struct is allocated by the caller.
559 *
560 * @param cmount the ceph mount handle to use for performing the readdir.
561 * @param dirp the directory stream pointer from an opendir holding the state of the
562 * next entry to return.
563 * @param de the directory entry pointer filled in with the next directory entry of the dirp state.
564 * @returns 1 if the next entry was filled in, 0 if the end of the directory stream was reached,
565 * and a negative error code on failure.
566 */
567int ceph_readdir_r(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp, struct dirent *de);
568
569/**
570 * A safe version of ceph_readdir that also returns the file statistics (readdir+stat).
571 *
572 * @param cmount the ceph mount handle to use for performing the readdir_plus_r.
573 * @param dirp the directory stream pointer from an opendir holding the state of the
574 * next entry to return.
575 * @param de the directory entry pointer filled in with the next directory entry of the dirp state.
576 * @param stx the stats of the file/directory of the entry returned
577 * @param want mask showing desired inode attrs for returned entry
578 * @param flags bitmask of flags to use when filling out attributes
579 * @param out optional returned Inode argument. If non-NULL, then a reference will be taken on
580 * the inode and the pointer set on success.
581 * @returns 1 if the next entry was filled in, 0 if the end of the directory stream was reached,
582 * and a negative error code on failure.
583 */
584int ceph_readdirplus_r(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp, struct dirent *de,
585 struct ceph_statx *stx, unsigned want, unsigned flags, struct Inode **out);
586
587/**
588 * Gets multiple directory entries.
589 *
590 * @param cmount the ceph mount handle to use for performing the getdents.
591 * @param dirp the directory stream pointer from an opendir holding the state of the
592 * next entry/entries to return.
593 * @param name an array of struct dirent that gets filled in with the to fill returned directory entries into.
594 * @param buflen the length of the buffer, which should be the number of dirent structs * sizeof(struct dirent).
595 * @returns the length of the buffer that was filled in, will always be multiples of sizeof(struct dirent), or a
596 * negative error code. If the buffer is not large enough for a single entry, -ERANGE is returned.
597 */
598int ceph_getdents(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp, char *name, int buflen);
599
600/**
601 * Gets multiple directory names.
602 *
603 * @param cmount the ceph mount handle to use for performing the getdents.
604 * @param dirp the directory stream pointer from an opendir holding the state of the
605 * next entry/entries to return.
606 * @param name a buffer to fill in with directory entry names.
607 * @param buflen the length of the buffer that can be filled in.
608 * @returns the length of the buffer filled in with entry names, or a negative error code on failure.
609 * If the buffer isn't large enough for a single entry, -ERANGE is returned.
610 */
611int ceph_getdnames(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp, char *name, int buflen);
612
613/**
614 * Rewind the directory stream to the beginning of the directory.
615 *
616 * @param cmount the ceph mount handle to use for performing the rewinddir.
617 * @param dirp the directory stream pointer to rewind.
618 */
619void ceph_rewinddir(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp);
620
621/**
622 * Get the current position of a directory stream.
623 *
624 * @param cmount the ceph mount handle to use for performing the telldir.
625 * @param dirp the directory stream pointer to get the current position of.
626 * @returns the position of the directory stream. Note that the offsets returned
627 * by ceph_telldir do not have a particular order (cannot be compared with
628 * inequality).
629 */
630int64_t ceph_telldir(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp);
631
632/**
633 * Move the directory stream to a position specified by the given offset.
634 *
635 * @param cmount the ceph mount handle to use for performing the seekdir.
636 * @param dirp the directory stream pointer to move.
637 * @param offset the position to move the directory stream to. This offset should be
9f95a23c 638 * a value returned by telldir. Note that this value does not refer to the nth
7c673cae
FG
639 * entry in a directory, and can not be manipulated with plus or minus.
640 */
641void ceph_seekdir(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp, int64_t offset);
642
643/**
644 * Create a directory.
645 *
646 * @param cmount the ceph mount handle to use for making the directory.
647 * @param path the path of the directory to create. This must be either an
648 * absolute path or a relative path off of the current working directory.
649 * @param mode the permissions the directory should have once created.
650 * @returns 0 on success or a negative return code on error.
651 */
652int ceph_mkdir(struct ceph_mount_info *cmount, const char *path, mode_t mode);
653
f67539c2
TL
654/**
655 * Create a snapshot
656 *
657 * @param cmount the ceph mount handle to use for making the directory.
658 * @param path the path of the directory to create snapshot. This must be either an
659 * absolute path or a relative path off of the current working directory.
660 * @param name snapshot name
661 * @param mode the permissions the directory should have once created.
662 * @param snap_metadata array of snap metadata structs
663 * @param nr_snap_metadata number of snap metadata struct entries
664 * @returns 0 on success or a negative return code on error.
665 */
666int ceph_mksnap(struct ceph_mount_info *cmount, const char *path, const char *name,
667 mode_t mode, struct snap_metadata *snap_metadata, size_t nr_snap_metadata);
668
669/**
670 * Remove a snapshot
671 *
672 * @param cmount the ceph mount handle to use for making the directory.
673 * @param path the path of the directory to create snapshot. This must be either an
674 * absolute path or a relative path off of the current working directory.
675 * @param name snapshot name
676 * @returns 0 on success or a negative return code on error.
677 */
678int ceph_rmsnap(struct ceph_mount_info *cmount, const char *path, const char *name);
679
7c673cae
FG
680/**
681 * Create multiple directories at once.
682 *
683 * @param cmount the ceph mount handle to use for making the directories.
684 * @param path the full path of directories and sub-directories that should
685 * be created.
686 * @param mode the permissions the directory should have once created.
687 * @returns 0 on success or a negative return code on error.
688 */
689int ceph_mkdirs(struct ceph_mount_info *cmount, const char *path, mode_t mode);
690
691/**
692 * Remove a directory.
693 *
694 * @param cmount the ceph mount handle to use for removing directories.
695 * @param path the path of the directory to remove.
696 * @returns 0 on success or a negative return code on error.
697 */
698int ceph_rmdir(struct ceph_mount_info *cmount, const char *path);
699
700/** @} dir */
701
702/**
703 * @defgroup libcephfs_h_links Links and Link Handling.
704 * Functions for creating and manipulating hard links and symbolic inks.
705 *
706 * @{
707 */
708
709/**
710 * Create a link.
711 *
712 * @param cmount the ceph mount handle to use for creating the link.
713 * @param existing the path to the existing file/directory to link to.
714 * @param newname the path to the new file/directory to link from.
715 * @returns 0 on success or a negative return code on error.
716 */
717int ceph_link(struct ceph_mount_info *cmount, const char *existing, const char *newname);
718
719/**
720 * Read a symbolic link.
721 *
722 * @param cmount the ceph mount handle to use for creating the link.
723 * @param path the path to the symlink to read
724 * @param buf the buffer to hold the path of the file that the symlink points to.
725 * @param size the length of the buffer
726 * @returns number of bytes copied on success or negative error code on failure
727 */
728int ceph_readlink(struct ceph_mount_info *cmount, const char *path, char *buf, int64_t size);
729
730/**
731 * Creates a symbolic link.
732 *
733 * @param cmount the ceph mount handle to use for creating the symbolic link.
734 * @param existing the path to the existing file/directory to link to.
735 * @param newname the path to the new file/directory to link from.
736 * @returns 0 on success or a negative return code on failure.
737 */
738int ceph_symlink(struct ceph_mount_info *cmount, const char *existing, const char *newname);
739
740/** @} links */
741
742/**
743 * @defgroup libcephfs_h_files File manipulation and handling.
744 * Functions for creating and manipulating files.
745 *
746 * @{
747 */
748
f67539c2
TL
749
750/**
751 * Checks if deleting a file, link or directory is allowed.
752 *
753 * @param cmount the ceph mount handle to use.
754 * @param path the path of the file, link or directory.
755 * @returns 0 on success or negative error code on failure.
756 */
757int ceph_may_delete(struct ceph_mount_info *cmount, const char *path);
758
7c673cae
FG
759/**
760 * Removes a file, link, or symbolic link. If the file/link has multiple links to it, the
761 * file will not disappear from the namespace until all references to it are removed.
762 *
763 * @param cmount the ceph mount handle to use for performing the unlink.
764 * @param path the path of the file or link to unlink.
765 * @returns 0 on success or negative error code on failure.
766 */
767int ceph_unlink(struct ceph_mount_info *cmount, const char *path);
768
769/**
770 * Rename a file or directory.
771 *
772 * @param cmount the ceph mount handle to use for performing the rename.
773 * @param from the path to the existing file or directory.
774 * @param to the new name of the file or directory
775 * @returns 0 on success or negative error code on failure.
776 */
777int ceph_rename(struct ceph_mount_info *cmount, const char *from, const char *to);
778
779/**
780 * Get an open file's extended statistics and attributes.
781 *
782 * @param cmount the ceph mount handle to use for performing the stat.
783 * @param fd the file descriptor of the file to get statistics of.
784 * @param stx the ceph_statx struct that will be filled in with the file's statistics.
785 * @param want bitfield of CEPH_STATX_* flags showing designed attributes
786 * @param flags bitfield that can be used to set AT_* modifier flags (only AT_NO_ATTR_SYNC and AT_SYMLINK_NOFOLLOW)
787 * @returns 0 on success or negative error code on failure.
788 */
789int ceph_fstatx(struct ceph_mount_info *cmount, int fd, struct ceph_statx *stx,
790 unsigned int want, unsigned int flags);
791
792/**
793 * Get a file's extended statistics and attributes.
794 *
795 * @param cmount the ceph mount handle to use for performing the stat.
796 * @param path the file or directory to get the statistics of.
797 * @param stx the ceph_statx struct that will be filled in with the file's statistics.
798 * @param want bitfield of CEPH_STATX_* flags showing designed attributes
799 * @param flags bitfield that can be used to set AT_* modifier flags (only AT_NO_ATTR_SYNC and AT_SYMLINK_NOFOLLOW)
800 * @returns 0 on success or negative error code on failure.
801 */
802int ceph_statx(struct ceph_mount_info *cmount, const char *path, struct ceph_statx *stx,
803 unsigned int want, unsigned int flags);
804
11fdf7f2
TL
805/**
806 * Get a file's statistics and attributes.
807 *
f67539c2
TL
808 * ceph_stat() is deprecated, use ceph_statx() instead.
809 *
11fdf7f2
TL
810 * @param cmount the ceph mount handle to use for performing the stat.
811 * @param path the file or directory to get the statistics of.
812 * @param stbuf the stat struct that will be filled in with the file's statistics.
813 * @returns 0 on success or negative error code on failure.
814 */
f67539c2
TL
815int ceph_stat(struct ceph_mount_info *cmount, const char *path, struct stat *stbuf)
816 LIBCEPHFS_DEPRECATED;
11fdf7f2
TL
817
818/**
819 * Get a file's statistics and attributes, without following symlinks.
820 *
f67539c2
TL
821 * ceph_lstat() is deprecated, use ceph_statx(.., AT_SYMLINK_NOFOLLOW) instead.
822 *
11fdf7f2
TL
823 * @param cmount the ceph mount handle to use for performing the stat.
824 * @param path the file or directory to get the statistics of.
825 * @param stbuf the stat struct that will be filled in with the file's statistics.
826 * @returns 0 on success or negative error code on failure.
827 */
f67539c2
TL
828int ceph_lstat(struct ceph_mount_info *cmount, const char *path, struct stat *stbuf)
829 LIBCEPHFS_DEPRECATED;
11fdf7f2
TL
830
831/**
832 * Get the open file's statistics.
833 *
f67539c2
TL
834 * ceph_fstat() is deprecated, use ceph_fstatx() instead.
835 *
11fdf7f2
TL
836 * @param cmount the ceph mount handle to use for performing the fstat.
837 * @param fd the file descriptor of the file to get statistics of.
838 * @param stbuf the stat struct of the file's statistics, filled in by the
839 * function.
840 * @returns 0 on success or a negative error code on failure
841 */
f67539c2
TL
842int ceph_fstat(struct ceph_mount_info *cmount, int fd, struct stat *stbuf)
843 LIBCEPHFS_DEPRECATED;
11fdf7f2 844
7c673cae
FG
845/**
846 * Set a file's attributes.
847 *
848 * @param cmount the ceph mount handle to use for performing the setattr.
849 * @param relpath the path to the file/directory to set the attributes of.
850 * @param stx the statx struct that must include attribute values to set on the file.
851 * @param mask a mask of all the CEPH_SETATTR_* values that have been set in the statx struct.
852 * @param flags mask of AT_* flags (only AT_ATTR_NOFOLLOW is respected for now)
853 * @returns 0 on success or negative error code on failure.
854 */
855int ceph_setattrx(struct ceph_mount_info *cmount, const char *relpath, struct ceph_statx *stx, int mask, int flags);
856
857/**
858 * Set a file's attributes (extended version).
859 *
860 * @param cmount the ceph mount handle to use for performing the setattr.
861 * @param fd the fd of the open file/directory to set the attributes of.
862 * @param stx the statx struct that must include attribute values to set on the file.
863 * @param mask a mask of all the stat values that have been set on the stat struct.
864 * @returns 0 on success or negative error code on failure.
865 */
866int ceph_fsetattrx(struct ceph_mount_info *cmount, int fd, struct ceph_statx *stx, int mask);
867
868/**
869 * Change the mode bits (permissions) of a file/directory.
870 *
871 * @param cmount the ceph mount handle to use for performing the chmod.
872 * @param path the path to the file/directory to change the mode bits on.
873 * @param mode the new permissions to set.
874 * @returns 0 on success or a negative error code on failure.
875 */
876int ceph_chmod(struct ceph_mount_info *cmount, const char *path, mode_t mode);
877
f67539c2
TL
878/**
879 * Change the mode bits (permissions) of a file/directory. If the path is a
880 * symbolic link, it's not de-referenced.
881 *
882 * @param cmount the ceph mount handle to use for performing the chmod.
883 * @param path the path of file/directory to change the mode bits on.
884 * @param mode the new permissions to set.
885 * @returns 0 on success or a negative error code on failure.
886 */
887int ceph_lchmod(struct ceph_mount_info *cmount, const char *path, mode_t mode);
888
7c673cae
FG
889/**
890 * Change the mode bits (permissions) of an open file.
891 *
892 * @param cmount the ceph mount handle to use for performing the chmod.
893 * @param fd the open file descriptor to change the mode bits on.
894 * @param mode the new permissions to set.
895 * @returns 0 on success or a negative error code on failure.
896 */
897int ceph_fchmod(struct ceph_mount_info *cmount, int fd, mode_t mode);
898
899/**
900 * Change the ownership of a file/directory.
901 *
902 * @param cmount the ceph mount handle to use for performing the chown.
903 * @param path the path of the file/directory to change the ownership of.
904 * @param uid the user id to set on the file/directory.
905 * @param gid the group id to set on the file/directory.
906 * @returns 0 on success or negative error code on failure.
907 */
908int ceph_chown(struct ceph_mount_info *cmount, const char *path, int uid, int gid);
909
910/**
911 * Change the ownership of a file from an open file descriptor.
912 *
913 * @param cmount the ceph mount handle to use for performing the chown.
914 * @param fd the fd of the open file/directory to change the ownership of.
915 * @param uid the user id to set on the file/directory.
916 * @param gid the group id to set on the file/directory.
917 * @returns 0 on success or negative error code on failure.
918 */
919int ceph_fchown(struct ceph_mount_info *cmount, int fd, int uid, int gid);
920
921/**
922 * Change the ownership of a file/directory, don't follow symlinks.
923 *
924 * @param cmount the ceph mount handle to use for performing the chown.
925 * @param path the path of the file/directory to change the ownership of.
926 * @param uid the user id to set on the file/directory.
927 * @param gid the group id to set on the file/directory.
928 * @returns 0 on success or negative error code on failure.
929 */
930int ceph_lchown(struct ceph_mount_info *cmount, const char *path, int uid, int gid);
931
932/**
933 * Change file/directory last access and modification times.
934 *
935 * @param cmount the ceph mount handle to use for performing the utime.
936 * @param path the path to the file/directory to set the time values of.
937 * @param buf holding the access and modification times to set on the file.
938 * @returns 0 on success or negative error code on failure.
939 */
940int ceph_utime(struct ceph_mount_info *cmount, const char *path, struct utimbuf *buf);
941
11fdf7f2
TL
942/**
943 * Change file/directory last access and modification times.
944 *
945 * @param cmount the ceph mount handle to use for performing the utime.
946 * @param fd the fd of the open file/directory to set the time values of.
947 * @param buf holding the access and modification times to set on the file.
948 * @returns 0 on success or negative error code on failure.
949 */
950int ceph_futime(struct ceph_mount_info *cmount, int fd, struct utimbuf *buf);
951
952/**
953 * Change file/directory last access and modification times.
954 *
955 * @param cmount the ceph mount handle to use for performing the utime.
956 * @param path the path to the file/directory to set the time values of.
957 * @param times holding the access and modification times to set on the file.
958 * @returns 0 on success or negative error code on failure.
959 */
960int ceph_utimes(struct ceph_mount_info *cmount, const char *path, struct timeval times[2]);
961
962/**
963 * Change file/directory last access and modification times, don't follow symlinks.
964 *
965 * @param cmount the ceph mount handle to use for performing the utime.
966 * @param path the path to the file/directory to set the time values of.
967 * @param times holding the access and modification times to set on the file.
968 * @returns 0 on success or negative error code on failure.
969 */
970int ceph_lutimes(struct ceph_mount_info *cmount, const char *path, struct timeval times[2]);
971
972/**
973 * Change file/directory last access and modification times.
974 *
975 * @param cmount the ceph mount handle to use for performing the utime.
976 * @param fd the fd of the open file/directory to set the time values of.
977 * @param times holding the access and modification times to set on the file.
978 * @returns 0 on success or negative error code on failure.
979 */
980int ceph_futimes(struct ceph_mount_info *cmount, int fd, struct timeval times[2]);
981
982/**
983 * Change file/directory last access and modification times.
984 *
985 * @param cmount the ceph mount handle to use for performing the utime.
986 * @param fd the fd of the open file/directory to set the time values of.
987 * @param times holding the access and modification times to set on the file.
988 * @returns 0 on success or negative error code on failure.
989 */
990int ceph_futimens(struct ceph_mount_info *cmount, int fd, struct timespec times[2]);
991
7c673cae
FG
992/**
993 * Apply or remove an advisory lock.
994 *
995 * @param cmount the ceph mount handle to use for performing the lock.
996 * @param fd the open file descriptor to change advisory lock.
997 * @param operation the advisory lock operation to be performed on the file
998 * descriptor among LOCK_SH (shared lock), LOCK_EX (exclusive lock),
999 * or LOCK_UN (remove lock). The LOCK_NB value can be ORed to perform a
1000 * non-blocking operation.
1001 * @param owner the user-supplied owner identifier (an arbitrary integer)
1002 * @returns 0 on success or negative error code on failure.
1003 */
1004int ceph_flock(struct ceph_mount_info *cmount, int fd, int operation,
1005 uint64_t owner);
1006
1007/**
1008 * Truncate the file to the given size. If this operation causes the
1009 * file to expand, the empty bytes will be filled in with zeros.
1010 *
1011 * @param cmount the ceph mount handle to use for performing the truncate.
1012 * @param path the path to the file to truncate.
1013 * @param size the new size of the file.
1014 * @returns 0 on success or a negative error code on failure.
1015 */
1016int ceph_truncate(struct ceph_mount_info *cmount, const char *path, int64_t size);
1017
1018/**
1019 * Make a block or character special file.
1020 *
1021 * @param cmount the ceph mount handle to use for performing the mknod.
1022 * @param path the path to the special file.
1023 * @param mode the permissions to use and the type of special file. The type can be
1024 * one of S_IFREG, S_IFCHR, S_IFBLK, S_IFIFO.
1025 * @param rdev If the file type is S_IFCHR or S_IFBLK then this parameter specifies the
1026 * major and minor numbers of the newly created device special file. Otherwise,
1027 * it is ignored.
1028 * @returns 0 on success or negative error code on failure.
1029 */
1030int ceph_mknod(struct ceph_mount_info *cmount, const char *path, mode_t mode, dev_t rdev);
1031/**
1032 * Create and/or open a file.
1033 *
1034 * @param cmount the ceph mount handle to use for performing the open.
1035 * @param path the path of the file to open. If the flags parameter includes O_CREAT,
1036 * the file will first be created before opening.
1037 * @param flags a set of option masks that control how the file is created/opened.
1038 * @param mode the permissions to place on the file if the file does not exist and O_CREAT
1039 * is specified in the flags.
1040 * @returns a non-negative file descriptor number on success or a negative error code on failure.
1041 */
1042int ceph_open(struct ceph_mount_info *cmount, const char *path, int flags, mode_t mode);
1043
1044/**
1045 * Create and/or open a file with a specific file layout.
1046 *
1047 * @param cmount the ceph mount handle to use for performing the open.
1048 * @param path the path of the file to open. If the flags parameter includes O_CREAT,
1049 * the file will first be created before opening.
1050 * @param flags a set of option masks that control how the file is created/opened.
1051 * @param mode the permissions to place on the file if the file does not exist and O_CREAT
1052 * is specified in the flags.
1053 * @param stripe_unit the stripe unit size (option, 0 for default)
1054 * @param stripe_count the stripe count (optional, 0 for default)
1055 * @param object_size the object size (optional, 0 for default)
1056 * @param data_pool name of target data pool name (optional, NULL or empty string for default)
1057 * @returns a non-negative file descriptor number on success or a negative error code on failure.
1058 */
1059int ceph_open_layout(struct ceph_mount_info *cmount, const char *path, int flags,
1060 mode_t mode, int stripe_unit, int stripe_count, int object_size,
1061 const char *data_pool);
1062
1063/**
1064 * Close the open file.
1065 *
1066 * @param cmount the ceph mount handle to use for performing the close.
1067 * @param fd the file descriptor referring to the open file.
1068 * @returns 0 on success or a negative error code on failure.
1069 */
1070int ceph_close(struct ceph_mount_info *cmount, int fd);
1071
1072/**
1073 * Reposition the open file stream based on the given offset.
1074 *
1075 * @param cmount the ceph mount handle to use for performing the lseek.
1076 * @param fd the open file descriptor referring to the open file and holding the
1077 * current position of the stream.
1078 * @param offset the offset to set the stream to
1079 * @param whence the flag to indicate what type of seeking to perform:
1080 * SEEK_SET: the offset is set to the given offset in the file.
1081 * SEEK_CUR: the offset is set to the current location plus @e offset bytes.
1082 * SEEK_END: the offset is set to the end of the file plus @e offset bytes.
1083 * @returns 0 on success or a negative error code on failure.
1084 */
1085int64_t ceph_lseek(struct ceph_mount_info *cmount, int fd, int64_t offset, int whence);
1086/**
1087 * Read data from the file.
1088 *
1089 * @param cmount the ceph mount handle to use for performing the read.
1090 * @param fd the file descriptor of the open file to read from.
1091 * @param buf the buffer to read data into
1092 * @param size the initial size of the buffer
1093 * @param offset the offset in the file to read from. If this value is negative, the
1094 * function reads from the current offset of the file descriptor.
1095 * @returns the number of bytes read into buf, or a negative error code on failure.
1096 */
1097int ceph_read(struct ceph_mount_info *cmount, int fd, char *buf, int64_t size, int64_t offset);
1098
1099/**
1100 * Read data from the file.
1101 * @param cmount the ceph mount handle to use for performing the read.
1102 * @param fd the file descriptor of the open file to read from.
1103 * @param iov the iov structure to read data into
1104 * @param iovcnt the number of items that iov includes
1105 * @param offset the offset in the file to read from. If this value is negative, the
1106 * function reads from the current offset of the file descriptor.
1107 * @returns the number of bytes read into buf, or a negative error code on failure.
1108 */
1109int ceph_preadv(struct ceph_mount_info *cmount, int fd, const struct iovec *iov, int iovcnt,
1110 int64_t offset);
1111
1112/**
1113 * Write data to a file.
1114 *
1115 * @param cmount the ceph mount handle to use for performing the write.
1116 * @param fd the file descriptor of the open file to write to
1117 * @param buf the bytes to write to the file
1118 * @param size the size of the buf array
1119 * @param offset the offset of the file write into. If this value is negative, the
1120 * function writes to the current offset of the file descriptor.
1121 * @returns the number of bytes written, or a negative error code
1122 */
1123int ceph_write(struct ceph_mount_info *cmount, int fd, const char *buf, int64_t size,
1124 int64_t offset);
1125
1126/**
1127 * Write data to a file.
1128 *
1129 * @param cmount the ceph mount handle to use for performing the write.
1130 * @param fd the file descriptor of the open file to write to
1131 * @param iov the iov structure to read data into
1132 * @param iovcnt the number of items that iov includes
1133 * @param offset the offset of the file write into. If this value is negative, the
1134 * function writes to the current offset of the file descriptor.
1135 * @returns the number of bytes written, or a negative error code
1136 */
1137int ceph_pwritev(struct ceph_mount_info *cmount, int fd, const struct iovec *iov, int iovcnt,
1138 int64_t offset);
1139
1140/**
1141 * Truncate a file to the given size.
1142 *
1143 * @param cmount the ceph mount handle to use for performing the ftruncate.
1144 * @param fd the file descriptor of the file to truncate
1145 * @param size the new size of the file
1146 * @returns 0 on success or a negative error code on failure.
1147 */
1148int ceph_ftruncate(struct ceph_mount_info *cmount, int fd, int64_t size);
1149
1150/**
1151 * Synchronize an open file to persistent media.
1152 *
1153 * @param cmount the ceph mount handle to use for performing the fsync.
1154 * @param fd the file descriptor of the file to sync.
1155 * @param syncdataonly a boolean whether to synchronize metadata and data (0)
1156 * or just data (1).
1157 * @return 0 on success or a negative error code on failure.
1158 */
1159int ceph_fsync(struct ceph_mount_info *cmount, int fd, int syncdataonly);
1160
1161/**
1162 * Preallocate or release disk space for the file for the byte range.
1163 *
1164 * @param cmount the ceph mount handle to use for performing the fallocate.
1165 * @param fd the file descriptor of the file to fallocate.
1166 * @param mode the flags determines the operation to be performed on the given range.
1167 * default operation (0) allocate and initialize to zero the file in the byte range,
1168 * and the file size will be changed if offset + length is greater than
1169 * the file size. if the FALLOC_FL_KEEP_SIZE flag is specified in the mode,
1170 * the file size will not be changed. if the FALLOC_FL_PUNCH_HOLE flag is
1171 * specified in the mode, the operation is deallocate space and zero the byte range.
1172 * @param offset the byte range starting.
1173 * @param length the length of the range.
1174 * @return 0 on success or a negative error code on failure.
1175 */
1176int ceph_fallocate(struct ceph_mount_info *cmount, int fd, int mode,
1177 int64_t offset, int64_t length);
1178
11fdf7f2
TL
1179/**
1180 * Enable/disable lazyio for the file.
1181 *
1182 * @param cmount the ceph mount handle to use for performing the fsync.
1183 * @param fd the file descriptor of the file to sync.
1184 * @param enable a boolean to enable lazyio or disable lazyio.
1185 * @returns 0 on success or a negative error code on failure.
1186 */
1187int ceph_lazyio(struct ceph_mount_info *cmount, int fd, int enable);
1188
92f5a8d4
TL
1189
1190/**
1191 * Flushes the write buffer for the file thereby propogating the buffered write to the file.
1192 *
1193 * @param cmount the ceph mount handle to use for performing the fsync.
1194 * @param fd the file descriptor of the file to sync.
1195 * @param offset a boolean to enable lazyio or disable lazyio.
1196 * @returns 0 on success or a negative error code on failure.
1197 */
1198int ceph_lazyio_propagate(struct ceph_mount_info *cmount, int fd, int64_t offset, size_t count);
1199
1200
1201/**
1202 * 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.
1203 *
1204 * @param cmount the ceph mount handle to use for performing the fsync.
1205 * @param fd the file descriptor of the file to sync.
1206 * @param offset a boolean to enable lazyio or disable lazyio.
1207 * @returns 0 on success or a negative error code on failure.
1208 */
1209int ceph_lazyio_synchronize(struct ceph_mount_info *cmount, int fd, int64_t offset, size_t count);
1210
7c673cae
FG
1211/** @} file */
1212
1213/**
1214 * @defgroup libcephfs_h_xattr Extended Attribute manipulation and handling.
1215 * Functions for creating and manipulating extended attributes on files.
1216 *
1217 * @{
1218 */
1219
1220/**
1221 * Get an extended attribute.
1222 *
1223 * @param cmount the ceph mount handle to use for performing the getxattr.
1224 * @param path the path to the file
1225 * @param name the name of the extended attribute to get
1226 * @param value a pre-allocated buffer to hold the xattr's value
1227 * @param size the size of the pre-allocated buffer
1228 * @returns the size of the value or a negative error code on failure.
1229 */
1230int ceph_getxattr(struct ceph_mount_info *cmount, const char *path, const char *name,
1231 void *value, size_t size);
1232
1233/**
1234 * Get an extended attribute.
1235 *
1236 * @param cmount the ceph mount handle to use for performing the getxattr.
1237 * @param fd the open file descriptor referring to the file to get extended attribute from.
1238 * @param name the name of the extended attribute to get
1239 * @param value a pre-allocated buffer to hold the xattr's value
1240 * @param size the size of the pre-allocated buffer
1241 * @returns the size of the value or a negative error code on failure.
1242 */
1243int ceph_fgetxattr(struct ceph_mount_info *cmount, int fd, const char *name,
1244 void *value, size_t size);
1245
1246/**
1247 * Get an extended attribute without following symbolic links. This function is
1248 * identical to ceph_getxattr, but if the path refers to a symbolic link,
1249 * we get the extended attributes of the symlink rather than the attributes
1250 * of the link itself.
1251 *
1252 * @param cmount the ceph mount handle to use for performing the lgetxattr.
1253 * @param path the path to the file
1254 * @param name the name of the extended attribute to get
1255 * @param value a pre-allocated buffer to hold the xattr's value
1256 * @param size the size of the pre-allocated buffer
1257 * @returns the size of the value or a negative error code on failure.
1258 */
1259int ceph_lgetxattr(struct ceph_mount_info *cmount, const char *path, const char *name,
1260 void *value, size_t size);
1261
1262/**
1263 * List the extended attribute keys on a file.
1264 *
1265 * @param cmount the ceph mount handle to use for performing the listxattr.
1266 * @param path the path to the file.
1267 * @param list a buffer to be filled in with the list of extended attributes keys.
1268 * @param size the size of the list buffer.
1269 * @returns the size of the resulting list filled in.
1270 */
1271int ceph_listxattr(struct ceph_mount_info *cmount, const char *path, char *list, size_t size);
1272
1273/**
1274 * List the extended attribute keys on a file.
1275 *
1276 * @param cmount the ceph mount handle to use for performing the listxattr.
1277 * @param fd the open file descriptor referring to the file to list extended attributes on.
1278 * @param list a buffer to be filled in with the list of extended attributes keys.
1279 * @param size the size of the list buffer.
1280 * @returns the size of the resulting list filled in.
1281 */
1282int ceph_flistxattr(struct ceph_mount_info *cmount, int fd, char *list, size_t size);
1283
1284/**
1285 * Get the list of extended attribute keys on a file, but do not follow symbolic links.
1286 *
1287 * @param cmount the ceph mount handle to use for performing the llistxattr.
1288 * @param path the path to the file.
1289 * @param list a buffer to be filled in with the list of extended attributes keys.
1290 * @param size the size of the list buffer.
1291 * @returns the size of the resulting list filled in.
1292 */
1293int ceph_llistxattr(struct ceph_mount_info *cmount, const char *path, char *list, size_t size);
1294
1295/**
1296 * Remove an extended attribute from a file.
1297 *
1298 * @param cmount the ceph mount handle to use for performing the removexattr.
1299 * @param path the path to the file.
1300 * @param name the name of the extended attribute to remove.
1301 * @returns 0 on success or a negative error code on failure.
1302 */
1303int ceph_removexattr(struct ceph_mount_info *cmount, const char *path, const char *name);
1304
1305/**
1306 * Remove an extended attribute from a file.
1307 *
1308 * @param cmount the ceph mount handle to use for performing the removexattr.
1309 * @param fd the open file descriptor referring to the file to remove extended attribute from.
1310 * @param name the name of the extended attribute to remove.
1311 * @returns 0 on success or a negative error code on failure.
1312 */
1313int ceph_fremovexattr(struct ceph_mount_info *cmount, int fd, const char *name);
1314
1315/**
1316 * Remove the extended attribute from a file, do not follow symbolic links.
1317 *
1318 * @param cmount the ceph mount handle to use for performing the lremovexattr.
1319 * @param path the path to the file.
1320 * @param name the name of the extended attribute to remove.
1321 * @returns 0 on success or a negative error code on failure.
1322 */
1323int ceph_lremovexattr(struct ceph_mount_info *cmount, const char *path, const char *name);
1324
1325/**
1326 * Set an extended attribute on a file.
1327 *
1328 * @param cmount the ceph mount handle to use for performing the setxattr.
1329 * @param path the path to the file.
1330 * @param name the name of the extended attribute to set.
1331 * @param value the bytes of the extended attribute value
1332 * @param size the size of the extended attribute value
1333 * @param flags the flags can be:
1334 * CEPH_XATTR_CREATE: create the extended attribute. Must not exist.
1335 * CEPH_XATTR_REPLACE: replace the extended attribute, Must already exist.
1336 * @returns 0 on success or a negative error code on failure.
1337 */
1338int ceph_setxattr(struct ceph_mount_info *cmount, const char *path, const char *name,
1339 const void *value, size_t size, int flags);
1340
1341/**
1342 * Set an extended attribute on a file.
1343 *
1344 * @param cmount the ceph mount handle to use for performing the setxattr.
1345 * @param fd the open file descriptor referring to the file to set extended attribute on.
1346 * @param name the name of the extended attribute to set.
1347 * @param value the bytes of the extended attribute value
1348 * @param size the size of the extended attribute value
1349 * @param flags the flags can be:
1350 * CEPH_XATTR_CREATE: create the extended attribute. Must not exist.
1351 * CEPH_XATTR_REPLACE: replace the extended attribute, Must already exist.
1352 * @returns 0 on success or a negative error code on failure.
1353 */
1354int ceph_fsetxattr(struct ceph_mount_info *cmount, int fd, const char *name,
1355 const void *value, size_t size, int flags);
1356
1357/**
1358 * Set an extended attribute on a file, do not follow symbolic links.
1359 *
1360 * @param cmount the ceph mount handle to use for performing the lsetxattr.
1361 * @param path the path to the file.
1362 * @param name the name of the extended attribute to set.
1363 * @param value the bytes of the extended attribute value
1364 * @param size the size of the extended attribute value
1365 * @param flags the flags can be:
1366 * CEPH_XATTR_CREATE: create the extended attribute. Must not exist.
1367 * CEPH_XATTR_REPLACE: replace the extended attribute, Must already exist.
1368 * @returns 0 on success or a negative error code on failure.
1369 */
1370int ceph_lsetxattr(struct ceph_mount_info *cmount, const char *path, const char *name,
1371 const void *value, size_t size, int flags);
1372
1373/** @} xattr */
1374
1375/**
1376 * @defgroup libcephfs_h_filelayout Control File Layout.
1377 * Functions for setting and getting the file layout of existing files.
1378 *
1379 * @{
1380 */
1381
1382/**
1383 * Get the file striping unit from an open file descriptor.
1384 *
1385 * @param cmount the ceph mount handle to use.
1386 * @param fh the open file descriptor referring to the file to get the striping unit of.
1387 * @returns the striping unit of the file or a negative error code on failure.
1388 */
1389int ceph_get_file_stripe_unit(struct ceph_mount_info *cmount, int fh);
1390
1391/**
1392 * Get the file striping unit.
1393 *
1394 * @param cmount the ceph mount handle to use.
1395 * @param path the path of the file/directory get the striping unit of.
1396 * @returns the striping unit of the file or a negative error code on failure.
1397 */
1398int ceph_get_path_stripe_unit(struct ceph_mount_info *cmount, const char *path);
1399
1400/**
1401 * Get the file striping count from an open file descriptor.
1402 *
1403 * @param cmount the ceph mount handle to use.
1404 * @param fh the open file descriptor referring to the file to get the striping count of.
1405 * @returns the striping count of the file or a negative error code on failure.
1406 */
1407int ceph_get_file_stripe_count(struct ceph_mount_info *cmount, int fh);
1408
1409/**
1410 * Get the file striping count.
1411 *
1412 * @param cmount the ceph mount handle to use.
1413 * @param path the path of the file/directory get the striping count of.
1414 * @returns the striping count of the file or a negative error code on failure.
1415 */
1416int ceph_get_path_stripe_count(struct ceph_mount_info *cmount, const char *path);
1417
1418/**
1419 * Get the file object size from an open file descriptor.
1420 *
1421 * @param cmount the ceph mount handle to use.
1422 * @param fh the open file descriptor referring to the file to get the object size of.
1423 * @returns the object size of the file or a negative error code on failure.
1424 */
1425int ceph_get_file_object_size(struct ceph_mount_info *cmount, int fh);
1426
1427/**
1428 * Get the file object size.
1429 *
1430 * @param cmount the ceph mount handle to use.
1431 * @param path the path of the file/directory get the object size of.
1432 * @returns the object size of the file or a negative error code on failure.
1433 */
1434int ceph_get_path_object_size(struct ceph_mount_info *cmount, const char *path);
1435
1436/**
1437 * Get the file pool information from an open file descriptor.
1438 *
1439 * @param cmount the ceph mount handle to use.
1440 * @param fh the open file descriptor referring to the file to get the pool information of.
1441 * @returns the ceph pool id that the file is in
1442 */
1443int ceph_get_file_pool(struct ceph_mount_info *cmount, int fh);
1444
1445/**
1446 * Get the file pool information.
1447 *
1448 * @param cmount the ceph mount handle to use.
1449 * @param path the path of the file/directory get the pool information of.
1450 * @returns the ceph pool id that the file is in
1451 */
1452int ceph_get_path_pool(struct ceph_mount_info *cmount, const char *path);
1453
1454/**
1455 * Get the name of the pool a opened file is stored in,
1456 *
1457 * Write the name of the file's pool to the buffer. If buflen is 0, return
1458 * a suggested length for the buffer.
1459 *
1460 * @param cmount the ceph mount handle to use.
1461 * @param fh the open file descriptor referring to the file
1462 * @param buf buffer to store the name in
1463 * @param buflen size of the buffer
1464 * @returns length in bytes of the pool name, or -ERANGE if the buffer is not large enough.
1465 */
1466int ceph_get_file_pool_name(struct ceph_mount_info *cmount, int fh, char *buf, size_t buflen);
1467
1468/**
1469 * get the name of a pool by id
1470 *
1471 * Given a pool's numeric identifier, get the pool's alphanumeric name.
1472 *
1473 * @param cmount the ceph mount handle to use
1474 * @param pool the numeric pool id
1475 * @param buf buffer to sore the name in
1476 * @param buflen size of the buffer
1477 * @returns length in bytes of the pool name, or -ERANGE if the buffer is not large enough
1478 */
1479int ceph_get_pool_name(struct ceph_mount_info *cmount, int pool, char *buf, size_t buflen);
1480
1481/**
1482 * Get the name of the pool a file is stored in
1483 *
1484 * Write the name of the file's pool to the buffer. If buflen is 0, return
1485 * a suggested length for the buffer.
1486 *
1487 * @param cmount the ceph mount handle to use.
1488 * @param path the path of the file/directory
1489 * @param buf buffer to store the name in
1490 * @param buflen size of the buffer
1491 * @returns length in bytes of the pool name, or -ERANGE if the buffer is not large enough.
1492 */
1493int ceph_get_path_pool_name(struct ceph_mount_info *cmount, const char *path, char *buf, size_t buflen);
1494
d2e6a577
FG
1495/**
1496 * Get the default pool name of cephfs
1497 * Write the name of the default pool to the buffer. If buflen is 0, return
1498 * a suggested length for the buffer.
1499 * @param cmount the ceph mount handle to use.
1500 * @param buf buffer to store the name in
1501 * @param buflen size of the buffer
1502 * @returns length in bytes of the pool name, or -ERANGE if the buffer is not large enough.
1503 */
1504int ceph_get_default_data_pool_name(struct ceph_mount_info *cmount, char *buf, size_t buflen);
1505
7c673cae
FG
1506/**
1507 * Get the file layout from an open file descriptor.
1508 *
1509 * @param cmount the ceph mount handle to use.
1510 * @param fh the open file descriptor referring to the file to get the layout of.
1511 * @param stripe_unit where to store the striping unit of the file
1512 * @param stripe_count where to store the striping count of the file
1513 * @param object_size where to store the object size of the file
1514 * @param pg_pool where to store the ceph pool id that the file is in
1515 * @returns 0 on success or a negative error code on failure.
1516 */
1517int ceph_get_file_layout(struct ceph_mount_info *cmount, int fh, int *stripe_unit, int *stripe_count, int *object_size, int *pg_pool);
1518
1519/**
1520 * Get the file layout.
1521 *
1522 * @param cmount the ceph mount handle to use.
1523 * @param path the path of the file/directory get the layout of.
1524 * @param stripe_unit where to store the striping unit of the file
1525 * @param stripe_count where to store the striping count of the file
1526 * @param object_size where to store the object size of the file
1527 * @param pg_pool where to store the ceph pool id that the file is in
1528 * @returns 0 on success or a negative error code on failure.
1529 */
1530int ceph_get_path_layout(struct ceph_mount_info *cmount, const char *path, int *stripe_unit, int *stripe_count, int *object_size, int *pg_pool);
1531
1532/**
1533 * Get the file replication information from an open file descriptor.
1534 *
1535 * @param cmount the ceph mount handle to use.
1536 * @param fh the open file descriptor referring to the file to get the replication information of.
1537 * @returns the replication factor of the file.
1538 */
1539int ceph_get_file_replication(struct ceph_mount_info *cmount, int fh);
1540
1541/**
1542 * Get the file replication information.
1543 *
1544 * @param cmount the ceph mount handle to use.
1545 * @param path the path of the file/directory get the replication information of.
1546 * @returns the replication factor of the file.
1547 */
1548int ceph_get_path_replication(struct ceph_mount_info *cmount, const char *path);
1549
1550/**
1551 * Get the id of the named pool.
1552 *
1553 * @param cmount the ceph mount handle to use.
1554 * @param pool_name the name of the pool.
1555 * @returns the pool id, or a negative error code on failure.
1556 */
1557int ceph_get_pool_id(struct ceph_mount_info *cmount, const char *pool_name);
1558
1559/**
1560 * Get the pool replication factor.
1561 *
1562 * @param cmount the ceph mount handle to use.
1563 * @param pool_id the pool id to look up
1564 * @returns the replication factor, or a negative error code on failure.
1565 */
1566int ceph_get_pool_replication(struct ceph_mount_info *cmount, int pool_id);
1567
1568/**
1569 * Get the OSD address where the primary copy of a file stripe is located.
1570 *
1571 * @param cmount the ceph mount handle to use.
1572 * @param fd the open file descriptor referring to the file to get the striping unit of.
1573 * @param offset the offset into the file to specify the stripe. The offset can be
1574 * anywhere within the stripe unit.
1575 * @param addr the address of the OSD holding that stripe
1576 * @param naddr the capacity of the address passed in.
1577 * @returns the size of the addressed filled into the @e addr parameter, or a negative
1578 * error code on failure.
1579 */
1580int ceph_get_file_stripe_address(struct ceph_mount_info *cmount, int fd, int64_t offset,
1581 struct sockaddr_storage *addr, int naddr);
1582
1583/**
1584 * Get the list of OSDs where the objects containing a file offset are located.
1585 *
1586 * @param cmount the ceph mount handle to use.
1587 * @param fd the open file descriptor referring to the file.
1588 * @param offset the offset within the file.
1589 * @param length return the number of bytes between the offset and the end of
1590 * the stripe unit (optional).
1591 * @param osds an integer array to hold the OSD ids.
1592 * @param nosds the size of the integer array.
1593 * @returns the number of items stored in the output array, or -ERANGE if the
1594 * array is not large enough.
1595 */
1596int ceph_get_file_extent_osds(struct ceph_mount_info *cmount, int fd,
1597 int64_t offset, int64_t *length, int *osds, int nosds);
1598
1599/**
1600 * Get the fully qualified CRUSH location of an OSD.
1601 *
1602 * Returns (type, name) string pairs for each device in the CRUSH bucket
1603 * hierarchy starting from the given osd to the root. Each pair element is
1604 * separated by a NULL character.
1605 *
1606 * @param cmount the ceph mount handle to use.
1607 * @param osd the OSD id.
1608 * @param path buffer to store location.
1609 * @param len size of buffer.
1610 * @returns the amount of bytes written into the buffer, or -ERANGE if the
1611 * array is not large enough.
1612 */
1613int ceph_get_osd_crush_location(struct ceph_mount_info *cmount,
1614 int osd, char *path, size_t len);
1615
1616/**
1617 * Get the network address of an OSD.
1618 *
1619 * @param cmount the ceph mount handle.
1620 * @param osd the OSD id.
1621 * @param addr the OSD network address.
1622 * @returns zero on success, other returns a negative error code.
1623 */
1624int ceph_get_osd_addr(struct ceph_mount_info *cmount, int osd,
1625 struct sockaddr_storage *addr);
1626
1627/**
1628 * Get the file layout stripe unit granularity.
1629 * @param cmount the ceph mount handle.
1630 * @returns the stripe unit granularity or a negative error code on failure.
1631 */
1632int ceph_get_stripe_unit_granularity(struct ceph_mount_info *cmount);
1633
1634/** @} filelayout */
1635
1636/**
1637 * No longer available. Do not use.
1638 * These functions will return -EOPNOTSUPP.
1639 */
1640int ceph_set_default_file_stripe_unit(struct ceph_mount_info *cmount, int stripe);
1641int ceph_set_default_file_stripe_count(struct ceph_mount_info *cmount, int count);
1642int ceph_set_default_object_size(struct ceph_mount_info *cmount, int size);
1643int ceph_set_default_preferred_pg(struct ceph_mount_info *cmount, int osd);
1644int ceph_set_default_file_replication(struct ceph_mount_info *cmount, int replication);
1645
1646/**
1647 * Read from local replicas when possible.
1648 *
1649 * @param cmount the ceph mount handle to use.
1650 * @param val a boolean to set (1) or clear (0) the option to favor local objects
1651 * for reads.
1652 * @returns 0
1653 */
1654int ceph_localize_reads(struct ceph_mount_info *cmount, int val);
1655
1656/**
1657 * Get the osd id of the local osd (if any)
1658 *
1659 * @param cmount the ceph mount handle to use.
1660 * @returns the osd (if any) local to the node where this call is made, otherwise
1661 * -1 is returned.
1662 */
1663int ceph_get_local_osd(struct ceph_mount_info *cmount);
1664
1665/** @} default_filelayout */
1666
1667/**
1668 * Get the capabilities currently issued to the client.
1669 *
1670 * @param cmount the ceph mount handle to use.
1671 * @param fd the file descriptor to get issued
1672 * @returns the current capabilities issued to this client
1673 * for the open file
1674 */
1675int ceph_debug_get_fd_caps(struct ceph_mount_info *cmount, int fd);
1676
1677/**
1678 * Get the capabilities currently issued to the client.
1679 *
1680 * @param cmount the ceph mount handle to use.
1681 * @param path the path to the file
1682 * @returns the current capabilities issued to this client
1683 * for the file
1684 */
1685int ceph_debug_get_file_caps(struct ceph_mount_info *cmount, const char *path);
1686
1687/* Low Level */
1688struct Inode *ceph_ll_get_inode(struct ceph_mount_info *cmount,
1689 vinodeno_t vino);
f67539c2
TL
1690
1691int ceph_ll_lookup_vino(struct ceph_mount_info *cmount, vinodeno_t vino,
1692 Inode **inode);
1693
7c673cae
FG
1694int ceph_ll_lookup_inode(
1695 struct ceph_mount_info *cmount,
1696 struct inodeno_t ino,
1697 Inode **inode);
1698
1699/**
1700 * Get the root inode of FS. Increase counter of references for root Inode. You must call ceph_ll_forget for it!
1701 *
1702 * @param cmount the ceph mount handle to use.
1703 * @param parent pointer to pointer to Inode struct. Pointer to root inode will be returned
1704 * @returns 0 if all good
1705 */
1706int ceph_ll_lookup_root(struct ceph_mount_info *cmount,
1707 Inode **parent);
1708int ceph_ll_lookup(struct ceph_mount_info *cmount, Inode *parent,
1709 const char *name, Inode **out, struct ceph_statx *stx,
1710 unsigned want, unsigned flags, const UserPerm *perms);
1711int ceph_ll_put(struct ceph_mount_info *cmount, struct Inode *in);
1712int ceph_ll_forget(struct ceph_mount_info *cmount, struct Inode *in,
1713 int count);
1714int ceph_ll_walk(struct ceph_mount_info *cmount, const char* name, Inode **i,
1715 struct ceph_statx *stx, unsigned int want, unsigned int flags,
1716 const UserPerm *perms);
1717int ceph_ll_getattr(struct ceph_mount_info *cmount, struct Inode *in,
1718 struct ceph_statx *stx, unsigned int want, unsigned int flags,
1719 const UserPerm *perms);
1720int ceph_ll_setattr(struct ceph_mount_info *cmount, struct Inode *in,
1721 struct ceph_statx *stx, int mask, const UserPerm *perms);
1722int ceph_ll_open(struct ceph_mount_info *cmount, struct Inode *in, int flags,
1723 struct Fh **fh, const UserPerm *perms);
1724off_t ceph_ll_lseek(struct ceph_mount_info *cmount, struct Fh* filehandle,
1725 off_t offset, int whence);
1726int ceph_ll_read(struct ceph_mount_info *cmount, struct Fh* filehandle,
1727 int64_t off, uint64_t len, char* buf);
1728int ceph_ll_fsync(struct ceph_mount_info *cmount, struct Fh *fh,
1729 int syncdataonly);
28e407b8
AA
1730int ceph_ll_sync_inode(struct ceph_mount_info *cmount, struct Inode *in,
1731 int syncdataonly);
11fdf7f2
TL
1732int ceph_ll_fallocate(struct ceph_mount_info *cmount, struct Fh *fh,
1733 int mode, int64_t offset, int64_t length);
7c673cae
FG
1734int ceph_ll_write(struct ceph_mount_info *cmount, struct Fh* filehandle,
1735 int64_t off, uint64_t len, const char *data);
1736int64_t ceph_ll_readv(struct ceph_mount_info *cmount, struct Fh *fh,
1737 const struct iovec *iov, int iovcnt, int64_t off);
1738int64_t ceph_ll_writev(struct ceph_mount_info *cmount, struct Fh *fh,
1739 const struct iovec *iov, int iovcnt, int64_t off);
1740int ceph_ll_close(struct ceph_mount_info *cmount, struct Fh* filehandle);
1741int ceph_ll_iclose(struct ceph_mount_info *cmount, struct Inode *in, int mode);
1742/**
1743 * Get xattr value by xattr name.
1744 *
1745 * @param cmount the ceph mount handle to use.
1746 * @param in file handle
1747 * @param name name of attribute
1748 * @param value pointer to begin buffer
1749 * @param size buffer size
1750 * @param perms pointer to UserPerms object
1751 * @returns size of returned buffer. Negative number in error case
1752 */
1753int ceph_ll_getxattr(struct ceph_mount_info *cmount, struct Inode *in,
1754 const char *name, void *value, size_t size,
1755 const UserPerm *perms);
1756int ceph_ll_setxattr(struct ceph_mount_info *cmount, struct Inode *in,
1757 const char *name, const void *value, size_t size,
1758 int flags, const UserPerm *perms);
1759int ceph_ll_listxattr(struct ceph_mount_info *cmount, struct Inode *in,
1760 char *list, size_t buf_size, size_t *list_size,
1761 const UserPerm *perms);
1762int ceph_ll_removexattr(struct ceph_mount_info *cmount, struct Inode *in,
1763 const char *name, const UserPerm *perms);
1764int ceph_ll_create(struct ceph_mount_info *cmount, Inode *parent,
1765 const char *name, mode_t mode, int oflags, Inode **outp,
1766 Fh **fhp, struct ceph_statx *stx, unsigned want,
1767 unsigned lflags, const UserPerm *perms);
1768int ceph_ll_mknod(struct ceph_mount_info *cmount, Inode *parent,
1769 const char *name, mode_t mode, dev_t rdev, Inode **out,
1770 struct ceph_statx *stx, unsigned want, unsigned flags,
1771 const UserPerm *perms);
1772int ceph_ll_mkdir(struct ceph_mount_info *cmount, Inode *parent,
1773 const char *name, mode_t mode, Inode **out,
1774 struct ceph_statx *stx, unsigned want,
1775 unsigned flags, const UserPerm *perms);
1776int ceph_ll_link(struct ceph_mount_info *cmount, struct Inode *in,
1777 struct Inode *newparent, const char *name,
1778 const UserPerm *perms);
1779int ceph_ll_opendir(struct ceph_mount_info *cmount, struct Inode *in,
1780 struct ceph_dir_result **dirpp, const UserPerm *perms);
1781int ceph_ll_releasedir(struct ceph_mount_info *cmount,
1782 struct ceph_dir_result* dir);
1783int ceph_ll_rename(struct ceph_mount_info *cmount, struct Inode *parent,
1784 const char *name, struct Inode *newparent,
1785 const char *newname, const UserPerm *perms);
1786int ceph_ll_unlink(struct ceph_mount_info *cmount, struct Inode *in,
1787 const char *name, const UserPerm *perms);
1788int ceph_ll_statfs(struct ceph_mount_info *cmount, struct Inode *in,
1789 struct statvfs *stbuf);
1790int ceph_ll_readlink(struct ceph_mount_info *cmount, struct Inode *in,
1791 char *buf, size_t bufsize, const UserPerm *perms);
1792int ceph_ll_symlink(struct ceph_mount_info *cmount,
1793 Inode *in, const char *name, const char *value,
1794 Inode **out, struct ceph_statx *stx,
1795 unsigned want, unsigned flags,
1796 const UserPerm *perms);
1797int ceph_ll_rmdir(struct ceph_mount_info *cmount, struct Inode *in,
1798 const char *name, const UserPerm *perms);
1799uint32_t ceph_ll_stripe_unit(struct ceph_mount_info *cmount,
1800 struct Inode *in);
1801uint32_t ceph_ll_file_layout(struct ceph_mount_info *cmount,
1802 struct Inode *in,
1803 struct ceph_file_layout *layout);
1804uint64_t ceph_ll_snap_seq(struct ceph_mount_info *cmount,
1805 struct Inode *in);
1806int ceph_ll_get_stripe_osd(struct ceph_mount_info *cmount,
1807 struct Inode *in,
1808 uint64_t blockno,
1809 struct ceph_file_layout* layout);
1810int ceph_ll_num_osds(struct ceph_mount_info *cmount);
1811int ceph_ll_osdaddr(struct ceph_mount_info *cmount,
1812 int osd, uint32_t *addr);
1813uint64_t ceph_ll_get_internal_offset(struct ceph_mount_info *cmount,
1814 struct Inode *in, uint64_t blockno);
1815int ceph_ll_read_block(struct ceph_mount_info *cmount,
1816 struct Inode *in, uint64_t blockid,
1817 char* bl, uint64_t offset, uint64_t length,
1818 struct ceph_file_layout* layout);
1819int ceph_ll_write_block(struct ceph_mount_info *cmount,
1820 struct Inode *in, uint64_t blockid,
1821 char* buf, uint64_t offset,
1822 uint64_t length, struct ceph_file_layout* layout,
1823 uint64_t snapseq, uint32_t sync);
1824int ceph_ll_commit_blocks(struct ceph_mount_info *cmount,
1825 struct Inode *in, uint64_t offset, uint64_t range);
1826
1827
1828int ceph_ll_getlk(struct ceph_mount_info *cmount,
1829 Fh *fh, struct flock *fl, uint64_t owner);
1830int ceph_ll_setlk(struct ceph_mount_info *cmount,
1831 Fh *fh, struct flock *fl, uint64_t owner, int sleep);
1832
11fdf7f2
TL
1833int ceph_ll_lazyio(struct ceph_mount_info *cmount, Fh *fh, int enable);
1834
b32b8144
FG
1835/*
1836 * Delegation support
1837 *
1838 * Delegations are way for an application to request exclusive or
1839 * semi-exclusive access to an Inode. The client requests the delegation and
1840 * if it's successful it can reliably cache file data and metadata until the
1841 * delegation is recalled.
1842 *
1843 * Recalls are issued via a callback function, provided by the application.
1844 * Callback functions should act something like signal handlers. You want to
1845 * do as little as possible in the callback. Any major work should be deferred
1846 * in some fashion as it's difficult to predict the context in which this
1847 * function will be called.
1848 *
1849 * Once the delegation has been recalled, the application should return it as
1850 * soon as possible. The application has client_deleg_timeout seconds to
1851 * return it, after which the cmount structure is forcibly unmounted and
1852 * further calls into it fail.
1853 *
1854 * The application can set the client_deleg_timeout config option to suit its
1855 * needs, but it should take care to choose a value that allows it to avoid
1856 * forcible eviction from the cluster in the event of an application bug.
1857 */
b32b8144
FG
1858
1859/* Commands for manipulating delegation state */
1860#ifndef CEPH_DELEGATION_NONE
1861# define CEPH_DELEGATION_NONE 0
1862# define CEPH_DELEGATION_RD 1
1863# define CEPH_DELEGATION_WR 2
1864#endif
1865
1866/**
1867 * Get the amount of time that the client has to return caps
1868 * @param cmount the ceph mount handle to use.
1869 *
f67539c2 1870 * In the event that a client does not return its caps, the MDS may blocklist
b32b8144
FG
1871 * it after this timeout. Applications should check this value and ensure
1872 * that they set the delegation timeout to a value lower than this.
1873 *
1874 * This call returns the cap return timeout (in seconds) for this cmount, or
1875 * zero if it's not mounted.
1876 */
1877uint32_t ceph_get_cap_return_timeout(struct ceph_mount_info *cmount);
1878
1879/**
1880 * Set the delegation timeout for the mount (thereby enabling delegations)
1881 * @param cmount the ceph mount handle to use.
1882 * @param timeout the delegation timeout (in seconds)
1883 *
f67539c2 1884 * Since the client could end up blocklisted if it doesn't return delegations
b32b8144
FG
1885 * in time, we mandate that any application wanting to use delegations
1886 * explicitly set the timeout beforehand. Until this call is done on the
1887 * mount, attempts to set a delegation will return -ETIME.
1888 *
1889 * Once a delegation is recalled, if it is not returned in this amount of
1890 * time, the cmount will be forcibly unmounted and further access attempts
1891 * will fail (usually with -ENOTCONN errors).
1892 *
1893 * This value is further vetted against the cap return timeout, and this call
1894 * can fail with -EINVAL if the timeout value is too long. Delegations can be
1895 * disabled again by setting the timeout to 0.
1896 */
1897int ceph_set_deleg_timeout(struct ceph_mount_info *cmount, uint32_t timeout);
1898
1899/**
1900 * Request a delegation on an open Fh
1901 * @param cmount the ceph mount handle to use.
1902 * @param fh file handle
1903 * @param cmd CEPH_DELEGATION_* command
1904 * @param cb callback function for recalling delegation
1905 * @param priv opaque token passed back during recalls
1906 *
1907 * Returns 0 if the delegation was granted, -EAGAIN if there was a conflict
1908 * and other error codes if there is a fatal error of some sort (e.g. -ENOMEM,
1909 * -ETIME)
1910 */
1911int ceph_ll_delegation(struct ceph_mount_info *cmount, Fh *fh,
1912 unsigned int cmd, ceph_deleg_cb_t cb, void *priv);
11fdf7f2
TL
1913
1914mode_t ceph_umask(struct ceph_mount_info *cmount, mode_t mode);
1915
1916/* state reclaim */
1917#define CEPH_RECLAIM_RESET 1
1918
1919/**
1920 * Set ceph client uuid
1921 * @param cmount the ceph mount handle to use.
1922 * @param uuid the uuid to set
1923 *
1924 * Must be called before mount.
1925 */
1926void ceph_set_uuid(struct ceph_mount_info *cmount, const char *uuid);
1927
1928/**
1929 * Set ceph client session timeout
1930 * @param cmount the ceph mount handle to use.
1931 * @param timeout the timeout to set
1932 *
1933 * Must be called before mount.
1934 */
1935void ceph_set_session_timeout(struct ceph_mount_info *cmount, unsigned timeout);
1936
1937/**
1938 * Start to reclaim states of other client
1939 * @param cmount the ceph mount handle to use.
1940 * @param uuid uuid of client whose states need to be reclaimed
1941 * @param flags flags that control how states get reclaimed
1942 *
1943 * Returns 0 success, -EOPNOTSUPP if mds does not support the operation,
1944 * -ENOENT if CEPH_RECLAIM_RESET is specified and there is no client
1945 * with the given uuid, -ENOTRECOVERABLE in all other error cases.
1946 */
1947int ceph_start_reclaim(struct ceph_mount_info *cmount,
1948 const char *uuid, unsigned flags);
1949
1950/**
1951 * finish reclaiming states of other client (
1952 * @param cmount the ceph mount handle to use.
1953 */
1954void ceph_finish_reclaim(struct ceph_mount_info *cmount);
1955
e306af50
TL
1956/**
1957 * Register a set of callbacks to be used with this cmount
1958 * @param cmount the ceph mount handle on which the cb's should be registerd
1959 * @param args callback arguments to register with the cmount
1960 *
1961 * Any fields set to NULL will be ignored. There currently is no way to
1962 * unregister these callbacks, so this is a one-way change.
1963 */
1964void ceph_ll_register_callbacks(struct ceph_mount_info *cmount,
1965 struct ceph_client_callback_args *args);
f67539c2
TL
1966
1967/**
1968 * Get snapshot info
1969 *
1970 * @param cmount the ceph mount handle to use for making the directory.
1971 * @param path the path of the snapshot. This must be either an
1972 * absolute path or a relative path off of the current working directory.
1973 * @returns 0 on success or a negative return code on error.
1974 */
1975int ceph_get_snap_info(struct ceph_mount_info *cmount,
1976 const char *path, struct snap_info *snap_info);
1977
1978/**
1979 * Free snapshot info buffers
1980 *
1981 * @param snap_info snapshot info struct (fetched via call to ceph_get_snap_info()).
1982 */
1983void ceph_free_snap_info_buffer(struct snap_info *snap_info);
7c673cae
FG
1984#ifdef __cplusplus
1985}
1986#endif
1987
1988#endif