From patchwork Fri Apr 7 13:27:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Davies X-Patchwork-Id: 9669515 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A13F960364 for ; Fri, 7 Apr 2017 13:30:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9328328375 for ; Fri, 7 Apr 2017 13:30:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8807A28604; Fri, 7 Apr 2017 13:30:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3A4FF28375 for ; Fri, 7 Apr 2017 13:30:13 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cwTvW-0004Iu-AE; Fri, 07 Apr 2017 13:27:46 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cwTvV-0004Ia-Dw for xen-devel@lists.xenproject.org; Fri, 07 Apr 2017 13:27:45 +0000 Received: from [85.158.137.68] by server-7.bemta-3.messagelabs.com id A4/C0-23854-0D397E85; Fri, 07 Apr 2017 13:27:44 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmplkeJIrShJLcpLzFFi42JxWrrBXvfC5Oc RBl8buS2+b5nM5MDocfjDFZYAxijWzLyk/IoE1oypV0ILzglWfPz7kaWB8TlfFyMnh4SAv8Tf K3PYQWw2ASOJG++nsYDYIgLeEpeO72LrYuTiYBY4yShx9tF0JpCEsECQxNVdp5lBbBYBFYlF7 z+BxXkFvCQezznIBjFUTuLmuU6wGk6gQROnt4INFQKqefNlAhOErS7R8GgSVK+gxMmZT8BqmA UkJA6+eME8gZF3FpLULCSpBYxMqxg1ilOLylKLdI3M9ZKKMtMzSnITM3N0DQ2M9XJTi4sT01N zEpOK9ZLzczcxAoOnnoGBcQdjy16/Q4ySHExKorwKPk8ihPiS8lMqMxKLM+KLSnNSiw8xynBw KEnwTpz0PEJIsCg1PbUiLTMHGMYwaQkOHiUR3q8gad7igsTc4sx0iNQpRkUpcd6tIAkBkERGa R5cGyx2LjHKSgnzMjIwMAjxFKQW5WaWoMq/YhTnYFQS5t0NMoUnM68EbvoroMVMQIt9bj0FWV ySiJCSamBcdcig47DXjr+Gmz5/etQcIpFkce5801qNguybkjtrOJRYjXrso6rk1Ta9rdwhtVg t0XpBXtiO3k2PzSTO9Wj1FTkyblSdUViw2WL3ptaUxmbpDZM5tWOEG7Lk5Du9zGbm3PjkrlA0 32fCDQnmrbP7TA4vjbx1QvNm5HzPOT5f7mS5P2zY0qzEUpyRaKjFXFScCAAnkgL+mAIAAA== X-Env-Sender: prvs=263a3545e=Jonathan.Davies@citrix.com X-Msg-Ref: server-12.tower-31.messagelabs.com!1491571661!77984345!2 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 40098 invoked from network); 7 Apr 2017 13:27:43 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-12.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 7 Apr 2017 13:27:43 -0000 X-IronPort-AV: E=Sophos;i="5.37,165,1488844800"; d="scan'208";a="426682587" From: Jonathan Davies To: "xen-devel @ lists . xenproject . org" Date: Fri, 7 Apr 2017 14:27:19 +0100 Message-ID: <1491571642-24403-3-git-send-email-jonathan.davies@citrix.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1491571642-24403-1-git-send-email-jonathan.davies@citrix.com> References: <1491571642-24403-1-git-send-email-jonathan.davies@citrix.com> MIME-Version: 1.0 Cc: Wei Liu , Jonathan Davies , Ian Jackson , Christian Lindig , David Scott Subject: [Xen-devel] [PATCH 2/5] oxenstored: avoid leading slash in paths in saved store state X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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". Signed-off-by: Jonathan Davies --- tools/ocaml/xenstored/store.ml | 8 +++++++- tools/ocaml/xenstored/xenstored.ml | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/ocaml/xenstored/store.ml b/tools/ocaml/xenstored/store.ml index 9f619b8..13cf3b5 100644 --- a/tools/ocaml/xenstored/store.ml +++ b/tools/ocaml/xenstored/store.ml @@ -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 diff --git a/tools/ocaml/xenstored/xenstored.ml b/tools/ocaml/xenstored/xenstored.ml index 09da257..77fd9e3 100644 --- a/tools/ocaml/xenstored/xenstored.ml +++ b/tools/ocaml/xenstored/xenstored.ml @@ -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) );