From nobody Sun Feb 8 14:51:50 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569337486; cv=none; d=zoho.com; s=zohoarc; b=E29bsniXDPfrc3Hgvok1KKH6wiSOTdm6CWsvg7YovNR8QjG4P6CiQzp0+OQQ6kSKELhdKBzgoFA5Jt9jqdQ1BhcD2ZbG5fWrNEn12qTQdnlR64krST9PCRXT2rySU1v7a0xId64vCS/xSVEo2JsaJPLxoQOi9ALOk7Y+CdJ6qLY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569337486; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=E/uOIIsiywEdLhmLKgTSuvTQuxTk+M1/k88w5vsinnY=; b=DaqvNQoJo9K07akvzOHEpryxXV5+HT9dBKk3fskX4tWKQalbI+QOKNpFdrIEc88Rzpqcqw53M7NTQjSyrQbfQmKGpgnndaespNv1WArk5YVFS/IYMJk09amd699ydUc3shom5+IkbtGrY0ehBSJHaYnWFd4e18pIN/whUOGfjq8= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1569337486315975.7514913101105; Tue, 24 Sep 2019 08:04:46 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BF18320EE; Tue, 24 Sep 2019 15:04:44 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9AF53608C2; Tue, 24 Sep 2019 15:04:44 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 5CF69180B761; Tue, 24 Sep 2019 15:04:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8OF4WOh027948 for ; Tue, 24 Sep 2019 11:04:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id 383435DAAC; Tue, 24 Sep 2019 15:04:32 +0000 (UTC) Received: from catbus.gsslab.fab.redhat.com (dhcp-32.gsslab.fab.redhat.com [10.33.9.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D54E5D9D5; Tue, 24 Sep 2019 15:04:29 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 24 Sep 2019 15:58:53 +0100 Message-Id: <20190924145903.17123-13-berrange@redhat.com> In-Reply-To: <20190924145903.17123-1-berrange@redhat.com> References: <20190924145903.17123-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 12/22] src: rewrite systemtap function generator in Python X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.71]); Tue, 24 Sep 2019 15:04:45 +0000 (UTC) As part of an goal to eliminate Perl from libvirt build tools, rewrite the gensystemtap.pl tool in Python. This was a straight conversion, manually going line-by-line to change the syntax from Perl to Python. Thus the overall structure of the file and approach is the same. Signed-off-by: Daniel P. Berrang=C3=A9 --- cfg.mk | 4 +- src/Makefile.am | 5 +- src/rpc/Makefile.inc.am | 2 +- src/rpc/gensystemtap.pl | 193 ---------------------------------------- src/rpc/gensystemtap.py | 184 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 189 insertions(+), 199 deletions(-) delete mode 100755 src/rpc/gensystemtap.pl create mode 100755 src/rpc/gensystemtap.py diff --git a/cfg.mk b/cfg.mk index f0aed0365a..18bab6e9a4 100644 --- a/cfg.mk +++ b/cfg.mk @@ -407,6 +407,7 @@ sc_prohibit_risky_id_promotion: # since gnulib has more guarantees for snprintf portability sc_prohibit_sprintf: @prohibit=3D'\<[s]printf\>' \ + in_vc_files=3D'\.[ch]$$' \ halt=3D'use snprintf, not sprintf' \ $(_sc_search_regexp) =20 @@ -1272,9 +1273,6 @@ exclude_file_name_regexp--sc_prohibit_readlink =3D \ =20 exclude_file_name_regexp--sc_prohibit_setuid =3D ^src/util/virutil\.c|tool= s/virt-login-shell\.c$$ =20 -exclude_file_name_regexp--sc_prohibit_sprintf =3D \ - ^(cfg\.mk|docs/hacking\.html\.in|.*\.stp|.*\.pl)$$ - exclude_file_name_regexp--sc_prohibit_strncpy =3D ^src/util/virstring\.c$$ =20 exclude_file_name_regexp--sc_prohibit_strtol =3D ^examples/.*$$ diff --git a/src/Makefile.am b/src/Makefile.am index 5a1df7a93c..5226871a73 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -635,8 +635,9 @@ RPC_PROBE_FILES +=3D $(srcdir)/rpc/virnetprotocol.x \ $(srcdir)/remote/qemu_protocol.x \ $(srcdir)/admin/admin_protocol.x =20 -libvirt_functions.stp: $(RPC_PROBE_FILES) $(srcdir)/rpc/gensystemtap.pl - $(AM_V_GEN)$(PERL) -w $(srcdir)/rpc/gensystemtap.pl $(RPC_PROBE_FILES) > = $@ +libvirt_functions.stp: $(RPC_PROBE_FILES) $(srcdir)/rpc/gensystemtap.py + $(AM_V_GEN)$(RUNUTF8) $(PYTHON) $(srcdir)/rpc/gensystemtap.py \ + $(RPC_PROBE_FILES) > $@ =20 %_probes.stp: %_probes.d $(srcdir)/dtrace2systemtap.py \ $(top_builddir)/config.status diff --git a/src/rpc/Makefile.inc.am b/src/rpc/Makefile.inc.am index b8ca53c69a..b43ee4ab7a 100644 --- a/src/rpc/Makefile.inc.am +++ b/src/rpc/Makefile.inc.am @@ -3,7 +3,7 @@ EXTRA_DIST +=3D \ rpc/gendispatch.pl \ rpc/genprotocol.pl \ - rpc/gensystemtap.pl \ + rpc/gensystemtap.py \ rpc/virnetprotocol.x \ rpc/virkeepaliveprotocol.x \ $(NULL) diff --git a/src/rpc/gensystemtap.pl b/src/rpc/gensystemtap.pl deleted file mode 100755 index 6693d4d6f5..0000000000 --- a/src/rpc/gensystemtap.pl +++ /dev/null @@ -1,193 +0,0 @@ -#!/usr/bin/env perl -# -# Copyright (C) 2011-2012 Red Hat, Inc. -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library. If not, see -# . -# -# Generate a set of systemtap functions for translating various -# RPC enum values into strings -# -# perl gensystemtap.pl */*.x > libvirt_functions.stp -# - -use strict; - -my %funcs; - -my %type; -my %status; -my %auth; - -my $instatus =3D 0; -my $intype =3D 0; -my $inauth =3D 0; -while (<>) { - if (/enum\s+virNetMessageType/) { - $intype =3D 1; - } elsif (/enum\s+virNetMessageStatus/) { - $instatus =3D 1; - } elsif (/enum remote_auth_type/) { - $inauth =3D 1; - } elsif (/}/) { - $instatus =3D $intype =3D $inauth =3D 0; - } elsif ($instatus) { - if (/^\s+VIR_NET_(\w+)\s*=3D\s*(\d+),?$/) { - $status{$2} =3D lc $1; - } - } elsif ($intype) { - if (/^\s+VIR_NET_(\w+)\s*=3D\s*(\d+),?$/) { - $type{$2} =3D lc $1; - } - } elsif ($inauth) { - if (/^\s+REMOTE_AUTH_(\w+)\s*=3D\s*(\d+),?$/) { - $auth{$2} =3D lc $1; - } - } else { - if (/(?:VIR_)?(\w+?)(?:_PROTOCOL)?_PROGRAM\s*=3D\s*0x([a-fA-F0-9]+= )\s*;/) { - $funcs{lc $1} =3D { id =3D> hex($2), version =3D> undef, progs= =3D> [] }; - } elsif (/(?:VIR_)?(\w+?)(?:_PROTOCOL)?_(?:PROGRAM|PROTOCOL)_VERSI= ON\s*=3D\s*(\d+)\s*;/) { - $funcs{lc $1}->{version} =3D $2; - } elsif (/(?:VIR_)?(\w+?)(?:_PROTOCOL)?_PROC_(.*?)\s+=3D\s+(\d+)/)= { - $funcs{lc $1}->{progs}->[$3] =3D lc $2; - } - } -} - -print <{id}, ") {\n"; - print " programstr =3D \"", $prog, "\"\n"; -} -print <{id}, " && version = =3D=3D ", $funcs{$prog}->{version}, ") {\n"; - - my $pfirst =3D 1; - for (my $id =3D 1 ; $id <=3D $#{$funcs{$prog}->{progs}} ; $id++) { - my $cond =3D $pfirst ? "if" : "} else if"; - $pfirst =3D 0; - print " $cond (proc =3D=3D $id) {\n"; - print " procstr =3D \"", $funcs{$prog}->{progs}->[$id], "= \";\n"; - } - print " } else {\n"; - print " procstr =3D \"unknown\";\n"; - print " verbose =3D 1;\n"; - print " }\n"; -} -print <. +# +# Generate a set of systemtap functions for translating various +# RPC enum values into strings +# +# python gensystemtap.py */*.x > libvirt_functions.stp +# + +from __future__ import print_function + +import re +import sys + +funcs =3D {} + +types =3D {} +status =3D {} +auth =3D {} + + +def load_file(fh): + instatus =3D False + intype =3D False + inauth =3D False + + for line in fh: + if re.match(r'''\s*enum\s+virNetMessageType\s*''', line): + intype =3D True + elif re.match(r'''\s*enum\s+virNetMessageStatus\s*''', line): + instatus =3D True + elif re.match(r'''\s*enum remote_auth_type.*''', line): + inauth =3D True + elif line.find("}") !=3D -1: + intype =3D False + instatus =3D False + inauth =3D False + elif instatus: + m =3D re.match(r'''^\s+VIR_NET_(\w+)\s*=3D\s*(\d+),?$''', line) + if m is not None: + status[m.group(2)] =3D m.group(1).lower() + elif intype: + m =3D re.match(r'''^\s+VIR_NET_(\w+)\s*=3D\s*(\d+),?$''', line) + if m is not None: + types[m.group(2)] =3D m.group(1).lower() + elif inauth: + m =3D re.match(r'''^\s+REMOTE_AUTH_(\w+)\s*=3D\s*(\d+),?$''', = line) + if m is not None: + auth[m.group(2)] =3D m.group(1).lower() + else: + m =3D re.match(r'''^.*?(?:VIR_)?(\w+?)(?:_PROTOCOL)?''' + + r'''_PROGRAM\s*=3D\s*0x([a-fA-F0-9]+)\s*;''', lin= e) + if m is not None: + funcs[m.group(1).lower()] =3D { + "id": int(m.group(2), 16), + "version": None, + "progs": [] + } + continue + + m =3D re.match(r'''^.*?(?:VIR_)?(\w+?)(?:_PROTOCOL)?_''' + + r'''(?:PROGRAM|PROTOCOL)_VERSION\s*=3D\s*(\d+)\s*= ;''', + line) + if m is not None: + funcs[m.group(1).lower()]["version"] =3D m.group(2) + continue + + m =3D re.match(r'''^.*?(?:VIR_)?(\w+?)(?:_PROTOCOL)?''' + + r'''_PROC_(.*?)\s+=3D\s+(\d+)''', line) + if m is not None: + funcs[m.group(1).lower()]["progs"].insert( + int(m.group(3)), m.group(2).lower()) + + +for file in sys.argv[1:]: + with open(file, "r") as fh: + load_file(fh) + + +def genfunc(name, varname, types): + print("function %s(%s, verbose)" % (name, varname)) + print("{") + + first =3D True + for typename in sorted(types.keys()): + cond =3D "} else if" + if first: + cond =3D "if" + first =3D False + + print(" %s (%s =3D=3D %s) {" % (cond, varname, typename)) + print(" %sstr =3D \"%s\"" % (varname, types[typename])) + + print(" } else {") + print(" %sstr =3D \"unknown\";" % varname) + print(" verbose =3D 1;") + print(" }") + print(" if (verbose) {") + print(" %sstr =3D %sstr . sprintf(\":%%d\", %s)" % + (varname, varname, varname)) + print(" }") + print(" return %sstr;" % varname) + print("}") + + +genfunc("libvirt_rpc_auth_name", "type", auth) +genfunc("libvirt_rpc_type_name", "type", types) +genfunc("libvirt_rpc_status_name", "status", status) + +print("function libvirt_rpc_program_name(program, verbose)") +print("{") + +first =3D True +for funcname in sorted(funcs.keys()): + cond =3D "} else if" + if first: + cond =3D "if" + first =3D False + + print(" %s (program =3D=3D %s) {" % (cond, funcs[funcname]["id"])) + print(" programstr =3D \"%s\"" % funcname) + +print(" } else {") +print(" programstr =3D \"unknown\";") +print(" verbose =3D 1;") +print(" }") +print(" if (verbose) {") +print(" programstr =3D programstr . sprintf(\":%d\", program)") +print(" }") +print(" return programstr;") +print("}") + +print("function libvirt_rpc_procedure_name(program, version, proc, verbose= )") +print("{") + +first =3D True +for prog in sorted(funcs.keys()): + cond =3D "} else if" + if first: + cond =3D "if" + first =3D False + + print(" %s (program =3D=3D %s && version =3D=3D %s) {" % + (cond, funcs[prog]["id"], funcs[prog]["version"])) + + pfirst =3D True + for id in range(len(funcs[prog]["progs"])): + pcond =3D "} else if" + if pfirst: + pcond =3D "if" + pfirst =3D False + + print(" %s (proc =3D=3D %s) {" % (pcond, id + 1)) + print(" procstr =3D \"%s\";" % funcs[prog]["progs"][id]) + + print(" } else {") + print(" procstr =3D \"unknown\";") + print(" verbose =3D 1;") + print(" }") + +print(" } else {") +print(" procstr =3D \"unknown\";") +print(" verbose =3D 1;") +print(" }") +print(" if (verbose) {") +print(" procstr =3D procstr . sprintf(\":%d\", proc)") +print(" }") +print(" return procstr;") +print("}") --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list