From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wi0-f175.google.com (mail-wi0-f175.google.com [209.85.212.175]) by dpdk.org (Postfix) with ESMTP id 41FF65927 for ; Fri, 28 Aug 2015 20:51:28 +0200 (CEST) Received: by wiyy7 with SMTP id y7so7599441wiy.1 for ; Fri, 28 Aug 2015 11:51:28 -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=b55zYYgHB7nlsKabQv6z/8OtZf79h0C0BIU9JD5tplg=; b=FN8Z1vERM3KZJz1Db9XBzZ9sunxrvG0J94D51ebig2nuQM1JPhgzcOeZDbyCoaHk6w 51DVYlnQK69WmHzdRQbsstj88dnxrwcGCsjDtLVBFp5HsK7N9/di7olFMeC3My2nbIM7 Xyu3si8gj9aLV4GSpuE/mYBg9i6tnCWPAywZw= 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=b55zYYgHB7nlsKabQv6z/8OtZf79h0C0BIU9JD5tplg=; b=P4clkclIn29KEy0FiBQzjGTaXotepS2ulWXvK9uhiDdrV1TVEQljkwDBPlYwOItx3y 37UtZf1i81MQhdgEArsN8JFwe3niBcGlmbTtQX81deTa15u2Ok1zVirpsTw7tr/C6EVx GLDF+bWNzAFsliq7kYXF3lpZ/muxlP/cgYnPeVNODLcAFgFRMRz5xmumOJHyVpV1fRr1 5Gwuo0/LyA3pOPACTBM8nlBkebGKT/Fsrghiy1cqf/t01EC4WyEcS0cLtbyoQpTS6R72 v81IqlLQ/v+jSajUm427VLf7y584seeS1b7YpSBrmNeNc15pksDR7nBuLkdgzoREIDr2 X9Vg== X-Gm-Message-State: ALoCoQn8l8Uihv5qz408cXzfaD9LG90OMsTmC4roN6vUpvRCqbHQ/9+UctKcIEtNY9IlxQJA5bHM X-Received: by 10.194.184.82 with SMTP id es18mr13822706wjc.79.1440787887940; Fri, 28 Aug 2015 11:51:27 -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.26 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 28 Aug 2015 11:51:27 -0700 (PDT) From: Pavel Boldin To: dev@dpdk.org Date: Fri, 28 Aug 2015 21:51:18 +0300 Message-Id: <1440787880-7079-2-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 2/4] vhost: add EVENTFD_COPY2 ioctl 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:28 -0000 Signed-off-by: Pavel Boldin --- lib/librte_vhost/eventfd_link/eventfd_link.c | 61 ++++++++++++++++++++++++++++ lib/librte_vhost/eventfd_link/eventfd_link.h | 28 ++++++++++--- 2 files changed, 84 insertions(+), 5 deletions(-) diff --git a/lib/librte_vhost/eventfd_link/eventfd_link.c b/lib/librte_vhost/eventfd_link/eventfd_link.c index 5ba1068..0264365 100644 --- a/lib/librte_vhost/eventfd_link/eventfd_link.c +++ b/lib/librte_vhost/eventfd_link/eventfd_link.c @@ -77,6 +77,64 @@ fget_from_files(struct files_struct *files, unsigned fd) } static long +eventfd_link_ioctl_copy2(unsigned long arg) +{ + void __user *argp = (void __user *) arg; + struct task_struct *task_target = NULL; + struct file *file; + struct files_struct *files; + struct eventfd_copy2 eventfd_copy2; + long ret = -EFAULT; + + if (copy_from_user(&eventfd_copy2, argp, sizeof(struct eventfd_copy2))) + goto out; + + /* + * Find the task struct for the target pid + */ + ret = -ESRCH; + + task_target = + get_pid_task(find_vpid(eventfd_copy2.pid), PIDTYPE_PID); + if (task_target == NULL) { + pr_info("Unable to find pid %d\n", eventfd_copy2.pid); + goto out; + } + + ret = -ESTALE; + files = get_files_struct(task_target); + if (files == NULL) { + pr_info("Failed to get target files struct\n"); + goto out_task; + } + + ret = -EBADF; + file = fget_from_files(files, eventfd_copy2.fd); + put_files_struct(files); + + if (file == NULL) { + pr_info("Failed to get fd %d from target\n", eventfd_copy2.fd); + goto out_task; + } + + /* + * Install the file struct from the target process into the + * newly allocated file desciptor of the source process. + */ + ret = get_unused_fd_flags(eventfd_copy2.flags); + if (ret < 0) { + fput(file); + goto out_task; + } + fd_install(ret, file); + +out_task: + put_task_struct(task_target); +out: + return ret; +} + +static long eventfd_link_ioctl_copy(unsigned long arg) { void __user *argp = (void __user *) arg; @@ -175,6 +233,9 @@ eventfd_link_ioctl(struct file *f, unsigned int ioctl, unsigned long arg) case EVENTFD_COPY: ret = eventfd_link_ioctl_copy(arg); break; + case EVENTFD_COPY2: + ret = eventfd_link_ioctl_copy2(arg); + break; } return ret; diff --git a/lib/librte_vhost/eventfd_link/eventfd_link.h b/lib/librte_vhost/eventfd_link/eventfd_link.h index ea619ec..5ebc20b 100644 --- a/lib/librte_vhost/eventfd_link/eventfd_link.h +++ b/lib/librte_vhost/eventfd_link/eventfd_link.h @@ -61,11 +61,6 @@ #define _EVENTFD_LINK_H_ /* - * ioctl to copy an fd entry in calling process to an fd in a target process - */ -#define EVENTFD_COPY 1 - -/* * arguements for the EVENTFD_COPY ioctl */ struct eventfd_copy { @@ -73,4 +68,27 @@ struct eventfd_copy { unsigned source_fd; /* fd in the calling pid */ pid_t target_pid; /* pid of the target pid */ }; + +/* + * ioctl to copy an fd entry in calling process to an fd in a target process + * NOTE: this one should be + * #define EVENTFD_COPY _IOWR('D', 1, struct eventfd_copy) actually + */ +#define EVENTFD_COPY 1 + +/* + * arguments for the EVENTFD_COPY2 ioctl + */ +struct eventfd_copy2 { + unsigned fd; /* fd to steal */ + pid_t pid; /* pid of the process to steal from */ + unsigned flags; /* flags to allocate new fd with */ +}; + +/* + * ioctl to copy an fd entry from the target process into newly allocated + * fd in the calling process + */ +#define EVENTFD_COPY2 _IOW('D', 2, struct eventfd_copy2) + #endif /* _EVENTFD_LINK_H_ */ -- 1.9.1