All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrange" <berrange@redhat.com>
To: Programmingkid <programmingkidx@gmail.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
	qemu-devel qemu-devel <qemu-devel@nongnu.org>,
	Qemu-block <qemu-block@nongnu.org>
Subject: Re: [Qemu-devel] ping: [PATCH v13] block/raw-posix.c: Make physical devices usable in QEMU under Mac OS X host
Date: Tue, 2 Feb 2016 17:16:07 +0000	[thread overview]
Message-ID: <20160202171606.GM18461@redhat.com> (raw)
In-Reply-To: <1CF37786-9AAA-4E5E-B571-DE20E7A463EB@gmail.com>

On Tue, Feb 02, 2016 at 12:08:31PM -0500, Programmingkid wrote:
> https://patchwork.ozlabs.org/patch/570128/
> 
> Mac OS X can be picky when it comes to allowing the user
> to use physical devices in QEMU. Most mounted volumes
> appear to be off limits to QEMU. If an issue is detected,
> a message is displayed showing the user how to unmount a
> volume. Now QEMU uses both CD and DVD media.
> 
> Signed-off-by: John Arbuckle <programmingkidx@gmail.com>
> 
> ---
> Changed filename variable to a character array.
> Changed how filename was set to bsd_path's value by using snprintf().

Whats the rationale here ? Using pre-allocated fixed
length arrays is pretty bad practice in general, but
especially so for filenames


> @@ -2119,34 +2173,59 @@ static int hdev_open(BlockDriverState *bs, QDict *options, int flags,
>      int ret;
>  
>  #if defined(__APPLE__) && defined(__MACH__)
> -    const char *filename = qdict_get_str(options, "filename");

[snip]

> +    char filename[MAXPATHLEN];
> +    bool error_occurred = false;
> +    snprintf(filename, MAXPATHLEN, "%s", qdict_get_str(options, "filename"));

This is a step backwards compared to the original code
IMHO. There's no good reason to use a stack allocated
fixed array here - the code that follows would be
quite happy with the original 'const char *'.

> +    /* If using a real cdrom */
> +    if (strcmp(filename, "/dev/cdrom") == 0) {
> +        char bsd_path[MAXPATHLEN];
> +        char *mediaType = NULL;
> +        kern_return_t ret_val;
> +        io_iterator_t mediaIterator = 0;
> +
> +        mediaType = FindEjectableOpticalMedia(&mediaIterator);
> +        if (mediaType == NULL) {
> +            error_setg(errp, "Please make sure your CD/DVD is in the optical"
> +                       " drive");
> +            error_occurred = true;
> +            goto hdev_open_Mac_error;
> +        }
> +
> +        ret_val = GetBSDPath(mediaIterator, bsd_path, sizeof(bsd_path), flags);
> +        if (ret_val != KERN_SUCCESS) {
> +            error_setg(errp, "Could not get BSD path for optical drive");
> +            error_occurred = true;
> +            goto hdev_open_Mac_error;
> +        }
> +
> +        /* If a real optical drive was not found */
> +        if (bsd_path[0] == '\0') {
> +            error_setg(errp, "Failed to obtain bsd path for optical drive");
> +            error_occurred = true;
> +            goto hdev_open_Mac_error;
> +        }
> +
> +        /* If using a cdrom disc and finding a partition on the disc failed */
> +        if (strncmp(mediaType, kIOCDMediaClass, 9) == 0 &&
> +            setup_cdrom(bsd_path, errp) == false) {
> +            print_unmounting_directions(bsd_path);
> +            error_occurred = true;
> +            goto hdev_open_Mac_error;
>          }
>  
> -        if ( mediaIterator )
> -            IOObjectRelease( mediaIterator );
> +        snprintf(filename, MAXPATHLEN, "%s", bsd_path);
> +        qdict_put(options, "filename", qstring_from_str(filename));
> +
> +hdev_open_Mac_error:
> +        g_free(mediaType);
> +        if (mediaIterator) {
> +            IOObjectRelease(mediaIterator);
> +        }
> +        if (error_occurred) {
> +            return -1;
> +        }
>      }
> -#endif
> +#endif /* defined(__APPLE__) && defined(__MACH__) */

Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

  reply	other threads:[~2016-02-02 17:16 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-02 17:08 [Qemu-devel] ping: [PATCH v13] block/raw-posix.c: Make physical devices usable in QEMU under Mac OS X host Programmingkid
2016-02-02 17:16 ` Daniel P. Berrange [this message]
2016-02-02 17:28   ` Programmingkid
2016-02-02 17:31     ` Daniel P. Berrange
2016-02-02 19:10       ` Programmingkid
2016-02-02 19:24         ` Eric Blake
2016-02-02 19:46           ` Programmingkid
2016-02-02 21:23           ` Programmingkid
2016-02-02 22:04             ` Eric Blake
2016-02-03  1:15               ` Programmingkid
2016-02-03  2:30                 ` Eric Blake
2016-02-03  4:21                   ` Programmingkid
2016-02-03  4:36                     ` Eric Blake
2016-02-03 15:54                       ` Programmingkid
2016-02-04 20:58                         ` Eric Blake
2016-02-02 19:29     ` Eric Blake
2016-02-03 10:37       ` Kevin Wolf

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=20160202171606.GM18461@redhat.com \
    --to=berrange@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=programmingkidx@gmail.com \
    --cc=qemu-block@nongnu.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.