From: Dimitris Aragiorgis <dimara@arrikto.com>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: kwolf@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org,
qemu-block@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v4 5/5] raw-posix: Introduce hdev_is_sg()
Date: Mon, 22 Jun 2015 13:18:43 +0300 [thread overview]
Message-ID: <20150622101843.GA16825@arr> (raw)
In-Reply-To: <20150619123302.GK11189@stefanha-thinkpad.redhat.com>
[-- Attachment #1: Type: text/plain, Size: 2020 bytes --]
Hello Stefan,
Yes, you are right. Using realpath() is a workaround for supporting
symlinks, as long as they point to a path starting with "/dev/sg". I
will remove this reference in the revised version of this patch.
However, it still holds that determining whether a filename is an SG
device or not is based on textual (and hardcoded) examination, i.e.,
whether it starts with "/dev/sg".
The point is that a device node is a device node no matter what its
filename or its location in the fs tree is. A device node with major 1,
minor 3 is the null device whether it's called /dev/null or not.
The proposed patch allows the use of any device node which is capable of
acting as a scsi-generic device; it checks for the required intrinsic
property ("does this device support the SG ioctl?") versus trying to
second-guess the nature of the device node by checking its filename.
Similarly, the programming example from SG's documentation does not
check the node of the device node at all:
http://sg.danny.cz/sg/p/sg_v3_ho.html#pexample
/* It is prudent to check we have a sg device by trying an ioctl */
if ((ioctl(sg_fd, SG_GET_VERSION_NUM, &k) < 0) || (k < 30000)) {
printf("%s is not an sg device, or old sg driver\n", argv[1]);
return 1;
The above has the advantage that it works with device nodes of any name,
and in any directory.
So I suggest we go with the submitted patch taking into account Eric's
proposal: The code first stat()s the given filename to ensure it is a
character device node, and then it issues the SG_GET_VERSION_NUM and
SG_GET_SCSI_ID ioctl()s.
Thanks,
dimara
* Stefan Hajnoczi <stefanha@redhat.com> [2015-06-19 13:33:02 +0100]:
> On Wed, May 20, 2015 at 12:57:39PM +0300, Dimitris Aragiorgis wrote:
> > This is very fragile, e.g. it fails with symlinks or relative paths.
>
> This is not true since realpath(3) is used to resolve symlinks and
> product an absolute path.
>
> Is this patch really necessary?
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 490 bytes --]
next prev parent reply other threads:[~2015-06-22 10:19 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-20 9:57 [Qemu-devel] [PATCH v4 0/5] Some fixes related to scsi-generic Dimitris Aragiorgis
2015-05-20 9:57 ` [Qemu-devel] [PATCH v4 1/5] block: Use bdrv_is_sg() everywhere Dimitris Aragiorgis
2015-06-19 12:18 ` Stefan Hajnoczi
2015-05-20 9:57 ` [Qemu-devel] [PATCH v4 2/5] Fix migration in case of scsi-generic Dimitris Aragiorgis
2015-06-19 12:23 ` Stefan Hajnoczi
2015-05-20 9:57 ` [Qemu-devel] [PATCH v4 3/5] raw-posix: DPRINTF instead of DEBUG_BLOCK_PRINT Dimitris Aragiorgis
2015-06-18 20:05 ` Eric Blake
2015-06-19 12:25 ` Stefan Hajnoczi
2015-05-20 9:57 ` [Qemu-devel] [PATCH v4 4/5] raw-posix: Use DPRINTF for DEBUG_FLOPPY Dimitris Aragiorgis
2015-06-18 20:14 ` Eric Blake
2015-06-19 12:25 ` Stefan Hajnoczi
2015-05-20 9:57 ` [Qemu-devel] [PATCH v4 5/5] raw-posix: Introduce hdev_is_sg() Dimitris Aragiorgis
2015-06-18 20:16 ` Eric Blake
2015-06-19 12:33 ` Stefan Hajnoczi
2015-06-22 10:18 ` Dimitris Aragiorgis [this message]
2015-06-22 12:33 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2015-05-29 5:15 ` [Qemu-devel] [PATCH v4 0/5] Some fixes related to scsi-generic Dimitris Aragiorgis
2015-06-18 11:07 ` Dimitris Aragiorgis
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=20150622101843.GA16825@arr \
--to=dimara@arrikto.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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).