qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Tomoki Sekiyama <tomoki.sekiyama@hds.com>
To: Eric Blake <eblake@redhat.com>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Cc: Mitsuhiro Tanino <mitsuhiro.tanino@hds.com>,
	"mdroth@linux.vnet.ibm.com" <mdroth@linux.vnet.ibm.com>
Subject: Re: [Qemu-devel] [PATCH v4 2/2] qga: Add guest-get-fsinfo command
Date: Fri, 20 Jun 2014 21:19:41 +0000	[thread overview]
Message-ID: <CFCA1215.C2BF%Tomoki.Sekiyama@hds.com> (raw)
In-Reply-To: <53A45171.1080406@redhat.com>

On 6/20/14 11:21 , "Eric Blake" <eblake@redhat.com> wrote:

>On 06/19/2014 06:34 PM, Tomoki Sekiyama wrote:
>
>>>> +    }
>>>> +    if (S_ISBLK(st.st_mode)) {
>>>> +        *devmajor = major(st.st_rdev);
>>>> +        *devminor = minor(st.st_rdev);
>>>
>>> major() and minor() are not POSIX functions.  While they work on Linux,
>>> and appear to have BSD origins, I still wonder if you need to be more
>>> careful on guarding their use.
>> 
>> This function is guarded by '#if defined(__linux__)' (and also
>> '#if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM)' ),
>> so I believe it is ok here.
>
>I take it the function gracefully fails on non-Linux.  But that's not
>very nice to management functions - they learn that the function exists,
>but have to call it to see if it actually works.  It might be nicer to
>conditionally expose the command only if it will work, so that querying
>the list of commands makes it obvious whether the agent supports subset
>freezing.

I think hiding unsupported commands from 'guest-info' is reasonable.
Currently the list is auto-generated from qapi-schema.json and all
commands are listed even though some of them just returns QERR_
UNSUPPORTED on some platforms(like guest-fstrim and guest-network-
get-interfaces etc. on non-Linux platform).
We may need a new mechanism to unregister them from the list,
or to mark them "unsupported", or to extend the generator so that
we can omit them from the list on unsupported platforms.
(And that should be done in another patch series.)

>>>> +    while (getline(&line, &n, fp) != -1) {
>>>> +        ret = sscanf(line,
>>>> +                     "%*u %*u %u:%u %*s %n%*s%n %*s %*s %*s %n%*s%n
>>>> %n%*s%n%c",
>>>> +                     &devmajor, &devminor, &dir_s, &dir_e, &type_s,
>>>> &type_e,
>>>
>>> I'm not a huge fan of sscanf("%u") - it has undefined behavior on
>>> integer overflow.  But the alternative of avoiding sscanf and
>>> open-coding your parser is so much bulkier, that I tend to look the
>>> other way.
>> 
>> Hmm, '%*u' can be simply replaced by '%*s' then.
>> For '%u:%u', maybe we can catch this part with '%s' or '%n%*s%n'
>> and convert them into integers later by strtoul().
>> Does it sound good to you?
>
>As I said, the cost of properly parsing a row of integers explodes into
>so much more code that I'm just fine looking the other way if you want
>to use sscanf for compactness - after all, this is a kernel file we're
>supposed to be reading, and if that interface has been corrupted to give
>us bogus data that doesn't parse correctly, then we're probably already
>hurting in other ways.

Right... then I'm going to keep sscanf here then.

Thanks,
Tomoki Sekiyama

  reply	other threads:[~2014-06-20 21:19 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-05 14:57 [Qemu-devel] [PATCH v4 0/2] qga: Add guest-fsfreeze-freeze-list command Tomoki Sekiyama
2014-06-05 14:57 ` [Qemu-devel] [PATCH v4 1/2] " Tomoki Sekiyama
2014-06-19 21:03   ` Eric Blake
2014-06-05 14:57 ` [Qemu-devel] [PATCH v4 2/2] qga: Add guest-get-fsinfo command Tomoki Sekiyama
2014-06-19 21:23   ` Eric Blake
2014-06-20  0:34     ` Tomoki Sekiyama
2014-06-20 15:21       ` Eric Blake
2014-06-20 21:19         ` Tomoki Sekiyama [this message]
2014-06-16 19:39 ` [Qemu-devel] [PATCH v4 0/2] qga: Add guest-fsfreeze-freeze-list command Tomoki Sekiyama

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CFCA1215.C2BF%Tomoki.Sekiyama@hds.com \
    --to=tomoki.sekiyama@hds.com \
    --cc=eblake@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=mitsuhiro.tanino@hds.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).