#include <sys/syscall.h>
#include <sys/xattr.h>
#include <fnmatch.h>
-#include <glob.h>
#include <libgen.h> /* for dirname() */
#ifdef HAVE_LINUX_UNISTD_H
#include <linux/unistd.h>
#endif
#include <poll.h>
+#include <libcfs/util/param.h>
#include <libcfs/util/string.h>
#include <lnet/lnetctl.h>
#include <lustre/lustreapi.h>
return 0;
}
-/* return the first file matching this pattern */
-static int first_match(char *pattern, char *buffer)
-{
- glob_t glob_info;
-
- if (glob(pattern, GLOB_BRACE, NULL, &glob_info))
- return -ENOENT;
-
- if (glob_info.gl_pathc < 1) {
- globfree(&glob_info);
- return -ENOENT;
- }
-
- strcpy(buffer, glob_info.gl_pathv[0]);
-
- globfree(&glob_info);
- return 0;
-}
-
-static int find_target_obdpath(char *fsname, char *path)
-{
- glob_t glob_info;
- char pattern[PATH_MAX + 1];
- int rc;
-
- snprintf(pattern, PATH_MAX,
- "/proc/fs/lustre/lov/%s-*/target_obd",
- fsname);
- rc = glob(pattern, GLOB_BRACE, NULL, &glob_info);
- if (rc == GLOB_NOMATCH)
- return -ENODEV;
- else if (rc)
- return -EINVAL;
-
- strcpy(path, glob_info.gl_pathv[0]);
- globfree(&glob_info);
- return 0;
-}
-
-static int find_poolpath(char *fsname, char *poolname, char *poolpath)
-{
- glob_t glob_info;
- char pattern[PATH_MAX + 1];
- int rc;
-
- snprintf(pattern, PATH_MAX,
- "/proc/fs/lustre/lov/%s-*/pools/%s",
- fsname, poolname);
- rc = glob(pattern, GLOB_BRACE, NULL, &glob_info);
- /* If no pools, make sure the lov is available */
- if ((rc == GLOB_NOMATCH) &&
- (find_target_obdpath(fsname, poolpath) == -ENODEV))
- return -ENODEV;
- if (rc)
- return -EINVAL;
-
- strcpy(poolpath, glob_info.gl_pathv[0]);
- globfree(&glob_info);
- return 0;
-}
-
/*
* Trim a trailing newline from a string, if it exists.
*/
return '\n';
}
-/**
- * return a parameter string for a specific device type or mountpoint
- *
- * \param param_path the path to the file containing parameter data
- * \param result buffer for parameter value string
- * \param result_size size of buffer for return value
- *
- * The \param param_path is appended to /proc/{fs,sys}/{lnet,lustre} to
- * complete the absolute path to the file containing the parameter data
- * the user is requesting. If that file exist then the data is read from
- * the file and placed into the \param result buffer that is passed by
- * the user. Data is only copied up to the \param result_size to prevent
- * overflow of the array.
- *
- * Return 0 for success, with a NUL-terminated string in \param result.
- * Return -ve value for error.
- */
-int get_param(const char *param_path, char *result,
- unsigned int result_size)
-{
- char file[PATH_MAX + 1], pattern[PATH_MAX + 1], buf[result_size];
- FILE *fp = NULL;
- int rc = 0;
-
- snprintf(pattern, PATH_MAX, "/proc/{fs,sys}/{lnet,lustre}/%s",
- param_path);
- rc = first_match(pattern, file);
- if (rc != 0 || result == NULL)
- return rc;
-
- fp = fopen(file, "r");
- if (fp != NULL) {
- while (fgets(buf, result_size, fp) != NULL)
- strcpy(result, buf);
- fclose(fp);
- } else {
- rc = -errno;
- }
- return rc;
-}
-
-#define DEVICES_LIST "/proc/fs/lustre/devices"
-
-/**
- * return a parameter string for a specific device type or mountpoint
- *
- * \param fsname Lustre filesystem name (optional)
- * \param file_path path to file in filesystem (optional, if fsname unset)
- * \param obd_type Lustre OBD device type
- * \param param_name parameter name to fetch
- * \param value return buffer for parameter value string
- * \param val_len size of buffer for return value
- *
- * If fsname is specified then the parameter will be from that filesystem
- * (if it exists). If file_path is given and it is in a mounted Lustre
- * filesystem, then the parameter will be otherwise the value may be
- * from any mounted filesystem (if there is more than one).
- *
- * If "obd_type" matches a Lustre device then the first matching device
- * (as with "lctl dl", constrained by \param fsname or \param mount_path)
- * will be used to provide the return value, otherwise the first such
- * device found will be used.
- *
- * Return 0 for success, with a NUL-terminated string in \param buffer.
- * Return -ve value for error.
- */
-static int get_param_obdvar(const char *fsname, const char *file_path,
- const char *obd_type, const char *param_name,
- char *value, unsigned int val_len)
-{
- char devices[PATH_MAX];
- char dev[PATH_MAX] = "*";
- char fs[PATH_MAX];
- FILE *fp = NULL;
- int rc = 0;
-
- fp = fopen(DEVICES_LIST, "r");
- if (fp == NULL) {
- rc = -errno;
- llapi_error(LLAPI_MSG_ERROR, rc, "error: opening "DEVICES_LIST);
- goto out;
- }
-
- if (fsname == NULL && file_path != NULL) {
- rc = llapi_search_fsname(file_path, fs);
- if (rc) {
- llapi_error(LLAPI_MSG_ERROR, rc,
- "'%s' is not on a Lustre filesystem",
- file_path);
- goto out;
- }
- } else if (fsname != NULL) {
- rc = strlcpy(fs, fsname, sizeof(fs));
- if (rc >= sizeof(fs)) {
- rc = -E2BIG;
- goto out;
- }
- }
-
- while (fgets(devices, sizeof(devices) - 1, fp) != NULL) {
- char *bufp = devices, *tmp;
-
- devices[sizeof(devices) - 1] = '\0';
- while (bufp[0] == ' ')
- ++bufp;
-
- tmp = strstr(bufp, obd_type);
- if (tmp != NULL) {
- tmp += strlen(obd_type) + 1;
- if (strcmp(tmp, fs))
- continue;
- rc = strlcpy(dev, tmp, sizeof(dev));
- if (rc >= sizeof(dev)) {
- rc = -E2BIG;
- goto out;
- }
-
- tmp = strchr(dev, ' ');
- if (tmp != NULL)
- *tmp = '\0';
- break;
- }
- }
-
- if (dev[0] == '*' && strlen(fs)) {
- rc = snprintf(dev, sizeof(dev), "%s-*", fs);
- if (rc >= sizeof(dev)) {
- rc = -E2BIG;
- goto out;
- }
- }
- rc = snprintf(devices, sizeof(devices), "%s/%s/%s", obd_type, dev,
- param_name);
- if (rc >= sizeof(devices)) {
- rc = -E2BIG;
- goto out;
- }
-
- fclose(fp);
- return get_param(devices, value, val_len);
-out:
- if (fp != NULL)
- fclose(fp);
- return rc;
-}
-
/*
- * TYPE one of llite, lmv, lov.
- * /proc/fs/lustre/TYPE/INST the directory of interest.
+ * Wrapper to grab parameter settings for lov.*-clilov-*.* values
*/
-static int get_param_cli(const char *type, const char *inst,
- const char *param, char *buf, size_t buf_size)
-{
- char param_path[PATH_MAX + 1];
- FILE *param_file = NULL;
- int rc;
-
- snprintf(param_path, sizeof(param_path),
- "/proc/fs/lustre/%s/%s/%s", type, inst, param);
-
- param_file = fopen(param_path, "r");
- if (param_file == NULL) {
- rc = -errno;
- goto out;
- }
-
- if (fgets(buf, buf_size, param_file) == NULL) {
- rc = -errno;
- goto out;
- }
-
- rc = 0;
-out:
- if (param_file != NULL)
- fclose(param_file);
-
- return rc;
-}
-
-static int get_param_llite(const char *path,
- const char *param, char *buf, size_t buf_size)
-{
- char inst[80];
- int rc;
-
- rc = llapi_getname(path, inst, sizeof(inst));
- if (rc != 0)
- return rc;
-
- return get_param_cli("llite", inst, param, buf, buf_size);
-}
-
-static int get_param_lov(const char *path,
- const char *param, char *buf, size_t buf_size)
+static int get_param_lov(const char *path, const char *param,
+ char *buf, size_t buf_size)
{
struct obd_uuid uuid;
int rc;
if (rc != 0)
return rc;
- return get_param_cli("lov", uuid.uuid, param, buf, buf_size);
+ return get_lustre_param_value("lov", uuid.uuid, FILTER_BY_EXACT, param,
+ buf, buf_size);
}
-static int get_param_lmv(const char *path,
- const char *param, char *buf, size_t buf_size)
+/*
+ * Wrapper to grab parameter settings for lmv.*-clilov-*.* values
+ */
+static int get_param_lmv(const char *path, const char *param,
+ char *buf, size_t buf_size)
{
struct obd_uuid uuid;
int rc;
if (rc != 0)
return rc;
- return get_param_cli("lmv", uuid.uuid, param, buf, buf_size);
+ return get_lustre_param_value("lmv", uuid.uuid, FILTER_BY_EXACT, param,
+ buf, buf_size);
}
static int get_mds_md_size(const char *path)
{
+ char buf[PATH_MAX], inst[PATH_MAX];
int md_size = lov_user_md_size(LOV_MAX_STRIPE_COUNT, LOV_USER_MAGIC_V3);
- char buf[80];
int rc;
- /* Get the max ea size from llite proc. */
- rc = get_param_llite(path, "max_easize", buf, sizeof(buf));
+ rc = llapi_getname(path, inst, sizeof(inst));
if (rc != 0)
- goto out;
+ return md_size;
+
+ /* Get the max ea size from llite parameters. */
+ rc = get_lustre_param_value("llite", inst, FILTER_BY_EXACT,
+ "max_easize", buf, sizeof(buf));
+ if (rc != 0)
+ return md_size;
rc = atoi(buf);
- if (rc > 0)
- md_size = rc;
-out:
- return md_size;
+ return rc > 0 ? rc : md_size;
}
int llapi_get_agent_uuid(char *path, char *buf, size_t bufsize)
*/
int llapi_search_ost(char *fsname, char *poolname, char *ostname)
{
- FILE *fd;
- char buffer[PATH_MAX + 1];
- int len = 0, rc;
+ char buffer[PATH_MAX];
+ size_t len = 0;
+ glob_t param;
+ FILE *fd;
+ int rc;
- if (ostname != NULL)
- len = strlen(ostname);
+ /* You need one or the other */
+ if (poolname == NULL && fsname == NULL)
+ return -EINVAL;
- if (poolname == NULL) {
- if (len == 0)
- rc = -EINVAL;
- else
- rc = find_target_obdpath(fsname, buffer);
+ if (ostname != NULL)
+ len = strlen(ostname);
+
+ if (poolname == NULL && len == 0)
+ return -EINVAL;
+
+ /* Search by poolname and fsname if is not NULL */
+ if (poolname != NULL) {
+ rc = poolpath(¶m, fsname, NULL);
+ if (rc == 0) {
+ snprintf(buffer, sizeof(buffer), "%s/%s",
+ param.gl_pathv[0], poolname);
+ }
+ } else if (fsname != NULL) {
+ rc = get_lustre_param_path("lov", fsname,
+ FILTER_BY_FS_NAME,
+ "target_obd", ¶m);
+ if (rc == 0) {
+ strncpy(buffer, param.gl_pathv[0],
+ sizeof(buffer));
+ }
} else {
- rc = find_poolpath(fsname, poolname, buffer);
+ return -EINVAL;
}
- if (rc)
- return rc;
+ cfs_free_param_data(¶m);
+ if (rc)
+ return rc;
fd = fopen(buffer, "r");
if (fd == NULL)
return rc;
}
-
-/*
- * find the pool directory path under /proc
- * (can be also used to test if a fsname is known)
- */
-static int poolpath(char *fsname, char *pathname, char *pool_pathname)
-{
- int rc = 0;
- char pattern[PATH_MAX + 1];
- char buffer[PATH_MAX];
-
- if (fsname == NULL) {
- rc = llapi_search_fsname(pathname, buffer);
- if (rc != 0)
- return rc;
- fsname = buffer;
- strcpy(pathname, fsname);
- }
-
- snprintf(pattern, PATH_MAX, "/proc/fs/lustre/lov/%s-*/pools", fsname);
- rc = first_match(pattern, buffer);
- if (rc)
- return rc;
-
- /* in fsname test mode, pool_pathname is NULL */
- if (pool_pathname != NULL)
- strcpy(pool_pathname, buffer);
-
- return 0;
-}
-
/**
* Get the list of pool members.
* \param poolname string of format \<fsname\>.\<poolname\>
{
char fsname[PATH_MAX];
char *pool, *tmp;
- char pathname[PATH_MAX];
- char path[PATH_MAX];
- char buf[1024];
- FILE *fd;
- int rc = 0;
- int nb_entries = 0;
- int used = 0;
+ glob_t pathname;
+ char buf[PATH_MAX];
+ FILE *fd;
+ int rc = 0;
+ int nb_entries = 0;
+ int used = 0;
- /* name is FSNAME.POOLNAME */
+ /* name is FSNAME.POOLNAME */
if (strlen(poolname) >= sizeof(fsname))
return -EOVERFLOW;
strlcpy(fsname, poolname, sizeof(fsname));
- pool = strchr(fsname, '.');
- if (pool == NULL)
- return -EINVAL;
+ pool = strchr(fsname, '.');
+ if (pool == NULL)
+ return -EINVAL;
- *pool = '\0';
- pool++;
+ *pool = '\0';
+ pool++;
- rc = poolpath(fsname, NULL, pathname);
- if (rc != 0) {
- llapi_error(LLAPI_MSG_ERROR, rc,
- "Lustre filesystem '%s' not found",
- fsname);
- return rc;
- }
+ rc = poolpath(&pathname, fsname, NULL);
+ if (rc != 0) {
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "Lustre filesystem '%s' not found",
+ fsname);
+ return rc;
+ }
- llapi_printf(LLAPI_MSG_NORMAL, "Pool: %s.%s\n", fsname, pool);
- rc = snprintf(path, sizeof(path), "%s/%s", pathname, pool);
- if (rc >= sizeof(path))
+ llapi_printf(LLAPI_MSG_NORMAL, "Pool: %s.%s\n", fsname, pool);
+ rc = snprintf(buf, sizeof(buf), "%s/%s", pathname.gl_pathv[0], pool);
+ cfs_free_param_data(&pathname);
+ if (rc >= sizeof(buf))
return -EOVERFLOW;
- fd = fopen(path, "r");
- if (fd == NULL) {
- rc = -errno;
- llapi_error(LLAPI_MSG_ERROR, rc, "Cannot open %s", path);
- return rc;
- }
+ fd = fopen(buf, "r");
+ if (fd == NULL) {
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc, "cannot open %s", buf);
+ return rc;
+ }
rc = 0;
while (fgets(buf, sizeof(buf), fd) != NULL) {
int llapi_get_poollist(const char *name, char **poollist, int list_size,
char *buffer, int buffer_size)
{
- char fsname[PATH_MAX + 1], rname[PATH_MAX + 1], pathname[PATH_MAX + 1];
+ char rname[PATH_MAX];
+ glob_t pathname;
+ char *fsname;
char *ptr;
DIR *dir;
struct dirent pool;
return rc;
}
- rc = poolpath(NULL, rname, pathname);
- if (rc != 0) {
- llapi_error(LLAPI_MSG_ERROR, rc, "'%s' is not"
- " a Lustre filesystem", name);
- return rc;
- }
- if (strlen(rname) > sizeof(fsname)-1)
- return -E2BIG;
- strncpy(fsname, rname, sizeof(fsname));
- } else {
- /* name is FSNAME */
- if (strlen(name) > sizeof(fsname)-1)
- return -E2BIG;
- strncpy(fsname, name, sizeof(fsname));
- rc = poolpath(fsname, NULL, pathname);
- }
- if (rc != 0) {
- llapi_error(LLAPI_MSG_ERROR, rc,
- "Lustre filesystem '%s' not found", name);
- return rc;
- }
+ fsname = strdup(rname);
+ if (!fsname)
+ return -ENOMEM;
- llapi_printf(LLAPI_MSG_NORMAL, "Pools from %s:\n", fsname);
- dir = opendir(pathname);
- if (dir == NULL) {
- rc = -errno;
- llapi_error(LLAPI_MSG_ERROR, rc,
- "Could not open pool list for '%s'",
- name);
- return rc;
- }
+ rc = poolpath(&pathname, NULL, rname);
+ } else {
+ /* name is FSNAME */
+ fsname = strdup(name);
+ if (!fsname)
+ return -ENOMEM;
+ rc = poolpath(&pathname, fsname, NULL);
+ }
+ if (rc != 0) {
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "Lustre filesystem '%s' not found", name);
+ goto free_path;
+ }
- while(1) {
- rc = readdir_r(dir, &pool, &cookie);
+ llapi_printf(LLAPI_MSG_NORMAL, "Pools from %s:\n", fsname);
+ dir = opendir(pathname.gl_pathv[0]);
+ if (dir == NULL) {
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "Could not open pool list for '%s'",
+ name);
+ goto free_path;
+ }
- if (rc != 0) {
- rc = -errno;
- llapi_error(LLAPI_MSG_ERROR, rc,
- "Error reading pool list for '%s'", name);
- goto out;
- } else if ((rc == 0) && (cookie == NULL)) {
- /* end of directory */
- break;
- }
+ while(1) {
+ rc = readdir_r(dir, &pool, &cookie);
+ if (rc != 0) {
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "Error reading pool list for '%s'", name);
+ goto free_path;
+ } else if ((rc == 0) && (cookie == NULL)) {
+ /* end of directory */
+ break;
+ }
/* ignore . and .. */
if (!strcmp(pool.d_name, ".") || !strcmp(pool.d_name, ".."))
/* check output bounds */
if (nb_entries >= list_size) {
rc = -EOVERFLOW;
- goto out;
+ goto free_dir;
}
/* +2 for '.' and final '\0' */
if (used + strlen(pool.d_name) + strlen(fsname) + 2
> buffer_size) {
rc = -EOVERFLOW;
- goto out;
+ goto free_dir;
}
sprintf(buffer + used, "%s.%s", fsname, pool.d_name);
nb_entries++;
}
-out:
- closedir(dir);
- return ((rc != 0) ? rc : nb_entries);
+free_dir:
+ closedir(dir);
+free_path:
+ cfs_free_param_data(&pathname);
+ if (fsname)
+ free(fsname);
+ return rc != 0 ? rc : nb_entries;
}
/* wrapper for lfs.c and obd.c */
int llapi_poollist(const char *name)
{
- /* list of pool names (assume that pool count is smaller
- than OST count) */
- char **list, *buffer = NULL, *path = NULL, *fsname = NULL;
- int obdcount, bufsize, rc, nb, i;
- char *poolname = NULL, *tmp = NULL, data[16];
+ /* list of pool names (assume that pool count is smaller
+ than OST count) */
+ char **list, *buffer = NULL, *fsname = (char *)name;
+ char *poolname = NULL, *tmp = NULL, data[16];
+ enum param_filter type = FILTER_BY_PATH;
+ int obdcount, bufsize, rc, nb, i;
if (name == NULL)
return -EINVAL;
if (fsname == NULL)
return -ENOMEM;
- poolname = strchr(fsname, '.');
- if (poolname)
- *poolname = '\0';
- } else {
- path = (char *) name;
- }
+ poolname = strchr(fsname, '.');
+ if (poolname)
+ *poolname = '\0';
+ type = FILTER_BY_FS_NAME;
+ }
- rc = get_param_obdvar(fsname, path, "lov", "numobd",
- data, sizeof(data));
- if (rc < 0)
- goto err;
- obdcount = atoi(data);
+ rc = get_lustre_param_value("lov", fsname, type, "numobd",
+ data, sizeof(data));
+ if (rc < 0)
+ goto err;
+ obdcount = atoi(data);
/* Allocate space for each fsname-OST0000_UUID, 1 per OST,
* and also an array to store the pointers for all that
err:
if (buffer)
free(buffer);
- if (fsname)
- free(fsname);
- return rc;
+ if (fsname != NULL && type == FILTER_BY_FS_NAME)
+ free(fsname);
+ return rc;
}
typedef int (semantic_func_t)(char *path, DIR *parent, DIR **d,
LOV_TYPE = 1,
LMV_TYPE
};
+
/*
* If uuidp is NULL, return the number of available obd uuids.
* If uuidp is non-NULL, then it will return the uuids of the obds. If
static int llapi_get_target_uuids(int fd, struct obd_uuid *uuidp,
int *ost_count, enum tgt_type type)
{
+ char buf[PATH_MAX], format[32];
+ int rc = 0, index = 0;
struct obd_uuid name;
- char buf[1024];
- char format[32];
+ glob_t param;
FILE *fp;
- int rc = 0, index = 0;
- /* Get the lov name */
- if (type == LOV_TYPE) {
- rc = llapi_file_fget_lov_uuid(fd, &name);
- if (rc)
- return rc;
- } else {
- rc = llapi_file_fget_lmv_uuid(fd, &name);
- if (rc)
- return rc;
- }
+ /* Get the lov name */
+ if (type == LOV_TYPE)
+ rc = llapi_file_fget_lov_uuid(fd, &name);
+ else
+ rc = llapi_file_fget_lmv_uuid(fd, &name);
+ if (rc != 0)
+ return rc;
- /* Now get the ost uuids from /proc */
- snprintf(buf, sizeof(buf), "/proc/fs/lustre/%s/%s/target_obd",
- type == LOV_TYPE ? "lov" : "lmv", name.uuid);
- fp = fopen(buf, "r");
- if (fp == NULL) {
- rc = -errno;
- llapi_error(LLAPI_MSG_ERROR, rc, "error: opening '%s'", buf);
- return rc;
- }
+ /* Now get the ost uuids */
+ rc = get_lustre_param_path(type == LOV_TYPE ? "lov" : "lmv", name.uuid,
+ FILTER_BY_EXACT, "target_obd", ¶m);
+ if (rc != 0)
+ return -ENOENT;
+
+ fp = fopen(param.gl_pathv[0], "r");
+ if (fp == NULL) {
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc, "error: opening '%s'",
+ param.gl_pathv[0]);
+ goto free_param;
+ }
snprintf(format, sizeof(format),
"%%d: %%%zus", sizeof(uuidp[0].uuid) - 1);
if (uuidp && (index > *ost_count))
rc = -EOVERFLOW;
- *ost_count = index;
- return rc;
+ *ost_count = index;
+free_param:
+ cfs_free_param_data(¶m);
+ return rc;
}
int llapi_lov_get_uuids(int fd, struct obd_uuid *uuidp, int *ost_count)
static int setup_obd_uuid(DIR *dir, char *dname, struct find_param *param)
{
struct obd_uuid obd_uuid;
- char buf[1024];
+ char buf[PATH_MAX];
+ glob_t param_data;
char format[32];
- FILE *fp;
int rc = 0;
+ FILE *fp;
if (param->fp_got_uuids)
- return rc;
+ return rc;
- /* Get the lov/lmv name */
+ /* Get the lov/lmv name */
if (param->fp_get_lmv)
- rc = llapi_file_fget_lmv_uuid(dirfd(dir), &obd_uuid);
- else
- rc = llapi_file_fget_lov_uuid(dirfd(dir), &obd_uuid);
- if (rc) {
- if (rc != -ENOTTY) {
- llapi_error(LLAPI_MSG_ERROR, rc,
- "error: can't get lov name: %s", dname);
- } else {
- rc = 0;
- }
- return rc;
- }
+ rc = llapi_file_fget_lmv_uuid(dirfd(dir), &obd_uuid);
+ else
+ rc = llapi_file_fget_lov_uuid(dirfd(dir), &obd_uuid);
+ if (rc) {
+ if (rc != -ENOTTY) {
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "error: can't get %s name: %s",
+ param->fp_get_lmv ? "lmv" : "lov",
+ dname);
+ } else {
+ rc = 0;
+ }
+ return rc;
+ }
param->fp_got_uuids = 1;
- /* Now get the ost uuids from /proc */
- snprintf(buf, sizeof(buf), "/proc/fs/lustre/%s/%s/target_obd",
- param->fp_get_lmv ? "lmv" : "lov", obd_uuid.uuid);
- fp = fopen(buf, "r");
- if (fp == NULL) {
- rc = -errno;
- llapi_error(LLAPI_MSG_ERROR, rc, "error: opening '%s'", buf);
- return rc;
- }
+ /* Now get the ost uuids */
+ rc = get_lustre_param_path(param->fp_get_lmv ? "lmv" : "lov",
+ obd_uuid.uuid, FILTER_BY_EXACT,
+ "target_obd", ¶m_data);
+ if (rc != 0)
+ return -ENOENT;
+
+ fp = fopen(param_data.gl_pathv[0], "r");
+ if (fp == NULL) {
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc, "error: opening '%s'",
+ param_data.gl_pathv[0]);
+ goto free_param;
+ }
if (!param->fp_obd_uuid && !param->fp_quiet && !param->fp_obds_printed)
llapi_printf(LLAPI_MSG_NORMAL, "%s:\n",
- param->fp_get_lmv ? "MDTS" : "OBDS:");
+ param->fp_get_lmv ? "MDTS" : "OBDS");
snprintf(format, sizeof(format),
"%%d: %%%zus", sizeof(obd_uuid.uuid) - 1);
__func__, param->fp_obd_uuid->uuid);
rc = -EINVAL;
}
-
- return (rc);
+free_param:
+ cfs_free_param_data(¶m_data);
+ return rc;
}
/* In this case, param->fp_obd_uuid will be an array of obduuids and
if (ret != 0)
return ret;
- obdcount = atoi(buf);
- uuids = (struct obd_uuid *)malloc(obdcount *
- sizeof(struct obd_uuid));
- if (uuids == NULL)
- return -ENOMEM;
+ obdcount = atoi(buf);
+ uuids = malloc(obdcount * sizeof(struct obd_uuid));
+ if (uuids == NULL)
+ return -ENOMEM;
retry_get_uuids:
- ret = llapi_get_target_uuids(dirfd(dir), uuids, &obdcount, type);
- if (ret) {
- struct obd_uuid *uuids_temp;
+ ret = llapi_get_target_uuids(dirfd(dir), uuids, &obdcount, type);
+ if (ret) {
+ if (ret == -EOVERFLOW) {
+ struct obd_uuid *uuids_temp;
- if (ret == -EOVERFLOW) {
- uuids_temp = realloc(uuids, obdcount *
- sizeof(struct obd_uuid));
+ uuids_temp = realloc(uuids, obdcount *
+ sizeof(struct obd_uuid));
if (uuids_temp != NULL) {
+ free(uuids);
uuids = uuids_temp;
- goto retry_get_uuids;
+ goto retry_get_uuids;
}
- else
- ret = -ENOMEM;
- }
+ ret = -ENOMEM;
+ }
llapi_error(LLAPI_MSG_ERROR, ret, "get ost uuid failed");
goto out_free;
}
/*
- * Given a filesystem name, or a pathname of a file on a lustre filesystem,
- * tries to determine the path to the filesystem's clilov directory under /proc
- *
- * fsname is limited to MTI_NAME_MAXLEN in lustre_idl.h
- * The NUL terminator is compensated by the additional "%s" bytes. */
-#define LOV_LEN (sizeof("/proc/fs/lustre/lov/%s-clilov-*") + MTI_NAME_MAXLEN)
-static int clilovpath(const char *fsname, const char *const pathname,
- char *clilovpath)
-{
- int rc;
- char pattern[LOV_LEN];
- char buffer[PATH_MAX + 1];
-
- if (fsname == NULL) {
- rc = llapi_search_fsname(pathname, buffer);
- if (rc != 0)
- return rc;
- fsname = buffer;
- }
-
- snprintf(pattern, sizeof(pattern), "/proc/fs/lustre/lov/%s-clilov-*",
- fsname);
-
- rc = first_match(pattern, buffer);
- if (rc != 0)
- return rc;
-
- strlcpy(clilovpath, buffer, sizeof(buffer));
-
- return 0;
-}
-
-/*
- * Given the path to a stripe attribute proc file, tries to open and
- * read the attribute and return the value using the attr parameter
- */
-static int sattr_read_attr(const char *const fpath,
- unsigned int *attr)
-{
-
- FILE *f;
- char line[PATH_MAX + 1];
- int rc = 0;
-
- f = fopen(fpath, "r");
- if (f == NULL) {
- rc = -errno;
- llapi_error(LLAPI_MSG_ERROR, rc, "Cannot open '%s'", fpath);
- return rc;
- }
-
- if (fgets(line, sizeof(line), f) != NULL) {
- *attr = atoi(line);
- } else {
- llapi_error(LLAPI_MSG_ERROR, errno, "Cannot read from '%s'", fpath);
- rc = 1;
- }
-
- fclose(f);
- return rc;
-}
-
-/*
* Tries to determine the default stripe attributes for a given filesystem. The
* filesystem to check should be specified by fsname, or will be determined
* using pathname.
*/
static int sattr_get_defaults(const char *const fsname,
- const char *const pathname,
unsigned int *scount,
unsigned int *ssize,
unsigned int *soffset)
{
- int rc;
- char dpath[PATH_MAX + 1];
- char fpath[PATH_MAX + 1];
-
- rc = clilovpath(fsname, pathname, dpath);
- if (rc != 0)
- return rc;
+ char val[PATH_MAX];
+ int rc;
- if (scount) {
- snprintf(fpath, PATH_MAX, "%s/stripecount", dpath);
- rc = sattr_read_attr(fpath, scount);
- if (rc != 0)
- return rc;
- }
+ if (scount) {
+ rc = get_lustre_param_value("lov", fsname, FILTER_BY_FS_NAME,
+ "stripecount", val, sizeof(val));
+ if (rc != 0)
+ return rc;
+ *scount = atoi(val);
+ }
- if (ssize) {
- snprintf(fpath, PATH_MAX, "%s/stripesize", dpath);
- rc = sattr_read_attr(fpath, ssize);
- if (rc != 0)
- return rc;
- }
+ if (ssize) {
+ rc = get_lustre_param_value("lov", fsname, FILTER_BY_FS_NAME,
+ "stripesize", val, sizeof(val));
+ if (rc != 0)
+ return rc;
+ *ssize = atoi(val);
+ }
- if (soffset) {
- snprintf(fpath, PATH_MAX, "%s/stripeoffset", dpath);
- rc = sattr_read_attr(fpath, soffset);
- if (rc != 0)
- return rc;
- }
+ if (soffset) {
+ rc = get_lustre_param_value("lov", fsname, FILTER_BY_FS_NAME,
+ "stripeoffset", val, sizeof(val));
+ if (rc != 0)
+ return rc;
+ *soffset = atoi(val);
+ }
- return 0;
+ return 0;
}
/*
* successfully retrieved and stored in tmp before writing to
* cache.
*/
- rc = sattr_get_defaults(fsname_buf, NULL, &tmp[0], &tmp[1],
- &tmp[2]);
+ rc = sattr_get_defaults(fsname_buf, &tmp[0], &tmp[1], &tmp[2]);
if (rc != 0)
return rc;
int llapi_ping(char *obd_type, char *obd_name)
{
- char path[MAX_STRING_SIZE];
- char buf[1];
- int rc, fd;
+ glob_t path;
+ char buf[1];
+ int rc, fd;
- snprintf(path, MAX_STRING_SIZE, "/proc/fs/lustre/%s/%s/ping",
- obd_type, obd_name);
+ rc = cfs_get_param_paths(&path, "%s/%s/ping",
+ obd_type, obd_name);
+ if (rc != 0)
+ return -errno;
- fd = open(path, O_WRONLY);
- if (fd < 0) {
- rc = -errno;
- llapi_error(LLAPI_MSG_ERROR, rc, "error opening %s", path);
- return rc;
- }
+ fd = open(path.gl_pathv[0], O_WRONLY);
+ if (fd < 0) {
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc, "error opening %s",
+ path.gl_pathv[0]);
+ goto failed;
+ }
/* The purpose is to send a byte as a ping, whatever this byte is. */
/* coverity[uninit_use_in_call] */
- rc = write(fd, buf, 1);
- if (rc < 0)
- rc = -errno;
- close(fd);
+ rc = write(fd, buf, 1);
+ if (rc < 0)
+ rc = -errno;
+ close(fd);
- if (rc == 1)
- return 0;
- return rc;
+ if (rc == 1)
+ rc = 0;
+failed:
+ cfs_free_param_data(&path);
+ return rc;
}
int llapi_target_iterate(int type_num, char **obd_type,
void *args, llapi_cb_t cb)
{
- char buf[MAX_STRING_SIZE];
- FILE *fp = fopen(DEVICES_LIST, "r");
- int i, rc = 0;
+ char buf[MAX_STRING_SIZE];
+ int i, rc = 0;
+ glob_t param;
+ FILE *fp;
- if (fp == NULL) {
- rc = -errno;
- llapi_error(LLAPI_MSG_ERROR, rc, "error: opening "DEVICES_LIST);
- return rc;
- }
+ rc = cfs_get_param_paths(¶m, "devices");
+ if (rc != 0)
+ return -ENOENT;
+
+ fp = fopen(param.gl_pathv[0], "r");
+ if (fp == NULL) {
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc, "error: opening '%s'",
+ param.gl_pathv[0]);
+ goto free_path;
+ }
while (fgets(buf, sizeof(buf), fp) != NULL) {
char *obd_type_name = NULL;
cb(obd_type_name, obd_name, obd_uuid, args);
}
- }
- fclose(fp);
- return 0;
+ }
+ fclose(fp);
+free_path:
+ cfs_free_param_data(¶m);
+ return 0;
}
static void do_target_check(char *obd_type_name, char *obd_name,