Whamcloud - gitweb
LU-15833 llapi: don't use realpath in llapi_search_fsname()
[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  *     alternatives
8  *
9  * Copyright (c) 2016, 2017, Intel Corporation.
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  * Author: Aurelien Degremont <aurelien.degremont@cea.fr>
30  * Author: JC Lafoucriere <jacques-charles.lafoucriere@cea.fr>
31  * Author: Thomas Leibovici <thomas.leibovici@cea.fr>
32  */
33
34 #ifndef _LUSTREAPI_INTERNAL_H_
35 #define _LUSTREAPI_INTERNAL_H_
36
37 #include <limits.h>
38 #include <stdint.h>
39
40 #include <libcfs/util/ioctl.h>
41 #include <libcfs/util/param.h>
42
43 #include <linux/lustre/lustre_ioctl.h>
44 #include <linux/lustre/lustre_kernelcomm.h>
45
46 #define MAX_IOC_BUFLEN  8192
47
48 #define WANT_PATH   0x1
49 #define WANT_FSNAME 0x2
50 #define WANT_FD     0x4
51 #define WANT_INDEX  0x8
52 #define WANT_ERROR  0x10
53 #define WANT_DEV    0x20
54
55 /* Define a fixed 4096-byte encryption unit size */
56 #define LUSTRE_ENCRYPTION_BLOCKBITS   12
57 #define LUSTRE_ENCRYPTION_UNIT_SIZE   ((size_t)1 << LUSTRE_ENCRYPTION_BLOCKBITS)
58 #define LUSTRE_ENCRYPTION_MASK        (~(LUSTRE_ENCRYPTION_UNIT_SIZE - 1))
59
60 /* mount point listings in /proc/mounts */
61 #ifndef PROC_MOUNTS
62 #define PROC_MOUNTS "/proc/mounts"
63 #endif
64
65 int get_root_path(int want, char *fsname, int *outfd, char *path, int index,
66                   dev_t *dev);
67 int llapi_ioctl_pack(struct obd_ioctl_data *data, char **pbuf, int max_len);
68 int llapi_ioctl_unpack(struct obd_ioctl_data *data, char *pbuf, int max_len);
69 int sattr_cache_get_defaults(const char *const fsname,
70                              const char *const pathname, unsigned int *scount,
71                              unsigned int *ssize, unsigned int *soffset);
72
73 /**
74  * Often when determining the parameter path in sysfs/procfs we
75  * are often only interest set of data. This enum gives use the
76  * ability to return data of parameters for:
77  *
78  * FILTER_BY_FS_NAME: a specific file system mount
79  * FILTER_BY_PATH:    Using a Lustre file path to determine which
80  *                    file system is of interest
81  * FILTER_BY_EXACT:   The default behavior. Search the parameter
82  *                    path as is.
83  */
84 enum param_filter {
85         FILTER_BY_NONE,
86         FILTER_BY_EXACT,
87         FILTER_BY_FS_NAME,
88         FILTER_BY_PATH
89 };
90
91 int get_lustre_param_path(const char *obd_type, const char *filter,
92                           enum param_filter type, const char *param_name,
93                           glob_t *param);
94 int get_lustre_param_value(const char *obd_type, const char *filter,
95                            enum param_filter type, const char *param_name,
96                            char *value, size_t val_len);
97
98 static inline int
99 poolpath(glob_t *pool_path, const char *fsname, char *pathname)
100 {
101         int rc;
102
103         if (fsname != NULL)
104                 rc = get_lustre_param_path("lov", fsname, FILTER_BY_FS_NAME,
105                                            "pools", pool_path);
106         else
107                 rc = get_lustre_param_path("lov", pathname, FILTER_BY_PATH,
108                                            "pools", pool_path);
109         return rc;
110 }
111
112 #define LLAPI_LAYOUT_MAGIC 0x11AD1107 /* LLAPILOT */
113
114 /* Helper functions for testing validity of stripe attributes. */
115
116 static inline bool llapi_stripe_size_is_aligned(uint64_t size)
117 {
118         return (size & (LOV_MIN_STRIPE_SIZE - 1)) == 0;
119 }
120
121 static inline bool llapi_stripe_size_is_too_big(uint64_t size)
122 {
123         return size >= (1ULL << 32);
124 }
125
126 static inline bool llapi_stripe_count_is_valid(int64_t count)
127 {
128         return count >= -1 && count <= LOV_MAX_STRIPE_COUNT;
129 }
130
131 static inline bool llapi_stripe_index_is_valid(int64_t index)
132 {
133         return index >= -1 && index <= LOV_V1_INSANE_STRIPE_COUNT;
134 }
135
136 static inline bool llapi_pool_name_is_valid(const char **pool_name)
137 {
138         const char *ptr;
139
140         if (*pool_name == NULL)
141                 return false;
142
143         /* Strip off any 'fsname.' portion. */
144         ptr = strchr(*pool_name, '.');
145         if (ptr != NULL)
146                 *pool_name = ptr + 1;
147
148         if (strlen(*pool_name) > LOV_MAXPOOLNAME)
149                 return false;
150
151         return true;
152 }
153
154 /* Compatibility macro for legacy llapi functions that use "offset"
155  * terminology instead of the preferred "index". */
156 #define llapi_stripe_offset_is_valid(os) llapi_stripe_index_is_valid(os)
157
158 static inline bool llapi_dir_stripe_count_is_valid(int64_t count)
159 {
160         return count >= -1 && count <= LMV_MAX_STRIPE_COUNT;
161 }
162
163 static inline bool llapi_dir_stripe_index_is_valid(int64_t index)
164 {
165         return index >= -1 && index < LMV_MAX_STRIPE_COUNT;
166 }
167
168 static inline bool llapi_dir_hash_type_is_valid(int64_t hash)
169 {
170         int64_t _hash = hash & LMV_HASH_TYPE_MASK;
171
172         return _hash >= LMV_HASH_TYPE_UNKNOWN && _hash <  LMV_HASH_TYPE_MAX;
173 }
174
175 /*
176  * Kernel communication for Changelogs and HSM requests.
177  */
178 int libcfs_ukuc_start(struct lustre_kernelcomm *l, int groups, int rfd_flags);
179 int libcfs_ukuc_stop(struct lustre_kernelcomm *l);
180 int libcfs_ukuc_get_rfd(struct lustre_kernelcomm *link);
181 int libcfs_ukuc_msg_get(struct lustre_kernelcomm *l, char *buf, int maxsize,
182                         int transport);
183
184 enum get_lmd_info_type {
185         GET_LMD_INFO = 1,
186         GET_LMD_STRIPE = 2,
187 };
188
189 int get_lmd_info_fd(const char *path, int parentfd, int dirfd,
190                     void *lmd_buf, int lmd_len, enum get_lmd_info_type type);
191
192 int lov_comp_md_size(struct lov_comp_md_v1 *lcm);
193 #endif /* _LUSTREAPI_INTERNAL_H_ */