diff options
author | James Smart <jsmart2021@gmail.com> | 2017-09-19 17:01:50 -0400 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2017-09-25 14:42:11 -0400 |
commit | fddc9923c6d41de9fe7b1f323a3cece53e046c88 (patch) | |
tree | 2eb7c2776d6779e8f98e66144a0a3040bbf43187 | |
parent | 6b71f9e1e849f82abb4a8d54ce7f4b1c71f19ac4 (diff) |
nvme-fcloop: fix port deletes and callbacks
Now that there are potentially long delays between when a remoteport or
targetport delete calls is made and when the callback occurs (dev_loss_tmo
timeout), no longer block in the delete routines and move the final nport
puts to the callbacks.
Moved the fcloop_nport_get/put/free routines to avoid forward declarations.
Ensure port_info structs used in registrations are nulled in case fields
are not set (ex: devloss_tmo values).
Signed-off-by: James Smart <james.smart@broadcom.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r-- | drivers/nvme/target/fcloop.c | 102 |
1 files changed, 38 insertions, 64 deletions
diff --git a/drivers/nvme/target/fcloop.c b/drivers/nvme/target/fcloop.c index 1fd1afbb8b2a..7b75d9de55ab 100644 --- a/drivers/nvme/target/fcloop.c +++ b/drivers/nvme/target/fcloop.c | |||
@@ -224,8 +224,6 @@ struct fcloop_nport { | |||
224 | struct fcloop_lport *lport; | 224 | struct fcloop_lport *lport; |
225 | struct list_head nport_list; | 225 | struct list_head nport_list; |
226 | struct kref ref; | 226 | struct kref ref; |
227 | struct completion rport_unreg_done; | ||
228 | struct completion tport_unreg_done; | ||
229 | u64 node_name; | 227 | u64 node_name; |
230 | u64 port_name; | 228 | u64 port_name; |
231 | u32 port_role; | 229 | u32 port_role; |
@@ -631,6 +629,32 @@ fcloop_fcp_abort(struct nvme_fc_local_port *localport, | |||
631 | } | 629 | } |
632 | 630 | ||
633 | static void | 631 | static void |
632 | fcloop_nport_free(struct kref *ref) | ||
633 | { | ||
634 | struct fcloop_nport *nport = | ||
635 | container_of(ref, struct fcloop_nport, ref); | ||
636 | unsigned long flags; | ||
637 | |||
638 | spin_lock_irqsave(&fcloop_lock, flags); | ||
639 | list_del(&nport->nport_list); | ||
640 | spin_unlock_irqrestore(&fcloop_lock, flags); | ||
641 | |||
642 | kfree(nport); | ||
643 | } | ||
644 | |||
645 | static void | ||
646 | fcloop_nport_put(struct fcloop_nport *nport) | ||
647 | { | ||
648 | kref_put(&nport->ref, fcloop_nport_free); | ||
649 | } | ||
650 | |||
651 | static int | ||
652 | fcloop_nport_get(struct fcloop_nport *nport) | ||
653 | { | ||
654 | return kref_get_unless_zero(&nport->ref); | ||
655 | } | ||
656 | |||
657 | static void | ||
634 | fcloop_localport_delete(struct nvme_fc_local_port *localport) | 658 | fcloop_localport_delete(struct nvme_fc_local_port *localport) |
635 | { | 659 | { |
636 | struct fcloop_lport *lport = localport->private; | 660 | struct fcloop_lport *lport = localport->private; |
@@ -644,8 +668,7 @@ fcloop_remoteport_delete(struct nvme_fc_remote_port *remoteport) | |||
644 | { | 668 | { |
645 | struct fcloop_rport *rport = remoteport->private; | 669 | struct fcloop_rport *rport = remoteport->private; |
646 | 670 | ||
647 | /* release any threads waiting for the unreg to complete */ | 671 | fcloop_nport_put(rport->nport); |
648 | complete(&rport->nport->rport_unreg_done); | ||
649 | } | 672 | } |
650 | 673 | ||
651 | static void | 674 | static void |
@@ -653,8 +676,7 @@ fcloop_targetport_delete(struct nvmet_fc_target_port *targetport) | |||
653 | { | 676 | { |
654 | struct fcloop_tport *tport = targetport->private; | 677 | struct fcloop_tport *tport = targetport->private; |
655 | 678 | ||
656 | /* release any threads waiting for the unreg to complete */ | 679 | fcloop_nport_put(tport->nport); |
657 | complete(&tport->nport->tport_unreg_done); | ||
658 | } | 680 | } |
659 | 681 | ||
660 | #define FCLOOP_HW_QUEUES 4 | 682 | #define FCLOOP_HW_QUEUES 4 |
@@ -722,6 +744,7 @@ fcloop_create_local_port(struct device *dev, struct device_attribute *attr, | |||
722 | goto out_free_opts; | 744 | goto out_free_opts; |
723 | } | 745 | } |
724 | 746 | ||
747 | memset(&pinfo, 0, sizeof(pinfo)); | ||
725 | pinfo.node_name = opts->wwnn; | 748 | pinfo.node_name = opts->wwnn; |
726 | pinfo.port_name = opts->wwpn; | 749 | pinfo.port_name = opts->wwpn; |
727 | pinfo.port_role = opts->roles; | 750 | pinfo.port_role = opts->roles; |
@@ -804,32 +827,6 @@ fcloop_delete_local_port(struct device *dev, struct device_attribute *attr, | |||
804 | return ret ? ret : count; | 827 | return ret ? ret : count; |
805 | } | 828 | } |
806 | 829 | ||
807 | static void | ||
808 | fcloop_nport_free(struct kref *ref) | ||
809 | { | ||
810 | struct fcloop_nport *nport = | ||
811 | container_of(ref, struct fcloop_nport, ref); | ||
812 | unsigned long flags; | ||
813 | |||
814 | spin_lock_irqsave(&fcloop_lock, flags); | ||
815 | list_del(&nport->nport_list); | ||
816 | spin_unlock_irqrestore(&fcloop_lock, flags); | ||
817 | |||
818 | kfree(nport); | ||
819 | } | ||
820 | |||
821 | static void | ||
822 | fcloop_nport_put(struct fcloop_nport *nport) | ||
823 | { | ||
824 | kref_put(&nport->ref, fcloop_nport_free); | ||
825 | } | ||
826 | |||
827 | static int | ||
828 | fcloop_nport_get(struct fcloop_nport *nport) | ||
829 | { | ||
830 | return kref_get_unless_zero(&nport->ref); | ||
831 | } | ||
832 | |||
833 | static struct fcloop_nport * | 830 | static struct fcloop_nport * |
834 | fcloop_alloc_nport(const char *buf, size_t count, bool remoteport) | 831 | fcloop_alloc_nport(const char *buf, size_t count, bool remoteport) |
835 | { | 832 | { |
@@ -938,6 +935,7 @@ fcloop_create_remote_port(struct device *dev, struct device_attribute *attr, | |||
938 | if (!nport) | 935 | if (!nport) |
939 | return -EIO; | 936 | return -EIO; |
940 | 937 | ||
938 | memset(&pinfo, 0, sizeof(pinfo)); | ||
941 | pinfo.node_name = nport->node_name; | 939 | pinfo.node_name = nport->node_name; |
942 | pinfo.port_name = nport->port_name; | 940 | pinfo.port_name = nport->port_name; |
943 | pinfo.port_role = nport->port_role; | 941 | pinfo.port_role = nport->port_role; |
@@ -979,24 +977,12 @@ __unlink_remote_port(struct fcloop_nport *nport) | |||
979 | } | 977 | } |
980 | 978 | ||
981 | static int | 979 | static int |
982 | __wait_remoteport_unreg(struct fcloop_nport *nport, struct fcloop_rport *rport) | 980 | __remoteport_unreg(struct fcloop_nport *nport, struct fcloop_rport *rport) |
983 | { | 981 | { |
984 | int ret; | ||
985 | |||
986 | if (!rport) | 982 | if (!rport) |
987 | return -EALREADY; | 983 | return -EALREADY; |
988 | 984 | ||
989 | init_completion(&nport->rport_unreg_done); | 985 | return nvme_fc_unregister_remoteport(rport->remoteport); |
990 | |||
991 | ret = nvme_fc_unregister_remoteport(rport->remoteport); | ||
992 | if (ret) | ||
993 | return ret; | ||
994 | |||
995 | wait_for_completion(&nport->rport_unreg_done); | ||
996 | |||
997 | fcloop_nport_put(nport); | ||
998 | |||
999 | return ret; | ||
1000 | } | 986 | } |
1001 | 987 | ||
1002 | static ssize_t | 988 | static ssize_t |
@@ -1029,7 +1015,7 @@ fcloop_delete_remote_port(struct device *dev, struct device_attribute *attr, | |||
1029 | if (!nport) | 1015 | if (!nport) |
1030 | return -ENOENT; | 1016 | return -ENOENT; |
1031 | 1017 | ||
1032 | ret = __wait_remoteport_unreg(nport, rport); | 1018 | ret = __remoteport_unreg(nport, rport); |
1033 | 1019 | ||
1034 | return ret ? ret : count; | 1020 | return ret ? ret : count; |
1035 | } | 1021 | } |
@@ -1086,24 +1072,12 @@ __unlink_target_port(struct fcloop_nport *nport) | |||
1086 | } | 1072 | } |
1087 | 1073 | ||
1088 | static int | 1074 | static int |
1089 | __wait_targetport_unreg(struct fcloop_nport *nport, struct fcloop_tport *tport) | 1075 | __targetport_unreg(struct fcloop_nport *nport, struct fcloop_tport *tport) |
1090 | { | 1076 | { |
1091 | int ret; | ||
1092 | |||
1093 | if (!tport) | 1077 | if (!tport) |
1094 | return -EALREADY; | 1078 | return -EALREADY; |
1095 | 1079 | ||
1096 | init_completion(&nport->tport_unreg_done); | 1080 | return nvmet_fc_unregister_targetport(tport->targetport); |
1097 | |||
1098 | ret = nvmet_fc_unregister_targetport(tport->targetport); | ||
1099 | if (ret) | ||
1100 | return ret; | ||
1101 | |||
1102 | wait_for_completion(&nport->tport_unreg_done); | ||
1103 | |||
1104 | fcloop_nport_put(nport); | ||
1105 | |||
1106 | return ret; | ||
1107 | } | 1081 | } |
1108 | 1082 | ||
1109 | static ssize_t | 1083 | static ssize_t |
@@ -1136,7 +1110,7 @@ fcloop_delete_target_port(struct device *dev, struct device_attribute *attr, | |||
1136 | if (!nport) | 1110 | if (!nport) |
1137 | return -ENOENT; | 1111 | return -ENOENT; |
1138 | 1112 | ||
1139 | ret = __wait_targetport_unreg(nport, tport); | 1113 | ret = __targetport_unreg(nport, tport); |
1140 | 1114 | ||
1141 | return ret ? ret : count; | 1115 | return ret ? ret : count; |
1142 | } | 1116 | } |
@@ -1223,11 +1197,11 @@ static void __exit fcloop_exit(void) | |||
1223 | 1197 | ||
1224 | spin_unlock_irqrestore(&fcloop_lock, flags); | 1198 | spin_unlock_irqrestore(&fcloop_lock, flags); |
1225 | 1199 | ||
1226 | ret = __wait_targetport_unreg(nport, tport); | 1200 | ret = __targetport_unreg(nport, tport); |
1227 | if (ret) | 1201 | if (ret) |
1228 | pr_warn("%s: Failed deleting target port\n", __func__); | 1202 | pr_warn("%s: Failed deleting target port\n", __func__); |
1229 | 1203 | ||
1230 | ret = __wait_remoteport_unreg(nport, rport); | 1204 | ret = __remoteport_unreg(nport, rport); |
1231 | if (ret) | 1205 | if (ret) |
1232 | pr_warn("%s: Failed deleting remote port\n", __func__); | 1206 | pr_warn("%s: Failed deleting remote port\n", __func__); |
1233 | 1207 | ||