Skip to content

Conversation

mcintyre94
Copy link
Contributor

@mcintyre94 mcintyre94 commented Feb 23, 2018

This adds the iSCSI IQN functionality and multipatching changes (they were closely intertwined, and only 2 commits were identified initially as multipathing anyway so I combined them here).

Note that the changes to datamodel.ml in a few commits were manually patched into datamodel_host.ml since the split was done since those commits were made.

@jonludlam
Copy link
Contributor

This looks fine to me.

@coveralls
Copy link

coveralls commented Feb 23, 2018

Coverage Status

Coverage increased (+0.09%) to 18.186% when pulling 2629e6b on mcintyre94:CP-26970-iscsiiqn into 694b31b on xapi-project:master.

@mcintyre94
Copy link
Contributor Author

Rebased on master now #3468 has merged :)

@lindig
Copy link
Contributor

lindig commented Feb 27, 2018

This needs a rebase

@mcintyre94
Copy link
Contributor Author

Fixup: Moved test_host_helpers.ml to ocaml/tests/

@edwintorok
Copy link
Contributor

We should replace rel_jura with rel_kolkata, this change didn't make it into jura.

@mcintyre94
Copy link
Contributor Author

Replaced rel_jura with rel_kolkata per Edwin's comment ^

field ~qualifier:DynamicRO ~lifecycle:[Published, rel_falcon, ""] ~ty:(Set (Ref _feature)) "features" "List of features available on this host"
field ~qualifier:DynamicRO ~lifecycle:[Published, rel_falcon, ""] ~ty:(Set (Ref _feature)) "features" "List of features available on this host";
field ~qualifier:StaticRO ~lifecycle:[Published, rel_kolkata, ""] ~default_value:(Some (VString "")) ~ty:String "iscsi_iqn" "The initiator IQN for the host";
field ~qualifier:StaticRO ~lifecycle:[Published, rel_kolkata, ""] ~default_value:(Some (VBool false)) ~ty:Bool "multipathing" "Specifies whether multipathing is enabled";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will likely need a run of ocp-indent

Copy link
Contributor

@mseri mseri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mostly have minor changes. I am bit scared on some potential failures and the need of the weird set+other_config flow

Test_network_event_loop.test;
Test_network.test;
Test_pusb.test;
Test_host_helpers.test;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From now on, when we introduce new tests we should probably use Alcotest from the start. No change needed, this can be ported later with the other tests

field ~qualifier:DynamicRO ~lifecycle:[Published, rel_falcon, ""] ~ty:(Set (Ref _feature)) "features" "List of features available on this host"
field ~qualifier:DynamicRO ~lifecycle:[Published, rel_falcon, ""] ~ty:(Set (Ref _feature)) "features" "List of features available on this host";
field ~qualifier:StaticRO ~lifecycle:[Published, rel_kolkata, ""] ~default_value:(Some (VString "")) ~ty:String "iscsi_iqn" "The initiator IQN for the host";
field ~qualifier:StaticRO ~lifecycle:[Published, rel_kolkata, ""] ~default_value:(Some (VBool false)) ~ty:Bool "multipathing" "Specifies whether multipathing is enabled";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the new fields break update/compatibility or they are safe? I am assuming the second, but I can never remember which fields are a problem and which not.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discussed today new fields are safe.

Db.Host.add_to_other_config ~__context ~self:host1 ~key:"multipathing" ~value:"false";
let _token = watcher token in
assert_equal !calls []

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are testing "success" cases, do we have understood failure cases that also would make sense to check?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that setting multipathing should fail (unless the DB itself fails)

if value = "" then raise Api_errors.(Server_error (invalid_value, ["value"; value]));
(* Note, the following sequence is carefully written - see the
other-config watcher thread in xapi_host_helpers.ml *)
Db.Host.remove_from_other_config ~__context ~self:host ~key:"iscsi_iqn";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is out of scope for this PR, and I suggest not to touch it. But, as a remark for the future, we really need a with_other_config_update and replace_in_other_config pair of helpers. I have seen quite a few instances of these patterns...

iqn hostname_chopped

let set_initiator_name iqn =
let hostname = Unix.gethostname () in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we protect this against Unix_errors?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd let this one to be treated as an internal error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure 👍

let flag = !Xapi_globs.multipathing_config_file in
if enabled then Unixext.touch_file flag
else begin
if Sys.file_exists flag then Sys.remove flag
Copy link
Contributor

@mseri mseri Mar 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wary of Sys... we cannot catch the errors properly when using it. Can we do this using Unix and maybe handle potential exceptions with internal_error?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced with Unixext.unlink_safe.

Copy link
Contributor

@mseri mseri Mar 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! That also prevents potential error in case of races, although I don't think it would have been the case for this.

other-config watcher thread in xapi_host_helpers.ml *)
Db.Host.remove_from_other_config ~__context ~self:host ~key:"iscsi_iqn";
Db.Host.set_iscsi_iqn ~__context ~self:host ~value;
Db.Host.add_to_other_config ~__context ~self:host ~key:"iscsi_iqn" ~value;
Copy link
Contributor

