#include "common/errno.h"
#include "common/strtol.h"
+#ifdef HAVE_SYS_VFS_H
+#include <sys/vfs.h>
+#endif
+
// test if an entire buf is zero in 8-byte chunks
bool buf_is_zero(const char *buf, size_t len)
{
}
return (r * (1LL << modifier));
}
+
+int get_fs_stats(ceph_data_stats_t &stats, const char *path)
+{
+ if (!path)
+ return -EINVAL;
+
+ struct statfs stbuf;
+ int err = ::statfs(path, &stbuf);
+ if (err < 0) {
+ return -errno;
+ }
+
+ stats.byte_total = stbuf.f_blocks * stbuf.f_bsize;
+ stats.byte_used = (stbuf.f_blocks - stbuf.f_bfree) * stbuf.f_bsize;
+ stats.byte_avail = stbuf.f_bavail * stbuf.f_bsize;
+ stats.avail_percent = (((float)stats.byte_avail/stats.byte_total)*100);
+ return 0;
+}
* Ceph - scalable distributed file system
*
* Copyright (C) 2012 Inktank Storage, Inc.
+ * Copyright (C) 2014 Red Hat <contact@redhat.com>
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
// is buf~len completely zero (in 8-byte chunks)
+#include "common/Formatter.h"
#include "include/types.h"
bool buf_is_zero(const char *buf, size_t len);
int64_t unit_to_bytesize(string val, ostream *pss);
+
+struct ceph_data_stats
+{
+ uint64_t byte_total;
+ uint64_t byte_used;
+ uint64_t byte_avail;
+ int avail_percent;
+
+ void dump(Formatter *f) const {
+ assert(f != NULL);
+ f->dump_int("total", byte_total);
+ f->dump_int("used", byte_used);
+ f->dump_int("avail", byte_avail);
+ f->dump_int("avail_percent", avail_percent);
+ }
+};
+typedef struct ceph_data_stats ceph_data_stats_t;
+
+int get_fs_stats(ceph_data_stats_t &stats, const char *path);
#endif /* CEPH_UTIL_H */