From nobody Sun Feb 8 14:10:18 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=1568219326; cv=none; d=zoho.com; s=zohoarc; b=BHyvSiFDyvzKhaSPFUBjy2DRER6uEwUcXvfuCjq8+NYZqcSPe9Ynimp8xHAQkohVJtWDlsCTJC7ye8qzOSwalpXjj6QJI5ijCvlNjduljc8AiozY5c0ULLale6U6LlkLVFuPwdX38vwcKIFnZylqvm2fqUE8lD8XT2iyrGVzIvM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568219326; 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=f7GirJqm58nyBZKPXHXjW0AQOyfexHJb0T1ujdcVStE=; b=hmme6P2vIoGGheNz3ScZmUvHJqgMaTj09JTSlT0a9u0Q8BymOs9GaGrVTvAgCN/XLmwFY7D/vjf/XxnnRs1c55zIcSvWXWI7vFEY27LgrEGE+InPZRLYz3p9VinK+VQMKQWxLRkzr+qF6UJAJBLPaiI/kpVbcjCgYTGY94H2NQ8= 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 1568219326749515.7126206640746; Wed, 11 Sep 2019 09:28:46 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2580B8AC6F6; Wed, 11 Sep 2019 16:28:45 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F11E119C70; Wed, 11 Sep 2019 16:28: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 B5CCD206CC; Wed, 11 Sep 2019 16:28:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8BGSPTL013185 for ; Wed, 11 Sep 2019 12:28:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3D2066017E; Wed, 11 Sep 2019 16:28:25 +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 A1DD7601A5; Wed, 11 Sep 2019 16:28:23 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Wed, 11 Sep 2019 17:23:24 +0100 Message-Id: <20190911162333.8668-16-berrange@redhat.com> In-Reply-To: <20190911162333.8668-1-berrange@redhat.com> References: <20190911162333.8668-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 15/24] src: rewrite driver name checker 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.69]); Wed, 11 Sep 2019 16:28:45 +0000 (UTC) As part of an goal to eliminate Perl from libvirt build tools, rewrite the check-drivername.pl tool in Python. This was mostly 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. In testing though it was discovered the existing code was broken since it hadn't been updated after driver.h was split into many files. Since the old code is being thrown away, the fix was done as part of the rewrite rather than split into a separate commit. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/Makefile.am | 18 +++++-- src/check-drivername.pl | 83 ----------------------------- src/check-drivername.py | 112 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+), 86 deletions(-) delete mode 100755 src/check-drivername.pl create mode 100644 src/check-drivername.py diff --git a/src/Makefile.am b/src/Makefile.am index 539d8b0f58..58d228eb4f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -336,15 +336,27 @@ check-protocol: endif !WITH_REMOTE EXTRA_DIST +=3D $(PROTOCOL_STRUCTS) =20 +DRIVERS =3D \ + $(srcdir)/driver-hypervisor.h \ + $(srcdir)/driver-interface.h \ + $(srcdir)/driver-network.h \ + $(srcdir)/driver-nodedev.h \ + $(srcdir)/driver-nwfilter.h \ + $(srcdir)/driver-secret.h \ + $(srcdir)/driver-state.h \ + $(srcdir)/driver-storage.h \ + $(srcdir)/driver-stream.h \ + $(NULL) + check-drivername: - $(AM_V_GEN)$(PERL) $(srcdir)/check-drivername.pl \ - $(srcdir)/driver.h \ + $(AM_V_GEN)$(RUNUTF8) $(PYTHON) $(srcdir)/check-drivername.py \ + $(DRIVERS) \ $(srcdir)/libvirt_public.syms \ $(srcdir)/libvirt_admin_public.syms \ $(srcdir)/libvirt_qemu.syms \ $(srcdir)/libvirt_lxc.syms =20 -EXTRA_DIST +=3D check-drivername.pl +EXTRA_DIST +=3D check-drivername.py =20 check-driverimpls: $(AM_V_GEN)$(PERL) $(srcdir)/check-driverimpls.pl \ diff --git a/src/check-drivername.pl b/src/check-drivername.pl deleted file mode 100755 index 3a62193e33..0000000000 --- a/src/check-drivername.pl +++ /dev/null @@ -1,83 +0,0 @@ -#!/usr/bin/env perl -# -# Copyright (C) 2013 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 -# . -# - -use strict; -use warnings; - -my $drvfile =3D shift; -my @symfiles =3D @ARGV; - -my %symbols; - -foreach my $symfile (@symfiles) { - open SYMFILE, "<", $symfile - or die "cannot read $symfile: $!"; - while () { - if (/^\s*(vir\w+)\s*;\s*$/) { - $symbols{$1} =3D 1; - } - } - - close SYMFILE; -} - -open DRVFILE, "<", $drvfile - or die "cannot read $drvfile: $!"; - -my $status =3D 0; - -while () { - next if /virDrvConnectSupportsFeature/; - if (/\*(virDrv\w+)\s*\)/) { - - my $drv =3D $1; - - next if $drv =3D~ /virDrvState/; - next if $drv =3D~ /virDrvDomainMigrate(Prepare|Perform|Confirm|Beg= in|Finish)/; - - my $sym =3D $drv; - $sym =3D~ s/virDrv/vir/; - - unless (exists $symbols{$sym}) { - print "Driver method name $drv doesn't match public API name\n= "; - $status =3D 1; - } - } elsif (/^\*(vir\w+)\s*\)/) { - my $name =3D $1; - print "Bogus name $1\n"; - $status =3D 1; - } elsif (/^\s*(virDrv\w+)\s+(\w+);\s*/) { - my $drv =3D $1; - my $field =3D $2; - - my $tmp =3D $drv; - $tmp =3D~ s/virDrv//; - $tmp =3D~ s/^NWFilter/nwfilter/; - $tmp =3D~ s/^(\w)/lc $1/e; - - unless ($tmp eq $field) { - print "Driver struct field $field should be named $tmp\n"; - $status =3D 1; - } - } -} - -close DRVFILE; - -exit $status; diff --git a/src/check-drivername.py b/src/check-drivername.py new file mode 100644 index 0000000000..e87202be6d --- /dev/null +++ b/src/check-drivername.py @@ -0,0 +1,112 @@ +#!/usr/bin/env python +# +# Copyright (C) 2013-2019 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 +# . +# + +from __future__ import print_function + +import re +import sys + +drvfiles =3D [] +symfiles =3D [] +for arg in sys.argv: + if arg.endswith(".h"): + drvfiles.append(arg) + else: + symfiles.append(arg) + +symbols =3D {} + +for symfile in symfiles: + with open(symfile, "r") as fh: + for line in fh: + m =3D re.match(r'''^\s*(vir\w+)\s*;\s*$''', line) + if m is not None: + symbols[m.group(1)] =3D True + +status =3D 0 +for drvfile in drvfiles: + with open(drvfile, "r") as fh: + for line in fh: + if line.find("virDrvConnectSupportsFeature") !=3D -1: + continue + + m =3D re.match(r'''.*\*(virDrv\w+)\s*\).*''', line) + if m is not None: + drv =3D m.group(1) + + skip =3D [ + "virDrvStateInitialize", + "virDrvStateCleanup", + "virDrvStateReload", + "virDrvStateStop", + "virDrvConnectURIProbe", + "virDrvDomainMigratePrepare", + "virDrvDomainMigratePrepare2", + "virDrvDomainMigratePrepare3", + "virDrvDomainMigratePrepare3Params", + "virDrvDomainMigratePrepareTunnel", + "virDrvDomainMigratePrepareTunnelParams", + "virDrvDomainMigratePrepareTunnel3", + "virDrvDomainMigratePrepareTunnel3Params", + "virDrvDomainMigratePerform", + "virDrvDomainMigratePerform3", + "virDrvDomainMigratePerform3Params", + "virDrvDomainMigrateConfirm", + "virDrvDomainMigrateConfirm3", + "virDrvDomainMigrateConfirm3Params", + "virDrvDomainMigrateBegin", + "virDrvDomainMigrateBegin3", + "virDrvDomainMigrateBegin3Params", + "virDrvDomainMigrateFinish", + "virDrvDomainMigrateFinish2", + "virDrvDomainMigrateFinish3", + "virDrvDomainMigrateFinish3Params", + "virDrvStreamInData", + ] + if drv in skip: + continue + + sym =3D drv.replace("virDrv", "vir") + + if sym not in symbols: + print("Driver method name %s doesn't match public API = name" % drv) + continue + + m =3D re.match(r'''^\*(vir\w+)\s*\)''', line) + if m is not None: + name =3D m.group(1) + print("Bogus name %s" % name) + status =3D 1 + continue + + m =3D re.match(r'''^\s*(virDrv\w+)\s+(\w+);\s*''', line) + if m is not None: + drv =3D m.group(1) + field =3D m.group(2) + + tmp =3D drv.replace("virDrv", "") + if tmp.startswith("NWFilter"): + tmp =3D "nwfilter" + tmp[8:] + tmp =3D tmp[0:1].lower() + tmp[1:] + + if tmp !=3D field: + print("Driver struct field %s should be named %s" % (f= ield, tmp)) + status =3D 1 + +sys.exit(status) --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list