From nobody Fri Apr 26 13:02:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1605803207; cv=none; d=zohomail.com; s=zohoarc; b=PSSp4tnLte36ajfKvWIMMdrLO7c4BdNI6WfocZMm5YyeHfmlHE0IVtsxDpSq7o+ERi/CJsvntzgzBzIf4fXFjl9B4NNJJA5WLirvOg9i9U5OG2SRm0hqJe0cJIna5VOguQHDCn3VJux8ka+a/GQwiOtQCv2RjrWKTjAYNwP7PfQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605803207; h=Content-Type:Content-Transfer-Encoding:Cc: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=+6bLJokhiV17qaLztOHU5r8pem25K/qtExxAYmte7nQ=; b=XwLcQ6z4QMWaPxWN2dR/DzVbxVFM3pa5SOR9hKL8Obpdw+9+rZ4Sy6gg0jKefG0TbFY6IdQjyE2wr3xPeRaoQ7zhFUlExq0bq8eHBu/yNNddieuORr2HrEJV2togUkmtY9j0fYITORfhSGz0sSfd+ToCbFKGw9koGlaqTHzyJmw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1605803207713131.2932455057628; Thu, 19 Nov 2020 08:26:47 -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-51-OmbvPXpeN6qoLBim1JHSlg-1; Thu, 19 Nov 2020 11:26:38 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9A40E8797DC; Thu, 19 Nov 2020 16:26:31 +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 78AAC5D9C6; Thu, 19 Nov 2020 16:26:31 +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 404F2180954D; Thu, 19 Nov 2020 16:26:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0AJGQTRP030626 for ; Thu, 19 Nov 2020 11:26:29 -0500 Received: by smtp.corp.redhat.com (Postfix) id B84015C1B4; Thu, 19 Nov 2020 16:26:29 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 36C875C1A1; Thu, 19 Nov 2020 16:26:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605803201; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=+6bLJokhiV17qaLztOHU5r8pem25K/qtExxAYmte7nQ=; b=E5VMZgURnsyjyAbZuI7G8L20l8wNI+Myj0ZMqxcjePqskf2p9mkbmvsWGRo24Fi5ARDJ4u Jm5KPkeOrokbApbwcn+roRWjYF3e7Xg34PfpKGJvUgIemtmQyHpwGeu7dyEDTnzajL1Uge l2g8j9zflJ9V5Ko03NjsfsA1b/N4GWc= X-MC-Unique: OmbvPXpeN6qoLBim1JHSlg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 01/16] tests: virsh: Add simple testsuite for using --print-xml of various commands Date: Thu, 19 Nov 2020 17:26:07 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Ryan Gahagan 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.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The test uses a script and compares the output against a template file VIR_TEST_REGENREATE_OUTPUT can be used on test failures. This test will be marked as expensive once the refactors it guards are done. Signed-off-by: Peter Krempa Reviewed-by: Daniel Henrique Barboza --- tests/meson.build | 1 + tests/virsh-output | 27 +++ tests/virsh-output-commands | 80 +++++++ tests/virsh-output.out | 408 ++++++++++++++++++++++++++++++++++++ 4 files changed, 516 insertions(+) create mode 100755 tests/virsh-output create mode 100755 tests/virsh-output-commands create mode 100644 tests/virsh-output.out diff --git a/tests/meson.build b/tests/meson.build index f88410ff33..3ef4d06177 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -654,6 +654,7 @@ if conf.has('WITH_LIBVIRTD') 'virsh-define-dev-segfault', 'virsh-int-overflow', 'virsh-optparse', + 'virsh-output', 'virsh-read-bufsiz', 'virsh-read-non-seekable', 'virsh-schedinfo', diff --git a/tests/virsh-output b/tests/virsh-output new file mode 100755 index 0000000000..44833c7048 --- /dev/null +++ b/tests/virsh-output @@ -0,0 +1,27 @@ +#!/bin/sh + +. "$(dirname $0)/test-lib.sh" + +if [ ! -x /bin/bash ]; then + echo skipping test - no bash + exit 77 +fi + +mock_xdg_ || framework_failure + +export LIBVIRT_DEFAULT_URI=3D'test:///default' +ln -s $abs_top_builddir/tools/virsh virsh + +$abs_top_srcdir/tests/virsh-output-commands > out 2>&1 + +echo end >> out + +if compare $abs_top_srcdir/tests/virsh-output.out out; then + exit 0 +else + if [ "x$VIR_TEST_REGENERATE_OUTPUT" =3D "x1" ]; then + cp out $abs_top_srcdir/tests/virsh-output.out + fi + + exit 1 +fi diff --git a/tests/virsh-output-commands b/tests/virsh-output-commands new file mode 100755 index 0000000000..43f87bee0f --- /dev/null +++ b/tests/virsh-output-commands @@ -0,0 +1,80 @@ +#!/bin/bash + +attach_disk() +{ + ./virsh attach-disk --print-xml --domain testdom $@ --source /nonexist= ent/file +} + +set -x + +./virsh attach-disk +./virsh attach-disk --print-xml --domain testdom $@ --source "" +./virsh attach-disk --print-xml --domain testdom $@ --source "" --sourcety= pe file +./virsh attach-disk --print-xml --domain testdom $@ --source "" --sourcety= pe blah +attach_disk --target hda +attach_disk --target hda --sourcetype file +attach_disk --target hda --sourcetype block +attach_disk --target hda --sourcetype nothing +attach_disk --target hda --sourcetype file --type disk +attach_disk --target hda --sourcetype block --type disk +attach_disk --target hda --sourcetype file --type cdrom +attach_disk --target hda --sourcetype block --type cdrom +attach_disk --target hda --sourcetype file --type blah +attach_disk --target hda --sourcetype block --type blah +attach_disk --target hda --sourcetype file --type disk --driver testdriver +attach_disk --target hda --sourcetype file --type disk --subdriver qcow2 +attach_disk --target hda --sourcetype file --type disk --subdriver raw +attach_disk --target hda --sourcetype file --type disk --cache none +attach_disk --target hda --sourcetype file --type disk --subdriver qcow2 -= -cache none +attach_disk --target hda --sourcetype file --type disk --subdriver qcow2 -= -serial TEST_SERIAL +attach_disk --target hda --sourcetype file --type disk --mode readonly +attach_disk --target hda --sourcetype file --type disk --mode shareable +attach_disk --target hda --sourcetype file --type disk --mode whatever +attach_disk --target hda --sourcetype file --type disk --subdriver qcow2 -= -alias testalias +attach_disk --target hda --sourcetype file --type disk --rawio +attach_disk --target hda --sourcetype file --type disk --multifunction +attach_disk --target hda --sourcetype file --type disk --subdriver qcow2 -= -alias testalias --iothread 3 --mode readonly --cache none --driver qemu + +attach_disk --target hda --sourcetype file --type disk --address ide:1.2.3 +attach_disk --target hda --sourcetype file --type disk --address ide:1.2.4 +attach_disk --target hda --sourcetype file --type disk --address ide:1:2:5 +attach_disk --target sda --sourcetype file --type disk --address ide:1.2.3 +attach_disk --target vda --sourcetype file --type disk --address ide:1.2.3 + +attach_disk --target sda --sourcetype file --type disk --address usb:12.34 +attach_disk --target sda --sourcetype file --type disk --address usb:12.3 +attach_disk --target sda --sourcetype file --type disk --address usb:12:34 +attach_disk --target vda --sourcetype file --type disk --address usb:12.34 +attach_disk --target hda --sourcetype file --type disk --address usb:12.34 + +attach_disk --target sda --sourcetype file --type disk --address scsi:1.2.3 +attach_disk --target sda --sourcetype file --type disk --address scsi:1.2.4 +attach_disk --target sda --sourcetype file --type disk --address scsi:1:2:5 +attach_disk --target hda --sourcetype file --type disk --address scsi:1.2.3 +attach_disk --target vda --sourcetype file --type disk --address scsi:1.2.3 + +attach_disk --target sda --sourcetype file --type disk --address sata:1.2.3 +attach_disk --target sda --sourcetype file --type disk --address sata:1.2.4 +attach_disk --target sda --sourcetype file --type disk --address sata:1:2:5 +attach_disk --target hda --sourcetype file --type disk --address sata:1.2.3 +attach_disk --target vda --sourcetype file --type disk --address sata:1.2.3 + +attach_disk --target vda --sourcetype file --type disk --address pci:12.34= .56.78 +attach_disk --target vda --sourcetype file --type disk --address pci:12:34= :56:78 +attach_disk --target vda --sourcetype file --type disk --address pci:12.34= .56.aa +attach_disk --target hda --sourcetype file --type disk --address pci:12.34= .56.aa +attach_disk --target sda --sourcetype file --type disk --address pci:12.34= .56.aa + +attach_disk --target vda --sourcetype file --type disk --address pci:12.34= .56.78 --multifunction +attach_disk --target vda --sourcetype file --type disk --address pci:12:34= :56:78 --multifunction +attach_disk --target vda --sourcetype file --type disk --address pci:12.34= .56.aa --multifunction + +attach_disk --target vda --sourcetype file --type disk --address ccw:12.34= .56 +attach_disk --target vda --sourcetype file --type disk --address ccw:12:34= :56 +attach_disk --target vda --sourcetype file --type disk --address ccw:12.34= .56 +attach_disk --target hda --sourcetype file --type disk --address ccw:12.34= .56 +attach_disk --target sda --sourcetype file --type disk --address ccw:12.34= .56 + +attach_disk --target vda --sourcetype file --type disk --address test:12.3= 4.56 +attach_disk --target vda --sourcetype file --type disk --address test:12:3= 4:56 +attach_disk --target vda --sourcetype file --type disk --address test:12.3= 4.56 diff --git a/tests/virsh-output.out b/tests/virsh-output.out new file mode 100644 index 0000000000..8fbe02a232 --- /dev/null +++ b/tests/virsh-output.out @@ -0,0 +1,408 @@ ++ ./virsh attach-disk +error: command 'attach-disk' requires option +error: command 'attach-disk' requires option +error: command 'attach-disk' requires option ++ ./virsh attach-disk --print-xml --domain testdom --source '' +error: command 'attach-disk' requires option ++ ./virsh attach-disk --print-xml --domain testdom --source '' --sourcetyp= e file +error: command 'attach-disk' requires option ++ ./virsh attach-disk --print-xml --domain testdom --source '' --sourcetyp= e blah +error: command 'attach-disk' requires option ++ attach_disk --target hda ++ ./virsh attach-disk --print-xml --domain testdom --target hda --source /= nonexistent/file + + + + + ++ attach_disk --target hda --sourcetype file ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe file --source /nonexistent/file + + + + + ++ attach_disk --target hda --sourcetype block ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe block --source /nonexistent/file + + + + + ++ attach_disk --target hda --sourcetype nothing ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe nothing --source /nonexistent/file +error: Unknown source type: 'nothing' + ++ attach_disk --target hda --sourcetype file --type disk ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe file --type disk --source /nonexistent/file + + + + + ++ attach_disk --target hda --sourcetype block --type disk ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe block --type disk --source /nonexistent/file + + + + + ++ attach_disk --target hda --sourcetype file --type cdrom ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe file --type cdrom --source /nonexistent/file + + + + + ++ attach_disk --target hda --sourcetype block --type cdrom ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe block --type cdrom --source /nonexistent/file + + + + + ++ attach_disk --target hda --sourcetype file --type blah ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe file --type blah --source /nonexistent/file + + + + + ++ attach_disk --target hda --sourcetype block --type blah ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe block --type blah --source /nonexistent/file + + + + + ++ attach_disk --target hda --sourcetype file --type disk --driver testdriv= er ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe file --type disk --driver testdriver --source /nonexistent/file + + + + + + ++ attach_disk --target hda --sourcetype file --type disk --subdriver qcow2 ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe file --type disk --subdriver qcow2 --source /nonexistent/file + + + + + + ++ attach_disk --target hda --sourcetype file --type disk --subdriver raw ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe file --type disk --subdriver raw --source /nonexistent/file + + + + + + ++ attach_disk --target hda --sourcetype file --type disk --cache none ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe file --type disk --cache none --source /nonexistent/file + + + + + + ++ attach_disk --target hda --sourcetype file --type disk --subdriver qcow2= --cache none ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe file --type disk --subdriver qcow2 --cache none --source /nonexistent/fi= le + + + + + + ++ attach_disk --target hda --sourcetype file --type disk --subdriver qcow2= --serial TEST_SERIAL ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe file --type disk --subdriver qcow2 --serial TEST_SERIAL --source /nonexi= stent/file + + + + + TEST_SERIAL + + ++ attach_disk --target hda --sourcetype file --type disk --mode readonly ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe file --type disk --mode readonly --source /nonexistent/file + + + + + + ++ attach_disk --target hda --sourcetype file --type disk --mode shareable ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe file --type disk --mode shareable --source /nonexistent/file + + + + + + ++ attach_disk --target hda --sourcetype file --type disk --mode whatever ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe file --type disk --mode whatever --source /nonexistent/file +error: No support for whatever in command 'attach-disk' + ++ attach_disk --target hda --sourcetype file --type disk --subdriver qcow2= --alias testalias ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe file --type disk --subdriver qcow2 --alias testalias --source /nonexiste= nt/file + + + + + + + ++ attach_disk --target hda --sourcetype file --type disk --rawio ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe file --type disk --rawio --source /nonexistent/file + + + + + ++ attach_disk --target hda --sourcetype file --type disk --multifunction ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe file --type disk --multifunction --source /nonexistent/file + + + + + ++ attach_disk --target hda --sourcetype file --type disk --subdriver qcow2= --alias testalias --iothread 3 --mode readonly --cache none --driver qemu ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe file --type disk --subdriver qcow2 --alias testalias --iothread 3 --mode= readonly --cache none --driver qemu --source /nonexistent/file + + + + + + + + ++ attach_disk --target hda --sourcetype file --type disk --address ide:1.2= .3 ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe file --type disk --address ide:1.2.3 --source /nonexistent/file + + + +
+ + ++ attach_disk --target hda --sourcetype file --type disk --address ide:1.2= .4 ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe file --type disk --address ide:1.2.4 --source /nonexistent/file + + + +
+ + ++ attach_disk --target hda --sourcetype file --type disk --address ide:1:2= :5 ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe file --type disk --address ide:1:2:5 --source /nonexistent/file + + + +
+ + ++ attach_disk --target sda --sourcetype file --type disk --address ide:1.2= .3 ++ ./virsh attach-disk --print-xml --domain testdom --target sda --sourcety= pe file --type disk --address ide:1.2.3 --source /nonexistent/file +error: expecting a scsi:00.00.00 or usb:00.00 or sata:00.00.00 address. + ++ attach_disk --target vda --sourcetype file --type disk --address ide:1.2= .3 ++ ./virsh attach-disk --print-xml --domain testdom --target vda --sourcety= pe file --type disk --address ide:1.2.3 --source /nonexistent/file +error: expecting a pci:0000.00.00.00 or ccw:00.0.0000 address. + ++ attach_disk --target sda --sourcetype file --type disk --address usb:12.= 34 ++ ./virsh attach-disk --print-xml --domain testdom --target sda --sourcety= pe file --type disk --address usb:12.34 --source /nonexistent/file + + + +
+ + ++ attach_disk --target sda --sourcetype file --type disk --address usb:12.3 ++ ./virsh attach-disk --print-xml --domain testdom --target sda --sourcety= pe file --type disk --address usb:12.3 --source /nonexistent/file + + + +
+ + ++ attach_disk --target sda --sourcetype file --type disk --address usb:12:= 34 ++ ./virsh attach-disk --print-xml --domain testdom --target sda --sourcety= pe file --type disk --address usb:12:34 --source /nonexistent/file + + + +
+ + ++ attach_disk --target vda --sourcetype file --type disk --address usb:12.= 34 ++ ./virsh attach-disk --print-xml --domain testdom --target vda --sourcety= pe file --type disk --address usb:12.34 --source /nonexistent/file +error: expecting a pci:0000.00.00.00 or ccw:00.0.0000 address. + ++ attach_disk --target hda --sourcetype file --type disk --address usb:12.= 34 ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe file --type disk --address usb:12.34 --source /nonexistent/file +error: expecting an ide:00.00.00 address. + ++ attach_disk --target sda --sourcetype file --type disk --address scsi:1.= 2.3 ++ ./virsh attach-disk --print-xml --domain testdom --target sda --sourcety= pe file --type disk --address scsi:1.2.3 --source /nonexistent/file + + + +
+ + ++ attach_disk --target sda --sourcetype file --type disk --address scsi:1.= 2.4 ++ ./virsh attach-disk --print-xml --domain testdom --target sda --sourcety= pe file --type disk --address scsi:1.2.4 --source /nonexistent/file + + + +
+ + ++ attach_disk --target sda --sourcetype file --type disk --address scsi:1:= 2:5 ++ ./virsh attach-disk --print-xml --domain testdom --target sda --sourcety= pe file --type disk --address scsi:1:2:5 --source /nonexistent/file + + + +
+ + ++ attach_disk --target hda --sourcetype file --type disk --address scsi:1.= 2.3 ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe file --type disk --address scsi:1.2.3 --source /nonexistent/file +error: expecting an ide:00.00.00 address. + ++ attach_disk --target vda --sourcetype file --type disk --address scsi:1.= 2.3 ++ ./virsh attach-disk --print-xml --domain testdom --target vda --sourcety= pe file --type disk --address scsi:1.2.3 --source /nonexistent/file +error: expecting a pci:0000.00.00.00 or ccw:00.0.0000 address. + ++ attach_disk --target sda --sourcetype file --type disk --address sata:1.= 2.3 ++ ./virsh attach-disk --print-xml --domain testdom --target sda --sourcety= pe file --type disk --address sata:1.2.3 --source /nonexistent/file + + + +
+ + ++ attach_disk --target sda --sourcetype file --type disk --address sata:1.= 2.4 ++ ./virsh attach-disk --print-xml --domain testdom --target sda --sourcety= pe file --type disk --address sata:1.2.4 --source /nonexistent/file + + + +
+ + ++ attach_disk --target sda --sourcetype file --type disk --address sata:1:= 2:5 ++ ./virsh attach-disk --print-xml --domain testdom --target sda --sourcety= pe file --type disk --address sata:1:2:5 --source /nonexistent/file + + + +
+ + ++ attach_disk --target hda --sourcetype file --type disk --address sata:1.= 2.3 ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe file --type disk --address sata:1.2.3 --source /nonexistent/file +error: expecting an ide:00.00.00 address. + ++ attach_disk --target vda --sourcetype file --type disk --address sata:1.= 2.3 ++ ./virsh attach-disk --print-xml --domain testdom --target vda --sourcety= pe file --type disk --address sata:1.2.3 --source /nonexistent/file +error: expecting a pci:0000.00.00.00 or ccw:00.0.0000 address. + ++ attach_disk --target vda --sourcetype file --type disk --address pci:12.= 34.56.78 ++ ./virsh attach-disk --print-xml --domain testdom --target vda --sourcety= pe file --type disk --address pci:12.34.56.78 --source /nonexistent/file + + + +
+ + ++ attach_disk --target vda --sourcetype file --type disk --address pci:12:= 34:56:78 ++ ./virsh attach-disk --print-xml --domain testdom --target vda --sourcety= pe file --type disk --address pci:12:34:56:78 --source /nonexistent/file + + + +
+ + ++ attach_disk --target vda --sourcetype file --type disk --address pci:12.= 34.56.aa ++ ./virsh attach-disk --print-xml --domain testdom --target vda --sourcety= pe file --type disk --address pci:12.34.56.aa --source /nonexistent/file + + + +
+ + ++ attach_disk --target hda --sourcetype file --type disk --address pci:12.= 34.56.aa ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe file --type disk --address pci:12.34.56.aa --source /nonexistent/file +error: expecting an ide:00.00.00 address. + ++ attach_disk --target sda --sourcetype file --type disk --address pci:12.= 34.56.aa ++ ./virsh attach-disk --print-xml --domain testdom --target sda --sourcety= pe file --type disk --address pci:12.34.56.aa --source /nonexistent/file +error: expecting a scsi:00.00.00 or usb:00.00 or sata:00.00.00 address. + ++ attach_disk --target vda --sourcetype file --type disk --address pci:12.= 34.56.78 --multifunction ++ ./virsh attach-disk --print-xml --domain testdom --target vda --sourcety= pe file --type disk --address pci:12.34.56.78 --multifunction --source /non= existent/file + + + +
+ + ++ attach_disk --target vda --sourcetype file --type disk --address pci:12:= 34:56:78 --multifunction ++ ./virsh attach-disk --print-xml --domain testdom --target vda --sourcety= pe file --type disk --address pci:12:34:56:78 --multifunction --source /non= existent/file + + + +
+ + ++ attach_disk --target vda --sourcetype file --type disk --address pci:12.= 34.56.aa --multifunction ++ ./virsh attach-disk --print-xml --domain testdom --target vda --sourcety= pe file --type disk --address pci:12.34.56.aa --multifunction --source /non= existent/file + + + +
+ + ++ attach_disk --target vda --sourcetype file --type disk --address ccw:12.= 34.56 ++ ./virsh attach-disk --print-xml --domain testdom --target vda --sourcety= pe file --type disk --address ccw:12.34.56 --source /nonexistent/file + + + +
+ + ++ attach_disk --target vda --sourcetype file --type disk --address ccw:12:= 34:56 ++ ./virsh attach-disk --print-xml --domain testdom --target vda --sourcety= pe file --type disk --address ccw:12:34:56 --source /nonexistent/file + + + +
+ + ++ attach_disk --target vda --sourcetype file --type disk --address ccw:12.= 34.56 ++ ./virsh attach-disk --print-xml --domain testdom --target vda --sourcety= pe file --type disk --address ccw:12.34.56 --source /nonexistent/file + + + +
+ + ++ attach_disk --target hda --sourcetype file --type disk --address ccw:12.= 34.56 ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe file --type disk --address ccw:12.34.56 --source /nonexistent/file +error: expecting an ide:00.00.00 address. + ++ attach_disk --target sda --sourcetype file --type disk --address ccw:12.= 34.56 ++ ./virsh attach-disk --print-xml --domain testdom --target sda --sourcety= pe file --type disk --address ccw:12.34.56 --source /nonexistent/file +error: expecting a scsi:00.00.00 or usb:00.00 or sata:00.00.00 address. + ++ attach_disk --target vda --sourcetype file --type disk --address test:12= .34.56 ++ ./virsh attach-disk --print-xml --domain testdom --target vda --sourcety= pe file --type disk --address test:12.34.56 --source /nonexistent/file +error: Invalid address. + ++ attach_disk --target vda --sourcetype file --type disk --address test:12= :34:56 ++ ./virsh attach-disk --print-xml --domain testdom --target vda --sourcety= pe file --type disk --address test:12:34:56 --source /nonexistent/file +error: Invalid address. + ++ attach_disk --target vda --sourcetype file --type disk --address test:12= .34.56 ++ ./virsh attach-disk --print-xml --domain testdom --target vda --sourcety= pe file --type disk --address test:12.34.56 --source /nonexistent/file +error: Invalid address. + +end --=20 2.28.0 From nobody Fri Apr 26 13:02:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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=1605803204; cv=none; d=zohomail.com; s=zohoarc; b=lQxnGwrwqnR0HXfxUGtrjHCSRW3F2b4G6/Uv/6oTKs5OEuVtb0vxXivHzBZOfWlPTqsNTZ1zTlKy0GwaEURQrbbxJ9ExZuMLpClpE+BTNbC0J+NEhVFdXHmmgSlpuw5rxyEJf8eVfM5HZBTK2+yasMV4KFQjJ92fMjS2fTouBSg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605803204; h=Content-Type:Content-Transfer-Encoding:Cc: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=DeRLSIOOGfVoAczIrC89cJ+/t3Eh/3dLvahfIcQIDMQ=; b=eDX+QjS7Rkl+QEVqfdn4kbeJiGZMSOU7NiRqbCYyHQFKRNT+VapZaq2TLFNzN6TBrYX1kJ8rUHmY12lnAcqrUWL1HkTt6MbL3/BybBzAPffx5Cd4ohI9X+1ghkRqzn5Xn6TcHdOIAaXJNM+Wg7Bz3xD79/DK/1/LTpyrG02E8WE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1605803204791848.9138324273115; Thu, 19 Nov 2020 08:26:44 -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-360-haVWHMCYMk-B1iD-mVHxKQ-1; Thu, 19 Nov 2020 11:26:41 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B977A100C606; Thu, 19 Nov 2020 16:26:35 +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 92D9B5D9C6; Thu, 19 Nov 2020 16:26:35 +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 5F1B15002E; Thu, 19 Nov 2020 16:26:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0AJGQVMA030639 for ; Thu, 19 Nov 2020 11:26:31 -0500 Received: by smtp.corp.redhat.com (Postfix) id 243AA5C1B4; Thu, 19 Nov 2020 16:26:31 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 357FA5C1A1; Thu, 19 Nov 2020 16:26:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605803203; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=DeRLSIOOGfVoAczIrC89cJ+/t3Eh/3dLvahfIcQIDMQ=; b=Ff0mvqjpGmTQdedI4ws7dMTKYiWmScwLtklkxgUDQlppUw9Kbw2COmp/NdLPOb9S0hRM9E LSmvT9spO9QfbxLYONozkC8u7tOEu2pnfNK32vtj2eR4bnbsx2/wYvsPtUIpxiAtHOIEk9 PCl1i72geVwdQEFHVtMw1lWS5brhreA= X-MC-Unique: haVWHMCYMk-B1iD-mVHxKQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 02/16] virsh: cmdAttachDisk: Declare one variable per line Date: Thu, 19 Nov 2020 17:26:08 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Ryan Gahagan 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.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: Daniel Henrique Barboza --- tools/virsh-domain.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index c999458d72..e27b779533 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -562,13 +562,23 @@ static bool cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) { virDomainPtr dom =3D NULL; - const char *source =3D NULL, *target =3D NULL, *driver =3D NULL, - *subdriver =3D NULL, *type =3D NULL, *mode =3D NULL, - *iothread =3D NULL, *cache =3D NULL, *io =3D NULL, - *serial =3D NULL, *straddr =3D NULL, *wwn =3D NULL, - *targetbus =3D NULL, *alias =3D NULL; + const char *source =3D NULL; + const char *target =3D NULL; + const char *driver =3D NULL; + const char *subdriver =3D NULL; + const char *type =3D NULL; + const char *mode =3D NULL; + const char *iothread =3D NULL; + const char *cache =3D NULL; + const char *io =3D NULL; + const char *serial =3D NULL; + const char *straddr =3D NULL; + const char *wwn =3D NULL; + const char *targetbus =3D NULL; + const char *alias =3D NULL; struct DiskAddress diskAddr; - bool isFile =3D false, functionReturn =3D false; + bool isFile =3D false; + bool functionReturn =3D false; int ret; unsigned int flags =3D VIR_DOMAIN_AFFECT_CURRENT; const char *stype =3D NULL; --=20 2.28.0 From nobody Fri Apr 26 13:02:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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=1605803211; cv=none; d=zohomail.com; s=zohoarc; b=QIILDZrdpIRENZSAkDwdfw9l3WkbEDU2NnQzu6NyhyL+pz3iimLLUlfTMZmA8ROenBrGIztsbP30WDzfMSHNbOPctDW8hBLBKFPrVsI21uG0cmkA8QpB9ORv0Cu1XL70ymVNy5UMwvJdtQMOtsFWjQ957op9cFemIGCXxYEXtx0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605803211; h=Content-Type:Content-Transfer-Encoding:Cc: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=8KDDTsyfVkWUwk0KlIiiKN/4z6aPmpItmdbPSXq8hik=; b=oJ8ZdaaxxkQNpbrD/jKiD3FoKmLU1U0DEOItfQpcjAJcPMgN8498qlu899fu/kao6JuSSMaAXMLTFEP9frPsy27mS68RfwaKk7H7zJyyBJ/mirJ55DqLkYGDlLsh3UkmlynHqQ5twHiNj0rQ6SF2IlY1ebQrxpC/hMThuH4f2Pg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1605803211111283.8493732629347; Thu, 19 Nov 2020 08:26:51 -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-188-FweIGQhZOxuF2IjDdOhhrQ-1; Thu, 19 Nov 2020 11:26:44 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 95C46E767; Thu, 19 Nov 2020 16:26:38 +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 7334360853; Thu, 19 Nov 2020 16:26:38 +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 3A2D350030; Thu, 19 Nov 2020 16:26:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0AJGQWE1030648 for ; Thu, 19 Nov 2020 11:26:32 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7C79B5C1B4; Thu, 19 Nov 2020 16:26:32 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 928785C1A1; Thu, 19 Nov 2020 16:26:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605803210; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=8KDDTsyfVkWUwk0KlIiiKN/4z6aPmpItmdbPSXq8hik=; b=RfyqKywbzb3mGXlfPhq2USMVAuDBgO+4g3xveiFjHxLMhmkAQUwIhiVNQ+uSNZb6+IlY4e BrRIen+FE/eRtouvCxQ/N4gV+UccghAZmRENp28uXc/PHYseO2i/fDvJzIWPDm4z9Qs2a1 mAwbLGi33h+ptdXqqI2/YrbDYKK6ABg= X-MC-Unique: FweIGQhZOxuF2IjDdOhhrQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 03/16] virsh: cmdAttachDisk: Use automatic memory clearing for 'xml' and 'dom' Date: Thu, 19 Nov 2020 17:26:09 +0100 Message-Id: <889844d2eb60c67cd8dd5398136abbc1d7ee4493.1605802531.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Ryan Gahagan 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.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: Daniel Henrique Barboza --- tools/virsh-domain.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index e27b779533..42a255cd6d 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -561,7 +561,7 @@ static int str2DiskAddress(const char *str, struct Disk= Address *diskAddr) static bool cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom =3D NULL; + g_autoptr(virshDomain) dom =3D NULL; const char *source =3D NULL; const char *target =3D NULL; const char *driver =3D NULL; @@ -583,7 +583,7 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) unsigned int flags =3D VIR_DOMAIN_AFFECT_CURRENT; const char *stype =3D NULL; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - char *xml =3D NULL; + g_autofree char *xml =3D NULL; struct stat st; bool current =3D vshCommandOptBool(cmd, "current"); bool config =3D vshCommandOptBool(cmd, "config"); @@ -783,8 +783,6 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) } cleanup: - VIR_FREE(xml); - virshDomainFree(dom); return functionReturn; } --=20 2.28.0 From nobody Fri Apr 26 13:02:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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=1605803210; cv=none; d=zohomail.com; s=zohoarc; b=ISEkrn3ue86IA+ysRmCuibzVMftNPbB4zZ8IdM7bykf7XvcnOI75ZhCIcLr+BW8nPRS8/qTLlx8qGOq3fVeVZEaz44+HlRQ17pmbBunIUqKY+MW5haicFJMmaEXVvBU7FFoK9Kkf/LhNl9Qkbns9CGD25m4YEiuyKglqXFo7RbU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605803210; h=Content-Type:Content-Transfer-Encoding:Cc: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=oJNYCQCGaSIDYBcZuN1dLsenNV/RLptsWn5okvdoo/M=; b=cW+oTxM3XFZWhT/ZrtWEK839XH7rKij6PbogYKpn/rYqZtIu0lswQRZjO+0HqbKRAJIIIRK8bt3kjxv/R7L/GNUDcdt4HhRdKIDSaVzoabhye3wzDoPwDKRDp6OkAGbDHLye4LxuMhQaFSQw7vr9f0cDS93Wo1E8qaYWh73t0jM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1605803210456937.3648949055494; Thu, 19 Nov 2020 08:26:50 -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-4-zwiftC0qNeiin12w9LRk_Q-1; Thu, 19 Nov 2020 11:26:45 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BCCD218C43C5; Thu, 19 Nov 2020 16:26:37 +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 9D68E60636; Thu, 19 Nov 2020 16:26:37 +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 69A861809CA1; Thu, 19 Nov 2020 16:26:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0AJGQXXA030671 for ; Thu, 19 Nov 2020 11:26:33 -0500 Received: by smtp.corp.redhat.com (Postfix) id DB2B25C1B4; Thu, 19 Nov 2020 16:26:33 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id F03255C1A1; Thu, 19 Nov 2020 16:26:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605803207; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=oJNYCQCGaSIDYBcZuN1dLsenNV/RLptsWn5okvdoo/M=; b=TB8MSR7MzRYcFxyfodOFijYX43eihVo6tfxXElTa0NExeWRCyTTGIHUsn2B6UKEehA0E8i IamdFlcz+oobp2+sdQ0xOCIfcZByRqMKDQ004DXmsdgytWdGLaI1IR3IBaZ+mFeBIfRcx6 fBn1SS94OWDyvL3jaF1VTizd02TFUR0= X-MC-Unique: zwiftC0qNeiin12w9LRk_Q-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 04/16] virsh: cmdAttachDisk: Refactor control flow Date: Thu, 19 Nov 2020 17:26:10 +0100 Message-Id: <6cae7cf854fd494fd3c1f005558dad979175293a.1605802531.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Ryan Gahagan 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.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Remove the unnecessary 'cleanup:' label since we can directly return as the memory clearing is now automated. We can also remove the 'functionReturn' variable and use the usual pattern of returning success. Signed-off-by: Peter Krempa Reviewed-by: Daniel Henrique Barboza --- tools/virsh-domain.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 42a255cd6d..2eaac9ad8c 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -578,7 +578,6 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) const char *alias =3D NULL; struct DiskAddress diskAddr; bool isFile =3D false; - bool functionReturn =3D false; int ret; unsigned int flags =3D VIR_DOMAIN_AFFECT_CURRENT; const char *stype =3D NULL; @@ -615,7 +614,7 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) vshCommandOptStringReq(ctl, cmd, "targetbus", &targetbus) < 0 || vshCommandOptStringReq(ctl, cmd, "alias", &alias) < 0 || vshCommandOptStringReq(ctl, cmd, "sourcetype", &stype) < 0) - goto cleanup; + return false; if (!stype) { if (driver && (STREQ(driver, "file") || STREQ(driver, "tap"))) { @@ -628,19 +627,19 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) isFile =3D true; } else if (STRNEQ(stype, "block")) { vshError(ctl, _("Unknown source type: '%s'"), stype); - goto cleanup; + return false; } if (mode) { if (STRNEQ(mode, "readonly") && STRNEQ(mode, "shareable")) { vshError(ctl, _("No support for %s in command 'attach-disk'"), mode); - goto cleanup; + return false; } } if (wwn && !virValidateWWN(wwn)) - goto cleanup; + return false; /* Make XML of disk */ virBufferAsprintf(&buf, " (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 160580321195158.57972564179977; Thu, 19 Nov 2020 08:26:51 -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-517-MoZqyJgtNbebY2lIgOcVqA-1; Thu, 19 Nov 2020 11:26:48 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B9752107AD30; Thu, 19 Nov 2020 16:26:41 +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 8E0065D6AC; Thu, 19 Nov 2020 16:26:41 +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 553FC1809CA6; Thu, 19 Nov 2020 16:26:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0AJGQZXj030684 for ; Thu, 19 Nov 2020 11:26:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id 64C8F5C1B4; Thu, 19 Nov 2020 16:26:35 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 57D5F5C1A1; Thu, 19 Nov 2020 16:26:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605803210; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=N+0gCq+UWeM4s/YPPOOf+3Q3T8oNR72YXw3waIOgewU=; b=T+9BaQ4sahGd8mtjFbY5cXcF6r7wOGoJO+z0jT1M9nK7Qzmw3p0z2HckuqBA/EPt89fU8R eMNDt8TAaHazj0H+mf2sbCxffgRg7cojGxufWtQiK2vybF/m6+4hYJURClqPJR1Hh5yWvg G4EFPmwSFLaAJ5KUSxMa46MiZkADwzo= X-MC-Unique: MoZqyJgtNbebY2lIgOcVqA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 05/16] virsh: cmdAttachDisk: Don't assume type='block' if file can't be examined Date: Thu, 19 Nov 2020 17:26:11 +0100 Message-Id: <68127809fef584e5e0f8a1a5b7a03f4f2ee5ca8a.1605802531.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Ryan Gahagan 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.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" 'virsh attach-disk' uses stat() to determine if the 'source' is a regular file. If stat fails though it assumes that the file is block. Since it's way more common to have regular files and the detection does not work at all when accessing a remote host, modify the default to assume type=3D'file' by default. Signed-off-by: Peter Krempa Reviewed-by: Daniel Henrique Barboza --- tests/virsh-output.out | 4 ++-- tools/virsh-domain.c | 30 +++++++++++++++++------------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/tests/virsh-output.out b/tests/virsh-output.out index 8fbe02a232..a93492e8f8 100644 --- a/tests/virsh-output.out +++ b/tests/virsh-output.out @@ -10,8 +10,8 @@ error: command 'attach-disk' requires option error: command 'attach-disk' requires option + attach_disk --target hda + ./virsh attach-disk --print-xml --domain testdom --target hda --source /= nonexistent/file - - + + diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 2eaac9ad8c..18e9ab0b46 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -577,7 +577,7 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) const char *targetbus =3D NULL; const char *alias =3D NULL; struct DiskAddress diskAddr; - bool isFile =3D false; + bool isBlock =3D false; int ret; unsigned int flags =3D VIR_DOMAIN_AFFECT_CURRENT; const char *stype =3D NULL; @@ -617,15 +617,15 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) return false; if (!stype) { - if (driver && (STREQ(driver, "file") || STREQ(driver, "tap"))) { - isFile =3D true; - } else { - if (source && !stat(source, &st)) - isFile =3D S_ISREG(st.st_mode) ? true : false; - } - } else if (STREQ(stype, "file")) { - isFile =3D true; - } else if (STRNEQ(stype, "block")) { + if (STRNEQ_NULLABLE(driver, "file") && + STRNEQ_NULLABLE(driver, "tap") && + source && + stat(source, &st) =3D=3D 0 && + S_ISBLK(st.st_mode)) + isBlock =3D true; + } else if (STREQ(stype, "block")) { + isBlock =3D true; + } else if (STRNEQ(stype, "file")) { vshError(ctl, _("Unknown source type: '%s'"), stype); return false; } @@ -642,8 +642,12 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) return false; /* Make XML of disk */ - virBufferAsprintf(&buf, "\n", - isFile ? "file" : "dev", source); + !isBlock ? "file" : "dev", source); virBufferAsprintf(&buf, " (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1605803215864972.9642387756008; Thu, 19 Nov 2020 08:26:55 -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-29-8kxO38efPdijHjS23iBMDg-1; Thu, 19 Nov 2020 11:26:52 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7BF24100C612; Thu, 19 Nov 2020 16:26:44 +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 59D775D9C6; Thu, 19 Nov 2020 16:26: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 2346450039; Thu, 19 Nov 2020 16:26:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0AJGQaHF030692 for ; Thu, 19 Nov 2020 11:26:36 -0500 Received: by smtp.corp.redhat.com (Postfix) id ACC3D5C1B4; Thu, 19 Nov 2020 16:26:36 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id CBD225C1A1; Thu, 19 Nov 2020 16:26:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605803214; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=Fft2mLR8qoEw9f4/SAqG1aq/TVj5rIOkWPkdHSUSYRw=; b=D15ynLJVUPXOqoHPiQI7cEKs5Y8FGWCK+MJ625PcPiTHST+fA12ZgeQxt24Bn97TOQM9Qf SrBnTNHknsasINojV+i3MjoeCvsqwU6MO6rg2wRuJGLmsnP7iINVOW2hHIveoU1mf05Iq8 TFhtrnR/ke+6ekcB83Opx3BW3ZsdFF8= X-MC-Unique: 8kxO38efPdijHjS23iBMDg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 06/16] virsh: cmdAttachDisk: Split out formatting of disk address Date: Thu, 19 Nov 2020 17:26:12 +0100 Message-Id: <1d84b7d3ee3d73eb340680535825bd1492a35ac3.1605802531.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Ryan Gahagan 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.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" First step is to remove all of the address handling code to a new function called 'cmdAttachDiskFormatAddress'. Signed-off-by: Peter Krempa Reviewed-by: Daniel Henrique Barboza --- tools/virsh-domain.c | 142 ++++++++++++++++++++++++------------------- 1 file changed, 79 insertions(+), 63 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 18e9ab0b46..84b8a6fb52 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -558,6 +558,81 @@ static int str2DiskAddress(const char *str, struct Dis= kAddress *diskAddr) return -1; } + +static int +cmdAttachDiskFormatAddress(vshControl *ctl, + virBufferPtr buf, + const char *straddr, + const char *target, + bool multifunction) +{ + struct DiskAddress diskAddr; + + if (str2DiskAddress(straddr, &diskAddr) !=3D 0) { + vshError(ctl, _("Invalid address.")); + return -1; + } + + if (STRPREFIX((const char *)target, "vd")) { + if (diskAddr.type =3D=3D DISK_ADDR_TYPE_PCI) { + virBufferAsprintf(buf, + "
\n"); + } else if (diskAddr.type =3D=3D DISK_ADDR_TYPE_CCW) { + virBufferAsprintf(buf, + "
\n", + diskAddr.addr.ccw.cssid, diskAddr.addr.ccw.s= sid, + diskAddr.addr.ccw.devno); + } else { + vshError(ctl, "%s", + _("expecting a pci:0000.00.00.00 or ccw:00.0.0000 add= ress.")); + return -1; + } + } else if (STRPREFIX((const char *)target, "sd")) { + if (diskAddr.type =3D=3D DISK_ADDR_TYPE_SCSI) { + virBufferAsprintf(buf, + "
\n", + diskAddr.addr.scsi.controller, diskAddr.addr= .scsi.bus, + diskAddr.addr.scsi.unit); + } else if (diskAddr.type =3D=3D DISK_ADDR_TYPE_USB) { + virBufferAsprintf(buf, + "
\n", + diskAddr.addr.usb.bus, diskAddr.addr.usb.por= t); + } else if (diskAddr.type =3D=3D DISK_ADDR_TYPE_SATA) { + virBufferAsprintf(buf, + "
\n", + diskAddr.addr.sata.controller, diskAddr.addr= .sata.bus, + diskAddr.addr.sata.unit); + } else { + vshError(ctl, "%s", + _("expecting a scsi:00.00.00 or usb:00.00 or sata:00.= 00.00 address.")); + return -1; + } + } else if (STRPREFIX((const char *)target, "hd")) { + if (diskAddr.type =3D=3D DISK_ADDR_TYPE_IDE) { + virBufferAsprintf(buf, + "
\n", + diskAddr.addr.ide.controller, diskAddr.addr.= ide.bus, + diskAddr.addr.ide.unit); + } else { + vshError(ctl, "%s", _("expecting an ide:00.00.00 address.")); + return -1; + } + } + + return 0; +} + + static bool cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) { @@ -576,7 +651,6 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) const char *wwn =3D NULL; const char *targetbus =3D NULL; const char *alias =3D NULL; - struct DiskAddress diskAddr; bool isBlock =3D false; int ret; unsigned int flags =3D VIR_DOMAIN_AFFECT_CURRENT; @@ -588,6 +662,7 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) bool config =3D vshCommandOptBool(cmd, "config"); bool live =3D vshCommandOptBool(cmd, "live"); bool persistent =3D vshCommandOptBool(cmd, "persistent"); + bool multifunction =3D vshCommandOptBool(cmd, "multifunction"); VSH_EXCLUSIVE_OPTIONS_VAR(persistent, current); @@ -692,68 +767,9 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) if (wwn) virBufferAsprintf(&buf, "%s\n", wwn); - if (straddr) { - if (str2DiskAddress(straddr, &diskAddr) !=3D 0) { - vshError(ctl, _("Invalid address.")); - return false; - } - - if (STRPREFIX((const char *)target, "vd")) { - if (diskAddr.type =3D=3D DISK_ADDR_TYPE_PCI) { - virBufferAsprintf(&buf, - "
\n"); - } else if (diskAddr.type =3D=3D DISK_ADDR_TYPE_CCW) { - virBufferAsprintf(&buf, - "
\n", - diskAddr.addr.ccw.cssid, diskAddr.addr.c= cw.ssid, - diskAddr.addr.ccw.devno); - } else { - vshError(ctl, "%s", - _("expecting a pci:0000.00.00.00 or ccw:00.0.0000= address.")); - return false; - } - } else if (STRPREFIX((const char *)target, "sd")) { - if (diskAddr.type =3D=3D DISK_ADDR_TYPE_SCSI) { - virBufferAsprintf(&buf, - "
\n", - diskAddr.addr.scsi.controller, diskAddr.= addr.scsi.bus, - diskAddr.addr.scsi.unit); - } else if (diskAddr.type =3D=3D DISK_ADDR_TYPE_USB) { - virBufferAsprintf(&buf, - "
\n", - diskAddr.addr.usb.bus, diskAddr.addr.usb= .port); - } else if (diskAddr.type =3D=3D DISK_ADDR_TYPE_SATA) { - virBufferAsprintf(&buf, - "
\n", - diskAddr.addr.sata.controller, diskAddr.= addr.sata.bus, - diskAddr.addr.sata.unit); - } else { - vshError(ctl, "%s", - _("expecting a scsi:00.00.00 or usb:00.00 or sata:00.00.00= address.")); - return false; - } - } else if (STRPREFIX((const char *)target, "hd")) { - if (diskAddr.type =3D=3D DISK_ADDR_TYPE_IDE) { - virBufferAsprintf(&buf, - "
\n", - diskAddr.addr.ide.controller, diskAddr.a= ddr.ide.bus, - diskAddr.addr.ide.unit); - } else { - vshError(ctl, "%s", _("expecting an ide:00.00.00 address."= )); - return false; - } - } - } + if (straddr && + cmdAttachDiskFormatAddress(ctl, &buf, straddr, target, multifuncti= on) < 0) + return false; virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "\n"); --=20 2.28.0 From nobody Fri Apr 26 13:02:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1605803296; cv=none; d=zohomail.com; s=zohoarc; b=cMny78R77T94aYFx9pmvNazE1Aq45iOKR0Iy8XKzL9istNP7xvaWUHnlYB61Jj5QQRM47DxmbU4S1MCw61jW5DXVDTzjMBLw2TAipNtz4BBNdqcAbQbfY6MFlQpRmXQf2QxN/L48VR5G3LOeZnw0HhMMkXbdh22LsnE2ou/Cquk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605803296; h=Content-Type:Content-Transfer-Encoding:Cc: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=+rluipugJN/dq3b1mw3Pot/62S0C276Q514Oa6Y/ito=; b=Z/8gpL1A1rbKqk45ImHP+d81/rNmPvMZrTMFe3bDXcmsxWnLlZvnfonwnZR4dpsy2wyJByv9FrtArG+uy88jakuDYQmTp70/y77N7ja0z1pUOPmO0752MrsXiegoOq0fDCtw6bvUYhZPBxWc0Izt5QSIWDF31Q54glO89moAEOs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1605803296845956.0183410255643; Thu, 19 Nov 2020 08:28:16 -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-329-YLD6ajrdNQ-UmJa1rivR-Q-1; Thu, 19 Nov 2020 11:26:53 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7B4318797DC; Thu, 19 Nov 2020 16:26:47 +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 590665D9C6; Thu, 19 Nov 2020 16:26:47 +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 254E25003D; Thu, 19 Nov 2020 16:26:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0AJGQcMs030702 for ; Thu, 19 Nov 2020 11:26:38 -0500 Received: by smtp.corp.redhat.com (Postfix) id 29FD75C1B4; Thu, 19 Nov 2020 16:26:38 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1C1605C1A1; Thu, 19 Nov 2020 16:26:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605803295; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=+rluipugJN/dq3b1mw3Pot/62S0C276Q514Oa6Y/ito=; b=epOvOv9qTUty7cNtD33ivyybHUdS8CIBX4hzKArrGnTe57RjpDGJ8gV/m3yfjtXmB3m7YC 7RyQ8ARt7AMbKNy5qKtuWRqxjSaJnhut0lkcwhahmc4MyUxYKReYrwXHETAyJeumB12BwL bfUCqRBPS5D8LqXiOyg+Ge0yLX8ThFQ= X-MC-Unique: YLD6ajrdNQ-UmJa1rivR-Q-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 07/16] virsh: Extract address formatting from cmdAttachDiskFormatAddress Date: Thu, 19 Nov 2020 17:26:13 +0100 Message-Id: <231acfd039260e3bd30cba9042e224331bc03f68.1605802531.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Ryan Gahagan 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.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Introduce virshAddressFormat with code from cmdAttachDiskFormatAddress to format the address. Note that this patch fixes some whitespace inconsistencies in the formatted addresses. Signed-off-by: Peter Krempa Reviewed-by: Daniel Henrique Barboza --- tests/virsh-output.out | 42 +++++++------- tools/virsh-domain.c | 122 ++++++++++++++++++++++++++--------------- 2 files changed, 99 insertions(+), 65 deletions(-) diff --git a/tests/virsh-output.out b/tests/virsh-output.out index a93492e8f8..6af7600a9c 100644 --- a/tests/virsh-output.out +++ b/tests/virsh-output.out @@ -182,7 +182,7 @@ error: No support for whatever in command 'attach-disk' -
+
+ attach_disk --target hda --sourcetype file --type disk --address ide:1.2= .4 @@ -190,7 +190,7 @@ error: No support for whatever in command 'attach-disk' -
+
+ attach_disk --target hda --sourcetype file --type disk --address ide:1:2= :5 @@ -198,7 +198,7 @@ error: No support for whatever in command 'attach-disk' -
+
+ attach_disk --target sda --sourcetype file --type disk --address ide:1.2= .3 @@ -214,7 +214,7 @@ error: expecting a pci:0000.00.00.00 or ccw:00.0.0000 a= ddress. -
+
+ attach_disk --target sda --sourcetype file --type disk --address usb:12.3 @@ -222,7 +222,7 @@ error: expecting a pci:0000.00.00.00 or ccw:00.0.0000 a= ddress. -
+
+ attach_disk --target sda --sourcetype file --type disk --address usb:12:= 34 @@ -230,7 +230,7 @@ error: expecting a pci:0000.00.00.00 or ccw:00.0.0000 a= ddress. -
+
+ attach_disk --target vda --sourcetype file --type disk --address usb:12.= 34 @@ -246,7 +246,7 @@ error: expecting an ide:00.00.00 address. -
+
+ attach_disk --target sda --sourcetype file --type disk --address scsi:1.= 2.4 @@ -254,7 +254,7 @@ error: expecting an ide:00.00.00 address. -
+
+ attach_disk --target sda --sourcetype file --type disk --address scsi:1:= 2:5 @@ -262,7 +262,7 @@ error: expecting an ide:00.00.00 address. -
+
+ attach_disk --target hda --sourcetype file --type disk --address scsi:1.= 2.3 @@ -278,7 +278,7 @@ error: expecting a pci:0000.00.00.00 or ccw:00.0.0000 a= ddress. -
+
+ attach_disk --target sda --sourcetype file --type disk --address sata:1.= 2.4 @@ -286,7 +286,7 @@ error: expecting a pci:0000.00.00.00 or ccw:00.0.0000 a= ddress. -
+
+ attach_disk --target sda --sourcetype file --type disk --address sata:1:= 2:5 @@ -294,7 +294,7 @@ error: expecting a pci:0000.00.00.00 or ccw:00.0.0000 a= ddress. -
+
+ attach_disk --target hda --sourcetype file --type disk --address sata:1.= 2.3 @@ -310,7 +310,7 @@ error: expecting a pci:0000.00.00.00 or ccw:00.0.0000 a= ddress. -
+
+ attach_disk --target vda --sourcetype file --type disk --address pci:12:= 34:56:78 @@ -318,7 +318,7 @@ error: expecting a pci:0000.00.00.00 or ccw:00.0.0000 a= ddress. -
+
+ attach_disk --target vda --sourcetype file --type disk --address pci:12.= 34.56.aa @@ -326,7 +326,7 @@ error: expecting a pci:0000.00.00.00 or ccw:00.0.0000 a= ddress. -
+
+ attach_disk --target hda --sourcetype file --type disk --address pci:12.= 34.56.aa @@ -342,7 +342,7 @@ error: expecting a scsi:00.00.00 or usb:00.00 or sata:0= 0.00.00 address. -
+
+ attach_disk --target vda --sourcetype file --type disk --address pci:12:= 34:56:78 --multifunction @@ -350,7 +350,7 @@ error: expecting a scsi:00.00.00 or usb:00.00 or sata:0= 0.00.00 address. -
+
+ attach_disk --target vda --sourcetype file --type disk --address pci:12.= 34.56.aa --multifunction @@ -358,7 +358,7 @@ error: expecting a scsi:00.00.00 or usb:00.00 or sata:0= 0.00.00 address. -
+
+ attach_disk --target vda --sourcetype file --type disk --address ccw:12.= 34.56 @@ -366,7 +366,7 @@ error: expecting a scsi:00.00.00 or usb:00.00 or sata:0= 0.00.00 address. -
+
+ attach_disk --target vda --sourcetype file --type disk --address ccw:12:= 34:56 @@ -374,7 +374,7 @@ error: expecting a scsi:00.00.00 or usb:00.00 or sata:0= 0.00.00 address. -
+
+ attach_disk --target vda --sourcetype file --type disk --address ccw:12.= 34.56 @@ -382,7 +382,7 @@ error: expecting a scsi:00.00.00 or usb:00.00 or sata:0= 0.00.00 address. -
+
+ attach_disk --target hda --sourcetype file --type disk --address ccw:12.= 34.56 diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 84b8a6fb52..e1a0b9087b 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -305,7 +305,7 @@ static const vshCmdOptDef opts_attach_disk[] =3D { {.name =3D NULL} }; -enum { +enum diskAddrType { DISK_ADDR_TYPE_INVALID, DISK_ADDR_TYPE_PCI, DISK_ADDR_TYPE_SCSI, @@ -320,6 +320,7 @@ struct PCIAddress { unsigned int bus; unsigned int slot; unsigned int function; + bool multifunction; }; struct SCSIAddress { @@ -521,7 +522,7 @@ static int str2SATAAddress(const char *str, struct SATA= Address *sataAddr) * sata disk address: sata:00.00.0 (controller:bus:unit) */ -static int str2DiskAddress(const char *str, struct DiskAddress *diskAddr) +static int str2DiskAddress(const char *str, struct DiskAddress *diskAddr, = bool multifunction) { char *type, *addr; @@ -537,6 +538,7 @@ static int str2DiskAddress(const char *str, struct Disk= Address *diskAddr) if (STREQLEN(type, "pci", addr - type)) { diskAddr->type =3D DISK_ADDR_TYPE_PCI; + diskAddr->addr.pci.multifunction =3D multifunction; return str2PCIAddress(addr + 1, &diskAddr->addr.pci); } else if (STREQLEN(type, "scsi", addr - type)) { diskAddr->type =3D DISK_ADDR_TYPE_SCSI; @@ -559,6 +561,71 @@ static int str2DiskAddress(const char *str, struct Dis= kAddress *diskAddr) } +static void +virshAddressFormat(virBufferPtr buf, + struct DiskAddress *addr) +{ + switch ((enum diskAddrType) addr->type) { + case DISK_ADDR_TYPE_PCI: + virBufferAsprintf(buf, + "
addr.pci.domain, + addr->addr.pci.bus, + addr->addr.pci.slot, + addr->addr.pci.function); + + if (addr->addr.pci.multifunction) + virBufferAddLit(buf, " multifunction=3D'on'"); + + virBufferAddLit(buf, "/>\n"); + break; + + case DISK_ADDR_TYPE_SCSI: + virBufferAsprintf(buf, + "
\n", + addr->addr.scsi.controller, + addr->addr.scsi.bus, + addr->addr.scsi.unit); + break; + + case DISK_ADDR_TYPE_IDE: + virBufferAsprintf(buf, + "
\n", + addr->addr.ide.controller, + addr->addr.ide.bus, + addr->addr.ide.unit); + break; + + case DISK_ADDR_TYPE_CCW: + virBufferAsprintf(buf, + "
\n", + addr->addr.ccw.cssid, + addr->addr.ccw.ssid, + addr->addr.ccw.devno); + break; + + case DISK_ADDR_TYPE_USB: + virBufferAsprintf(buf, + "
\= n", + addr->addr.usb.bus, + addr->addr.usb.port); + break; + + case DISK_ADDR_TYPE_SATA: + virBufferAsprintf(buf, + "
\n", + addr->addr.sata.controller, + addr->addr.sata.bus, + addr->addr.sata.unit); + break; + + case DISK_ADDR_TYPE_INVALID: + default: + return; + } +} + + static int cmdAttachDiskFormatAddress(vshControl *ctl, virBufferPtr buf, @@ -568,67 +635,34 @@ cmdAttachDiskFormatAddress(vshControl *ctl, { struct DiskAddress diskAddr; - if (str2DiskAddress(straddr, &diskAddr) !=3D 0) { + if (str2DiskAddress(straddr, &diskAddr, multifunction) !=3D 0) { vshError(ctl, _("Invalid address.")); return -1; } if (STRPREFIX((const char *)target, "vd")) { - if (diskAddr.type =3D=3D DISK_ADDR_TYPE_PCI) { - virBufferAsprintf(buf, - "
\n"); - } else if (diskAddr.type =3D=3D DISK_ADDR_TYPE_CCW) { - virBufferAsprintf(buf, - "
\n", - diskAddr.addr.ccw.cssid, diskAddr.addr.ccw.s= sid, - diskAddr.addr.ccw.devno); - } else { + if (diskAddr.type !=3D DISK_ADDR_TYPE_PCI && + diskAddr.type !=3D DISK_ADDR_TYPE_CCW) { vshError(ctl, "%s", _("expecting a pci:0000.00.00.00 or ccw:00.0.0000 add= ress.")); return -1; } } else if (STRPREFIX((const char *)target, "sd")) { - if (diskAddr.type =3D=3D DISK_ADDR_TYPE_SCSI) { - virBufferAsprintf(buf, - "
\n", - diskAddr.addr.scsi.controller, diskAddr.addr= .scsi.bus, - diskAddr.addr.scsi.unit); - } else if (diskAddr.type =3D=3D DISK_ADDR_TYPE_USB) { - virBufferAsprintf(buf, - "
\n", - diskAddr.addr.usb.bus, diskAddr.addr.usb.por= t); - } else if (diskAddr.type =3D=3D DISK_ADDR_TYPE_SATA) { - virBufferAsprintf(buf, - "
\n", - diskAddr.addr.sata.controller, diskAddr.addr= .sata.bus, - diskAddr.addr.sata.unit); - } else { + if (diskAddr.type !=3D DISK_ADDR_TYPE_SCSI && + diskAddr.type !=3D DISK_ADDR_TYPE_USB && + diskAddr.type !=3D DISK_ADDR_TYPE_SATA) { vshError(ctl, "%s", _("expecting a scsi:00.00.00 or usb:00.00 or sata:00.= 00.00 address.")); return -1; } } else if (STRPREFIX((const char *)target, "hd")) { - if (diskAddr.type =3D=3D DISK_ADDR_TYPE_IDE) { - virBufferAsprintf(buf, - "
\n", - diskAddr.addr.ide.controller, diskAddr.addr.= ide.bus, - diskAddr.addr.ide.unit); - } else { + if (diskAddr.type !=3D DISK_ADDR_TYPE_IDE) { vshError(ctl, "%s", _("expecting an ide:00.00.00 address.")); return -1; } } + virshAddressFormat(buf, &diskAddr); return 0; } @@ -1006,7 +1040,7 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd) break; case VIR_DOMAIN_NET_TYPE_HOSTDEV: { - struct PCIAddress pciAddr =3D {0, 0, 0, 0}; + struct PCIAddress pciAddr =3D {0, 0, 0, 0, false}; if (str2PCIAddress(source, &pciAddr) < 0) { vshError(ctl, _("cannot parse pci address '%s' for network " --=20 2.28.0 From nobody Fri Apr 26 13:02:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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=1605803211; cv=none; d=zohomail.com; s=zohoarc; b=eRfcWN4rVfWSX+SjjaTLoO+0nEtBw3Nbez7QJ67OWUE8G7Xc19bciG/30ZibEh7oz71ZeCr+tD+MCar7UKpV9C6S6WjvHVUgrLZ/7A0nXm7lyIeyNVTXWEFxKu6NLfqkxRBGbF0i/Yt0xTH22CYofSllFdip/FdfyujBnxBz3nI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605803211; h=Content-Type:Content-Transfer-Encoding:Cc: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=z4renasl/+NzNT36DJmWTWRfKNmq8huJtRzbpx9bn2U=; b=lk4HVOmTftPk8tAlshLoln7cIkvI2JDTdpm/P1sfLYIrvznGM8e47If4T7dq3zh2nVJ7386H3nPXp5aifZua3qTzK2qESCB1DDIdyq+JQZAX6FM25Og+5V2JLVEPJSizYDXe1JvKQkhJVXe1GCGEv0oe7RBBcStFp09ZUXVsUog= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1605803211509859.4673781313454; Thu, 19 Nov 2020 08:26:51 -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-286-v6IhL0dlNUCicMsCAP976Q-1; Thu, 19 Nov 2020 11:26:47 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C1851107ACFC; Thu, 19 Nov 2020 16:26:40 +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 9E5685D9C6; Thu, 19 Nov 2020 16:26:40 +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 651DD50033; Thu, 19 Nov 2020 16:26:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0AJGQdum030715 for ; Thu, 19 Nov 2020 11:26:39 -0500 Received: by smtp.corp.redhat.com (Postfix) id 671075C1B4; Thu, 19 Nov 2020 16:26:39 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8BD355C1A1; Thu, 19 Nov 2020 16:26:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605803210; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=z4renasl/+NzNT36DJmWTWRfKNmq8huJtRzbpx9bn2U=; b=ONspsGrb3vxhyWNf0pO4wquH+jadueWNRVhH07QLcXQOmK9qhC4LeFHMeH1QsmPEqKNNdJ RxVQ3gWddFIyofS7lsN+9HZL78RH9/dnYnzasM6gNX5YzeAbmhkQT0xgZrnZlf0YOcptzM cQuGZv9GhY/SNvWod+cxGEC4c+pJ7Dw= X-MC-Unique: v6IhL0dlNUCicMsCAP976Q-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 08/16] virsh: Unify code for
In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Ryan Gahagan 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.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" DISK_ADDR_TYPE_SATA, DISK_ADDR_TYPE_IDE and DISK_ADDR_TYPE_SCSI are driven by basically identical data types. Unify them. Note that changes to 'str2DiskAddress' are deliberately lazy as it will be refactored later. Signed-off-by: Peter Krempa Reviewed-by: Daniel Henrique Barboza --- tools/virsh-domain.c | 100 +++++-------------------------------------- 1 file changed, 11 insertions(+), 89 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index e1a0b9087b..942974fd39 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -323,18 +323,12 @@ struct PCIAddress { bool multifunction; }; -struct SCSIAddress { +struct DriveAddress { unsigned int controller; unsigned int bus; unsigned long long unit; }; -struct IDEAddress { - unsigned int controller; - unsigned int bus; - unsigned int unit; -}; - struct CCWAddress { unsigned int cssid; unsigned int ssid; @@ -346,21 +340,13 @@ struct USBAddress { unsigned int port; }; -struct SATAAddress { - unsigned int controller; - unsigned int bus; - unsigned long long unit; -}; - struct DiskAddress { int type; union { struct PCIAddress pci; - struct SCSIAddress scsi; - struct IDEAddress ide; + struct DriveAddress drive; struct CCWAddress ccw; struct USBAddress usb; - struct SATAAddress sata; } addr; }; @@ -393,7 +379,7 @@ static int str2PCIAddress(const char *str, struct PCIAd= dress *pciAddr) return 0; } -static int str2SCSIAddress(const char *str, struct SCSIAddress *scsiAddr) +static int str2DriveAddress(const char *str, struct DriveAddress *scsiAddr) { char *controller, *bus, *unit; @@ -418,31 +404,6 @@ static int str2SCSIAddress(const char *str, struct SCS= IAddress *scsiAddr) return 0; } -static int str2IDEAddress(const char *str, struct IDEAddress *ideAddr) -{ - char *controller, *bus, *unit; - - if (!ideAddr) - return -1; - if (!str) - return -1; - - controller =3D (char *)str; - - if (virStrToLong_uip(controller, &bus, 10, &ideAddr->controller) !=3D = 0) - return -1; - - bus++; - if (virStrToLong_uip(bus, &unit, 10, &ideAddr->bus) !=3D 0) - return -1; - - unit++; - if (virStrToLong_uip(unit, NULL, 10, &ideAddr->unit) !=3D 0) - return -1; - - return 0; -} - static int str2CCWAddress(const char *str, struct CCWAddress *ccwAddr) { char *cssid, *ssid, *devno; @@ -489,31 +450,6 @@ static int str2USBAddress(const char *str, struct USBA= ddress *usbAddr) return 0; } -static int str2SATAAddress(const char *str, struct SATAAddress *sataAddr) -{ - char *controller, *bus, *unit; - - if (!sataAddr) - return -1; - if (!str) - return -1; - - controller =3D (char *)str; - - if (virStrToLong_uip(controller, &bus, 10, &sataAddr->controller) !=3D= 0) - return -1; - - bus++; - if (virStrToLong_uip(bus, &unit, 10, &sataAddr->bus) !=3D 0) - return -1; - - unit++; - if (virStrToLong_ullp(unit, NULL, 10, &sataAddr->unit) !=3D 0) - return -1; - - return 0; -} - /* pci address pci:0000.00.0x0a.0 (domain:bus:slot:function) * ide disk address: ide:00.00.0 (controller:bus:unit) * scsi disk address: scsi:00.00.0 (controller:bus:unit) @@ -542,10 +478,10 @@ static int str2DiskAddress(const char *str, struct Di= skAddress *diskAddr, bool m return str2PCIAddress(addr + 1, &diskAddr->addr.pci); } else if (STREQLEN(type, "scsi", addr - type)) { diskAddr->type =3D DISK_ADDR_TYPE_SCSI; - return str2SCSIAddress(addr + 1, &diskAddr->addr.scsi); + return str2DriveAddress(addr + 1, &diskAddr->addr.drive); } else if (STREQLEN(type, "ide", addr - type)) { diskAddr->type =3D DISK_ADDR_TYPE_IDE; - return str2IDEAddress(addr + 1, &diskAddr->addr.ide); + return str2DriveAddress(addr + 1, &diskAddr->addr.drive); } else if (STREQLEN(type, "ccw", addr - type)) { diskAddr->type =3D DISK_ADDR_TYPE_CCW; return str2CCWAddress(addr + 1, &diskAddr->addr.ccw); @@ -554,7 +490,7 @@ static int str2DiskAddress(const char *str, struct Disk= Address *diskAddr, bool m return str2USBAddress(addr + 1, &diskAddr->addr.usb); } else if (STREQLEN(type, "sata", addr - type)) { diskAddr->type =3D DISK_ADDR_TYPE_SATA; - return str2SATAAddress(addr + 1, &diskAddr->addr.sata); + return str2DriveAddress(addr + 1, &diskAddr->addr.drive); } return -1; @@ -580,20 +516,14 @@ virshAddressFormat(virBufferPtr buf, virBufferAddLit(buf, "/>\n"); break; + case DISK_ADDR_TYPE_SATA: + case DISK_ADDR_TYPE_IDE: case DISK_ADDR_TYPE_SCSI: virBufferAsprintf(buf, "
\n", - addr->addr.scsi.controller, - addr->addr.scsi.bus, - addr->addr.scsi.unit); - break; - - case DISK_ADDR_TYPE_IDE: - virBufferAsprintf(buf, - "
\n", - addr->addr.ide.controller, - addr->addr.ide.bus, - addr->addr.ide.unit); + addr->addr.drive.controller, + addr->addr.drive.bus, + addr->addr.drive.unit); break; case DISK_ADDR_TYPE_CCW: @@ -611,14 +541,6 @@ virshAddressFormat(virBufferPtr buf, addr->addr.usb.port); break; - case DISK_ADDR_TYPE_SATA: - virBufferAsprintf(buf, - "
\n", - addr->addr.sata.controller, - addr->addr.sata.bus, - addr->addr.sata.unit); - break; - case DISK_ADDR_TYPE_INVALID: default: return; --=20 2.28.0 From nobody Fri Apr 26 13:02:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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=1605803216; cv=none; d=zohomail.com; s=zohoarc; b=a8FsAdMaUUKRwznvcjEE+vgNCBbLjBshXE1ydgs4XlN4FFAxMMbDmk9OeAmS/v3yNGPpozirdcG/HdJorPJ/BQrszNaVtVxeppjhNjqfGzgO3R+WcEIqkcxGK+xMhzLLA+A3AmNu7WZleXBYqwLMWo+LwiHXADnNZ+I9YRK5gkI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605803216; h=Content-Type:Content-Transfer-Encoding:Cc: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=c706uelbTC68AEgRcWrXU5tX6o+6sKcGnito3EEDCCs=; b=E7McPaFupROz7CstTJ1ONkOV071O0EyLYpOHqNrohU0NNs7ofoTq5tCUG+KIJArsfqXY3S/ybFfw6dueSUWtx/hh4ylu7witYzC6V9U/SiZ7/veRNjzj7b7NUOMKr+FCQGnFKQR9hk8mHPkVukoL7cLukTZPeF7qlO5ZylSrXcA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1605803216016770.027218002064; Thu, 19 Nov 2020 08:26:56 -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-234-Ljr0oh15MbSSUdWuXRBwUQ-1; Thu, 19 Nov 2020 11:26:51 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id EE5B6809AC7; Thu, 19 Nov 2020 16:26:43 +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 C256B19D7D; Thu, 19 Nov 2020 16:26:43 +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 8913150036; Thu, 19 Nov 2020 16:26:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0AJGQeqi030732 for ; Thu, 19 Nov 2020 11:26:40 -0500 Received: by smtp.corp.redhat.com (Postfix) id B7E285C1B4; Thu, 19 Nov 2020 16:26:40 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id CF7215C1A1; Thu, 19 Nov 2020 16:26:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605803213; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=c706uelbTC68AEgRcWrXU5tX6o+6sKcGnito3EEDCCs=; b=UesH2aF1fd1aLDoHCkUZXxd+/7AFoyTcsBVVaFwxqaSFAs5kauZfwVosqA+wAmX0+RGKU3 ZzjPrpBdN+BTh5xQuAYriQddC7loOkawKbAfMJ/pFmAhcJvQsXHQ74/kZWGknfC4L7ma6E b1SstMgavNhA6FVxpRwVU+5N7XKzZkY= X-MC-Unique: Ljr0oh15MbSSUdWuXRBwUQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 09/16] virsh: Refactor str2DiskAddress Date: Thu, 19 Nov 2020 17:26:15 +0100 Message-Id: <95b01b2761deec3810a7f955625a387cc488f349.1605802531.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Ryan Gahagan 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.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Rewrite and rename the address parser. As a fallout the use of the removed 'str2PCIAddress' is replaced by virshAddressParse and virshAddressFormat. Signed-off-by: Peter Krempa Reviewed-by: Daniel Henrique Barboza --- tools/virsh-domain.c | 207 ++++++++++++++----------------------------- 1 file changed, 67 insertions(+), 140 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 942974fd39..57b17f3b5c 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -306,15 +306,26 @@ static const vshCmdOptDef opts_attach_disk[] =3D { }; enum diskAddrType { - DISK_ADDR_TYPE_INVALID, DISK_ADDR_TYPE_PCI, DISK_ADDR_TYPE_SCSI, DISK_ADDR_TYPE_IDE, DISK_ADDR_TYPE_CCW, DISK_ADDR_TYPE_USB, DISK_ADDR_TYPE_SATA, + + DISK_ADDR_TYPE_LAST }; +VIR_ENUM_DECL(diskAddr); +VIR_ENUM_IMPL(diskAddr, + DISK_ADDR_TYPE_LAST, + "pci", + "scsi", + "ide", + "ccw", + "usb", + "sata"); + struct PCIAddress { unsigned int domain; unsigned int bus; @@ -350,105 +361,6 @@ struct DiskAddress { } addr; }; -static int str2PCIAddress(const char *str, struct PCIAddress *pciAddr) -{ - char *domain, *bus, *slot, *function; - - if (!pciAddr) - return -1; - if (!str) - return -1; - - domain =3D (char *)str; - - if (virStrToLong_uip(domain, &bus, 16, &pciAddr->domain) !=3D 0) - return -1; - - bus++; - if (virStrToLong_uip(bus, &slot, 16, &pciAddr->bus) !=3D 0) - return -1; - - slot++; - if (virStrToLong_uip(slot, &function, 16, &pciAddr->slot) !=3D 0) - return -1; - - function++; - if (virStrToLong_uip(function, NULL, 16, &pciAddr->function) !=3D 0) - return -1; - - return 0; -} - -static int str2DriveAddress(const char *str, struct DriveAddress *scsiAddr) -{ - char *controller, *bus, *unit; - - if (!scsiAddr) - return -1; - if (!str) - return -1; - - controller =3D (char *)str; - - if (virStrToLong_uip(controller, &bus, 10, &scsiAddr->controller) !=3D= 0) - return -1; - - bus++; - if (virStrToLong_uip(bus, &unit, 10, &scsiAddr->bus) !=3D 0) - return -1; - - unit++; - if (virStrToLong_ullp(unit, NULL, 10, &scsiAddr->unit) !=3D 0) - return -1; - - return 0; -} - -static int str2CCWAddress(const char *str, struct CCWAddress *ccwAddr) -{ - char *cssid, *ssid, *devno; - - if (!ccwAddr) - return -1; - if (!str) - return -1; - - cssid =3D (char *)str; - - if (virStrToLong_uip(cssid, &ssid, 16, &ccwAddr->cssid) !=3D 0) - return -1; - - ssid++; - if (virStrToLong_uip(ssid, &devno, 16, &ccwAddr->ssid) !=3D 0) - return -1; - - devno++; - if (virStrToLong_uip(devno, NULL, 16, &ccwAddr->devno) !=3D 0) - return -1; - - return 0; -} - -static int str2USBAddress(const char *str, struct USBAddress *usbAddr) -{ - char *bus, *port; - - if (!usbAddr) - return -1; - if (!str) - return -1; - - bus =3D (char *)str; - - if (virStrToLong_uip(bus, &port, 10, &usbAddr->bus) !=3D 0) - return -1; - - port++; - if (virStrToLong_uip(port, NULL, 10, &usbAddr->port) !=3D 0) - return -1; - - return 0; -} /* pci address pci:0000.00.0x0a.0 (domain:bus:slot:function) * ide disk address: ide:00.00.0 (controller:bus:unit) @@ -457,43 +369,60 @@ static int str2USBAddress(const char *str, struct USB= Address *usbAddr) * usb disk address: usb:00.00 (bus:port) * sata disk address: sata:00.00.0 (controller:bus:unit) */ - -static int str2DiskAddress(const char *str, struct DiskAddress *diskAddr, = bool multifunction) +static int +virshAddressParse(const char *str, + bool multifunction, + struct DiskAddress *addr) { - char *type, *addr; + g_autofree char *type =3D g_strdup(str); + char *a =3D strchr(type, ':'); - if (!diskAddr) - return -1; - if (!str) - return -1; - - type =3D (char *)str; - addr =3D strchr(type, ':'); if (!addr) return -1; - if (STREQLEN(type, "pci", addr - type)) { - diskAddr->type =3D DISK_ADDR_TYPE_PCI; - diskAddr->addr.pci.multifunction =3D multifunction; - return str2PCIAddress(addr + 1, &diskAddr->addr.pci); - } else if (STREQLEN(type, "scsi", addr - type)) { - diskAddr->type =3D DISK_ADDR_TYPE_SCSI; - return str2DriveAddress(addr + 1, &diskAddr->addr.drive); - } else if (STREQLEN(type, "ide", addr - type)) { - diskAddr->type =3D DISK_ADDR_TYPE_IDE; - return str2DriveAddress(addr + 1, &diskAddr->addr.drive); - } else if (STREQLEN(type, "ccw", addr - type)) { - diskAddr->type =3D DISK_ADDR_TYPE_CCW; - return str2CCWAddress(addr + 1, &diskAddr->addr.ccw); - } else if (STREQLEN(type, "usb", addr - type)) { - diskAddr->type =3D DISK_ADDR_TYPE_USB; - return str2USBAddress(addr + 1, &diskAddr->addr.usb); - } else if (STREQLEN(type, "sata", addr - type)) { - diskAddr->type =3D DISK_ADDR_TYPE_SATA; - return str2DriveAddress(addr + 1, &diskAddr->addr.drive); + *a =3D '\0'; + + addr->type =3D diskAddrTypeFromString(type); + + switch ((enum diskAddrType) addr->type) { + case DISK_ADDR_TYPE_PCI: + addr->addr.pci.multifunction =3D multifunction; + + if (virStrToLong_uip(++a, &a, 16, &addr->addr.pci.domain) < 0 || + virStrToLong_uip(++a, &a, 16, &addr->addr.pci.bus) < 0 || + virStrToLong_uip(++a, &a, 16, &addr->addr.pci.slot) < 0 || + virStrToLong_uip(++a, &a, 16, &addr->addr.pci.function) < 0) + return -1; + break; + + case DISK_ADDR_TYPE_SATA: + case DISK_ADDR_TYPE_IDE: + case DISK_ADDR_TYPE_SCSI: + if (virStrToLong_uip(++a, &a, 10, &addr->addr.drive.controller) < = 0 || + virStrToLong_uip(++a, &a, 10, &addr->addr.drive.bus) < 0 || + virStrToLong_ullp(++a, &a, 10, &addr->addr.drive.unit) < 0) + return -1; + break; + + case DISK_ADDR_TYPE_CCW: + if (virStrToLong_uip(++a, &a, 16, &addr->addr.ccw.cssid) < 0 || + virStrToLong_uip(++a, &a, 16, &addr->addr.ccw.ssid) < 0 || + virStrToLong_uip(++a, &a, 16, &addr->addr.ccw.devno) < 0) + return -1; + break; + + case DISK_ADDR_TYPE_USB: + if (virStrToLong_uip(++a, &a, 10, &addr->addr.usb.bus) < 0 || + virStrToLong_uip(++a, &a, 10, &addr->addr.usb.port) < 0) + return -1; + break; + + case DISK_ADDR_TYPE_LAST: + default: + return -1; } - return -1; + return 0; } @@ -541,7 +470,7 @@ virshAddressFormat(virBufferPtr buf, addr->addr.usb.port); break; - case DISK_ADDR_TYPE_INVALID: + case DISK_ADDR_TYPE_LAST: default: return; } @@ -557,7 +486,7 @@ cmdAttachDiskFormatAddress(vshControl *ctl, { struct DiskAddress diskAddr; - if (str2DiskAddress(straddr, &diskAddr, multifunction) !=3D 0) { + if (virshAddressParse(straddr, multifunction, &diskAddr) < 0) { vshError(ctl, _("Invalid address.")); return -1; } @@ -962,20 +891,18 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd) break; case VIR_DOMAIN_NET_TYPE_HOSTDEV: { - struct PCIAddress pciAddr =3D {0, 0, 0, 0, false}; + g_autofree char *pciaddrstr =3D g_strdup_printf("pci:%s", source); + struct DiskAddress addr =3D { 0 }; - if (str2PCIAddress(source, &pciAddr) < 0) { - vshError(ctl, _("cannot parse pci address '%s' for network " - "interface"), source); + if (virshAddressParse(pciaddrstr, false, &addr) < 0) { + vshError(ctl, _("cannot parse pci address '%s' for network int= erface"), + source); goto cleanup; } virBufferAddLit(&buf, "\n"); virBufferAdjustIndent(&buf, 2); - virBufferAsprintf(&buf, "
\n", - pciAddr.domain, pciAddr.bus, - pciAddr.slot, pciAddr.function); + virshAddressFormat(&buf, &addr); virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "\n"); break; --=20 2.28.0 From nobody Fri Apr 26 13:02:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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=1605803220; cv=none; d=zohomail.com; s=zohoarc; b=ndCYh3ZN/C7x8b3VjioG/Ehsb1hayUXWbe1Kl3p+kfAMgbZ74lUNZny7G7GHeVNDywQdnUij9P3FU6PqRvr3v3FhAz93ppD5JFbSSwnq6btFBfzZDhEAIVHCIihubArG4Ad+i2nqtf2so7IEe8LWeHdXlUksXKKuaOUBxrTYEQk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605803220; h=Content-Type:Content-Transfer-Encoding:Cc: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=Uuav3vBKW8tVSPUP8DmfAYb7k7LnHOs4ncffJYOZxOg=; b=dfS8ZQMR5O8bUOSKONqDDKyVBiCd6tmbU930px6NivPowXCqYIuPMFGrZBeAHokqHsjbB/cQiek8QjzmC/tywyc6kzNKfA3fYVEhtNnY4eFYTf+YTCPEALXD0MmlUTHT12q7EOKS87a3LZcOpHSSekYdBvMGLkzYEln5m5ootps= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1605803220369791.3823351332046; Thu, 19 Nov 2020 08:27:00 -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-198-voQ8L34SMPG3CWyH6GRWzA-1; Thu, 19 Nov 2020 11:26:56 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F2B87100C608; Thu, 19 Nov 2020 16:26:49 +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 CD8525D9DB; Thu, 19 Nov 2020 16:26:49 +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 8C2FF5003F; Thu, 19 Nov 2020 16:26:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0AJGQlWI030779 for ; Thu, 19 Nov 2020 11:26:47 -0500 Received: by smtp.corp.redhat.com (Postfix) id ED1E85C1A1; Thu, 19 Nov 2020 16:26:47 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 162755C1D1; Thu, 19 Nov 2020 16:26:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605803218; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=Uuav3vBKW8tVSPUP8DmfAYb7k7LnHOs4ncffJYOZxOg=; b=S6h9SbJhU7EGfeY6j2cn790Z5gyMLn9BDpjQBbGd5tPWRO50rkYrDXO035J8u4r4t70yOT yVzIl1QHqvwMgBX/7WvxD64WmAgmKq4afcGYyMWYn/PWhszXA8IOQLUKDpHo6V7G8JrT+X wOzaA5AUVVnENSKHoTG3aLvhbloPn3k= X-MC-Unique: voQ8L34SMPG3CWyH6GRWzA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 10/16] virsh: Rename 'struct DiskAddress' and friends Date: Thu, 19 Nov 2020 17:26:16 +0100 Message-Id: <5d0a4b16927e1f249966096a7b42835da8b277e6.1605802531.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Ryan Gahagan 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.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Use 'virshAddress' prefix for all the related structs and enums. Signed-off-by: Peter Krempa Reviewed-by: Daniel Henrique Barboza --- tools/virsh-domain.c | 96 ++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 57b17f3b5c..afb859eaa0 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -305,20 +305,20 @@ static const vshCmdOptDef opts_attach_disk[] =3D { {.name =3D NULL} }; -enum diskAddrType { - DISK_ADDR_TYPE_PCI, - DISK_ADDR_TYPE_SCSI, - DISK_ADDR_TYPE_IDE, - DISK_ADDR_TYPE_CCW, - DISK_ADDR_TYPE_USB, - DISK_ADDR_TYPE_SATA, +enum virshAddressType { + VIRSH_ADDRESS_TYPE_PCI, + VIRSH_ADDRESS_TYPE_SCSI, + VIRSH_ADDRESS_TYPE_IDE, + VIRSH_ADDRESS_TYPE_CCW, + VIRSH_ADDRESS_TYPE_USB, + VIRSH_ADDRESS_TYPE_SATA, - DISK_ADDR_TYPE_LAST + VIRSH_ADDRESS_TYPE_LAST }; -VIR_ENUM_DECL(diskAddr); -VIR_ENUM_IMPL(diskAddr, - DISK_ADDR_TYPE_LAST, +VIR_ENUM_DECL(virshAddress); +VIR_ENUM_IMPL(virshAddress, + VIRSH_ADDRESS_TYPE_LAST, "pci", "scsi", "ide", @@ -326,7 +326,7 @@ VIR_ENUM_IMPL(diskAddr, "usb", "sata"); -struct PCIAddress { +struct virshAddressPCI { unsigned int domain; unsigned int bus; unsigned int slot; @@ -334,30 +334,30 @@ struct PCIAddress { bool multifunction; }; -struct DriveAddress { +struct virshAddressDrive { unsigned int controller; unsigned int bus; unsigned long long unit; }; -struct CCWAddress { +struct virshAddressCCW { unsigned int cssid; unsigned int ssid; unsigned int devno; }; -struct USBAddress { +struct virshAddressUSB { unsigned int bus; unsigned int port; }; -struct DiskAddress { - int type; +struct virshAddress { + int type; /* enum virshAddressType */ union { - struct PCIAddress pci; - struct DriveAddress drive; - struct CCWAddress ccw; - struct USBAddress usb; + struct virshAddressPCI pci; + struct virshAddressDrive drive; + struct virshAddressCCW ccw; + struct virshAddressUSB usb; } addr; }; @@ -372,7 +372,7 @@ struct DiskAddress { static int virshAddressParse(const char *str, bool multifunction, - struct DiskAddress *addr) + struct virshAddress *addr) { g_autofree char *type =3D g_strdup(str); char *a =3D strchr(type, ':'); @@ -382,10 +382,10 @@ virshAddressParse(const char *str, *a =3D '\0'; - addr->type =3D diskAddrTypeFromString(type); + addr->type =3D virshAddressTypeFromString(type); - switch ((enum diskAddrType) addr->type) { - case DISK_ADDR_TYPE_PCI: + switch ((enum virshAddressType) addr->type) { + case VIRSH_ADDRESS_TYPE_PCI: addr->addr.pci.multifunction =3D multifunction; if (virStrToLong_uip(++a, &a, 16, &addr->addr.pci.domain) < 0 || @@ -395,29 +395,29 @@ virshAddressParse(const char *str, return -1; break; - case DISK_ADDR_TYPE_SATA: - case DISK_ADDR_TYPE_IDE: - case DISK_ADDR_TYPE_SCSI: + case VIRSH_ADDRESS_TYPE_SATA: + case VIRSH_ADDRESS_TYPE_IDE: + case VIRSH_ADDRESS_TYPE_SCSI: if (virStrToLong_uip(++a, &a, 10, &addr->addr.drive.controller) < = 0 || virStrToLong_uip(++a, &a, 10, &addr->addr.drive.bus) < 0 || virStrToLong_ullp(++a, &a, 10, &addr->addr.drive.unit) < 0) return -1; break; - case DISK_ADDR_TYPE_CCW: + case VIRSH_ADDRESS_TYPE_CCW: if (virStrToLong_uip(++a, &a, 16, &addr->addr.ccw.cssid) < 0 || virStrToLong_uip(++a, &a, 16, &addr->addr.ccw.ssid) < 0 || virStrToLong_uip(++a, &a, 16, &addr->addr.ccw.devno) < 0) return -1; break; - case DISK_ADDR_TYPE_USB: + case VIRSH_ADDRESS_TYPE_USB: if (virStrToLong_uip(++a, &a, 10, &addr->addr.usb.bus) < 0 || virStrToLong_uip(++a, &a, 10, &addr->addr.usb.port) < 0) return -1; break; - case DISK_ADDR_TYPE_LAST: + case VIRSH_ADDRESS_TYPE_LAST: default: return -1; } @@ -428,10 +428,10 @@ virshAddressParse(const char *str, static void virshAddressFormat(virBufferPtr buf, - struct DiskAddress *addr) + struct virshAddress *addr) { - switch ((enum diskAddrType) addr->type) { - case DISK_ADDR_TYPE_PCI: + switch ((enum virshAddressType) addr->type) { + case VIRSH_ADDRESS_TYPE_PCI: virBufferAsprintf(buf, "
addr.pci.domain, @@ -445,9 +445,9 @@ virshAddressFormat(virBufferPtr buf, virBufferAddLit(buf, "/>\n"); break; - case DISK_ADDR_TYPE_SATA: - case DISK_ADDR_TYPE_IDE: - case DISK_ADDR_TYPE_SCSI: + case VIRSH_ADDRESS_TYPE_SATA: + case VIRSH_ADDRESS_TYPE_IDE: + case VIRSH_ADDRESS_TYPE_SCSI: virBufferAsprintf(buf, "
\n", addr->addr.drive.controller, @@ -455,7 +455,7 @@ virshAddressFormat(virBufferPtr buf, addr->addr.drive.unit); break; - case DISK_ADDR_TYPE_CCW: + case VIRSH_ADDRESS_TYPE_CCW: virBufferAsprintf(buf, "
\n", addr->addr.ccw.cssid, @@ -463,14 +463,14 @@ virshAddressFormat(virBufferPtr buf, addr->addr.ccw.devno); break; - case DISK_ADDR_TYPE_USB: + case VIRSH_ADDRESS_TYPE_USB: virBufferAsprintf(buf, "
\= n", addr->addr.usb.bus, addr->addr.usb.port); break; - case DISK_ADDR_TYPE_LAST: + case VIRSH_ADDRESS_TYPE_LAST: default: return; } @@ -484,7 +484,7 @@ cmdAttachDiskFormatAddress(vshControl *ctl, const char *target, bool multifunction) { - struct DiskAddress diskAddr; + struct virshAddress diskAddr; if (virshAddressParse(straddr, multifunction, &diskAddr) < 0) { vshError(ctl, _("Invalid address.")); @@ -492,22 +492,22 @@ cmdAttachDiskFormatAddress(vshControl *ctl, } if (STRPREFIX((const char *)target, "vd")) { - if (diskAddr.type !=3D DISK_ADDR_TYPE_PCI && - diskAddr.type !=3D DISK_ADDR_TYPE_CCW) { + if (diskAddr.type !=3D VIRSH_ADDRESS_TYPE_PCI && + diskAddr.type !=3D VIRSH_ADDRESS_TYPE_CCW) { vshError(ctl, "%s", _("expecting a pci:0000.00.00.00 or ccw:00.0.0000 add= ress.")); return -1; } } else if (STRPREFIX((const char *)target, "sd")) { - if (diskAddr.type !=3D DISK_ADDR_TYPE_SCSI && - diskAddr.type !=3D DISK_ADDR_TYPE_USB && - diskAddr.type !=3D DISK_ADDR_TYPE_SATA) { + if (diskAddr.type !=3D VIRSH_ADDRESS_TYPE_SCSI && + diskAddr.type !=3D VIRSH_ADDRESS_TYPE_USB && + diskAddr.type !=3D VIRSH_ADDRESS_TYPE_SATA) { vshError(ctl, "%s", _("expecting a scsi:00.00.00 or usb:00.00 or sata:00.= 00.00 address.")); return -1; } } else if (STRPREFIX((const char *)target, "hd")) { - if (diskAddr.type !=3D DISK_ADDR_TYPE_IDE) { + if (diskAddr.type !=3D VIRSH_ADDRESS_TYPE_IDE) { vshError(ctl, "%s", _("expecting an ide:00.00.00 address.")); return -1; } @@ -892,7 +892,7 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd) case VIR_DOMAIN_NET_TYPE_HOSTDEV: { g_autofree char *pciaddrstr =3D g_strdup_printf("pci:%s", source); - struct DiskAddress addr =3D { 0 }; + struct virshAddress addr =3D { 0 }; if (virshAddressParse(pciaddrstr, false, &addr) < 0) { vshError(ctl, _("cannot parse pci address '%s' for network int= erface"), --=20 2.28.0 From nobody Fri Apr 26 13:02:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1605803224; cv=none; d=zohomail.com; s=zohoarc; b=QuYj3dhkrbfchwhP/SQ8WM22WzD0QC0XbI9YE8byZEcu4wpCbqEoW0HfCN/uKL/iOVGPCvaaZa9ptmAf7DO6iyN+hDqJuJBq/pOuO+Hl9kgJrgcE8FS9vpixjCDeYJXFuKn7yge4otZyJaO++8onyHgxYhLJrOcNXaNFrFciGUs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605803224; h=Content-Type:Content-Transfer-Encoding:Cc: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=TayXcR0Hl5pP6sP0Ek/wUbYXhD0sqmfhWJ2vKwrBUK0=; b=bwh0msvARrveqW7MeJXKa/rZykSy8/tDwY1IplqlcgZNcLKhzQ3OpVwqEduerVOfwbPfavUaLmeP1cmOvPn5o0ovxFum4KQ8YJ7iXUaBJWj9Q3FX1u/vAYRgNuYm7U64V/CDqD6LMWYJKiIgBIaKmXilDOWxkbViFn0MfI9kenI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1605803224259122.05721842904222; Thu, 19 Nov 2020 08:27:04 -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-25--b_mLI1FNVet75i_z1zkQQ-1; Thu, 19 Nov 2020 11:26:59 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CF725814411; Thu, 19 Nov 2020 16:26:52 +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 9C73C5D6AC; Thu, 19 Nov 2020 16:26:52 +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 6427B1809CA9; Thu, 19 Nov 2020 16:26:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0AJGQnuw030789 for ; Thu, 19 Nov 2020 11:26:49 -0500 Received: by smtp.corp.redhat.com (Postfix) id 49BA95C1D1; Thu, 19 Nov 2020 16:26:49 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 63F2F5C1A1; Thu, 19 Nov 2020 16:26:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605803223; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=TayXcR0Hl5pP6sP0Ek/wUbYXhD0sqmfhWJ2vKwrBUK0=; b=AtDDMl499dVpcIR7vSYT7i4dbjEl8uzoa8IXPA5WuR7cE0KUZA5KKfpvWKukeG4RRe2ENC bOEMFRzyW0sLNsHwSE6i849DKxHjXYWHbMaqm/Vck3TJjhzY79i4Q56FOHB0ubadalE8KP beYFthUgrEGUJpPAq1f/HyVE2DFctrc= X-MC-Unique: -b_mLI1FNVet75i_z1zkQQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 11/16] virsh: virshAddress*: Move out of cmdAttachDisk block Date: Thu, 19 Nov 2020 17:26:17 +0100 Message-Id: <35ee6ffa0181da2cce32bea5e58b7166664828eb.1605802531.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Ryan Gahagan 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.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The helper started as helper for cmdAttachDisk but is now used outside of it too. Signed-off-by: Peter Krempa Reviewed-by: Daniel Henrique Barboza --- tools/virsh-domain.c | 343 ++++++++++++++++++++++--------------------- 1 file changed, 172 insertions(+), 171 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index afb859eaa0..f8d97593b8 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -52,6 +52,178 @@ #include "virenum.h" #include "virutil.h" +enum virshAddressType { + VIRSH_ADDRESS_TYPE_PCI, + VIRSH_ADDRESS_TYPE_SCSI, + VIRSH_ADDRESS_TYPE_IDE, + VIRSH_ADDRESS_TYPE_CCW, + VIRSH_ADDRESS_TYPE_USB, + VIRSH_ADDRESS_TYPE_SATA, + + VIRSH_ADDRESS_TYPE_LAST +}; + +VIR_ENUM_DECL(virshAddress); +VIR_ENUM_IMPL(virshAddress, + VIRSH_ADDRESS_TYPE_LAST, + "pci", + "scsi", + "ide", + "ccw", + "usb", + "sata"); + +struct virshAddressPCI { + unsigned int domain; + unsigned int bus; + unsigned int slot; + unsigned int function; + bool multifunction; +}; + +struct virshAddressDrive { + unsigned int controller; + unsigned int bus; + unsigned long long unit; +}; + +struct virshAddressCCW { + unsigned int cssid; + unsigned int ssid; + unsigned int devno; +}; + +struct virshAddressUSB { + unsigned int bus; + unsigned int port; +}; + +struct virshAddress { + int type; /* enum virshAddressType */ + union { + struct virshAddressPCI pci; + struct virshAddressDrive drive; + struct virshAddressCCW ccw; + struct virshAddressUSB usb; + } addr; +}; + + +/* pci address pci:0000.00.0x0a.0 (domain:bus:slot:function) + * ide disk address: ide:00.00.0 (controller:bus:unit) + * scsi disk address: scsi:00.00.0 (controller:bus:unit) + * ccw disk address: ccw:0xfe.0.0000 (cssid:ssid:devno) + * usb disk address: usb:00.00 (bus:port) + * sata disk address: sata:00.00.0 (controller:bus:unit) + */ +static int +virshAddressParse(const char *str, + bool multifunction, + struct virshAddress *addr) +{ + g_autofree char *type =3D g_strdup(str); + char *a =3D strchr(type, ':'); + + if (!addr) + return -1; + + *a =3D '\0'; + + addr->type =3D virshAddressTypeFromString(type); + + switch ((enum virshAddressType) addr->type) { + case VIRSH_ADDRESS_TYPE_PCI: + addr->addr.pci.multifunction =3D multifunction; + + if (virStrToLong_uip(++a, &a, 16, &addr->addr.pci.domain) < 0 || + virStrToLong_uip(++a, &a, 16, &addr->addr.pci.bus) < 0 || + virStrToLong_uip(++a, &a, 16, &addr->addr.pci.slot) < 0 || + virStrToLong_uip(++a, &a, 16, &addr->addr.pci.function) < 0) + return -1; + break; + + case VIRSH_ADDRESS_TYPE_SATA: + case VIRSH_ADDRESS_TYPE_IDE: + case VIRSH_ADDRESS_TYPE_SCSI: + if (virStrToLong_uip(++a, &a, 10, &addr->addr.drive.controller) < = 0 || + virStrToLong_uip(++a, &a, 10, &addr->addr.drive.bus) < 0 || + virStrToLong_ullp(++a, &a, 10, &addr->addr.drive.unit) < 0) + return -1; + break; + + case VIRSH_ADDRESS_TYPE_CCW: + if (virStrToLong_uip(++a, &a, 16, &addr->addr.ccw.cssid) < 0 || + virStrToLong_uip(++a, &a, 16, &addr->addr.ccw.ssid) < 0 || + virStrToLong_uip(++a, &a, 16, &addr->addr.ccw.devno) < 0) + return -1; + break; + + case VIRSH_ADDRESS_TYPE_USB: + if (virStrToLong_uip(++a, &a, 10, &addr->addr.usb.bus) < 0 || + virStrToLong_uip(++a, &a, 10, &addr->addr.usb.port) < 0) + return -1; + break; + + case VIRSH_ADDRESS_TYPE_LAST: + default: + return -1; + } + + return 0; +} + + +static void +virshAddressFormat(virBufferPtr buf, + struct virshAddress *addr) +{ + switch ((enum virshAddressType) addr->type) { + case VIRSH_ADDRESS_TYPE_PCI: + virBufferAsprintf(buf, + "
addr.pci.domain, + addr->addr.pci.bus, + addr->addr.pci.slot, + addr->addr.pci.function); + + if (addr->addr.pci.multifunction) + virBufferAddLit(buf, " multifunction=3D'on'"); + + virBufferAddLit(buf, "/>\n"); + break; + + case VIRSH_ADDRESS_TYPE_SATA: + case VIRSH_ADDRESS_TYPE_IDE: + case VIRSH_ADDRESS_TYPE_SCSI: + virBufferAsprintf(buf, + "
\n", + addr->addr.drive.controller, + addr->addr.drive.bus, + addr->addr.drive.unit); + break; + + case VIRSH_ADDRESS_TYPE_CCW: + virBufferAsprintf(buf, + "
\n", + addr->addr.ccw.cssid, + addr->addr.ccw.ssid, + addr->addr.ccw.devno); + break; + + case VIRSH_ADDRESS_TYPE_USB: + virBufferAsprintf(buf, + "
\= n", + addr->addr.usb.bus, + addr->addr.usb.port); + break; + + case VIRSH_ADDRESS_TYPE_LAST: + default: + return; + } +} + + #define VIRSH_COMMON_OPT_DOMAIN_PERSISTENT \ {.name =3D "persistent", \ .type =3D VSH_OT_BOOL, \ @@ -305,177 +477,6 @@ static const vshCmdOptDef opts_attach_disk[] =3D { {.name =3D NULL} }; -enum virshAddressType { - VIRSH_ADDRESS_TYPE_PCI, - VIRSH_ADDRESS_TYPE_SCSI, - VIRSH_ADDRESS_TYPE_IDE, - VIRSH_ADDRESS_TYPE_CCW, - VIRSH_ADDRESS_TYPE_USB, - VIRSH_ADDRESS_TYPE_SATA, - - VIRSH_ADDRESS_TYPE_LAST -}; - -VIR_ENUM_DECL(virshAddress); -VIR_ENUM_IMPL(virshAddress, - VIRSH_ADDRESS_TYPE_LAST, - "pci", - "scsi", - "ide", - "ccw", - "usb", - "sata"); - -struct virshAddressPCI { - unsigned int domain; - unsigned int bus; - unsigned int slot; - unsigned int function; - bool multifunction; -}; - -struct virshAddressDrive { - unsigned int controller; - unsigned int bus; - unsigned long long unit; -}; - -struct virshAddressCCW { - unsigned int cssid; - unsigned int ssid; - unsigned int devno; -}; - -struct virshAddressUSB { - unsigned int bus; - unsigned int port; -}; - -struct virshAddress { - int type; /* enum virshAddressType */ - union { - struct virshAddressPCI pci; - struct virshAddressDrive drive; - struct virshAddressCCW ccw; - struct virshAddressUSB usb; - } addr; -}; - - -/* pci address pci:0000.00.0x0a.0 (domain:bus:slot:function) - * ide disk address: ide:00.00.0 (controller:bus:unit) - * scsi disk address: scsi:00.00.0 (controller:bus:unit) - * ccw disk address: ccw:0xfe.0.0000 (cssid:ssid:devno) - * usb disk address: usb:00.00 (bus:port) - * sata disk address: sata:00.00.0 (controller:bus:unit) - */ -static int -virshAddressParse(const char *str, - bool multifunction, - struct virshAddress *addr) -{ - g_autofree char *type =3D g_strdup(str); - char *a =3D strchr(type, ':'); - - if (!addr) - return -1; - - *a =3D '\0'; - - addr->type =3D virshAddressTypeFromString(type); - - switch ((enum virshAddressType) addr->type) { - case VIRSH_ADDRESS_TYPE_PCI: - addr->addr.pci.multifunction =3D multifunction; - - if (virStrToLong_uip(++a, &a, 16, &addr->addr.pci.domain) < 0 || - virStrToLong_uip(++a, &a, 16, &addr->addr.pci.bus) < 0 || - virStrToLong_uip(++a, &a, 16, &addr->addr.pci.slot) < 0 || - virStrToLong_uip(++a, &a, 16, &addr->addr.pci.function) < 0) - return -1; - break; - - case VIRSH_ADDRESS_TYPE_SATA: - case VIRSH_ADDRESS_TYPE_IDE: - case VIRSH_ADDRESS_TYPE_SCSI: - if (virStrToLong_uip(++a, &a, 10, &addr->addr.drive.controller) < = 0 || - virStrToLong_uip(++a, &a, 10, &addr->addr.drive.bus) < 0 || - virStrToLong_ullp(++a, &a, 10, &addr->addr.drive.unit) < 0) - return -1; - break; - - case VIRSH_ADDRESS_TYPE_CCW: - if (virStrToLong_uip(++a, &a, 16, &addr->addr.ccw.cssid) < 0 || - virStrToLong_uip(++a, &a, 16, &addr->addr.ccw.ssid) < 0 || - virStrToLong_uip(++a, &a, 16, &addr->addr.ccw.devno) < 0) - return -1; - break; - - case VIRSH_ADDRESS_TYPE_USB: - if (virStrToLong_uip(++a, &a, 10, &addr->addr.usb.bus) < 0 || - virStrToLong_uip(++a, &a, 10, &addr->addr.usb.port) < 0) - return -1; - break; - - case VIRSH_ADDRESS_TYPE_LAST: - default: - return -1; - } - - return 0; -} - - -static void -virshAddressFormat(virBufferPtr buf, - struct virshAddress *addr) -{ - switch ((enum virshAddressType) addr->type) { - case VIRSH_ADDRESS_TYPE_PCI: - virBufferAsprintf(buf, - "
addr.pci.domain, - addr->addr.pci.bus, - addr->addr.pci.slot, - addr->addr.pci.function); - - if (addr->addr.pci.multifunction) - virBufferAddLit(buf, " multifunction=3D'on'"); - - virBufferAddLit(buf, "/>\n"); - break; - - case VIRSH_ADDRESS_TYPE_SATA: - case VIRSH_ADDRESS_TYPE_IDE: - case VIRSH_ADDRESS_TYPE_SCSI: - virBufferAsprintf(buf, - "
\n", - addr->addr.drive.controller, - addr->addr.drive.bus, - addr->addr.drive.unit); - break; - - case VIRSH_ADDRESS_TYPE_CCW: - virBufferAsprintf(buf, - "
\n", - addr->addr.ccw.cssid, - addr->addr.ccw.ssid, - addr->addr.ccw.devno); - break; - - case VIRSH_ADDRESS_TYPE_USB: - virBufferAsprintf(buf, - "
\= n", - addr->addr.usb.bus, - addr->addr.usb.port); - break; - - case VIRSH_ADDRESS_TYPE_LAST: - default: - return; - } -} - static int cmdAttachDiskFormatAddress(vshControl *ctl, --=20 2.28.0 From nobody Fri Apr 26 13:02:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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=1605803223; cv=none; d=zohomail.com; s=zohoarc; b=ICIi+d4CEQVYLlm/FmpQboOeeUghzwjVuWKinNLiZaYntPBQ3V1QMDODCKmUcgAxaxDM2aIhYBLMBFXHFQz1DwBHtuSoWF3HwwiDK9ufHFHchF5vl7LD1jbM6bEWCc3yOpgkjS1NbYuX/HnEBv27ex1fzsTK7qForZmSgcr+kzo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605803223; h=Content-Type:Content-Transfer-Encoding:Cc: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=j7gz/Bolx0TilHaIn5BEPhi+dnJCdGSADIot8u5CBsU=; b=FixrPlCqIavEoBK/M72AVfOs3OaDyjbq9cmaJQF5rzfxXC1bcmLDsFQgI/lQ3QUsVZ+iohaWCD/c0K1+tFMhYqfWodFlEPavlxorAxqk3vCCGx67Chzcg2p6C9zyECq+9Wjg0RNh91WCOx1GP2B6mR+ykfcUxH09+pHBgXfq/BQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1605803223723254.39862909623332; Thu, 19 Nov 2020 08:27:03 -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-412-IYiH7z_9OiC5scoq4Vy4cg-1; Thu, 19 Nov 2020 11:27:00 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 95093801B1B; Thu, 19 Nov 2020 16:26:54 +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 752FD60BE2; Thu, 19 Nov 2020 16:26:54 +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 3F78C5003E; Thu, 19 Nov 2020 16:26:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0AJGQofR030805 for ; Thu, 19 Nov 2020 11:26:50 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8EF685C1A1; Thu, 19 Nov 2020 16:26:50 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id B4FCA5C1D1; Thu, 19 Nov 2020 16:26:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605803222; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=j7gz/Bolx0TilHaIn5BEPhi+dnJCdGSADIot8u5CBsU=; b=BtRcT1WeHzEFnGVCoVaWL1NHrPWNMhxwgisTYdwh19Yy/VkC/0lUPJKfP2VzMeluE5AobW bMP+oBXn9hO3ceTzdMJbuP45xCWoRPckbf2l+s+uUJvoxanNw5Y06KDfqfasOy0Heo40Yt 5ZrbtAnvFuiFVhmDiom6dacKnlhL9e0= X-MC-Unique: IYiH7z_9OiC5scoq4Vy4cg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 12/16] virsh: cmdAttachDisk: Use enum for disk source type Date: Thu, 19 Nov 2020 17:26:18 +0100 Message-Id: <1d083a1f8351c0315017470803ebc646734d85c1.1605802531.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Ryan Gahagan 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.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" For extendability and clarity add enum virshAttachDiskSourceType and use it to drive the XML formatting. Signed-off-by: Peter Krempa Reviewed-by: Daniel Henrique Barboza --- tools/virsh-domain.c | 68 +++++++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 20 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index f8d97593b8..5c7cb994f1 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -519,6 +519,22 @@ cmdAttachDiskFormatAddress(vshControl *ctl, } +enum virshAttachDiskSourceType { + VIRSH_ATTACH_DISK_SOURCE_TYPE_NONE, + VIRSH_ATTACH_DISK_SOURCE_TYPE_FILE, + VIRSH_ATTACH_DISK_SOURCE_TYPE_BLOCK, + + VIRSH_ATTACH_DISK_SOURCE_TYPE_LAST +}; + +VIR_ENUM_DECL(virshAttachDiskSource); +VIR_ENUM_IMPL(virshAttachDiskSource, + VIRSH_ATTACH_DISK_SOURCE_TYPE_LAST, + "", + "file", + "block"); + + static bool cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) { @@ -527,7 +543,7 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) const char *target =3D NULL; const char *driver =3D NULL; const char *subdriver =3D NULL; - const char *type =3D NULL; + const char *device =3D NULL; const char *mode =3D NULL; const char *iothread =3D NULL; const char *cache =3D NULL; @@ -537,10 +553,10 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) const char *wwn =3D NULL; const char *targetbus =3D NULL; const char *alias =3D NULL; - bool isBlock =3D false; int ret; unsigned int flags =3D VIR_DOMAIN_AFFECT_CURRENT; const char *stype =3D NULL; + int type =3D VIR_STORAGE_TYPE_NONE; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; g_autofree char *xml =3D NULL; struct stat st; @@ -564,7 +580,7 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) vshCommandOptStringReq(ctl, cmd, "target", &target) < 0 || vshCommandOptStringReq(ctl, cmd, "driver", &driver) < 0 || vshCommandOptStringReq(ctl, cmd, "subdriver", &subdriver) < 0 || - vshCommandOptStringReq(ctl, cmd, "type", &type) < 0 || + vshCommandOptStringReq(ctl, cmd, "type", &device) < 0 || vshCommandOptStringReq(ctl, cmd, "mode", &mode) < 0 || vshCommandOptStringReq(ctl, cmd, "iothread", &iothread) < 0 || vshCommandOptStringReq(ctl, cmd, "cache", &cache) < 0 || @@ -577,18 +593,22 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) vshCommandOptStringReq(ctl, cmd, "sourcetype", &stype) < 0) return false; - if (!stype) { + if (stype && + (type =3D virshAttachDiskSourceTypeFromString(stype)) < 0) { + vshError(ctl, _("Unknown source type: '%s'"), stype); + return false; + } + + if (type =3D=3D VIRSH_ATTACH_DISK_SOURCE_TYPE_NONE) { if (STRNEQ_NULLABLE(driver, "file") && STRNEQ_NULLABLE(driver, "tap") && source && stat(source, &st) =3D=3D 0 && - S_ISBLK(st.st_mode)) - isBlock =3D true; - } else if (STREQ(stype, "block")) { - isBlock =3D true; - } else if (STRNEQ(stype, "file")) { - vshError(ctl, _("Unknown source type: '%s'"), stype); - return false; + S_ISBLK(st.st_mode)) { + type =3D VIRSH_ATTACH_DISK_SOURCE_TYPE_BLOCK; + } else { + type =3D VIRSH_ATTACH_DISK_SOURCE_TYPE_FILE; + } } if (mode) { @@ -604,13 +624,10 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) /* Make XML of disk */ virBufferAddLit(&buf, "\n"); @@ -633,9 +650,20 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) virBufferAddLit(&buf, "/>\n"); } - if (source) - virBufferAsprintf(&buf, "\n", - !isBlock ? "file" : "dev", source); + switch ((enum virshAttachDiskSourceType) type) { + case VIRSH_ATTACH_DISK_SOURCE_TYPE_FILE: + virBufferEscapeString(&buf, "\n", source); + break; + + case VIRSH_ATTACH_DISK_SOURCE_TYPE_BLOCK: + virBufferEscapeString(&buf, "\n", source); + break; + + case VIRSH_ATTACH_DISK_SOURCE_TYPE_NONE: + case VIRSH_ATTACH_DISK_SOURCE_TYPE_LAST: + break; + } + virBufferAsprintf(&buf, " (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1605803231862951.0813383864664; Thu, 19 Nov 2020 08:27:11 -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-235-C6SI0S6-PguCbLnX8E3cmw-1; Thu, 19 Nov 2020 11:27:06 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5B437107ACFC; Thu, 19 Nov 2020 16:26:58 +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 3643C5B4A4; Thu, 19 Nov 2020 16:26:58 +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 1F39F1809CB2; Thu, 19 Nov 2020 16:26:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0AJGQpUa030815 for ; Thu, 19 Nov 2020 11:26:51 -0500 Received: by smtp.corp.redhat.com (Postfix) id D33E75C1D1; Thu, 19 Nov 2020 16:26:51 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 019995C1A1; Thu, 19 Nov 2020 16:26:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605803230; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=ByfXSFIAgpbzpUBwJKBaEkeBkA42C5vhD8LHkWScOd4=; b=Z+JL6UCPr746LhEv6YxuMfzs1wMb/SzGWBXZUBMXUKhFdDCO318dcqMKFDf3xDsi61u8yE /CV31f2qdcMIHwREnNl3mxmX/a/QTZT08f28Ez5x5jW95T2ntuMgQm5MSFN2ZYkgn3YaOo Ui3g5P4XBuVGF9FoEUu+swn08EraAZ0= X-MC-Unique: C6SI0S6-PguCbLnX8E3cmw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 13/16] virsh: cmdAttachDisk: Use virXMLFormatElement Date: Thu, 19 Nov 2020 17:26:19 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Ryan Gahagan 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.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Convert the code to the new XML formatting approach for simpler code and future additions. Signed-off-by: Peter Krempa Reviewed-by: Daniel Henrique Barboza --- tools/virsh-domain.c | 61 ++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 36 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 5c7cb994f1..b0e1c6e6f7 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -558,6 +558,10 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) const char *stype =3D NULL; int type =3D VIR_STORAGE_TYPE_NONE; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) diskAttrBuf =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) diskChildBuf =3D VIR_BUFFER_INIT_CHILD(&buf); + g_auto(virBuffer) driverAttrBuf =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) sourceAttrBuf =3D VIR_BUFFER_INITIALIZER; g_autofree char *xml =3D NULL; struct stat st; bool current =3D vshCommandOptBool(cmd, "current"); @@ -622,71 +626,56 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) if (wwn && !virValidateWWN(wwn)) return false; - /* Make XML of disk */ - virBufferAddLit(&buf, "\n"); - virBufferAdjustIndent(&buf, 2); - - if (driver || subdriver || iothread || cache || io) { - virBufferAddLit(&buf, "\n"); - } + virXMLFormatElement(&diskChildBuf, "driver", &driverAttrBuf, NULL); switch ((enum virshAttachDiskSourceType) type) { case VIRSH_ATTACH_DISK_SOURCE_TYPE_FILE: - virBufferEscapeString(&buf, "\n", source); + virBufferEscapeString(&sourceAttrBuf, " file=3D'%s'", source); break; case VIRSH_ATTACH_DISK_SOURCE_TYPE_BLOCK: - virBufferEscapeString(&buf, "\n", source); + virBufferEscapeString(&sourceAttrBuf, " dev=3D'%s'", source); break; case VIRSH_ATTACH_DISK_SOURCE_TYPE_NONE: case VIRSH_ATTACH_DISK_SOURCE_TYPE_LAST: break; } + virXMLFormatElement(&diskChildBuf, "source", &sourceAttrBuf, NULL); - virBufferAsprintf(&buf, "\n"); + virBufferAsprintf(&diskChildBuf, " bus=3D'%s'", targetbus); + virBufferAddLit(&diskChildBuf, "/>\n"); if (mode) - virBufferAsprintf(&buf, "<%s/>\n", mode); + virBufferAsprintf(&diskChildBuf, "<%s/>\n", mode); if (serial) - virBufferAsprintf(&buf, "%s\n", serial); + virBufferAsprintf(&diskChildBuf, "%s\n", serial); if (alias) - virBufferAsprintf(&buf, "\n", alias); + virBufferAsprintf(&diskChildBuf, "\n", alias); if (wwn) - virBufferAsprintf(&buf, "%s\n", wwn); + virBufferAsprintf(&diskChildBuf, "%s\n", wwn); if (straddr && - cmdAttachDiskFormatAddress(ctl, &buf, straddr, target, multifuncti= on) < 0) + cmdAttachDiskFormatAddress(ctl, &diskChildBuf, straddr, target, mu= ltifunction) < 0) return false; - virBufferAdjustIndent(&buf, -2); - virBufferAddLit(&buf, "\n"); + virXMLFormatElement(&buf, "disk", &diskAttrBuf, &diskChildBuf); xml =3D virBufferContentAndReset(&buf); --=20 2.28.0 From nobody Fri Apr 26 13:02:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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=1605803234; cv=none; d=zohomail.com; s=zohoarc; b=XGZvzluxFHef7Lfjfz0y0crruZ/Hnx2sAiKcyhhRe7pSRt/aVp7XrELu+ep5KkPBDxGEZ3QFcGVnAdYtVBbDSaB9goQazbU9jYXmT/9p+Mxfyl6/p6ZWgi2tiVpJKbNfyeaRjGUReKx45QhmSIMdRxw68XB9PlUplhDRUXJVyrs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605803234; h=Content-Type:Content-Transfer-Encoding:Cc: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=E68yxUZKBKUO1gcLo+fRspTvpoZkXDRfefl6FmWIOJg=; b=fGCucOvfSeS7TI6DK0wwLI9UE3G2itbWe4z0mSjBOrSq+WBbZBKZJ1aEZEbWgzTDfU2ImlvhDVfmr2KCm+zw8sQRKLNNyKGLgkXtnsi9nxKUICLvAu3KT2MUxhyu52J/SOBHoAJieeKQxMVPqDwvWI9X4BeOvoH1wft/dAzpE44= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1605803234823572.5596010076428; Thu, 19 Nov 2020 08:27:14 -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-126-T_9bvwcROomD-_AsAvBR-A-1; Thu, 19 Nov 2020 11:27:02 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id EDEFE1005D61; Thu, 19 Nov 2020 16:26:56 +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 BFC4819D80; Thu, 19 Nov 2020 16:26:56 +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 81A5C1809CAE; Thu, 19 Nov 2020 16:26:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0AJGQr4I030827 for ; Thu, 19 Nov 2020 11:26:53 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2786E5C1A1; Thu, 19 Nov 2020 16:26:53 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 419D85C1D1; Thu, 19 Nov 2020 16:26:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605803226; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=E68yxUZKBKUO1gcLo+fRspTvpoZkXDRfefl6FmWIOJg=; b=bv1GnmQMcCYJBjuzN+CiwvswuRKe/57ruhmtuuq7wiE+pDyACdHkuYBt5HZpPp+UHOUZgn 1r5cC7HBplVmmnO+kWnj8+FSXUZaMA9An75TiSys3dxgbEDAsFY8A6UvsGggLqJ8iHrEqK qtfTKarebRUECcJ3uc9HL2vqn6WG2lU= X-MC-Unique: T_9bvwcROomD-_AsAvBR-A-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 14/16] virsh: Added attach-disk support for network disk Date: Thu, 19 Nov 2020 17:26:20 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Ryan Gahagan 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.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Ryan Gahagan Related issue: https://gitlab.com/libvirt/libvirt/-/issues/16 Added in support for the following parameters in attach-disk: --source-protocol --source-host-name --source-host-socket --source-host-transport Added documentation to virsh.rst specifying usage. Signed-off-by: Ryan Gahagan Signed-off-by: Peter Krempa Reviewed-by: Daniel Henrique Barboza --- docs/manpages/virsh.rst | 31 ++++++++++--- tests/virsh-output-commands | 14 ++++++ tests/virsh-output.out | 88 +++++++++++++++++++++++++++++++++++++ tools/virsh-domain.c | 84 ++++++++++++++++++++++++++++++----- 4 files changed, 200 insertions(+), 17 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 1ae6d1a0d4..36c868a3e6 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -4538,14 +4538,18 @@ attach-disk [--current]] | [--persistent]] [--targetbus bus] [--driver driver] [--subdriver subdriver] [--iothread iothread] [--cache cache] [--io io] [--type type] [--alias alias] - [--mode mode] [--sourcetype sourcetype] [--serial serial] - [--wwn wwn] [--rawio] [--address address] [--multifunction] - [--print-xml] + [--mode mode] [--sourcetype sourcetype] + [--source-protocol protocol] [--source-host-name hostname:port] + [--source-host-transport transport] [--source-host-socket socket] + [--serial serial] [--wwn wwn] [--rawio] [--address address] + [--multifunction] [--print-xml] Attach a new disk device to the domain. -*source* is path for the files and devices. *target* controls the bus or -device under which the disk is exposed to the guest OS. It indicates the -"logical" device name; the optional *targetbus* attribute specifies the ty= pe +*source* is path for the files and devices unless *--source-protocol* +is specified, in which case *source* is the name of a network disk. +*target* controls the bus or device under which the disk is exposed +to the guest OS. It indicates the "logical" device name; +the optional *targetbus* attribute specifies the type of disk device to emulate; possible values are driver specific, with typic= al values being *ide*, *scsi*, *virtio*, *xen*, *usb*, *sata*, or *sd*, if omitted, the bus type is inferred from the style of the device name (e.g. = a @@ -4563,7 +4567,7 @@ within the existing virtual cdrom or floppy device; c= onsider using ``update-device`` for this usage instead. *alias* can set user supplied alias. *mode* can specify the two specific mode *readonly* or *shareable*. -*sourcetype* can indicate the type of source (block|file) +*sourcetype* can indicate the type of source (block|file|network) *cache* can be one of "default", "none", "writethrough", "writeback", "directsync" or "unsafe". *io* controls specific policies on I/O; QEMU guests support "threads", @@ -4579,6 +4583,19 @@ ccw:cssid.ssid.devno. Virtio-ccw devices must have t= heir cssid set to 0xfe. *multifunction* indicates specified pci address is a multifunction pci dev= ice address. +There is also support for using a network disk. As specified, the user can +provide a *--source-protocol* in which case the *source* parameter will +be interpreted as the source name. *--source-protocol* must be provided +if the user intends to provide a network disk or host information. +Host information can be provided using the tags +*--source-host-name*, *--source-host-transport*, and *--source-host-socket= *, +which respectively denote the name of the host, the host's transport metho= d, +and the socket that the host uses. *--source-host-socket* and +*--source-host-name* cannot both be provided, and the user must provide a +*--source-host-transport* if they want to provide a *--source-host-socket*. +The *--source-host-name* parameter supports host:port syntax +if the user wants to provide a port as well. + If *--print-xml* is specified, then the XML of the disk that would be atta= ched is printed instead. diff --git a/tests/virsh-output-commands b/tests/virsh-output-commands index 43f87bee0f..d8e73fc1ac 100755 --- a/tests/virsh-output-commands +++ b/tests/virsh-output-commands @@ -78,3 +78,17 @@ attach_disk --target sda --sourcetype file --type disk -= -address ccw:12.34.56 attach_disk --target vda --sourcetype file --type disk --address test:12.3= 4.56 attach_disk --target vda --sourcetype file --type disk --address test:12:3= 4:56 attach_disk --target vda --sourcetype file --type disk --address test:12.3= 4.56 + +./virsh attach-disk --print-xml --domain testdom $@ --source "" --source-p= rotocol AAA +./virsh attach-disk --print-xml --domain testdom $@ --source "" --source-p= rotocol AAA +attach_disk --target hda --source-protocol AAA --sourcetype file +attach_disk --target hda --sourcetype network +attach_disk --target hda --sourcetype network --source-protocol TEST --sou= rce-host-name hostname +attach_disk --target hda --sourcetype network --source-protocol TEST --sou= rce-host-name hostname:port +attach_disk --target hda --sourcetype network --source-protocol TEST --sou= rce-host-name hostname: +attach_disk --target hda --sourcetype network --source-protocol TEST --sou= rce-host-name :port +attach_disk --target hda --sourcetype network --source-protocol TEST --sou= rce-host-name : +attach_disk --target hda --sourcetype network --source-protocol TEST --sou= rce-host-name hostname:port --source-host-transport trnsp +attach_disk --target hda --sourcetype network --source-protocol TEST --sou= rce-host-transport trnsp +attach_disk --target hda --sourcetype network --source-protocol TEST --sou= rce-host-transport trnsp --source-host-socket /nonexistent/socket +attach_disk --target hda --sourcetype network --source-protocol TEST --sou= rce-host-socket /nonexistent/socket diff --git a/tests/virsh-output.out b/tests/virsh-output.out index 6af7600a9c..d8ef641c2a 100644 --- a/tests/virsh-output.out +++ b/tests/virsh-output.out @@ -405,4 +405,92 @@ error: Invalid address. + ./virsh attach-disk --print-xml --domain testdom --target vda --sourcety= pe file --type disk --address test:12.34.56 --source /nonexistent/file error: Invalid address. ++ ./virsh attach-disk --print-xml --domain testdom --source '' --source-pr= otocol AAA +error: command 'attach-disk' requires option ++ ./virsh attach-disk --print-xml --domain testdom --source '' --source-pr= otocol AAA +error: command 'attach-disk' requires option ++ attach_disk --target hda --source-protocol AAA --sourcetype file ++ ./virsh attach-disk --print-xml --domain testdom --target hda --source-p= rotocol AAA --sourcetype file --source /nonexistent/file +error: --source-protocol option requires --sourcetype network + ++ attach_disk --target hda --sourcetype network ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe network --source /nonexistent/file +error: --source-protocol option requires --sourcetype network + ++ attach_disk --target hda --sourcetype network --source-protocol TEST --s= ource-host-name hostname ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe network --source-protocol TEST --source-host-name hostname --source /non= existent/file + + + + + + + ++ attach_disk --target hda --sourcetype network --source-protocol TEST --s= ource-host-name hostname:port ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe network --source-protocol TEST --source-host-name hostname:port --source= /nonexistent/file + + + + + + + ++ attach_disk --target hda --sourcetype network --source-protocol TEST --s= ource-host-name hostname: ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe network --source-protocol TEST --source-host-name hostname: --source /no= nexistent/file + + + + + + + ++ attach_disk --target hda --sourcetype network --source-protocol TEST --s= ource-host-name :port ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe network --source-protocol TEST --source-host-name :port --source /nonexi= stent/file + + + + + + + ++ attach_disk --target hda --sourcetype network --source-protocol TEST --s= ource-host-name : ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe network --source-protocol TEST --source-host-name : --source /nonexisten= t/file + + + + + + + ++ attach_disk --target hda --sourcetype network --source-protocol TEST --s= ource-host-name hostname:port --source-host-transport trnsp ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe network --source-protocol TEST --source-host-name hostname:port --source= -host-transport trnsp --source /nonexistent/file + + + + + + + ++ attach_disk --target hda --sourcetype network --source-protocol TEST --s= ource-host-transport trnsp ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe network --source-protocol TEST --source-host-transport trnsp --source /n= onexistent/file + + + + + + + ++ attach_disk --target hda --sourcetype network --source-protocol TEST --s= ource-host-transport trnsp --source-host-socket /nonexistent/socket ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe network --source-protocol TEST --source-host-transport trnsp --source-ho= st-socket /nonexistent/socket --source /nonexistent/file + + + + + + + ++ attach_disk --target hda --sourcetype network --source-protocol TEST --s= ource-host-socket /nonexistent/socket ++ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcety= pe network --source-protocol TEST --source-host-socket /nonexistent/socket = --source /nonexistent/file +error: Option --source-host-transport is required by option --source-host-= socket + end diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index b0e1c6e6f7..7203403b31 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -394,7 +394,7 @@ static const vshCmdOptDef opts_attach_disk[] =3D { {.name =3D "source", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ | VSH_OFLAG_EMPTY_OK, - .help =3D N_("source of disk device") + .help =3D N_("source of disk device or name of network disk") }, {.name =3D "target", .type =3D VSH_OT_DATA, @@ -440,7 +440,7 @@ static const vshCmdOptDef opts_attach_disk[] =3D { }, {.name =3D "sourcetype", .type =3D VSH_OT_STRING, - .help =3D N_("type of source (block|file)") + .help =3D N_("type of source (block|file|network)") }, {.name =3D "serial", .type =3D VSH_OT_STRING, @@ -470,6 +470,22 @@ static const vshCmdOptDef opts_attach_disk[] =3D { .type =3D VSH_OT_BOOL, .help =3D N_("print XML document rather than attach the disk") }, + {.name =3D "source-protocol", + .type =3D VSH_OT_STRING, + .help =3D N_("protocol used by disk device source") + }, + {.name =3D "source-host-name", + .type =3D VSH_OT_STRING, + .help =3D N_("host name for source of disk device") + }, + {.name =3D "source-host-transport", + .type =3D VSH_OT_STRING, + .help =3D N_("host transport for source of disk device") + }, + {.name =3D "source-host-socket", + .type =3D VSH_OT_STRING, + .help =3D N_("host socket for source of disk device") + }, VIRSH_COMMON_OPT_DOMAIN_PERSISTENT, VIRSH_COMMON_OPT_DOMAIN_CONFIG, VIRSH_COMMON_OPT_DOMAIN_LIVE, @@ -523,6 +539,7 @@ enum virshAttachDiskSourceType { VIRSH_ATTACH_DISK_SOURCE_TYPE_NONE, VIRSH_ATTACH_DISK_SOURCE_TYPE_FILE, VIRSH_ATTACH_DISK_SOURCE_TYPE_BLOCK, + VIRSH_ATTACH_DISK_SOURCE_TYPE_NETWORK, VIRSH_ATTACH_DISK_SOURCE_TYPE_LAST }; @@ -532,7 +549,8 @@ VIR_ENUM_IMPL(virshAttachDiskSource, VIRSH_ATTACH_DISK_SOURCE_TYPE_LAST, "", "file", - "block"); + "block", + "network"); static bool @@ -553,6 +571,10 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) const char *wwn =3D NULL; const char *targetbus =3D NULL; const char *alias =3D NULL; + const char *source_protocol =3D NULL; + const char *host_name =3D NULL; + const char *host_transport =3D NULL; + const char *host_socket =3D NULL; int ret; unsigned int flags =3D VIR_DOMAIN_AFFECT_CURRENT; const char *stype =3D NULL; @@ -562,6 +584,8 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) g_auto(virBuffer) diskChildBuf =3D VIR_BUFFER_INIT_CHILD(&buf); g_auto(virBuffer) driverAttrBuf =3D VIR_BUFFER_INITIALIZER; g_auto(virBuffer) sourceAttrBuf =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) sourceChildBuf =3D VIR_BUFFER_INIT_CHILD(&diskChildB= uf); + g_auto(virBuffer) hostAttrBuf =3D VIR_BUFFER_INITIALIZER; g_autofree char *xml =3D NULL; struct stat st; bool current =3D vshCommandOptBool(cmd, "current"); @@ -575,6 +599,13 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) VSH_EXCLUSIVE_OPTIONS_VAR(current, live); VSH_EXCLUSIVE_OPTIONS_VAR(current, config); + VSH_REQUIRE_OPTION("source-host-name", "source-protocol"); + VSH_REQUIRE_OPTION("source-host-transport", "source-protocol"); + VSH_REQUIRE_OPTION("source-host-socket", "source-protocol"); + VSH_REQUIRE_OPTION("source-host-socket", "source-host-transport"); + + VSH_EXCLUSIVE_OPTIONS("source-host-name", "source-host-socket"); + if (config || persistent) flags |=3D VIR_DOMAIN_AFFECT_CONFIG; if (live) @@ -594,7 +625,11 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) vshCommandOptStringReq(ctl, cmd, "address", &straddr) < 0 || vshCommandOptStringReq(ctl, cmd, "targetbus", &targetbus) < 0 || vshCommandOptStringReq(ctl, cmd, "alias", &alias) < 0 || - vshCommandOptStringReq(ctl, cmd, "sourcetype", &stype) < 0) + vshCommandOptStringReq(ctl, cmd, "sourcetype", &stype) < 0 || + vshCommandOptStringReq(ctl, cmd, "source-protocol", &source_protoc= ol) < 0 || + vshCommandOptStringReq(ctl, cmd, "source-host-name", &host_name) <= 0 || + vshCommandOptStringReq(ctl, cmd, "source-host-transport", &host_tr= ansport) < 0 || + vshCommandOptStringReq(ctl, cmd, "source-host-socket", &host_socke= t) < 0) return false; if (stype && @@ -604,17 +639,24 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) } if (type =3D=3D VIRSH_ATTACH_DISK_SOURCE_TYPE_NONE) { - if (STRNEQ_NULLABLE(driver, "file") && - STRNEQ_NULLABLE(driver, "tap") && - source && - stat(source, &st) =3D=3D 0 && - S_ISBLK(st.st_mode)) { + if (source_protocol) { + type =3D VIRSH_ATTACH_DISK_SOURCE_TYPE_NETWORK; + } else if (STRNEQ_NULLABLE(driver, "file") && + STRNEQ_NULLABLE(driver, "tap") && + source && + stat(source, &st) =3D=3D 0 && + S_ISBLK(st.st_mode)) { type =3D VIRSH_ATTACH_DISK_SOURCE_TYPE_BLOCK; } else { type =3D VIRSH_ATTACH_DISK_SOURCE_TYPE_FILE; } } + if ((type =3D=3D VIRSH_ATTACH_DISK_SOURCE_TYPE_NETWORK) !=3D !!source_= protocol) { + vshError(ctl, _("--source-protocol option requires --sourcetype ne= twork")); + return false; + } + if (mode) { if (STRNEQ(mode, "readonly") && STRNEQ(mode, "shareable")) { vshError(ctl, _("No support for %s in command 'attach-disk'"), @@ -648,11 +690,33 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) virBufferEscapeString(&sourceAttrBuf, " dev=3D'%s'", source); break; + case VIRSH_ATTACH_DISK_SOURCE_TYPE_NETWORK: + virBufferEscapeString(&sourceAttrBuf, " protocol=3D'%s'", source_p= rotocol); + virBufferEscapeString(&sourceAttrBuf, " name=3D'%s'", source); + + virBufferEscapeString(&hostAttrBuf, " transport=3D'%s'", host_tran= sport); + virBufferEscapeString(&hostAttrBuf, " socket=3D'%s'", host_socket); + + if (host_name) { + g_autofree char *host_name_copy =3D g_strdup(host_name); + char *host_port =3D strchr(host_name_copy, ':'); + + if (host_port) { + *host_port =3D '\0'; + host_port++; + } + + virBufferEscapeString(&hostAttrBuf, " name=3D'%s'", host_name_= copy); + virBufferEscapeString(&hostAttrBuf, " port=3D'%s'", host_port); + } + virXMLFormatElement(&sourceChildBuf, "host", &hostAttrBuf, NULL); + break; + case VIRSH_ATTACH_DISK_SOURCE_TYPE_NONE: case VIRSH_ATTACH_DISK_SOURCE_TYPE_LAST: break; } - virXMLFormatElement(&diskChildBuf, "source", &sourceAttrBuf, NULL); + virXMLFormatElement(&diskChildBuf, "source", &sourceAttrBuf, &sourceCh= ildBuf); virBufferAsprintf(&diskChildBuf, " (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 160580329367113.368650009789803; Thu, 19 Nov 2020 08:28:13 -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-281-rH16vIUyMASfAIVj9ujDTA-1; Thu, 19 Nov 2020 11:27:05 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6773A1842165; Thu, 19 Nov 2020 16:26:57 +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 3ECCE1001B2C; Thu, 19 Nov 2020 16:26:57 +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 06AC350045; Thu, 19 Nov 2020 16:26:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0AJGQsgF030841 for ; Thu, 19 Nov 2020 11:26:54 -0500 Received: by smtp.corp.redhat.com (Postfix) id 799EE5C1A1; Thu, 19 Nov 2020 16:26:54 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F7915C1D1; Thu, 19 Nov 2020 16:26:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605803292; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=CXnLjlZ7dag8wM+ZE2saBvpV+rnznuuUxL93MSKsABE=; b=dSzhmNWKcvajus712GfqbLyWsrUSYjpPazwtaB3sFjmF17JzWJjY0OxhHhJETWv124/Hxt 1IAm48eGiYIXTNcNX2LmmFZ4Lvh9YxB+g/LbZm5GHnTLQmpAiAHWLZfQngJSnGtzX1XDaW JMUSmsgvwtYDGZnTbQwyVv44H2KCNAs= X-MC-Unique: rH16vIUyMASfAIVj9ujDTA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 15/16] tests: virsh-output: Mark as expensive Date: Thu, 19 Nov 2020 17:26:21 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Ryan Gahagan 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.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The test takes more than a second on a beefy machine. While it's more useful than some expensive tests it's not worth running all the time. Signed-off-by: Peter Krempa Reviewed-by: Daniel Henrique Barboza --- tests/virsh-output | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/virsh-output b/tests/virsh-output index 44833c7048..aa2d386c39 100755 --- a/tests/virsh-output +++ b/tests/virsh-output @@ -2,6 +2,8 @@ . "$(dirname $0)/test-lib.sh" +test_expensive + if [ ! -x /bin/bash ]; then echo skipping test - no bash exit 77 --=20 2.28.0 From nobody Fri Apr 26 13:02:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1605803293; cv=none; d=zohomail.com; s=zohoarc; b=RXzaX9d/lfBE467/CknWyFXp/Ysj5WOQ3ZjTPf+e2PrsFw8R8aLBIMqpGkaD7lXWA6CrkZeVAaemQiK1yUpq6oETEnzoC4BPPNYiixCmyPhjzdR+iR47Vg7kZDrFz3Ia5W5eBznRJ98T/5WneDstGNHIqX3lQp3teN/FfrB0xVU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605803293; h=Content-Type:Content-Transfer-Encoding:Cc: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=a0P8CWsZxm1ITYu4UNaZX8gCwEIULmDnXlk3bq4gJ6U=; b=i8NWyWkOL3FUPA/1HZgUT/P4FkhxgTjFLpMtzwTf/JBu+BRvCehL5wOXkMmvVoPRwW/licPyypkwqiGkk7ehxP2W3tWyeC5HRHxZOKol/Wlrq8XNUg6pP4xcH9I+EBIjXcCNIpT5DiNJXTuhURaB207HQynxry9LU+pMP7QmY6o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1605803293389270.48205267332423; Thu, 19 Nov 2020 08:28:13 -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-587-Zy8nJLkBP56cA-UX7FSfqw-1; Thu, 19 Nov 2020 11:27:08 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6AA168144EF; Thu, 19 Nov 2020 16:27:00 +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 4477D5D9DB; Thu, 19 Nov 2020 16:27:00 +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 061FC1809CB1; Thu, 19 Nov 2020 16:27:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0AJGQtAY030866 for ; Thu, 19 Nov 2020 11:26:55 -0500 Received: by smtp.corp.redhat.com (Postfix) id D4D2E5C1A1; Thu, 19 Nov 2020 16:26:55 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF5325C1D1; Thu, 19 Nov 2020 16:26:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605803292; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=a0P8CWsZxm1ITYu4UNaZX8gCwEIULmDnXlk3bq4gJ6U=; b=Vb1dXtP1LbAgQdsS4hNer6t7pDM74sVA3+an8h6325I0ZOierf1UDDFBS6lnzrHZoBBiHn gVrbbiCo64/STnhqsgvTVK4Tbt2LA8OQWaVxbCbQaFotpTWCTyIw/UvsgZgQZFJ8NH20SU nEKUj9wZKkLXkh1E50d/Lo0dDtQoOgI= X-MC-Unique: Zy8nJLkBP56cA-UX7FSfqw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 16/16] tests: virsh-checkpoint/snapshot: Mark as expensive Date: Thu, 19 Nov 2020 17:26:22 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Ryan Gahagan 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.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: Daniel Henrique Barboza --- tests/virsh-checkpoint | 2 ++ tests/virsh-snapshot | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tests/virsh-checkpoint b/tests/virsh-checkpoint index 92962d2205..2492d29f53 100755 --- a/tests/virsh-checkpoint +++ b/tests/virsh-checkpoint @@ -19,6 +19,8 @@ . "$(dirname $0)/test-lib.sh" +test_expensive + if test "$VERBOSE" =3D yes; then set -x $abs_top_builddir/tools/virsh --version diff --git a/tests/virsh-snapshot b/tests/virsh-snapshot index 473e3b3f2d..289de5b2db 100755 --- a/tests/virsh-snapshot +++ b/tests/virsh-snapshot @@ -19,6 +19,8 @@ . "$(dirname $0)/test-lib.sh" +test_expensive + if test "$VERBOSE" =3D yes; then set -x $abs_top_builddir/tools/virsh --version --=20 2.28.0