core.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242
  1. /*
  2. * Common code for the NVMe target.
  3. * Copyright (c) 2015-2016 HGST, a Western Digital Company.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. */
  14. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  15. #include <linux/module.h>
  16. #include <linux/random.h>
  17. #include <linux/rculist.h>
  18. #include "nvmet.h"
  19. struct workqueue_struct *buffered_io_wq;
  20. static const struct nvmet_fabrics_ops *nvmet_transports[NVMF_TRTYPE_MAX];
  21. static DEFINE_IDA(cntlid_ida);
  22. /*
  23. * This read/write semaphore is used to synchronize access to configuration
  24. * information on a target system that will result in discovery log page
  25. * information change for at least one host.
  26. * The full list of resources to protected by this semaphore is:
  27. *
  28. * - subsystems list
  29. * - per-subsystem allowed hosts list
  30. * - allow_any_host subsystem attribute
  31. * - nvmet_genctr
  32. * - the nvmet_transports array
  33. *
  34. * When updating any of those lists/structures write lock should be obtained,
  35. * while when reading (popolating discovery log page or checking host-subsystem
  36. * link) read lock is obtained to allow concurrent reads.
  37. */
  38. DECLARE_RWSEM(nvmet_config_sem);
  39. u32 nvmet_ana_group_enabled[NVMET_MAX_ANAGRPS + 1];
  40. u64 nvmet_ana_chgcnt;
  41. DECLARE_RWSEM(nvmet_ana_sem);
  42. static struct nvmet_subsys *nvmet_find_get_subsys(struct nvmet_port *port,
  43. const char *subsysnqn);
  44. u16 nvmet_copy_to_sgl(struct nvmet_req *req, off_t off, const void *buf,
  45. size_t len)
  46. {
  47. if (sg_pcopy_from_buffer(req->sg, req->sg_cnt, buf, len, off) != len)
  48. return NVME_SC_SGL_INVALID_DATA | NVME_SC_DNR;
  49. return 0;
  50. }
  51. u16 nvmet_copy_from_sgl(struct nvmet_req *req, off_t off, void *buf, size_t len)
  52. {
  53. if (sg_pcopy_to_buffer(req->sg, req->sg_cnt, buf, len, off) != len)
  54. return NVME_SC_SGL_INVALID_DATA | NVME_SC_DNR;
  55. return 0;
  56. }
  57. u16 nvmet_zero_sgl(struct nvmet_req *req, off_t off, size_t len)
  58. {
  59. if (sg_zero_buffer(req->sg, req->sg_cnt, len, off) != len)
  60. return NVME_SC_SGL_INVALID_DATA | NVME_SC_DNR;
  61. return 0;
  62. }
  63. static unsigned int nvmet_max_nsid(struct nvmet_subsys *subsys)
  64. {
  65. struct nvmet_ns *ns;
  66. if (list_empty(&subsys->namespaces))
  67. return 0;
  68. ns = list_last_entry(&subsys->namespaces, struct nvmet_ns, dev_link);
  69. return ns->nsid;
  70. }
  71. static u32 nvmet_async_event_result(struct nvmet_async_event *aen)
  72. {
  73. return aen->event_type | (aen->event_info << 8) | (aen->log_page << 16);
  74. }
  75. static void nvmet_async_events_free(struct nvmet_ctrl *ctrl)
  76. {
  77. struct nvmet_req *req;
  78. while (1) {
  79. mutex_lock(&ctrl->lock);
  80. if (!ctrl->nr_async_event_cmds) {
  81. mutex_unlock(&ctrl->lock);
  82. return;
  83. }
  84. req = ctrl->async_event_cmds[--ctrl->nr_async_event_cmds];
  85. mutex_unlock(&ctrl->lock);
  86. nvmet_req_complete(req, NVME_SC_INTERNAL | NVME_SC_DNR);
  87. }
  88. }
  89. static void nvmet_async_event_work(struct work_struct *work)
  90. {
  91. struct nvmet_ctrl *ctrl =
  92. container_of(work, struct nvmet_ctrl, async_event_work);
  93. struct nvmet_async_event *aen;
  94. struct nvmet_req *req;
  95. while (1) {
  96. mutex_lock(&ctrl->lock);
  97. aen = list_first_entry_or_null(&ctrl->async_events,
  98. struct nvmet_async_event, entry);
  99. if (!aen || !ctrl->nr_async_event_cmds) {
  100. mutex_unlock(&ctrl->lock);
  101. return;
  102. }
  103. req = ctrl->async_event_cmds[--ctrl->nr_async_event_cmds];
  104. nvmet_set_result(req, nvmet_async_event_result(aen));
  105. list_del(&aen->entry);
  106. kfree(aen);
  107. mutex_unlock(&ctrl->lock);
  108. nvmet_req_complete(req, 0);
  109. }
  110. }
  111. static void nvmet_add_async_event(struct nvmet_ctrl *ctrl, u8 event_type,
  112. u8 event_info, u8 log_page)
  113. {
  114. struct nvmet_async_event *aen;
  115. aen = kmalloc(sizeof(*aen), GFP_KERNEL);
  116. if (!aen)
  117. return;
  118. aen->event_type = event_type;
  119. aen->event_info = event_info;
  120. aen->log_page = log_page;
  121. mutex_lock(&ctrl->lock);
  122. list_add_tail(&aen->entry, &ctrl->async_events);
  123. mutex_unlock(&ctrl->lock);
  124. schedule_work(&ctrl->async_event_work);
  125. }
  126. static bool nvmet_aen_disabled(struct nvmet_ctrl *ctrl, u32 aen)
  127. {
  128. if (!(READ_ONCE(ctrl->aen_enabled) & aen))
  129. return true;
  130. return test_and_set_bit(aen, &ctrl->aen_masked);
  131. }
  132. static void nvmet_add_to_changed_ns_log(struct nvmet_ctrl *ctrl, __le32 nsid)
  133. {
  134. u32 i;
  135. mutex_lock(&ctrl->lock);
  136. if (ctrl->nr_changed_ns > NVME_MAX_CHANGED_NAMESPACES)
  137. goto out_unlock;
  138. for (i = 0; i < ctrl->nr_changed_ns; i++) {
  139. if (ctrl->changed_ns_list[i] == nsid)
  140. goto out_unlock;
  141. }
  142. if (ctrl->nr_changed_ns == NVME_MAX_CHANGED_NAMESPACES) {
  143. ctrl->changed_ns_list[0] = cpu_to_le32(0xffffffff);
  144. ctrl->nr_changed_ns = U32_MAX;
  145. goto out_unlock;
  146. }
  147. ctrl->changed_ns_list[ctrl->nr_changed_ns++] = nsid;
  148. out_unlock:
  149. mutex_unlock(&ctrl->lock);
  150. }
  151. void nvmet_ns_changed(struct nvmet_subsys *subsys, u32 nsid)
  152. {
  153. struct nvmet_ctrl *ctrl;
  154. list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) {
  155. nvmet_add_to_changed_ns_log(ctrl, cpu_to_le32(nsid));
  156. if (nvmet_aen_disabled(ctrl, NVME_AEN_CFG_NS_ATTR))
  157. continue;
  158. nvmet_add_async_event(ctrl, NVME_AER_TYPE_NOTICE,
  159. NVME_AER_NOTICE_NS_CHANGED,
  160. NVME_LOG_CHANGED_NS);
  161. }
  162. }
  163. void nvmet_send_ana_event(struct nvmet_subsys *subsys,
  164. struct nvmet_port *port)
  165. {
  166. struct nvmet_ctrl *ctrl;
  167. mutex_lock(&subsys->lock);
  168. list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) {
  169. if (port && ctrl->port != port)
  170. continue;
  171. if (nvmet_aen_disabled(ctrl, NVME_AEN_CFG_ANA_CHANGE))
  172. continue;
  173. nvmet_add_async_event(ctrl, NVME_AER_TYPE_NOTICE,
  174. NVME_AER_NOTICE_ANA, NVME_LOG_ANA);
  175. }
  176. mutex_unlock(&subsys->lock);
  177. }
  178. void nvmet_port_send_ana_event(struct nvmet_port *port)
  179. {
  180. struct nvmet_subsys_link *p;
  181. down_read(&nvmet_config_sem);
  182. list_for_each_entry(p, &port->subsystems, entry)
  183. nvmet_send_ana_event(p->subsys, port);
  184. up_read(&nvmet_config_sem);
  185. }
  186. int nvmet_register_transport(const struct nvmet_fabrics_ops *ops)
  187. {
  188. int ret = 0;
  189. down_write(&nvmet_config_sem);
  190. if (nvmet_transports[ops->type])
  191. ret = -EINVAL;
  192. else
  193. nvmet_transports[ops->type] = ops;
  194. up_write(&nvmet_config_sem);
  195. return ret;
  196. }
  197. EXPORT_SYMBOL_GPL(nvmet_register_transport);
  198. void nvmet_unregister_transport(const struct nvmet_fabrics_ops *ops)
  199. {
  200. down_write(&nvmet_config_sem);
  201. nvmet_transports[ops->type] = NULL;
  202. up_write(&nvmet_config_sem);
  203. }
  204. EXPORT_SYMBOL_GPL(nvmet_unregister_transport);
  205. int nvmet_enable_port(struct nvmet_port *port)
  206. {
  207. const struct nvmet_fabrics_ops *ops;
  208. int ret;
  209. lockdep_assert_held(&nvmet_config_sem);
  210. ops = nvmet_transports[port->disc_addr.trtype];
  211. if (!ops) {
  212. up_write(&nvmet_config_sem);
  213. request_module("nvmet-transport-%d", port->disc_addr.trtype);
  214. down_write(&nvmet_config_sem);
  215. ops = nvmet_transports[port->disc_addr.trtype];
  216. if (!ops) {
  217. pr_err("transport type %d not supported\n",
  218. port->disc_addr.trtype);
  219. return -EINVAL;
  220. }
  221. }
  222. if (!try_module_get(ops->owner))
  223. return -EINVAL;
  224. ret = ops->add_port(port);
  225. if (ret) {
  226. module_put(ops->owner);
  227. return ret;
  228. }
  229. /* If the transport didn't set inline_data_size, then disable it. */
  230. if (port->inline_data_size < 0)
  231. port->inline_data_size = 0;
  232. port->enabled = true;
  233. return 0;
  234. }
  235. void nvmet_disable_port(struct nvmet_port *port)
  236. {
  237. const struct nvmet_fabrics_ops *ops;
  238. lockdep_assert_held(&nvmet_config_sem);
  239. port->enabled = false;
  240. ops = nvmet_transports[port->disc_addr.trtype];
  241. ops->remove_port(port);
  242. module_put(ops->owner);
  243. }
  244. static void nvmet_keep_alive_timer(struct work_struct *work)
  245. {
  246. struct nvmet_ctrl *ctrl = container_of(to_delayed_work(work),
  247. struct nvmet_ctrl, ka_work);
  248. pr_err("ctrl %d keep-alive timer (%d seconds) expired!\n",
  249. ctrl->cntlid, ctrl->kato);
  250. nvmet_ctrl_fatal_error(ctrl);
  251. }
  252. static void nvmet_start_keep_alive_timer(struct nvmet_ctrl *ctrl)
  253. {
  254. pr_debug("ctrl %d start keep-alive timer for %d secs\n",
  255. ctrl->cntlid, ctrl->kato);
  256. INIT_DELAYED_WORK(&ctrl->ka_work, nvmet_keep_alive_timer);
  257. schedule_delayed_work(&ctrl->ka_work, ctrl->kato * HZ);
  258. }
  259. static void nvmet_stop_keep_alive_timer(struct nvmet_ctrl *ctrl)
  260. {
  261. pr_debug("ctrl %d stop keep-alive\n", ctrl->cntlid);
  262. cancel_delayed_work_sync(&ctrl->ka_work);
  263. }
  264. static struct nvmet_ns *__nvmet_find_namespace(struct nvmet_ctrl *ctrl,
  265. __le32 nsid)
  266. {
  267. struct nvmet_ns *ns;
  268. list_for_each_entry_rcu(ns, &ctrl->subsys->namespaces, dev_link) {
  269. if (ns->nsid == le32_to_cpu(nsid))
  270. return ns;
  271. }
  272. return NULL;
  273. }
  274. struct nvmet_ns *nvmet_find_namespace(struct nvmet_ctrl *ctrl, __le32 nsid)
  275. {
  276. struct nvmet_ns *ns;
  277. rcu_read_lock();
  278. ns = __nvmet_find_namespace(ctrl, nsid);
  279. if (ns)
  280. percpu_ref_get(&ns->ref);
  281. rcu_read_unlock();
  282. return ns;
  283. }
  284. static void nvmet_destroy_namespace(struct percpu_ref *ref)
  285. {
  286. struct nvmet_ns *ns = container_of(ref, struct nvmet_ns, ref);
  287. complete(&ns->disable_done);
  288. }
  289. void nvmet_put_namespace(struct nvmet_ns *ns)
  290. {
  291. percpu_ref_put(&ns->ref);
  292. }
  293. static void nvmet_ns_dev_disable(struct nvmet_ns *ns)
  294. {
  295. nvmet_bdev_ns_disable(ns);
  296. nvmet_file_ns_disable(ns);
  297. }
  298. int nvmet_ns_enable(struct nvmet_ns *ns)
  299. {
  300. struct nvmet_subsys *subsys = ns->subsys;
  301. int ret;
  302. mutex_lock(&subsys->lock);
  303. ret = -EMFILE;
  304. if (subsys->nr_namespaces == NVMET_MAX_NAMESPACES)
  305. goto out_unlock;
  306. ret = 0;
  307. if (ns->enabled)
  308. goto out_unlock;
  309. ret = nvmet_bdev_ns_enable(ns);
  310. if (ret == -ENOTBLK)
  311. ret = nvmet_file_ns_enable(ns);
  312. if (ret)
  313. goto out_unlock;
  314. ret = percpu_ref_init(&ns->ref, nvmet_destroy_namespace,
  315. 0, GFP_KERNEL);
  316. if (ret)
  317. goto out_dev_put;
  318. if (ns->nsid > subsys->max_nsid)
  319. subsys->max_nsid = ns->nsid;
  320. /*
  321. * The namespaces list needs to be sorted to simplify the implementation
  322. * of the Identify Namepace List subcommand.
  323. */
  324. if (list_empty(&subsys->namespaces)) {
  325. list_add_tail_rcu(&ns->dev_link, &subsys->namespaces);
  326. } else {
  327. struct nvmet_ns *old;
  328. list_for_each_entry_rcu(old, &subsys->namespaces, dev_link) {
  329. BUG_ON(ns->nsid == old->nsid);
  330. if (ns->nsid < old->nsid)
  331. break;
  332. }
  333. list_add_tail_rcu(&ns->dev_link, &old->dev_link);
  334. }
  335. subsys->nr_namespaces++;
  336. nvmet_ns_changed(subsys, ns->nsid);
  337. ns->enabled = true;
  338. ret = 0;
  339. out_unlock:
  340. mutex_unlock(&subsys->lock);
  341. return ret;
  342. out_dev_put:
  343. nvmet_ns_dev_disable(ns);
  344. goto out_unlock;
  345. }
  346. void nvmet_ns_disable(struct nvmet_ns *ns)
  347. {
  348. struct nvmet_subsys *subsys = ns->subsys;
  349. mutex_lock(&subsys->lock);
  350. if (!ns->enabled)
  351. goto out_unlock;
  352. ns->enabled = false;
  353. list_del_rcu(&ns->dev_link);
  354. if (ns->nsid == subsys->max_nsid)
  355. subsys->max_nsid = nvmet_max_nsid(subsys);
  356. mutex_unlock(&subsys->lock);
  357. /*
  358. * Now that we removed the namespaces from the lookup list, we
  359. * can kill the per_cpu ref and wait for any remaining references
  360. * to be dropped, as well as a RCU grace period for anyone only
  361. * using the namepace under rcu_read_lock(). Note that we can't
  362. * use call_rcu here as we need to ensure the namespaces have
  363. * been fully destroyed before unloading the module.
  364. */
  365. percpu_ref_kill(&ns->ref);
  366. synchronize_rcu();
  367. wait_for_completion(&ns->disable_done);
  368. percpu_ref_exit(&ns->ref);
  369. mutex_lock(&subsys->lock);
  370. subsys->nr_namespaces--;
  371. nvmet_ns_changed(subsys, ns->nsid);
  372. nvmet_ns_dev_disable(ns);
  373. out_unlock:
  374. mutex_unlock(&subsys->lock);
  375. }
  376. void nvmet_ns_free(struct nvmet_ns *ns)
  377. {
  378. nvmet_ns_disable(ns);
  379. down_write(&nvmet_ana_sem);
  380. nvmet_ana_group_enabled[ns->anagrpid]--;
  381. up_write(&nvmet_ana_sem);
  382. kfree(ns->device_path);
  383. kfree(ns);
  384. }
  385. struct nvmet_ns *nvmet_ns_alloc(struct nvmet_subsys *subsys, u32 nsid)
  386. {
  387. struct nvmet_ns *ns;
  388. ns = kzalloc(sizeof(*ns), GFP_KERNEL);
  389. if (!ns)
  390. return NULL;
  391. INIT_LIST_HEAD(&ns->dev_link);
  392. init_completion(&ns->disable_done);
  393. ns->nsid = nsid;
  394. ns->subsys = subsys;
  395. down_write(&nvmet_ana_sem);
  396. ns->anagrpid = NVMET_DEFAULT_ANA_GRPID;
  397. nvmet_ana_group_enabled[ns->anagrpid]++;
  398. up_write(&nvmet_ana_sem);
  399. uuid_gen(&ns->uuid);
  400. ns->buffered_io = false;
  401. return ns;
  402. }
  403. static void __nvmet_req_complete(struct nvmet_req *req, u16 status)
  404. {
  405. u32 old_sqhd, new_sqhd;
  406. u16 sqhd;
  407. if (status)
  408. nvmet_set_status(req, status);
  409. if (req->sq->size) {
  410. do {
  411. old_sqhd = req->sq->sqhd;
  412. new_sqhd = (old_sqhd + 1) % req->sq->size;
  413. } while (cmpxchg(&req->sq->sqhd, old_sqhd, new_sqhd) !=
  414. old_sqhd);
  415. }
  416. sqhd = req->sq->sqhd & 0x0000FFFF;
  417. req->rsp->sq_head = cpu_to_le16(sqhd);
  418. req->rsp->sq_id = cpu_to_le16(req->sq->qid);
  419. req->rsp->command_id = req->cmd->common.command_id;
  420. if (req->ns)
  421. nvmet_put_namespace(req->ns);
  422. req->ops->queue_response(req);
  423. }
  424. void nvmet_req_complete(struct nvmet_req *req, u16 status)
  425. {
  426. __nvmet_req_complete(req, status);
  427. percpu_ref_put(&req->sq->ref);
  428. }
  429. EXPORT_SYMBOL_GPL(nvmet_req_complete);
  430. void nvmet_cq_setup(struct nvmet_ctrl *ctrl, struct nvmet_cq *cq,
  431. u16 qid, u16 size)
  432. {
  433. cq->qid = qid;
  434. cq->size = size;
  435. ctrl->cqs[qid] = cq;
  436. }
  437. void nvmet_sq_setup(struct nvmet_ctrl *ctrl, struct nvmet_sq *sq,
  438. u16 qid, u16 size)
  439. {
  440. sq->sqhd = 0;
  441. sq->qid = qid;
  442. sq->size = size;
  443. ctrl->sqs[qid] = sq;
  444. }
  445. static void nvmet_confirm_sq(struct percpu_ref *ref)
  446. {
  447. struct nvmet_sq *sq = container_of(ref, struct nvmet_sq, ref);
  448. complete(&sq->confirm_done);
  449. }
  450. void nvmet_sq_destroy(struct nvmet_sq *sq)
  451. {
  452. /*
  453. * If this is the admin queue, complete all AERs so that our
  454. * queue doesn't have outstanding requests on it.
  455. */
  456. if (sq->ctrl && sq->ctrl->sqs && sq->ctrl->sqs[0] == sq)
  457. nvmet_async_events_free(sq->ctrl);
  458. percpu_ref_kill_and_confirm(&sq->ref, nvmet_confirm_sq);
  459. wait_for_completion(&sq->confirm_done);
  460. wait_for_completion(&sq->free_done);
  461. percpu_ref_exit(&sq->ref);
  462. if (sq->ctrl) {
  463. nvmet_ctrl_put(sq->ctrl);
  464. sq->ctrl = NULL; /* allows reusing the queue later */
  465. }
  466. }
  467. EXPORT_SYMBOL_GPL(nvmet_sq_destroy);
  468. static void nvmet_sq_free(struct percpu_ref *ref)
  469. {
  470. struct nvmet_sq *sq = container_of(ref, struct nvmet_sq, ref);
  471. complete(&sq->free_done);
  472. }
  473. int nvmet_sq_init(struct nvmet_sq *sq)
  474. {
  475. int ret;
  476. ret = percpu_ref_init(&sq->ref, nvmet_sq_free, 0, GFP_KERNEL);
  477. if (ret) {
  478. pr_err("percpu_ref init failed!\n");
  479. return ret;
  480. }
  481. init_completion(&sq->free_done);
  482. init_completion(&sq->confirm_done);
  483. return 0;
  484. }
  485. EXPORT_SYMBOL_GPL(nvmet_sq_init);
  486. static inline u16 nvmet_check_ana_state(struct nvmet_port *port,
  487. struct nvmet_ns *ns)
  488. {
  489. enum nvme_ana_state state = port->ana_state[ns->anagrpid];
  490. if (unlikely(state == NVME_ANA_INACCESSIBLE))
  491. return NVME_SC_ANA_INACCESSIBLE;
  492. if (unlikely(state == NVME_ANA_PERSISTENT_LOSS))
  493. return NVME_SC_ANA_PERSISTENT_LOSS;
  494. if (unlikely(state == NVME_ANA_CHANGE))
  495. return NVME_SC_ANA_TRANSITION;
  496. return 0;
  497. }
  498. static inline u16 nvmet_io_cmd_check_access(struct nvmet_req *req)
  499. {
  500. if (unlikely(req->ns->readonly)) {
  501. switch (req->cmd->common.opcode) {
  502. case nvme_cmd_read:
  503. case nvme_cmd_flush:
  504. break;
  505. default:
  506. return NVME_SC_NS_WRITE_PROTECTED;
  507. }
  508. }
  509. return 0;
  510. }
  511. static u16 nvmet_parse_io_cmd(struct nvmet_req *req)
  512. {
  513. struct nvme_command *cmd = req->cmd;
  514. u16 ret;
  515. ret = nvmet_check_ctrl_status(req, cmd);
  516. if (unlikely(ret))
  517. return ret;
  518. req->ns = nvmet_find_namespace(req->sq->ctrl, cmd->rw.nsid);
  519. if (unlikely(!req->ns))
  520. return NVME_SC_INVALID_NS | NVME_SC_DNR;
  521. ret = nvmet_check_ana_state(req->port, req->ns);
  522. if (unlikely(ret))
  523. return ret;
  524. ret = nvmet_io_cmd_check_access(req);
  525. if (unlikely(ret))
  526. return ret;
  527. if (req->ns->file)
  528. return nvmet_file_parse_io_cmd(req);
  529. else
  530. return nvmet_bdev_parse_io_cmd(req);
  531. }
  532. bool nvmet_req_init(struct nvmet_req *req, struct nvmet_cq *cq,
  533. struct nvmet_sq *sq, const struct nvmet_fabrics_ops *ops)
  534. {
  535. u8 flags = req->cmd->common.flags;
  536. u16 status;
  537. req->cq = cq;
  538. req->sq = sq;
  539. req->ops = ops;
  540. req->sg = NULL;
  541. req->sg_cnt = 0;
  542. req->transfer_len = 0;
  543. req->rsp->status = 0;
  544. req->ns = NULL;
  545. /* no support for fused commands yet */
  546. if (unlikely(flags & (NVME_CMD_FUSE_FIRST | NVME_CMD_FUSE_SECOND))) {
  547. status = NVME_SC_INVALID_FIELD | NVME_SC_DNR;
  548. goto fail;
  549. }
  550. /*
  551. * For fabrics, PSDT field shall describe metadata pointer (MPTR) that
  552. * contains an address of a single contiguous physical buffer that is
  553. * byte aligned.
  554. */
  555. if (unlikely((flags & NVME_CMD_SGL_ALL) != NVME_CMD_SGL_METABUF)) {
  556. status = NVME_SC_INVALID_FIELD | NVME_SC_DNR;
  557. goto fail;
  558. }
  559. if (unlikely(!req->sq->ctrl))
  560. /* will return an error for any Non-connect command: */
  561. status = nvmet_parse_connect_cmd(req);
  562. else if (likely(req->sq->qid != 0))
  563. status = nvmet_parse_io_cmd(req);
  564. else if (req->cmd->common.opcode == nvme_fabrics_command)
  565. status = nvmet_parse_fabrics_cmd(req);
  566. else if (req->sq->ctrl->subsys->type == NVME_NQN_DISC)
  567. status = nvmet_parse_discovery_cmd(req);
  568. else
  569. status = nvmet_parse_admin_cmd(req);
  570. if (status)
  571. goto fail;
  572. if (unlikely(!percpu_ref_tryget_live(&sq->ref))) {
  573. status = NVME_SC_INVALID_FIELD | NVME_SC_DNR;
  574. goto fail;
  575. }
  576. return true;
  577. fail:
  578. __nvmet_req_complete(req, status);
  579. return false;
  580. }
  581. EXPORT_SYMBOL_GPL(nvmet_req_init);
  582. void nvmet_req_uninit(struct nvmet_req *req)
  583. {
  584. percpu_ref_put(&req->sq->ref);
  585. if (req->ns)
  586. nvmet_put_namespace(req->ns);
  587. }
  588. EXPORT_SYMBOL_GPL(nvmet_req_uninit);
  589. void nvmet_req_execute(struct nvmet_req *req)
  590. {
  591. if (unlikely(req->data_len != req->transfer_len))
  592. nvmet_req_complete(req, NVME_SC_SGL_INVALID_DATA | NVME_SC_DNR);
  593. else
  594. req->execute(req);
  595. }
  596. EXPORT_SYMBOL_GPL(nvmet_req_execute);
  597. static inline bool nvmet_cc_en(u32 cc)
  598. {
  599. return (cc >> NVME_CC_EN_SHIFT) & 0x1;
  600. }
  601. static inline u8 nvmet_cc_css(u32 cc)
  602. {
  603. return (cc >> NVME_CC_CSS_SHIFT) & 0x7;
  604. }
  605. static inline u8 nvmet_cc_mps(u32 cc)
  606. {
  607. return (cc >> NVME_CC_MPS_SHIFT) & 0xf;
  608. }
  609. static inline u8 nvmet_cc_ams(u32 cc)
  610. {
  611. return (cc >> NVME_CC_AMS_SHIFT) & 0x7;
  612. }
  613. static inline u8 nvmet_cc_shn(u32 cc)
  614. {
  615. return (cc >> NVME_CC_SHN_SHIFT) & 0x3;
  616. }
  617. static inline u8 nvmet_cc_iosqes(u32 cc)
  618. {
  619. return (cc >> NVME_CC_IOSQES_SHIFT) & 0xf;
  620. }
  621. static inline u8 nvmet_cc_iocqes(u32 cc)
  622. {
  623. return (cc >> NVME_CC_IOCQES_SHIFT) & 0xf;
  624. }
  625. static void nvmet_start_ctrl(struct nvmet_ctrl *ctrl)
  626. {
  627. lockdep_assert_held(&ctrl->lock);
  628. if (nvmet_cc_iosqes(ctrl->cc) != NVME_NVM_IOSQES ||
  629. nvmet_cc_iocqes(ctrl->cc) != NVME_NVM_IOCQES ||
  630. nvmet_cc_mps(ctrl->cc) != 0 ||
  631. nvmet_cc_ams(ctrl->cc) != 0 ||
  632. nvmet_cc_css(ctrl->cc) != 0) {
  633. ctrl->csts = NVME_CSTS_CFS;
  634. return;
  635. }
  636. ctrl->csts = NVME_CSTS_RDY;
  637. /*
  638. * Controllers that are not yet enabled should not really enforce the
  639. * keep alive timeout, but we still want to track a timeout and cleanup
  640. * in case a host died before it enabled the controller. Hence, simply
  641. * reset the keep alive timer when the controller is enabled.
  642. */
  643. mod_delayed_work(system_wq, &ctrl->ka_work, ctrl->kato * HZ);
  644. }
  645. static void nvmet_clear_ctrl(struct nvmet_ctrl *ctrl)
  646. {
  647. lockdep_assert_held(&ctrl->lock);
  648. /* XXX: tear down queues? */
  649. ctrl->csts &= ~NVME_CSTS_RDY;
  650. ctrl->cc = 0;
  651. }
  652. void nvmet_update_cc(struct nvmet_ctrl *ctrl, u32 new)
  653. {
  654. u32 old;
  655. mutex_lock(&ctrl->lock);
  656. old = ctrl->cc;
  657. ctrl->cc = new;
  658. if (nvmet_cc_en(new) && !nvmet_cc_en(old))
  659. nvmet_start_ctrl(ctrl);
  660. if (!nvmet_cc_en(new) && nvmet_cc_en(old))
  661. nvmet_clear_ctrl(ctrl);
  662. if (nvmet_cc_shn(new) && !nvmet_cc_shn(old)) {
  663. nvmet_clear_ctrl(ctrl);
  664. ctrl->csts |= NVME_CSTS_SHST_CMPLT;
  665. }
  666. if (!nvmet_cc_shn(new) && nvmet_cc_shn(old))
  667. ctrl->csts &= ~NVME_CSTS_SHST_CMPLT;
  668. mutex_unlock(&ctrl->lock);
  669. }
  670. static void nvmet_init_cap(struct nvmet_ctrl *ctrl)
  671. {
  672. /* command sets supported: NVMe command set: */
  673. ctrl->cap = (1ULL << 37);
  674. /* CC.EN timeout in 500msec units: */
  675. ctrl->cap |= (15ULL << 24);
  676. /* maximum queue entries supported: */
  677. ctrl->cap |= NVMET_QUEUE_SIZE - 1;
  678. }
  679. u16 nvmet_ctrl_find_get(const char *subsysnqn, const char *hostnqn, u16 cntlid,
  680. struct nvmet_req *req, struct nvmet_ctrl **ret)
  681. {
  682. struct nvmet_subsys *subsys;
  683. struct nvmet_ctrl *ctrl;
  684. u16 status = 0;
  685. subsys = nvmet_find_get_subsys(req->port, subsysnqn);
  686. if (!subsys) {
  687. pr_warn("connect request for invalid subsystem %s!\n",
  688. subsysnqn);
  689. req->rsp->result.u32 = IPO_IATTR_CONNECT_DATA(subsysnqn);
  690. return NVME_SC_CONNECT_INVALID_PARAM | NVME_SC_DNR;
  691. }
  692. mutex_lock(&subsys->lock);
  693. list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) {
  694. if (ctrl->cntlid == cntlid) {
  695. if (strncmp(hostnqn, ctrl->hostnqn, NVMF_NQN_SIZE)) {
  696. pr_warn("hostnqn mismatch.\n");
  697. continue;
  698. }
  699. if (!kref_get_unless_zero(&ctrl->ref))
  700. continue;
  701. *ret = ctrl;
  702. goto out;
  703. }
  704. }
  705. pr_warn("could not find controller %d for subsys %s / host %s\n",
  706. cntlid, subsysnqn, hostnqn);
  707. req->rsp->result.u32 = IPO_IATTR_CONNECT_DATA(cntlid);
  708. status = NVME_SC_CONNECT_INVALID_PARAM | NVME_SC_DNR;
  709. out:
  710. mutex_unlock(&subsys->lock);
  711. nvmet_subsys_put(subsys);
  712. return status;
  713. }
  714. u16 nvmet_check_ctrl_status(struct nvmet_req *req, struct nvme_command *cmd)
  715. {
  716. if (unlikely(!(req->sq->ctrl->cc & NVME_CC_ENABLE))) {
  717. pr_err("got cmd %d while CC.EN == 0 on qid = %d\n",
  718. cmd->common.opcode, req->sq->qid);
  719. return NVME_SC_CMD_SEQ_ERROR | NVME_SC_DNR;
  720. }
  721. if (unlikely(!(req->sq->ctrl->csts & NVME_CSTS_RDY))) {
  722. pr_err("got cmd %d while CSTS.RDY == 0 on qid = %d\n",
  723. cmd->common.opcode, req->sq->qid);
  724. return NVME_SC_CMD_SEQ_ERROR | NVME_SC_DNR;
  725. }
  726. return 0;
  727. }
  728. static bool __nvmet_host_allowed(struct nvmet_subsys *subsys,
  729. const char *hostnqn)
  730. {
  731. struct nvmet_host_link *p;
  732. if (subsys->allow_any_host)
  733. return true;
  734. list_for_each_entry(p, &subsys->hosts, entry) {
  735. if (!strcmp(nvmet_host_name(p->host), hostnqn))
  736. return true;
  737. }
  738. return false;
  739. }
  740. static bool nvmet_host_discovery_allowed(struct nvmet_req *req,
  741. const char *hostnqn)
  742. {
  743. struct nvmet_subsys_link *s;
  744. list_for_each_entry(s, &req->port->subsystems, entry) {
  745. if (__nvmet_host_allowed(s->subsys, hostnqn))
  746. return true;
  747. }
  748. return false;
  749. }
  750. bool nvmet_host_allowed(struct nvmet_req *req, struct nvmet_subsys *subsys,
  751. const char *hostnqn)
  752. {
  753. lockdep_assert_held(&nvmet_config_sem);
  754. if (subsys->type == NVME_NQN_DISC)
  755. return nvmet_host_discovery_allowed(req, hostnqn);
  756. else
  757. return __nvmet_host_allowed(subsys, hostnqn);
  758. }
  759. u16 nvmet_alloc_ctrl(const char *subsysnqn, const char *hostnqn,
  760. struct nvmet_req *req, u32 kato, struct nvmet_ctrl **ctrlp)
  761. {
  762. struct nvmet_subsys *subsys;
  763. struct nvmet_ctrl *ctrl;
  764. int ret;
  765. u16 status;
  766. status = NVME_SC_CONNECT_INVALID_PARAM | NVME_SC_DNR;
  767. subsys = nvmet_find_get_subsys(req->port, subsysnqn);
  768. if (!subsys) {
  769. pr_warn("connect request for invalid subsystem %s!\n",
  770. subsysnqn);
  771. req->rsp->result.u32 = IPO_IATTR_CONNECT_DATA(subsysnqn);
  772. goto out;
  773. }
  774. status = NVME_SC_CONNECT_INVALID_PARAM | NVME_SC_DNR;
  775. down_read(&nvmet_config_sem);
  776. if (!nvmet_host_allowed(req, subsys, hostnqn)) {
  777. pr_info("connect by host %s for subsystem %s not allowed\n",
  778. hostnqn, subsysnqn);
  779. req->rsp->result.u32 = IPO_IATTR_CONNECT_DATA(hostnqn);
  780. up_read(&nvmet_config_sem);
  781. status = NVME_SC_CONNECT_INVALID_HOST | NVME_SC_DNR;
  782. goto out_put_subsystem;
  783. }
  784. up_read(&nvmet_config_sem);
  785. status = NVME_SC_INTERNAL;
  786. ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL);
  787. if (!ctrl)
  788. goto out_put_subsystem;
  789. mutex_init(&ctrl->lock);
  790. nvmet_init_cap(ctrl);
  791. ctrl->port = req->port;
  792. INIT_WORK(&ctrl->async_event_work, nvmet_async_event_work);
  793. INIT_LIST_HEAD(&ctrl->async_events);
  794. memcpy(ctrl->subsysnqn, subsysnqn, NVMF_NQN_SIZE);
  795. memcpy(ctrl->hostnqn, hostnqn, NVMF_NQN_SIZE);
  796. kref_init(&ctrl->ref);
  797. ctrl->subsys = subsys;
  798. WRITE_ONCE(ctrl->aen_enabled, NVMET_AEN_CFG_OPTIONAL);
  799. ctrl->changed_ns_list = kmalloc_array(NVME_MAX_CHANGED_NAMESPACES,
  800. sizeof(__le32), GFP_KERNEL);
  801. if (!ctrl->changed_ns_list)
  802. goto out_free_ctrl;
  803. ctrl->cqs = kcalloc(subsys->max_qid + 1,
  804. sizeof(struct nvmet_cq *),
  805. GFP_KERNEL);
  806. if (!ctrl->cqs)
  807. goto out_free_changed_ns_list;
  808. ctrl->sqs = kcalloc(subsys->max_qid + 1,
  809. sizeof(struct nvmet_sq *),
  810. GFP_KERNEL);
  811. if (!ctrl->sqs)
  812. goto out_free_cqs;
  813. ret = ida_simple_get(&cntlid_ida,
  814. NVME_CNTLID_MIN, NVME_CNTLID_MAX,
  815. GFP_KERNEL);
  816. if (ret < 0) {
  817. status = NVME_SC_CONNECT_CTRL_BUSY | NVME_SC_DNR;
  818. goto out_free_sqs;
  819. }
  820. ctrl->cntlid = ret;
  821. ctrl->ops = req->ops;
  822. if (ctrl->subsys->type == NVME_NQN_DISC) {
  823. /* Don't accept keep-alive timeout for discovery controllers */
  824. if (kato) {
  825. status = NVME_SC_INVALID_FIELD | NVME_SC_DNR;
  826. goto out_remove_ida;
  827. }
  828. /*
  829. * Discovery controllers use some arbitrary high value in order
  830. * to cleanup stale discovery sessions
  831. *
  832. * From the latest base diff RC:
  833. * "The Keep Alive command is not supported by
  834. * Discovery controllers. A transport may specify a
  835. * fixed Discovery controller activity timeout value
  836. * (e.g., 2 minutes). If no commands are received
  837. * by a Discovery controller within that time
  838. * period, the controller may perform the
  839. * actions for Keep Alive Timer expiration".
  840. */
  841. ctrl->kato = NVMET_DISC_KATO;
  842. } else {
  843. /* keep-alive timeout in seconds */
  844. ctrl->kato = DIV_ROUND_UP(kato, 1000);
  845. }
  846. nvmet_start_keep_alive_timer(ctrl);
  847. mutex_lock(&subsys->lock);
  848. list_add_tail(&ctrl->subsys_entry, &subsys->ctrls);
  849. mutex_unlock(&subsys->lock);
  850. *ctrlp = ctrl;
  851. return 0;
  852. out_remove_ida:
  853. ida_simple_remove(&cntlid_ida, ctrl->cntlid);
  854. out_free_sqs:
  855. kfree(ctrl->sqs);
  856. out_free_cqs:
  857. kfree(ctrl->cqs);
  858. out_free_changed_ns_list:
  859. kfree(ctrl->changed_ns_list);
  860. out_free_ctrl:
  861. kfree(ctrl);
  862. out_put_subsystem:
  863. nvmet_subsys_put(subsys);
  864. out:
  865. return status;
  866. }
  867. static void nvmet_ctrl_free(struct kref *ref)
  868. {
  869. struct nvmet_ctrl *ctrl = container_of(ref, struct nvmet_ctrl, ref);
  870. struct nvmet_subsys *subsys = ctrl->subsys;
  871. mutex_lock(&subsys->lock);
  872. list_del(&ctrl->subsys_entry);
  873. mutex_unlock(&subsys->lock);
  874. nvmet_stop_keep_alive_timer(ctrl);
  875. flush_work(&ctrl->async_event_work);
  876. cancel_work_sync(&ctrl->fatal_err_work);
  877. ida_simple_remove(&cntlid_ida, ctrl->cntlid);
  878. kfree(ctrl->sqs);
  879. kfree(ctrl->cqs);
  880. kfree(ctrl->changed_ns_list);
  881. kfree(ctrl);
  882. nvmet_subsys_put(subsys);
  883. }
  884. void nvmet_ctrl_put(struct nvmet_ctrl *ctrl)
  885. {
  886. kref_put(&ctrl->ref, nvmet_ctrl_free);
  887. }
  888. static void nvmet_fatal_error_handler(struct work_struct *work)
  889. {
  890. struct nvmet_ctrl *ctrl =
  891. container_of(work, struct nvmet_ctrl, fatal_err_work);
  892. pr_err("ctrl %d fatal error occurred!\n", ctrl->cntlid);
  893. ctrl->ops->delete_ctrl(ctrl);
  894. }
  895. void nvmet_ctrl_fatal_error(struct nvmet_ctrl *ctrl)
  896. {
  897. mutex_lock(&ctrl->lock);
  898. if (!(ctrl->csts & NVME_CSTS_CFS)) {
  899. ctrl->csts |= NVME_CSTS_CFS;
  900. INIT_WORK(&ctrl->fatal_err_work, nvmet_fatal_error_handler);
  901. schedule_work(&ctrl->fatal_err_work);
  902. }
  903. mutex_unlock(&ctrl->lock);
  904. }
  905. EXPORT_SYMBOL_GPL(nvmet_ctrl_fatal_error);
  906. static struct nvmet_subsys *nvmet_find_get_subsys(struct nvmet_port *port,
  907. const char *subsysnqn)
  908. {
  909. struct nvmet_subsys_link *p;
  910. if (!port)
  911. return NULL;
  912. if (!strncmp(NVME_DISC_SUBSYS_NAME, subsysnqn,
  913. NVMF_NQN_SIZE)) {
  914. if (!kref_get_unless_zero(&nvmet_disc_subsys->ref))
  915. return NULL;
  916. return nvmet_disc_subsys;
  917. }
  918. down_read(&nvmet_config_sem);
  919. list_for_each_entry(p, &port->subsystems, entry) {
  920. if (!strncmp(p->subsys->subsysnqn, subsysnqn,
  921. NVMF_NQN_SIZE)) {
  922. if (!kref_get_unless_zero(&p->subsys->ref))
  923. break;
  924. up_read(&nvmet_config_sem);
  925. return p->subsys;
  926. }
  927. }
  928. up_read(&nvmet_config_sem);
  929. return NULL;
  930. }
  931. struct nvmet_subsys *nvmet_subsys_alloc(const char *subsysnqn,
  932. enum nvme_subsys_type type)
  933. {
  934. struct nvmet_subsys *subsys;
  935. subsys = kzalloc(sizeof(*subsys), GFP_KERNEL);
  936. if (!subsys)
  937. return NULL;
  938. subsys->ver = NVME_VS(1, 3, 0); /* NVMe 1.3.0 */
  939. /* generate a random serial number as our controllers are ephemeral: */
  940. get_random_bytes(&subsys->serial, sizeof(subsys->serial));
  941. switch (type) {
  942. case NVME_NQN_NVME:
  943. subsys->max_qid = NVMET_NR_QUEUES;
  944. break;
  945. case NVME_NQN_DISC:
  946. subsys->max_qid = 0;
  947. break;
  948. default:
  949. pr_err("%s: Unknown Subsystem type - %d\n", __func__, type);
  950. kfree(subsys);
  951. return NULL;
  952. }
  953. subsys->type = type;
  954. subsys->subsysnqn = kstrndup(subsysnqn, NVMF_NQN_SIZE,
  955. GFP_KERNEL);
  956. if (!subsys->subsysnqn) {
  957. kfree(subsys);
  958. return NULL;
  959. }
  960. kref_init(&subsys->ref);
  961. mutex_init(&subsys->lock);
  962. INIT_LIST_HEAD(&subsys->namespaces);
  963. INIT_LIST_HEAD(&subsys->ctrls);
  964. INIT_LIST_HEAD(&subsys->hosts);
  965. return subsys;
  966. }
  967. static void nvmet_subsys_free(struct kref *ref)
  968. {
  969. struct nvmet_subsys *subsys =
  970. container_of(ref, struct nvmet_subsys, ref);
  971. WARN_ON_ONCE(!list_empty(&subsys->namespaces));
  972. kfree(subsys->subsysnqn);
  973. kfree(subsys);
  974. }
  975. void nvmet_subsys_del_ctrls(struct nvmet_subsys *subsys)
  976. {
  977. struct nvmet_ctrl *ctrl;
  978. mutex_lock(&subsys->lock);
  979. list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry)
  980. ctrl->ops->delete_ctrl(ctrl);
  981. mutex_unlock(&subsys->lock);
  982. }
  983. void nvmet_subsys_put(struct nvmet_subsys *subsys)
  984. {
  985. kref_put(&subsys->ref, nvmet_subsys_free);
  986. }
  987. static int __init nvmet_init(void)
  988. {
  989. int error;
  990. nvmet_ana_group_enabled[NVMET_DEFAULT_ANA_GRPID] = 1;
  991. buffered_io_wq = alloc_workqueue("nvmet-buffered-io-wq",
  992. WQ_MEM_RECLAIM, 0);
  993. if (!buffered_io_wq) {
  994. error = -ENOMEM;
  995. goto out;
  996. }
  997. error = nvmet_init_discovery();
  998. if (error)
  999. goto out_free_work_queue;
  1000. error = nvmet_init_configfs();
  1001. if (error)
  1002. goto out_exit_discovery;
  1003. return 0;
  1004. out_exit_discovery:
  1005. nvmet_exit_discovery();
  1006. out_free_work_queue:
  1007. destroy_workqueue(buffered_io_wq);
  1008. out:
  1009. return error;
  1010. }
  1011. static void __exit nvmet_exit(void)
  1012. {
  1013. nvmet_exit_configfs();
  1014. nvmet_exit_discovery();
  1015. ida_destroy(&cntlid_ida);
  1016. destroy_workqueue(buffered_io_wq);
  1017. BUILD_BUG_ON(sizeof(struct nvmf_disc_rsp_page_entry) != 1024);
  1018. BUILD_BUG_ON(sizeof(struct nvmf_disc_rsp_page_hdr) != 1024);
  1019. }
  1020. module_init(nvmet_init);
  1021. module_exit(nvmet_exit);
  1022. MODULE_LICENSE("GPL v2");