[PATCH 5/5] qemuPrepareNVRAM: Us virFileRewrite() to write NVRAM

Michal Prívozník mprivozn at redhat.com
Fri Feb 11 08:02:59 UTC 2022


On 2/10/22 17:16, Daniel P. Berrangé wrote:
> On Thu, Feb 10, 2022 at 12:13:26PM +0100, Michal Privoznik wrote:
>> After previous commits there is no need for qemuPrepareNVRAM() to
>> open code virFileRewrite(). Deduplicate the code by calling the
>> function.
>>
>> Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
>> ---
>>  src/qemu/qemu_process.c | 118 +++++++++++++---------------------------
>>  1 file changed, 39 insertions(+), 79 deletions(-)
>>


>>  static int
>>  qemuPrepareNVRAM(virQEMUDriver *driver,
>>                   virDomainObj *vm,
>> @@ -4428,13 +4462,8 @@ qemuPrepareNVRAM(virQEMUDriver *driver,
>>  {
>>      g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
>>      int ret = -1;
>> -    int srcFD = -1;
>> -    int dstFD = -1;
>>      virDomainLoaderDef *loader = vm->def->os.loader;
>> -    bool created = false;
>>      const char *master_nvram_path;
>> -    ssize_t r;
>> -    g_autofree char *tmp_dst_path = NULL;
>>  
>>      if (!loader || !loader->nvram ||
>>          (virFileExists(loader->nvram) && !reset_nvram))
>> @@ -4458,84 +4487,15 @@ qemuPrepareNVRAM(virQEMUDriver *driver,
>>          goto cleanup;
>>      }
>>  
>> -    if ((srcFD = virFileOpenAs(master_nvram_path, O_RDONLY,
>> -                               0, -1, -1, 0)) < 0) {
>> -        virReportSystemError(-srcFD,
>> -                             _("Failed to open file '%s'"),
>> -                             master_nvram_path);
> 
> We don't need to remove this surely, if we pass...
> 
>> +    if (virFileRewrite(loader->nvram,
>> +                       S_IRUSR | S_IWUSR,
>> +                       cfg->user, cfg->group,
>> +                       qemuPrepareNVRAMHelper,
>> +                       master_nvram_path) < 0)
> 
> ... &srcFD instead of master_nvram_path   here  ?

Yep. My aim was to have a self contained callback, but it's just a
matter of preference. Let me fix that in v2.

Michal




More information about the libvir-list mailing list