@mseri mseri Mar 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This re-triggers the loop and an rpc call to set the iscsi_iqn, thing that we have "kind of" just done above.
Why such a complicated flow?

Update: the rpc call is ignored because we compare with the db record, still it is quite a compilcate flow and the comment on the careful ordering could benefit from more context

Copy link
Contributor

@edwintorok edwintorok Mar 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a comment attempting to explain my understanding of it:

+  (* we need to first set the iscsi_iqn field and then the other-config field:
+   * setting the other-config field triggers and update on the iscsi_iqn
+   * field if they are different
+   *
+   * we want to keep the legacy `other_config:iscsi_iqn` and the new `iscsi_iqn`
+   * fields in sync:
+   * when you update the `iscsi_iqn` field we want to update `other_config`,
+   * but when updating `other_config` we want to update `iscsi_iqn` too.
+   * we have to be careful not to introduce an infinite loop of updates.
+   * *)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think it's clearer. Thanks

* GNU Lesser General Public License for more details.
*)

(** Common code between for dealing with Hosts.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably between is a leftover from an old version

intended to be run on the master. The returned function has type
[token -> token], where [token] is a string. The initial value should be
the empty string, and the returned value should be used for further
invocations. This function is exposed only for unit testing, and should
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is annoying that for unit testing we need to do this...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a ppx to do inline testing, but that would require using yet another ppx...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I know, I wasn't suggesting to do anything. It's unfortunate, I only wish there was some compiler level support for tests behind mli

@mseri
Copy link
Contributor

mseri commented Mar 1, 2018

As per current discussion, we need to update:
https://github.com/xapi-project/xen-api/blob/master/scripts/xe-set-iscsi-iqn
and/or the firstboot script calling it.

Signed-off-by: Jon Ludlam <jonathan.ludlam@citrix.com>

Note: Manually applied the patch from datamodel.ml to datamodel_host.ml

Signed-off-by: Callum McIntyre <callum.mcintyre@citrix.com>
Signed-off-by: Jon Ludlam <jonathan.ludlam@citrix.com>

Note: Manually applied the patch from datamodel.ml to datamodel_host.ml

Signed-off-by: Callum McIntyre <callum.mcintyre@citrix.com>
Signed-off-by: Jon Ludlam <jonathan.ludlam@citrix.com>
This adds the functions that set the initiatorname.iscsi file and
the thread that watches the database for host.other-config:iscsi_iqn
changes. When that thread is running a change to the other-config
field will trigger a call to Host.set_iscsi_iqn.

Signed-off-by: Jon Ludlam <jonathan.ludlam@citrix.com>
Signed-off-by: Jon Ludlam <jonathan.ludlam@citrix.com>
Signed-off-by: Jon Ludlam <jonathan.ludlam@citrix.com>
Copy link
Contributor

@mseri mseri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what concerns me, with this last comment (that practically reflects also what happens in the multipath case), this is good to go.

Before merging, please squash the fixups

jonludlam and others added 11 commits March 1, 2018 17:43
It's got to coexist with the other-config watcher

Signed-off-by: Jon Ludlam <jonathan.ludlam@citrix.com>
Signed-off-by: Jon Ludlam <jonathan.ludlam@citrix.com>
Signed-off-by: Jon Ludlam <jonathan.ludlam@citrix.com>
Signed-off-by: Gabor Igloi <gabor.igloi@citrix.com>
Signed-off-by: Jon Ludlam <jonathan.ludlam@citrix.com>
Signed-off-by: Jon Ludlam <jonathan.ludlam@citrix.com>
And keep it up to date with the value of the multipath key in
other_config for backward compatibility.
The file /var/run/nonpersistent/multipath_enabled is touched / removed
when multipathing is enabled / disabled.

Signed-off-by: Gabor Igloi <gabor.igloi@citrix.com>

Note: Manually applied the patch from datamodel.ml to datamodel_host.ml

Signed-off-by: Callum McIntyre <callum.mcintyre@citrix.com>
We have to make sure these are handled correctly on startup, in case
there was a hard reboot and had to recover from a redo log, or when one
of these are in a nonpersistent file. We cannot know the state of these
config files before xapi started, so it's the safest to sync them at
startup.

Signed-off-by: Gabor Igloi <gabor.igloi@citrix.com>
Because it's invalid.

Signed-off-by: Gabor Igloi <gabor.igloi@citrix.com>
Signed-off-by: Mark Syms <mark.syms@citrix.com>
I tested this on a DT box and it properly updated  the other-config and
iscsi_iqn host param.

Signed-off-by: Edwin Török <edvin.torok@citrix.com>
@edwintorok
Copy link
Contributor

Thanks for the review, lets wait until Travis build finishes.

@edwintorok edwintorok merged commit abe969c into xapi-project:master Mar 1, 2018
@edwintorok edwintorok deleted the CP-26970-iscsiiqn branch March 1, 2018 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants