qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATC 7/9] Skipping drm build, unsupported
@ 2020-06-29 21:48 David CARLIER
  2020-06-30  6:44 ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 14+ messages in thread
From: David CARLIER @ 2020-06-29 21:48 UTC (permalink / raw)
  To: QEMU Trivial, qemu-devel

From 157a0374093371719de42e99364352d64190f52a Mon Sep 17 00:00:00 2001
From: David Carlier <devnexen@gmail.com>
Date: Mon, 29 Jun 2020 22:20:06 +0000
Subject: [PATCH 7/9] Skipping drm build, unsupported.

Signed-off-by: David Carlier <devnexen@gmail.com>
---
 util/Makefile.objs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/util/Makefile.objs b/util/Makefile.objs
index cc5e37177a..faebc13fac 100644
--- a/util/Makefile.objs
+++ b/util/Makefile.objs
@@ -39,7 +39,7 @@ util-obj-y += qsp.o
 util-obj-y += range.o
 util-obj-y += stats64.o
 util-obj-y += systemd.o
-util-obj-$(CONFIG_POSIX) += drm.o
+util-obj-$(CONFIG_LINUX) += drm.o
 util-obj-y += guest-random.o
 util-obj-$(CONFIG_GIO) += dbus.o
 dbus.o-cflags = $(GIO_CFLAGS)
--
2.26.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATC 7/9] Skipping drm build, unsupported
  2020-06-29 21:48 [PATC 7/9] Skipping drm build, unsupported David CARLIER
@ 2020-06-30  6:44 ` Philippe Mathieu-Daudé
  2020-06-30  8:23   ` Gerd Hoffmann
  0 siblings, 1 reply; 14+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-06-30  6:44 UTC (permalink / raw)
  To: David CARLIER, QEMU Trivial, qemu-devel, Gerd Hoffmann

+Gerd

On 6/29/20 11:48 PM, David CARLIER wrote:
> From 157a0374093371719de42e99364352d64190f52a Mon Sep 17 00:00:00 2001
> From: David Carlier <devnexen@gmail.com>
> Date: Mon, 29 Jun 2020 22:20:06 +0000
> Subject: [PATCH 7/9] Skipping drm build, unsupported.
> 
> Signed-off-by: David Carlier <devnexen@gmail.com>

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> ---
>  util/Makefile.objs | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/util/Makefile.objs b/util/Makefile.objs
> index cc5e37177a..faebc13fac 100644
> --- a/util/Makefile.objs
> +++ b/util/Makefile.objs
> @@ -39,7 +39,7 @@ util-obj-y += qsp.o
>  util-obj-y += range.o
>  util-obj-y += stats64.o
>  util-obj-y += systemd.o
> -util-obj-$(CONFIG_POSIX) += drm.o
> +util-obj-$(CONFIG_LINUX) += drm.o
>  util-obj-y += guest-random.o
>  util-obj-$(CONFIG_GIO) += dbus.o
>  dbus.o-cflags = $(GIO_CFLAGS)
> --
> 2.26.0
> 



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATC 7/9] Skipping drm build, unsupported
  2020-06-30  6:44 ` Philippe Mathieu-Daudé
@ 2020-06-30  8:23   ` Gerd Hoffmann
  2020-06-30  8:46     ` Philippe Mathieu-Daudé
  2020-06-30 15:53     ` Peter Maydell
  0 siblings, 2 replies; 14+ messages in thread
From: Gerd Hoffmann @ 2020-06-30  8:23 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé; +Cc: QEMU Trivial, David CARLIER, qemu-devel

On Tue, Jun 30, 2020 at 08:44:24AM +0200, Philippe Mathieu-Daudé wrote:
> +Gerd
> 
> On 6/29/20 11:48 PM, David CARLIER wrote:
> > From 157a0374093371719de42e99364352d64190f52a Mon Sep 17 00:00:00 2001
> > From: David Carlier <devnexen@gmail.com>
> > Date: Mon, 29 Jun 2020 22:20:06 +0000
> > Subject: [PATCH 7/9] Skipping drm build, unsupported.

