loop.c (d22524a4782a943bb02a9cf6885ac470210aabfc) loop.c (c5017e85705bfea721732e153305d1988ff965c2)
1/*
2 * NVMe over Fabrics loopback device.
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 *

--- 39 unchanged lines hidden (view full) ---

48 struct blk_mq_tag_set admin_tag_set;
49
50 struct list_head list;
51 struct blk_mq_tag_set tag_set;
52 struct nvme_loop_iod async_event_iod;
53 struct nvme_ctrl ctrl;
54
55 struct nvmet_ctrl *target_ctrl;
1/*
2 * NVMe over Fabrics loopback device.
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 *

--- 39 unchanged lines hidden (view full) ---

48 struct blk_mq_tag_set admin_tag_set;
49
50 struct list_head list;
51 struct blk_mq_tag_set tag_set;
52 struct nvme_loop_iod async_event_iod;
53 struct nvme_ctrl ctrl;
54
55 struct nvmet_ctrl *target_ctrl;
56 struct work_struct delete_work;
57};
58
59static inline struct nvme_loop_ctrl *to_loop_ctrl(struct nvme_ctrl *ctrl)
60{
61 return container_of(ctrl, struct nvme_loop_ctrl, ctrl);
62}
63
64struct nvme_loop_queue {

--- 369 unchanged lines hidden (view full) ---

434
435 blk_mq_quiesce_queue(ctrl->ctrl.admin_q);
436 blk_mq_tagset_busy_iter(&ctrl->admin_tag_set,
437 nvme_cancel_request, &ctrl->ctrl);
438 blk_mq_unquiesce_queue(ctrl->ctrl.admin_q);
439 nvme_loop_destroy_admin_queue(ctrl);
440}
441
56};
57
58static inline struct nvme_loop_ctrl *to_loop_ctrl(struct nvme_ctrl *ctrl)
59{
60 return container_of(ctrl, struct nvme_loop_ctrl, ctrl);
61}
62
63struct nvme_loop_queue {

--- 369 unchanged lines hidden (view full) ---

433
434 blk_mq_quiesce_queue(ctrl->ctrl.admin_q);
435 blk_mq_tagset_busy_iter(&ctrl->admin_tag_set,
436 nvme_cancel_request, &ctrl->ctrl);
437 blk_mq_unquiesce_queue(ctrl->ctrl.admin_q);
438 nvme_loop_destroy_admin_queue(ctrl);
439}
440
442static void nvme_loop_del_ctrl_work(struct work_struct *work)
441static void nvme_loop_delete_ctrl_host(struct nvme_ctrl *ctrl)
443{
442{
444 struct nvme_loop_ctrl *ctrl = container_of(work,
445 struct nvme_loop_ctrl, delete_work);
446
447 nvme_stop_ctrl(&ctrl->ctrl);
448 nvme_remove_namespaces(&ctrl->ctrl);
449 nvme_loop_shutdown_ctrl(ctrl);
450 nvme_uninit_ctrl(&ctrl->ctrl);
451 nvme_put_ctrl(&ctrl->ctrl);
443 nvme_stop_ctrl(ctrl);
444 nvme_remove_namespaces(ctrl);
445 nvme_loop_shutdown_ctrl(to_loop_ctrl(ctrl));
446 nvme_uninit_ctrl(ctrl);
447 nvme_put_ctrl(ctrl);
452}
453
448}
449
454static int __nvme_loop_del_ctrl(struct nvme_loop_ctrl *ctrl)
455{
456 if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_DELETING))
457 return -EBUSY;
458
459 if (!queue_work(nvme_wq, &ctrl->delete_work))
460 return -EBUSY;
461
462 return 0;
463}
464
465static int nvme_loop_del_ctrl(struct nvme_ctrl *nctrl)
466{
467 struct nvme_loop_ctrl *ctrl = to_loop_ctrl(nctrl);
468 int ret;
469
470 ret = __nvme_loop_del_ctrl(ctrl);
471 if (ret)
472 return ret;
473
474 flush_work(&ctrl->delete_work);
475
476 return 0;
477}
478
479static void nvme_loop_delete_ctrl(struct nvmet_ctrl *nctrl)
480{
481 struct nvme_loop_ctrl *ctrl;
482
483 mutex_lock(&nvme_loop_ctrl_mutex);
484 list_for_each_entry(ctrl, &nvme_loop_ctrl_list, list) {
485 if (ctrl->ctrl.cntlid == nctrl->cntlid)
450static void nvme_loop_delete_ctrl(struct nvmet_ctrl *nctrl)
451{
452 struct nvme_loop_ctrl *ctrl;
453
454 mutex_lock(&nvme_loop_ctrl_mutex);
455 list_for_each_entry(ctrl, &nvme_loop_ctrl_list, list) {
456 if (ctrl->ctrl.cntlid == nctrl->cntlid)
486 __nvme_loop_del_ctrl(ctrl);
457 nvme_delete_ctrl(&ctrl->ctrl);
487 }
488 mutex_unlock(&nvme_loop_ctrl_mutex);
489}
490
491static void nvme_loop_reset_ctrl_work(struct work_struct *work)
492{
493 struct nvme_loop_ctrl *ctrl =
494 container_of(work, struct nvme_loop_ctrl, ctrl.reset_work);

--- 39 unchanged lines hidden (view full) ---

534 .name = "loop",
535 .module = THIS_MODULE,
536 .flags = NVME_F_FABRICS,
537 .reg_read32 = nvmf_reg_read32,
538 .reg_read64 = nvmf_reg_read64,
539 .reg_write32 = nvmf_reg_write32,
540 .free_ctrl = nvme_loop_free_ctrl,
541 .submit_async_event = nvme_loop_submit_async_event,
458 }
459 mutex_unlock(&nvme_loop_ctrl_mutex);
460}
461
462static void nvme_loop_reset_ctrl_work(struct work_struct *work)
463{
464 struct nvme_loop_ctrl *ctrl =
465 container_of(work, struct nvme_loop_ctrl, ctrl.reset_work);

--- 39 unchanged lines hidden (view full) ---

505 .name = "loop",
506 .module = THIS_MODULE,
507 .flags = NVME_F_FABRICS,
508 .reg_read32 = nvmf_reg_read32,
509 .reg_read64 = nvmf_reg_read64,
510 .reg_write32 = nvmf_reg_write32,
511 .free_ctrl = nvme_loop_free_ctrl,
512 .submit_async_event = nvme_loop_submit_async_event,
542 .delete_ctrl = nvme_loop_del_ctrl,
513 .delete_ctrl = nvme_loop_delete_ctrl_host,
543};
544
545static int nvme_loop_create_io_queues(struct nvme_loop_ctrl *ctrl)
546{
547 int ret;
548
549 ret = nvme_loop_init_io_queues(ctrl);
550 if (ret)

--- 45 unchanged lines hidden (view full) ---

596 int ret;
597
598 ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL);
599 if (!ctrl)
600 return ERR_PTR(-ENOMEM);
601 ctrl->ctrl.opts = opts;
602 INIT_LIST_HEAD(&ctrl->list);
603
514};
515
516static int nvme_loop_create_io_queues(struct nvme_loop_ctrl *ctrl)
517{
518 int ret;
519
520 ret = nvme_loop_init_io_queues(ctrl);
521 if (ret)

--- 45 unchanged lines hidden (view full) ---

567 int ret;
568
569 ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL);
570 if (!ctrl)
571 return ERR_PTR(-ENOMEM);
572 ctrl->ctrl.opts = opts;
573 INIT_LIST_HEAD(&ctrl->list);
574
604 INIT_WORK(&ctrl->delete_work, nvme_loop_del_ctrl_work);
605 INIT_WORK(&ctrl->ctrl.reset_work, nvme_loop_reset_ctrl_work);
606
607 ret = nvme_init_ctrl(&ctrl->ctrl, dev, &nvme_loop_ctrl_ops,
608 0 /* no quirks, we're perfect! */);
609 if (ret)
610 goto out_put_ctrl;
611
612 ret = -ENOMEM;

