From nobody Tue Nov 26 14:16:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 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=1573483566; cv=none; d=zoho.com; s=zohoarc; b=k5Ej2i8+TbkltulDVc8kxtOlOa6pRpvbVWeQ1Jo6ghtW47SaONzicVqL8MtU/zwuMH/G2nBl+NMF+I5DCUPHGdTu/ZfuUseCt3fO00B59NSOs+Rf/rUo8X3y14vt5i6oUL2smSZ2Lu9mBNKbCrko/JYk74P5JzkYsxmQKif6jiA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573483566; 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=BrHmO8wAkZhGm6Q6M7Amh1U6xWTGJ/hd3vsu7fxpNf0=; b=IcFrCc8g7aZ1SxN8cU2d0TPvPxKJuMOxzqBTdHeMEbm8c4S+9y/HM3BdADbcu7DgpoQSbP8kxyZ2aJjQjdQDq7p1N8SDeL/R3AK3eJlevFvIFt84BKDPlCpSMCdK3aTC5ozdeD9jvpDhn2DqZbhpwfdYB/vYu3j4CLzOwMGEueY= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1573483566132728.2511329137852; Mon, 11 Nov 2019 06:46:06 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-408-6w2w1zemO7qHrKYxII_8IQ-1; Mon, 11 Nov 2019 09:45:19 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A0AA38A2432; Mon, 11 Nov 2019 14:45:12 +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 68B6B4B4; Mon, 11 Nov 2019 14:45:12 +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 0BD8818034FF; Mon, 11 Nov 2019 14:45:12 +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 xABEiwdj020421 for ; Mon, 11 Nov 2019 09:44:58 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7689A5DD73; Mon, 11 Nov 2019 14:44:58 +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 DB7E55D9C9; Mon, 11 Nov 2019 14:44:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573483564; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=BrHmO8wAkZhGm6Q6M7Amh1U6xWTGJ/hd3vsu7fxpNf0=; b=DOq4fE/THCWM41xCeXkbj/OnuafsY35qZa6DyPCSBDhV37czoY4uBeH/fbeWIVGB8mm0Of PpduAqqN+ugKOfB3x7BlTJd4aUpiM8+QUDf5IwlkKvAs4nNxY82aJB2+fuRqVIWQplaUSJ q0Cb9P2MTBE2hs7jIM31JghQ9jP4mVY= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Mon, 11 Nov 2019 14:38:13 +0000 Message-Id: <20191111143826.16050-11-berrange@redhat.com> In-Reply-To: <20191111143826.16050-1-berrange@redhat.com> References: <20191111143826.16050-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 v5 10/23] 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: 6w2w1zemO7qHrKYxII_8IQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: J=C3=A1n Tomko Tested-by: Cole Robinson --- 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 afed409c94..7155ab6ce9 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 b0ca9d3442..55ad51abf1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -330,15 +330,25 @@ 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_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