Skip to content

Commit 4b4dc10

Browse files
committed
Initial commit
Signed-off-by: Alin Gabriel Serdean <[email protected]>
0 parents  commit 4b4dc10

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+9602
-0
lines changed

.gitignore

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#*#
2+
*.a
3+
*.d
4+
*.gcno
5+
*.gcda
6+
*.ko
7+
*.la
8+
*.lo
9+
*.loT
10+
*.mod.c
11+
*.o
12+
*.obj
13+
*.exe
14+
*.exp
15+
*.ilk
16+
*.lib
17+
*.pdb
18+
*.pyc
19+
*.retry
20+
*.so
21+
*.suo
22+
**/*.sym
23+
*~
24+
*,cover
25+
.#*
26+
.*.cmd
27+
.*.swp
28+
Module.symvers
29+
TAGS
30+
cscope.*
31+
tags
32+
*/.vs
33+
/vstudio/x64/
34+
/lib/ksocket_wsk/x64/
35+
/userspace/userspace/x64/
36+

Dockerfile/Dockerfile

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# escape=`
2+
3+
ARG WIN_VER="ltsc2019"
4+
5+
FROM mcr.microsoft.com/windows/servercore:$WIN_VER
6+
7+
ADD https://aka.ms/vs/16/release/vs_buildtools.exe C:\TEMP\vs_buildtools.exe
8+
ADD https://chocolatey.org/install.ps1 C:\TEMP\choco-install.ps1
9+
ADD https://go.microsoft.com/fwlink/?linkid=2085767 C:\TEMP\wdksetup.exe
10+
11+
# Let's be explicit about the shell that we're going to use.
12+
SHELL ["cmd", "/S", "/C"]
13+
14+
# Install Build Tools. A 3010 error signals that requested operation is
15+
# successfull but changes will not be effective until the system is rebooted.
16+
RUN C:\TEMP\vs_buildtools.exe --quiet --wait --norestart --nocache `
17+
--installPath C:\BuildTools `
18+
--add Microsoft.VisualStudio.Workload.VCTools `
19+
--add Microsoft.VisualStudio.Workload.MSBuildTools `
20+
--add Microsoft.VisualStudio.Component.VC.Runtimes.x86.x64.Spectre `
21+
--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 `
22+
--add Microsoft.VisualStudio.Component.Windows10SDK.18362 `
23+
--add Microsoft.VisualStudio.Component.VC.14.24.x86.x64 `
24+
--add Microsoft.VisualStudio.Component.VC.14.24.x86.x64.Spectre `
25+
|| IF "%ERRORLEVEL%"=="3010" EXIT 0
26+
27+
RUN powershell C:\TEMP\choco-install.ps1
28+
29+
RUN choco install git -y
30+
31+
# Install WDK excluding WDK.vsix.
32+
RUN C:\TEMP\wdksetup.exe /q
33+
34+
# Install WDK.vsix in manual manner.
35+
RUN copy "C:\Program Files (x86)\Windows Kits\10\Vsix\VS2019\WDK.vsix" C:\TEMP\wdkvsix.zip
36+
RUN powershell Expand-Archive C:\TEMP\wdkvsix.zip -DestinationPath C:\TEMP\wdkvsix
37+
RUN robocopy.exe /e "C:\temp\wdkvsix\$MSBuild\Microsoft\VC\v160" "C:\BuildTools\MSBuild\Microsoft\VC\v160" || EXIT 0
38+
39+
SHELL ["cmd"]
40+
41+
CMD [ "cmd","/k","c:\\BuildTools\\VC\\Auxiliary\\Build\\vcvarsall.bat", "x86_x64", "10.0.18362.0" ]

Dockerfile/Readme.md

+415
Large diffs are not rendered by default.

LICENSE

+504
Large diffs are not rendered by default.

README.md

+168
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
Windows Network Block Device (WNBD)
2+
===================================
3+
4+
Build Status:
5+
-------------
6+
[![Build status](https://ci.appveyor.com/api/projects/status/2m73dxm2t7s7jlit/branch/master?svg=true)](https://ci.appveyor.com/project/aserdean/wnbd/branch/master)
7+
8+
9+
What is WNBD?
10+
-------------
11+
12+
WNBD is a client side implementation of [Network Block Device](https://nbd.sourceforge.io/)
13+
14+
Prerequisites
15+
-------------
16+
17+
Visual Studio 2019 build tools or GUI ([Community version](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=Community&rel=16) or above)
18+
19+
[Windows Driver Kit 1909](https://docs.microsoft.com/en-us/windows-hardware/drivers/download-the-wdk)
20+
21+
Folders
22+
-------
23+
24+
* <a href="Dockerfile/">Dockerfile</a> contains a Dockerfile to create a Docker image that contains needed prerequisites
25+
26+
* <a href="driver/">driver</a> contains the driver sources
27+
28+
* <a href="lib/ksocket_wsk/">ksocket_wsk</a> contains the WSK implementation needed to communicate with the Network Block Device server
29+
30+
* <a href="userspace/userspace/">userspace</a> contains a simple console application `wnbd-client` useful for testing
31+
32+
* <a href="vstudio/">vstudio</a> contains the Visual Studio solution file and its projects
33+
34+
How to build
35+
------------
36+
37+
```
38+
> git clone https://github.com/aserdean/wnbd
39+
> msbuild wnbd\vstudio\wnbd.sln
40+
> copy wnbd\vstudio\x64\Debug\driver\* .
41+
> copy wnbd\vstudio\x64\Debug\wnbd-client.exe .
42+
```
43+
44+
* You can download the latest prebuilt packages from Appveyor via the links:
45+
* [Debug](https://ci.appveyor.com/api/projects/aserdean/wnbd/artifacts/wnbd-Debug.zip?job=Configuration%3A+Debug)
46+
* [Release](https://ci.appveyor.com/api/projects/aserdean/wnbd/artifacts/wnbd-Release.zip?job=Configuration%3A+Release)
47+
48+
How to install
49+
--------------
50+
51+
* **Prerequisites**.
52+
53+
After building, the driver is automatically test signed. To install the built driver you must make sure that your target machine is Test Signed enabled first.
54+
To enable Test Signing on your target machine, please issue the following from an elevated command prompt:
55+
```
56+
> bcdedit.exe /set testsigning yes
57+
```
58+
Please note that you can enable driver signing only if Secure Boot is not enabled on the target machine.
59+
To check if your target machine does not have Secure Boot enabled issue `Confirm-SecureBootUEFI` from an elevated powershell prompt
60+
```
61+
PS C:\WINDOWS\system32> Confirm-SecureBootUEFI
62+
False
63+
```
64+
65+
* **Installation/removal**.
66+
67+
We require [devcon.exe](https://cloudbase.it/downloads/devcon.exe) utility to install and uninstall the driver.
68+
69+
* To **install** the driver issue the following from an elevated command prompt:
70+
```
71+
> .\devcon.exe install .\wnbd.inf root\wnbd
72+
```
73+
(The command above assumes that the utility `devcon.exe` and the driver files `wnbd.inf`, `wnbd.cat`, `wnbd.sys` are in the current directory)
74+
75+
* To **uninstall** the driver issue the following from an elevated command prompt:
76+
```
77+
.\devcon.exe remove "root\wnbd"
78+
```
79+
(The command above assumes that the utility `devcon.exe` is in the current directory)
80+
81+
For convenience, we included <a href="vstudio/reinstall.cmd">reinstall.cmd</a> which uninstalls (ignoring the error) and installs the driver again.
82+
83+
[Ceph integration](https://docs.ceph.com/docs/master/man/8/rbd-nbd/) [`rbd-nbd`](https://github.com/cloudbase/ceph/tree/windows)
84+
--------------------------
85+
86+
87+
Testing with NBD (Network Block Device)
88+
---------------------------------------
89+
90+
We assume you are familiar with <a href="https://github.com/NetworkBlockDevice/nbd#using-nbd">using NBD</a>.
91+
92+
* `wnbd-client` syntax
93+
```
94+
PS C:\workspace> .\wnbd-client.exe
95+
Syntax:
96+
wnbd-client map <InstanceName> <HostName> <PortName> <ExportName> <DoNotNegotiate>
97+
wnbd-client unmap <InstanceName>
98+
wnbd-client list
99+
```
100+
101+
* NBD server configuration:
102+
```
103+
root@ubuntu-Virtual-Machine:/home/ubuntu# cat /etc/nbd-server/config
104+
[generic]
105+
# If you want to run everything as root rather than the nbd user, you
106+
# may either say "root" in the two following lines, or remove them
107+
# altogether. Do not remove the [generic] section, however.
108+
port = 9000
109+
user = nbd
110+
group = nbd
111+
includedir = /etc/nbd-server/conf.d
112+
113+
# What follows are export definitions. You may create as much of them as
114+
# you want, but the section header has to be unique.
115+
116+
[foo]
117+
exportname = /blaz/bla.img
118+
port = 9000
119+
copyonwrite = true
120+
root@ubuntu-Virtual-Machine:/home/ubuntu# ifconfig eth0 | grep 172
121+
inet 172.17.160.251 netmask 255.255.255.240 broadcast 172.17.160.255
122+
```
123+
124+
* Mapping an export:
125+
```
126+
PS C:\workspace> .\wnbd-client.exe map test2 172.17.160.251 9000 foo
127+
InstanceName=test2
128+
HostName=172.17.160.251
129+
PortName=9000
130+
ExportName=foo
131+
MustNegociate=1
132+
PS C:\workspace> Get-Disk
133+
134+
Number Friendly Name Serial Number HealthStatus OperationalStatus Total Size Partition
135+
Style
136+
------ ------------- ------------- ------------ ----------------- ---------- ----------
137+
0 Msft Virtual Disk Healthy Online 127 GB GPT
138+
1 WNBD Dis WNBD_DISK_ID test2 Healthy Online 256 MB RAW
139+
```
140+
141+
* Listing the mapped device
142+
```
143+
PS C:\workspace> .\wnbd-client.exe list
144+
Status: 0
145+
InstanceName Pid DiskNumber
146+
test2 6712 1
147+
```
148+
149+
* Unmapping the device
150+
```
151+
PS C:\workspace> .\wnbd-client.exe unmap test2
152+
PS C:\workspace> Get-Disk
153+
154+
Number Friendly Name Serial Number HealthStatus OperationalStatus Total Size Partition
155+
Style
156+
------ ------------- ------------- ------------ ----------------- ---------- ----------
157+
0 Msft Virtual Disk Healthy Online 127 GB GPT
158+
159+
```
160+
161+
What other documentation is available?
162+
--------------------------------------
163+
164+
Build via docker
165+
166+
- [BUILD.Docker.md]
167+
168+
[BUILD.Docker.md]:Dockerfile/Readme.md

appveyor.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
version: 1.0.{build}
2+
image: Visual Studio 2019
3+
branches:
4+
only:
5+
- master
6+
configuration:
7+
- Debug
8+
- Release
9+
clone_folder: C:\wnbd
10+
init:
11+
- ps: $env:PATH ="C:\Python37;"+$env:PATH
12+
- ps: New-Item -Type HardLink -Path "C:\Python37\python3.exe" -Value "C:\Python37\python.exe"
13+
14+
build_script:
15+
- '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsx86_amd64.bat"'
16+
- msbuild C:\wnbd\vstudio\wnbd.sln /property:Configuration=%CONFIGURATION%
17+
- copy C:\wnbd\vstudio\x64\%CONFIGURATION%\driver\* .
18+
- 7z a wnbd-%CONFIGURATION%.zip C:\wnbd\vstudio\x64\%CONFIGURATION%\driver\wnbd.cat C:\wnbd\vstudio\x64\%CONFIGURATION%\driver\wnbd.inf C:\wnbd\vstudio\x64\%CONFIGURATION%\driver\wnbd.sys C:\wnbd\vstudio\x64\%CONFIGURATION%\wnbd-client.exe
19+
20+
artifacts:
21+
- path: wnbd-%CONFIGURATION%.zip
22+
name: wnbd

driver/common.h

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (c) 2019 SUSE LLC
3+
*
4+
* Licensed under LGPL-2.1 (see LICENSE)
5+
*/
6+
7+
#ifndef COMMON_H
8+
#define COMMON_H 1
9+
10+
#include <wdm.h>
11+
#include <storport.h>
12+
#include <devioctl.h>
13+
#include <ntstatus.h>
14+
#include <ntddscsi.h>
15+
#include <ntintsafe.h>
16+
#include <ntstrsafe.h>
17+
18+
#endif

driver/debug.c

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2019 SUSE LLC
3+
*
4+
* Licensed under LGPL-2.1 (see LICENSE)
5+
*/
6+
7+
#include <ntstatus.h>
8+
#include <ntstrsafe.h>
9+
#include <wdm.h>
10+
11+
#include "debug.h"
12+
13+
#define WNBD_LOG_BUFFER_SIZE 512
14+
#define WNBD_DBG_DEFAULT WNBD_DBG_INFO
15+
16+
UINT32 WnbdLogLevel = WNBD_DBG_DEFAULT;
17+
18+
_Use_decl_annotations_
19+
VOID
20+
WnbdLog(UINT32 Level,
21+
PCHAR FuncName,
22+
UINT32 Line,
23+
PCHAR Format,
24+
...)
25+
{
26+
va_list Args;
27+
CHAR Buf[WNBD_LOG_BUFFER_SIZE];
28+
29+
if (Level > WnbdLogLevel) {
30+
return;
31+
}
32+
33+
Buf[0] = 0;
34+
va_start(Args, Format);
35+
RtlStringCbVPrintfA(Buf, sizeof(Buf), Format, Args);
36+
va_end(Args);
37+
38+
DbgPrintEx(DPFLTR_SCSIMINIPORT_ID, Level, "%s:%lu %s\n", FuncName, Line, Buf);
39+
}

driver/debug.h

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2019 SUSE LLC
3+
*
4+
* Licensed under LGPL-2.1 (see LICENSE)
5+
*/
6+
7+
#ifndef DEBUG_H
8+
#define DEBUG_H 1
9+
10+
#include <ntdef.h>
11+
#include <wdm.h>
12+
13+
//TODO remove
14+
#if DBG
15+
#define OVERRIDE_LOUD
16+
#endif
17+
18+
#ifndef OVERRIDE_LOUD
19+
#define WNBD_DBG_ERROR DPFLTR_ERROR_LEVEL
20+
#define WNBD_DBG_WARN DPFLTR_WARNING_LEVEL
21+
#define WNBD_DBG_TRACE DPFLTR_TRACE_LEVEL
22+
#define WNBD_DBG_INFO DPFLTR_INFO_LEVEL
23+
#define WNBD_DBG_LOUD (DPFLTR_INFO_LEVEL + 1)
24+
#else
25+
#define WNBD_DBG_ERROR DPFLTR_ERROR_LEVEL
26+
#define WNBD_DBG_WARN DPFLTR_ERROR_LEVEL
27+
#define WNBD_DBG_TRACE DPFLTR_ERROR_LEVEL
28+
#define WNBD_DBG_INFO DPFLTR_ERROR_LEVEL
29+
#define WNBD_DBG_LOUD DPFLTR_ERROR_LEVEL
30+
#endif
31+
32+
33+
34+
VOID
35+
WnbdLog(_In_ UINT32 Level,
36+
_In_ PCHAR FuncName,
37+
_In_ UINT32 Line,
38+
_In_ PCHAR Format, ...);
39+
40+
#define WNBD_LOG_LOUD(_format, ...) \
41+
WnbdLog(WNBD_DBG_LOUD, __FUNCTION__, __LINE__, _format, __VA_ARGS__)
42+
43+
#define WNBD_LOG_INFO(_format, ...) \
44+
WnbdLog(WNBD_DBG_INFO, __FUNCTION__, __LINE__, _format, __VA_ARGS__)
45+
46+
#define WNBD_LOG_TRACE(_format, ...) \
47+
WnbdLog(WNBD_DBG_TRACE, __FUNCTION__, __LINE__, _format, __VA_ARGS__)
48+
49+
#define WNBD_LOG_ERROR(_format, ...) \
50+
WnbdLog(WNBD_DBG_ERROR, __FUNCTION__, __LINE__, _format, __VA_ARGS__)
51+
52+
#define WNBD_LOG_WARN(_format, ...) \
53+
WnbdLog(WNBD_DBG_WARN, __FUNCTION__, __LINE__, _format, __VA_ARGS__)
54+
55+
#endif

0 commit comments

Comments
 (0)