Skip to content

Commit 1c19aa8

Browse files
committed
CA-411122: do not call set-iscsi-initiator with an empty string for IQN
Back in 2018 a4a94b3 rejected empty IQNs in set_iscsi_iqn API calls. However hosts are created with an empty IQN, and if this code runs too early then it will attempt to call `set-iscsi-initiator` with an empty string for the IQN: ``` /opt/xensource/libexec/set-iscsi-initiator myhost ``` About a second later the script is called again with the correct value. This could potentially result in the iscsid service being restarted multiple times (and if a restart is still pending when restart is called a 2nd time I'm not sure it'll take effect, so we might be left with an empty initiator). It is best to avoid setting empty initiators. The exception would be raised and ignore due to the log_and_ignore in the caller. Also log wherever the IQN is set using %S, so that we notice if it ends up containing some extra whitespace characters. Signed-off-by: Edwin Török <[email protected]>
1 parent 983a48a commit 1c19aa8

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

ocaml/xapi/xapi_host.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2790,6 +2790,7 @@ let set_uefi_certificates ~__context ~host:_ ~value:_ =
27902790
let set_iscsi_iqn ~__context ~host ~value =
27912791
if value = "" then
27922792
raise Api_errors.(Server_error (invalid_value, ["value"; value])) ;
2793+
D.debug "%s: iqn=%S" __FUNCTION__ value ;
27932794
(* Note, the following sequence is carefully written - see the
27942795
other-config watcher thread in xapi_host_helpers.ml *)
27952796
Db.Host.remove_from_other_config ~__context ~self:host ~key:"iscsi_iqn" ;

ocaml/xapi/xapi_host_helpers.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,10 +497,13 @@ module Configuration = struct
497497
[iqn; hostname_chopped]
498498

499499
let set_initiator_name iqn =
500+
if iqn = "" then
501+
raise Api_errors.(Server_error (invalid_value, ["iqn"; iqn])) ;
500502
let hostname = Unix.gethostname () in
501503
(* CA-377454 - robustness, create dir if necessary *)
502504
Unixext.mkdir_rec "/var/lock/sm/iscsiadm" 0o700 ;
503505
let args = make_set_initiator_args iqn hostname in
506+
D.debug "%s: iqn=%S" __FUNCTION__ iqn ;
504507
ignore (Helpers.call_script !Xapi_globs.set_iSCSI_initiator_script args)
505508

506509
let set_multipathing enabled =
@@ -541,6 +544,7 @@ module Configuration = struct
541544
| Some "" ->
542545
()
543546
| Some iqn when iqn <> host_rec.API.host_iscsi_iqn ->
547+
D.debug "%s: iqn=%S" __FUNCTION__ iqn ;
544548
Client.Client.Host.set_iscsi_iqn ~rpc ~session_id ~host:host_ref
545549
~value:iqn
546550
| _ ->

0 commit comments

Comments
 (0)