--verbose please.

> > -util-obj-$(CONFIG_POSIX) += drm.o
> > +util-obj-$(CONFIG_LINUX) += drm.o

Can't see anything linux-specific there.  Also note that FreeBSD (and
possibly other *BSDs too) have drm support.  So CONFIG_POSIX looks
correct to me.

take care,
  Gerd



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATC 7/9] Skipping drm build, unsupported
  2020-06-30  8:23   ` Gerd Hoffmann
@ 2020-06-30  8:46     ` Philippe Mathieu-Daudé
  2020-06-30 15:48       ` Gerd Hoffmann
  2020-06-30 15:53     ` Peter Maydell
  1 sibling, 1 reply; 14+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-06-30  8:46 UTC (permalink / raw)
  To: Gerd Hoffmann
  Cc: QEMU Trivial, Daniel P . Berrange, David CARLIER, qemu-devel

On 6/30/20 10:23 AM, Gerd Hoffmann wrote:
> On Tue, Jun 30, 2020 at 08:44:24AM +0200, Philippe Mathieu-Daudé wrote:
>> +Gerd
>>
>> On 6/29/20 11:48 PM, David CARLIER wrote:
>>> From 157a0374093371719de42e99364352d64190f52a Mon Sep 17 00:00:00 2001
>>> From: David Carlier <devnexen@gmail.com>
>>> Date: Mon, 29 Jun 2020 22:20:06 +0000
>>> Subject: [PATCH 7/9] Skipping drm build, unsupported.
> 
> --verbose please.

David has difficulties understanding how to send patches,
so you missed the cover/context. This is for the Haiku OS
which apparently is POSIX.1-2001 compatible.

I don't know about DRI-1.0, maybe it is POSIX.1-2008?

