Whamcloud - gitweb
LU-13906 build: Fix %{name}-osd-ldiskfs-mount
[fs/lustre-release.git] / lustre / include / lustre / lustreapi.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  */
31
32 #ifndef _LUSTREAPI_H_
33 #define _LUSTREAPI_H_
34
35 /** \defgroup llapi llapi
36  *
37  * @{
38  */
39
40 #include <glob.h>
41 #include <stdarg.h>
42 #include <stdint.h>
43 #include <time.h>
44 #include <unistd.h>
45 #include <sys/types.h>
46 #include <linux/lustre/lustre_user.h>
47
48 #if defined(__cplusplus)
49 extern "C" {
50 #endif
51
52 #ifndef LL_MAXQUOTAS
53 #define LL_MAXQUOTAS 3
54 #endif
55
56 #ifndef SEL_UNIT_SIZE
57 #define SEL_UNIT_SIZE 1024llu
58 #endif
59
60 #ifndef LOV_PATTERN_DEFAULT
61 #define LOV_PATTERN_DEFAULT     0xffffffff
62 #endif
63
64 #ifndef fallthrough
65 #define fallthrough do {} while (0)  /* fallthrough */
66 #endif
67
68 typedef struct statx lstatx_t;
69
70 #define lustre_fid struct lu_fid
71
72 /*
73  * BUILD_BUG_ON() is Compile-time check which verifies correctness at
74  * compile-time rather than runtime. If "cond" is true, (1 - 2*!!(cond))
75  * will be a negative value, which will cause the compiler to complain.
76  *
77  */
78 #ifndef BUILD_BUG_ON
79 #define BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2*!!(cond)]))
80 #endif
81
82 /* Currently external applications can access this but in the
83  * future this will no longer be exposed for the user. Instead
84  * if you want to know if the library is initialized just call
85  * llapi_liblustreapi_initialized() which is now available. */
86 extern bool liblustreapi_initialized;
87
88 typedef void (*llapi_cb_t)(char *obd_type_name, char *obd_name, char *obd_uuid,
89                            void *args);
90
91 /* lustreapi message severity level */
92 enum llapi_message_level {
93         LLAPI_MSG_OFF    = 0,
94         LLAPI_MSG_FATAL  = 1,
95         LLAPI_MSG_ERROR  = 2,
96         LLAPI_MSG_WARN   = 3,
97         LLAPI_MSG_NORMAL = 4,
98         LLAPI_MSG_INFO   = 5,
99         LLAPI_MSG_DEBUG  = 6,
100         LLAPI_MSG_MAX
101 };
102
103 typedef void (*llapi_log_callback_t)(enum llapi_message_level level, int err,
104                                      const char *fmt, va_list ap);
105
106 static inline bool llapi_liblustreapi_initialized(void)
107 {
108         return liblustreapi_initialized;
109 }
110
111 /* the bottom three bits reserved for llapi_message_level */
112 #define LLAPI_MSG_MASK          0x00000007
113 #define LLAPI_MSG_NO_ERRNO      0x00000010
114
115 static inline const char *llapi_msg_level2str(enum llapi_message_level level)
116 {
117         static const char *levels[LLAPI_MSG_MAX] = {"OFF", "FATAL", "ERROR",
118                                                     "WARNING", "NORMAL",
119                                                     "INFO", "DEBUG"};
120
121         if (level >= LLAPI_MSG_MAX)
122                 return NULL;
123
124         return levels[level];
125 }
126
127 void llapi_msg_set_level(int level);
128 int llapi_msg_get_level(void);
129 llapi_log_callback_t llapi_error_callback_set(llapi_log_callback_t cb);
130 llapi_log_callback_t llapi_info_callback_set(llapi_log_callback_t cb);
131
132 void llapi_error(enum llapi_message_level level, int err, const char *fmt, ...)
133         __attribute__((__format__(__printf__, 3, 4)));
134 #define llapi_err_noerrno(level, fmt, a...)                     \
135         llapi_error((level) | LLAPI_MSG_NO_ERRNO, 0, fmt, ## a)
136 void llapi_printf(enum llapi_message_level level, const char *fmt, ...)
137         __attribute__((__format__(__printf__, 2, 3)));
138
139 struct llapi_stripe_param {
140         unsigned long long      lsp_stripe_size;
141         char                    *lsp_pool;
142         int                     lsp_stripe_offset;
143         int                     lsp_stripe_pattern;
144         /* Number of stripes. Size of lsp_osts[] if lsp_specific is true.*/
145         int                     lsp_stripe_count;
146         bool                    lsp_is_specific;
147         bool                    lsp_is_create;
148         __u8                    lsp_max_inherit;
149         __u8                    lsp_max_inherit_rr;
150         __u32                   lsp_osts[0];
151 };
152
153 #define lsp_tgts        lsp_osts
154
155 enum {
156         LLAPI_MIGRATION_NONBLOCK        = 0x0001,
157         LLAPI_MIGRATION_MIRROR          = 0x0002,
158         LLAPI_MIGRATION_NONDIRECT       = 0x0004,
159         LLAPI_MIGRATION_VERBOSE         = 0x0008,
160 };
161
162 __u32 llapi_pattern_to_lov(uint64_t pattern);
163
164 int llapi_file_open_param(const char *name, int flags, mode_t mode,
165                           const struct llapi_stripe_param *param);
166 int llapi_file_is_encrypted(int fd);
167 int llapi_file_create_foreign(const char *name, mode_t mode, __u32 type,
168                               __u32 flags, char *foreign_lov);
169 int llapi_file_create(const char *name, unsigned long long stripe_size,
170                       int stripe_offset, int stripe_count, int stripe_pattern);
171 int llapi_file_open(const char *name, int flags, int mode,
172                     unsigned long long stripe_size, int stripe_offset,
173                     int stripe_count, int stripe_pattern);
174 int llapi_file_create_pool(const char *name, unsigned long long stripe_size,
175                            int stripe_offset, int stripe_count,
176                            int stripe_pattern, char *pool_name);
177 int llapi_file_open_pool(const char *name, int flags, int mode,
178                          unsigned long long stripe_size, int stripe_offset,
179                          int stripe_count, int stripe_pattern, char *pool_name);
180 int llapi_poollist(const char *name);
181 int llapi_get_poolbuf(const char *name, char **buf,
182                       char ***poolist, int *poolcount);
183 int llapi_get_poollist(const char *name, char **poollist, int list_size,
184                        char *buffer, int buffer_size);
185 int llapi_get_poolmembers(const char *poolname, char **members, int list_size,
186                           char *buffer, int buffer_size);
187 int llapi_file_get_stripe(const char *path, struct lov_user_md *lum);
188 int llapi_file_lookup(int dirfd, const char *name);
189 void llapi_set_command_name(const char *cmd);
190 void llapi_clear_command_name(void);
191
192 enum llapi_layout_verbose  {
193         VERBOSE_STRIPE_COUNT    =      0x1,
194         VERBOSE_STRIPE_SIZE     =      0x2,
195         VERBOSE_STRIPE_OFFSET   =      0x4,
196         VERBOSE_POOL            =      0x8,
197         VERBOSE_DETAIL          =     0x10,
198         VERBOSE_OBJID           =     0x20,
199         VERBOSE_GENERATION      =     0x40,
200         VERBOSE_MDTINDEX        =     0x80,
201         VERBOSE_PATTERN         =    0x100,
202         VERBOSE_COMP_COUNT      =    0x200,
203         VERBOSE_COMP_FLAGS      =    0x400,
204         VERBOSE_COMP_START      =    0x800,
205         VERBOSE_COMP_END        =   0x1000,
206         VERBOSE_COMP_ID         =   0x2000,
207         VERBOSE_DFID            =   0x4000,
208         VERBOSE_HASH_TYPE       =   0x8000,
209         VERBOSE_MIRROR_COUNT    =  0x10000,
210         VERBOSE_MIRROR_ID       =  0x20000,
211         VERBOSE_EXT_SIZE        =  0x40000,
212         VERBOSE_INHERIT         =  0x80000,
213         VERBOSE_INHERIT_RR      = 0x100000,
214         VERBOSE_DEFAULT         = VERBOSE_STRIPE_COUNT | VERBOSE_STRIPE_SIZE |
215                                   VERBOSE_STRIPE_OFFSET | VERBOSE_POOL |
216                                   VERBOSE_OBJID | VERBOSE_GENERATION |
217                                   VERBOSE_PATTERN | VERBOSE_HASH_TYPE |
218                                   VERBOSE_COMP_COUNT | VERBOSE_COMP_FLAGS |
219                                   VERBOSE_COMP_START | VERBOSE_COMP_END |
220                                   VERBOSE_COMP_ID | VERBOSE_MIRROR_COUNT |
221                                   VERBOSE_MIRROR_ID | VERBOSE_EXT_SIZE |
222                                   VERBOSE_INHERIT | VERBOSE_INHERIT_RR
223 };
224 /* Compatibility with original names */
225 #define VERBOSE_SIZE    VERBOSE_STRIPE_SIZE
226 #define VERBOSE_COUNT   VERBOSE_STRIPE_COUNT
227 #define VERBOSE_OFFSET  VERBOSE_STRIPE_OFFSET
228 #define VERBOSE_LAYOUT  VERBOSE_PATTERN
229
230 enum {
231         NEWERXY_ATIME = 0,      /* neweraY */
232         NEWERXY_MTIME = 1,      /* newermY */
233         NEWERXY_CTIME = 2,      /* newercY */
234         NEWERXY_BTIME = 3,      /* newerbY | newerBY */
235         NEWERXY_MAX,
236 };
237
238 enum lfs_find_perm {
239         LFS_FIND_PERM_EXACT = -2,
240         LFS_FIND_PERM_ANY   = -1,
241         LFS_FIND_PERM_OFF   =  0,
242         LFS_FIND_PERM_ALL   =  1,
243 };
244
245 struct find_param {
246         unsigned int             fp_max_depth;
247         dev_t                    fp_dev;
248         mode_t                   fp_type; /* S_IFIFO,... */
249         uid_t                    fp_uid;
250         gid_t                    fp_gid;
251         mode_t                   fp_perm;
252         time_t                   fp_atime;
253         time_t                   fp_mtime;
254         time_t                   fp_ctime;
255         /* {a,m,c,b}sign cannot be bitfields due to using pointers to
256          * access them during argument parsing. */
257         int                      fp_asign;
258         int                      fp_msign;
259         int                      fp_csign;
260         /* these need to be signed values */
261         int                      fp_size_sign:2,
262                                  fp_stripe_size_sign:2,
263                                  fp_stripe_count_sign:2,
264                                  fp_comp_start_sign:2,
265                                  fp_comp_end_sign:2,
266                                  fp_comp_count_sign:2,
267                                  fp_mirror_count_sign:2,
268                                  fp_mirror_index_sign:2,
269                                  fp_mirror_id_sign:2,
270                                  fp_mdt_count_sign:2,
271                                  fp_blocks_sign:2,
272                                  fp_ext_size_sign:2,
273                                  fp_perm_sign:2,
274                                  fp_unused2_sign:2, /* Once used we must add  */
275                                  fp_unused3_sign:2, /* a separate flag field  */
276                                  fp_unused4_sign:2; /* at end of the struct.  */
277         unsigned long long       fp_size;
278         unsigned long long       fp_size_units;
279
280         unsigned long long       fp_zero_end:1,
281                                  fp_recursive:1,
282                                  fp_exclude_pattern:1,
283                                  fp_exclude_type:1,
284                                  fp_exclude_obd:1,
285                                  fp_exclude_mdt:1,
286                                  fp_exclude_gid:1,
287                                  fp_exclude_uid:1,
288                                  fp_check_gid:1,
289                                  fp_check_uid:1,
290                                  fp_check_pool:1,       /* LOV pool name */
291                                  fp_check_size:1,       /* file size */
292                                  fp_exclude_pool:1,
293                                  fp_exclude_size:1,
294                                  fp_exclude_atime:1,
295                                  fp_exclude_mtime:1,
296                                  fp_exclude_ctime:1,
297                                  fp_get_lmv:1,  /* get MDT list from LMV */
298                                  fp_raw:1,      /* do not fill in defaults */
299                                  fp_check_stripe_size:1, /* LOV stripe size */
300                                  fp_exclude_stripe_size:1,
301                                  fp_check_stripe_count:1, /* LOV stripe count */
302                                  fp_exclude_stripe_count:1,
303                                  fp_check_layout:1,
304                                  fp_exclude_layout:1,
305                                  fp_get_default_lmv:1, /* Get default LMV */
306                                  fp_migrate:1,
307                                  fp_check_projid:1,
308                                  fp_exclude_projid:1,
309                                  fp_check_comp_count:1,
310                                  fp_exclude_comp_count:1,
311                                  fp_check_mirror_count:1,
312                                  fp_exclude_mirror_count:1,
313                                  fp_check_comp_flags:1,
314                                  fp_check_mirror_state:1,
315                                  fp_check_comp_start:1,
316                                  fp_exclude_comp_start:1,
317                                  fp_check_comp_end:1,
318                                  fp_exclude_comp_end:1,
319                                  fp_check_comp_id:1,
320                                  fp_exclude_comp_id:1,
321                                  fp_check_mirror_id:1,
322                                  fp_exclude_mirror_id:1,
323                                  fp_check_mirror_index:1,
324                                  fp_exclude_mirror_index:1,
325                                  fp_check_mdt_count:1,
326                                  fp_exclude_mdt_count:1,
327                                  fp_check_hash_flag:1,
328                                  fp_exclude_hash_type:1,
329                                  fp_yaml:1,     /* output layout in YAML */
330                                  fp_check_blocks:1,
331                                  fp_exclude_blocks:1,
332                                  fp_check_foreign:1,
333                                  fp_exclude_foreign:1,
334                                  fp_check_ext_size:1, /* extension size */
335                                  fp_exclude_ext_size:1,
336                                  fp_lazy:1,
337                                  fp_newerxy:1,
338                                  fp_exclude_btime:1,
339                                  fp_exclude_perm:1,
340                                  fp_unused_bit4:1, /* Once all unused fields  */
341                                  fp_unused_bit5:1, /* are used we need to add */
342                                  fp_unused_bit6:1, /* a separate flag field at*/
343                                  fp_unused_bit7:1; /* the end of the struct.  */
344
345         enum llapi_layout_verbose fp_verbose;
346         int                      fp_quiet;
347
348         /* regular expression */
349         char                    *fp_pattern;
350
351         struct  obd_uuid        *fp_obd_uuid;
352         int                      fp_num_obds;
353         int                      fp_num_alloc_obds;
354         int                      fp_obd_index;
355         int                     *fp_obd_indexes;
356
357         struct  obd_uuid        *fp_mdt_uuid;
358         int                      fp_num_mdts;
359         int                      fp_num_alloc_mdts;
360         int                      fp_mdt_index;
361         int                     *fp_mdt_indexes;
362         int                      fp_file_mdt_index;
363
364         size_t                   fp_lum_size;
365         struct  lov_user_mds_data *fp_lmd;
366
367         char                     fp_poolname[LOV_MAXPOOLNAME + 1];
368
369         __u32                    fp_lmv_stripe_count;
370         struct lmv_user_md      *fp_lmv_md;
371
372         unsigned long long       fp_stripe_size;
373         unsigned long long       fp_stripe_size_units;
374         unsigned long long       fp_stripe_count;
375         __u32                    fp_layout;
376
377         __u32                    fp_comp_count;
378         __u32                    fp_mirror_count;
379         __u32                    fp_comp_flags;
380         __u32                    fp_comp_neg_flags;
381         __u16                    fp_mirror_state;
382         __u16                    fp_mirror_neg_state;
383         __u32                    fp_comp_id;
384         __u16                    fp_mirror_id;
385         __u16                    fp_mirror_index;
386         unsigned long long       fp_comp_start;
387         unsigned long long       fp_comp_start_units;
388         unsigned long long       fp_comp_end;
389         unsigned long long       fp_comp_end_units;
390         unsigned long long       fp_mdt_count;
391         unsigned int             fp_projid;
392         unsigned long long       fp_blocks;
393         unsigned long long       fp_blocks_units;
394
395         unsigned long            fp_got_uuids:1,
396                                  fp_obds_printed:1;
397         unsigned int             fp_depth;
398         unsigned int             fp_hash_type;
399         unsigned int             fp_time_margin; /* time margin in seconds */
400         __u32                    fp_foreign_type;
401         unsigned long long       fp_ext_size;
402         unsigned long long       fp_ext_size_units;
403
404         /*
405          * fp_newery[NEWERXY_MAX][0]: --newerXY reference
406          * fp_newery[NEWERXY_MAX][1]: ! -- newerXY reference
407          */
408         time_t                   fp_newery[NEWERXY_MAX][2];
409
410         time_t                   fp_btime;
411         int                      fp_bsign;
412         unsigned int             fp_hash_inflags;
413         unsigned int             fp_hash_exflags;
414         /* Print all information (lfs find only) */
415         char                     *fp_format_printf_str;
416 };
417
418 int llapi_ostlist(char *path, struct find_param *param);
419 int llapi_uuid_match(char *real_uuid, char *search_uuid);
420 int llapi_getstripe(char *path, struct find_param *param);
421 int llapi_find(char *path, struct find_param *param);
422
423 int llapi_file_fget_mdtidx(int fd, int *mdtidx);
424 int llapi_dir_set_default_lmv(const char *name,
425                               const struct llapi_stripe_param *param);
426 int llapi_dir_set_default_lmv_stripe(const char *name, int stripe_offset,
427                                      int stripe_count, int stripe_pattern,
428                                      const char *pool_name);
429 int llapi_dir_create(const char *name, mode_t mode,
430                      const struct llapi_stripe_param *param);
431 int llapi_dir_create_foreign(const char *name, mode_t mode, __u32 type,
432                              __u32 flags, const char *value);
433 int llapi_dir_create_pool(const char *name, int flags, int stripe_offset,
434                           int stripe_count, int stripe_pattern,
435                           const char *poolname);
436 int llapi_direntry_remove(char *dname);
437 int llapi_unlink_foreign(char *dname);
438
439 int llapi_obd_fstatfs(int fd, __u32 type, __u32 index,
440                       struct obd_statfs *stat_buf, struct obd_uuid *uuid_buf);
441 int llapi_obd_statfs(char *path, __u32 type, __u32 index,
442                      struct obd_statfs *stat_buf, struct obd_uuid *uuid_buf);
443 int llapi_ping(char *obd_type, char *obd_name);
444 int llapi_target_check(int num_types, char **obd_types, char *dir);
445 int llapi_file_get_lov_uuid(const char *path, struct obd_uuid *lov_uuid);
446 int llapi_file_get_lmv_uuid(const char *path, struct obd_uuid *lmv_uuid);
447 int llapi_file_fget_lov_uuid(int fd, struct obd_uuid *lov_uuid);
448 int llapi_lov_get_uuids(int fd, struct obd_uuid *uuidp, int *ost_count);
449 int llapi_lmv_get_uuids(int fd, struct obd_uuid *uuidp, int *mdt_count);
450 int llapi_is_lustre_mnttype(const char *type);
451 int llapi_search_tgt(const char *fsname, const char *poolname,
452                      const char *tgtname, bool is_mdt);
453 int llapi_search_mdt(const char *fsname, const char *poolname,
454                      const char *mdtname);
455 int llapi_search_ost(const char *fsname, const char *poolname,
456                      const char *ostname);
457 int llapi_get_obd_count(char *mnt, int *count, int is_mdt);
458 int llapi_parse_size(const char *optarg, unsigned long long *size,
459                      unsigned long long *size_units, int bytes_spec);
460 int llapi_search_mounts(const char *pathname, int index, char *mntdir,
461                         char *fsname);
462 int llapi_search_fsname(const char *pathname, char *fsname);
463 int llapi_get_fsname_instance(const char *path, char *fsname, size_t fsname_len,
464                               char *instance, size_t instance_len);
465 int llapi_get_instance(const char *path, char *instance, size_t instance_len);
466 int llapi_get_fsname(const char *path, char *fsname, size_t fsname_len);
467 int llapi_getname(const char *path, char *name, size_t namelen);
468 int llapi_search_fileset(const char *pathname, char *fileset);
469
470 int llapi_search_rootpath(char *pathname, const char *fsname);
471 int llapi_nodemap_exists(const char *name);
472 int llapi_migrate_mdt(char *path, struct find_param *param);
473 int llapi_mv(char *path, struct find_param *param);
474
475 struct mntent;
476
477 #define HAVE_LLAPI_IS_LUSTRE_MNT
478 int llapi_is_lustre_mnt(struct mntent *mnt);
479 int llapi_quotactl(char *mnt, struct if_quotactl *qctl);
480 int llapi_target_iterate(int type_num, char **obd_type, void *args,
481                          llapi_cb_t cb);
482 int llapi_get_connect_flags(const char *mnt, __u64 *flags);
483 int llapi_cp(int argc, char *argv[]);
484 int llapi_ls(int argc, char *argv[]);
485 int llapi_fid_parse(const char *fidstr, struct lu_fid *fid, char **endptr);
486 int llapi_fid2path_at(int mnt_fd, const struct lu_fid *fid, char *path,
487                       int pathlen, long long *recno, int *linkno);
488 int llapi_fid2path(const char *device, const char *fidstr, char *path,
489                    int pathlen, long long *recno, int *linkno);
490 int llapi_path2fid(const char *path, struct lu_fid *fid);
491 int llapi_get_mdt_index_by_fid(int fd, const struct lu_fid *fid,
492                                int *mdt_index);
493 int llapi_get_lum_file(const char *path, __u64 *valid, lstatx_t *statx,
494                        struct lov_user_md *lum, size_t lumsize);
495 int llapi_get_lum_dir(const char *path, __u64 *valid, lstatx_t *statx,
496                       struct lov_user_md *lum, size_t lumsize);
497 int llapi_get_lum_file_fd(int dir_fd, const char *fname, __u64 *valid,
498                           lstatx_t *statx, struct lov_user_md *lum,
499                           size_t lumsize);
500 int llapi_get_lum_dir_fd(int dir_fd, __u64 *valid, lstatx_t *statx,
501                          struct lov_user_md *lum, size_t lumsize);
502
503 int llapi_fd2fid(int fd, struct lu_fid *fid);
504 /* get FID of parent dir + the related name of entry in this parent dir */
505 int llapi_path2parent(const char *path, unsigned int linkno,
506                       struct lu_fid *parent_fid, char *name, size_t name_size);
507 int llapi_fd2parent(int fd, unsigned int linkno, struct lu_fid *parent_fid,
508                     char *name, size_t name_size);
509 int llapi_rmfid(const char *path, struct fid_array *fa);
510 int llapi_chomp_string(char *buf);
511 int llapi_open_by_fid(const char *dir, const struct lu_fid *fid,
512                       int open_flags);
513 int llapi_get_version_string(char *version, unsigned int version_size);
514 /* llapi_get_version() is deprecated, use llapi_get_version_string() instead */
515 int llapi_get_version(char *buffer, int buffer_size, char **version)
516         __attribute__((deprecated));
517 int llapi_get_data_version(int fd, __u64 *data_version, __u64 flags);
518 int llapi_file_flush(int fd);
519 extern int llapi_get_ost_layout_version(int fd, __u32 *layout_version);
520 int llapi_hsm_state_get_fd(int fd, struct hsm_user_state *hus);
521 int llapi_hsm_state_get(const char *path, struct hsm_user_state *hus);
522 int llapi_hsm_state_set_fd(int fd, __u64 setmask, __u64 clearmask,
523                            __u32 archive_id);
524 int llapi_hsm_state_set(const char *path, __u64 setmask, __u64 clearmask,
525                         __u32 archive_id);
526 int llapi_hsm_register_event_fifo(const char *path);
527 int llapi_hsm_unregister_event_fifo(const char *path);
528 void llapi_hsm_log_error(enum llapi_message_level level, int _rc,
529                          const char *fmt, va_list args);
530
531 int llapi_get_agent_uuid(char *path, char *buf, size_t bufsize);
532 int llapi_create_volatile_idx(const char *directory, int mdt_idx,
533                               int open_flags);
534 int llapi_create_volatile_param(const char *directory, int mdt_idx,
535                                 int open_flags, mode_t mode,
536                                 const struct llapi_stripe_param *stripe_param);
537
538 static inline int llapi_create_volatile(char *directory, int open_flags)
539 {
540         return llapi_create_volatile_idx(directory, -1, open_flags);
541 }
542
543
544 int llapi_fswap_layouts_grouplock(int fd1, int fd2, __u64 dv1, __u64 dv2,
545                                   int gid, __u64 flags);
546 int llapi_fswap_layouts(int fd1, int fd2, __u64 dv1, __u64 dv2, __u64 flags);
547 int llapi_swap_layouts(const char *path1, const char *path2, __u64 dv1,
548                        __u64 dv2, __u64 flags);
549
550 /* Changelog interface.  priv is private state, managed internally by these
551  * functions */
552
553 /* Records received are in extended format now, though most of them are still
554  * written in disk in changelog_rec format (to save space and time), it's
555  * converted to extended format in the lustre api to ease changelog analysis.
556  */
557 #define HAVE_CHANGELOG_EXTEND_REC 1
558
559 int llapi_changelog_start(void **priv, enum changelog_send_flag flags,
560                           const char *mdtname, long long startrec);
561 int llapi_changelog_fini(void **priv);
562 int llapi_changelog_recv(void *priv, struct changelog_rec **rech);
563 int llapi_changelog_in_buf(void *priv);
564 int llapi_changelog_free(struct changelog_rec **rech);
565 int llapi_changelog_get_fd(void *priv);
566 /* Allow records up to endrec to be destroyed; requires registered id. */
567 int llapi_changelog_clear(const char *mdtname, const char *idstr,
568                           long long endrec);
569 extern int llapi_changelog_set_xflags(void *priv,
570                                     enum changelog_send_extra_flag extra_flags);
571
572 /* HSM copytool interface.
573  * priv is private state, managed internally by these functions
574  */
575 struct hsm_copytool_private;
576 struct hsm_copyaction_private;
577
578 int llapi_hsm_copytool_register(struct hsm_copytool_private **priv,
579                                 const char *mnt, int archive_count,
580                                 int *archives, int rfd_flags);
581 int llapi_hsm_copytool_unregister(struct hsm_copytool_private **priv);
582 int llapi_hsm_copytool_get_fd(struct hsm_copytool_private *ct);
583 int llapi_hsm_copytool_recv(struct hsm_copytool_private *priv,
584                             struct hsm_action_list **hal, int *msgsize);
585 int llapi_hsm_action_begin(struct hsm_copyaction_private **phcp,
586                            const struct hsm_copytool_private *ct,
587                            const struct hsm_action_item *hai,
588                            int restore_mdt_index, int restore_open_flags,
589                            bool is_error);
590 int llapi_hsm_action_end(struct hsm_copyaction_private **phcp,
591                          const struct hsm_extent *he, int hp_flags, int errval);
592 int llapi_hsm_action_progress(struct hsm_copyaction_private *hcp,
593                               const struct hsm_extent *he, __u64 total,
594                               int hp_flags);
595 int llapi_hsm_action_get_dfid(const struct hsm_copyaction_private *hcp,
596                               struct lu_fid *fid);
597 int llapi_hsm_action_get_fd(const struct hsm_copyaction_private *hcp);
598 int llapi_hsm_import(const char *dst, int archive, const struct stat *st,
599                      unsigned long long stripe_size, int stripe_offset,
600                      int stripe_count, int stripe_pattern, char *pool_name,
601                      struct lu_fid *newfid);
602
603 /* HSM user interface */
604 struct hsm_user_request *llapi_hsm_user_request_alloc(int itemcount,
605                                                       int data_len);
606 int llapi_hsm_request(const char *path, const struct hsm_user_request *request);
607 int llapi_hsm_current_action(const char *path, struct hsm_current_action *hca);
608
609 /* JSON handling */
610 enum llapi_json_types {
611         LLAPI_JSON_INTEGER = 1,
612         LLAPI_JSON_BIGNUM,
613         LLAPI_JSON_REAL,
614         LLAPI_JSON_STRING
615 };
616
617 struct llapi_json_item {
618         char                    *lji_key;
619         __u32                   lji_type;
620         union {
621                 int             lji_integer;
622                 __u64           lji_u64;
623                 double          lji_real;
624                 char            *lji_string;
625         };
626         struct llapi_json_item  *lji_next;
627 };
628
629 struct llapi_json_item_list {
630         int                     ljil_item_count;
631         struct llapi_json_item  *ljil_items;
632 };
633
634 int llapi_json_init_list(struct llapi_json_item_list **item_list);
635 int llapi_json_destroy_list(struct llapi_json_item_list **item_list);
636 int llapi_json_add_item(struct llapi_json_item_list **item_list, char *key,
637                         __u32 type, void *val);
638 int llapi_json_write_list(struct llapi_json_item_list **item_list, FILE *fp);
639
640 /* File lease */
641 int llapi_lease_acquire(int fd, enum ll_lease_mode mode);
642 int llapi_lease_release(int fd);
643 int llapi_lease_set(int fd, const struct ll_ioc_lease *data);
644 int llapi_lease_check(int fd);
645 int llapi_lease_get(int fd, int mode); /* obsoleted */
646 int llapi_lease_put(int fd); /* obsoleted */
647
648 /* Group lock */
649 int llapi_group_lock(int fd, int gid);
650 int llapi_group_unlock(int fd, int gid);
651 int llapi_group_lock64(int fd, __u64 gid);
652 int llapi_group_unlock64(int fd, __u64 gid);
653
654 bool llapi_file_is_sparse(int fd);
655 off_t llapi_data_seek(int src_fd, off_t offset, size_t *length);
656 int llapi_hole_punch(int fd, off_t start, size_t length);
657
658 /* Ladvise */
659 int llapi_ladvise(int fd, unsigned long long flags, int num_advise,
660                   struct llapi_lu_ladvise *ladvise);
661
662 /* PCC */
663 int llapi_pcc_attach(const char *path, __u32 id, enum lu_pcc_type type);
664 int llapi_pcc_attach_fid(const char *mntpath, const struct lu_fid *fid,
665                          __u32 id, enum lu_pcc_type type);
666 int llapi_pcc_attach_fid_str(const char *mntpath, const char *fidstr,
667                              __u32 id, enum lu_pcc_type type);
668 int llapi_pcc_detach_fd(int fd, __u32 option);
669 int llapi_pcc_detach_fid(const char *mntpath, const struct lu_fid *fid,
670                          __u32 option);
671 int llapi_pcc_detach_fid_str(const char *mntpath, const char *fidstr,
672                              __u32 option);
673 int llapi_pcc_detach_file(const char *path, __u32 option);
674 int llapi_pcc_state_get_fd(int fd, struct lu_pcc_state *state);
675 int llapi_pcc_state_get(const char *path, struct lu_pcc_state *state);
676 int llapi_pccdev_set(const char *mntpath, const char *cmd);
677 int llapi_pccdev_get(const char *mntpath);
678 /** @} llapi */
679
680 /* llapi_layout user interface */
681
682 /**
683  * An array element storing component info to be resynced during mirror
684  * resynchronization.
685  */
686 struct llapi_resync_comp {
687         uint64_t lrc_start;
688         uint64_t lrc_end;
689         uint32_t lrc_mirror_id;
690         uint32_t lrc_id;        /* component id */
691         bool lrc_synced;
692 };
693
694 /** Opaque data type abstracting the layout of a Lustre file. */
695 struct llapi_layout;
696
697 int llapi_mirror_truncate(int fd, unsigned int id, off_t length);
698 ssize_t llapi_mirror_write(int fd, unsigned int id, const void *buf,
699                            size_t count, off_t pos);
700 int llapi_mirror_find(struct llapi_layout *layout, uint64_t file_start,
701                       uint64_t file_end, uint64_t *endp);
702 int llapi_layout_get_last_init_comp(struct llapi_layout *layout);
703 int llapi_layout_mirror_inherit(struct llapi_layout *f_layout,
704                                 struct llapi_layout *m_layout);
705 int llapi_mirror_find_stale(struct llapi_layout *layout,
706                 struct llapi_resync_comp *comp, size_t comp_size,
707                 __u16 *mirror_ids, int ids_nr);
708 int llapi_mirror_resync_many(int fd, struct llapi_layout *layout,
709                              struct llapi_resync_comp *comp_array,
710                              int comp_size,  uint64_t start, uint64_t end);
711 /*
712  * Flags to control how layouts are retrieved.
713  */
714
715 enum llapi_layout_get_flags {
716         /** Replace non-specified values with expected inherited values. */
717         LLAPI_LAYOUT_GET_EXPECTED       = 0x0001,
718         /** Use a temporary buffer to swab and return xattrs. */
719         LLAPI_LAYOUT_GET_COPY           = 0x0002,
720         /** Verify xattr contains sane layout values. */
721         LLAPI_LAYOUT_GET_CHECK          = 0x0004,
722 };
723 /* compatibility macros for old interfaces */
724 #define LAYOUT_GET_EXPECTED     LLAPI_LAYOUT_GET_EXPECTED
725 #define LLAPI_LXF_COPY          LLAPI_LAYOUT_GET_COPY
726 #define LLAPI_LXF_CHECK         LLAPI_LAYOUT_GET_CHECK
727
728 /**
729  * Return a pointer to a newly-allocated opaque data structure containing
730  * the layout for the file at \a path.  The pointer should be freed with
731  * llapi_layout_free() when it is no longer needed. Failure is indicated
732  * by a NULL return value and an appropriate error code stored in errno.
733  */
734 struct llapi_layout *llapi_layout_get_by_path(const char *path,
735                                              enum llapi_layout_get_flags flags);
736
737 /**
738  * Return a pointer to a newly-allocated opaque data type containing the
739  * layout for the file referenced by open file descriptor \a fd.  The
740  * pointer should be freed with llapi_layout_free() when it is no longer
741  * needed. Failure is indicated by a NULL return value and an
742  * appropriate error code stored in errno.
743  */
744 struct llapi_layout *llapi_layout_get_by_fd(int fd,
745                                             enum llapi_layout_get_flags flags);
746
747 /**
748  * Return a pointer to a newly-allocated opaque data type containing the
749  * layout for the file associated with Lustre file identifier
750  * \a fid.  The string \a path must name a path within the
751  * filesystem that contains the file being looked up, such as the
752  * filesystem root.  The returned pointer should be freed with
753  * llapi_layout_free() when it is no longer needed.  Failure is
754  * indicated with a NULL return value and an appropriate error code
755  * stored in errno.
756  */
757 struct llapi_layout *llapi_layout_get_by_fid(const char *path,
758                                              const struct lu_fid *fid,
759                                              enum llapi_layout_get_flags flags);
760
761 /**
762  * Return a pointer to a newly-allocated opaque data type containing the
763  * layout for the file associated with extended attribute \a lov_xattr.  The
764  * length of the extended attribute is \a lov_xattr_size. The \a lov_xattr
765  * should be raw xattr without being swapped, since this function will swap it
766  * properly. Thus, \a lov_xattr will be modified during the process. If the
767  * \a LLAPI_LXF_CHECK flag of \a flags is set, this function will check whether
768  * the objects count in lum is consistent with the stripe count in lum. This
769  * check only apply to regular file, so \a LLAPI_LAYOUT_GET_CHECK flag should
770  * be cleared if the xattr belongs to a directory. If the flag \a
771  * LLAPI_LAYOUT_GET_COPY is set, this function will use a temporary buffer for
772  * byte swapping when necessary, leaving \a lov_xattr untouched. Otherwise, the
773  * byte swapping will be done to the \a lov_xattr buffer directly.  The returned
774  * pointer should be freed with llapi_layout_free() when it is no longer
775  * needed.  Failure is  * indicated with a NULL return value and an appropriate
776  * error code stored in errno.
777  */
778 struct llapi_layout *llapi_layout_get_by_xattr(void *lov_xattr,
779                                              ssize_t lov_xattr_size,
780                                              enum llapi_layout_get_flags flags);
781
782 /**
783  * Allocate a new layout. Use this when creating a new file with
784  * llapi_layout_file_create().
785  */
786 struct llapi_layout *llapi_layout_alloc(void);
787
788 /**
789  * Free memory allocated for \a layout.
790  */
791 void llapi_layout_free(struct llapi_layout *layout);
792
793 /**
794  * llapi_layout_merge() - Merge a composite layout into another one.
795  * @dst_layout: Destination composite layout.
796  * @src_layout: Source composite layout.
797  *
798  * This function copies all of the components from @src_layout and
799  * appends them to @dst_layout.
800  *
801  * Return: 0 on success or -1 on failure.
802  */
803 int llapi_layout_merge(struct llapi_layout **dst_layout,
804                        const struct llapi_layout *src_layout);
805
806 /** Not a valid stripe size, offset, or RAID pattern. */
807 #define LLAPI_LAYOUT_INVALID    0x1000000000000001ULL
808
809 /**
810  * When specified or returned as the value for stripe count,
811  * stripe size, offset, or RAID pattern, the filesystem-wide
812  * default behavior will apply.
813  */
814 #define LLAPI_LAYOUT_DEFAULT    (LLAPI_LAYOUT_INVALID + 1)
815
816 /**
817  * When specified or returned as the value for stripe count, all
818  * available OSTs will be used.
819  */
820 #define LLAPI_LAYOUT_WIDE       (LLAPI_LAYOUT_INVALID + 2)
821
822 /**
823  * When specified as the value for layout pattern, file objects will be
824  * stored using RAID0.  That is, data will be split evenly and without
825  * redundancy across all OSTs in the layout.
826  */
827 #define LLAPI_LAYOUT_RAID0              0ULL
828 #define LLAPI_LAYOUT_MDT                2ULL
829 #define LLAPI_LAYOUT_OVERSTRIPING       4ULL
830
831 /**
832  * The layout includes a specific set of OSTs on which to allocate.
833  */
834 #define LLAPI_LAYOUT_SPECIFIC   0x2000000000000000ULL
835
836 /**
837  * A valid ost index should be less than maximum valid OST index (UINT_MAX).
838  */
839 #define LLAPI_LAYOUT_IDX_MAX    0x00000000FFFFFFFFULL
840
841 /**
842  * Flags to modify how layouts are retrieved.
843  */
844 /******************** Stripe Count ********************/
845
846 /**
847  * Store the stripe count of \a layout in \a count.
848  *
849  * \retval  0 Success
850  * \retval -1 Error with status code in errno.
851  */
852 int llapi_layout_stripe_count_get(const struct llapi_layout *layout,
853                                   uint64_t *count);
854
855 /**
856  * Set the stripe count of \a layout to \a count.
857  *
858  * \retval  0 Success.
859  * \retval -1 Invalid argument, errno set to EINVAL.
860  */
861 int llapi_layout_stripe_count_set(struct llapi_layout *layout, uint64_t count);
862
863 /**
864  * Check if the stripe count \a stripe_count \a is valid.
865  */
866 bool llapi_layout_stripe_count_is_valid(int64_t stripe_count);
867 /******************** Stripe Size ********************/
868
869 /**
870  * Store the stripe size of \a layout in \a size.
871  *
872  * \retval  0 Success.
873  * \retval -1 Invalid argument, errno set to EINVAL.
874  */
875 int llapi_layout_stripe_size_get(const struct llapi_layout *layout,
876                                  uint64_t *size);
877
878 /**
879  * Set the stripe size of \a layout to \a stripe_size.
880  *
881  * \retval  0 Success.
882  * \retval -1 Invalid argument, errno set to EINVAL.
883  */
884 int llapi_layout_stripe_size_set(struct llapi_layout *layout, uint64_t size);
885
886
887 /******************** Extension Size ********************/
888
889 /**
890  * Store the extension size of \a layout in \a size.
891  *
892  * \retval  0 Success.
893  * \retval -1 Invalid argument, errno set to EINVAL.
894  */
895 int llapi_layout_extension_size_get(const struct llapi_layout *layout,
896                                     uint64_t *size);
897
898 /**
899  * Set the extension size of \a layout to \a stripe_size.
900  *
901  * \retval  0 Success.
902  * \retval -1 Invalid argument, errno set to EINVAL.
903  */
904 int llapi_layout_extension_size_set(struct llapi_layout *layout, uint64_t size);
905
906
907 /******************** Stripe Pattern ********************/
908
909 /**
910  * Store the stripe pattern of \a layout in \a pattern.
911  *
912  * \retval 0  Success.
913  * \retval -1 Error with status code in errno.
914  */
915 int llapi_layout_pattern_get(const struct llapi_layout *layout,
916                              uint64_t *pattern);
917
918 /**
919  * Set the stripe pattern of \a layout to \a pattern.
920  *
921  * \retval  0 Success.
922  * \retval -1 Invalid argument, errno set to EINVAL.
923  */
924 int llapi_layout_pattern_set(struct llapi_layout *layout, uint64_t pattern);
925
926 /******************** OST Index ********************/
927
928 /**
929  * Store the index of the OST where stripe number \a stripe_number is stored
930  * in \a index.
931  *
932  * An error return value will result from a NULL layout, if \a
933  * stripe_number is out of range, or if \a layout was not initialized
934  * with llapi_layout_lookup_by{path,fd,fid}().
935  *
936  * \retval  0 Success
937  * \retval -1 Invalid argument, errno set to EINVAL.
938  */
939 int llapi_layout_ost_index_get(const struct llapi_layout *layout,
940                                uint64_t stripe_number, uint64_t *index);
941
942 /**
943  * Set the OST index associated with stripe number \a stripe_number to
944  * \a ost_index.
945  * NB: This is currently supported only for \a stripe_number = 0 and
946  * other usage will return ENOTSUPP in errno.  A NULL \a layout or
947  * out-of-range \a stripe_number will return EINVAL in errno.
948  *
949  * \retval  0 Success.
950  * \retval -1 Error with errno set to non-zero value.
951  */
952 int llapi_layout_ost_index_set(struct llapi_layout *layout, int stripe_number,
953                                uint64_t index);
954
955 /******************** Pool Name ********************/
956
957 /**
958  * Store up to \a pool_name_len characters of the name of the pool of
959  * OSTs associated with \a layout into the buffer pointed to by
960  * \a pool_name.
961  *
962  * The correct calling form is:
963  *
964  *   llapi_layout_pool_name_get(layout, pool_name, sizeof(pool_name));
965  *
966  * A pool defines a set of OSTs from which file objects may be
967  * allocated for a file using \a layout.
968  *
969  * On success, the number of bytes stored is returned, excluding the
970  * terminating '\0' character (zero indicates that \a layout does not
971  * have an associated OST pool).  On error, -1 is returned and errno is
972  * set appropriately. Possible sources of error include a NULL pointer
973  * argument or insufficient space in \a dest to store the pool name,
974  * in which cases errno will be set to EINVAL.
975  *
976  * \retval 0+           The number of bytes stored in \a dest.
977  * \retval -1           Invalid argument, errno set to EINVAL.
978  */
979 int llapi_layout_pool_name_get(const struct llapi_layout *layout,
980                               char *pool_name, size_t pool_name_len);
981
982 /**
983  * Set the name of the pool of OSTs from which file objects will be
984  * allocated to \a pool_name.
985  *
986  * If the pool name uses "fsname.pool" notation to qualify the pool name
987  * with a filesystem name, the "fsname." portion will be silently
988  * discarded before storing the value. No validation that \a pool_name
989  * is an existing non-empty pool in filesystem \a fsname will be
990  * performed.  Such validation can be performed by the application if
991  * desired using the llapi_search_ost() function.  The maximum length of
992  * the stored value is defined by the constant LOV_MAXPOOLNAME.
993  *
994  * \retval  0   Success.
995  * \retval -1   Invalid argument, errno set to EINVAL.
996  */
997 int llapi_layout_pool_name_set(struct llapi_layout *layout,
998                                const char *pool_name);
999
1000 /******************** File Creation ********************/
1001
1002 /**
1003  * Open an existing file at \a path, or create it with the specified
1004  * \a layout and \a mode.
1005  *
1006  * One access mode and zero or more file creation flags and file status
1007  * flags May be bitwise-or'd in \a open_flags (see open(2)).  Return an
1008  * open file descriptor for the file.  If \a layout is non-NULL and
1009  * \a path is not on a Lustre filesystem this function will fail and set
1010  * errno to ENOTTY.
1011  *
1012  * An already existing file may be opened with this function, but
1013  * \a layout and \a mode will not be applied to it.  Callers requiring a
1014  * guarantee that the opened file is created with the specified
1015  * \a layout and \a mode should use llapi_layout_file_create().
1016  *
1017  * A NULL \a layout may be specified, in which case the standard Lustre
1018  * behavior for assigning layouts to newly-created files will apply.
1019  *
1020  * \retval 0+ An open file descriptor.
1021  * \retval -1 Error with status code in errno.
1022  */
1023 int llapi_layout_file_open(const char *path, int open_flags, mode_t mode,
1024                            const struct llapi_layout *layout);
1025
1026 /**
1027  * Create a new file at \a path with the specified \a layout and \a mode.
1028  *
1029  * One access mode and zero or more file creation flags and file status
1030  * flags May be bitwise-or'd in \a open_flags (see open(2)).  Return an
1031  * open file descriptor for the file.  If \a layout is non-NULL and
1032  * \a path is not on a Lustre filesystem this function will fail and set
1033  * errno to ENOTTY.
1034  *
1035  * The function call
1036  *
1037  *   llapi_layout_file_create(path, open_flags, mode, layout)
1038  *
1039  * shall be equivalent to:
1040  *
1041  *   llapi_layout_file_open(path, open_flags|O_CREAT|O_EXCL, mode, layout)
1042  *
1043  * It is an error if \a path specifies an existing file.
1044  *
1045  * A NULL \a layout may be specified, in which the standard Lustre
1046  * behavior for assigning layouts to newly-created files will apply.
1047  *
1048  * \retval 0+ An open file descriptor.
1049  * \retval -1 Error with status code in errno.
1050  */
1051 int llapi_layout_file_create(const char *path, int open_flags, int mode,
1052                              const struct llapi_layout *layout);
1053
1054 /**
1055  * Set flags to the header of component layout.
1056  */
1057 int llapi_layout_flags_set(struct llapi_layout *layout, uint32_t flags);
1058 int llapi_layout_flags_get(struct llapi_layout *layout, uint32_t *flags);
1059 const char *llapi_layout_flags_string(uint32_t flags);
1060 __u16 llapi_layout_string_flags(char *string);
1061
1062 /**
1063  * llapi_layout_mirror_count_get() - Get mirror count from the header of
1064  *                                   a layout.
1065  * @layout: Layout to get mirror count from.
1066  * @count:  Returned mirror count value.
1067  *
1068  * This function gets mirror count from the header of a layout.
1069  *
1070  * Return: 0 on success or -1 on failure.
1071  */
1072 int llapi_layout_mirror_count_get(struct llapi_layout *layout,
1073                                   uint16_t *count);
1074
1075 /**
1076  * llapi_layout_mirror_count_set() - Set mirror count to the header of a layout.
1077  * @layout: Layout to set mirror count in.
1078  * @count:  Mirror count value to be set.
1079  *
1080  * This function sets mirror count to the header of a layout.
1081  *
1082  * Return: 0 on success or -1 on failure.
1083  */
1084 int llapi_layout_mirror_count_set(struct llapi_layout *layout,
1085                                   uint16_t count);
1086
1087 /**
1088  * Fetch the start and end offset of the current layout component.
1089  */
1090 int llapi_layout_comp_extent_get(const struct llapi_layout *layout,
1091                                  uint64_t *start, uint64_t *end);
1092 /**
1093  * Set the extent of current layout component.
1094  */
1095 int llapi_layout_comp_extent_set(struct llapi_layout *layout,
1096                                  uint64_t start, uint64_t end);
1097
1098 /* PFL component flags table */
1099 static const struct comp_flag_name {
1100         enum lov_comp_md_entry_flags cfn_flag;
1101         const char *cfn_name;
1102 } comp_flags_table[] = {
1103         { LCME_FL_INIT,         "init" },
1104         { LCME_FL_STALE,        "stale" },
1105         { LCME_FL_PREF_RW,      "prefer" },
1106         { LCME_FL_OFFLINE,      "offline" },
1107         { LCME_FL_NOSYNC,       "nosync" },
1108         { LCME_FL_EXTENSION,    "extension" },
1109         { LCME_FL_PARITY,       "parity" },
1110 };
1111
1112 /**
1113  * Gets the attribute flags of the current component.
1114  */
1115 int llapi_layout_comp_flags_get(const struct llapi_layout *layout,
1116                                 uint32_t *flags);
1117 /**
1118  * Sets the specified flags of the current component leaving other flags as-is.
1119  */
1120 int llapi_layout_comp_flags_set(struct llapi_layout *layout, uint32_t flags);
1121 /**
1122  * Clears the flags specified in the flags leaving other flags as-is.
1123  */
1124 int llapi_layout_comp_flags_clear(struct llapi_layout *layout, uint32_t flags);
1125 /**
1126  * Fetches the file-unique component ID of the current layout component.
1127  */
1128 int llapi_layout_comp_id_get(const struct llapi_layout *layout, uint32_t *id);
1129 /**
1130  * Fetches the mirror ID of the current layout component.
1131  */
1132 int llapi_layout_mirror_id_get(const struct llapi_layout *layout, uint32_t *id);
1133 /**
1134  * Adds one component to the existing composite or plain layout.
1135  */
1136 int llapi_layout_comp_add(struct llapi_layout *layout);
1137 /**
1138  * Adds a first component of a mirror to the existing composite layout.
1139  */
1140 int llapi_layout_add_first_comp(struct llapi_layout *layout);
1141 /**
1142  * Deletes the current layout component from the composite layout.
1143  */
1144 int llapi_layout_comp_del(struct llapi_layout *layout);
1145
1146 enum llapi_layout_comp_use {
1147         LLAPI_LAYOUT_COMP_USE_FIRST = 1,
1148         LLAPI_LAYOUT_COMP_USE_LAST = 2,
1149         LLAPI_LAYOUT_COMP_USE_NEXT = 3,
1150         LLAPI_LAYOUT_COMP_USE_PREV = 4,
1151 };
1152
1153 /**
1154  * Set the currently active component to the specified component ID.
1155  */
1156 int llapi_layout_comp_use_id(struct llapi_layout *layout, uint32_t id);
1157 /**
1158  * Select the currently active component at the specified position.
1159  */
1160 int llapi_layout_comp_use(struct llapi_layout *layout, uint32_t pos);
1161 /**
1162  * Add layout components to an existing file.
1163  */
1164 int llapi_layout_file_comp_add(const char *path,
1165                                const struct llapi_layout *layout);
1166 /**
1167  * Delete component(s) by the specified component id or flags.
1168  */
1169 int llapi_layout_file_comp_del(const char *path, uint32_t id, uint32_t flags);
1170 /**
1171  * Change flags or other parameters of the component(s) by component ID of an
1172  * existing file. The component to be modified is specified by the
1173  * comp->lcme_id value, which must be an unique component ID. The new
1174  * attributes are passed in by @comp and @valid is used to specify which
1175  * attributes in the component are going to be changed.
1176  */
1177 int llapi_layout_file_comp_set(const char *path, uint32_t *ids, uint32_t *flags,
1178                                size_t count);
1179 /**
1180  * Check if the file layout is composite.
1181  */
1182 bool llapi_layout_is_composite(struct llapi_layout *layout);
1183
1184 enum {
1185         LLAPI_LAYOUT_ITER_CONT = 0,
1186         LLAPI_LAYOUT_ITER_STOP = 1,
1187 };
1188
1189 /**
1190  * Iteration callback function.
1191  *
1192  * \retval LLAPI_LAYOUT_ITER_CONT       Iteration proceeds
1193  * \retval LLAPI_LAYOUT_ITER_STOP       Stop iteration
1194  * \retval < 0                          error code
1195  */
1196 typedef int (*llapi_layout_iter_cb)(struct llapi_layout *layout, void *cbdata);
1197
1198 /**
1199  * Iterate all components in the corresponding layout
1200  */
1201 int llapi_layout_comp_iterate(struct llapi_layout *layout,
1202                               llapi_layout_iter_cb cb, void *cbdata);
1203
1204 /**
1205  * FLR: mirror operation APIs
1206  */
1207 int llapi_mirror_set(int fd, unsigned int id);
1208 int llapi_mirror_clear(int fd);
1209 ssize_t llapi_mirror_read(int fd, unsigned int id,
1210                            void *buf, size_t count, off_t pos);
1211 ssize_t llapi_mirror_copy_many(int fd, __u16 src, __u16 *dst, size_t count);
1212 int llapi_mirror_copy(int fd, unsigned int src, unsigned int dst,
1213                       off_t pos, size_t count);
1214 off_t llapi_mirror_data_seek(int fd, unsigned int id, off_t pos, size_t *size);
1215 int llapi_mirror_punch(int fd, unsigned int id, off_t start, size_t length);
1216
1217 int llapi_heat_get(int fd, struct lu_heat *heat);
1218 int llapi_heat_set(int fd, __u64 flags);
1219
1220 int llapi_layout_sanity(struct llapi_layout *layout, bool incomplete, bool flr);
1221 void llapi_layout_sanity_perror(int error);
1222 int llapi_layout_dom_size(struct llapi_layout *layout, uint64_t *size);
1223
1224 int llapi_param_get_paths(const char *pattern, glob_t *paths);
1225 int llapi_param_get_value(const char *path, char **buf, size_t *buflen);
1226 void llapi_param_paths_free(glob_t *paths);
1227
1228 /** @} llapi */
1229
1230 #if defined(__cplusplus)
1231 }
1232 #endif
1233
1234 #endif