From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-la0-f51.google.com (mail-la0-f51.google.com [209.85.215.51]) by dpdk.org (Postfix) with ESMTP id 4676CC30E for ; Thu, 16 Apr 2015 13:48:37 +0200 (CEST) Received: by lagv1 with SMTP id v1so54580721lag.3 for ; Thu, 16 Apr 2015 04:48:36 -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=lMR9ooVeUZ2IKtwZFZqwL/7gTVV/f2HFxwIkzWAOX6Q=; b=QnEB1vTeKhctvGMy7Lv/YTn1Asj1OlHMdukrxpZCmbqVJYjdKJN0Do+1xUDb0Ld1CB 3Ukl2JV1f9F2myB0GIvKtKAEzll14UspXLIsXGRywSxTVt4qqiKb1ngTHxAWJ5PrYBTN hc6GBEciJbL9K4go127g3p0+MEMa8SKBi3Exc= 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=lMR9ooVeUZ2IKtwZFZqwL/7gTVV/f2HFxwIkzWAOX6Q=; b=lxmuv2JddSubEBA6qm4zKrx4A2FSd3K/6S+MtMrq08wLSI0iDBGszW7FkA39wBWAo0 lsSShcfn3eIcHOsdJcpvfvRhMdgrZkfXa0ybyjpPew399bBXy9cqBciwNKe+kxNl0SIA P7gbQiMvv8nKzGPQMUBFfZjrI0W/n5Xw6/JnlvAo3B7v/omo2JbTrXz+dIE9EGrgvOZo PS1NkJ+7vocjmxDBSglbrsClRD0oNgetjE0FouD329iHIti8zwnbGO6qzx+Zo3GAnv5z qJO3u8sHusERs9Kl9TYewQPCSGxTe8rm+nK7IFKwb2rchK3XS1UIMRIESz91q0w0tY1K AXlA== X-Gm-Message-State: ALoCoQmIKgGeeGDmWDHhA1xcyn2by2GcjDFgh64kFXGhtl4OVA3F+3j+NjStdmXPAR7UnuNDX1LL X-Received: by 10.152.203.162 with SMTP id kr2mr28267860lac.68.1429184916785; Thu, 16 Apr 2015 04:48:36 -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.35 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 16 Apr 2015 04:48:35 -0700 (PDT) From: Pavel Boldin To: dev@dpdk.org Date: Thu, 16 Apr 2015 14:48:27 +0300 Message-Id: <1429184910-30186-3-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 2/5] vhost: eventfd_link: add function fget_from_files 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:37 -0000 Move copy-pasted code of `fget' for different `struct files' to the added `fget_from_files' function. Signed-off-by: Pavel Boldin --- lib/librte_vhost/eventfd_link/eventfd_link.c | 36 +++++++++++++++------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/lib/librte_vhost/eventfd_link/eventfd_link.c b/lib/librte_vhost/eventfd_link/eventfd_link.c index d7cb81f..2a29999 100644 --- a/lib/librte_vhost/eventfd_link/eventfd_link.c +++ b/lib/librte_vhost/eventfd_link/eventfd_link.c @@ -65,6 +65,24 @@ put_files_struct(struct files_struct *files) BUG(); } +static struct file * +fget_from_files(struct files_struct *files, unsigned fd) +{ + struct file *file; + + rcu_read_lock(); + file = fcheck_files(files, fd); + if (file) + { + if (file->f_mode & FMODE_PATH + || !atomic_long_inc_not_zero(&file->f_count)) + file = NULL; + } + rcu_read_unlock(); + + return file; +} + static inline long eventfd_link_ioctl_copy(unsigned long arg) { @@ -95,14 +113,7 @@ eventfd_link_ioctl_copy(unsigned long arg) 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(); + file = fget_from_files(files, eventfd_copy.source_fd); put_files_struct(files); if (file == NULL) { @@ -130,14 +141,7 @@ eventfd_link_ioctl_copy(unsigned long arg) 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(); + file = fget_from_files(files, eventfd_copy.target_fd); put_files_struct(files); if (file == NULL) { -- 1.9.1