From nobody Sat Nov 30 01:46:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1620756428; cv=none; d=zohomail.com; s=zohoarc; b=AW2X5VhhSt35THhxp/4pjxtAi65MxSODM5k9C8LMl5eYkmBUIGTdasDPsBGYAodAs+/vv3CbOEsqPNX9MofCspxLd+I+PZ86+4VV6fzCp3onLE6sMQgiuDzw94auiXNj7raQ2fShbLP344PdmBnSF3dwn3s3y1vBGeY+fqUTaRg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620756428; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=bNgxsbldBS8EnVRine+MOsZOfO8ZJnYq+virNFDLFTU=; b=BsAac9KpuxhSVpfaNQ7qGv5bsV/vJaNwI/SfLkjC7/f62jOV2T3tSY/gut2ygFvUksx2QGBAOay5bgt5guM1lYQplRqIRJKbCW5nWZgUXMVOMTOP6T51sectAjscG1sN76dS91IIybUiAoqbkzyw8HiYKJV08PSk51RYitBWbko= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 16207564286638.019195913568979; Tue, 11 May 2021 11:07:08 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.125898.236977 (Exim 4.92) (envelope-from ) id 1lgWmU-0000hz-Vc; Tue, 11 May 2021 18:06:54 +0000 Received: by outflank-mailman (output) from mailman id 125898.236977; Tue, 11 May 2021 18:06:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lgWmU-0000hs-Sm; Tue, 11 May 2021 18:06:54 +0000 Received: by outflank-mailman (input) for mailman id 125898; Tue, 11 May 2021 18:06:53 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lgWmT-0000hb-Qp for xen-devel@lists.xenproject.org; Tue, 11 May 2021 18:06:53 +0000 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 030b699d-ba57-4ff2-92aa-1b1c49c25836; Tue, 11 May 2021 18:06:52 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 030b699d-ba57-4ff2-92aa-1b1c49c25836 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1620756412; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LJybmG+tBz4IHj5Tv2R6AGzuVV3gHz/bSFDawWJReUw=; b=Hnnvl/WIu49Q1HX5O/aKBIEfWdKtoAt7mEYDZvtniN6G3BnePUKKK1PY 9rvhEQQdDQBfleGYU5VP4407exUB0fSLugsxUN3j+NYE40PQvbPLVUphE EDq4BiXLw2XEfNud2dQTY9jJXPg4KvR7ZXNOruBNG0o8u7C7GEgO0G7FO o=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: 2XBnpXDrfeAUsHExPzOU4DUtdbP3NkWpMxhDt2/N9KZXxZrAf8DE0E5VECDQoJdKOe+eVTcUNF Wnmairsgd8GscxkAymYmA3YauKCpr1MTQ2uil240NVafuLPpsq9xQngdpRpUsBhX7Ohp+OMTXA PXGdzw8acPYvfu9axqxRLUENFfoSAVc5Pz+jYARskbiOkPiC/jlNwiX6jUB2tomNkcjxCk8hOc xZEN8fdlRy8TbvcSYyGEdqIOjuIuflsOuaJR/gDe/FuEkYMYl1gDEGsi23CBbnmVQaX6d6nnvd m34= X-SBRS: 5.1 X-MesageID: 43675314 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:S4LKvq39hDQLwVEJvbUAtwqjBIokLtp133Aq2lEZdPRUGvb3qy nIpoVj6faUskd2ZJhOo7C90cW7LU80sKQFhLX5Xo3SOzUO2lHYT72KhLGKq1aLdhEWtNQtsZ uIG5IOcOEYZmIasS+V2maF+q4bsbu6zJw= X-IronPort-AV: E=Sophos;i="5.82,291,1613451600"; d="scan'208";a="43675314" From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= To: CC: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= , "Christian Lindig" , David Scott , "Ian Jackson" , Wei Liu Subject: [PATCH v2 05/17] tools/ocaml/xenstored: add binary dump format support Date: Tue, 11 May 2021 19:05:18 +0100 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) Do not dump -1, it'll trigger an assertion, use 0xFF.. instead. Signed-off-by: Edwin T=C3=B6r=C3=B6k --- tools/ocaml/xenstored/connection.ml | 63 +++++++++++++++++++++-------- tools/ocaml/xenstored/disk.ml | 3 +- 2 files changed, 49 insertions(+), 17 deletions(-) diff --git a/tools/ocaml/xenstored/connection.ml b/tools/ocaml/xenstored/co= nnection.ml index 65f99ea6f2..7a894a2eb1 100644 --- a/tools/ocaml/xenstored/connection.ml +++ b/tools/ocaml/xenstored/connection.ml @@ -17,6 +17,7 @@ exception End_of_file =20 open Stdext +module LR =3D Disk.LiveRecord =20 let xenstore_payload_max =3D 4096 (* xen/include/public/io/xs_wire.h *) =20 @@ -77,6 +78,10 @@ let number_of_transactions con =3D =20 let get_domain con =3D con.dom =20 +let get_id con =3D match con.dom with +| None -> 2*LR.domid_invalid + con.anonid +| Some dom -> 1 + Domain.get_id dom + let anon_id_next =3D ref 1 =20 let get_domstr con =3D @@ -278,6 +283,9 @@ let end_transaction con tid commit =3D let get_transaction con tid =3D Hashtbl.find con.transactions tid =20 +let iter_transactions con f =3D + Hashtbl.iter f con.transactions + let do_input con =3D Xenbus.Xb.input con.xb let has_input con =3D Xenbus.Xb.has_in_packet con.xb let has_partial_input con =3D match con.xb.Xenbus.Xb.partial_in with @@ -336,22 +344,45 @@ let incr_ops con =3D con.stat_nb_ops <- con.stat_nb_o= ps + 1 let stats con =3D Hashtbl.length con.watches, con.stat_nb_ops =20 -let dump con chan =3D - let id =3D match con.dom with - | Some dom -> - let domid =3D Domain.get_id dom in - (* dump domain *) - Domain.dump dom chan; - domid - | None -> - let fd =3D con |> get_fd |> Utils.FD.to_int in - Printf.fprintf chan "socket,%d\n" fd; - -fd - in - (* dump watches *) - List.iter (fun (path, token) -> - Printf.fprintf chan "watch,%d,%s,%s\n" id (Utils.hexify path) (Utils.hex= ify token) - ) (list_watches con) +let serialize_pkt_in buf xb =3D + let open Xenbus.Xb in + Queue.iter (fun p -> Buffer.add_string buf (Packet.to_string p)) xb.pkt_i= n; + match xb.partial_in with + | NoHdr (to_read, hdrb) -> + (* see Xb.input *) + let used =3D Xenbus.Partial.header_size () - to_read in + Buffer.add_subbytes buf hdrb 0 used + | HaveHdr p -> + p |> Packet.of_partialpkt |> Packet.to_string |> Buffer.add_string buf + +let serialize_pkt_out buf xb =3D + let open Xenbus.Xb in + Buffer.add_string buf xb.partial_out; + Queue.iter (fun p -> Buffer.add_string buf (Packet.to_string p)) xb.pkt_o= ut + +let dump con store chan =3D + let conid =3D get_id con in + let conn =3D match con.dom with + | None -> LR.Socket (get_fd con) + | Some dom -> LR.Domain { + id =3D Domain.get_id dom; + target =3D LR.domid_invalid; (* TODO: we do not store this info *) + remote_port =3D Domain.get_remote_port dom + } in + let pkt_in =3D Buffer.create 4096 in + let pkt_out =3D Buffer.create 4096 in + serialize_pkt_in pkt_in con.xb; + serialize_pkt_out pkt_out con.xb; + LR.write_connection_data chan ~conid ~conn pkt_in con.xb.partial_out pkt= _out; + + con |> list_watches + |> List.rev (* preserve order in dump/reload *) + |> List.iter (fun (wpath, token) -> + LR.write_watch_data chan ~conid ~wpath ~token + ); + let conpath =3D get_path con in + iter_transactions con (fun _ txn -> + Transaction.dump store conpath ~conid txn chan) =20 let debug con =3D let domid =3D get_domstr con in diff --git a/tools/ocaml/xenstored/disk.ml b/tools/ocaml/xenstored/disk.ml index 595fdab54a..59794324e1 100644 --- a/tools/ocaml/xenstored/disk.ml +++ b/tools/ocaml/xenstored/disk.ml @@ -292,7 +292,8 @@ module LiveRecord =3D struct let write_global_data t ~rw_sock =3D write_record t Type.global_data 8 @@ fun b -> O.w32 b (FD.to_int rw_sock); - O.w32 b (-1) + (* TODO: this needs a unit test/live update test too! *) + O.w32 b 0xFFFF_FFFF =20 let read_global_data t ~len f =3D read_expect t "global_data" 8 len; --=20 2.25.1