Hi Peter, Thank you for the feedback. On Fri, Nov 13, 2026 at 05:36:44PM +0100, Peter Krempa wrote: > On Sat, Sep 19, 2026 at 13:53:15 +0530, Arun Menon via Devel wrote: > > From: Arun Menon <[email protected]> > > > > This commit adds the backup and fsync options while constructing the > > swtpm command. Both of these attributes only work with the directory > > backend. > > Which means they ought to be rejected from the others; your patch > doesn't do that.
I see. VIR_DOMAIN_TPM_SOURCE_TYPE_FILE case in qemuTPMVirCommandSwtpmAddTPMState() should reject the backup and fsync options with an error. > > Possibly also for the passthrough backend; you need to check if that is > the case and potentially fix it later. I checked passthrough mode. backup and fsync are scoped strictly to <backend type='emulator'> in src/conf/schemas/domaincommon.rng. In src/conf/domain_conf.h, virDomainTPMDef.data is a union of passthrough, emulator, and external, and virDomainTPMDefParseXML() only parses backup and fsync into data.emulator (along with persistent_state and debug). So passthrough cannot represent or parse those attributes at all. I think, we don't need an additional rejection check for it. Please let me know if I missed anything. > > > > > Refactor qemuTPMVirCommandSwtpmAddTPMState() function, use virBuffer API > > to construct the qemu command and use virReportError to report > > configuration errors. > > Mixing refactors and code additions is not a good idea. Next time > refactor first and add new functionality in a separate patch. Yes, noted. > > This time I'll split it for you. > > > > > Signed-off-by: Arun Menon <[email protected]> > > --- > > src/qemu/qemu_tpm.c | 55 ++++++++++++++++++++++++++++++++++----------- > > src/util/virtpm.c | 2 ++ > > src/util/virtpm.h | 2 ++ > > 3 files changed, 46 insertions(+), 13 deletions(-) > > > > diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c > > index 34e11cc02f..2421c0ddba 100644 > > --- a/src/qemu/qemu_tpm.c > > +++ b/src/qemu/qemu_tpm.c > > @@ -669,34 +669,61 @@ qemuTPMVirCommandSwtpmAddEncryption(virCommand *cmd, > > return 0; > > } > > > > -static void > > +static int > > qemuTPMVirCommandSwtpmAddTPMState(virCommand *cmd, > > const virDomainTPMEmulatorDef *emulator, > > const virDomainTPMDef *tpmDef, > > const virQEMUDriverConfig *cfg) > > { > > - const char *lock = ",lock"; > > + g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; > > + g_autofree char *swtpm = NULL; > > + bool hasLock = > > virTPMSwtpmCapsGet(VIR_TPM_SWTPM_FEATURE_TPMSTATE_OPT_LOCK); > > > > - if (!virTPMSwtpmCapsGet(VIR_TPM_SWTPM_FEATURE_TPMSTATE_OPT_LOCK)) { > > - if (qemuTPMHasSharedStorage(cfg, tpmDef)) > > - VIR_WARN("This swtpm version doesn't support explicit > > locking"); > > + swtpm = virTPMGetSwtpm(); > > > > - lock = ""; > > - } > > + if (!hasLock && qemuTPMHasSharedStorage(cfg, tpmDef)) > > + VIR_WARN("This swtpm version doesn't support explicit locking"); > > Pre-existing, but VIR_WARN ought not to be used in code. It just logs > output to syslog. users will not read it. I suggest removing this > completely or turning it into a hard error if that's appropriate. > > > > > virCommandAddArg(cmd, "--tpmstate"); > > + > > switch (emulator->source_type) { > > case VIR_DOMAIN_TPM_SOURCE_TYPE_FILE: > > - virCommandAddArgFormat(cmd, "backend-uri=file://%s%s", > > - emulator->source_path, lock); > > + virBufferAsprintf(&buf, "backend-uri=file://%s", > > emulator->source_path); > > + if (hasLock) > > + virBufferAddLit(&buf, ",lock"); > > This ought to reject the unsupported parameters. > > > break; > > + > > case VIR_DOMAIN_TPM_SOURCE_TYPE_DIR: > > case VIR_DOMAIN_TPM_SOURCE_TYPE_DEFAULT: > > case VIR_DOMAIN_TPM_SOURCE_TYPE_LAST: > > - virCommandAddArgFormat(cmd, "dir=%s,mode=0600%s", > > - emulator->source_path, lock); > > + virBufferAsprintf(&buf, "dir=%s,mode=0600", emulator->source_path); > > + if (hasLock) > > + virBufferAddLit(&buf, ",lock"); > > + > > + if (emulator->backup == VIR_TRISTATE_BOOL_YES) { > > + if > > (!virTPMSwtpmCapsGet(VIR_TPM_SWTPM_FEATURE_TPMSTATE_OPT_BACKUP)) { > > + virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, > > + _("%1$s does not support backup feature"), > > Our coding style guidelines for error messages suggest that both the > path to the swtpm as well as 'backup' ought to be surrouded by quotes. Thanks, noted. > > > + swtpm); > > + return -1; > > + } > > + virBufferAddLit(&buf, ",backup"); > > + } > > + > > + if (emulator->fsync == VIR_TRISTATE_BOOL_YES) { > > + if > > (!virTPMSwtpmCapsGet(VIR_TPM_SWTPM_FEATURE_TPMSTATE_OPT_FSYNC)) { > > + virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, > > + _("%1$s does not support fsync feature"), > > + swtpm); > > + return -1; > > + } > > + virBufferAddLit(&buf, ",fsync"); > > + } > > break; > > } > > + > > + virCommandAddArgBuffer(cmd, &buf); > > + return 0; > > } > > I'll add what I've pointed out and split this commit; Thank you again. > > Reviewed-by: Peter Krempa <[email protected]> > > Please have a look whether the passhtrough TPM mode also needs to reject > the arguments similarly to the fixed version > Regards, Arun Menon
