Skip to content

Commit

Permalink
Update compile VERSION and set it in registry (#233)
Browse files Browse the repository at this point in the history
When the kernel driver is initialised, set the compile time version
string in the registry.
System\\ControlSet001\\Services\\ZFSin\\version

Update the userland "zpool version" to query registry for kernel
version (via registry):

$ zpool version
zfs-0.2.3-1
zfs-kmod-0.2.3-1

We should also update ZFS_META_RELEASE with the git rev like upstream
does. It is generally set to the last section in the output of
git describe --always --long

It is unknown to me how Visual Studio could do that currently.

Eventually, it will look like:

zfs-1.9.4-0-gfa24877f83
  • Loading branch information
lundman authored Apr 1, 2020
1 parent b31f7bc commit 15406fa
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 17 deletions.
38 changes: 28 additions & 10 deletions ZFSin/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,6 @@ void spl_create_hostid(HANDLE h, PUNICODE_STRING pRegistryPath)
UNICODE_STRING AttachKey;
RtlInitUnicodeString(&AttachKey, L"hostid");

ULONG Length;
Length = sizeof(KEY_VALUE_FULL_INFORMATION) + AttachKey.Length * sizeof(WCHAR) + sizeof(unsigned long);

PKEY_VALUE_FULL_INFORMATION keyValue;
keyValue = ExAllocatePoolWithTag(NonPagedPoolNx,
Length,
'geRa');

random_get_bytes(&spl_hostid, sizeof(spl_hostid));

Status = ZwSetValueKey(
Expand All @@ -125,11 +117,34 @@ void spl_create_hostid(HANDLE h, PUNICODE_STRING pRegistryPath)
spl_hostid = 0;
}

ExFreePoolWithTag(keyValue, 'geRa');

KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "SPL: created hostid 0x%04x\n", spl_hostid));
}

// Whenever we start up, write the version string to registry.
#include <../zfs_config.h>

void spl_update_version(HANDLE h, PUNICODE_STRING pRegistryPath)
{
NTSTATUS Status;

UNICODE_STRING AttachKey;
UNICODE_STRING ValueKey;
RtlInitUnicodeString(&AttachKey, L"version");
RtlInitUnicodeString(&ValueKey, L""ZFS_META_VERSION "-" ZFS_META_RELEASE);

Status = ZwSetValueKey(
h,
&AttachKey,
0,
REG_SZ,
ValueKey.Buffer,
ValueKey.Length
);

if (!NT_SUCCESS(Status)) {
KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "%s: Unable to create Registry %wZ/version: 0x%x. hostid unset.\n", __func__, pRegistryPath, Status));
}
}

int spl_check_assign_types(kstat_named_t *kold, PKEY_VALUE_FULL_INFORMATION regBuffer)
{
Expand Down Expand Up @@ -288,6 +303,9 @@ int spl_kstat_registry(PUNICODE_STRING pRegistryPath, kstat_t *ksp)
spl_create_hostid(h, pRegistryPath);
}

// Make sure version is updated
spl_update_version(h, pRegistryPath);

ZwClose(h);
return (changed);
}
Expand Down
2 changes: 1 addition & 1 deletion ZFSin/spl/spl_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
#define SPL_META_RELEASE "7-gc1b4a00"

/* Define the project version. */
#define SPL_META_VERSION "1.6.0"
#define SPL_META_VERSION "0.2.3"

/* Define ZFS_BOOT to enable kext load at boot */
#define ZFS_BOOT 1
Expand Down
20 changes: 18 additions & 2 deletions ZFSin/zfs/lib/libzfs/libzfs_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -2235,14 +2235,30 @@ zfs_version_userland(char *version, int len)
* Fill given version buffer with zfs kernel version read from ZFS_SYSFS_DIR
* Returns 0 on success, and -1 on error (with errno set)
* "zfs.kext_version: 1.9.0-1"
* "zfs-kmod-0.8.1-1"
*/
int
zfs_version_kernel(char *version, int len)
{
size_t rlen = len;
HKEY hKey; // SYSTEM\ControlSet001\Services\ZFSin
LSTATUS status = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SYSTEM\\ControlSet001\\Services\\ZFSin", 0, KEY_READ, &hKey);

snprintf(version, len, "port me!");
if (status != ERROR_SUCCESS)
return -1;

DWORD count = len;
DWORD type;

status = RegQueryValueExA(hKey, "version", 0, &type, version, &count);

RegCloseKey(hKey);

if (status == ERROR_SUCCESS &&
(type == REG_SZ)) {
return 0;
}

snprintf(version, len, "(registry lookup failed)");
return (0);
}

Expand Down
7 changes: 3 additions & 4 deletions ZFSin/zfs/zfs_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@
/* zfs debugging enabled */
/* #undef ZFS_DEBUG */

/* Define the project alias string. */
#define ZFS_META_ALIAS "zfs-1.6.0-1"

/* Define the project author. */
#define ZFS_META_AUTHOR "OpenZFS on OS X"

Expand All @@ -92,5 +89,7 @@
#define ZFS_META_RELEASE "1"

/* Define the project version. */
#define ZFS_META_VERSION "1.6.0"
#define ZFS_META_VERSION "0.2.3"

/* Define the project alias string. */
#define ZFS_META_ALIAS "zfs-" ZFS_META_VERSION "-" ZFS_META_RELEASE

0 comments on commit 15406fa

Please sign in to comment.