Merge upstream commits to downstream

In hope of fixing DB timeout issues (and other potential hidden
issues), merging all the upstream patches that we missed.

Signed-off-by: Ryu Ishimoto <ryu@midokura.com>