diff options
author | Chris Leech <christopher.leech@intel.com> | 2009-11-03 14:46:19 -0500 |
---|---|---|
committer | James Bottomley <James.Bottomley@suse.de> | 2009-12-04 13:00:57 -0500 |
commit | 8faecddb212d502b1b77936498b9a82b13c4ff44 (patch) | |
tree | 6809700a72089288aec97187fc7f6455fa6b1d95 /drivers/scsi/libfc/fc_npiv.c | |
parent | 174e1ebffd30a7599b889900089f7acef944cc6b (diff) |
[SCSI] libfc: vport link handling and fc_vport state managment
NPIV vports are managed in libfc by changing their virtual link state
when the parent N_Ports internal state changes. The vport link is only
online when the N_Port is in a ready state (logged into the fabric).
vport_state is updated as needed in this patch as well, currently the states
LINKDOWN, INITIALIZING, ACTIVE, DSIABLED, and NO_FABRIC_SUPP are used.
This also changes the fc_host port_state handling to differentiate between
LINKDOWN and OFFLINE.
Signed-off-by: Chris Leech <christopher.leech@intel.com>
Signed-off-by: Robert Love <robert.w.love@intel.com>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>
Diffstat (limited to 'drivers/scsi/libfc/fc_npiv.c')
-rw-r--r-- | drivers/scsi/libfc/fc_npiv.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/drivers/scsi/libfc/fc_npiv.c b/drivers/scsi/libfc/fc_npiv.c index 39f02c09a8d9..c68f6c7341c2 100644 --- a/drivers/scsi/libfc/fc_npiv.c +++ b/drivers/scsi/libfc/fc_npiv.c | |||
@@ -84,3 +84,78 @@ struct fc_lport *fc_vport_id_lookup(struct fc_lport *n_port, u32 port_id) | |||
84 | return lport; | 84 | return lport; |
85 | } | 85 | } |
86 | 86 | ||
87 | /* | ||
88 | * When setting the link state of vports during an lport state change, it's | ||
89 | * necessary to hold the lp_mutex of both the N_Port and the VN_Port. | ||
90 | * This tells the lockdep engine to treat the nested locking of the VN_Port | ||
91 | * as a different lock class. | ||
92 | */ | ||
93 | enum libfc_lport_mutex_class { | ||
94 | LPORT_MUTEX_NORMAL = 0, | ||
95 | LPORT_MUTEX_VN_PORT = 1, | ||
96 | }; | ||
97 | |||
98 | /** | ||
99 | * __fc_vport_setlink() - update link and status on a VN_Port | ||
100 | * @n_port: parent N_Port | ||
101 | * @vn_port: VN_Port to update | ||
102 | * | ||
103 | * Locking: must be called with both the N_Port and VN_Port lp_mutex held | ||
104 | */ | ||
105 | static void __fc_vport_setlink(struct fc_lport *n_port, | ||
106 | struct fc_lport *vn_port) | ||
107 | { | ||
108 | struct fc_vport *vport = vn_port->vport; | ||
109 | |||
110 | if (vn_port->state == LPORT_ST_DISABLED) | ||
111 | return; | ||
112 | |||
113 | if (n_port->state == LPORT_ST_READY) { | ||
114 | if (n_port->npiv_enabled) { | ||
115 | fc_vport_set_state(vport, FC_VPORT_INITIALIZING); | ||
116 | __fc_linkup(vn_port); | ||
117 | } else { | ||
118 | fc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP); | ||
119 | __fc_linkdown(vn_port); | ||
120 | } | ||
121 | } else { | ||
122 | fc_vport_set_state(vport, FC_VPORT_LINKDOWN); | ||
123 | __fc_linkdown(vn_port); | ||
124 | } | ||
125 | } | ||
126 | |||
127 | /** | ||
128 | * fc_vport_setlink() - update link and status on a VN_Port | ||
129 | * @vn_port: virtual port to update | ||
130 | */ | ||
131 | void fc_vport_setlink(struct fc_lport *vn_port) | ||
132 | { | ||
133 | struct fc_vport *vport = vn_port->vport; | ||
134 | struct Scsi_Host *shost = vport_to_shost(vport); | ||
135 | struct fc_lport *n_port = shost_priv(shost); | ||
136 | |||
137 | mutex_lock(&n_port->lp_mutex); | ||
138 | mutex_lock_nested(&vn_port->lp_mutex, LPORT_MUTEX_VN_PORT); | ||
139 | __fc_vport_setlink(n_port, vn_port); | ||
140 | mutex_unlock(&vn_port->lp_mutex); | ||
141 | mutex_unlock(&n_port->lp_mutex); | ||
142 | } | ||
143 | EXPORT_SYMBOL(fc_vport_setlink); | ||
144 | |||
145 | /** | ||
146 | * fc_vports_linkchange() - change the link state of all vports | ||
147 | * @n_port: Parent N_Port that has changed state | ||
148 | * | ||
149 | * Locking: called with the n_port lp_mutex held | ||
150 | */ | ||
151 | void fc_vports_linkchange(struct fc_lport *n_port) | ||
152 | { | ||
153 | struct fc_lport *vn_port; | ||
154 | |||
155 | list_for_each_entry(vn_port, &n_port->vports, list) { | ||
156 | mutex_lock_nested(&vn_port->lp_mutex, LPORT_MUTEX_VN_PORT); | ||
157 | __fc_vport_setlink(n_port, vn_port); | ||
158 | mutex_unlock(&vn_port->lp_mutex); | ||
159 | } | ||
160 | } | ||
161 | |||