SMAPIv2 bugfixes

These are the obvious SMAPIv2 bugfixes from xenserver-core.

I still need to test these in a trunk-ring3 context.