* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*
- * Copyright (c) 2011, 2015, Intel Corporation.
+ * Copyright (c) 2011, 2016, Intel Corporation.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
int llapi_get_obd_count(char *mnt, int *count, int is_mdt)
{
- DIR *root;
- int rc;
+ int root;
+ int rc;
- root = opendir(mnt);
- if (!root) {
- rc = -errno;
- llapi_error(LLAPI_MSG_ERROR, rc, "open %s failed", mnt);
- return rc;
- }
+ root = open(mnt, O_RDONLY | O_DIRECTORY);
+ if (root < 0) {
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc, "open %s failed", mnt);
+ return rc;
+ }
- *count = is_mdt;
- rc = ioctl(dirfd(root), LL_IOC_GETOBDCOUNT, count);
- if (rc < 0)
- rc = -errno;
+ *count = is_mdt;
+ rc = ioctl(root, LL_IOC_GETOBDCOUNT, count);
+ if (rc < 0)
+ rc = -errno;
- closedir(root);
- return rc;
+ close(root);
+ return rc;
}
/* Check if user specified value matches a real uuid. Ignore _UUID,
/* Here, param->fp_obd_uuid points to a single obduuid, the index of which is
* returned in param->fp_obd_index */
-static int setup_obd_uuid(DIR *dir, char *dname, struct find_param *param)
+static int setup_obd_uuid(int fd, char *dname, struct find_param *param)
{
struct obd_uuid obd_uuid;
char buf[PATH_MAX];
/* Get the lov/lmv name */
if (param->fp_get_lmv)
- rc = llapi_file_fget_lmv_uuid(dirfd(dir), &obd_uuid);
+ rc = llapi_file_fget_lmv_uuid(fd, &obd_uuid);
else
- rc = llapi_file_fget_lov_uuid(dirfd(dir), &obd_uuid);
+ rc = llapi_file_fget_lov_uuid(fd, &obd_uuid);
if (rc) {
if (rc != -ENOTTY) {
llapi_error(LLAPI_MSG_ERROR, rc,
int llapi_ostlist(char *path, struct find_param *param)
{
- DIR *dir;
- int ret;
+ int fd;
+ int ret;
- dir = opendir(path);
- if (dir == NULL)
- return -errno;
+ fd = open(path, O_RDONLY | O_DIRECTORY);
+ if (fd < 0)
+ return -errno;
- ret = setup_obd_uuid(dir, path, param);
- closedir(dir);
+ ret = setup_obd_uuid(fd, path, param);
+ close(fd);
- return ret;
+ return ret;
}
/*
if (param->fp_obd_uuid) {
param->fp_quiet = 1;
- ret = setup_obd_uuid(d ? d : parent, path, param);
- if (ret)
- return ret;
- }
+ ret = setup_obd_uuid(d ? dirfd(d) : dirfd(parent), path, param);
+ if (ret)
+ return ret;
+ }
if (d) {
if (param->fp_get_lmv || param->fp_get_default_lmv) {
cb_common_fini, param);
}
-int llapi_obd_statfs(char *path, __u32 type, __u32 index,
- struct obd_statfs *stat_buf,
- struct obd_uuid *uuid_buf)
+int llapi_obd_fstatfs(int fd, __u32 type, __u32 index,
+ struct obd_statfs *stat_buf, struct obd_uuid *uuid_buf)
{
- int fd;
char raw[OBD_MAX_IOCTL_BUFFER] = {'\0'};
char *rawbuf = raw;
struct obd_ioctl_data data = { 0 };
return rc;
}
- fd = open(path, O_RDONLY);
- if (errno == EISDIR)
- fd = open(path, O_DIRECTORY | O_RDONLY);
+ rc = ioctl(fd, IOC_OBD_STATFS, (void *)rawbuf);
+ return rc < 0 ? -errno : 0;
+}
+
+int llapi_obd_statfs(char *path, __u32 type, __u32 index,
+ struct obd_statfs *stat_buf, struct obd_uuid *uuid_buf)
+{
+ int fd;
+ int rc;
+
+ fd = open(path, O_RDONLY);
if (fd < 0) {
- rc = errno ? -errno : -EBADF;
+ rc = -errno;
llapi_error(LLAPI_MSG_ERROR, rc, "error: %s: opening '%s'",
__func__, path);
/* If we can't even open a file on the filesystem (e.g. with
* -ESHUTDOWN), force caller to exit or it will loop forever. */
return -ENODEV;
}
- rc = ioctl(fd, IOC_OBD_STATFS, (void *)rawbuf);
- if (rc)
- rc = errno ? -errno : -EINVAL;
+
+ rc = llapi_obd_fstatfs(fd, type, index, stat_buf, uuid_buf);
close(fd);
+
return rc;
}
int llapi_quotactl(char *mnt, struct if_quotactl *qctl)
{
- DIR *root;
- int rc;
+ char fsname[PATH_MAX + 1];
+ int root;
+ int rc;
- root = opendir(mnt);
- if (!root) {
- rc = -errno;
- llapi_error(LLAPI_MSG_ERROR, rc, "open %s failed", mnt);
- return rc;
- }
+ rc = llapi_search_fsname(mnt, fsname);
+ if (rc) {
+ llapi_err_noerrno(LLAPI_MSG_ERROR,
+ "'%s' isn't on Lustre filesystem", mnt);
+ return rc;
+ }
- rc = ioctl(dirfd(root), OBD_IOC_QUOTACTL, qctl);
- if (rc < 0)
- rc = -errno;
+ root = open(mnt, O_RDONLY | O_DIRECTORY);
+ if (root < 0) {
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc, "open %s failed", mnt);
+ return rc;
+ }
- closedir(root);
- return rc;
+ rc = ioctl(root, OBD_IOC_QUOTACTL, qctl);
+ if (rc < 0)
+ rc = -errno;
+
+ close(root);
+ return rc;
}
/* Print mdtname 'name' into 'buf' using 'format'. Add -MDT0000 if needed.
int llapi_get_connect_flags(const char *mnt, __u64 *flags)
{
- DIR *root;
- int rc;
+ int root;
+ int rc;
- root = opendir(mnt);
- if (!root) {
- rc = -errno;
- llapi_error(LLAPI_MSG_ERROR, rc, "open %s failed", mnt);
- return rc;
- }
+ root = open(mnt, O_RDONLY | O_DIRECTORY);
+ if (root < 0) {
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc, "open %s failed", mnt);
+ return rc;
+ }
- rc = ioctl(dirfd(root), LL_IOC_GET_CONNECT_FLAGS, flags);
- if (rc < 0) {
- rc = -errno;
- llapi_error(LLAPI_MSG_ERROR, rc,
- "ioctl on %s for getting connect flags failed", mnt);
- }
- closedir(root);
- return rc;
+ rc = ioctl(root, LL_IOC_GET_CONNECT_FLAGS, flags);
+ if (rc < 0) {
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "ioctl on %s for getting connect flags failed", mnt);
+ }
+ close(root);
+ return rc;
}
/**