From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-la0-f50.google.com (mail-la0-f50.google.com [209.85.215.50]) by dpdk.org (Postfix) with ESMTP id EDE5FADA2 for ; Thu, 16 Apr 2015 13:48:35 +0200 (CEST) Received: by laat2 with SMTP id t2so54586959laa.1 for ; Thu, 16 Apr 2015 04:48:35 -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; bh=QxfMAqnJbcbOv/kD2ERCdY8wBzas7W6NArESlKtbFqk=; b=g5TyACfFEqXjdokfIv7LjIbjmTqxH6yCLd3C5Rz0YQbZWbgkIDE8pVsz+fzvwa9LOJ 9xBbEdY3mOlyI2nv2yCIwMRbrFrpskc+LhY+3AoloiFTIDT2VE5yrq3yFYtNZZVpYy8L S1I09D6+WuFHMUoeuzJ6IB7f/J7XazsUszL/w= 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; bh=QxfMAqnJbcbOv/kD2ERCdY8wBzas7W6NArESlKtbFqk=; b=bJno/xzltGVK8krDK7nVG0De0uRhV1j4pbYDgCpg7zPdOSFiYaiQlEAuXFe+3EO0/R HMLiY12xNpePWHGXelIpTm9H4ZQypiDJCAqD/WHb5kQmkhcVf4tdAUumR6FykPSkc/3J zyR6U0bZJxCv7TD6J/wNjWawAnrWU47wp5Lnz73w2DxL506ZcizFyR6wtNHkq1+jScs1 MupFRwoGAbi/k87LFnbq4h5YNh1i78ZzkNpG+BSkl7der546LoG5ckbOvH/5XyTqS1lY Ctvb8vlpTBQt9WgJZnMoZBzMKr2OUAOEK58Sej1uBIiTXkCq/heL8mE+86aCa6BfziC4 +7ug== X-Gm-Message-State: ALoCoQn/V+h9U2t9afip05rHqqf8b0prKC1UYFKsVtWK1hWzEJptoe3S58O22A588t4JNHaBJxP4 X-Received: by 10.152.8.78 with SMTP id p14mr28368266laa.19.1429184915611; Thu, 16 Apr 2015 04:48:35 -0700 (PDT) Received: from pboldin-pc.kha.mirantis.net ([194.213.110.67]) by mx.google.com with ESMTPSA id oy3sm1636510lbb.1.2015.04.16.04.48.34 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 16 Apr 2015 04:48:34 -0700 (PDT) From: Pavel Boldin To: dev@dpdk.org Date: Thu, 16 Apr 2015 14:48:26 +0300 Message-Id: <1429184910-30186-2-git-send-email-pboldin@mirantis.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1429184910-30186-1-git-send-email-pboldin@mirantis.com> References: <1427994080-10163-1-git-send-email-pboldin@mirantis.com> <1429184910-30186-1-git-send-email-pboldin@mirantis.com> Subject: [dpdk-dev] [PATCH v5 1/5] vhost: eventfd_link: moving ioctl to a function 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: Thu, 16 Apr 2015 11:48:36 -0000 Move ioctl `EVENTFD_COPY' handler code to an inline function. Signed-off-by: Pavel Boldin --- lib/librte_vhost/eventfd_link/eventfd_link.c | 171 ++++++++++++++------------- 1 file changed, 89 insertions(+), 82 deletions(-) diff --git a/lib/librte_vhost/eventfd_link/eventfd_link.c b/lib/librte_vhost/eventfd_link/eventfd_link.c index 62c45c8..d7cb81f 100644 --- a/lib/librte_vhost/eventfd_link/eventfd_link.c +++ b/lib/librte_vhost/eventfd_link/eventfd_link.c @@ -65,9 +65,8 @@ put_files_struct(struct files_struct *files) BUG(); } - -static long -eventfd_link_ioctl(struct file *f, unsigned int ioctl, unsigned long arg) +static inline long +eventfd_link_ioctl_copy(unsigned long arg) { void __user *argp = (void __user *) arg; struct task_struct *task_target = NULL; @@ -76,90 +75,98 @@ eventfd_link_ioctl(struct file *f, unsigned int ioctl, unsigned long arg) struct fdtable *fdt; struct eventfd_copy eventfd_copy; - switch (ioctl) { - case EVENTFD_COPY: - if (copy_from_user(&eventfd_copy, argp, - sizeof(struct eventfd_copy))) - return -EFAULT; - - /* - * Find the task struct for the target pid - */ - task_target = - pid_task(find_vpid(eventfd_copy.target_pid), PIDTYPE_PID); - if (task_target == NULL) { - pr_debug("Failed to get mem ctx for target pid\n"); - return -EFAULT; - } - - files = get_files_struct(current); - if (files == NULL) { - pr_debug("Failed to get files struct\n"); - return -EFAULT; - } - - rcu_read_lock(); - file = fcheck_files(files, eventfd_copy.source_fd); - if (file) { - if (file->f_mode & FMODE_PATH || - !atomic_long_inc_not_zero(&file->f_count)) + if (copy_from_user(&eventfd_copy, argp, + sizeof(struct eventfd_copy))) + return -EFAULT; + + /* + * Find the task struct for the target pid + */ + task_target = + pid_task(find_vpid(eventfd_copy.target_pid), PIDTYPE_PID); + if (task_target == NULL) { + pr_debug("Failed to get mem ctx for target pid\n"); + return -EFAULT; + } + + files = get_files_struct(current); + if (files == NULL) { + pr_debug("Failed to get files struct\n"); + return -EFAULT; + } + + rcu_read_lock(); + file = fcheck_files(files, eventfd_copy.source_fd); + if (file) { + if (file->f_mode & FMODE_PATH || + !atomic_long_inc_not_zero(&file->f_count)) + file = NULL; + } + rcu_read_unlock(); + put_files_struct(files); + + if (file == NULL) { + pr_debug("Failed to get file from source pid\n"); + return 0; + } + + /* + * Release the existing eventfd in the source process + */ + spin_lock(&files->file_lock); + fput(file); + filp_close(file, files); + fdt = files_fdtable(files); + fdt->fd[eventfd_copy.source_fd] = NULL; + spin_unlock(&files->file_lock); + + /* + * Find the file struct associated with the target fd. + */ + + files = get_files_struct(task_target); + if (files == NULL) { + pr_debug("Failed to get files struct\n"); + return -EFAULT; + } + + rcu_read_lock(); + file = fcheck_files(files, eventfd_copy.target_fd); + if (file) { + if (file->f_mode & FMODE_PATH || + !atomic_long_inc_not_zero(&file->f_count)) file = NULL; - } - rcu_read_unlock(); - put_files_struct(files); - - if (file == NULL) { - pr_debug("Failed to get file from source pid\n"); - return 0; - } - - /* - * Release the existing eventfd in the source process - */ - spin_lock(&files->file_lock); - fput(file); - filp_close(file, files); - fdt = files_fdtable(files); - fdt->fd[eventfd_copy.source_fd] = NULL; - spin_unlock(&files->file_lock); - - /* - * Find the file struct associated with the target fd. - */ - - files = get_files_struct(task_target); - if (files == NULL) { - pr_debug("Failed to get files struct\n"); - return -EFAULT; - } - - rcu_read_lock(); - file = fcheck_files(files, eventfd_copy.target_fd); - if (file) { - if (file->f_mode & FMODE_PATH || - !atomic_long_inc_not_zero(&file->f_count)) - file = NULL; - } - rcu_read_unlock(); - put_files_struct(files); - - if (file == NULL) { - pr_debug("Failed to get file from target pid\n"); - return 0; - } - - /* - * Install the file struct from the target process into the - * file desciptor of the source process, - */ - - fd_install(eventfd_copy.source_fd, file); + } + rcu_read_unlock(); + put_files_struct(files); + if (file == NULL) { + pr_debug("Failed to get file from target pid\n"); return 0; + } + + /* + * Install the file struct from the target process into the + * file desciptor of the source process, + */ + + fd_install(eventfd_copy.source_fd, file); + + return 0; +} - default: - return -ENOIOCTLCMD; +static long +eventfd_link_ioctl(struct file *f, unsigned int ioctl, unsigned long arg) +{ + long ret = -ENOIOCTLCMD; + + switch (ioctl) { + case EVENTFD_COPY: + ret = eventfd_link_ioctl_copy(arg); + break; } + + return ret; } static const struct file_operations eventfd_link_fops = { -- 1.9.1