Skip to content

Commit

Permalink
Merge pull request #3 from anitashekar/devel
Browse files Browse the repository at this point in the history
Initial commit for the NVMeoF gateway to Ceph management daemon

Reviewed-by: Ilya Dryomov <idryomov@gmail.com>
Reviewed by: Jonas Pfefferle <jpf@zurich.ibm.com>
Reviewed by: Mykola Golub <mykola.golub@clyso.com>
Reviewed by: Scott Peterson <scott.d.peterson@intel.com>
  • Loading branch information
trociny authored Nov 3, 2021
2 parents ce221f7 + a293095 commit a3f8d5a
Show file tree
Hide file tree
Showing 11 changed files with 1,202 additions and 1 deletion.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

__pycache__
spdk
nvme_gw_pb2_grpc.py
nvme_gw_pb2.py
server.crt
server.key
client.crt
client.key
17 changes: 17 additions & 0 deletions COPYING
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

Source: http://github.com/ceph/ceph-nvmeof

Files: *
License: LGPL-3.0-or-later (see LICENSE)

Files: proto/nvme_gw.proto
License: MIT
Copyright: Copyright (c) 2021 International Business Machines

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


63 changes: 63 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007

Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>

Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.

This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below.

0. Additional Definitions.

As used herein, “this License” refers to version 3 of the GNU Lesser General Public License, and the “GNU GPL” refers to version 3 of the GNU General Public License.

“The Library” refers to a covered work governed by this License, other than an Application or a Combined Work as defined below.

An “Application” is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library.

A “Combined Work” is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the “Linked Version”.

The “Minimal Corresponding Source” for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version.

The “Corresponding Application Code” for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work.

1. Exception to Section 3 of the GNU GPL.

You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL.

2. Conveying Modified Versions.

If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version:

a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.

The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following:

a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license document.
4. Combined Works.

You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following:

a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license document.
c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.
1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version.
e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.)
5. Combined Libraries.

You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following:

a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.

The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.

Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation.

If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.
205 changes: 204 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,204 @@
# ceph-nvmeof
# nvmeof-gateway

Management gateway daemon to setup access to Ceph storage over NVMeoF

This daemon runs as root. It provides the ability to export existing RBD images as NVMeoF namespaces. Creation of RBD images is not within the scope of this daemon.

# Initial configuration

1. The daemon is a gRPC server, so the host running the server will need to install gRPC packages:

$ python3 -m pip install grpcio
$ python3 -m pip install grpcio-tools
2. Modify the config file (default nvme_gw.config) to reflect the IP/ Port where the server can be reached:

gateway_addr = <IP address at which the client can reach the gateway>
gateway_port = <port at which the client can reach the gateway>

