Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ILDC Performance Metrics IOCTL #45

Merged
merged 1 commit into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_metrics(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_METRICS_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 compress_ratio;
unsigned __int64 used;
unsigned __int64 available;
unsigned __int64 zpool_allocated;
unsigned __int64 zpool_size;
unsigned __int64 zpool_dedup_ratio;
unsigned __int64 zfs_volSize;

char zpoolHealthState[MAXNAMELEN];
char name[MAXNAMELEN];
}zpool_zfs_metrics;

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 getZvolSize(char* name);
extern void latency_stats(uint64_t *histo, unsigned int buckets,
stat_pair* lat);

Expand Down
51 changes: 51 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,57 @@ zfs_vfs_ref(zfsvfs_t **zfvp)
return (error);
}

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

if (!perf)
return STATUS_INVALID_PARAMETER;

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

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

perf->used = getUsedData(perf->name);
perf->compress_ratio = getCompressRatio(perf->name);
perf->available = getAvail(perf->name);

if (is_zpool == 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);
perf->zpool_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);

perf->zpool_allocated = vs.vs_alloc;
perf->zpool_size = vs.vs_space;
strcpy(perf->zpoolHealthState, healthState);

}
else
perf->zfs_volSize = getZvolSize(perf->name);

Irp->IoStatus.Information = sizeof(zpool_zfs_metrics);
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_METRICS_DATA:
dprintf("ZPOOL_ZFS_GET_METRICS_DATA\n");
Status = zpool_zfs_get_metrics(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
getZvolSize(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