WIP: Add info command
This just reads the sysfs nodes and presents the information in a convenient way.
This commit is contained in:
parent
d3d581ecb6
commit
d87de4e238
1
Makefile
1
Makefile
|
@ -81,6 +81,7 @@ LIB_SRCS := \
|
|||
open.c \
|
||||
resize.c \
|
||||
stats.c \
|
||||
info.c \
|
||||
tune.c \
|
||||
util.c
|
||||
BIN_SRCS := \
|
||||
|
|
26
cbd/cbd.c
26
cbd/cbd.c
|
@ -489,6 +489,31 @@ do_stats(int argc, char** argv)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
do_info(int argc, char** argv)
|
||||
{
|
||||
const char* name;
|
||||
struct cbd_info info;
|
||||
|
||||
if (argc != 2) {
|
||||
usage();
|
||||
}
|
||||
name = argv[1];
|
||||
|
||||
cbd_info(name, &info);
|
||||
printf("Info:\n");
|
||||
printf("pblk used: %u%% (%lu of %lu)\n",
|
||||
(unsigned int)((100 * info.pblk_used) / info.pblk_total),
|
||||
(unsigned long)info.pblk_used,
|
||||
(unsigned long)info.pblk_total);
|
||||
printf("lblk used: %u%% (%lu of %lu)\n",
|
||||
(unsigned int)((100 * info.lblk_used) / info.lblk_total),
|
||||
(unsigned long)info.lblk_used,
|
||||
(unsigned long)info.lblk_total);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
do_tune(int argc, char** argv)
|
||||
{
|
||||
|
@ -563,6 +588,7 @@ static struct cmd_dispatch dispatch[] =
|
|||
{ "check", do_check },
|
||||
{ "resize", do_resize },
|
||||
{ "stats", do_stats },
|
||||
{ "info", do_info },
|
||||
{ "tune", do_tune },
|
||||
};
|
||||
|
||||
|
|
|
@ -71,6 +71,22 @@ typedef enum {
|
|||
t_none
|
||||
} tristate_t;
|
||||
|
||||
struct cbd_info {
|
||||
u64 lbatpblk_r;
|
||||
u64 lbatpblk_w;
|
||||
u64 lbd_r;
|
||||
u64 lbd_w;
|
||||
u64 lblk_size;
|
||||
u64 lblk_total;
|
||||
u64 lblk_used;
|
||||
u64 pbat_r;
|
||||
u64 pbat_w;
|
||||
u64 pblk_total;
|
||||
u64 pblk_used;
|
||||
u64 zone_init;
|
||||
u64 zone_total;
|
||||
};
|
||||
|
||||
int cbd_format(const char* dev,
|
||||
uint16_t flags,
|
||||
enum cbd_alg alg, uint level,
|
||||
|
@ -83,6 +99,8 @@ int cbd_open(const char* dev,
|
|||
int cbd_close(const char* name);
|
||||
int cbd_stats(const char* dev,
|
||||
struct cbd_stats* stats);
|
||||
int cbd_info(const char* dev,
|
||||
struct cbd_info* info);
|
||||
int cbd_check(const char* dev,
|
||||
bool force,
|
||||
tristate_t auto_response,
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
#include <libcbd.h>
|
||||
|
||||
#include <cbdutil.h>
|
||||
|
||||
static u64
|
||||
get_sysfs_value(const char* dirname, const char* filename)
|
||||
{
|
||||
char pathname[PATH_MAX];
|
||||
int fd;
|
||||
char buf[80];
|
||||
|
||||
sprintf(pathname, "%s/%s", dirname, filename);
|
||||
fd = open(pathname, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
error("Cannot open device\n");
|
||||
}
|
||||
if (read(fd, buf, sizeof(buf)) < 1) {
|
||||
error("Cannot read device\n");
|
||||
}
|
||||
close(fd);
|
||||
return (u64)strtoul(buf, NULL, 10);
|
||||
}
|
||||
|
||||
int
|
||||
cbd_info(const char* dev, struct cbd_info* info)
|
||||
{
|
||||
char dirname[PATH_MAX];
|
||||
|
||||
sprintf(dirname, "/sys/fs/compress/%s", dev);
|
||||
|
||||
info->lbatpblk_r = get_sysfs_value(dirname, "lbatpblk_r");
|
||||
info->lbatpblk_w = get_sysfs_value(dirname, "lbatpblk_w");
|
||||
info->lbd_r = get_sysfs_value(dirname, "lbd_r");
|
||||
info->lbd_w = get_sysfs_value(dirname, "lbd_w");
|
||||
info->lblk_size = get_sysfs_value(dirname, "lblk_size");
|
||||
info->lblk_total = get_sysfs_value(dirname, "lblk_total");
|
||||
info->lblk_used = get_sysfs_value(dirname, "lblk_used");
|
||||
info->pbat_r = get_sysfs_value(dirname, "pbat_r");
|
||||
info->pbat_w = get_sysfs_value(dirname, "pbat_w");
|
||||
info->pblk_total = get_sysfs_value(dirname, "pblk_total");
|
||||
info->pblk_used = get_sysfs_value(dirname, "pblk_used");
|
||||
info->zone_init = get_sysfs_value(dirname, "zone_init");
|
||||
info->zone_total = get_sysfs_value(dirname, "zone_total");
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue