とあるシステムの中の人

プログラミング、育児、武道、3Dグラフィック、ゲーム開発

VDDK8.02のサンプルプログラムをビルドして動かしてみる

  • Virtual Disk Development Kit (VDDK)は、VMWareが出している仮想ディスクを操作するライブラリです。仮想ディスクの操作の自動化などに役立ちます。
  • 今回はVDDK8.02をダウンロードをしてビルド環境を整え、使用できるところまで持って行こうと思います。

環境

  • Ubuntu22.04
  • VDDK8.02

ビルド環境構築

  • ubuntuは最小構成でインストールします。
  • インストール後、apt update, apt upgradeで最新にしておきます。

VDDKのダウンロード

  • 以下のサイトからダウンロードします。
  • https://developer.vmware.com/web/sdk/vddk/
  • 今回はlinux用をダウンロードします。
  • ダウンロードしたファイルはscpで開発用のサーバーに送ります。
  • ubuntuの初期状態ではopenssh-serverが入っていないのでインストールします。
% scp ./VMware-vix-disklib-8.0.2-22388865.x86_64.tar ${USER}@${IP}:/tmp                      
  • 解凍
$ tar -xvf VMware-vix-disklib-8.0.2-22388865.x86_64.tar 
  • 解凍したフォルダは以下のような構成になっています。
$ ll
合計 36
drwxr-xr-x  7 ttmp ttmp 4096  9月  6 15:49 ./
drwxr-x--- 15 ttmp ttmp 4096 12月 16 12:34 ../
-rw-r--r--  1 ttmp ttmp 8068  9月  6 15:49 FILES
drwxr-xr-x  2 ttmp ttmp 4096 12月 16 12:34 bin64/
drwxr-xr-x  6 ttmp ttmp 4096 12月 16 12:34 doc/
drwxr-xr-x  2 ttmp ttmp 4096 12月 16 12:34 include/
drwxr-xr-x  2 ttmp ttmp 4096  9月  6 15:37 lib32/
drwxr-xr-x  2 ttmp ttmp 4096 12月 16 12:34 lib64/
  • lib32とlib64にはビルドに必要なライブラリ類が入っています。
  • docにはサンプルプログラムやエラーコードが記されたドキュメントが入っています。
  • サンプルプログラムのフォルダを見てみます。
$ ll
合計 3832
drwxr-xr-x 2 ttmp ttmp    4096  9月  6 15:45 ./
drwxr-xr-x 3 ttmp ttmp    4096 12月 16 12:34 ../
-r--r--r-- 1 ttmp ttmp     596  9月  6 15:44 Makefile
-rwxr-xr-x 1 ttmp ttmp 1777024  9月  6 15:44 vixDiskLibSample*
-r--r--r-- 1 ttmp ttmp   95768  9月  6 15:43 vixDiskLibSample.cpp
-rwxr-xr-x 1 ttmp ttmp 2034352  9月  6 15:45 vixMntapiSample*
  • makeファイルがありました。
  • 中身を見てみましょう。
$ cat Makefile 
INCLUDEDIR=../../../include
LIBDIR=../../../lib64
LIBS=-ldl -lz -lcurl -lssl -lcrypto -lcares

ifdef VIX_AIO_BUFPOOL_SIZE
CXXFLAGS+= -DVIX_AIO_BUFPOOL_SIZE=$(VIX_AIO_BUFPOOL_SIZE)
endif

CXXFLAGS+= -std=c++1y -lpthread

all: vix-disklib-sample vix-mntapi-sample

vix-disklib-sample: vixDiskLibSample.cpp
    $(CXX) $(CXXFLAGS) -o $@ -I$(INCLUDEDIR) -L$(LIBDIR) $? $(LIBS) -lvixDiskLib

vix-mntapi-sample:  vixDiskLibSample.cpp
    $(CXX) $(CXXFLAGS) -o $@ -DFOR_MNTAPI -I$(INCLUDEDIR) -L$(LIBDIR) $? $(LIBS) \
       -lfuse -lvixDiskLib -lvixMntapi

