Per-thread logging flag must be made immutable

Host environment

  • Operating system: Fedora 35
  • OS/kernel version: Linux bahia 6.0.5-100.fc35.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Oct 26 16:27:59 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
  • Architecture: x86
  • QEMU flavor: qemu-system-x86_64
  • QEMU version: QEMU emulator version 7.1.50 (v7.1.0-1678-g466e81ff)
  • QEMU command line:
    ./qemu-system-x86_64 -S -monitor stdio -D qemu.log.%d

Emulated/Virtualized environment

Issue doesn't need to start the guest to be hit.

Description of problem

The problem is that the code assumes it isn't possible to switch from global logging to per-thread logging and vice-versa per design, but it lags appropriate checks to enforce it. Enabling or disabling per-thread logging at runtime from the monitor causes unexpected results.

Steps to reproduce

Enabling per-thread logging at runtime:

  1. Start QEMU : ./qemu-system-x86_64 -S -monitor stdio -D qemu.log.%d
  2. Enable per-thread logging from the HMP monitor : (qemu) log tid
  3. Fails with Filename template with '%d' required for 'tid' even though such a template was passed with -D.

Disabling per-thread logging at runtime:

  1. Start QEMU : ./qemu-system-x86_64 -S -monitor stdio -D qemu.log.%d -d tid,cpu_reset
  2. Disable per-thread logging from the HMP monitor: (qemu) log cpu_reset
  3. QEMU creates a log file with a bogus qemu.log.%d name.

Additional information

Series posted and already reviewed by @rth7680 .

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information