block: Add qemu_dup in osdep.c and use it
cover block: Add qemu_dup in osdep.c and use it
This is an independent tiny change extracted from the image locking series, which can be processed separately.
Improved according to Kevin's suggestion in v6 image locking series.
Fam
Fam Zheng (2):
osdep: Introduce qemu_dup
raw-posix: Use qemu_dup
block/raw-posix.c | 10 +--------- include/qemu/osdep.h | 3 +++ util/osdep.c | 23 +++++++++++++++-------- 3 files changed, 19 insertions(+), 17 deletions(-)
Signature · 1 line
2.9.0
PATCH 1/2 osdep: Introduce qemu_dup
And use it in qemu_dup_flags.
--- include/qemu/osdep.h | 3 +++ util/osdep.c | 23 +++++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-)
include/qemu/osdep.h +3 -0
@@ -278,6 +278,9 @@ int qemu_madvise(void *addr, size_t len, int advice);int qemu_open (const char *name,int flags, ...);int qemu_close (int fd); +#ifndef _WIN32 +int qemu_dup (int fd); +#endif #if defined(__HAIKU__) && defined(__i386__)#define FMT_pid "%ld"
util/osdep.c +15 -8
@@ -83,14 +83,7 @@ static int qemu_dup_flags(int fd, int flags)int serrno;int dup_flags; -#ifdef F_DUPFD_CLOEXEC - ret =fcntl (fd,F_DUPFD_CLOEXEC ,0 ); -#else - ret =dup (fd); -if (ret !=-1 ) { -qemu_set_cloexec (ret); - } -#endif + ret =qemu_dup (fd);if (ret ==-1 ) { goto fail; }
@@ -129,6 +122,20 @@ fail:return -1 ; } +int qemu_dup (int fd) +{ +int r; +#ifdef F_DUPFD_CLOEXEC + r =fcntl (fd,F_DUPFD_CLOEXEC ,0 ); +#else + r =dup (fd); +if (r !=-1 ) { +qemu_set_cloexec (raw_s->fd); + } +#endif +return r; +} +static int qemu_parse_fdset (const char *param) {return qemu_parse_fd (param);
Signature · 1 line
2.9.0
Re: [Qemu-devel] [PATCH 1/2] osdep: Introduce qemu_dup
Am 22.06.2016 um 10:02 hat Fam Zheng geschrieben:
Quoted 43 lines
And use it in
qemu_dup_flags.Signed-off-by Fam Zheng <[email protected]>--- include/qemu/osdep.h | 3 +++ util/osdep.c | 23 +++++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-)include/qemu/osdep.h +3
-0@@ -278,6 +278,9 @@ int qemu_madvise(void *addr, size_t len, int advice);int qemu_open (const char *name,int flags, ...);int qemu_close (int fd); +#ifndef _WIN32 +int qemu_dup (int fd); +#endif #if defined(__HAIKU__) && defined(__i386__)#define FMT_pid "%ld"util/osdep.c +1
-8@@ -83,14 +83,7 @@ static int qemu_dup_flags(int fd, int flags)int serrno;int dup_flags; -#ifdef F_DUPFD_CLOEXEC - ret =fcntl (fd,F_DUPFD_CLOEXEC ,0 ); -#else - ret =dup (fd); -if (ret !=-1 ) { -qemu_set_cloexec (ret); - } -#endif + ret =qemu_dup (fd);if (ret ==-1 ) { goto fail; }
util/osdep.c fail: · line 127
Quoted 6 lines
util/osdep.c +3
-0@@ -129,6 +122,20 @@ fail:return -1 ; } +int qemu_dup (int fd) +{ +int r;
Why the rename? (Not necessarily objecting, just curious.)
util/osdep.c fail: · line 133
Quoted 6 lines
util/osdep.c +6
-0+#ifdef F_DUPFD_CLOEXEC + r =fcntl (fd,F_DUPFD_CLOEXEC ,0 ); +#else + r =dup (fd); +if (r !=-1 ) { +qemu_set_cloexec (raw_s->fd);
This won't compile.
Kevin
Re: [Qemu-devel] [PATCH 1/2] osdep: Introduce qemu_dup
Quoted 24 lines · Kevin Wolf
Quoted 24 lines
util/osdep.c +1
-8@@ -83,14 +83,7 @@ static int qemu_dup_flags(int fd, int flags)int serrno;int dup_flags; -#ifdef F_DUPFD_CLOEXEC - ret =fcntl (fd,F_DUPFD_CLOEXEC ,0 ); -#else - ret =dup (fd); -if (ret !=-1 ) { -qemu_set_cloexec (ret); - } -#endif + ret =qemu_dup (fd);if (ret ==-1 ) { goto fail; }@@ -129,6 +122,20 @@ fail:return -1 ; }
Quoted 5 lines
util/osdep.c fail: · line 127
Quoted 3 lines
util/osdep.c +3
-0+int qemu_dup (int fd) +{ +int r;Why the rename? (Not necessarily objecting, just curious.)
Obviously I should have copied from qemu_dup_flags instead of raw_reopen_prepare. :(
Quoted 9 lines
util/osdep.c fail: · line 133
Quoted 7 lines
util/osdep.c +6
-0+#ifdef F_DUPFD_CLOEXEC + r =fcntl (fd,F_DUPFD_CLOEXEC ,0 ); +#else + r =dup (fd); +if (r !=-1 ) { +qemu_set_cloexec (raw_s->fd);This won't compile.
Will fix.
Fam
Re: [Qemu-devel] [PATCH 1/2] osdep: Introduce qemu_dup
In reply to Fam ZhengQuoted 8 lines · Fam Zheng
And use it in
qemu_dup_flags.Signed-off-by Fam Zheng <[email protected]>--- include/qemu/osdep.h | 3 +++ util/osdep.c | 23 +++++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-)
util/osdep.c fail: · line 133
Quoted 9 lines
util/osdep.c +9
-0+int qemu_dup (int fd) +{ +int r; +#ifdef F_DUPFD_CLOEXEC + r =fcntl (fd,F_DUPFD_CLOEXEC ,0 ); +#else + r =dup (fd); +if (r !=-1 ) { +qemu_set_cloexec (raw_s->fd);
Uhh, don't you mean s/raw_s->fd/r/ ?
Quoted 9 lines
util/osdep.c +5
-0+ } +#endif +return r; +} +static int qemu_parse_fdset (const char *param) {return qemu_parse_fd (param);
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 2/2 raw-posix: Use qemu_dup
In reply to Fam Zheng--- block/raw-posix.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
block/raw-posix.c +1 -9
@@ -639,15 +639,7 @@ static int raw_reopen_prepare(BDRVReopenState *state,if ((raw_s->open_flags & ~fcntl_flags) == (s->open_flags & ~fcntl_flags)) {/* dup the original fd */ -/* TODO: use qemu fcntl wrapper */ -#ifdef F_DUPFD_CLOEXEC - raw_s->fd =fcntl (s->fd,F_DUPFD_CLOEXEC ,0 ); -#else - raw_s->fd =dup (s->fd); -if (raw_s->fd !=-1 ) { -qemu_set_cloexec (raw_s->fd); - } -#endif + raw_s->fd =qemu_dup (s->fd);if (raw_s->fd >=0 ) { ret =fcntl_setfl (raw_s->fd, raw_s->open_flags);if (ret) {
Signature · 1 line
2.9.0
Re: [Qemu-devel] [PATCH 2/2] raw-posix: Use qemu_dup
Am 22.06.2016 um 10:02 hat Fam Zheng geschrieben:
Quoted 2 lines
Signed-off-by Fam Zheng <[email protected]>Reviewed-by Max Reitz <[email protected]>