Apply a few spa_writeable() changes that were made to Illumos in
illumos/illumos-gate.git@cd1c8b8 as part of the 3112, 3113,
3114 and 3115 fixes.

Add a missing call to fnvlist_free(nvl) in log_internal() that
was added in Illumos to fix issue 3085 but couldn't be ported
to ZoL at the time (zfsonlinux/zfs@9e11c73) because it depended
on future work.