Debian Codegraph @

heartbeat/nvmet-namespace

raw
1 #!/bin/sh
2 #
3 #
4 # NVMe-oF (rdma, tcp, fc) OCF RA. Exports and manages NVMe targets.
5 #
6 # (c) 2021 LINBIT HA-Solutions GmbH, written by Philipp Reisner
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of version 2 of the GNU General Public License as
10 # published by the Free Software Foundation.
11 #
12 # This program is distributed in the hope that it would be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 #
16 # Further, this software is distributed without any warranty that it is
17 # free of the rightful claim of any third person regarding infringement
18 # or the like. Any license provided herein, whether implied or
19 # otherwise, applies only to this software file. Patent licenses, if
20 # any, provided herein do not apply to combinations of this program with
21 # other software, or any other product whatsoever.
22 #
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write the Free Software Foundation,
25 # Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
26 #
27
28 #######################################################################
29 # Initialization:
30 : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
31 . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
32
33 OCF_RESKEY_namespace_id_default="1"
34 : ${OCF_RESKEY_namespace_id=${OCF_RESKEY_namespace_id_default}}
35
36 OCF_RESKEY_nguid_default=""
37 : ${OCF_RESKEY_nguid=${OCF_RESKEY_nguid_default}}
38 #######################################################################
39
40 meta_data() {
41 cat <<END
42 <?xml version="1.0"?>
43 <!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
44 <resource-agent name="nvmet-namespace" version="0.9">
45 <version>1.0</version>
46
47 <longdesc lang="en">
48 Manages NVMe-oF namespaces. An NVMe-oF namespace is part of an NVMe-oF target.
49 A namespace must be created after the subsystem. It is similar in concept to
50 the LUN of an iSCSI target.
51 </longdesc>
52 <shortdesc lang="en">NVMe-oF target export agent</shortdesc>
53
54 <parameters>
55 <parameter name="nqn" required="1" unique="1">
56 <longdesc lang="en">
57 The NVMe Qualified Name (NQN) is used to identify the remote NVMe
58 storage target. It is similar to an iSCSI Qualified Name
59 (IQN). While it is a free-form string, you should follow the convention:
60 nqn.2014-08.com.vendor:nvme:nvm-subsystem-sn-12345
61 You need to refer here to the NQN of an NVMe Subsystem your created
62 with the NVMeSubsystem resource agent.
63 </longdesc>
64 <shortdesc lang="en">NVMe Qualified Name</shortdesc>
65 <content type="string" />
66 </parameter>
67
68 <parameter name="namespace_id" required="0" unique="1">
69 <longdesc lang="en">
70 The NVMe namespace id (number).
71 </longdesc>
72 <shortdesc lang="en">namespace id</shortdesc>
73 <content type="integer" default="${OCF_RESKEY_namespace_id_default}"/>
74 </parameter>
75
76 <parameter name="backing_path" required="1" unique="0">
77 <longdesc lang="en">
78 The full path to the block device or file that should be exposed through this
79 namespace.
80 </longdesc>
81 <shortdesc lang="en">block device full path</shortdesc>
82 <content type="string"/>
83 </parameter>
84
85 <parameter name="uuid" required="1" unique="1">
86 <longdesc lang="en">
87 The UUID that should be exposed by NVMe. Create it using uuidgen. This is
88 necessary for the initiators to accept the namespace from the new server
89 after failover.
90 </longdesc>
91 <shortdesc lang="en">UUID</shortdesc>
92 <content type="string"/>
93 </parameter>
94
95 <parameter name="nguid" required="0" unique="1">
96 <longdesc lang="en">
97 NGUID stands for Namespace Globally Unique Identifier. Seems to be optional,
98 looks like e.g. VMWare ESXi7 uses it to identify namespaces.
99 Use 'uuidgen' to create it.
100 </longdesc>
101 <shortdesc lang="en">NGUID</shortdesc>
102 <content type="string" default="${OCF_RESKEY_nguid_default}"/>
103 </parameter>
104
105 </parameters>
106
107 <actions>
108 <action name="start" timeout="10s" />
109 <action name="stop" timeout="10s" />
110 <action name="status" timeout="10s" interval="10s" depth="0" />
111 <action name="monitor" timeout="10s" interval="10s" depth="0" />
112 <action name="meta-data" timeout="5s" />
113 <action name="validate-all" timeout="10s" />
114 </actions>
115 </resource-agent>
116 END
117 }
118
119 #######################################################################
120
121 nvmet_namespace_usage() {
122 cat <<END
123 usage: $0 {start|stop|status|monitor|validate-all|meta-data}
124
125 Expects to have a fully populated OCF RA-compliant environment set.
126 END
127 }
128
129 nvmet_namespace_start() {
130 nvmet_namespace_monitor
131 if [ $? = $OCF_SUCCESS ]; then
132 return $OCF_SUCCESS
133 fi
134
135 if [ ! -d ${subsys} ]; then
136 ocf_log err "$subsys does not exist -- Create it with NVMeSubsystem."
137 exit $OCF_ERR_GENERIC
138 fi
139
140 mkdir ${namespace}
141 echo "${OCF_RESKEY_backing_path}" > ${namespace}/device_path
142 echo "${OCF_RESKEY_uuid}" > ${namespace}/device_uuid
143 [ "${OCF_RESKEY_nguid}" ] && echo "${OCF_RESKEY_nguid}" > ${namespace}/device_nguid
144 echo 1 > ${namespace}/enable
145
146 nvmet_namespace_monitor
147 }
148
149 nvmet_namespace_stop() {
150 nvmet_namespace_monitor
151 if [ $? -eq $OCF_NOT_RUNNING ]; then
152 return $OCF_SUCCESS
153 fi
154
155 rmdir ${namespace}
156
157 return $OCF_SUCCESS
158 }
159
160 nvmet_namespace_monitor() {
161 [ -d ${namespace} ] || return $OCF_NOT_RUNNING
162 return $OCF_SUCCESS
163 }
164
165 nvmet_namespace_validate() {
166 if [ ! -d /sys/kernel/config/nvmet ]; then
167 ocf_log err "/sys/kernel/config/nvmet does not exist -- Load the nvmet.ko linux kernel module."
168 exit $OCF_ERR_INSTALLED
169 fi
170 subsys=/sys/kernel/config/nvmet/subsystems/${OCF_RESKEY_nqn}
171 namespace=${subsys}/namespaces/${OCF_RESKEY_namespace_id}
172
173 return $OCF_SUCCESS
174 }
175
176
177 case $1 in
178 meta-data)
179 meta_data
180 exit $OCF_SUCCESS
181 ;;
182 usage|help)
183 nvmet_namespace_usage
184 exit $OCF_SUCCESS
185 ;;
186 esac
187
188 # Everything except usage and meta-data must pass the validate test
189 nvmet_namespace_validate
190
191 case $__OCF_ACTION in
192 start) nvmet_namespace_start;;
193 stop) nvmet_namespace_stop;;
194 monitor|status) nvmet_namespace_monitor;;
195 reload) ocf_log info "Reloading..."
196 nvmet_namespace_start
197 ;;
198 validate-all) ;;
199 *) nvmet_namespace_usage
200 exit $OCF_ERR_UNIMPLEMENTED
201 ;;
202 esac
203 rc=$?
204 ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc"
205 exit $rc