[libvirt] [PATCH] qemu: add virQEMUBuildBufferEscapeComma in qemu_command.c

Martin Kletzander mkletzan at redhat.com
Fri Mar 30 20:19:39 UTC 2018


On Thu, Mar 29, 2018 at 12:10:46PM -0400, John Ferlan wrote:
>
>
>On 03/16/2018 01:02 PM, Sukrit Bhatnagar wrote:
>> This patch adds virQEMUBuildBufferEscapeComma wherever applicable in src/qemu/qemu_command.c
>> Based on: https://wiki.libvirt.org/page/BiteSizedTasks#qemu:_Use_comma_escaping_for_more_command_line_values
>>
>
>Try to keep shorter lines in your commit message (generally <=70 ish
>characters) and the link to the bite size task should have gone under
>the --- below since it's likely that once this task is complete (and
>code pushed) that someone will remove the entry from the bite size task
>page and we don't really want a knowingly dead link to live in git
>history forever.
>
>In any case, consider the following (or something even shorter):
>
>qemu: Add comma escape for more command line options
>
>This patch adds virQEMUBuildBufferEscapeComma to qemu command
>line processing for data fields which are user provided in order
>to ensure that if a comma (',') is provided that it'll be properly
>handled by the qemu monitor which expects a double comma as a form of
>escaping.
>

Yeah, this sounds nice, although I must admit I'm usually very lazy to explain
what's all the fuzz behind it when the difference between the long explanation
and just "Use function X more" is basically just the description of function X.
And since that function already exists and is not being added by the patch...
You know where I'm going with it =) Anyway, that's not why I'm replying here.  I
just want to give some hints further down.

>> Signed-off-by: Sukrit Bhatnagar <skrtbhtngr at gmail.com>
>> ---
>>
>
>BTW: Since this was a followup/adjustment of what you submitted:
>
>https://www.redhat.com/archives/libvir-list/2018-March/msg00940.html
>
>then you should prefix with a "v2" via something like
>'--subject-prefix="PATCH v2"' on your 'git send-email' where you can
>place a link to the v1 in this section (below the ---) and a description
>of what changed or was fixed since v1.
>

Even better, format-patch and send-email both accept `-v` parameter, so you can
just do `git send-email -v2` and it will do it properly for you, even if you
have some subject-prefix already set (e.g. for a subproject)

>BTW: Your next patch will be v3, so you'll have a shot to try it!
>Providing a link to the previous version is generally "nice" so that the
>reviewer doesn't have to search for it and it gives a bit more history.
>
>>
>> This patch is submitted towards my proposal for GSoC'18.
>>
>> Changes made:
>> - info->romfile in qemuBuildRomStr
>> - disk->vendor, disk->product in qemuBuildDriveDevStr
>> - fs->src->path in qemuBuildFSStr
>> - fs->dst in qemuBuildFSDevStr
>> - connect= in qemuBuildHostNetStr
>> - fileval handling in qemuBuildChrChardevStr
>> - TYPE_DEV, TYPE_PIPE handling in qemuBuildChrChardevStr
>> - cfg->vncTLSx509certdir in qemuBuildGraphicsVNCCommandLine
>> - cfg->spiceTLSx509certdir in qemuBuildGraphicsSPICECommandLine
>> - loader->path, loader->nvram usage qemuBuildDomainLoaderCommandLine
>>
>> Places where no changes were made:
>> - src->hosts->socket in qemuBuildNetworkDriveURI uses virAsprintf not virBufferAsprintf; src->path, src->configFile are not used
>
>Sure; however, you could use virBuffer* API's and then use
>virBufferContentAndReset in order to get the escaped string you'd want
>for the final result.
>
>I'll admit the src->configFile processing in qemuBuildNetworkDriveStr
>appears awful due to the need to escape the ':' for ":conf=", but I
>think you can get away with the EscapeComma on just the src->configFile.
>There is a test for adding the ":conf=%s", so if you do get it wrong,
>you'll know...  If you wanted to be sure the right thing was done with
>the comma, then alter the XML file and see that the ARGS output gets the
>double comma. Whether that becomes part of the commit isn't necessary,
>but at least it proves to yourself that things were done right.
>
>> - qemuBuildChrArgStr function does not exist
>
>hint...
>
>git log -p src/qemu/qemu_command.c
><search for qemuBuildChrArgStr>
>