clean:
    $(RM) -f vix-disklib-sample vix-mntapi-sample
  • 先ほどのlib64へリンクするためのパスが設定されていることがわかります。
  • 現状ではいくつか足りないものはありますが、とりあえずmakeコマンドを実行してみましょう。
$ make
コマンド 'make' が見つかりません。次の方法でインストールできます:
sudo apt install make        # version 4.3-4.1build1, or
sudo apt install make-guile  # version 4.3-4.1build1
  • makeコマンドが見つかりませんと言われてしまいました。インストールして再実行してみます。
$ sudo apt install make 
[sudo] ttmp のパスワード: 
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています... 完了        
状態情報を読み取っています... 完了        
以下のパッケージが自動でインストールされましたが、もう必要とされていません:
  libflashrom1 libftdi1-2 libllvm13
これを削除するには 'sudo apt autoremove' を利用してください。
提案パッケージ:
  make-doc
以下のパッケージが新たにインストールされます:
  make
アップグレード: 0 個、新規インストール: 1 個、削除: 0 個、保留: 6 個。
180 kB のアーカイブを取得する必要があります。
この操作後に追加で 426 kB のディスク容量が消費されます。
取得:1 http://jp.archive.ubuntu.com/ubuntu jammy/main amd64 make amd64 4.3-4.1build1 [180 kB]
180 kB を 3秒 で取得しました (62.4 kB/s)           
以前に未選択のパッケージ make を選択しています。
(データベースを読み込んでいます ... 現在 180557 個のファイルとディレクトリがインストールされています。)
.../make_4.3-4.1build1_amd64.deb を展開する準備をしています ...
make (4.3-4.1build1) を展開しています...
make (4.3-4.1build1) を設定しています ...
man-db (2.10.2-1) のトリガを処理しています ...
$ make
g++ -std=c++1y -lpthread -o vix-disklib-sample -I../../../include -L../../../lib64 vixDiskLibSample.cpp -ldl -lz -lcurl -lssl -lcrypto -lcares -lvixDiskLib
make: g++: そのようなファイルやディレクトリはありません
make: *** [Makefile:14: vix-disklib-sample] エラー 127
  • g++がない、と言われてしまいました。g++はC++言語のコンパイラです。こちらもインストールして、再実行してみます。
$ sudo apt install g++
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています... 完了        
状態情報を読み取っています... 完了        
以下のパッケージが自動でインストールされましたが、もう必要とされていません:
  libflashrom1 libftdi1-2 libllvm13
これを削除するには 'sudo apt autoremove' を利用してください。
以下の追加パッケージがインストールされます:
  binutils binutils-common binutils-x86-64-linux-gnu g++-11 gcc gcc-11 libasan6 libbinutils libc-dev-bin libc-devtools libc6-dev libcc1-0 libcrypt-dev libctf-nobfd0 libctf0 libgcc-11-dev libitm1 liblsan0 libnsl-dev libquadmath0
  libstdc++-11-dev libtirpc-dev libtsan0 libubsan1 linux-libc-dev manpages-dev rpcsvc-proto
提案パッケージ:
  binutils-doc g++-multilib g++-11-multilib gcc-11-doc gcc-multilib autoconf automake libtool flex bison gcc-doc gcc-11-multilib gcc-11-locales glibc-doc libstdc++-11-doc
以下のパッケージが新たにインストールされます:
  binutils binutils-common binutils-x86-64-linux-gnu g++ g++-11 gcc gcc-11 libasan6 libbinutils libc-dev-bin libc-devtools libc6-dev libcc1-0 libcrypt-dev libctf-nobfd0 libctf0 libgcc-11-dev libitm1 liblsan0 libnsl-dev libquadmath0
  libstdc++-11-dev libtirpc-dev libtsan0 libubsan1 linux-libc-dev manpages-dev rpcsvc-proto
アップグレード: 0 個、新規インストール: 28 個、削除: 0 個、保留: 6 個。
52.7 MB のアーカイブを取得する必要があります。
この操作後に追加で 180 MB のディスク容量が消費されます。
続行しますか? [Y/n] y
         : 以下略
