#include <libcfs/util/string.h>
#include <libcfs/util/param.h>
#include <libcfs/util/parser.h>
+#include <lustre/lustreapi.h>
#include <linux/lnet/nidstr.h>
#include <linux/lnet/lnetctl.h>
#include <linux/lustre/lustre_cfg.h>
static int
read_param(const char *path, const char *param_name, struct param_opts *popt)
{
- bool display_path = popt->po_show_path;
- long page_size = sysconf(_SC_PAGESIZE);
int rc = 0;
- char *buf;
- int fd;
-
- /* Read the contents of file to stdout */
- fd = open(path, O_RDONLY);
- if (fd < 0) {
- rc = -errno;
- fprintf(stderr,
- "error: get_param: opening '%s': %s\n",
- path, strerror(errno));
- return rc;
- }
+ char *buf = NULL;
+ size_t buflen;
- buf = calloc(1, page_size);
- if (buf == NULL) {
+ rc = llapi_param_get_value(path, &buf, &buflen);
+ if (rc != 0) {
fprintf(stderr,
- "error: get_param: allocating '%s' buffer: %s\n",
- path, strerror(errno));
- close(fd);
- return -ENOMEM;
+ "error: read_param: \'%s\': %s\n",
+ path, strerror(-rc));
+ goto free_buf;
}
+ /* don't print anything for empty files */
+ if (buf[0] == '\0')
+ goto free_buf;
- while (1) {
- ssize_t count = read(fd, buf, page_size);
+ if (popt->po_show_path) {
+ bool longbuf;
- if (count == 0)
- break;
- if (count < 0) {
- rc = -errno;
- if (errno != EIO) {
- fprintf(stderr, "error: get_param: "
- "reading '%s': %s\n",
- param_name, strerror(errno));
- }
- break;
- }
-
- /* Print the output in the format path=value if the value does
- * not contain a new line character and the output can fit in
- * a single line, else print value on new line */
- if (display_path) {
- bool longbuf;
-
- longbuf = strnchr(buf, count - 1, '\n') != NULL ||
- count + strlen(param_name) >= 80;
- printf("%s=%s", param_name, longbuf ? "\n" : buf);
-
- /* Make sure it doesn't print again while looping */
- display_path = false;
-
- if (!longbuf)
- continue;
- }
-
- if (fwrite(buf, 1, count, stdout) != count) {
- rc = -errno;
- fprintf(stderr,
- "error: get_param: write to stdout: %s\n",
- strerror(errno));
- break;
- }
+ longbuf = strnchr(buf, buflen - 1, '\n') != NULL ||
+ buflen + strlen(param_name) >= 80;
+ printf("%s=%s", param_name, longbuf ? "\n" : "");
}
- close(fd);
- free(buf);
+ printf("%s", buf);
+free_buf:
+ free(buf);
return rc;
}
char *opname = parameter_opname[mode];
int rc, i;
- rc = cfs_get_param_paths(&paths, "%s", pattern);
+ rc = llapi_param_get_paths(pattern, &paths);
if (rc != 0) {
rc = -errno;
if (!popt->po_recursive) {
free(dup_cache[i]);
free(dup_cache);
out_param:
- cfs_free_param_data(&paths);
+ llapi_param_paths_free(&paths);
return rc;
}