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