From nobody Sun Nov 2 12:50:16 2025 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=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1739546716; cv=none; d=zohomail.com; s=zohoarc; b=h9xC5uAYBt346k3dl08nmSYG5QVvIrvC5o+VwzvRC+vwJqVgPdRenk6n845fl3tjsKl2BPwRSZJix8MqK0AVeY+7Ij0aKjDUhW9h8cjSGXUsNJJaBHRavdLi/EHykHKpQ7m5py/xIaNEjP8nPimiC6SBSJMmqzcfnFbrxh9jv6k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1739546716; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=woWxc9kp8yBtz5vZ91LiRNGKXCo0bpkeXP1Q8zpuOSI=; b=ZDlJsZS6va5w+gpDLhgUkfgHeQq2YgR+GkkiXcAU8y5/9byD8aPkGMXnr8tQYAjmVbOpIZ/pxxP7KisbwgynEsUGJ+J3jqLjwgLTgvBzysAHtsZ17xXV87I9Kc8PwATpGAGN7L0zrSMHjIZX8Pqi7ac307OdFgEhHq1ka9HE9oM= 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) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1739546716482595.7842972392928; Fri, 14 Feb 2025 07:25:16 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.888903.1298179 (Exim 4.92) (envelope-from ) id 1tixYQ-0002Mz-Tz; Fri, 14 Feb 2025 15:24:34 +0000 Received: by outflank-mailman (output) from mailman id 888903.1298179; Fri, 14 Feb 2025 15:24:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tixYQ-0002Ms-Qj; Fri, 14 Feb 2025 15:24:34 +0000 Received: by outflank-mailman (input) for mailman id 888903; Fri, 14 Feb 2025 15:24:33 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tixYP-00028r-Ej for xen-devel@lists.xenproject.org; Fri, 14 Feb 2025 15:24:33 +0000 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [2a00:1450:4864:20::532]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ca6ee228-eae7-11ef-9aa4-95dc52dad729; Fri, 14 Feb 2025 16:24:32 +0100 (CET) Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-5ded69e6134so2734736a12.0 for ; Fri, 14 Feb 2025 07:24:32 -0800 (PST) Received: from CSGPROD238885.citrite.net (cpc92320-cmbg19-2-0-cust1786.5-4.cable.virginm.net. [82.13.70.251]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5dece287c7fsm3040608a12.70.2025.02.14.07.24.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2025 07:24:31 -0800 (PST) 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: ca6ee228-eae7-11ef-9aa4-95dc52dad729 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1739546672; x=1740151472; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=woWxc9kp8yBtz5vZ91LiRNGKXCo0bpkeXP1Q8zpuOSI=; b=kUqPaTdLmF3vL0+Zmtj5iGX8hSWZqm0UKF2uZPUmPdct/aFU9tj2HrBjD+IMNRURh3 UJC/eJBpeCq1I5dGacGPR9cKwz1gKhpB3QPvscTL7vhCQsAZJXKr4Uqy9KreF9ULb+0T r1sxFFvH4av1uEs0eh7mDSPzd52Fsv7SdSHvQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739546672; x=1740151472; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=woWxc9kp8yBtz5vZ91LiRNGKXCo0bpkeXP1Q8zpuOSI=; b=ZAkS/hUOOTdE62oBWvUMOyNUXrbX8zcLX08KF5l5RaGOhVNnVQcnQkbo/3XSp+35I7 2unyFlUYdYBtJ96LRvsq43T2yPgwaHk1suDzGd6bgEwglYq7ffWrQ2lzVCiRRrFFmLS2 vMsShLU14WbdyOP1LbgkMF7CvfJwidxBCn15D1M6I3x5IErSk9mXuRnIcGokHFx9Rxqd IrmO1/Mk3gLMMYEPHDRgi5M0lEHuMF2gnElxMdWnudglgmG8MPEpZ2gORNP1EF2vzHLM GoLJFDS1+5h948cYJlTZD40y08rzFMlXtUHPfM/B0W5JGN5kur40O31mtfOko7qNVbHy QAQw== X-Gm-Message-State: AOJu0YyFRCJPbsVZepzeIxXhZ+VZ0yj/rjn2ukWNZ61r7zzfgJli0nnY 2u626iMkFDau1AGDRLDq9pm4NL61uBvqs4MQR8nqdoW5C76ZTY3X0x46gQOEDBPS3Lg7Mf9BaDj I X-Gm-Gg: ASbGncsk61zMmmblk8z2cpQA4A02pyMA1o2d/JuKbBH3f7E5CVUPqCIa/Pl3F27jbzp bhUjw01GtOEROfxGGd0Xsih7ZdU2n9Vp9lU0e8GfqK/CjdUj4JzjQT7myaVd8uy+Yg/L6VuTDYA dNwKAq+E18rTtmqKpEso+Lc+tV6RuFz2p2yTagXXAeSqmmwAnLHVc4qGH8EdbElAC+EANY5tAU4 XnJhCfnb9jEO0kzuJ0PHd/Q3sKyHZlLjzNUxvorAGPVfgpf7NTJj4ZO8S1VP4pfIeR9lMpbWDDL KSisvpcoNlzJWDy9Zl+H+CvNG39PDHjstd8ZhGtIeXD3NkldFxsZQRa21YUIcDpx4LTESwboui9 w/IOhSTm1rdSVa6yv8eaiYw== X-Google-Smtp-Source: AGHT+IGi4M69OpVHSHBJJqod2T8e91L37p01TZpSUPrrQg584ptamACceaA4YZGsJkiVwUklgj7T6w== X-Received: by 2002:a05:6402:2791:b0:5dc:91c6:8096 with SMTP id 4fb4d7f45d1cf-5deade07fbamr12504451a12.30.1739546671866; Fri, 14 Feb 2025 07:24:31 -0800 (PST) From: Andrii Sultanov To: xen-devel@lists.xenproject.org Cc: Andrii Sultanov , Christian Lindig , David Scott , Anthony PERARD , Christian Lindig Subject: [PATCH v2 1/1] tools/ocaml: Fix oxenstored build warning Date: Fri, 14 Feb 2025 15:24:27 +0000 Message-Id: <0545259ba8f7c54b6fd6c82b185bdee475694747.1739546412.git.andrii.sultanov@cloud.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1739546718811019000 Content-Type: text/plain; charset="utf-8" OCaml, in preparation for a renaming of the error string associated with conversion failure in 'int_of_string' functions, started to issue this warning: ``` File "process.ml", line 440, characters 13-28: 440 | | (Failure "int_of_string") -> reply_error "EINVAL" ^^^^^^^^^^^^^^^ Warning 52 [fragile-literal-pattern]: Code should not depend on the actual = values of this constructor's arguments. They are only for information and may change in future versions. (See manual section 11.5) ``` Deal with this at the source, and instead create our own stable ConversionFailure exception that's raised on the None case in 'int_of_string_opt'. 'c_int_of_string' is safe and does not raise such exceptions. Signed-off-by: Andrii Sultanov Acked-by: Christian Lindig --- Changes since v1: * Revert logging added to error handling in process.ml, return just "EINVAL" --- tools/ocaml/xenstored/Makefile | 1 + tools/ocaml/xenstored/perms.ml | 2 +- tools/ocaml/xenstored/poll.ml | 2 +- tools/ocaml/xenstored/process.ml | 18 +++++++++--------- tools/ocaml/xenstored/utils.ml | 10 ++++++++-- tools/ocaml/xenstored/xenstored.ml | 16 ++++++++-------- 6 files changed, 28 insertions(+), 21 deletions(-) diff --git a/tools/ocaml/xenstored/Makefile b/tools/ocaml/xenstored/Makefile index 5e8210a906..c333394a34 100644 --- a/tools/ocaml/xenstored/Makefile +++ b/tools/ocaml/xenstored/Makefile @@ -54,6 +54,7 @@ OBJS =3D paths \ history \ parse_arg \ process \ + poll \ xenstored =20 INTF =3D symbol.cmi trie.cmi syslog.cmi systemd.cmi poll.cmi diff --git a/tools/ocaml/xenstored/perms.ml b/tools/ocaml/xenstored/perms.ml index 14f8e334fe..2c4ee9e617 100644 --- a/tools/ocaml/xenstored/perms.ml +++ b/tools/ocaml/xenstored/perms.ml @@ -70,7 +70,7 @@ struct =20 let perm_of_string s =3D let ty =3D permty_of_char s.[0] - and id =3D int_of_string (String.sub s 1 (String.length s - 1)) in + and id =3D Utils.int_of_string_exn (String.sub s 1 (String.length s - = 1)) in (id, ty) =20 let of_strings ls =3D diff --git a/tools/ocaml/xenstored/poll.ml b/tools/ocaml/xenstored/poll.ml index fefaa6e74c..f8571e4590 100644 --- a/tools/ocaml/xenstored/poll.ml +++ b/tools/ocaml/xenstored/poll.ml @@ -30,7 +30,7 @@ external set_fd_limit: int -> unit =3D "stub_set_fd_limit" let get_sys_fs_nr_open () =3D try let ch =3D open_in "/proc/sys/fs/nr_open" in - let v =3D int_of_string (input_line ch) in + let v =3D Utils.int_of_string_exn (input_line ch) in close_in_noerr ch; v with _ -> 1024 * 1024 =20 diff --git a/tools/ocaml/xenstored/process.ml b/tools/ocaml/xenstored/proce= ss.ml index 432d66321c..0c9c460a99 100644 --- a/tools/ocaml/xenstored/process.ml +++ b/tools/ocaml/xenstored/process.ml @@ -229,7 +229,7 @@ let do_debug con t _domains cons data =3D Logging.xb_op ~tid:0 ~ty:Xenbus.Xb.Op.Debug ~con:"=3D=3D=3D=3D=3D=3D= =3D>" msg; None | "quota" :: domid :: _ -> - let domid =3D int_of_string domid in + let domid =3D Utils.int_of_string_exn domid in let quota =3D (Store.get_quota t.Transaction.store) in Some (Quota.to_string quota domid ^ "\000") | "watches" :: _ -> @@ -242,7 +242,7 @@ let do_debug con t _domains cons data =3D History.trim (); Some "trimmed" | "txn" :: domid :: _ -> - let domid =3D int_of_string domid in + let domid =3D Utils.int_of_string_exn domid in let con =3D Connections.find_domain cons domid in let b =3D Buffer.create 128 in let () =3D con.transactions |> Hashtbl.iter @@ fun id tx -> @@ -253,7 +253,7 @@ let do_debug con t _domains cons data =3D in Some (Buffer.contents b) | "xenbus" :: domid :: _ -> - let domid =3D int_of_string domid in + let domid =3D Utils.int_of_string_exn domid in let con =3D Connections.find_domain cons domid in let s =3D Printf.sprintf "xenbus: %s; overflow queue length: %d, can= _input: %b, has_more_input: %b, has_old_output: %b, has_new_output: %b, has= _more_work: %b. pending: %s" (Xenbus.Xb.debug con.xb) @@ -267,7 +267,7 @@ let do_debug con t _domains cons data =3D in Some s | "mfn" :: domid :: _ -> - let domid =3D int_of_string domid in + let domid =3D Utils.int_of_string_exn domid in let con =3D Connections.find_domain cons domid in may (fun dom -> Printf.sprintf "%nd\000" (Domain.get_mfn dom)) (Conn= ection.get_domain con) | _ -> None @@ -340,7 +340,7 @@ let do_isintroduced con _t domains _cons data =3D then raise Define.Permission_denied; let domid =3D match (split None '\000' data) with - | domid :: _ -> int_of_string domid + | domid :: _ -> Utils.int_of_string_exn domid | _ -> raise Invalid_Cmd_Args in if domid =3D Define.domid_self || Domains.exist domains domid then "T\00= 0" else "F\000" @@ -437,7 +437,7 @@ let input_handle_error ~cons ~doms ~fct ~con ~t ~req = =3D | Quota.Limit_reached -> reply_error "EQUOTA" | Quota.Data_too_big -> reply_error "E2BIG" | Quota.Transaction_opened -> reply_error "EQUOTA" - | (Failure "int_of_string") -> reply_error "EINVAL" + | Utils.ConversionFailed s -> reply_error "EINVAL" | Define.Unknown_operation -> reply_error "ENOSYS" =20 let write_access_log ~ty ~tid ~con ~data =3D @@ -578,7 +578,7 @@ let do_introduce con t domains cons data =3D let (domid, mfn, remote_port) =3D match (split None '\000' data) with | domid :: mfn :: remote_port :: _ -> - int_of_string domid, Nativeint.of_string mfn, int_of_string remote_p= ort + Utils.int_of_string_exn domid, Nativeint.of_string mfn, Utils.int_of= _string_exn remote_port | _ -> raise Invalid_Cmd_Args; in let dom =3D @@ -604,7 +604,7 @@ let do_release con t domains cons data =3D then raise Define.Permission_denied; let domid =3D match (split None '\000' data) with - | [domid;""] -> int_of_string domid + | [domid;""] -> Utils.int_of_string_exn domid | _ -> raise Invalid_Cmd_Args in let fire_spec_watches =3D Domains.exist domains domid in @@ -620,7 +620,7 @@ let do_resume con _t domains _cons data =3D then raise Define.Permission_denied; let domid =3D match (split None '\000' data) with - | domid :: _ -> int_of_string domid + | domid :: _ -> Utils.int_of_string_exn domid | _ -> raise Invalid_Cmd_Args in if Domains.exist domains domid diff --git a/tools/ocaml/xenstored/utils.ml b/tools/ocaml/xenstored/utils.ml index 48d84ef7d3..7a556bce75 100644 --- a/tools/ocaml/xenstored/utils.ml +++ b/tools/ocaml/xenstored/utils.ml @@ -53,8 +53,14 @@ let hexify s =3D ) s; Bytes.unsafe_to_string hs =20 +exception ConversionFailed of string +let int_of_string_exn s =3D + match int_of_string_opt s with + | Some x -> x + | None -> raise (ConversionFailed s) + let unhexify hs =3D - let char_of_hexseq seq0 seq1 =3D Char.chr (int_of_string (sprintf "0x%c%= c" seq0 seq1)) in + let char_of_hexseq seq0 seq1 =3D Char.chr (int_of_string_exn (sprintf "0= x%c%c" seq0 seq1)) in let b =3D Bytes.create (String.length hs / 2) in for i =3D 0 to Bytes.length b - 1 do @@ -86,7 +92,7 @@ let read_file_single_integer filename =3D let buf =3D Bytes.make 20 '\000' in let sz =3D Unix.read fd buf 0 20 in Unix.close fd; - int_of_string (Bytes.sub_string buf 0 sz) + int_of_string_exn (Bytes.sub_string buf 0 sz) =20 (* @path may be guest data and needs its length validating. @connection_p= ath * is generated locally in xenstored and always of the form "/local/domain= /$N/" *) diff --git a/tools/ocaml/xenstored/xenstored.ml b/tools/ocaml/xenstored/xen= stored.ml index 1aaa3e995e..84dee622ea 100644 --- a/tools/ocaml/xenstored/xenstored.ml +++ b/tools/ocaml/xenstored/xenstored.ml @@ -167,20 +167,20 @@ module DB =3D struct e.g. a RO socket from a previous version: ignore it= *) global_f ~rw | "evtchn-dev" :: fd :: domexc_port :: [] -> - evtchn_f ~fd:(int_of_string fd) - ~domexc_port:(int_of_string domexc_port) + evtchn_f ~fd:(Utils.int_of_string_exn fd) + ~domexc_port:(Utils.int_of_string_exn domexc_port) | "socket" :: fd :: [] -> - socket_f ~fd:(int_of_string fd) + socket_f ~fd:(Utils.int_of_string_exn fd) | "dom" :: domid :: mfn :: remote_port :: rest -> let local_port =3D match rest with | [] -> None (* backward compat: old version didn't have it = *) - | local_port :: _ -> Some (int_of_string local_port) in + | local_port :: _ -> Some (Utils.int_of_string_exn local_por= t) in domain_f ?local_port - ~remote_port:(int_of_string remote_port) - (int_of_string domid) + ~remote_port:(Utils.int_of_string_exn remote_port) + (Utils.int_of_string_exn domid) (Nativeint.of_string mfn) | "watch" :: domid :: path :: token :: [] -> - watch_f (int_of_string domid) + watch_f (Utils.int_of_string_exn domid) (unhexify path) (unhexify token) | "store" :: path :: perms :: value :: [] -> store_f (getpath path) @@ -214,7 +214,7 @@ module DB =3D struct in let global_f ~rw =3D let get_listen_sock sockfd =3D - let fd =3D sockfd |> int_of_string |> Utils.FD.of_int in + let fd =3D sockfd |> Utils.int_of_string_exn |> Utils.FD.of_int in Unix.listen fd 1; Some fd in --=20 2.39.5