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