From patchwork Wed Oct 28 18:33:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Boldin X-Patchwork-Id: 8143 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id C20D88DAC; Wed, 28 Oct 2015 19:34:13 +0100 (CET) Received: from mail-lf0-f54.google.com (mail-lf0-f54.google.com [209.85.215.54]) by dpdk.org (Postfix) with ESMTP id 70CFD8DA4 for ; Wed, 28 Oct 2015 19:34:12 +0100 (CET) Received: by lfbn126 with SMTP id n126so8016339lfb.2 for ; Wed, 28 Oct 2015 11:34:12 -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=x76kVBb4zv17S/z0e964rMuttAsu+y54udPWaIWSl8U=; b=KnLlGNq62Z1k477FVwi92knhjZhPamPcA81qvOlhoq0v5fjMvqVPORRk2HZP7Gu4Ve rl9DnlchKlTK2sJVPHXe33x+GrvhJEQ4VIkvNr9FpfiGW0SC0WID9XqxNeaCo8DNDyVD k3lTGdg6xgVnKL7+sthvtbcCzBq34YgImh9fQ= 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=x76kVBb4zv17S/z0e964rMuttAsu+y54udPWaIWSl8U=; b=NdU66N1Ec38J/qUpBojzrHraU1AtxaGbyQN8blVDvEDbE/FHyl0mhBAGmRcWHgPw8Z nNbN2Ntojg1oh1ekrqETc5Qs7Kb2ITPgkJdm1vSMCtTygcZj4W0efBSnZxzXkvbayG8k pz8PCsRpkR3ezI62ktg9ldoB1NR+/I3Ddq/52NiJcJg+nX5i5rwer6fRBZUS44jsIsYj vdSaYZwBwXOoVw/nqlRKMVs+Y3o05uHMiVtLQACKN3zusK3Z8DWxSCTqsjBLpmxNe39H gVwgXbXQH7UFAYh+IWNTvAId1r9UsxA0qLcHowlW+JMC8W7tRHzw21+EadhgU4fGaz9+ CGvQ== X-Gm-Message-State: ALoCoQni2MQehvsavSt3vw46d1ffjvvuF5jwrxQ6iGzVAa0O40yR4289EtgZ21aI50HT9+kWXYBB X-Received: by 10.25.39.135 with SMTP id n129mr1758794lfn.60.1446057252200; Wed, 28 Oct 2015 11:34:12 -0700 (PDT) Received: from pboldin-pc.kha.mirantis.net ([194.213.110.67]) by smtp.gmail.com with ESMTPSA id g65sm2874107lfb.11.2015.10.28.11.34.11 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 28 Oct 2015 11:34:11 -0700 (PDT) From: Pavel Boldin To: dev@dpdk.org Date: Wed, 28 Oct 2015 20:33:48 +0200 Message-Id: <6a5337337b7135d29cf86b82246d031b382055d3.1446056748.git.pboldin@mirantis.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: In-Reply-To: <1440787880-7079-1-git-send-email-pboldin@mirantis.com> References: <1440787880-7079-1-git-send-email-pboldin@mirantis.com> Subject: [dpdk-dev] [PATCH v6 2/3] 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 7cbebd4..c54a938 100644 --- a/lib/librte_vhost/eventfd_link/eventfd_link.c +++ b/lib/librte_vhost/eventfd_link/eventfd_link.c @@ -78,6 +78,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; @@ -176,6 +234,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_ */