diff --git a/doc/bdev.md b/doc/bdev.md index 2af8e10cd..d9dad00a6 100644 --- a/doc/bdev.md +++ b/doc/bdev.md @@ -92,6 +92,12 @@ It is possible to create pmem bdev using SPDK RPC: ./scripts/rpc.py construct_pmem_bdev -n bdev_name /path/to/pmem_pool ~~~ +Configuration file syntax: +~~~ +[Pmem] + Blk /path/to/pmem_pool bdev_name +~~~ + ## Null {#bdev_config_null} The SPDK null bdev driver is a dummy block I/O target that discards all writes and returns undefined diff --git a/etc/spdk/iscsi.conf.in b/etc/spdk/iscsi.conf.in index d5d3a3e10..a2b0cd84c 100644 --- a/etc/spdk/iscsi.conf.in +++ b/etc/spdk/iscsi.conf.in @@ -152,6 +152,12 @@ AIO /dev/sdc AIO1 AIO /tmp/myfile AIO2 4096 +# PMDK libpmemblk-based block device +[Pmem] + # Syntax: + # Blk + Blk /path/to/pmem-pool Pmem0 + # The Split virtual block device slices block devices into multiple smaller bdevs. [Split] # Syntax: diff --git a/etc/spdk/nvmf.conf.in b/etc/spdk/nvmf.conf.in index a93963908..835229f6d 100644 --- a/etc/spdk/nvmf.conf.in +++ b/etc/spdk/nvmf.conf.in @@ -42,6 +42,12 @@ AIO /dev/sdc AIO1 AIO /tmp/myfile AIO2 4096 +# PMDK libpmemblk-based block device +[Pmem] + # Syntax: + # Blk + Blk /path/to/pmem-pool Pmem0 + # Define NVMf protocol global options [Nvmf] # Set the maximum number of submission and completion queues per session. diff --git a/etc/spdk/vhost.conf.in b/etc/spdk/vhost.conf.in index 2e29a1761..a14a362f8 100644 --- a/etc/spdk/vhost.conf.in +++ b/etc/spdk/vhost.conf.in @@ -43,6 +43,12 @@ #AIO /dev/sdb AIO0 #AIO /dev/sdc AIO1 +# PMDK libpmemblk-based block device +[Pmem] + # Syntax: + # Blk + Blk /path/to/pmem-pool Pmem0 + # Users may change this section to create a different number or size of # malloc LUNs. # If the system has hardware DMA engine, it will use an IOAT diff --git a/lib/bdev/pmem/bdev_pmem.c b/lib/bdev/pmem/bdev_pmem.c index 4c7052a5a..54b283a6d 100644 --- a/lib/bdev/pmem/bdev_pmem.c +++ b/lib/bdev/pmem/bdev_pmem.c @@ -385,6 +385,41 @@ spdk_create_pmem_disk(const char *pmem_file, const char *name, struct spdk_bdev return 0; } +static void +bdev_pmem_read_conf(void) +{ + struct spdk_conf_section *sp; + struct spdk_bdev *bdev; + const char *pmem_file; + const char *bdev_name; + int i; + + sp = spdk_conf_find_section(NULL, "Pmem"); + if (sp == NULL) { + return; + } + + for (i = 0; ; i++) { + if (!spdk_conf_section_get_nval(sp, "Blk", i)) { + break; + } + + pmem_file = spdk_conf_section_get_nmval(sp, "Blk", i, 0); + if (pmem_file == NULL) { + SPDK_ERRLOG("Pmem: missing filename\n"); + continue; + } + + bdev_name = spdk_conf_section_get_nmval(sp, "Blk", i, 1); + if (bdev_name == NULL) { + SPDK_ERRLOG("Pmem: missing bdev name\n"); + continue; + } + + spdk_create_pmem_disk(pmem_file, bdev_name, &bdev); + } +} + static int bdev_pmem_initialize(void) { @@ -398,6 +433,8 @@ bdev_pmem_initialize(void) spdk_io_device_register(&g_pmem_disks, bdev_pmem_create_cb, bdev_pmem_destroy_cb, 0); + bdev_pmem_read_conf(); + return 0; } diff --git a/test/bdev/blockdev.sh b/test/bdev/blockdev.sh index 858f972a8..85048badd 100755 --- a/test/bdev/blockdev.sh +++ b/test/bdev/blockdev.sh @@ -60,6 +60,13 @@ if [ $SPDK_TEST_RBD -eq 1 ]; then $rootdir/scripts/gen_rbd.sh >> $testdir/bdev.conf fi +if hash pmempool; then + rm -f /tmp/spdk-pmem-pool + pmempool create blk --size=32M 512 /tmp/spdk-pmem-pool + echo "[Pmem]" >> $testdir/bdev.conf + echo " Blk /tmp/spdk-pmem-pool Pmem0" >> $testdir/bdev.conf +fi + timing_enter bounds $testdir/bdevio/bdevio $testdir/bdev.conf timing_exit bounds @@ -138,6 +145,7 @@ if grep -q Nvme0 $testdir/bdev.conf; then fi rm -f /tmp/aiofile +rm -f /tmp/spdk-pmem-pool rm -f $testdir/bdev.conf report_test_completion "bdev" timing_exit bdev diff --git a/test/unit/lib/bdev/pmem/bdev_pmem_ut.c b/test/unit/lib/bdev/pmem/bdev_pmem_ut.c index a9eb09ba6..73b4b7ba1 100644 --- a/test/unit/lib/bdev/pmem/bdev_pmem_ut.c +++ b/test/unit/lib/bdev/pmem/bdev_pmem_ut.c @@ -38,6 +38,13 @@ #include "bdev/pmem/bdev_pmem.c" +DEFINE_STUB(spdk_conf_find_section, struct spdk_conf_section *, + (struct spdk_conf *cp, const char *name), NULL); +DEFINE_STUB(spdk_conf_section_get_nval, char *, + (struct spdk_conf_section *sp, const char *key, int idx), NULL); +DEFINE_STUB(spdk_conf_section_get_nmval, char *, + (struct spdk_conf_section *sp, const char *key, int idx1, int idx2), NULL); + static struct spdk_bdev_module *g_bdev_pmem_module; static int g_bdev_module_cnt;