>>> -util-obj-$(CONFIG_POSIX) += drm.o
>>> +util-obj-$(CONFIG_LINUX) += drm.o
> 
> Can't see anything linux-specific there.  Also note that FreeBSD (and
> possibly other *BSDs too) have drm support.  So CONFIG_POSIX looks
> correct to me.
> 
> take care,
>   Gerd
> 



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATC 7/9] Skipping drm build, unsupported
  2020-06-30  8:46     ` Philippe Mathieu-Daudé
@ 2020-06-30 15:48       ` Gerd Hoffmann
  2020-06-30 15:55         ` David CARLIER
  0 siblings, 1 reply; 14+ messages in thread
From: Gerd Hoffmann @ 2020-06-30 15:48 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: QEMU Trivial, Daniel P . Berrange, David CARLIER, qemu-devel

On Tue, Jun 30, 2020 at 10:46:59AM +0200, Philippe Mathieu-Daudé wrote:
> On 6/30/20 10:23 AM, Gerd Hoffmann wrote:
> > On Tue, Jun 30, 2020 at 08:44:24AM +0200, Philippe Mathieu-Daudé wrote:
> >> +Gerd
> >>
> >> On 6/29/20 11:48 PM, David CARLIER wrote:
> >>> From 157a0374093371719de42e99364352d64190f52a Mon Sep 17 00:00:00 2001
> >>> From: David Carlier <devnexen@gmail.com>
> >>> Date: Mon, 29 Jun 2020 22:20:06 +0000
> >>> Subject: [PATCH 7/9] Skipping drm build, unsupported.
> > 
> > --verbose please.
> 
> David has difficulties understanding how to send patches,
> so you missed the cover/context. This is for the Haiku OS
> which apparently is POSIX.1-2001 compatible.

That doesn't explain why he thinks this patch is needed.
It should build just fine on Haiku ...

take care,
  Gerd



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATC 7/9] Skipping drm build, unsupported
  2020-06-30  8:23   ` Gerd Hoffmann
  2020-06-30  8:46     ` Philippe Mathieu-Daudé
@ 2020-06-30 15:53     ` Peter Maydell
  2020-06-30 16:53       ` Gerd Hoffmann
  1 sibling, 1 reply; 14+ messages in thread
From: Peter Maydell @ 2020-06-30 15:53 UTC (permalink / raw)
  To: Gerd Hoffmann
  Cc: QEMU Trivial, David CARLIER, Philippe Mathieu-Daudé, qemu-devel

On Tue, 30 Jun 2020 at 09:24, Gerd Hoffmann <kraxel@redhat.com> wrote:
>
> On Tue, Jun 30, 2020 at 08:44:24AM +0200, Philippe Mathieu-Daudé wrote:
> > +Gerd
> >
> > On 6/29/20 11:48 PM, David CARLIER wrote:
> > > From 157a0374093371719de42e99364352d64190f52a Mon Sep 17 00:00:00 2001
> > > From: David Carlier <devnexen@gmail.com>
> > > Date: Mon, 29 Jun 2020 22:20:06 +0000
> > > Subject: [PATCH 7/9] Skipping drm build, unsupported.
>
> --verbose please.
>
> > > -util-obj-$(CONFIG_POSIX) += drm.o
> > > +util-obj-$(CONFIG_LINUX) += drm.o
>
> Can't see anything linux-specific there.  Also note that FreeBSD (and
> possibly other *BSDs too) have drm support.  So CONFIG_POSIX looks
> correct to me.

This change was my suggestion; I assumed that "open /dev/dri/whatever"
was Linux-specific. The specific thing that doesn't work on
Haiku, or on Solaris for that matter, is that the code uses
DT_CHR, which isn't in POSIX but is a Linux-and-BSDism.

thanks
-- PMM


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATC 7/9] Skipping drm build, unsupported
  2020-06-30 15:48       ` Gerd Hoffmann
@ 2020-06-30 15:55         ` David CARLIER
  2020-06-30 16:13           ` David CARLIER
  0 siblings, 1 reply; 14+ messages in thread
From: David CARLIER @ 2020-06-30 15:55 UTC (permalink / raw)
  To: Gerd Hoffmann
  Cc: QEMU Trivial, Daniel P . Berrange, Philippe Mathieu-Daudé,
	qemu-devel

1/ It does not compile on Haiku has dirent does not contain d_type
field (among other things).
2/ does not support drm anyway.
3/ Haiku is less portable than a illumos or NetBSD system, even with
the BSD compatibility layer.

On Tue, 30 Jun 2020 at 16:48, Gerd Hoffmann <kraxel@redhat.com> wrote:
>
> On Tue, Jun 30, 2020 at 10:46:59AM +0200, Philippe Mathieu-Daudé wrote:
> > On 6/30/20 10:23 AM, Gerd Hoffmann wrote:
> > > On Tue, Jun 30, 2020 at 08:44:24AM +0200, Philippe Mathieu-Daudé wrote:
> > >> +Gerd
> > >>
> > >> On 6/29/20 11:48 PM, David CARLIER wrote:
> > >>> From 157a0374093371719de42e99364352d64190f52a Mon Sep 17 00:00:00 2001
> > >>> From: David Carlier <devnexen@gmail.com>
> > >>> Date: Mon, 29 Jun 2020 22:20:06 +0000
> > >>> Subject: [PATCH 7/9] Skipping drm build, unsupported.
> > >
> > > --verbose please.
> >
> > David has difficulties understanding how to send patches,
> > so you missed the cover/context. This is for the Haiku OS
> > which apparently is POSIX.1-2001 compatible.
>
> That doesn't explain why he thinks this patch is needed.
> It should build just fine on Haiku ...
>
> take care,
>   Gerd
>


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATC 7/9] Skipping drm build, unsupported
  2020-06-30 15:55         ` David CARLIER
@ 2020-06-30 16:13           ` David CARLIER
  0 siblings, 0 replies; 14+ messages in thread
