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