Message ID | 4dc484ae240edf8df0de14edefc3c3a717a1c781.1717140354.git.mprivozn@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | backends/hostmem: Report more errors on failures | expand |
On 31/5/24 09:28, Michal Privoznik wrote: > Not every OS is capable of madvise() or posix_madvise() even. In > that case, errno should be set to ENOSYS as it reflects the cause > better. This also mimic what madvise()/posix_madvise() would > return if kernel lacks corresponding syscall (e.g. due to > configuration). > > Signed-off-by: Michal Privoznik <mprivozn@redhat.com> > --- > util/osdep.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
On 31.05.24 09:28, Michal Privoznik wrote: > Not every OS is capable of madvise() or posix_madvise() even. In > that case, errno should be set to ENOSYS as it reflects the cause > better. This also mimic what madvise()/posix_madvise() would > return if kernel lacks corresponding syscall (e.g. due to > configuration). Yes and no. According to the man page " EINVAL advice is not a valid." if a particular MADV_* call is not implemented, we would get EINVAL, which is really unfortunate ... to detect what is actually supported :( For the patch here ENOSYS makes sense: Reviewed-by: David Hildenbrand <david@redhat.com>
On 31/5/24 09:53, David Hildenbrand wrote: > On 31.05.24 09:28, Michal Privoznik wrote: >> Not every OS is capable of madvise() or posix_madvise() even. In >> that case, errno should be set to ENOSYS as it reflects the cause >> better. This also mimic what madvise()/posix_madvise() would >> return if kernel lacks corresponding syscall (e.g. due to >> configuration). > > Yes and no. According to the man page > > " EINVAL advice is not a valid." > > if a particular MADV_* call is not implemented, we would get EINVAL, > which is really unfortunate ... to detect what is actually supported :( Maybe skip "This also mimic what madvise()/posix_madvise() would return if kernel lacks corresponding syscall (e.g. due to configuration)." for clarity? > For the patch here ENOSYS makes sense: > > Reviewed-by: David Hildenbrand <david@redhat.com> >
diff --git a/util/osdep.c b/util/osdep.c index e42f4e8121..5d23bbfbec 100644 --- a/util/osdep.c +++ b/util/osdep.c @@ -64,7 +64,7 @@ int qemu_madvise(void *addr, size_t len, int advice) } return 0; #else - errno = EINVAL; + errno = ENOSYS; return -1; #endif }
Not every OS is capable of madvise() or posix_madvise() even. In that case, errno should be set to ENOSYS as it reflects the cause better. This also mimic what madvise()/posix_madvise() would return if kernel lacks corresponding syscall (e.g. due to configuration). Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- util/osdep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)