Skip to content

Commit

Permalink
ILDC Performance Metrics IOCTL
Browse files Browse the repository at this point in the history
  • Loading branch information
datacore-skumar committed Apr 20, 2022
1 parent f4459f9 commit 73d58d6
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/os/windows/zfs/sys/zfs_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,8 @@ extern NTSTATUS zpool_get_size_stats(PDEVICE_OBJECT DeviceObject, PIRP Irp,
PIO_STACK_LOCATION IrpSp);
extern NTSTATUS zpool_get_iops_thrput(PDEVICE_OBJECT DeviceObject, PIRP Irp,
PIO_STACK_LOCATION IrpSp);
extern NTSTATUS zpool_zfs_get_data(PDEVICE_OBJECT DeviceObject, PIRP Irp,
PIO_STACK_LOCATION IrpSp);


#endif
18 changes: 18 additions & 0 deletions include/sys/zfs_ioctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ typedef struct {
} zpool_size_stats;

#define ZPOOL_GET_IOPS_THRPUT_STATS CTL_CODE(ZFSIOCTL_TYPE, 0xFFE, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define ZPOOL_ZFS_GET_STATS_DATA CTL_CODE(ZFSIOCTL_TYPE, 0xFFD, METHOD_BUFFERED, FILE_ANY_ACCESS)

typedef struct
{
Expand Down Expand Up @@ -582,6 +583,19 @@ typedef struct {
char zpool_name[MAXNAMELEN];
} zpool_perf_counters;

typedef struct {
unsigned __int64 zpool_alloc; /* allocated */
unsigned __int64 zpool_space; /* size */
unsigned __int64 zpool_dedup_ratio;
unsigned __int64 compress_ratio;
unsigned __int64 used;
unsigned __int64 available;
unsigned __int64 zfs_volSize;

char healthState[MAXNAMELEN];
char name[MAXNAMELEN];
}zpool_zfs_get;

typedef struct {
uint64_t arcstat_hits;
uint64_t arcstat_misses;
Expand Down Expand Up @@ -651,6 +665,10 @@ extern void zfs_unmount_snap(const char *);
extern void zfs_destroy_unmount_origin(const char *);
extern int getzfsvfs_impl(struct objset *, struct zfsvfs **);
extern int getzfsvfs(const char *, struct zfsvfs **);
extern int getUsedData(char * name);
extern int getCompressRatio(char* name);
extern int getAvail(char* name);
extern uint64_t getVolSize(char* name);
extern void latency_stats(uint64_t *histo, unsigned int buckets,
stat_pair* lat);

Expand Down
57 changes: 57 additions & 0 deletions module/os/windows/zfs/zfs_ioctl_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,63 @@ zfs_vfs_ref(zfsvfs_t **zfvp)
return (error);
}

NTSTATUS zpool_zfs_get_data(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
{
if (IrpSp->Parameters.DeviceIoControl.OutputBufferLength < sizeof(zpool_zfs_get)) {
Irp->IoStatus.Information = sizeof(zpool_zfs_get);
return STATUS_BUFFER_TOO_SMALL;
}
zpool_zfs_get* perf = (zpool_zfs_get*)Irp->AssociatedIrp.SystemBuffer;

if (!perf)
return STATUS_INVALID_PARAMETER;

perf->name[MAXNAMELEN - 1] = '\0';

char* name_buf = perf->name;
int flag = 0;
if (strchr(name_buf, '/') != NULL) {
flag = 1;
}

mutex_enter(&spa_namespace_lock);
spa_t* spa_perf;
if ((spa_perf = spa_lookup(perf->name)) == NULL) {
mutex_exit(&spa_namespace_lock);
return STATUS_NOT_FOUND;
}
vdev_stat_t vs = { 0 };
vdev_stat_ex_t vsx = { 0 };
spa_config_enter(spa_perf, SCL_ALL, FTAG, RW_READER);
vdev_get_stats_ex(spa_perf->spa_root_vdev, &vs, &vsx);
uint64_t dedup_ratio = ddt_get_pool_dedup_ratio(spa_perf);
const char* healthState = spa_state_to_name(spa_perf);
spa_config_exit(spa_perf, SCL_ALL, FTAG);
mutex_exit(&spa_namespace_lock);

int used = getUsedData(name_buf);
int compress_ratio = getCompressRatio(name_buf);
int available = getAvail(name_buf);
uint64_t zfs_volSize = getVolSize(name_buf);

if (flag != 1) {
perf->zpool_alloc = vs.vs_alloc;
perf->zpool_space = vs.vs_space;
perf->zpool_dedup_ratio = dedup_ratio;
strcpy(perf->healthState, healthState);
}
perf->compress_ratio = compress_ratio;
perf->used = used;
perf->available = available;

if (flag == 1)
perf->zfs_volSize = zfs_volSize;

Irp->IoStatus.Information = sizeof(zpool_zfs_get);
return STATUS_SUCCESS;
}


NTSTATUS zpool_get_iops_thrput(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
{
if (IrpSp->Parameters.DeviceIoControl.OutputBufferLength < sizeof(zpool_perf_counters)) {
Expand Down
4 changes: 4 additions & 0 deletions module/os/windows/zfs/zfs_vnops_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -4664,6 +4664,10 @@ _Function_class_(DRIVER_DISPATCH)
dprintf("ZPOOL_GET_IOPS_THRPUT_STATS\n");
Status = zpool_get_iops_thrput(DeviceObject, Irp, IrpSp);
break;
case ZPOOL_ZFS_GET_STATS_DATA:
dprintf("ZPOOL_ZFS_GET_STATS_DATA\n");
Status = zpool_zfs_get_data(DeviceObject, Irp, IrpSp);
break;
default:
dprintf("**** unknown Windows IOCTL: 0x%lx\n",
cmd);
Expand Down
63 changes: 63 additions & 0 deletions module/zfs/zfs_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2143,6 +2143,69 @@ zfs_ioc_objset_stats(zfs_cmd_t *zc)
return (error);
}


static int
getUsedData(char* name)
{
int error;
objset_t* os;
uint64_t val;
error = dmu_objset_hold(name, FTAG, &os);
if (error == 0) {
dsl_dataset_t* ds = os->os_dsl_dataset;
val = dsl_get_used(ds);
dmu_objset_rele(os, FTAG);
}
return val;
}

static int
getCompressRatio(char* name)
{
int error;
objset_t* os;
uint64_t val;
error = dmu_objset_hold(name, FTAG, &os);
if (error == 0) {
dsl_dataset_t* ds = os->os_dsl_dataset;
val = dsl_get_compressratio(ds);
dmu_objset_rele(os, FTAG);
}
return val;
}

static int
getAvail(char* name)
{
int error;
objset_t* os;
uint64_t val;
error = dmu_objset_hold(name, FTAG, &os);
if (error == 0) {
dsl_dataset_t* ds = os->os_dsl_dataset;
val = dsl_get_available(ds);
dmu_objset_rele(os, FTAG);
}
return val;
}

static uint64_t
getVolSize(char* name)
{
int error;
uint64_t val;
objset_t* os;
uint64_t volSize;
error = dmu_objset_hold(name, FTAG, &os);
if (error == 0) {
zap_lookup(os, ZVOL_ZAP_OBJ, "size", 8, 1, &val);
volSize = val;
dmu_objset_rele(os, FTAG);
}
return volSize;
}


/*
* inputs:
* zc_name name of filesystem
Expand Down

0 comments on commit 73d58d6

Please sign in to comment.