4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * All rights reserved. This program and the accompanying materials
7 * are made available under the terms of the GNU Lesser General Public License
8 * (LGPL) version 2.1 or (at your discretion) any later version.
9 * (LGPL) version 2.1 accompanies this distribution, and is available at
10 * http://www.gnu.org/licenses/lgpl-2.1.html
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
20 * lustre/utils/liblustreapi_param.c
22 * This code handles user interaction with the configuration interface
23 * to the Lustre file system to fine tune it.
28 #include <libcfs/util/param.h>
29 #include <lustre/lustre_user.h>
30 #include <lustre/lustreapi.h>
31 #include "lustreapi_internal.h"
34 * return the parameter's path for a specific device type or mountpoint
36 * \param param the results returned to the caller
37 * \param obd_type Lustre OBD device type
39 * \param filter filter combined with the type agrument allow the
40 * \param type caller to limit the scope of the search for the
41 * parameter's path. Typical options are search by
42 * Lustre filesystem name or by the path to a file
43 * or directory in the filesystem.
45 * \param param_name parameter name to fetch
47 * Using filter and the type argument we can limit the scope of the
48 * search to either the parameter belonging to a specific lustre filesystem
49 * (if it exists) or using a given file or directory path located on a
50 * mounted Lustre filesystem. The last case it can do is a special search
51 * based on exactly what the user passed instead of scanning file paths
52 * or specific file systems.
54 * If "obd_type" matches a Lustre device then the first matching device
55 * (as with "lctl dl", constrained by \param filter and \param type)
56 * will be used to provide the return value, otherwise the first such
57 * device found will be used.
59 * Return 0 for success, with the results stored in \param param.
60 * Return -ve value for error.
63 get_lustre_param_path(const char *obd_type, const char *filter,
64 enum param_filter type, const char *param_name,
67 char pattern[PATH_MAX];
70 if (filter == NULL && type != FILTER_BY_NONE)
75 rc = llapi_search_fsname(filter, pattern);
77 llapi_error(LLAPI_MSG_ERROR, rc,
78 "'%s' is not on a Lustre filesystem",
82 if (strlen(pattern) + 3 > sizeof(pattern))
84 strncat(pattern, "-*", sizeof(pattern));
86 case FILTER_BY_FS_NAME:
87 rc = snprintf(pattern, sizeof(pattern) - 1, "%s-*", filter);
90 else if (rc >= sizeof(pattern))
95 if (strlen(filter) + 1 > sizeof(pattern))
97 strncpy(pattern, filter, sizeof(pattern));
104 if (type == FILTER_BY_NONE) {
105 if (cfs_get_param_paths(param, "%s", param_name) != 0)
107 } else if (param_name != NULL) {
108 if (cfs_get_param_paths(param, "%s/%s/%s",
109 obd_type, pattern, param_name) != 0)
112 if (cfs_get_param_paths(param, "%s/%s",
113 obd_type, pattern) != 0)
121 * return a parameter of a single line value for a specific device type
124 * \param obd_type Lustre OBD device type
126 * \param filter filter combined with the type agruments allow the
127 * \param type caller to limit the scope of the search for the
128 * parameter's path. Typical options are search by
129 * Lustre filesystem name or by the path to a file
130 * or directory in the filesystem.
132 * \param param_name parameter name to fetch
133 * \param value return buffer for parameter value string
134 * \param val_len size of buffer for return value
136 * Using filter and the type argument we can limit the scope of the
137 * search to either the parameter belonging to a specific lustre filesystem
138 * (if it exists) or using a given file or directory path located on a
139 * mounted Lustre filesystem. The last case it can do is a special search
140 * based on exactly what the user passed instead of scanning file paths
141 * or specific file systems.
143 * If "obd_type" matches a Lustre device then the first matching device
144 * (as with "lctl dl", constrained by \param filter and \param type)
145 * will be used to provide the return value, otherwise the first such
146 * device found will be used.
148 * Return 0 for success, with a NUL-terminated string in \param value.
149 * Return negative errno value for error.
152 get_lustre_param_value(const char *obd_type, const char *filter,
153 enum param_filter type, const char *param_name,
154 char *value, size_t val_len)
160 rc = get_lustre_param_path(obd_type, filter, type, param_name, ¶m);
164 fp = fopen(param.gl_pathv[0], "r");
167 llapi_error(LLAPI_MSG_ERROR, rc, "error: opening '%s'",
172 if (fgets(value, val_len, fp) == NULL) {
178 cfs_free_param_data(¶m);