Again, just a hint, you could do `git log -p -G qemuBuildChrArgStr`.  That will
only show you commits that had the string after -G in one of the added/removed
lines.

>and you'd see that processing was moved by commit id '426dc5eb' into
>qemuBuildChrChardevStr and qemuBuildChrChardevFileStr which were handled
>in this patch.
>
>> - not applicable on data.nix.path in qemuBuildVhostuserCommandLine
>
>True, since it's not built into the qemu command line but rather as part
>of some other command...
>
>> - converting places that use strchr in qemuBuildSmartcardCommandLine to use virBufferEscape
>
>Perhaps the request here was to remove the check and failure for "," in
>the name/path and use EscapeComma instead...
>
>Another one that wasn't listed is "rendernode" - although nothing tells
>us "how" that field is populated in the XML, I suppose someone could add
>a "," into the provided entry and that'd be problematic.
>
>Also "throttling.group" and "group_name" - although that's already
>escaped, someone conceivably could put in a "," into the name too as
>it's not checked.
>
>FWIW: After applying your patch I did a:
>
>grep "=%s" src/qemu/qemu_command.c | \
>    grep -v "bus=%s" | grep -v "fd=%s" | grep -v "id=%s"
>
>and that reduced the number things to specifically look at for needing
>the comma escaping.  You may want to make the same check - I didn't
>complete looking at the output...
>
>>
>> I have run `make check VIR_TEST_EXPENSIVE=1`, `make syntax-check` and `make -C tests valgrind`.
>> Some tests fail on my system, even for an unmodified clone of the repo.
>> But, all the tests which were passed by the unmodified clone were passed after I made these changes.
>>

VIR_TEST_EXPENSIVE is fine, but you probably won't be changing stuff related to
that.  The valgrind tests are kind of broken sometimes, don't worry about it.

Hope that helped, looking forward to v3 ;)

>> As always, your feedback is welcome!
>>
>>
>> src/qemu/qemu_command.c | 73 +++++++++++++++++++++++++++++--------------------
>>  1 file changed, 44 insertions(+), 29 deletions(-)
>>
>> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
>> index fa0aa5d5c..06f4f72fc 100644
>> --- a/src/qemu/qemu_command.c
>> +++ b/src/qemu/qemu_command.c
>
>[...]
>
>> @@ -3603,10 +3611,9 @@ qemuBuildHostNetStr(virDomainNetDefPtr net,
>>          break;
>>
>>      case VIR_DOMAIN_NET_TYPE_CLIENT:
>> -        virBufferAsprintf(&buf, "socket%cconnect=%s:%d,",
>> -                          type_sep,
>> -                          net->data.socket.address,
>> -                          net->data.socket.port);
>> +        virBufferAsprintf(&buf, "socket%cconnect=", type_sep);
>> +        virQEMUBuildBufferEscapeComma(&buf, net->data.socket.address);
>> +        virBufferAsprintf(&buf, ":%d,", net->data.socket.port);
>>          break;
>>
>>      case VIR_DOMAIN_NET_TYPE_SERVER:
>
>Below here there's a few more "%s" for net->data.socket.address that
>weren't addressed in different case's (SERVER, MCAST, UDP)
>
>> @@ -4858,7 +4865,8 @@ qemuBuildChrChardevFileStr(virLogManagerPtr logManager,
>
>[...]
>
>The rest seemed fine to my eyes.
>
>John
>
>--
>libvir-list mailing list
>libvir-list at redhat.com
>https://www.redhat.com/mailman/listinfo/libvir-list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20180330/beb71665/attachment-0001.sig>


More information about the libvir-list mailing list