Skip to contentSkip to conversation

Towards a restartable oxenstored

PATCH In review Jonathan Davies 6 participants 17 messages Apr 7, 2017 – Apr 10, 2017

lore
Share & tools
lore
#0 lore raw

cover Towards a restartable oxenstored

In order to make oxenstored restartable, we need to save internal state to a file on exit and restore from this file on startup.

Much of the infrastructure for making oxenstored restartable already existed, but a handful of bugs prevented it from working.

After these patches I can do the following:

    # xenstore-write foo bar
    # xenstore-read foo
    bar
    # xenstore-ls -f -p | sort > contents.before
    # killall oxenstored
    # ./oxenstored --restart
    # xenstore-ls -f -p | sort > contents.after
    # diff contents.before contents.after
    # xenstore-read foo
    bar

... and I can do similar kinds of activity in a guest across the restart.

Note that clients of local socket connections will get EPIPE or similar when oxenstored terminates. Hence these clients need to handle this gracefully, e.g. by attempting to reconnect, if they wish to tolerate xenstored restarts.

With these patches, the state saved on exit contains information about inter-domain connections and active watches, and the contents of the store. Some internal state is not currently preserved over a restart:
1. quota usage info
2. partially-read and already-queued packets from rings
3. recent transaction history

Items 1 and 2 are probably needed for this to be considered fully functional, so fixes for them should follow. But the bugfixes in this series already represent a worthwhile improvement.

Jonathan Davies (5):
oxenstored: initialise logging earlier
oxenstored: avoid leading slash in paths in saved store state
oxenstored: save remote evtchn port, not local port
oxenstored: improve event-channel binding logging
oxenstored: make --restart option best-effort

 tools/ocaml/xenstored/domain.ml    |  4 ++--
 tools/ocaml/xenstored/store.ml     |  8 +++++++-
 tools/ocaml/xenstored/xenstored.ml | 10 ++++++----
 3 files changed, 15 insertions(+), 7 deletions(-)
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#2 lore raw

PATCH 2/5 oxenstored: avoid leading slash in paths in saved store state

Internally, paths are represented as lists of strings, where
* path "/" is represented by []
* path "/local/domain/0" is represented by ["local"; "domain"; "0"]
(see comment for Store.Path.t).

However, the traversal function generated paths like

    [""; "local"; "domain"; "0"]

because the name of the root node is "". Change it to generate paths correctly.

Furthermore, the function passed to Store.dump_fct would render the node "foo" under the path [] as "//foo". Change this to return "/foo".

---
 tools/ocaml/xenstored/store.ml     | 8 +++++++-
 tools/ocaml/xenstored/xenstored.ml | 2 +-
 2 files changed, 8 insertions(+), 2 deletions(-)
tools/ocaml/xenstored/store.ml +7 -1
index 9f619b8..13cf3b5 100644
@@ -122,6 +122,11 @@ let of_string s =
 		| "" :: path when is_valid path -> path
 		| _ -> raise Define.Invalid_path
 
+let of_path_and_name path name =
+	match path, name with
+	| [], "" -> []
+	| _ -> path @ [name]
+
 let create path connection_path =
 	of_string (Utils.path_validate path connection_path)
 
@@ -343,7 +348,8 @@ let path_exists store path =
 let traversal root_node f =
 	let rec _traversal path node =
 		f path node;
-		List.iter (_traversal (path @ [ Symbol.to_string node.Node.name ])) node.Node.children
+		let node_path = Path.of_path_and_name path (Symbol.to_string node.Node.name) in
+		List.iter (_traversal node_path) node.Node.children
 		in
 	_traversal [] root_node
 
tools/ocaml/xenstored/xenstored.ml +1 -1
index 09da257..77fd9e3 100644
@@ -213,7 +213,7 @@ let to_channel store cons chan =
 	(* dump the store *)
 	Store.dump_fct store (fun path node ->
 		let name, perms, value = Store.Node.unpack node in
-		let fullpath = (Store.Path.to_string path) ^ "/" ^ name in
+		let fullpath = Store.Path.to_string (Store.Path.of_path_and_name path name) in
 		let permstr = Perms.Node.to_string perms in
 		fprintf chan "store,%s,%s,%s\n" (hexify fullpath) (hexify permstr) (hexify value)
 	);
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#3 lore raw

