9pfs: use event_notifier instead of qemu_pipe 66/23666/3
authorSeokYeon Hwang <syeon.hwang@samsung.com>
Tue, 1 Jul 2014 08:12:05 +0000 (17:12 +0900)
committerSooyoung Ha <yoosah.ha@samsung.com>
Wed, 2 Jul 2014 05:48:29 +0000 (14:48 +0900)
Change-Id: I5b2c51ef18849fa6f29e126ef889dcff86cad645
Signed-off-by: SeokYeon Hwang <syeon.hwang@samsung.com>
Signed-off-by: Sooyoung Ha <yoosah.ha@samsung.com>
hw/9pfs/Makefile.objs
hw/9pfs/virtio-9p-coth-maru.c [deleted file]
hw/9pfs/virtio-9p-coth.c
hw/9pfs/virtio-9p-coth.h
tizen/src/resources_win32.h

index 7e9264c92efbb13eeed3347fcff7b353ac51969f..6bd86c1d30b01f05b0d691805853e80d9b6efafd 100644 (file)
@@ -1,7 +1,14 @@
 ifeq ($(CONFIG_MARU),y)
 common-obj-y  = virtio-9p-maru.o
 common-obj-y += virtio-9p-local-maru.o
-common-obj-y += virtio-9p-coth-maru.o cofs.o codir.o cofile.o
+endif
+
+ifneq ($(CONFIG_MARU),y)
+common-obj-y  = virtio-9p.o
+common-obj-y += virtio-9p-local.o
+endif
+
+common-obj-y += virtio-9p-coth.o cofs.o codir.o cofile.o
 ifneq ($(CONFIG_WIN32),y)
 common-obj-y += virtio-9p-xattr-user.o virtio-9p-posix-acl.o
 common-obj-y += virtio-9p-xattr.o coxattr.o
@@ -11,16 +18,3 @@ common-obj-$(CONFIG_LINUX) += virtio-9p-proxy.o
 common-obj-$(CONFIG_OPEN_BY_HANDLE) +=  virtio-9p-handle.o
 
 obj-y += virtio-9p-device.o