From: David CARLIER @ 2020-06-30 16:13 UTC (permalink / raw)
  To: Gerd Hoffmann
  Cc: QEMU Trivial, Daniel P . Berrange, Philippe Mathieu-Daudé,
	qemu-devel

Otherwise, if it is ok if not all patches are accepted (like this one)
but at least most of them would be nice then Haikuport can decrease
needed local patches.

Regards.

On Tue, 30 Jun 2020 at 16:55, David CARLIER <devnexen@gmail.com> wrote:
>
> 1/ It does not compile on Haiku has dirent does not contain d_type
> field (among other things).
> 2/ does not support drm anyway.
> 3/ Haiku is less portable than a illumos or NetBSD system, even with
> the BSD compatibility layer.
>
> On Tue, 30 Jun 2020 at 16:48, Gerd Hoffmann <kraxel@redhat.com> wrote:
> >
> > On Tue, Jun 30, 2020 at 10:46:59AM +0200, Philippe Mathieu-Daudé wrote:
> > > On 6/30/20 10:23 AM, Gerd Hoffmann wrote:
> > > > On Tue, Jun 30, 2020 at 08:44:24AM +0200, Philippe Mathieu-Daudé wrote:
> > > >> +Gerd
> > > >>
> > > >> On 6/29/20 11:48 PM, David CARLIER wrote:
> > > >>> From 157a0374093371719de42e99364352d64190f52a Mon Sep 17 00:00:00 2001
> > > >>> From: David Carlier <devnexen@gmail.com>
> > > >>> Date: Mon, 29 Jun 2020 22:20:06 +0000
> > > >>> Subject: [PATCH 7/9] Skipping drm build, unsupported.
> > > >
> > > > --verbose please.
> > >
> > > David has difficulties understanding how to send patches,
> > > so you missed the cover/context. This is for the Haiku OS
> > > which apparently is POSIX.1-2001 compatible.
> >
> > That doesn't explain why he thinks this patch is needed.
> > It should build just fine on Haiku ...
> >
> > take care,
> >   Gerd
> >


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATC 7/9] Skipping drm build, unsupported
  2020-06-30 15:53     ` Peter Maydell
@ 2020-06-30 16:53       ` Gerd Hoffmann
  2020-07-01 14:16         ` Eric Blake
  0 siblings, 1 reply; 14+ messages in thread
From: Gerd Hoffmann @ 2020-06-30 16:53 UTC (permalink / raw)
  To: Peter Maydell
  Cc: QEMU Trivial, David CARLIER, Philippe Mathieu-Daudé, qemu-devel

> > > > -util-obj-$(CONFIG_POSIX) += drm.o
> > > > +util-obj-$(CONFIG_LINUX) += drm.o
> >
> > Can't see anything linux-specific there.  Also note that FreeBSD (and
> > possibly other *BSDs too) have drm support.  So CONFIG_POSIX looks
> > correct to me.
> 
> This change was my suggestion; I assumed that "open /dev/dri/whatever"
> was Linux-specific. The specific thing that doesn't work on
> Haiku, or on Solaris for that matter, is that the code uses
> DT_CHR, which isn't in POSIX but is a Linux-and-BSDism.

Ah, that is the problem.  Yes, DT_CHR is an non-posix optimization which
allows to get the file type directly, without another round-trip to the
kernel.  If that isn't available you can stat() the file and check
((st_mode & S_IFMT) == S_IFCHR) instead.

take care,
  Gerd



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATC 7/9] Skipping drm build, unsupported
  2020-06-30 16:53       ` Gerd Hoffmann
@ 2020-07-01 14:16         ` Eric Blake
  2020-07-01 15:15           ` Gerd Hoffmann
  0 siblings, 1 reply; 14+ messages in thread
