From mboxrd@z Thu Jan 1 00:00:00 1970 From: Pavel Boldin Subject: [PATCH v5 2/5] vhost: eventfd_link: add function fget_from_files Date: Thu, 16 Apr 2015 14:48:27 +0300 Message-ID: <1429184910-30186-3-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> To: dev-VfR2kkLFssw@public.gmane.org Return-path: In-Reply-To: <1429184910-30186-1-git-send-email-pboldin-nYU0QVwCCFFWk0Htik3J/w@public.gmane.org> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces-VfR2kkLFssw@public.gmane.org Sender: "dev" 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