Mailing List Archive

[PATCH 3 of 4] oxenstored: handle unknown operations by returning an error to the client
# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1323448556 0
# Node ID 74f94e15bfe1dad412d0342aeabdbd895657f54f
# Parent 18c0807a0504791bcb6e083866def9c4862a119a
oxenstored: handle unknown operations by returning an error to the client

Previous an unknown operation would be decoded as a Not_found exception which
would bubble all the way up to the try ... with surrounding the call to
main_loop where it would be logged and ignored.

This would leave the guest hanging waiting for a response to the invalid
request.

Instead introduce a specific "Invalid" operation. Higher level functionality,
such as Process.process_packet, already handles operations which are not
understood with an error reply due to the final wildcard entry in
Process.function_of_type but explicitly handle Invalid this way to make it
clear what is going on.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r 18c0807a0504 -r 74f94e15bfe1 tools/ocaml/libs/xb/op.ml
--- a/tools/ocaml/libs/xb/op.ml Fri Dec 09 16:19:36 2011 +0000
+++ b/tools/ocaml/libs/xb/op.ml Fri Dec 09 16:35:56 2011 +0000
@@ -19,8 +19,7 @@ type operation = Debug | Directory | Rea
Transaction_end | Introduce | Release |
Getdomainpath | Write | Mkdir | Rm |
Setperms | Watchevent | Error | Isintroduced |
- Resume | Set_target
- | Restrict
+ Resume | Set_target | Restrict | Invalid

let operation_c_mapping =
[| Debug; Directory; Read; Getperms;
@@ -41,7 +40,7 @@ let array_search el a =
let of_cval i =
if i >= 0 && i < size
then operation_c_mapping.(i)
- else raise Not_found
+ else Invalid

let to_cval op =
array_search op operation_c_mapping
@@ -69,3 +68,4 @@ let to_string ty =
| Resume -> "RESUME"
| Set_target -> "SET_TARGET"
| Restrict -> "RESTRICT"
+ | Invalid -> "INVALID"
diff -r 18c0807a0504 -r 74f94e15bfe1 tools/ocaml/libs/xb/xb.mli
--- a/tools/ocaml/libs/xb/xb.mli Fri Dec 09 16:19:36 2011 +0000
+++ b/tools/ocaml/libs/xb/xb.mli Fri Dec 09 16:35:56 2011 +0000
@@ -23,6 +23,7 @@ module Op :
| Resume
| Set_target
| Restrict
+ | Invalid (* Not a valid wire operation *)
val operation_c_mapping : operation array
val size : int
val array_search : 'a -> 'a array -> int
diff -r 18c0807a0504 -r 74f94e15bfe1 tools/ocaml/xenstored/process.ml
--- a/tools/ocaml/xenstored/process.ml Fri Dec 09 16:19:36 2011 +0000
+++ b/tools/ocaml/xenstored/process.ml Fri Dec 09 16:35:56 2011 +0000
@@ -324,7 +324,8 @@ let function_of_type ty =
| Xenbus.Xb.Op.Resume -> reply_ack do_resume
| Xenbus.Xb.Op.Set_target -> reply_ack do_set_target
| Xenbus.Xb.Op.Restrict -> reply_ack do_restrict
- | _ -> reply_ack do_error
+ | Xenbus.Xb.Op.Invalid -> reply_ack do_error
+ | _ -> reply_ack do_error

let input_handle_error ~cons ~doms ~fct ~ty ~con ~t ~rid ~data =
let reply_error e =
diff -r 18c0807a0504 -r 74f94e15bfe1 tools/ocaml/xenstored/xenstored.ml
--- a/tools/ocaml/xenstored/xenstored.ml Fri Dec 09 16:19:36 2011 +0000
+++ b/tools/ocaml/xenstored/xenstored.ml Fri Dec 09 16:35:56 2011 +0000
@@ -43,9 +43,7 @@ let process_connection_fds store cons do
debug "closing socket connection"
in
let process_fdset_with fds fct =
- List.iter (fun fd ->
- try try_fct fct (Connections.find cons fd)
- with Not_found -> ()) fds
+ List.iter (fun fd -> try_fct fct (Connections.find cons fd)) fds
in
process_fdset_with rset Process.do_input;
process_fdset_with wset Process.do_output

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
Re: [PATCH 3 of 4] oxenstored: handle unknown operations by returning an error to the client [ In reply to ]
Ian Campbell writes ("[Xen-devel] [PATCH 3 of 4] oxenstored: handle unknown operations by returning an error to the client"):
> oxenstored: handle unknown operations by returning an error to the client

This introduces a new warning:

File "logging.ml", line 157, characters 14-1067:
Warning P: this pattern-matching is not exhaustive.
Here is an example of a value that is not matched:
Invalid

I have applied 1/4 and 2/4.

Ian.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
Re: [PATCH 3 of 4] oxenstored: handle unknown operations by returning an error to the client [ In reply to ]
On Tue, 2011-12-13 at 15:52 +0000, Ian Jackson wrote:
> Ian Campbell writes ("[Xen-devel] [PATCH 3 of 4] oxenstored: handle unknown operations by returning an error to the client"):
> > oxenstored: handle unknown operations by returning an error to the client
>
> This introduces a new warning:
>
> File "logging.ml", line 157, characters 14-1067:
> Warning P: this pattern-matching is not exhaustive.
> Here is an example of a value that is not matched:
> Invalid

Sorry, will fix and resend.

> I have applied 1/4 and 2/4.

Did you see "5/4" and "6/4"? In any case I shall include them in my
resend.

Ian.



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel