LoginSignup
1
0

More than 3 years have passed since last update.

BitVisorのSQLite機能を試してみる

Last updated at Posted at 2020-12-07

先日のBitVisor Summit 9 で,processにsqliteの機能が追加されたという話がありました.確かにそのコミットがあります.ということでどんなものか試してみたいと思います.

コンパイル

make configでSQLITEをONにしてコンパイルしてみます.

[...]
/share/bitvisor/process/sqlite/sqliteexample.c:189: undefined reference to `storage_io_aread'
/share/bitvisor/process/sqlite/sqliteexample.c:195: undefined reference to `storage_io_awrite'
process/sqlite/sqliteexample.o: In function `_start':
/share/bitvisor/process/sqlite/sqliteexample.c:294: undefined reference to `storage_io_init'
/share/bitvisor/process/sqlite/sqliteexample.c:296: undefined reference to `storage_io_get_num_devices'
/share/bitvisor/process/sqlite/sqliteexample.c:323: undefined reference to `storage_io_aget_size'
[..]

何やら怒られてしまいました.どうも storage_io_* という関数が必要のようです.いろいろ試した結果,以下のmake configの設定をONにする必要があるみたいです.

STORAGE
STORAGE_IO
CRYPTO
STORAGE_PD
SQLITE

CRYPTOとか関係なさそうにみえますがきっと何かそこで定義されている関数を利用しているのでしょう.

動作確認

processにsqliteexampleというのがありますので,これを実行してみます.

ubuntu@ubuntu:~$ ./dbgsh
> sqliteexample
Memory(m) or storage_io(s)? m
sqliteexample> create table test (a int, b varchar(10))
sqliteexample> insert into test values (1, "hello")
sqliteexample> insert into test values (2, "bitvisor")
sqliteexample> select * from test
a = 1
b = hello

a = 2
b = bitvisor

sqliteexample> select b from test where a == 2
b = bitvisor

sqliteexample>

最初の Memory(m) or storage_io(s) というのはDBをメモリ上に作成するか,ストレージ上に作成するか聞いているようです.今回は動作確認だけしたいのでメモリを選択しました.あとは上記のようにsqlが実行できました.なお,sqliteexampleはDBに対して直接命令を送っているようなので,sqliteのCLIにある .help のようなコマンドは使えませんでした.

まとめ

ということでBitVisorにSQLiteの機能が入りました.うまくごにょごにょやるとストレージ上にもデータを置けるようなので,使い所によっては面白いことができそうです.


[追記]
書いた後に気がつきましたが普通にsqliteexample.cの冒頭に例が載っていました orz.以下抜粋.

/* Usage via dbgsh:                                                                                                                                                                       [284/3255]

[Memory] the database is always empty on start
------------------------------------------------------------
> sqliteexample
Memory(m) or storage_io(s)? m
sqliteexample> create table foo(bar)
sqliteexample> insert into foo(bar) values(1)
sqliteexample> select * from foo
bar = 1

sqliteexample>
------------------------------------------------------------

[Storage_io] the database is persistent on a storage
------------------------------------------------------------
> sqliteexample
Memory(m) or storage_io(s)? s
id 1
Number of devices 4
Device number? 1
Start LBA? 0
End LBA? 20479
Device 1 LBA 0-10239,10240-20479 Storage size 175913280995328 (may be incorrect)
Continue(y/n)? y
sqliteexample> select count(*) from a
count(*) = 52

sqliteexample> insert into a(a) values(2)
sqliteexample> select count(*) from a
count(*) = 53

sqliteexample>
> sqliteexample
Memory(m) or storage_io(s)? s
id 2
Number of devices 4
Device number? 1
Start LBA? 0
End LBA? 20479
Device 1 LBA 0-10239,10240-20479 Storage size 175913280995328 (may be incorrect)
Continue(y/n)? y
sqliteexample> select count(*) from a
count(*) = 53

sqliteexample> select * from a where a=2
a = 2
b = NULL
c = NULL
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0