From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wi0-f179.google.com (mail-wi0-f179.google.com [209.85.212.179]) by dpdk.org (Postfix) with ESMTP id 35CE69A99 for ; Thu, 2 Apr 2015 19:01:42 +0200 (CEST) Received: by widdi4 with SMTP id di4so85379659wid.0 for ; Thu, 02 Apr 2015 10:01:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mirantis.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=so7MJ7nHZsJx4FZ+QU6pU38UCj+9evy8Y8RHcDvZjWk=; b=IgLx3Zb8O33ohVVO21Ea+EW5HkJgUHW0vyFKVUZaxp5b4PQiaSes3c024+BO5ggaCa QBr7DtRpcKh+GV5IiydsurIAWQWKKJlwRifnFCkr7yecz1eb+7Db0PNV/JDgcq3CHcRd +Nyhw/5Rv60vxQdVA7Ti0Cow6DU6GPjV512HY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=so7MJ7nHZsJx4FZ+QU6pU38UCj+9evy8Y8RHcDvZjWk=; b=AWxdIqn97kUt++zFdFq4QgUK/dj8U6zeQEKviKsq0s6DFSIPvv3Rl/jhzLzPtZRv8v 1EJ1X9p+RB6CZUZ3eidBfKISVSvmL3Pmi+o/Z1dtPm6vDbjPZzi3qQzd3s+hK+INogI7 Hr/FEQODciRAfh5DrsDP9T9EFnfhFAeHwpVIs+bwISXxI4/P8WFyp958mKmpSaUYjRdO 1VnYeAYoCxzAc/4w18MQzn0i1M8Qi/epl/okQi0u1qRmnWLRTrjAjOChm+Ie5Lm6W71/ k4zYC2dhV8elSGhQZ8HmIUW9HgPcqv82GhnJxNuPOyUANEU0fUlYQLYE0VscLKIEhyKX xOhg== X-Gm-Message-State: ALoCoQme4k8QEgiC/qBbPE7Gf8KY/qFwvfZNyW1wZQfml4onB+Yeh+rDgEc4Qcox00LqWwk0/dL1 X-Received: by 10.180.102.165 with SMTP id fp5mr25567692wib.80.1427994101006; Thu, 02 Apr 2015 10:01:41 -0700 (PDT) Received: from pboldin-pc.kha.mirantis.net ([194.213.110.67]) by mx.google.com with ESMTPSA id md2sm30801242wic.19.2015.04.02.10.01.40 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 Apr 2015 10:01:40 -0700 (PDT) From: Pavel Boldin To: dev@dpdk.org Date: Thu, 2 Apr 2015 20:01:17 +0300 Message-Id: <1427994080-10163-3-git-send-email-pboldin@mirantis.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1427994080-10163-1-git-send-email-pboldin@mirantis.com> References: <1427123731-15654-1-git-send-email-pboldin@mirantis.com> <1427994080-10163-1-git-send-email-pboldin@mirantis.com> Subject: [dpdk-dev] [PATCH v4 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, 02 Apr 2015 17:01:42 -0000 Move copy-pasted code of `fget' for different `struct files' to the added `fget_from_files' function. --- 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