vhost: try to shrink pfdset when fdset_add fails
authorMatthias Gatto <matthias.gatto@outscale.com>
Tue, 21 Feb 2017 14:25:30 +0000 (15:25 +0100)
committerYuanhan Liu <yuanhan.liu@linux.intel.com>
Sat, 1 Apr 2017 06:58:54 +0000 (08:58 +0200)
commit1b815b89599cdd9b54e5aa70f5b97088225b2bcc
tree5b73202c73976182b6f5ce7087d5257393d2614b
parent6e2ea132abcb9165f3aaaee93a1d0e0a7caf08f8
vhost: try to shrink pfdset when fdset_add fails

fdset_add increments pfdset->num, but fdset_del doesn't decrement
pfdset->num, so if we call fdset_add then fdset_del in a loop without
calling fdset_shrink, we can easily exceed MAX_FDS with only a few
number of fds used.

So my solution is simply to call fdset_shrink in fdset_add when it
exceeds MAX_FDS.

Because fdset_shrink and fdset_add locks pfdset->fd_mutex we can't
call fdset_shrink inside fdset_add because that would cause a dead
lock, so this patch split fdset_shrink in two, fdset_shrink and
fdset_shrink_nolock.

Fixes: 59317cef249c ("vhost: allow many vhost-user ports")
Cc: stable@dpdk.org
Signed-off-by: Matthias Gatto <matthias.gatto@outscale.com>
lib/librte_vhost/fd_man.c