--- 113 unchanged lines hidden (view full) ---

726{
727 struct nvme_loop_ctrl *ctrl, *next;
728
729 nvmf_unregister_transport(&nvme_loop_transport);
730 nvmet_unregister_transport(&nvme_loop_ops);
731
732 mutex_lock(&nvme_loop_ctrl_mutex);
733 list_for_each_entry_safe(ctrl, next, &nvme_loop_ctrl_list, list)
575 INIT_WORK(&ctrl->ctrl.reset_work, nvme_loop_reset_ctrl_work);
576
577 ret = nvme_init_ctrl(&ctrl->ctrl, dev, &nvme_loop_ctrl_ops,
578 0 /* no quirks, we're perfect! */);
579 if (ret)
580 goto out_put_ctrl;
581
582 ret = -ENOMEM;

--- 113 unchanged lines hidden (view full) ---

696{
697 struct nvme_loop_ctrl *ctrl, *next;
698
699 nvmf_unregister_transport(&nvme_loop_transport);
700 nvmet_unregister_transport(&nvme_loop_ops);
701
702 mutex_lock(&nvme_loop_ctrl_mutex);
703 list_for_each_entry_safe(ctrl, next, &nvme_loop_ctrl_list, list)
734 __nvme_loop_del_ctrl(ctrl);
704 nvme_delete_ctrl(&ctrl->ctrl);
735 mutex_unlock(&nvme_loop_ctrl_mutex);
736
737 flush_workqueue(nvme_wq);
738}
739
740module_init(nvme_loop_init_module);
741module_exit(nvme_loop_cleanup_module);
742
743MODULE_LICENSE("GPL v2");
744MODULE_ALIAS("nvmet-transport-254"); /* 254 == NVMF_TRTYPE_LOOP */
705 mutex_unlock(&nvme_loop_ctrl_mutex);
706
707 flush_workqueue(nvme_wq);
708}
709
710module_init(nvme_loop_init_module);
711module_exit(nvme_loop_cleanup_module);
712
713MODULE_LICENSE("GPL v2");
714MODULE_ALIAS("nvmet-transport-254"); /* 254 == NVMF_TRTYPE_LOOP */