@@ -296,27 +296,23 @@ func (util *ISCSIUtil) AttachDisk(b iscsiDiskMounter) (string, error) {
296
296
var iscsiTransport string
297
297
var lastErr error
298
298
299
- out , err := b .exec .Run ("iscsiadm" , "-m" , "iface" , "-I" , b .Iface , "-o" , "show" )
299
+ out , err := b .exec .Run ("iscsiadm" , "-m" , "iface" , "-I" , b .InitIface , "-o" , "show" )
300
300
if err != nil {
301
- klog .Errorf ("iscsi: could not read iface %s error: %s" , b .Iface , string (out ))
301
+ klog .Errorf ("iscsi: could not read iface %s error: %s" , b .InitIface , string (out ))
302
302
return "" , err
303
303
}
304
304
305
305
iscsiTransport = extractTransportname (string (out ))
306
306
307
307
bkpPortal := b .Portals
308
308
309
- // create new iface and copy parameters from pre-configured iface to the created iface
309
+ // If the initiator name was set, the iface isn't created yet,
310
+ // so create it and copy parameters from the pre-configured one
310
311
if b .InitiatorName != "" {
311
- // new iface name is <target portal>:<volume name>
312
- newIface := bkpPortal [0 ] + ":" + b .VolName
313
- err = cloneIface (b , newIface )
314
- if err != nil {
315
- klog .Errorf ("iscsi: failed to clone iface: %s error: %v" , b .Iface , err )
312
+ if err = cloneIface (b ); err != nil {
313
+ klog .Errorf ("iscsi: failed to clone iface: %s error: %v" , b .InitIface , err )
316
314
return "" , err
317
315
}
318
- // update iface name
319
- b .Iface = newIface
320
316
}
321
317
322
318
// Lock the target while we login to avoid races between 2 volumes that share the same
@@ -860,10 +856,13 @@ func parseIscsiadmShow(output string) (map[string]string, error) {
860
856
return params , nil
861
857
}
862
858
863
- func cloneIface (b iscsiDiskMounter , newIface string ) error {
859
+ func cloneIface (b iscsiDiskMounter ) error {
864
860
var lastErr error
861
+ if b .InitIface == b .Iface {
862
+ return fmt .Errorf ("iscsi: cannot clone iface with same name: %s" , b .InitIface )
863
+ }
865
864
// get pre-configured iface records
866
- out , err := b .exec .Run ("iscsiadm" , "-m" , "iface" , "-I" , b .Iface , "-o" , "show" )
865
+ out , err := b .exec .Run ("iscsiadm" , "-m" , "iface" , "-I" , b .InitIface , "-o" , "show" )
867
866
if err != nil {
868
867
lastErr = fmt .Errorf ("iscsi: failed to show iface records: %s (%v)" , string (out ), err )
869
868
return lastErr
@@ -877,22 +876,22 @@ func cloneIface(b iscsiDiskMounter, newIface string) error {
877
876
// update initiatorname
878
877
params ["iface.initiatorname" ] = b .InitiatorName
879
878
// create new iface
880
- out , err = b .exec .Run ("iscsiadm" , "-m" , "iface" , "-I" , newIface , "-o" , "new" )
879
+ out , err = b .exec .Run ("iscsiadm" , "-m" , "iface" , "-I" , b . Iface , "-o" , "new" )
881
880
if err != nil {
882
881
exit , ok := err .(utilexec.ExitError )
883
882
if ok && exit .ExitStatus () == iscsiadmErrorSessExists {
884
- klog .Infof ("iscsi: there is a session already logged in with iface %s" , newIface )
883
+ klog .Infof ("iscsi: there is a session already logged in with iface %s" , b . Iface )
885
884
} else {
886
885
lastErr = fmt .Errorf ("iscsi: failed to create new iface: %s (%v)" , string (out ), err )
887
886
return lastErr
888
887
}
889
888
}
890
889
// update new iface records
891
890
for key , val := range params {
892
- _ , err = b .exec .Run ("iscsiadm" , "-m" , "iface" , "-I" , newIface , "-o" , "update" , "-n" , key , "-v" , val )
891
+ _ , err = b .exec .Run ("iscsiadm" , "-m" , "iface" , "-I" , b . Iface , "-o" , "update" , "-n" , key , "-v" , val )
893
892
if err != nil {
894
- b .exec .Run ("iscsiadm" , "-m" , "iface" , "-I" , newIface , "-o" , "delete" )
895
- lastErr = fmt .Errorf ("iscsi: failed to update iface records: %s (%v). iface(%s) will be used" , string (out ), err , b .Iface )
893
+ b .exec .Run ("iscsiadm" , "-m" , "iface" , "-I" , b . Iface , "-o" , "delete" )
894
+ lastErr = fmt .Errorf ("iscsi: failed to update iface records: %s (%v). iface(%s) will be used" , string (out ), err , b .InitIface )
896
895
break
897
896
}
898
897
}
0 commit comments