$ make
g++ -std=c++1y -lpthread -o vix-disklib-sample -I../../../include -L../../../lib64 vixDiskLibSample.cpp -ldl -lz -lcurl -lssl -lcrypto -lcares -lvixDiskLib
g++ -std=c++1y -lpthread -o vix-mntapi-sample -DFOR_MNTAPI -I../../../include -L../../../lib64 vixDiskLibSample.cpp -ldl -lz -lcurl -lssl -lcrypto -lcares \
   -lfuse -lvixDiskLib -lvixMntapi
/usr/bin/ld: -lfuse が見つかりません: そのようなファイルやディレクトリはありません
collect2: error: ld returned 1 exit status
make: *** [Makefile:17: vix-mntapi-sample] エラー 1
  • /usr/bin/ld: -lfuse が見つかりません: そのようなファイルやディレクトリはありませんと言われてしまいました。
  • libfuseがないようです。
  • FUSEカーネルとの橋渡しを行うライブラリのようです。
$ ldconfig -p | grep libfuse
    libfuse3.so.3 (libc6,x86-64) => /lib/x86_64-linux-gnu/libfuse3.so.3
  • こちらにライブラリがあるようです。
$ echo $LD_LIBRARY_PATH
  • LD_LIBRARY_PATHには何も設定されていません。つまりビルドした時にはこちらのライブラリがみえていません。

  • 今回インストールしたlib64もLD_LIBRARY_PATHに含めてみます。

$ export LD_LIBRARY_PATH=/home/ttmp/vmware-vix-disklib-distrib/lib64:/lib/x86_64-linux-gnu
  • makeしてみます。
$ make
g++ -std=c++1y -lpthread -o vix-mntapi-sample -DFOR_MNTAPI -I../../../include -L../../../lib64 vixDiskLibSample.cpp -ldl -lz -lcurl -lssl -lcrypto -lcares \
   -lfuse -lvixDiskLib -lvixMntapi
/usr/bin/ld: -lfuse が見つかりません: そのようなファイルやディレクトリはありません
collect2: error: ld returned 1 exit status
make: *** [Makefile:17: vix-mntapi-sample] エラー 1
  • まだダメなようです。どうやらライブラリ名がlibfuse.soでないといけないようです。
  • libfuse3.so.3を名称を変え、/home/ttmp/vmware-vix-disklib-distrib/lib64においてみます。ついでにLD_LIBRARY_PATHも変更します。
$ export LD_LIBRARY_PATH=/home/ttmp/vmware-vix-disklib-distrib/lib64
$ ll /lib/x86_64-linux-gnu/libfuse3.so.3
lrwxrwxrwx 1 root root 18 12月 16 10:56 /lib/x86_64-linux-gnu/libfuse3.so.3 -> libfuse3.so.3.10.5
$ sudo find / -name libfuse3.so.3.10.5
find: ‘/run/user/1000/doc’: 許可がありません
find: ‘/run/user/1000/gvfs’: 許可がありません
/usr/lib/x86_64-linux-gnu/libfuse3.so.3.10.5
$ cp -p /usr/lib/x86_64-linux-gnu/libfuse3.so.3.10.5 /home/ttmp/vmware-vix-disklib-distrib/lib64/libfuse.so
  • makeしてみます。
$ make
g++ -std=c++1y -lpthread -o vix-mntapi-sample -DFOR_MNTAPI -I../../../include -L../../../lib64 vixDiskLibSample.cpp -ldl -lz -lcurl -lssl -lcrypto -lcares \
   -lfuse -lvixDiskLib -lvixMntapi
