File: README.md

package info (click to toggle)
golang-github-mdlayher-vsock 0.0~git20210303.10d5918-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 204 kB
  • sloc: makefile: 3
file content (89 lines) | stat: -rw-r--r-- 2,825 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
vscp
====

Command `vscp` provides a `scp`-like utility for copying files over VM
sockets.  It is meant to show example usage of package `vsock`, but is
also useful in scenarios where a virtual machine does not have
networking configured, but VM sockets are available.

Usage
-----

`vscp` has two modes of operation: receiving and sending.

```
$ vscp -h
Usage of vscp:
  -c uint
        send only: context ID of the remote VM socket
  -p uint
        - receive: port ID to listen on (random port by default)
        - send: port ID to connect to
  -r    receive files from another instance of vscp
  -s    send files to another instance of vscp
  -v    enable verbose logging to stderr
```

For example, let's transfer the contents of `/proc/cpuinfo` from a
virtual machine to a hypervisor.

First, start a server on the hypervisor.  The following command will:
  - enable verbose logging
  - start `vscp` as a server to receive data
  - specify port 1024 as the server's listener port
  - use `cpuinfo.txt` as an output file

```
hv $ vscp -v -r -p 1024 cpuinfo.txt
2017/03/10 10:51:48 receive: creating file "cpuinfo.txt" for output
2017/03/10 10:51:48 receive: opening listener: 1024
2017/03/10 10:51:48 receive: listening: host(2):1024
# listening for client connection
```

Next, in the virtual machine, start a client to send a file to
the server on the hypervisor.  The following command will:
  - enable verbose logging
  - start `vscp` as a client to send data
  - specify context ID 2 (host process) as the server's context ID
  - specify port 1024 as the server's port
  - use `/proc/cpuinfo` as an input file

```
vm $ vscp -v -s -c 2 -p 1024 /proc/cpuinfo
2017/03/10 10:56:18 send: opening file "/proc/cpuinfo" for input
2017/03/10 10:56:18 send: dialing: 2.1024
2017/03/10 10:56:18 send: client: vm(3):1077
2017/03/10 10:56:18 send: server: host(2):1024
2017/03/10 10:56:18 send: sending data
2017/03/10 10:56:18 send: transfer complete
vm $
```

The transfer is now complete.  You should see more output in the
hypervisor's terminal, and the server process should have exited.

```
hv $ vscp -v -r -p 1024 cpuinfo.txt
2017/03/10 10:51:48 receive: creating file "cpuinfo.txt" for output
2017/03/10 10:51:48 receive: opening listener: 1024
2017/03/10 10:51:48 receive: listening: host(2):1024
# listening for client connection
2017/03/10 10:55:39 receive: server: host(2):1024
2017/03/10 10:55:39 receive: client: vm(3):1077
2017/03/10 10:55:39 receive: receiving data
2017/03/10 10:55:39 receive: transfer complete
hv $
```

To verify the transfer worked as intended, you can check the hash
of the file on both sides using a tool such as `md5sum`.

```
hv $ md5sum cpuinfo.txt
cda57941b11f0c82da425eec5d837c26  cpuinfo.txt
```
```
vm $ md5sum /proc/cpuinfo
cda57941b11f0c82da425eec5d837c26  /proc/cpuinfo
```