4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * (C) Copyright 2012 Commissariat a l'energie atomique et aux energies
9 * Copyright (c) 2016, 2017, Intel Corporation.
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
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.
27 * lustre/utils/lustreapi_internal.h
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>
34 #ifndef _LUSTREAPI_INTERNAL_H_
35 #define _LUSTREAPI_INTERNAL_H_
40 #include <libcfs/util/ioctl.h>
41 #include <libcfs/util/param.h>
43 #include <linux/lustre/lustre_ioctl.h>
44 #include <linux/lustre/lustre_kernelcomm.h>
46 #define MAX_IOC_BUFLEN 8192
47 #define MAX_LINE_LEN 256
48 #define MAX_INSTANCE_LEN 32
51 #define WANT_FSNAME 0x2
53 #define WANT_INDEX 0x8
54 #define WANT_ERROR 0x10
58 /* Define a fixed 4096-byte encryption unit size */
59 #define LUSTRE_ENCRYPTION_BLOCKBITS 12
60 #define LUSTRE_ENCRYPTION_UNIT_SIZE ((size_t)1 << LUSTRE_ENCRYPTION_BLOCKBITS)
61 #define LUSTRE_ENCRYPTION_MASK (~(LUSTRE_ENCRYPTION_UNIT_SIZE - 1))
63 /* mount point listings in /proc/mounts */
65 #define PROC_MOUNTS "/proc/mounts"
68 int get_root_path(int want, char *fsname, int *outfd, char *path, int index,
69 dev_t *dev, char *nid);
70 int llapi_ioctl_pack(struct obd_ioctl_data *data, char **pbuf, int max_len);
71 int llapi_ioctl_dev(int dev_id, unsigned int cmd, void *buf);
72 int llapi_ioctl_unpack(struct obd_ioctl_data *data, char *pbuf, int max_len);
73 int sattr_cache_get_defaults(const char *const fsname,
74 const char *const pathname, unsigned int *scount,
75 unsigned int *ssize, unsigned int *soffset);
78 * Often when determining the parameter path in sysfs/procfs we
79 * are often only interest set of data. This enum gives use the
80 * ability to return data of parameters for:
82 * FILTER_BY_FS_NAME: a specific file system mount
83 * FILTER_BY_PATH: Using a Lustre file path to determine which
84 * file system is of interest
85 * FILTER_BY_EXACT: The default behavior. Search the parameter
95 int get_lustre_param_path(const char *obd_type, const char *filter,
96 enum param_filter type, const char *param_name,
98 int get_lustre_param_value(const char *obd_type, const char *filter,
99 enum param_filter type, const char *param_name,
100 char *value, size_t val_len);
103 poolpath(glob_t *pool_path, const char *fsname, char *pathname)
108 rc = get_lustre_param_path("lov", fsname, FILTER_BY_FS_NAME,
111 rc = get_lustre_param_path("lov", pathname, FILTER_BY_PATH,
116 #define LLAPI_LAYOUT_MAGIC 0x11AD1107 /* LLAPILOT */
118 /* Helper functions for testing validity of stripe attributes. */
120 static inline bool llapi_stripe_size_is_aligned(uint64_t size)
122 return (size & (LOV_MIN_STRIPE_SIZE - 1)) == 0;
125 static inline bool llapi_stripe_size_is_too_big(uint64_t size)
127 return size >= (1ULL << 32);
130 static inline bool llapi_stripe_count_is_valid(int64_t count)
132 return count >= -1 && count <= LOV_MAX_STRIPE_COUNT;
135 static inline bool llapi_stripe_index_is_valid(int64_t index)
137 return index >= -1 && index <= LOV_V1_INSANE_STRIPE_COUNT;
140 static inline bool llapi_pool_name_is_valid(const char **pool_name)
144 if (*pool_name == NULL)
147 /* Strip off any 'fsname.' portion. */
148 ptr = strchr(*pool_name, '.');
150 *pool_name = ptr + 1;
152 if (strlen(*pool_name) > LOV_MAXPOOLNAME)
158 /* Compatibility macro for legacy llapi functions that use "offset"
159 * terminology instead of the preferred "index". */
160 #define llapi_stripe_offset_is_valid(os) llapi_stripe_index_is_valid(os)
162 static inline bool llapi_dir_stripe_count_is_valid(int64_t count)
164 return count >= -1 && count <= LMV_MAX_STRIPE_COUNT;
167 static inline bool llapi_dir_stripe_index_is_valid(int64_t index)
169 return index >= -1 && index < LMV_MAX_STRIPE_COUNT;
172 static inline bool llapi_dir_hash_type_is_valid(int64_t hash)
174 int64_t _hash = hash & LMV_HASH_TYPE_MASK;
176 return _hash >= LMV_HASH_TYPE_UNKNOWN && _hash < LMV_HASH_TYPE_MAX;
180 * Kernel communication for Changelogs and HSM requests.
182 int libcfs_ukuc_start(struct lustre_kernelcomm *l, int groups, int rfd_flags);
183 int libcfs_ukuc_stop(struct lustre_kernelcomm *l);
184 int libcfs_ukuc_get_rfd(struct lustre_kernelcomm *link);
185 int libcfs_ukuc_msg_get(struct lustre_kernelcomm *l, char *buf, int maxsize,
188 enum lctl_param_flags {
189 PARAM_FLAGS_YAML_FORMAT = 0x0001,
190 PARAM_FLAGS_SHOW_SOURCE = 0x0002,
191 PARAM_FLAGS_EXTRA_DETAILS = 0x0004,
194 int llapi_param_display_value(char *path, int version,
195 enum lctl_param_flags flags, FILE *fp);
197 enum get_lmd_info_type {
202 int get_lmd_info_fd(const char *path, int parentfd, int dirfd,
203 void *lmd_buf, int lmd_len, enum get_lmd_info_type type);
205 int lov_comp_md_size(struct lov_comp_md_v1 *lcm);
206 #endif /* _LUSTREAPI_INTERNAL_H_ */