- 命令行啟動(dòng)虛擬機(jī),虛擬機(jī)內(nèi)核需要是
分支pblk.20
分支pblk-lastest
(git clone https://github.com/OpenChannelSSD/linux.git)
sudo qemu-system-x86_64 --enable-kvm -m 4G -smp 2 -hda ./VMs/vm1.raw -hdb ./VMs/vm1_1.raw -net nic -net tap \
-drive file=./VMs/blknvme.1,if=none,id=blknvme.1 \
-device nvme,drive=blknvme.1,serial=deadbeef,namespaces=1,lver=1,nlbaf=5,lba_index=3,mdts=10
- 其中nvme設(shè)備的參數(shù)(qemu_src/hw/block/nvme.c)
serial=deadbeef,
namespaces=1, # namespaces=<int> : Namespaces to make out of the backing storage, Default:1
lver=1, # lver=<int> : version of the LightNVM standard to use, Default:1
nlbaf=5, # nlbaf=<int> : Number of logical block formats, Default:1
lba_index=3, # lba_index=<int> : Default namespace block format index, Default:0
mdts=10 # mdts=<int> : Maximum data transfer size, Default:5
nlbaf=5,lba_index=3據(jù)說這兩個(gè)參數(shù)決定了nvme設(shè)備的塊大邢裉洹(block = 4K),具體怎么處理的需要看Qemu中nvme設(shè)備的相關(guān)處理.
(git clone https://github.com/OpenChannelSSD/qemu-nvme.git)在虛擬機(jī)內(nèi)可以見到一個(gè)nvme設(shè)備了.
work@vm1:~$ sudo nvme lnvm list
Number of devices: 1
Device Block manager Version
nvme0n1 none (0,0,0)
work@vm1:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 0 30G 0 disk
└─sdb1 8:17 0 30G 0 part /home/work/mnt/1
sr0 11:0 1 1024M 0 rom
sda 8:0 0 20G 0 disk
├─sda2 8:2 0 1.4G 0 part [SWAP]
└─sda1 8:1 0 18.6G 0 part /
nvme0n1 259:0 0 16G 0 disk
work@vm1:~$ sudo nvme lnvm init -d nvme0n1
work@vm1:~$ sudo nvme lnvm list
Number of devices: 1
Device Block manager Version
nvme0n1 gennvm (0,1,0)
- 緊接著在虛擬機(jī)中安裝liblightnvm,以便用戶態(tài)可以使用一些與OpenChannelSSD相關(guān)的api.就是去下這個(gè)githttps://github.com/OpenChannelSSD/liblightnvm谋减,并make&&make install.
- 在虛擬機(jī)裝好liblightnvm后吕嘀,可以在用戶態(tài)access一個(gè)OpenChannelSSD.
- hello_nvme.c:
#include <stdio.h>
#include <liblightnvm.h>
int main(int argc, char **argv)
{
NVM_DEV dev = nvm_dev_open("/dev/nvme0n1");
if (!dev) {
perror("nvm_dev_open");
return 1;
}
nvm_dev_pr(dev);
nvm_dev_close(dev);
return 0;
- 編譯:(需要gcc版本 4.9.1以上)
gcc hello_nvme.c -llightnvm -o hello_nvme
- 運(yùn)行:
work@vm1:~/mnt/1/OpenChannelSSD/src/hello_nvme$ sudo ./hello_nvme
dev { path(/dev/nvme0n1), name(nvme0n1), fd(3) }
dev-geo {
nchannels(1), nluns(1), nplanes(1),
nblocks(16352), npages(256), nsectors(1),
page_nbytes(4096), sector_nbytes(4096), meta_nbytes(16),
tbytes(17146314752b:16352Mb),
vpg_nbytes(4096b:4Kb),
vblk_nbytes(1048576b:1Mb)
}
dev-lba_map {
channel_nbytes(17146314752)
lun_nbytes(17146314752)
plane_nbytes(4096)
block_nbytes(1048576)
page_nbytes(4096)
sector_nbytes(4096)
}
dev-fmt {
ch_ofz(20), ch_len(0),
lun_ofz(20), lun_len(0),
pl_ofz(20), pl_len(0),
blk_ofz(0), blk_len(12),
pg_ofz(12), pg_len(8),
sec_ofz(20), sec_len(0)
}
- (補(bǔ)上一個(gè)模塊關(guān)系簡(jiǎn)圖)
(http://openchannelssd.readthedocs.io/en/latest/)
- 過程中出了個(gè)問題.(感覺是需要OpenMP4.0)
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/liblightnvm.so: undefined reference to `GOMP_parallel@GOMP_4.0'
看一下我的GCC版本
work@vm1:~/mnt/1/OpenChannelSSD/src/hello_nvme$ gcc --version
gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
查一下這個(gè)GOMP是個(gè)所謂的多線程框架放可,gcc自帶的,并且版本關(guān)系如下:
From GCC 4.2.0, OpenMP 2.5 is fully supported.
From GCC 4.4.0, OpenMP 3.0 is fully supported.
From GCC 4.7.0, OpenMP 3.1 is fully supported.
In GCC 4.9.0, OpenMP 4.0 is supported for C and C++, but not Fortran.
From GCC 4.9.1, OpenMP 4.0 is fully supported.
所以這里應(yīng)該是gcc的版本不夠.按照這個(gè)threadUbuntu 14.04 LTS 下升級(jí) gcc 到 gcc-4.9、gcc-5 版本
裝個(gè)gcc-4.9.
簡(jiǎn)要步驟如下:
1 sudo add-apt-repository ppa:ubuntu-toolchain-r/test
2 sudo apt-get update
3 sudo apt-get upgrade
4 sudo apt-get install gcc-4.9 g++-4.9
work@vm1:~/mnt/1/OpenChannelSSD/src/hello_nvme$ gcc-4.9 --version
gcc-4.9 (Ubuntu 4.9.4-2ubuntu1~14.04.1) 4.9.4
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
再編譯果然就OK.
- 與OpenchannelSSD相關(guān)項(xiàng)目
Linux Kernel Support (https://github.com/OpenChannelSSD/linux) Implements support for Open-Channel SSDs in the kernel. It is the core of identifying, managing, and using the Open-Channel SSDs.
liblightnvm Library (https://github.com/OpenChannelSSD/liblightnvm)A library that abstracts the underlying "raw" Open-Channel SSD device and provides abstractions such as append only, bad block management, etc.
General documentation (https://github.com/OpenChannelSSD/documentation)The documentation that is exposed through readthedocs.org
liblightnvm documentation (http://lightnvm.io/liblightnvm)The liblightnvm documentation
LightNVM Conditioning Tool (https://github.com/OpenChannelSSD/lnvm) Provides the lnvm-tool
cli management tool for verifying and conditioning Open-Channel SSDs.
LightNVM Test Tools (https://github.com/OpenChannelSSD/lightnvm-hw)Various tools to test kernel and target implementations.
QEMU with NVMe Open-Channel Support (https://github.com/OpenChannelSSD/qemu-nvme)Implements support for exposing a virtual open-channel SSD. Very useful for development.