PATCH 3/5 oxenstored: save remote evtchn port, not local port

In reply to Jonathan Davies

Previously, Domain.dump output the number of the local port corresponding to each domain's event-channel. However, when oxenstored exits, it closes /dev/xen/evtchn which causes the kernel to close the local port (evtchn_release), so this port is no longer useful.

Instead, store the remote port. This can be used to reconnect the event-channel by binding the original remote port to a fresh local port.

Indeed, the logic for parsing the stored state already expects a remote port as it passes the parsed port number to Domain.make (via Domains.create), which takes a remote port.

---
 tools/ocaml/xenstored/domain.ml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/ocaml/xenstored/domain.ml +1 -1
index 4515650..eda2ea9 100644
@@ -62,7 +62,7 @@ let string_of_port = function
 | Some x -> string_of_int (Xeneventchn.to_int x)
 
 let dump d chan =
-	fprintf chan "dom,%d,%nd,%s\n" d.id d.mfn (string_of_port d.port)
+	fprintf chan "dom,%d,%nd,%d\n" d.id d.mfn d.remote_port
 
 let notify dom = match dom.port with
 | None ->
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#4 lore raw

PATCH 4/5 oxenstored: improve event-channel binding logging

In reply to Jonathan Davies

It's useful to see a bit more detail when an inter-domain event-channel is bound, especially over an oxenstored restart.

---
 tools/ocaml/xenstored/domain.ml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/ocaml/xenstored/domain.ml +1 -1
index eda2ea9..b0a01b0 100644
@@ -72,7 +72,7 @@ let notify dom = match dom.port with
 
 let bind_interdomain dom =
 	dom.port <- Some (Event.bind_interdomain dom.eventchn dom.id dom.remote_port);
-	debug "domain %d bound port %s" dom.id (string_of_port dom.port)
+	debug "bound domain %d remote port %d to local port %s" dom.id dom.remote_port (string_of_port dom.port)
 
 
 let close dom =
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#5 lore raw

PATCH 5/5 oxenstored: make --restart option best-effort

In reply to Jonathan Davies

Only attempt to restore from saved state if it exists.

Without this, oxenstored immediately exits with an exception if the --restart option is provided but the state file is not present.

