int stripe_count, int stripe_pattern,
const char *poolname);
int llapi_direntry_remove(char *dname);
+
+int llapi_obd_fstatfs(int fd, __u32 type, __u32 index,
+ struct obd_statfs *stat_buf, struct obd_uuid *uuid_buf);
extern int llapi_obd_statfs(char *path, __u32 type, __u32 index,
struct obd_statfs *stat_buf,
struct obd_uuid *uuid_buf);
__u64 ost_ffree = 0;
__u32 index;
__u32 type;
- int rc;
+ int fd;
+ int rc = 0;
+ int rc2;
if (pool) {
poolname = strchr(pool, '.');
poolname = pool;
}
+ fd = open(mntdir, O_RDONLY);
+ if (fd < 0) {
+ rc = -errno;
+ fprintf(stderr, "%s: cannot open '%s': %s\n", progname, mntdir,
+ strerror(errno));
+ return rc;
+ }
+
if (ishow)
printf(UUF" "CSF" "CSF" "CSF" "RSF" %-s\n",
"UUID", "Inodes", "IUsed", "IFree",
memset(&stat_buf, 0, sizeof(struct obd_statfs));
memset(&uuid_buf, 0, sizeof(struct obd_uuid));
type = lazy ? tp->st_op | LL_STATFS_NODELAY : tp->st_op;
- rc = llapi_obd_statfs(mntdir, type, index,
- &stat_buf, &uuid_buf);
- if (rc == -ENODEV)
- break;
-
- if (rc == -EAGAIN)
+ rc2 = llapi_obd_fstatfs(fd, type, index,
+ &stat_buf, &uuid_buf);
+ if (rc2 == -ENODEV)
+ break;
+ else if (rc2 == -EAGAIN)
continue;
+ else if (rc2 == -ENODATA)
+ ; /* Inactive device, OK. */
+ else if (rc2 < 0 && rc == 0)
+ rc = rc2;
if (poolname && tp->st_op == LL_STATFS_LOV &&
llapi_search_ost(fsname, poolname,
if (uuid_buf.uuid[0] == '\0')
sprintf(uuid_buf.uuid, "%s%04x",
tp->st_name, index);
- showdf(mntdir, &stat_buf, obd_uuid2str(&uuid_buf),
- ishow, cooked, tp->st_name, index, rc);
+ showdf(mntdir, &stat_buf, obd_uuid2str(&uuid_buf),
+ ishow, cooked, tp->st_name, index, rc2);
- if (rc == 0) {
+ if (rc2 == 0) {
if (tp->st_op == LL_STATFS_LMV) {
sum.os_ffree += stat_buf.os_ffree;
sum.os_files += stat_buf.os_files;
stat_buf.os_bsize;
ost_ffree += stat_buf.os_ffree;
}
- } else if (rc == -EINVAL || rc == -EFAULT) {
- break;
}
}
}
+ close(fd);
+
/* If we don't have as many objects free on the OST as inodes
* on the MDS, we reduce the total number of inodes to
* compensate, so that the "inodes in use" number is correct.
printf("\n");
showdf(mntdir, &sum, "filesystem summary:", ishow, cooked, NULL, 0, 0);
printf("\n");
- return 0;
+
+ return rc;
}
static int lfs_df(int argc, char **argv)
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;
}
+ 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;
* -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;
}