3. To [enable mTLS](#mtls-configuration-for-testing-purposes) using self signed certificates, edit the config file to set:

enable_auth = True # Setting this to False will open an insecure port

4. Compile protobuf files for gRPC:

$ python3 -m grpc_tools.protoc --proto_path=./proto ./proto/nvme_gw.proto --python_out=. --grpc_python_out=.

5. SPDK v21.04 is included in this repository. Edit the config file to set:

spdk_path = <complete path to SPDK parent directory>
spdk_tgt = <relative path to SPDK target executable>

6. Setup SPDK

Navigate to the spdk folder & install dependencies:

$ ./scripts/pkgdep.sh

Initialize configuration:

$ apt install librbd-dev
$ ./configure --with-rbd

Build the SPDK app:

$ make

SPDK requires hugepages to be set up:

$ sh -c 'echo 4096 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages'

7. Start the gateway server daemon:

$ python3 nvme_gw_server.py [-c config_filename]


# CLI Usage

The CLI tool can be used to initiate a connection to the gateway and run commands to configure the NVMe targets.

Run the tool with the -h flag to see a list of available commands:

$ python3 ./nvme_gw_cli.py -h
usage: python3 ./nvme_gw_cli.py [-h] [-c CONFIG]
{create_bdev,create_subsystem,create_namespace,allow_any_hosts,create_transport,create_listener} ...

CLI to manage NVMe gateways

positional arguments:
{create_bdev,create_subsystem,create_namespace,allow_any_hosts,create_transport,create_listener}

optional arguments:
-h, --help show this help message and exit
-c CONFIG, --config CONFIG
Path to config file

Example:

$ python3 ./nvme_gw_cli.py create_bdev -h
usage: python3 ./nvme_gw_cli.py create_bdev [-h] -i IMAGE -p POOL [-b BDEV_NAME] [-u USER] [-s BLOCK_SIZE]

optional arguments:
-h, --help show this help message and exit
-i IMAGE, --image IMAGE
RBD image name
-p POOL, --pool POOL Ceph pool name
-b BDEV_NAME, --bdev BDEV_NAME
Bdev name
-u USER, --user USER User ID
-s BLOCK_SIZE, --block_size BLOCK_SIZE
Block size

# mTLS Configuration for testing purposes

For testing purposes, self signed certificates and keys can be generated locally using OpenSSL.

For the server, generate credentials for server name 'my.server' in files called server.key and server.crt:

$ openssl req -x509 -newkey rsa:4096 -nodes -keyout server.key -out server.crt -days 3650 -subj '/CN=my.server'

For client:

$ openssl req -x509 -newkey rsa:4096 -nodes -keyout client.key -out client.crt -days 3650 -subj '/CN=client1'

Indicate the location of the keys and certificates in the config file:

[mtls]

server_key = ./server.key
client_key = ./client.key
server_cert = ./server.crt
client_cert = ./client.crt

# Example NVMe volume access

1. Start the gateway server:

$ python3 nvme_gw_server.py
INFO:root:SPDK PATH: /path/to/spdk
INFO:root:Starting /path/to/spdk/tgt/nvmf_tgt all -u
INFO:root:Attempting to initialize SPDK: server_addr: /var/tmp/spdk.sock, port: 5260, conn_retries: 3, timeout: 60.0
INFO: Setting log level to ERROR
INFO:JSONRPCClient(/var/tmp/spdk.sock):Setting log level to ERROR


2. Run the CLI (ensure a ceph pool 'rbd' with an rbdimage 'mytestdevimage' is created prior to this step):

$ python3 ./nvme_gw_cli.py create_bdev -i mytestdevimage -p rbd
INFO:root:Created bdev: Ceph0
$ python3 ./nvme_gw_cli.py create_subsystem -n nqn.2016-06.io.spdk:cnode1 -s SPDK00000000000001
INFO:root:Created subsystem: nqn.2016-06.io.spdk:cnode1
$ python3 ./nvme_gw_cli.py create_namespace -n nqn.2016-06.io.spdk:cnode1 -b Ceph0
INFO:root:Added namespace 1 to nqn.2016-06.io.spdk:cnode1
$ python3 ./nvme_gw_cli.py allow_any_hosts -n nqn.2016-06.io.spdk:cnode1
INFO:root:All host access to nqn.2016-06.io.spdk:cnode1: True
$ python3 ./nvme_gw_cli.py create_transport -t TCP
INFO:root:Created TCP transport: True
$ python3 ./nvme_gw_cli.py create_listener -n nqn.2016-06.io.spdk:cnode1 -a 192.168.50.4 -s 5001
INFO:root:Created nqn.2016-06.io.spdk:cnode1 listener: True

3. On the storage client system (ubuntu-21.04):

- Install requisite packages

$ apt install nvme-cli
$ modprobe nvme-fabrics

- Run nvme command to discover available subsystems

$ nvme discover -t tcp -a 192.168.50.4 -s 5001

Discovery Log Number of Records 1, Generation counter 6
=====Discovery Log Entry 0======
trtype: tcp
adrfam: ipv4
subtype: nvme subsystem
treq: not required
portid: 0
trsvcid: 5001
subnqn: nqn.2016-06.io.spdk:cnode1
traddr: 192.168.50.4
sectype: none

- Connect to desired subsystem

$ nvme connect -t tcp --traddr 192.168.50.4 -s 5001 -n nqn.2016-06.io.spdk:cnode1

- List targets that are available

$ nvme list
Node SN Model Namespace Usage Format FW Rev
---------------- -------------------- ---------------------------------------- --------- -------------------------- ---------------- --------
/dev/nvme0n1 SPDK00000000000001 SPDK bdev Controller 1 6.44 GB / 6.44 GB 4 KiB + 0 B 21.04

- Create a filesystem on the desired target

$ mkfs /dev/nvme0n1

mke2fs 1.45.7 (28-Jan-2021)
Creating filesystem with 1572864 4k blocks and 393216 inodes
Filesystem UUID: 1308f6ff-621b-4d17-b127-65eded31abe2
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736

Allocating group tables: done
Writing inode tables: done
Writing superblocks and filesystem accounting information: done

- Mount and use the storage volume

$ mount /dev/nvme0n1 /mnt

$ ls /mnt
lost+found

$ echo "NVMe volume" > /mnt/test.txt

$ ls /mnt
lost+found test.txt
32 changes: 32 additions & 0 deletions nvme_gw.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# Copyright (c) 2021 International Business Machines
# All rights reserved.
#
# SPDX-License-Identifier: LGPL-3.0-or-later
#
# Authors: anita.shekar@ibm.com, sandy.kaur@ibm.com
#

[config]

enable_auth = False
gateway_addr = [::]
gateway_port = 5500
spdk_path = /path/to/spdk
spdk_tgt = spdk/build/bin/nvmf_tgt
grpc_server_max_workers = 10

[mtls]

server_key = ./server.key
client_key = ./client.key
server_cert = ./server.crt
client_cert = ./client.crt

[spdk]

spdk_server_addr = /var/tmp/spdk.sock
spdk_port = 5260
timeout = 60.0
log_level = ERROR
conn_retries = 3
Loading

0 comments on commit a3f8d5a

Please sign in to comment.