(The time-of-check to time-of-use race isn't a concern as oxenstored is the only thing that should write the state file.)

---
 tools/ocaml/xenstored/xenstored.ml | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
tools/ocaml/xenstored/xenstored.ml +3 -2
index 77fd9e3..bb780d0 100644
@@ -287,8 +287,9 @@ let _ =
 
 	Logging.init_xenstored_log();
 
-	if cf.restart then (
-		DB.from_file store domains cons (Paths.xen_run_stored ^ "/db");
+	let filename = Paths.xen_run_stored ^ "/db" in
+	if cf.restart && Sys.file_exists filename then (
+		DB.from_file store domains cons filename;
 		Event.bind_dom_exc_virq eventchn
 	) else (
 		if !Disk.enable then (
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw

PATCH 1/5 oxenstored: initialise logging earlier

In reply to Jonathan Davies

Otherwise we miss out on messages from things that try to log earlier in the start-up procedure.

---
 tools/ocaml/xenstored/xenstored.ml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/ocaml/xenstored/xenstored.ml +2 -1
index 05ace4d..09da257 100644
@@ -285,6 +285,8 @@ let _ =
 
 	let quit = ref false in
 
+	Logging.init_xenstored_log();
+
 	if cf.restart then (
 		DB.from_file store domains cons (Paths.xen_run_stored ^ "/db");
 		Event.bind_dom_exc_virq eventchn
@@ -311,7 +313,6 @@ let _ =
 	Sys.set_signal Sys.sigusr1 (Sys.Signal_handle (fun i -> sigusr1_handler store));
 	Sys.set_signal Sys.sigpipe Sys.Signal_ignore;
 
-	Logging.init_xenstored_log();
 	if cf.activate_access_log then begin
 		let post_rotate () = DB.to_file store cons (Paths.xen_run_stored ^ "/db") in
 		Logging.init_access_log post_rotate
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#6 lore raw
In reply to Jonathan Davies
Quoted 38 lines · Jonathan Davies

In order to make oxenstored restartable, we need to save internal state to a file on exit and restore from this file on startup.

Much of the infrastructure for making oxenstored restartable already existed, but a handful of bugs prevented it from working.

After these patches I can do the following:

    # xenstore-write foo bar
    # xenstore-read foo
    bar
    # xenstore-ls -f -p | sort > contents.before
    # killall oxenstored
    # ./oxenstored --restart
    # xenstore-ls -f -p | sort > contents.after
    # diff contents.before contents.after
    # xenstore-read foo
    bar

... and I can do similar kinds of activity in a guest across the restart.

Note that clients of local socket connections will get EPIPE or similar when oxenstored terminates. Hence these clients need to handle this gracefully, e.g. by attempting to reconnect, if they wish to tolerate xenstored restarts.

With these patches, the state saved on exit contains information about inter-domain connections and active watches, and the contents of the store. Some internal state is not currently preserved over a restart:
1. quota usage info
2. partially-read and already-queued packets from rings
3. recent transaction history

Items 1 and 2 are probably needed for this to be considered fully functional, so fixes for them should follow. But the bugfixes in this series already represent a worthwhile improvement.

Quoted 7 lines

Jonathan Davies (5):
oxenstored: initialise logging earlier
oxenstored: avoid leading slash in paths in saved store state
oxenstored: save remote evtchn port, not local port
oxenstored: improve event-channel binding logging
oxenstored: make --restart option best-effort

I think this series can be considered for 4.9, given they are small changes.

The code looks good as far as I'm concerned. I will wait for OCaml experts to review them.

Quoted 8 lines
 tools/ocaml/xenstored/domain.ml    |  4 ++--
 tools/ocaml/xenstored/store.ml     |  8 +++++++-
 tools/ocaml/xenstored/xenstored.ml | 10 ++++++----
 3 files changed, 15 insertions(+), 7 deletions(-)
Signature · 1 line
2.7.4

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#10 lore raw
In reply to Jonathan Davies
Quoted 10 lines · Jonathan Davies

With these patches, the state saved on exit contains information about inter-domain connections and active watches, and the contents of the store. Some internal state is not currently preserved over a restart:
1. quota usage info
2. partially-read and already-queued packets from rings
3. recent transaction history

Items 1 and 2 are probably needed for this to be considered fully functional, so fixes for them should follow. But the bugfixes in this series already represent a worthwhile improvement.

Shouldn't quota usage be recalculated as part of parsing the stashed database? After all, the database is the canonical state of the world. What would you do if the database and the stashed quota differ?

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#7 lore raw
In reply to Wei Liu
Quoted 47 lines · Wei Liu
Quoted 38 lines · Jonathan Davies

In order to make oxenstored restartable, we need to save internal state to a file on exit and restore from this file on startup.

Much of the infrastructure for making oxenstored restartable already existed, but a handful of bugs prevented it from working.

After these patches I can do the following:

    # xenstore-write foo bar
    # xenstore-read foo
    bar
    # xenstore-ls -f -p | sort > contents.before
    # killall oxenstored
    # ./oxenstored --restart
    # xenstore-ls -f -p | sort > contents.after
    # diff contents.before contents.after
    # xenstore-read foo
    bar

... and I can do similar kinds of activity in a guest across the restart.

Note that clients of local socket connections will get EPIPE or similar when oxenstored terminates. Hence these clients need to handle this gracefully, e.g. by attempting to reconnect, if they wish to tolerate xenstored restarts.

With these patches, the state saved on exit contains information about inter-domain connections and active watches, and the contents of the store. Some internal state is not currently preserved over a restart:
1. quota usage info
2. partially-read and already-queued packets from rings
3. recent transaction history

Items 1 and 2 are probably needed for this to be considered fully functional, so fixes for them should follow. But the bugfixes in this series already represent a worthwhile improvement.

Quoted 7 lines

Jonathan Davies (5):
oxenstored: initialise logging earlier
oxenstored: avoid leading slash in paths in saved store state
oxenstored: save remote evtchn port, not local port
oxenstored: improve event-channel binding logging
oxenstored: make --restart option best-effort

Quoted 10 lines

I think this series can be considered for 4.9, given they are small changes.

The code looks good as far as I'm concerned. I will wait for OCaml experts to review them.

Quoted 4 lines
 tools/ocaml/xenstored/domain.ml    |  4 ++--
 tools/ocaml/xenstored/store.ml     |  8 +++++++-
 tools/ocaml/xenstored/xenstored.ml | 10 ++++++----
 3 files changed, 15 insertions(+), 7 deletions(-)

Is the data format of the saved state documented somewhere? I'd appreciate any pointer or (in case there is no such doc) a followup patch to add the documentation.

This would help later in case C-xenstored learns restartability, too, and someone would like to switch the xenstored type on a running system.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#11 lore raw
In reply to Andrew Cooper
Quoted 8 lines · Andrew Cooper
Quoted 7 lines · Jonathan Davies

With these patches, the state saved on exit contains information about inter-domain connections and active watches, and the contents of the store. Some internal state is not currently preserved over a restart:
1. quota usage info
2. partially-read and already-queued packets from rings
3. recent transaction history

Quoted 7 lines
Quoted 3 lines

Items 1 and 2 are probably needed for this to be considered fully functional, so fixes for them should follow. But the bugfixes in this series already represent a worthwhile improvement.

Shouldn't quota usage be recalculated as part of parsing the stashed database? After all, the database is the canonical state of the world. What would you do if the database and the stashed quota differ?

You're right. This would be recalculated when loading the saved state.

I had in mind that there were some quotas of "dynamic" things that aren't derived from the contents alone, but I can't spot them in the code so must have been imagining them.

So there's no need to dump quota state to disk.

Thanks,
Jonathan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#8 lore raw
In reply to Juergen Gross
Quoted 7 lines · Juergen Gross

Is the data format of the saved state documented somewhere? I'd appreciate any pointer or (in case there is no such doc) a followup patch to add the documentation.

This would help later in case C-xenstored learns restartability, too, and someone would like to switch the xenstored type on a running system.

That's a good idea. No, it's not currently documented as far as I'm aware.

My impression is that the existing bits of oxenstored code that produced this output have never been used in practice. So now would be a good time to review the format of the saved state before it potentially gets more widely used.

Thanks,
Jonathan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#9 lore raw
Quoted 9 lines · Jonathan Davies
Quoted 7 lines · Juergen Gross

Is the data format of the saved state documented somewhere? I'd appreciate any pointer or (in case there is no such doc) a followup patch to add the documentation.

This would help later in case C-xenstored learns restartability, too, and someone would like to switch the xenstored type on a running system.

Quoted 6 lines

That's a good idea. No, it's not currently documented as far as I'm aware.

My impression is that the existing bits of oxenstored code that produced this output have never been used in practice. So now would be a good time to review the format of the saved state before it potentially gets more widely used.

Oh yes, please!

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#12 lore raw
In reply to Jonathan Davies
Quoted 6 lines · Jonathan Davies
tools/ocaml/xenstored/domain.ml    |  4 ++--
tools/ocaml/xenstored/store.ml     |  8 +++++++-
tools/ocaml/xenstored/xenstored.ml | 10 ++++++----

The OCaml code is looking good and I’d be happy to take it as it is.

I noticed that the (existing) code for handling the path for the database file uses (^) to construct it. It would be better to use Filename.concat and this could have been done as part of this patch. Admittedly, this would be mostly cosmetic as it would help mainly portability to Windows.

— Christian

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#13 lore raw
Quoted 8 lines · Christian Lindig
Quoted 6 lines · Jonathan Davies
tools/ocaml/xenstored/domain.ml    |  4 ++--
tools/ocaml/xenstored/store.ml     |  8 +++++++-
tools/ocaml/xenstored/xenstored.ml | 10 ++++++----

The OCaml code is looking good and I’d be happy to take it as it is.

Can I translate that to reviewed-by's?

Quoted 7 lines

I noticed that the (existing) code for handling the path for the database file uses (^) to construct it. It would be better to use Filename.concat and this could have been done as part of this patch. Admittedly, this would be mostly cosmetic as it would help mainly portability to Windows.

Feel free to submit patches to fix that when the development window opens.

Wei.

Quoted 1 line

— Christian

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#14 lore raw
Quoted 7 lines · Wei Liu
Quoted 3 lines · Christian Lindig
Quoted 3 lines · Jonathan Davies
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
tools/ocaml/xenstored/domain.ml    |  4 ++--
tools/ocaml/xenstored/store.ml     |  8 +++++++-
tools/ocaml/xenstored/xenstored.ml | 10 ++++++----

The OCaml code is looking good and I’d be happy to take it as it is.

Can I translate that to reviewed-by's?

Yes.

— C
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#15 lore raw
In reply to Jonathan Davies

Cc Julien

These are small bug fixes that can be safely committed, IMHO.

Quoted 45 lines · Jonathan Davies

In order to make oxenstored restartable, we need to save internal state to a file on exit and restore from this file on startup.

Much of the infrastructure for making oxenstored restartable already existed, but a handful of bugs prevented it from working.

After these patches I can do the following:

    # xenstore-write foo bar
    # xenstore-read foo
    bar
    # xenstore-ls -f -p | sort > contents.before
    # killall oxenstored
    # ./oxenstored --restart
    # xenstore-ls -f -p | sort > contents.after
    # diff contents.before contents.after
    # xenstore-read foo
    bar

... and I can do similar kinds of activity in a guest across the restart.

Note that clients of local socket connections will get EPIPE or similar when oxenstored terminates. Hence these clients need to handle this gracefully, e.g. by attempting to reconnect, if they wish to tolerate xenstored restarts.

With these patches, the state saved on exit contains information about inter-domain connections and active watches, and the contents of the store. Some internal state is not currently preserved over a restart:
1. quota usage info
2. partially-read and already-queued packets from rings
3. recent transaction history

Items 1 and 2 are probably needed for this to be considered fully functional, so fixes for them should follow. But the bugfixes in this series already represent a worthwhile improvement.

Jonathan Davies (5):
oxenstored: initialise logging earlier
oxenstored: avoid leading slash in paths in saved store state
oxenstored: save remote evtchn port, not local port
oxenstored: improve event-channel binding logging
oxenstored: make --restart option best-effort

Quoted 8 lines
 tools/ocaml/xenstored/domain.ml    |  4 ++--
 tools/ocaml/xenstored/store.ml     |  8 +++++++-
 tools/ocaml/xenstored/xenstored.ml | 10 ++++++----
 3 files changed, 15 insertions(+), 7 deletions(-)
Signature · 1 line
2.7.4

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#16 lore raw

Hi Wei,

Quoted 3 lines · Wei Liu

Cc Julien

These are small bug fixes that can be safely committed, IMHO.

Cheers,

Quoted 55 lines · Jonathan Davies
Quoted 53 lines

In order to make oxenstored restartable, we need to save internal state to a file on exit and restore from this file on startup.

Much of the infrastructure for making oxenstored restartable already existed, but a handful of bugs prevented it from working.

After these patches I can do the following:

    # xenstore-write foo bar
    # xenstore-read foo
    bar
    # xenstore-ls -f -p | sort > contents.before
    # killall oxenstored
    # ./oxenstored --restart
    # xenstore-ls -f -p | sort > contents.after
    # diff contents.before contents.after
    # xenstore-read foo
    bar

... and I can do similar kinds of activity in a guest across the restart.

Note that clients of local socket connections will get EPIPE or similar when oxenstored terminates. Hence these clients need to handle this gracefully, e.g. by attempting to reconnect, if they wish to tolerate xenstored restarts.

With these patches, the state saved on exit contains information about inter-domain connections and active watches, and the contents of the store. Some internal state is not currently preserved over a restart:
1. quota usage info
2. partially-read and already-queued packets from rings
3. recent transaction history

Items 1 and 2 are probably needed for this to be considered fully functional, so fixes for them should follow. But the bugfixes in this series already represent a worthwhile improvement.

Jonathan Davies (5):
oxenstored: initialise logging earlier
oxenstored: avoid leading slash in paths in saved store state
oxenstored: save remote evtchn port, not local port
oxenstored: improve event-channel binding logging
oxenstored: make --restart option best-effort

 tools/ocaml/xenstored/domain.ml    |  4 ++--
 tools/ocaml/xenstored/store.ml     |  8 +++++++-
 tools/ocaml/xenstored/xenstored.ml | 10 ++++++----
 3 files changed, 15 insertions(+), 7 deletions(-)

--
2.7.4

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel