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.
25 * Copyright (c) 2016, Intel Corporation.
30 #include <libcfs/util/param.h>
31 #include <linux/lustre/lustre_user.h>
32 #include <lustre/lustreapi.h>
33 #include "lustreapi_internal.h"
36 * return the parameter's path for a specific device type or mountpoint
38 * \param param the results returned to the caller
39 * \param obd_type Lustre OBD device type
41 * \param filter filter combined with the type agrument allow the
42 * \param type caller to limit the scope of the search for the
43 * parameter's path. Typical options are search by
44 * Lustre filesystem name or by the path to a file
45 * or directory in the filesystem.
47 * \param param_name parameter name to fetch
49 * Using filter and the type argument we can limit the scope of the
50 * search to either the parameter belonging to a specific lustre filesystem
51 * (if it exists) or using a given file or directory path located on a
52 * mounted Lustre filesystem. The last case it can do is a special search
53 * based on exactly what the user passed instead of scanning file paths
54 * or specific file systems.
56 * If "obd_type" matches a Lustre device then the first matching device
57 * (as with "lctl dl", constrained by \param filter and \param type)
58 * will be used to provide the return value, otherwise the first such
59 * device found will be used.
61 * Return 0 for success, with the results stored in \param param.
62 * Return -ve value for error.
65 get_lustre_param_path(const char *obd_type, const char *filter,
66 enum param_filter type, const char *param_name,
69 char pattern[PATH_MAX];
72 if (filter == NULL && type != FILTER_BY_NONE)
77 rc = llapi_search_fsname(filter, pattern);
79 llapi_error(LLAPI_MSG_ERROR, rc,
80 "'%s' is not on a Lustre filesystem",
84 if (strlen(pattern) + 3 > sizeof(pattern))
86 strncat(pattern, "-*", sizeof(pattern));
88 case FILTER_BY_FS_NAME:
89 rc = snprintf(pattern, sizeof(pattern) - 1, "%s-*", filter);
92 else if (rc >= sizeof(pattern))
97 if (strlen(filter) + 1 > sizeof(pattern))
99 strncpy(pattern, filter, sizeof(pattern));
106 if (type == FILTER_BY_NONE) {
107 if (cfs_get_param_paths(param, "%s", param_name) != 0)
109 } else if (param_name != NULL) {
110 if (cfs_get_param_paths(param, "%s/%s/%s",
111 obd_type, pattern, param_name) != 0)
114 if (cfs_get_param_paths(param, "%s/%s",
115 obd_type, pattern) != 0)
123 * return a parameter of a single line value for a specific device type
126 * \param obd_type Lustre OBD device type
128 * \param filter filter combined with the type agruments allow the
129 * \param type caller to limit the scope of the search for the
130 * parameter's path. Typical options are search by
131 * Lustre filesystem name or by the path to a file
132 * or directory in the filesystem.
134 * \param param_name parameter name to fetch
135 * \param value return buffer for parameter value string
136 * \param val_len size of buffer for return value
138 * Using filter and the type argument we can limit the scope of the
139 * search to either the parameter belonging to a specific lustre filesystem
140 * (if it exists) or using a given file or directory path located on a
141 * mounted Lustre filesystem. The last case it can do is a special search
142 * based on exactly what the user passed instead of scanning file paths
143 * or specific file systems.
145 * If "obd_type" matches a Lustre device then the first matching device
146 * (as with "lctl dl", constrained by \param filter and \param type)
147 * will be used to provide the return value, otherwise the first such
148 * device found will be used.
150 * Return 0 for success, with a NUL-terminated string in \param value.
151 * Return negative errno value for error.
154 get_lustre_param_value(const char *obd_type, const char *filter,
155 enum param_filter type, const char *param_name,
156 char *value, size_t val_len)
162 rc = get_lustre_param_path(obd_type, filter, type, param_name, ¶m);
166 fp = fopen(param.gl_pathv[0], "r");
169 llapi_error(LLAPI_MSG_ERROR, rc, "error: opening '%s'",
174 if (fgets(value, val_len, fp) == NULL) {
180 cfs_free_param_data(¶m);