From: Eric Blake @ 2020-07-01 14:16 UTC (permalink / raw)
  To: Gerd Hoffmann, Peter Maydell
  Cc: QEMU Trivial, David CARLIER, Philippe Mathieu-Daudé, qemu-devel

On 6/30/20 11:53 AM, Gerd Hoffmann wrote:
>>>>> -util-obj-$(CONFIG_POSIX) += drm.o
>>>>> +util-obj-$(CONFIG_LINUX) += drm.o
>>>
>>> Can't see anything linux-specific there.  Also note that FreeBSD (and
>>> possibly other *BSDs too) have drm support.  So CONFIG_POSIX looks
>>> correct to me.
>>
>> This change was my suggestion; I assumed that "open /dev/dri/whatever"
>> was Linux-specific. The specific thing that doesn't work on
>> Haiku, or on Solaris for that matter, is that the code uses
>> DT_CHR, which isn't in POSIX but is a Linux-and-BSDism.
> 
> Ah, that is the problem.  Yes, DT_CHR is an non-posix optimization which
> allows to get the file type directly, without another round-trip to the
> kernel.  If that isn't available you can stat() the file and check
> ((st_mode & S_IFMT) == S_IFCHR) instead.

Even when d_type and DT_CHR is available, there are filesystems where 
the Linux kernel reports d_type of DT_UNKNOWN, and where you are best 
having that code also falling back to an fstat().  In short, any 
portable code that uses d_type should have fallback code for DT_UNKNOWN, 
at which point porting to systems without d_type is as easy as writing 
an accessor macro that returns d_type when it exists and DT_UNKNOWN 
where it doesn't.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATC 7/9] Skipping drm build, unsupported
  2020-07-01 14:16         ` Eric Blake
@ 2020-07-01 15:15           ` Gerd Hoffmann
  2020-07-01 15:48             ` David CARLIER
                               ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Gerd Hoffmann @ 2020-07-01 15:15 UTC (permalink / raw)
  To: Eric Blake
  Cc: QEMU Trivial, Peter Maydell, David CARLIER,
	Philippe Mathieu-Daudé,
	qemu-devel

> > Ah, that is the problem.  Yes, DT_CHR is an non-posix optimization which
> > allows to get the file type directly, without another round-trip to the
> > kernel.  If that isn't available you can stat() the file and check
> > ((st_mode & S_IFMT) == S_IFCHR) instead.
> 
> Even when d_type and DT_CHR is available, there are filesystems where the
> Linux kernel reports d_type of DT_UNKNOWN, and where you are best having
> that code also falling back to an fstat().

Given this isn't perforance critical at all it is probably simplest to
avoid non-portable d_type altogether and just to the fstat
unconditionally.

David, does that work for haiku?

take care,
  Gerd

diff --git a/util/drm.c b/util/drm.c
index a23ff2453826..a1d3520d00f2 100644
--- a/util/drm.c
+++ b/util/drm.c
@@ -24,6 +24,7 @@ int qemu_drm_rendernode_open(const char *rendernode)
 {
     DIR *dir;
     struct dirent *e;
+    struct stat st;
     int r, fd;
     char *p;
 
@@ -38,10 +39,6 @@ int qemu_drm_rendernode_open(const char *rendernode)
 
     fd = -1;
     while ((e = readdir(dir))) {
-        if (e->d_type != DT_CHR) {
-            continue;
-        }
-
         if (strncmp(e->d_name, "renderD", 7)) {
             continue;
         }
@@ -53,6 +50,12 @@ int qemu_drm_rendernode_open(const char *rendernode)
             g_free(p);
             continue;
         }
+        fstat(r, &st);
+        if ((st.st_mode & S_IFMT) != S_IFCHR) {
+            close(r);
+            g_free(p);
+            continue;
+        }
         fd = r;
         g_free(p);
         break;



^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATC 7/9] Skipping drm build, unsupported
  2020-07-01 15:15           ` Gerd Hoffmann
