From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wi0-f171.google.com (mail-wi0-f171.google.com [209.85.212.171]) by dpdk.org (Postfix) with ESMTP id 2EA9D7E6A for ; Fri, 28 Aug 2015 20:51:29 +0200 (CEST) Received: by wicfv10 with SMTP id fv10so19821878wic.0 for ; Fri, 28 Aug 2015 11:51:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mirantis.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=3TzJCaQEuIkZrkvM8IN7jeTQhkt5D0qwTUpOGZQ9P2U=; b=KJD1G/Xs/kXZYYx6RmDMqIdWJS+p2ofq//LbjgHFSPa7N6frRSwbxlwnSrVRcfWBVV L/Bguu4a7C7wD1slK70IfIgXCIeCTMmBbPyQz4N8QZdxRtSNQFPQoF5qLmkYUfxAe62X eQibhik+Gr208OpH3E0+e67poXYeAy+gjX+sA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=3TzJCaQEuIkZrkvM8IN7jeTQhkt5D0qwTUpOGZQ9P2U=; b=ZrgE0IGXR8SvQrQghFyI4yfTk1X5KA96rlbd+AkCp8XOXxy+z9lxBo8oaXqkNBpUCT +DRwd5fSH10BqJ1b7iDDpun+E+bxMYD2hFazxCeYWzvR4ng07Eofp4ZxrMquizuaYmQT Zq9FoqBG3prVP/v15Y+sgRcUo4XDzc6x0l1NHPmnmsTM9y3olfZnHv2Tnjz5r4mWOvlS g9/1PFtzmUkwPEBgR67zwzc2eDX7AYGod6XQFcWB7YBfGTyt48EW3YhMOJP3pAwk6zzn 2cjBWMKn7zgNv5fVhGpRTg3seAL8lrkbJekyi5xF5bpVYCZUgVCRGtvOCxGT9Bm/yNL5 J70A== X-Gm-Message-State: ALoCoQk9f8lHOViGU0rTbCiaK/m+M3TFf8rFaXEBx4XskCdVTyLInhu+PZssf+hWAq1NMBb5J/4a X-Received: by 10.194.209.167 with SMTP id mn7mr12482168wjc.64.1440787888986; Fri, 28 Aug 2015 11:51:28 -0700 (PDT) Received: from pboldin-pc.kha.mirantis.net ([194.213.110.67]) by smtp.gmail.com with ESMTPSA id lg6sm9279299wjb.10.2015.08.28.11.51.28 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 28 Aug 2015 11:51:28 -0700 (PDT) From: Pavel Boldin To: dev@dpdk.org Date: Fri, 28 Aug 2015 21:51:19 +0300 Message-Id: <1440787880-7079-3-git-send-email-pboldin@mirantis.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1440787880-7079-1-git-send-email-pboldin@mirantis.com> References: <1440787880-7079-1-git-send-email-pboldin@mirantis.com> In-Reply-To: <1429184910-30186-2-git-send-email-pboldin@mirantis.com> References: <1429184910-30186-2-git-send-email-pboldin@mirantis.com> Subject: [dpdk-dev] [PATCH v5 3/4] vhost: using EVENTFD_COPY2 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Aug 2015 18:51:29 -0000 Signed-off-by: Pavel Boldin --- lib/librte_vhost/vhost_cuse/eventfd_copy.c | 54 ++++++++++++++++++---------- lib/librte_vhost/vhost_cuse/eventfd_copy.h | 6 ++++ lib/librte_vhost/vhost_cuse/vhost-net-cdev.c | 3 ++ 3 files changed, 44 insertions(+), 19 deletions(-) diff --git a/lib/librte_vhost/vhost_cuse/eventfd_copy.c b/lib/librte_vhost/vhost_cuse/eventfd_copy.c index 4d697a2..1625163 100644 --- a/lib/librte_vhost/vhost_cuse/eventfd_copy.c +++ b/lib/librte_vhost/vhost_cuse/eventfd_copy.c @@ -46,6 +46,32 @@ static const char eventfd_cdev[] = "/dev/eventfd-link"; +static int eventfd_link = -1; + +int +eventfd_init(void) +{ + if (eventfd_link > 0) + return 0; + + eventfd_link = open(eventfd_cdev, O_RDWR); + if (eventfd_link < 0) { + RTE_LOG(ERR, VHOST_CONFIG, + "eventfd_link module is not loaded\n"); + return -1; + } + + return 0; +} + +int +eventfd_free(void) +{ + if (eventfd_link > 0) + close(eventfd_link); + return 0; +} + /* * This function uses the eventfd_link kernel module to copy an eventfd file * descriptor provided by QEMU in to our process space. @@ -53,36 +79,26 @@ static const char eventfd_cdev[] = "/dev/eventfd-link"; int eventfd_copy(int target_fd, int target_pid) { - int eventfd_link, ret; - struct eventfd_copy eventfd_copy; - int fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); + int ret; + struct eventfd_copy2 eventfd_copy2; - if (fd == -1) - return -1; /* Open the character device to the kernel module. */ /* TODO: check this earlier rather than fail until VM boots! */ - eventfd_link = open(eventfd_cdev, O_RDWR); - if (eventfd_link < 0) { - RTE_LOG(ERR, VHOST_CONFIG, - "eventfd_link module is not loaded\n"); - close(fd); + if (eventfd_init() < 0) return -1; - } - eventfd_copy.source_fd = fd; - eventfd_copy.target_fd = target_fd; - eventfd_copy.target_pid = target_pid; + eventfd_copy2.fd = target_fd; + eventfd_copy2.pid = target_pid; + eventfd_copy2.flags = O_NONBLOCK | O_CLOEXEC; /* Call the IOCTL to copy the eventfd. */ - ret = ioctl(eventfd_link, EVENTFD_COPY, &eventfd_copy); - close(eventfd_link); + ret = ioctl(eventfd_link, EVENTFD_COPY2, &eventfd_copy2); if (ret < 0) { RTE_LOG(ERR, VHOST_CONFIG, - "EVENTFD_COPY ioctl failed\n"); - close(fd); + "EVENTFD_COPY2 ioctl failed\n"); return -1; } - return fd; + return ret; } diff --git a/lib/librte_vhost/vhost_cuse/eventfd_copy.h b/lib/librte_vhost/vhost_cuse/eventfd_copy.h index 19ae30d..5f446ca 100644 --- a/lib/librte_vhost/vhost_cuse/eventfd_copy.h +++ b/lib/librte_vhost/vhost_cuse/eventfd_copy.h @@ -34,6 +34,12 @@ #define _EVENTFD_H int +eventfd_init(void); + +int +eventfd_free(void); + +int eventfd_copy(int target_fd, int target_pid); #endif diff --git a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c index 1ae7c49..ae7ad8d 100644 --- a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c +++ b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c @@ -373,6 +373,9 @@ rte_vhost_driver_register(const char *dev_name) return -1; } + if (eventfd_init() < 0) + return -1; + /* * The device name is created. This is passed to QEMU so that it can * register the device with our application. -- 1.9.1