Received: from eggs.gnu.org ([2001:4830:134:3::10]:58996) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1azxm0-0000uX-EK for qemu-devel@nongnu.org; Mon, 09 May 2016 22:51:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1azxly-0004b9-1h for qemu-devel@nongnu.org; Mon, 09 May 2016 22:51:47 -0400 From: Fam Zheng Date: Tue, 10 May 2016 10:50:41 +0800 Message-Id: <1462848659-28659-10-git-send-email-famz@redhat.com> In-Reply-To: <1462848659-28659-1-git-send-email-famz@redhat.com> References: <1462848659-28659-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [PATCH v4 09/27] osdep: Introduce qemu_dup List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Max Reitz , Jeff Cody , Markus Armbruster , Eric Blake , qemu-block@nongnu.org, rjones@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, John Snow , berrange@redhat.com, den@openvz.org This takes care both the CLOEXEC flag and fd-path mapping for image locking. Signed-off-by: Fam Zheng --- include/qemu/osdep.h | 1 + util/osdep.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 089c13f..8174902 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -251,6 +251,7 @@ int qemu_madvise(void *addr, size_t len, int advice); int qemu_open(const char *name, int flags, ...); int qemu_close(int fd); +int qemu_dup(int fd); int qemu_lock_fd(int fd, int64_t start, int64_t len, bool readonly); int qemu_unlock_fd(int fd, int64_t start, int64_t len); diff --git a/util/osdep.c b/util/osdep.c index 1510cbf..66c993a 100644 --- a/util/osdep.c +++ b/util/osdep.c @@ -408,6 +408,21 @@ int qemu_close(int fd) return qemu_fd_close(fd); } +int qemu_dup(int fd) +{ + char *path; + int ret = qemu_dup_flags(fd, 0); + if (ret == -1) { + return ret; + } + + path = g_hash_table_lookup(fd_to_path, GINT_TO_POINTER(fd)); + assert(path); + qemu_fd_add_record(ret, path); + return ret; +} + + /* * A variant of write(2) which handles partial write. * -- 2.8.2