@ 2020-07-01 15:48             ` David CARLIER
  2020-07-01 16:04             ` Philippe Mathieu-Daudé
  2020-07-01 16:53             ` Peter Maydell
  2 siblings, 0 replies; 14+ messages in thread
From: David CARLIER @ 2020-07-01 15:48 UTC (permalink / raw)
  To: Gerd Hoffmann
  Cc: QEMU Trivial, Peter Maydell, qemu-devel, Philippe Mathieu-Daudé

Yes it does. Regards.

On Wed, 1 Jul 2020 at 16:15, Gerd Hoffmann <kraxel@redhat.com> wrote:
>
> > > Ah, that is the problem.  Yes, DT_CHR is an non-posix optimization which
> > > allows to get the file type directly, without another round-trip to the
> > > kernel.  If that isn't available you can stat() the file and check
> > > ((st_mode & S_IFMT) == S_IFCHR) instead.
> >
> > Even when d_type and DT_CHR is available, there are filesystems where the
> > Linux kernel reports d_type of DT_UNKNOWN, and where you are best having
> > that code also falling back to an fstat().
>
> Given this isn't perforance critical at all it is probably simplest to
> avoid non-portable d_type altogether and just to the fstat
> unconditionally.
>
> David, does that work for haiku?
>
> take care,
>   Gerd
>
> diff --git a/util/drm.c b/util/drm.c
> index a23ff2453826..a1d3520d00f2 100644
> --- a/util/drm.c
> +++ b/util/drm.c
> @@ -24,6 +24,7 @@ int qemu_drm_rendernode_open(const char *rendernode)
>  {
>      DIR *dir;
>      struct dirent *e;
> +    struct stat st;
>      int r, fd;
>      char *p;
>
> @@ -38,10 +39,6 @@ int qemu_drm_rendernode_open(const char *rendernode)
>
>      fd = -1;
>      while ((e = readdir(dir))) {
> -        if (e->d_type != DT_CHR) {
> -            continue;
> -        }
> -
>          if (strncmp(e->d_name, "renderD", 7)) {
>              continue;
>          }
> @@ -53,6 +50,12 @@ int qemu_drm_rendernode_open(const char *rendernode)
>              g_free(p);
>              continue;
>          }
> +        fstat(r, &st);
> +        if ((st.st_mode & S_IFMT) != S_IFCHR) {
> +            close(r);
> +            g_free(p);
> +            continue;
> +        }
>          fd = r;
>          g_free(p);
>          break;
>


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATC 7/9] Skipping drm build, unsupported
  2020-07-01 15:15           ` Gerd Hoffmann
  2020-07-01 15:48             ` David CARLIER
@ 2020-07-01 16:04             ` Philippe Mathieu-Daudé
  2020-07-01 16:53             ` Peter Maydell
  2 siblings, 0 replies; 14+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-07-01 16:04 UTC (permalink / raw)
  To: Gerd Hoffmann, Eric Blake
  Cc: QEMU Trivial, Peter Maydell, David CARLIER, qemu-devel

Hi Gerd,

On 7/1/20 5:15 PM, Gerd Hoffmann wrote:
>>> Ah, that is the problem.  Yes, DT_CHR is an non-posix optimization which
>>> allows to get the file type directly, without another round-trip to the
>>> kernel.  If that isn't available you can stat() the file and check
>>> ((st_mode & S_IFMT) == S_IFCHR) instead.
>>
>> Even when d_type and DT_CHR is available, there are filesystems where the
>> Linux kernel reports d_type of DT_UNKNOWN, and where you are best having
>> that code also falling back to an fstat().
> 
> Given this isn't perforance critical at all it is probably simplest to
> avoid non-portable d_type altogether and just to the fstat
> unconditionally.
> 
> David, does that work for haiku?
> 
> take care,
>   Gerd
> 
> diff --git a/util/drm.c b/util/drm.c
> index a23ff2453826..a1d3520d00f2 100644
> --- a/util/drm.c
> +++ b/util/drm.c
> @@ -24,6 +24,7 @@ int qemu_drm_rendernode_open(const char *rendernode)
>  {
>      DIR *dir;
>      struct dirent *e;
> +    struct stat st;
>      int r, fd;
>      char *p;
>  
> @@ -38,10 +39,6 @@ int qemu_drm_rendernode_open(const char *rendernode)
>  
>      fd = -1;
>      while ((e = readdir(dir))) {
> -        if (e->d_type != DT_CHR) {
> -            continue;
> -        }
> -
>          if (strncmp(e->d_name, "renderD", 7)) {
>              continue;
>          }
> @@ -53,6 +50,12 @@ int qemu_drm_rendernode_open(const char *rendernode)
>              g_free(p);
>              continue;
>          }
> +        fstat(r, &st);

While preparing the formal patch, can you add a comment here explaining
we deliberately use this way for portability (not checking DT_CHR /
DT_UNKNOWN ...)?

Thanks!

> +        if ((st.st_mode & S_IFMT) != S_IFCHR) {
> +            close(r);
> +            g_free(p);
> +            continue;
> +        }
>          fd = r;
>          g_free(p);
>          break;
> 



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATC 7/9] Skipping drm build, unsupported
  2020-07-01 15:15           ` Gerd Hoffmann
  2020-07-01 15:48             ` David CARLIER
  2020-07-01 16:04             ` Philippe Mathieu-Daudé
