ppc64_cpu: work around bad sysfs online behaviour

The sysfs file /sys/devices/system/cpu/cpuXX/online will return EINVAL
if set to 1 when already online, or 0 when already offline. This is not
a fatal error: it is normal behaviour when setting the smt mode.

As we are stuck with the sysfs interface, work around it by looking at
errno after setting the CPU state, and ignoring the failure if errno is
set to EINVAL.

While we are here, merge the two for loops into one to avoid duplicating
the error checking code.

Signed-off-by: Joel Stanley <joel@jms.id.au>
ppc64_cpu: handle offline cpus when setting attributes

When a CPU is offline, sysfs files are removed from the
/sys/devices/system/cpu/cpuXX directory. The dscr and smt_snooze_delay
settings are set on every CPU, but for offline CPUs the sysfs file will
not exist. Detect when set_attribute has errored out due to a missing
file, and ignore it.

The only callers of set_system_attribute are dscr and smt_snooze_delay,
so special casing for their expected behaviour is okay.

Signed-off-by: Joel Stanley <joel@jms.id.au>
ppc64_cpu: use write(2) when modifying sysfs

This improves the error handling when setting attributes fails. fprintf
does not return an error when a sysfs write returns an error.  Using the
write(2), we can catch bad return codes and inform the user.

The callers of set_attribute have been updated to ignore errors where
they are expected.

This fixes the following bug:

 Modifying --subcores-per-core when a guest is running is not allowed.
 sysfs reports -EBUSY but currently ppc64_cpu reports success, despite
 not doing anything.

Signed-off-by: Joel Stanley <joel@jms.id.au>