/usr/bin/ld: warning: libfuse.so.2, needed by ../../../lib64/libvixMntapi.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: ../../../lib64/libvixMntapi.so: undefined reference to `fuse_opt_add_opt@FUSE_2.5'
/usr/bin/ld: ../../../lib64/libvixMntapi.so: undefined reference to `fuse_exit@FUSE_2.2'
/usr/bin/ld: ../../../lib64/libvixMntapi.so: undefined reference to `fuse_mount_compat25@FUSE_2.6'
/usr/bin/ld: ../../../lib64/libvixMntapi.so: undefined reference to `fuse_destroy@FUSE_2.2'
/usr/bin/ld: ../../../lib64/libvixMntapi.so: undefined reference to `fuse_unmount_compat22@FUSE_2.6'
/usr/bin/ld: ../../../lib64/libvixMntapi.so: undefined reference to `fuse_new_compat25@FUSE_2.6'
/usr/bin/ld: ../../../lib64/libvixMntapi.so: undefined reference to `fuse_opt_free_args@FUSE_2.5'
/usr/bin/ld: ../../../lib64/libvixMntapi.so: undefined reference to `fuse_opt_add_arg@FUSE_2.5'
/usr/bin/ld: ../../../lib64/libvixMntapi.so: undefined reference to `fuse_loop@FUSE_2.2'
collect2: error: ld returned 1 exit status
make: *** [Makefile:17: vix-mntapi-sample] エラー 1
  • まだダメなようです。libfuse.so.2が気になります。ubuntuに入っていたのは3系でした。どうも今インストールしたubuntuから3系になったようです。2系にしてみます。
$ sudo apt install libfuse2
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています... 完了        
状態情報を読み取っています... 完了        
以下のパッケージが自動でインストールされましたが、もう必要とされていません:
  libflashrom1 libftdi1-2 libllvm13
これを削除するには 'sudo apt autoremove' を利用してください。
以下のパッケージが新たにインストールされます:
  libfuse2
アップグレード: 0 個、新規インストール: 1 個、削除: 0 個、保留: 6 個。
90.3 kB のアーカイブを取得する必要があります。
この操作後に追加で 330 kB のディスク容量が消費されます。
取得:1 http://jp.archive.ubuntu.com/ubuntu jammy/universe amd64 libfuse2 amd64 2.9.9-5ubuntu3 [90.3 kB]
90.3 kB を 1秒 で取得しました (71.9 kB/s)                         
以前に未選択のパッケージ libfuse2:amd64 を選択しています。
(データベースを読み込んでいます ... 現在 185815 個のファイルとディレクトリがインストールされています。)
.../libfuse2_2.9.9-5ubuntu3_amd64.deb を展開する準備をしています ...
libfuse2:amd64 (2.9.9-5ubuntu3) を展開しています...
libfuse2:amd64 (2.9.9-5ubuntu3) を設定しています ...
libc-bin (2.35-0ubuntu3.5) のトリガを処理しています ...
ttmp@ttmp-virtual-machine:~/vmware-vix-disklib-distrib/doc/samples/diskLib$ ldconfig -p | grep libfuse
    libfuse3.so.3 (libc6,x86-64) => /lib/x86_64-linux-gnu/libfuse3.so.3
    libfuse.so.2 (libc6,x86-64) => /lib/x86_64-linux-gnu/libfuse.so.2
ttmp@ttmp-virtual-machine:~/vmware-vix-disklib-distrib/doc/samples/diskLib$ 
  • 2系が入ったようです。同じようにlib64に配置してみます。
$ ll /lib/x86_64-linux-gnu/libfuse.so.2
lrwxrwxrwx 1 root root 16  3月 23  2022 /lib/x86_64-linux-gnu/libfuse.so.2 -> libfuse.so.2.9.9
$ sudo find / -name libfuse.so.2
find: ‘/run/user/1000/doc’: 許可がありません
find: ‘/run/user/1000/gvfs’: 許可がありません
/usr/lib/x86_64-linux-gnu/libfuse.so.2
$ cp -p /usr/lib/x86_64-linux-gnu/libfuse.so.2 /home/ttmp/vmware-vix-disklib-distrib/lib64/libfuse.so
  • makeしてみます。
$ make
g++ -std=c++1y -lpthread -o vix-mntapi-sample -DFOR_MNTAPI -I../../../include -L../../../lib64 vixDiskLibSample.cpp -ldl -lz -lcurl -lssl -lcrypto -lcares \
   -lfuse -lvixDiskLib -lvixMntapi
  • makeできました。
$ ll
合計 5048
drwxr-xr-x 2 ttmp ttmp    4096 12月 16 14:26 ./
drwxr-xr-x 3 ttmp ttmp    4096 12月 16 12:34 ../
-r--r--r-- 1 ttmp ttmp     596  9月  6 15:44 Makefile
-rwxrwxr-x 1 ttmp ttmp  565296 12月 16 12:42 vix-disklib-sample*
-rwxrwxr-x 1 ttmp ttmp  674144 12月 16 14:26 vix-mntapi-sample*
-rwxr-xr-x 1 ttmp ttmp 1777024  9月  6 15:44 vixDiskLibSample*
-r--r--r-- 1 ttmp ttmp   95768  9月  6 15:43 vixDiskLibSample.cpp
-rwxr-xr-x 1 ttmp ttmp 2034352  9月  6 15:45 vixMntapiSample*
  • コマンドが実行できました。
$ ./vix-disklib-sample 
Error: Too few arguments. See usage below.

Usage: vixdisklibsample.exe command [options] diskPath

List of commands (all commands are mutually exclusive):
 -create : creates a sparse virtual disk with capacity specified by -cap
 -redo parentPath : creates a redo log 'diskPath' for base disk 'parentPath'
 -info : displays information for specified virtual disk
 -dump : dumps the contents of specified range of sectors in hexadecimal
 -mount : mount the virtual disk specified
 -fill : fills specified range of sectors with byte value specified by -val
 -wmeta key value : writes (key,value) entry into disk's metadata table
 -rmeta key : displays the value of the specified metada entry
 -meta : dumps all entries of the disk's metadata
 -clone sourcePath : clone source vmdk possibly to a remote site
 -compress type: specify the compression type for nbd transport mode
 -readbench blocksize: Does a read benchmark on a disk using the 
specified I/O block size (in sectors).
 -writebench blocksize: Does a write benchmark on a disk using the
specified I/O block size (in sectors). WARNING: This will
overwrite the contents of the disk specified.
 -readasyncbench blocksize: Does an async read benchmark on a disk using the 
specified I/O block size (in sectors).
 -writeasyncbench blocksize: Does an async write benchmark on a disk using the
specified I/O block size (in sectors). WARNING: This will
overwrite the contents of the disk specified.
 -getallocatedblocks : gets allocated block list on a disk using the 
specified I/O block size (in sectors).
 -check repair: Check a sparse disk for internal consistency, where repair is a boolean value to indicate if a repair operation should be attempted.

options:
 -adapter [ide|scsi] : bus adapter type for 'create' option (default='scsi')
 -start n : start sector for 'dump/fill' options (default=0)
 -count n : number of sectors for 'dump/fill' options (default=1)
 -val byte : byte value to fill with for 'write' option (default=255)
 -cap megabytes : capacity in MB for -create option (default=100)
 -single : open file as single disk link (default=open entire chain)
 -multithread n: start n threads and copy the file to n new files
 -host hostname : hostname/IP address of VC/vSphere host (Mandatory)
 -user userid : user name on host (Mandatory) 
 -password password : password on host. (Mandatory)
 -cookie cookie : cookie from existing authenticated session on host. (Optional)
 -port port : port to use to connect to VC/ESXi host (default = 443) 
 -nfchostport port : port to use to establish NFC connection to ESXi host (default = 902) 
 -vm moref=id : id is the managed object reference of the VM 
 -fcdid id : id is the uuid of the vStorage Object 
 -ds ds : ds is the managed object reference of the Datastore 
 -diskFolder diskFolder : the folder on the datastore 
 -fcdssid ssid : id is the uuid of the snapshot of the vStorage Object 
 -libdir dir : Folder location of the VDDK installation. On Windows, the bin folder holds the plugin.  On Linux, it is the lib64 directory
 -initex configfile : Specify path and filename of config file 
 -ssmoref moref : Managed object reference of VM snapshot 
 -mode mode : Mode string to pass into VixDiskLib_ConnectEx. Valid modes are: nbd, nbdssl, san, hotadd 
 -thumb string : Provides a SSL thumbprint string for validation. Format: xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx
 -chunksize n : number of sectors as a chunk to query allocated blocks
 -lssize n : number of logical sector size for -create and -clone option (default = 0) 
 -pssize n : number of physical sector size for -create and -clone option (default = 0) 
 -unbuffered: use VIXDISKLIB_FLAG_OPEN_UNBUFFERED flag 
 -cleanup: perform cleanup firstly 
  • つぎは実際にAPIを使ってみようと思います。