@@ -296,27 +296,23 @@ func (util *ISCSIUtil) AttachDisk(b iscsiDiskMounter) (string, error) {
296296 var iscsiTransport string
297297 var lastErr error
298298
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" )
300300 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 ))
302302 return "" , err
303303 }
304304
305305 iscsiTransport = extractTransportname (string (out ))
306306
307307 bkpPortal := b .Portals
308308
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
310311 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 )
316314 return "" , err
317315 }
318- // update iface name
319- b .Iface = newIface
320316 }
321317
322318 // 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) {
860856 return params , nil
861857}
862858
863- func cloneIface (b iscsiDiskMounter , newIface string ) error {
859+ func cloneIface (b iscsiDiskMounter ) error {
864860 var lastErr error
861+ if b .InitIface == b .Iface {
862+ return fmt .Errorf ("iscsi: cannot clone iface with same name: %s" , b .InitIface )
863+ }
865864 // 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" )
867866 if err != nil {
868867 lastErr = fmt .Errorf ("iscsi: failed to show iface records: %s (%v)" , string (out ), err )
869868 return lastErr
@@ -877,22 +876,22 @@ func cloneIface(b iscsiDiskMounter, newIface string) error {
877876 // update initiatorname
878877 params ["iface.initiatorname" ] = b .InitiatorName
879878 // 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" )
881880 if err != nil {
882881 exit , ok := err .(utilexec.ExitError )
883882 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 )
885884 } else {
886885 lastErr = fmt .Errorf ("iscsi: failed to create new iface: %s (%v)" , string (out ), err )
887886 return lastErr
888887 }
889888 }
890889 // update new iface records
891890 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 )
893892 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 )
896895 break
897896 }
898897 }
0 commit comments