Update Red Hat Copyright Notices
[nbdkit.git] / plugins / vddk / nbdkit-vddk-plugin.pod
blob704ff63c7ead2cbf28c36c0b9fa860983753ae31
1 =head1 NAME
3 nbdkit-vddk-plugin - nbdkit VMware VDDK plugin
5 =head1 SYNOPSIS
7  nbdkit vddk [file=]FILENAME
8              [compression=none|zlib|fastlz|skipz]
9              [config=FILENAME] [cookie=COOKIE]
10              [create=true] [create-adapter-type=ide|scsi-buslogic|...]
11              [create-hwversion=workstation4|workstation5|...]
12              [create-size=...] [create-type=monolithic-sparse|...]
13              [libdir=LIBRARY]
14              [nfchostport=PORT] [single-link=true]
15              [password=PASSWORD | password=- | password=+FILENAME |
16               password=-FD]
17              [port=PORT] [server=HOSTNAME] [snapshot=MOREF]
18              [thumbprint=THUMBPRINT] [transports=MODE:MODE:...]
19              [unbuffered=true] [user=USERNAME] [vm=moref=ID]
20  nbdkit vddk --dump-plugin
22 =head1 DESCRIPTION
24 C<nbdkit-vddk-plugin> is an L<nbdkit(1)> plugin that serves disks from
25 local VMware VMDK files, VMware ESXi servers, VMware VCenter servers,
26 and other sources.
28 It requires VMware's proprietary VDDK library that you must download
29 yourself (see L</LIBRARY LOCATION> below).
31 For an easy-to-use wrapper around this plugin which automates setting
32 things up to connect to a remote VMware server, see:
33 L<https://gitlab.com/nbdkit/vddk-remote>
35 =head1 EXAMPLES
37 =head2 Open an existing local VMDK file
39  nbdkit vddk /absolute/path/to/file.vmdk
41 When opening local files the filename B<must> be an absolute path.
43 Because VDDK needs to lock the file, the file must be on a writable
44 filesystem.  You can avoid this by opening the file read-only (the
45 I<-r> option):
47  nbdkit -r vddk /absolute/path/to/file.vmdk
49 =head2 Create a new local VMDK file
51 You can use VDDK to create a VMDK file and fill it with the contents
52 of a disk image.  Note the C<create-size> parameter is the virtual
53 size of the final VMDK disk image and must be at least as large as the
54 input disk:
56  nbdkit -U - vddk \
57         /absolute/path/to/output.vmdk \
58         create=true create-size=100M \
59         --run 'qemu-img convert input.qcow2 $uri'
61 =head2 Open a file on a remote VMware ESXi hypervisor
63 Connect directly to a VMware ESXi hypervisor and export a particular
64 file:
66  nbdkit vddk user=root password=+/tmp/rootpw \
67              server=esxi.example.com thumbprint=xx:xx:xx:... \
68              vm=moref=2 \
69              "[datastore1] Fedora/Fedora.vmdk"
71 C<user> and C<password> must be specified.  Use C<password=+FILENAME>
72 to provide the password securely in a file.
74 C<server> is the hostname of the ESXi server.
76 C<thumbprint> is the thumb print for validating the SSL certificate.
77 How to find the thumb print of a server is described in
78 L</THUMBPRINTS> below.
80 C<vm> is the Managed Object Reference ("moref") of the virtual
81 machine.  See L</MANAGED OBJECT REFERENCE> below.
83 The file parameter is the file you want to open, usually in the form
84 S<C<"[datastore] vmname/vmname.vmdk">>.  See L</FILE PARAMETER> below.
86 =head2 Open a file on a remote VMware vCenter server
88 Connect via VMware vCenter and export a particular file:
90  nbdkit vddk user=root password=vmware \
91              server=vcenter.example.com thumbprint=xx:xx:xx:... \
92              vm=moref=vm-16 \
93              "[datastore1] Fedora/Fedora.vmdk"
95 C<user> and C<password> must be specified.  Use C<password=+FILENAME>
96 to provide the password securely in a file.
98 C<server> is the hostname of the vCenter server.
100 C<thumbprint> is the thumb print for validating the SSL certificate.
101 How to find the thumb print of a server is described in
102 L</THUMBPRINTS> below.
104 C<vm> is the Managed Object Reference ("moref") of the virtual
105 machine.  See L</MANAGED OBJECT REFERENCE> below.
107 The file parameter is the file you want to open, usually in the form
108 S<C<"[datastore] vmname/vmname.vmdk">>.  See L</FILE PARAMETER> below.
110 =head1 PARAMETERS
112 For opening a local VMDK file, the C<file> parameter is required and
113 must be an absolute path.
115 For opening a remote connection, C<file>, C<server>, C<thumbprint>,
116 C<user>, C<password> and C<vm> are required.
118 All other parameters are optional.
120 =over 4
122 =item B<compression=none>
124 =item B<compression=zlib>
126 =item B<compression=fastlz>
128 =item B<compression=skipz>
130 (nbdkit E<ge> 1.24, vSphere E<ge> 6.5)
132 Select the compression type used over the network between VDDK and the
133 VMware server.  The default is C<none>.  See VMware document “Best
134 Practices for NBD Transport”.
136 =item B<config=>FILENAME
138 The name of the VDDK configuration file.
140 The config file controls rarely adjusted VDDK settings like log level,
141 caching and timeouts.  See the VDDK documentation for a full list of
142 settings.
144 VDDK itself looks in a few default locations for the configuration
145 file, usually including F</etc/vmware/config> and
146 F<$HOME/.vmware/config>.  Using C<config> overrides these defaults.
148 =item B<cookie=>COOKIE
150 (vSphere E<ge> 6.7)
152 Cookie from existing authenticated session on the host.
154 This changes the authentication type from C<VIXDISKLIB_CRED_UID> to
155 C<VIXDISKLIB_CRED_SESSIONID> which can improve performance.  The
156 cookie can be found by connecting to a VCenter Server over HTTPS and
157 retrieving the C<vmware_soap_session> cookie.
159 =item B<create=true>
161 (nbdkit E<ge> 1.30)
163 Create a new, local VMDK file.  Instead of opening an existing VMDK
164 file, a new VMDK file is created and opened.  The filename is given by
165 the C<file> parameter (see below).  The file must not exist already.
166 It is not possible to create a remote file using nbdkit.
168 If this is used, the C<create-size> parameter is required to specify
169 the virtual size of the disk.  Other C<create-*> parameters (see
170 below) can be used to control the VMDK sub-format.
172 =item B<create-adapter-type=ide>
174 =item B<create-adapter-type=scsi-buslogic>
176 =item B<create-adapter-type=scsi-lsilogic>
178 (nbdkit E<ge> 1.30)
180 Specify the VMDK disk adapter type.  The default is C<scsi-buslogic>.
182 =item B<create-hwversion=workstation4>
184 =item B<create-hwversion=workstation5>
186 =item B<create-hwversion=workstation6>
188 =item B<create-hwversion=esx30>
190 =item B<create-hwversion=esx4x>
192 =item B<create-hwversion=esx50>
194 =item B<create-hwversion=esx51>
196 =item B<create-hwversion=esx55>
198 =item B<create-hwversion=esx60>
200 =item B<create-hwversion=esx65>
202 =item B<create-hwversion=>N
204 (nbdkit E<ge> 1.30)
206 Specify the VMDK virtual hardware version.  You can give either the
207 named version or the equivalent 16 bit number.
209 The default is C<workstation5> (N = 4).
211 =item B<create-size=>SIZE
213 (nbdkit E<ge> 1.30)
215 Specify the virtual size of the created disk.  The C<SIZE> can use
216 modifiers like C<100M> etc.  It must be a multiple of 512 bytes
217 because VMware only supports sector sizes.
219 If you use C<create=true> then this parameter is required.
221 =item B<create-type=monolithic-sparse>
223 =item B<create-type=monolithic-flat>
225 =item B<create-type=split-sparse>
227 =item B<create-type=split-flat>
229 =item B<create-type=vmfs-flat>
231 =item B<create-type=stream-optimized>
233 =item B<create-type=vmfs-thin>
235 =item B<create-type=vmfs-sparse>
237 (nbdkit E<ge> 1.30)
239 Specify the VMDK sub-format.  The default is C<monolithic-sparse>.
241 Some VMDK sub-formats use multiple files, where the C<file> parameter
242 specifies the "Disk Descriptor File" and the disk contents are stored
243 in adjacent files.
245 =item [B<file=>]FILENAME
247 =item [B<file=>]B<[>datastoreB<] >vmname/vmnameB<.vmdk>
249 Set the name of the VMDK file to serve.
251 For local files you B<must> supply an absolute path.
252 For remote files see L</FILE PARAMETER> section below.
254 If a VM has multiple disks, nbdkit can only serve one at a time.  To
255 serve more than one you must run multiple copies of nbdkit.  (See
256 L</NOTES> below).
258 C<file=> is a magic config key and may be omitted in most cases.
259 See L<nbdkit(1)/Magic parameters>.
261 =item B<libdir=>PATHNAME
263 This sets the path of the VMware VDDK distribution.
265 VDDK uses this to load its own plugins, if this path is unspecified or
266 wrong then VDDK will work with reduced functionality.  See
267 L</LIBRARY LOCATION> below.
269 =item B<nfchostport=>PORT
271 Port used to establish an NFC connection to ESXi.  Defaults to 902.
273 =item B<password=>PASSWORD
275 Set the password to use when connecting to the remote server.
277 Note that passing this on the command line is not secure on shared
278 machines.
280 =item B<password=->
282 Ask for the password (interactively) when nbdkit starts up.
284 =item B<password=+>FILENAME
286 Read the password from the named file.  This is a secure method
287 to supply a password, as long as you set the permissions on the file
288 appropriately.
290 =item B<password=->FD
292 Read the password from file descriptor number C<FD>, inherited from
293 the parent process when nbdkit starts up.  This is also a secure
294 method to supply a password.
296 =item B<port=>PORT
298 The port on the VCenter/ESXi host.  Defaults to 443.
300 =item B<server=>HOSTNAME
302 The hostname or IP address of VCenter or ESXi host.
304 =item B<single-link=true>
306 (nbdkit E<ge> 1.12)
308 Open the current link, not the entire chain.  This corresponds to the
309 C<VIXDISKLIB_FLAG_OPEN_SINGLE_LINK> flag.
311 =item B<snapshot=>MOREF
313 The Managed Object Reference of the snapshot.
314 See L</MANAGED OBJECT REFERENCE> below.
316 =item B<thumbprint=>THUMBPRINT
318 The SSL (SHA1) thumbprint for validating the SSL certificate.
320 The format is
321 C<xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx>
322 (20 hex digit pairs).
324 See L</THUMBPRINTS> below for how to get this.
326 =item B<transports=>MODEB<:>MODEB<:>...
328 List of one or more transport modes to use.  Possible values include
329 ‘nbd’, ‘nbdssl’, ‘san’, ‘hotadd’, ‘file’ (there may be others).  If
330 not given, VDDK will try to choose the best transport mode.
332 =item B<unbuffered=true>
334 (nbdkit E<ge> 1.12)
336 Disable host caching.  This corresponds to the
337 C<VIXDISKLIB_FLAG_OPEN_UNBUFFERED> flag.
339 =item B<user=>USERNAME
341 The username to connect to the remote server as.
343 =item B<vm=moref=>ID
345 The Managed Object Reference ("moref") of the virtual machine.
346 See L</MANAGED OBJECT REFERENCE> below.
348 =item B<vimapiver=>APIVER
350 This parameter is ignored for backwards compatibility.
352 =back
354 =head1 LIBRARY LOCATION
356 The VDDK library should B<not> be placed on a system library path such
357 as F</usr/lib>.  The reason is that the VDDK library ships with
358 recompiled libraries like F<libcrypto.so> and F<libstdc++.so> that
359 conflict with system libraries.
361 You have two choices:
363 =over 4
365 =item *
367 Place VDDK in the default libdir which is compiled into this plugin,
368 for example:
370  $ nbdkit vddk --dump-plugin | grep ^vddk_default_libdir
371  vddk_default_libdir=/usr/lib64/vmware-vix-disklib
373 =item *
375 But the best advice is to unpack the VDDK tarball anywhere you like
376 and set the C<libdir=/path/to/vmware-vix-disklib-distrib>.  For
377 example:
379  nbdkit vddk \
380         libdir=/opt/vmware-vix-disklib-distrib \
381         /path/to/file.vmdk
383 =back
385 =head2 No need to set C<LD_LIBRARY_PATH>
387 In nbdkit E<le> 1.16 you had to set the environment variable
388 C<LD_LIBRARY_PATH> when using this plugin.  In nbdkit E<ge> 1.18 this
389 is I<not> recommended.
391 =head1 FILE PARAMETER
393 The C<file> parameter can either be a local file, in which case it
394 must be the absolute path.  Or it can refer to a remote file on the
395 VMware server in the format S<C<"[datastore] vmname/vmname.vmdk">>.
397 =head2 Finding the remote filename
399 For remote files you can find the path using L<virsh(1)>.  For ESXi:
401  $ virsh -c 'esx://esxi.example.com?no_verify=1' dumpxml guestname
402  ...
403   <disk type='file' device='disk'>
404     <source file='[datastore] vmname/vmname.vmdk'/>
405  ...
407 For vCenter the command is the same but the URI starts with C<vpx://>:
409  $ virsh -c 'vpx://vcenter.example.com/Datacenter/esxi.example.com?no_verify=1' \
410          dumpxml guestname
412 See also: L<https://libvirt.org/drvesx.html>
414 =head2 Optional file= prefix
416 The C<file=> part is optional, so these commands are equivalent:
418  nbdkit vddk file=/path/to/file.vmdk
419  nbdkit vddk /path/to/file.vmdk
421 =head1 THUMBPRINTS
423 The thumbprint is a 20 byte string containing the SSL (SHA1)
424 fingerprint of the remote VMware server and it is required when making
425 a remote connection.  There are several ways to obtain this.
427 =head2 Using a web browser
429 Visit C<https://SERVER-NAME/folder> and log in.  Click the lock icon
430 next to the URL bar and navigate to the SHA-1 fingerprint of the
431 site’s certificate.  This 20 hex digit pair string can be directly
432 copied to the C<thumbprint=> parameter.
434 =head2 Using openssl remotely
436 The following command will print the thumbprint of a VMware server
437 called C<SERVER-NAME>:
439  $ openssl s_client -connect SERVER-NAME:443 </dev/null |
440    openssl x509 -in /dev/stdin -fingerprint -sha1 -noout
442 =head2 By logging in to the ESXi or vCenter server
444 Log in to the ESXi hypervisor shell and run this command:
446  # openssl x509 -in /etc/vmware/ssl/rui.crt -fingerprint -sha1 -noout
448 For VMware vCenter servers the thumbprint is printed on the text
449 console of the server or is available by logging in to the server and
450 using this command:
452  # openssl x509 -in /etc/vmware-vpx/ssl/rui.crt -fingerprint -sha1 -noout
454 =head2 Trick: Get VDDK to tell you the thumbprint
456 Another way to get the thumbprint of a server is to connect to the
457 server using a bogus thumbprint with debugging enabled:
459  nbdkit -U - -fv vddk server=esxi.example.com [...] thumbprint=12 \
460         --run 'qemu-img info "$uri"'
462 The nbdkit process will try to connect (and fail because the
463 thumbprint is wrong).  However in the debug output will be a message
464 such as this:
466  nbdkit: debug: VixDiskLibVim: Failed to verify SSL certificate: actual thumbprint=B2:31:BD:DE:9F:DB:9D:E0:78:EF:30:42:8A:41:B0:28:92:93:C8:DD expected=12
468 This gives you the server’s real thumbprint.  Of course this method is
469 not secure since it allows a Man-in-the-Middle (MITM) attack.
471 =head1 MANAGED OBJECT REFERENCE
473 Some use cases require you to pass in the Managed Object Reference
474 ("moref") of an object on the VMware server.
476 For VMware ESXi hypervisors, the C<vm> moref is a number
477 (eg. C<vm=moref=2>).  For VMware VCenter it is a string beginning with
478 C<"vm-">) (eg. C<vm=moref=vm-16>).  Across ESXi and vCenter the
479 numbers are different even for the same virtual machine.
481 If you have libvirt E<ge> 3.7, the moref is available in the
482 L<virsh(1)> C<dumpxml> output:
484  $ virsh -c 'esx://esxi.example.com?no_verify=1' dumpxml guestname
485  ...
486  <vmware:moref>2</vmware:moref>
487  ...
491  $ virsh -c 'vpx://vcenter.example.com/Datacenter/esxi.example.com?no_verify=1' \
492        dumpxml guestname
493  ...
494  <vmware:moref>vm-16</vmware:moref>
495  ...
497 An alternative way to find the moref of a VM is using the
498 C<moRefFinder.pl> script written by William Lam
499 (L<http://www.virtuallyghetto.com/2011/11/vsphere-moref-managed-object-reference.html>
500 L<https://blogs.vmware.com/vsphere/2012/02/uniquely-identifying-virtual-machines-in-vsphere-and-vcloud-part-2-technical.html>).
502 =head1 DUMP-PLUGIN OUTPUT
504 To query more information about the plugin (and whether it is
505 working), use:
507  nbdkit vddk --dump-plugin
511  nbdkit vddk --dump-plugin libdir=/opt/vmware-vix-disklib-distrib
513 (see L</LIBRARY LOCATION> above).
515 If the plugin is not present or not working you will get an error.
517 If it works the output will include:
519 =over 4
521 =item C<vddk_default_libdir=...>
523 The compiled-in library path.  Use C<libdir=PATHNAME> to override this
524 at runtime.
526 =item C<vddk_has_nfchostport=1>
528 If this is printed then the C<nfchostport=PORT> parameter is supported
529 by this build.
531 =item C<vddk_library_version=...>
533 The VDDK major library version: 6, 7, 8, ...
534 If this is omitted it means the library could not be loaded.
536 =item C<vddk_dll=...>
538 Prints the full path to the VDDK shared library.  Since this requires
539 a glibc extension it may not be available in all builds of the plugin.
541 =item C<VixDiskLib_...=1>
543 For each VDDK API that the plugin uses I<and> which is present in the
544 VDDK library that was loaded, we print the name of the API
545 (eg. C<VixDiskLib_Open=1>).  This lets you see which optional APIs are
546 available, such as C<VixDiskLib_Flush> and
547 C<VixDiskLib_QueryAllocatedBlocks>.  If the library could not be
548 loaded then these lines are not printed.
550 =back
552 =head1 NOTES
554 =head2 Sector size limitation
556 The VDDK plugin can only answer read/write requests on whole 512 byte
557 sector boundaries.  This is because the VDDK Read and Write APIs only
558 take sector numbers.  If your client needs finer granularity, you can
559 use L<nbdkit-blocksize-filter(1)>:
561  nbdkit vddk ... --filter=blocksize minblock=512
563 =head2 Out of memory errors
565 In the verbose log you may see errors like:
567  nbdkit: vddk[3]: error: [NFC ERROR] NfcFssrvrProcessErrorMsg:
568  received NFC error 5 from server: Failed to allocate the
569  requested 2097176 bytes
571 This seems especially common when there are multiple parallel
572 connections open to the VMware server with large NBD reads and writes.
574 =head3 Increase resource limits on the server
576 The error above can be caused by resource limits set on the VMware
577 server.  You can increase the limit for the NFC service by editing
578 F</etc/vmware/hostd/config.xml> and adjusting the
579 C<E<lt>maxMemoryE<gt>> setting:
581  <nfcsvc>
582    <path>libnfcsvc.so</path>
583    <enabled>true</enabled>
584    <maxMemory>50331648</maxMemory>
585    <maxStreamMemory>10485760</maxStreamMemory>
586  </nfcsvc>
588 and restarting the C<hostd> service:
590  # /etc/init.d/hostd restart
592 For more information see L<https://bugzilla.redhat.com/1614276>.
594 =head3 Limit request sizes
596 In addition, or as an alternative to adjusting the server
597 configuration, you can use L<nbdkit-blocksize-filter(1)> to limit the
598 maximum request size.  By default this plugin translates NBD requests
599 directly into VDDK requests, and it appears that very large VDDK
600 requests can cause the error seen above.
602 Using:
604  nbdkit vddk ... --filter=blocksize minblock=512 maxdata=2M
606 will cause nbdkit to automatically split and combine requests so that
607 VDDK sees only sizes in the range C<[512..2M]>.
609 =head2 Troubleshooting performance problems
611 VDDK has very uneven performance with some operations being very slow.
612 This plugin has options to allow you to debug performance issues.  If
613 your application has a debug or diagnostic setting, add the following
614 nbdkit command line options:
616  -v -D nbdkit.backend.datapath=0 -D vddk.datapath=0 -D vddk.stats=1
618 C<-v> enables verbose messages and the two datapath options I<disable>
619 the very verbose per-read/-write messages.  C<-D vddk.stats=1> enables
620 a summary when nbdkit exits of the cumulative time taken in each VDDK
621 function, the number of times each function was called, and (for read
622 and write) the number of bytes transferred.  An example of what those
623 stats look like can be found here:
624 L<https://gitlab.com/nbdkit/nbdkit/-/commit/5c80f0d290db45a679d55baf37ff39bacb8ce7ec>
626 You can interpret the stats as follows:
628 =over 4
630 =item C<Read>
632 The cumulative time spent waiting for VDDK to return from
633 C<VixDiskLib_Read> calls, the number of times this function was
634 called, and the total bytes read.  You can use this to determine the
635 read bandwidth to the VMware server.
637 =item C<Write>
639 =item C<Flush>
641 Same as above, but for writing and flushing writes.
643 =item C<ReadAsync>
645 =item C<WriteAsync>
647 Same as above, but for asynchronous read and write calls introduced in
648 nbdkit 1.30.  Unfortunately at the moment the amount of time spent in
649 these calls is not accounted for correctly.
651 =item C<QueryAllocatedBlocks>
653 This call is used to query information about the sparseness of the
654 remote disk.  It is only available in VDDK E<ge> 6.7.  The call is
655 notably very slow in all versions of VMware we have tested.
657 =item C<Open>
659 =item C<Close>
661 =item C<ConnectEx>
663 =item C<Disconnect>
665 =item C<InitEx>
667 =item C<Exit>
669 The cumulative time spent connecting and disconnecting from the VMware
670 server, which can also be very slow.
672 =back
674 =head1 SUPPORTED VERSIONS OF VDDK
676 This plugin requires VDDK E<ge> 6.5 (released Nov 2016).  It is only
677 supported on the x64-64 archtecture.
679 It has been tested with all versions up to 8.0.0 (but should work with
680 future versions).
682 VDDK 6.7 was the first version that supported the
683 C<VixDiskLib_QueryAllocatedBlocks> API, required to provide extent
684 information over NBD.
686 =head1 DEBUG FLAGS
688 Debugging messages can be very helpful if you have problems connecting
689 to VMware servers, or to find the list of available transport modes,
690 or to diagnose SAN problems:
692  nbdkit -f -v vddk file=FILENAME [...]
694 Additional debug flags are available:
696 =over 4
698 =item B<-D vddk.diskinfo=1>
700 Debug disk information returned by C<GetInfo>.
702 =item B<-D vddk.extents=1>
704 Debug extents returned by C<QueryAllocatedBlocks>.
706 =item B<-D vddk.datapath=0>
708 Suppress debugging of datapath calls (C<Read>, C<ReadAsync>, C<Write>
709 and C<WriteAsync>).
711 =item B<-D vddk.stats=1>
713 When the plugin exits print some statistics about each VDDK call.
715 =back
717 =head1 FILES
719 =over 4
721 =item F<$plugindir/nbdkit-vddk-plugin.so>
723 The plugin.
725 Use C<nbdkit --dump-config> to find the location of C<$plugindir>.
727 =back
729 =head1 VERSION
731 C<nbdkit-vddk-plugin> first appeared in nbdkit 1.2.
733 =head1 SEE ALSO
735 L<nbdkit(1)>,
736 L<nbdkit-plugin(3)>,
737 L<nbdkit-blocksize-filter(1)>,
738 L<nbdkit-readahead-filter(1)>,
739 L<nbdkit-retry-filter(1)>,
740 L<nbdkit-scan-filter(1)>,
741 L<virsh(1)>,
742 L<https://gitlab.com/nbdkit/vddk-remote>,
743 L<https://libvirt.org/drvesx.html>,
744 L<https://www.vmware.com/support/developer/vddk/>,
745 VMware document “Best Practices for NBD Transport”.
747 =head1 AUTHORS
749 Richard W.M. Jones
751 =head1 COPYRIGHT
753 Copyright Red Hat