Browse Source

qga: Use error_setg_file_open() for better error messages

Error messages change from

    open("FNAME"): REASON

to

    Could not open 'FNAME': REASON

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dave@treblig.org>
Reviewed-by: Kostiantyn Kostiuk <kkostiuk@redhat.com>
Message-ID: <20251121121438.1249498-6-armbru@redhat.com>
pull/316/head
Markus Armbruster 4 months ago
parent
commit
578988e684
  1. 11
      qga/commands-linux.c

11
qga/commands-linux.c

@ -1503,14 +1503,15 @@ static void transfer_vcpu(GuestLogicalProcessor *vcpu, bool sys2vcpu,
dirfd = open(dirpath, O_RDONLY | O_DIRECTORY); dirfd = open(dirpath, O_RDONLY | O_DIRECTORY);
if (dirfd == -1) { if (dirfd == -1) {
error_setg_errno(errp, errno, "open(\"%s\")", dirpath); error_setg_file_open(errp, errno, dirpath);
return; return;
} }
fd = openat(dirfd, fn, sys2vcpu ? O_RDONLY : O_RDWR); fd = openat(dirfd, fn, sys2vcpu ? O_RDONLY : O_RDWR);
if (fd == -1) { if (fd == -1) {
if (errno != ENOENT) { if (errno != ENOENT) {
error_setg_errno(errp, errno, "open(\"%s/%s\")", dirpath, fn); error_setg_errno(errp, errno, "could not open %s/%s",
dirpath, fn);
} else if (sys2vcpu) { } else if (sys2vcpu) {
vcpu->online = true; vcpu->online = true;
vcpu->can_offline = false; vcpu->can_offline = false;
@ -1712,7 +1713,7 @@ static void transfer_memory_block(GuestMemoryBlock *mem_blk, bool sys2memblk,
dirfd = open(dirpath, O_RDONLY | O_DIRECTORY); dirfd = open(dirpath, O_RDONLY | O_DIRECTORY);
if (dirfd == -1) { if (dirfd == -1) {
if (sys2memblk) { if (sys2memblk) {
error_setg_errno(errp, errno, "open(\"%s\")", dirpath); error_setg_file_open(errp, errno, dirpath);
} else { } else {
if (errno == ENOENT) { if (errno == ENOENT) {
result->response = GUEST_MEMORY_BLOCK_RESPONSE_TYPE_NOT_FOUND; result->response = GUEST_MEMORY_BLOCK_RESPONSE_TYPE_NOT_FOUND;
@ -1937,7 +1938,7 @@ static GuestDiskStatsInfoList *guest_get_diskstats(Error **errp)
fp = fopen(diskstats, "r"); fp = fopen(diskstats, "r");
if (fp == NULL) { if (fp == NULL) {
error_setg_errno(errp, errno, "open(\"%s\")", diskstats); error_setg_file_open(errp, errno, diskstats);
return NULL; return NULL;
} }
@ -2048,7 +2049,7 @@ GuestCpuStatsList *qmp_guest_get_cpustats(Error **errp)
fp = fopen(cpustats, "r"); fp = fopen(cpustats, "r");
if (fp == NULL) { if (fp == NULL) {
error_setg_errno(errp, errno, "open(\"%s\")", cpustats); error_setg_file_open(errp, errno, cpustats);
return NULL; return NULL;
} }

Loading…
Cancel
Save