-endif
-
-ifneq ($(CONFIG_MARU),y)
-common-obj-y  = virtio-9p.o
-common-obj-y += virtio-9p-local.o virtio-9p-xattr.o
-common-obj-y += virtio-9p-xattr-user.o virtio-9p-posix-acl.o
-common-obj-y += virtio-9p-coth.o cofs.o codir.o cofile.o
-common-obj-y += coxattr.o virtio-9p-synth.o
-common-obj-$(CONFIG_OPEN_BY_HANDLE) +=  virtio-9p-handle.o
-common-obj-y += virtio-9p-proxy.o
-
-obj-y += virtio-9p-device.o
-endif
diff --git a/hw/9pfs/virtio-9p-coth-maru.c b/hw/9pfs/virtio-9p-coth-maru.c
deleted file mode 100644 (file)
index d86a302..0000000
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * Virtio 9p backend for Maru
- * Based on hw/9pfs/virtio-9p-coth.c:
- *
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Contact:
- *  Sooyoung Ha <yoosah.ha@samsung.com>
- *  YeongKyoon Lee <yeongkyoon.lee@samsung.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-
-#include "fsdev/qemu-fsdev.h"
-#include "qemu/thread.h"
-#include "block/coroutine.h"
-#include "virtio-9p-coth.h"
-
-#ifdef CONFIG_WIN32
-#include <winsock2.h>
-#endif
-
-#include "../../tizen/src/debug_ch.h"
-MULTI_DEBUG_CHANNEL(tizen, qemu_9p_coth);
-
-/* v9fs glib thread pool */
-static V9fsThPool v9fs_pool;
-
-void co_run_in_worker_bh(void *opaque)
-{
-    Coroutine *co = opaque;
-    g_thread_pool_push(v9fs_pool.pool, co, NULL);
-}
-
-static void v9fs_qemu_process_req_done(void *arg)
-{
-    char byte;
-    ssize_t len;
-    Coroutine *co;
-
-    do {
-#ifndef CONFIG_WIN32
-        len = read(v9fs_pool.rfd, &byte, sizeof(byte));
-#else
-        struct sockaddr_in saddr;
-        int recv_size = sizeof(saddr);
-        len = recvfrom((SOCKET)v9fs_pool.rfd, &byte, sizeof(byte), 0, (struct sockaddr *)&saddr, &recv_size);
-#endif
-    } while (len == -1 &&  errno == EINTR);
-
-    while ((co = g_async_queue_try_pop(v9fs_pool.completed)) != NULL) {
-        qemu_coroutine_enter(co, NULL);
-    }
-}
-
-static void v9fs_thread_routine(gpointer data, gpointer user_data)
-{
-    ssize_t len = 0;
-    char byte = 0;
-    Coroutine *co = data;
-
-    qemu_coroutine_enter(co, NULL);
-
-    g_async_queue_push(v9fs_pool.completed, co);
-    do {
-#ifndef CONFIG_WIN32
-        len = write(v9fs_pool.wfd, &byte, sizeof(byte));
-#else
-        struct sockaddr_in saddr;
-        saddr.sin_family = AF_INET;
-        saddr.sin_addr.s_addr = inet_addr("127.0.0.1");
-        saddr.sin_port=htons(9190);
-        len = sendto((SOCKET)v9fs_pool.wfd, &byte, sizeof(byte), 0, (const struct sockaddr *)&saddr, sizeof(saddr));
-#endif
-    } while (len == -1 && errno == EINTR);
-}
-
-int v9fs_init_worker_threads(void)
-{
-    TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
-    int ret = 0;
-    V9fsThPool *p = &v9fs_pool;
-#ifndef CONFIG_WIN32
-    int notifier_fds[2];
-    sigset_t set, oldset;
-
-    sigfillset(&set);
-    /* Leave signal handling to the iothread.  */
-    pthread_sigmask(SIG_SETMASK, &set, &oldset);
-
-    if (qemu_pipe(notifier_fds) == -1) {
-        ret = -1;
-        goto err_out;
-    }
-#else
-    WSADATA wsadata;
-    struct sockaddr_in saddr;
-
-    WSAStartup(MAKEWORD(2,2),&wsadata);
-
-    SOCKET pSock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
-
-    saddr.sin_family = AF_INET;
-    saddr.sin_addr.s_addr = htonl(INADDR_ANY);
-    saddr.sin_port=htons(9190);
-
-    if(bind(pSock, (const struct sockaddr *)&saddr, sizeof(saddr)) == -1){
-        ERR("[%d][%s] >> bind err: %d \n", __LINE__, __func__, WSAGetLastError());
-    } else {
-        TRACE("[%d][%s] >> bind ok\n", __LINE__, __func__);
-    }
-#endif
-    p->pool = g_thread_pool_new(v9fs_thread_routine, p, -1, FALSE, NULL);
-    if (!p->pool) {
-        ret = -1;
-        goto err_out;
-    }
-    p->completed = g_async_queue_new();
-    if (!p->completed) {
-        /*
-         * We are going to terminate.
-         * So don't worry about cleanup
-         */
-        ret = -1;
-        goto err_out;
-    }
-#ifndef CONFIG_WIN32
-    p->rfd = notifier_fds[0];
-    p->wfd = notifier_fds[1];
-
-    fcntl(p->rfd, F_SETFL, O_NONBLOCK);
-    fcntl(p->wfd, F_SETFL, O_NONBLOCK);
-#else
-    p->rfd = (int)pSock;
-    p->wfd = (int)pSock;
-#endif
-
-    qemu_set_fd_handler(p->rfd, v9fs_qemu_process_req_done, NULL, NULL);
-err_out:
-#ifndef CONFIG_WIN32
-    pthread_sigmask(SIG_SETMASK, &oldset, NULL);
-#endif
-    TRACE("[%d][ Leave >> %s]\n", __LINE__, __func__);
-    return ret;
-}
index ae6cde80053e5894aada975e1a0731a3d8d9ac4f..99056f1215e7f65ce8690423b57f6176a18f2deb 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "fsdev/qemu-fsdev.h"
 #include "qemu/thread.h"
