From nobody Sun Feb 8 01:33:32 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=1570621408; cv=none; d=zoho.com; s=zohoarc; b=T9qQE5xl/H6OEKtaIV7XcdAr5B72w2jt+gS8LXeEcNnGoKM2VgunrCvrRtxDKh9Qjqa66YYSoKTBMiJskFqB19WfvfFF58DYPbKtKuhLWjeCA7yoysM+F06Dp+YekmtpQ+PkAyRrMLxxhXt0fTnN4aHPyK8fqxsaon0ZbGlaTSc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570621408; 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; bh=m3PYosN2jBa5Qt17hwHYHk7w1vGHGg0viHla/9SJRnk=; b=bRnfujDUcpVfl/9ONPVav8vLo6p7Qp9Yf/xvMWSCGwHycHT9DHTUSXq82HDEujzTy0QD8NMWzbQ63fCv3qq8ZVzH70bxb1ffnUqoHhunKdOr83kOAg4a+s7OzOZbSDphTbKyac0UqajHZXMNTNUwbLNtmSNefNsH4yW62FLAiew= 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 1570621408449622.7896270441661; Wed, 9 Oct 2019 04:43:28 -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 93C576B; Wed, 9 Oct 2019 11:43:26 +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 29FCE614E3; Wed, 9 Oct 2019 11:43:26 +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 CD9F64EE50; Wed, 9 Oct 2019 11:43:25 +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 x99BhIlq030067 for ; Wed, 9 Oct 2019 07:43:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id CE2CD6031D; Wed, 9 Oct 2019 11:43:18 +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 40EC760466; Wed, 9 Oct 2019 11:43:18 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Wed, 9 Oct 2019 12:37:28 +0100 Message-Id: <20191009113741.5002-14-berrange@redhat.com> In-Reply-To: <20191009113741.5002-1-berrange@redhat.com> References: <20191009113741.5002-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 v4 13/26] 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.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 09 Oct 2019 11:43:27 +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 --- Makefile.am | 1 + scripts/check-drivername.py | 114 ++++++++++++++++++++++++++++++++++++ src/Makefile.am | 18 ++++-- src/check-drivername.pl | 83 -------------------------- 4 files changed, 129 insertions(+), 87 deletions(-) create mode 100644 scripts/check-drivername.py delete mode 100755 src/check-drivername.pl diff --git a/Makefile.am b/Makefile.am index 345ee2a5aa..51c39b6e01 100644 --- a/Makefile.am +++ b/Makefile.am @@ -47,6 +47,7 @@ EXTRA_DIST =3D \ AUTHORS.in \ scripts/augeas-gentest.py \ scripts/check-aclperms.py \ + scripts/check-drivername.py \ scripts/check-spacing.py \ scripts/check-symfile.py \ scripts/check-symsorting.py \ diff --git a/scripts/check-drivername.py b/scripts/check-drivername.py new file mode 100644 index 0000000000..3226ee7962 --- /dev/null +++ b/scripts/check-drivername.py @@ -0,0 +1,114 @@ +#!/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.search(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.search(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"= % + drv) + continue + + m =3D re.search(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.search(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" % + (field, tmp)) + status =3D 1 + +sys.exit(status) diff --git a/src/Makefile.am b/src/Makefile.am index 1f60aee625..9cf4ef2a6c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -333,16 +333,26 @@ 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) $(top_srcdir)/scripts/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 - check-driverimpls: $(AM_V_GEN)$(PERL) $(srcdir)/check-driverimpls.pl \ $(filter /%,$(DRIVER_SOURCE_FILES)) \ 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; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list