Whamcloud - gitweb
LU-8998 lustreapi: composite llapi_layout
[fs/lustre-release.git] / lustre / utils / lustreapi_internal.h
1 /*
2  * LGPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * (C) Copyright 2012 Commissariat a l'energie atomique et aux energies
7  *
8  * Copyright (c) 2016, Intel Corporation.
9  *     alternatives
10  *
11  * All rights reserved. This program and the accompanying materials
12  * are made available under the terms of the GNU Lesser General Public License
13  * (LGPL) version 2.1 or (at your discretion) any later version.
14  * (LGPL) version 2.1 accompanies this distribution, and is available at
15  * http://www.gnu.org/licenses/lgpl-2.1.html
16  *
17  *
18  * This library is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  * Lesser General Public License for more details.
22  *
23  * LGPL HEADER END
24  */
25 /*
26  *
27  * lustre/utils/lustreapi_internal.h
28  *
29  * Copyright (c) 2016 Intel Corporation.
30  *
31  * Author: Aurelien Degremont <aurelien.degremont@cea.fr>
32  * Author: JC Lafoucriere <jacques-charles.lafoucriere@cea.fr>
33  * Author: Thomas Leibovici <thomas.leibovici@cea.fr>
34  */
35
36 #ifndef _LUSTREAPI_INTERNAL_H_
37 #define _LUSTREAPI_INTERNAL_H_
38
39 #include <libcfs/util/param.h>
40 #include <uapi_kernelcomm.h>
41
42 #define WANT_PATH   0x1
43 #define WANT_FSNAME 0x2
44 #define WANT_FD     0x4
45 #define WANT_INDEX  0x8
46 #define WANT_ERROR  0x10
47
48 /* mount point listings in /proc/mounts */
49 #ifndef PROC_MOUNTS
50 #define PROC_MOUNTS "/proc/mounts"
51 #endif
52
53 int get_root_path(int want, char *fsname, int *outfd, char *path, int index);
54 int root_ioctl(const char *mdtname, int opc, void *data, int *mdtidxp,
55                int want_error);
56 int sattr_cache_get_defaults(const char *const fsname,
57                              const char *const pathname, unsigned int *scount,
58                              unsigned int *ssize, unsigned int *soffset);
59
60 /**
61  * Often when determining the parameter path in sysfs/procfs we
62  * are often only interest set of data. This enum gives use the
63  * ability to return data of parameters for:
64  *
65  * FILTER_BY_FS_NAME: a specific file system mount
66  * FILTER_BY_PATH:    Using a Lustre file path to determine which
67  *                    file system is of interest
68  * FILTER_BY_EXACT:   The default behavior. Search the parameter
69  *                    path as is.
70  */
71 enum param_filter {
72         FILTER_BY_NONE,
73         FILTER_BY_EXACT,
74         FILTER_BY_FS_NAME,
75         FILTER_BY_PATH
76 };
77
78 int get_lustre_param_path(const char *obd_type, const char *filter,
79                           enum param_filter type, const char *param_name,
80                           glob_t *param);
81 int get_lustre_param_value(const char *obd_type, const char *filter,
82                            enum param_filter type, const char *param_name,
83                            char *value, size_t val_len);
84
85 static inline int
86 poolpath(glob_t *pool_path, const char *fsname, char *pathname)
87 {
88         int rc;
89
90         if (fsname != NULL)
91                 rc = get_lustre_param_path("lov", fsname, FILTER_BY_FS_NAME,
92                                            "pools", pool_path);
93         else
94                 rc = get_lustre_param_path("lov", pathname, FILTER_BY_PATH,
95                                            "pools", pool_path);
96         return rc;
97 }
98
99 #define LLAPI_LAYOUT_MAGIC 0x11AD1107 /* LLAPILOT */
100
101 /* Helper functions for testing validity of stripe attributes. */
102
103 static inline bool llapi_stripe_size_is_aligned(uint64_t size)
104 {
105         return (size & (LOV_MIN_STRIPE_SIZE - 1)) == 0;
106 }
107
108 static inline bool llapi_stripe_size_is_too_big(uint64_t size)
109 {
110         return size >= (1ULL << 32);
111 }
112
113 static inline bool llapi_stripe_count_is_valid(int64_t count)
114 {
115         return count >= -1 && count <= LOV_MAX_STRIPE_COUNT;
116 }
117
118 static inline bool llapi_stripe_index_is_valid(int64_t index)
119 {
120         return index >= -1 && index <= LOV_V1_INSANE_STRIPE_COUNT;
121 }
122
123 /* Compatibility macro for legacy llapi functions that use "offset"
124  * terminology instead of the preferred "index". */
125 #define llapi_stripe_offset_is_valid(os) llapi_stripe_index_is_valid(os)
126
127 /*
128  * Kernel communication for Changelogs and HSM requests.
129  */
130 int libcfs_ukuc_start(struct lustre_kernelcomm *l, int groups, int rfd_flags);
131 int libcfs_ukuc_stop(struct lustre_kernelcomm *l);
132 int libcfs_ukuc_get_rfd(struct lustre_kernelcomm *link);
133 int libcfs_ukuc_msg_get(struct lustre_kernelcomm *l, char *buf, int maxsize,
134                         int transport);
135 #endif /* _LUSTREAPI_INTERNAL_H_ */