+#include "qemu/event_notifier.h"
 #include "block/coroutine.h"
 #include "virtio-9p-coth.h"
 
@@ -26,15 +27,11 @@ void co_run_in_worker_bh(void *opaque)
     g_thread_pool_push(v9fs_pool.pool, co, NULL);
 }
 
-static void v9fs_qemu_process_req_done(void *arg)
+static void v9fs_qemu_process_req_done(EventNotifier *e)
 {
-    char byte;
-    ssize_t len;
     Coroutine *co;
 
-    do {
-        len = read(v9fs_pool.rfd, &byte, sizeof(byte));
-    } while (len == -1 &&  errno == EINTR);
+    event_notifier_test_and_clear(e);
 
     while ((co = g_async_queue_try_pop(v9fs_pool.completed)) != NULL) {
         qemu_coroutine_enter(co, NULL);
@@ -43,33 +40,27 @@ static void v9fs_qemu_process_req_done(void *arg)
 
 static void v9fs_thread_routine(gpointer data, gpointer user_data)
 {
-    ssize_t len;
-    char byte = 0;
     Coroutine *co = data;
 
     qemu_coroutine_enter(co, NULL);
 
     g_async_queue_push(v9fs_pool.completed, co);
-    do {
-        len = write(v9fs_pool.wfd, &byte, sizeof(byte));
-    } while (len == -1 && errno == EINTR);
+
+    event_notifier_set(&v9fs_pool.e);
 }
 
 int v9fs_init_worker_threads(void)
 {
     int ret = 0;
-    int notifier_fds[2];
     V9fsThPool *p = &v9fs_pool;
+#ifndef __WIN32
     sigset_t set, oldset;
 
     sigfillset(&set);
     /* Leave signal handling to the iothread.  */
     pthread_sigmask(SIG_SETMASK, &set, &oldset);
+#endif
 
-    if (qemu_pipe(notifier_fds) == -1) {
-        ret = -1;
-        goto err_out;
-    }
     p->pool = g_thread_pool_new(v9fs_thread_routine, p, -1, FALSE, NULL);
     if (!p->pool) {
         ret = -1;
@@ -84,14 +75,13 @@ int v9fs_init_worker_threads(void)
         ret = -1;
         goto err_out;
     }
-    p->rfd = notifier_fds[0];
-    p->wfd = notifier_fds[1];
 
-    fcntl(p->rfd, F_SETFL, O_NONBLOCK);
-    fcntl(p->wfd, F_SETFL, O_NONBLOCK);
+    event_notifier_init(&p->e, 0);
 
-    qemu_set_fd_handler(p->rfd, v9fs_qemu_process_req_done, NULL, NULL);
+    event_notifier_set_handler(&p->e, v9fs_qemu_process_req_done);
 err_out:
+#ifndef __WIN32
     pthread_sigmask(SIG_SETMASK, &oldset, NULL);
+#endif
     return ret;
 }
index 86d5ed416999677874864784078fd6759ab47c6b..4f51b250d1d44fa842b554ad8bf272165648cf5a 100644 (file)
@@ -21,8 +21,8 @@
 #include <glib.h>
 
 typedef struct V9fsThPool {
-    int rfd;
-    int wfd;
+    EventNotifier e;
+
     GThreadPool *pool;
     GAsyncQueue *completed;
 } V9fsThPool;
index 883fe5ecc093f3f5b23e356aef269402777f3b0b..0e81d74befb06a7f75746796ca3cc81035f829d4 100644 (file)
 #define UTIME_OMIT      ((1l << 30) - 2l)
 #endif
 
+#ifndef HAVE_STRUCT_TIMESPEC
+#define HAVE_STRUCT_TIMESPEC
+#ifndef _TIMESPEC_DEFINED
+#define _TIMESPEC_DEFINED
 struct timespec {
     time_t  tv_sec;
     long    tv_nsec;
 };
+#endif /* _TIMESPEC_DEFINED */
+#endif /* HAVE_STRUCT_TIMESPEC */
 
 typedef struct {
     WORD val[2];