@ 2020-07-01 16:53             ` Peter Maydell
  2 siblings, 0 replies; 14+ messages in thread
From: Peter Maydell @ 2020-07-01 16:53 UTC (permalink / raw)
  To: Gerd Hoffmann
  Cc: QEMU Trivial, Philippe Mathieu-Daudé, David CARLIER, qemu-devel

On Wed, 1 Jul 2020 at 16:15, Gerd Hoffmann <kraxel@redhat.com> wrote:
>
> > > Ah, that is the problem.  Yes, DT_CHR is an non-posix optimization which
> > > allows to get the file type directly, without another round-trip to the
> > > kernel.  If that isn't available you can stat() the file and check
> > > ((st_mode & S_IFMT) == S_IFCHR) instead.
> >
> > Even when d_type and DT_CHR is available, there are filesystems where the
> > Linux kernel reports d_type of DT_UNKNOWN, and where you are best having
> > that code also falling back to an fstat().
>
> Given this isn't perforance critical at all it is probably simplest to
> avoid non-portable d_type altogether and just to the fstat
> unconditionally.

> @@ -53,6 +50,12 @@ int qemu_drm_rendernode_open(const char *rendernode)
>              g_free(p);
>              continue;
>          }
> +        fstat(r, &st);

Don't forget to check the fstat return code in the final
version of this patch :-)

thanks
-- PMM


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2020-07-01 16:54 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-29 21:48 [PATC 7/9] Skipping drm build, unsupported David CARLIER
2020-06-30  6:44 ` Philippe Mathieu-Daudé
2020-06-30  8:23   ` Gerd Hoffmann
2020-06-30  8:46     ` Philippe Mathieu-Daudé
2020-06-30 15:48       ` Gerd Hoffmann
2020-06-30 15:55         ` David CARLIER
2020-06-30 16:13           ` David CARLIER
2020-06-30 15:53     ` Peter Maydell
2020-06-30 16:53       ` Gerd Hoffmann
2020-07-01 14:16         ` Eric Blake
2020-07-01 15:15           ` Gerd Hoffmann
2020-07-01 15:48             ` David CARLIER
2020-07-01 16:04             ` Philippe Mathieu-Daudé
2020-07-01 16:53             ` Peter Maydell

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).