lib: move sockfd cache from sheep to lib

On some subcommands, collie also issues lots of request to sheeps. So
collie can enjoy sockfd caching. For this purpose, this patch moves
sockfd from sheep to lib and generalize the interfaces of sockfd.

This patch doesn't change anything related to IO NIC in sockfd
cache. Because collie can know address and port of IO NIC so
potentially use them.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
collie: check an error during issuing request correctly

Current collie checks error during issuing request by a return value
of collie_exec_req(). But it doesn't work well because
collie_exec_req() returns result code of the request. The code doesn't
represent that the request itself succeeded or not.

This patch lets collie_exec_req() return 0 or -1 for checking the
error which is caused during request issue. And also fixes invalid
error checking done in node_recovery().

In addtion, the last return statement of collie_exec_req() is changed
like this: return ret ? -1 : 0; This ternay operator is required
because exec_req() returns 1 when it fails. Some part of collie check
an error of collie_exec_req() by if (ret < ), and other part check by
if (ret). The above ternay operator is for avoiding return 1 and let
these error handlers work correct.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
lib: correct a way of freeing sockfd_cache_entry

Previous implementation of the sockfd caching mechanism has two memory
leaks. The leak is caused when sockfd_cache_destroy(),
sockfd_cache_add_nolock() try to free a sockfd cache entry. They
forget to free entry->fds.

This patch adds a new function, free_cache_entry() for safe freeing of
sockfd cache entries. And let the above two functions to use it.

Also this patch lets sockfd_cache_add() use free_cache_entry() for
consistency.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
collie: let collie use sockfd cache

This patch lets collie use sockfd cache. Because the sockfd caching
mechanism is now in libsheepdog, collie can enjoy it on some
subcommands which issue many requests to sheep.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>