qga: make build_fs_mount_list() return a bool

Change build_fs_mount_list() to return bool, in accordance
with the guidance under = Rules = in include/qapi/error.h

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Suggested-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20220525144140.591926-10-marcandre.lureau@redhat.com>
This commit is contained in:
Marc-André Lureau 2022-05-25 16:41:34 +02:00
parent b9947c9ce7
commit 561bfcb69d
1 changed files with 10 additions and 15 deletions

View File

@ -673,7 +673,7 @@ static int dev_major_minor(const char *devpath,
/* /*
* Walk the mount table and build a list of local file systems * Walk the mount table and build a list of local file systems
*/ */
static void build_fs_mount_list_from_mtab(FsMountList *mounts, Error **errp) static bool build_fs_mount_list_from_mtab(FsMountList *mounts, Error **errp)
{ {
struct mntent *ment; struct mntent *ment;
FsMount *mount; FsMount *mount;
@ -684,7 +684,7 @@ static void build_fs_mount_list_from_mtab(FsMountList *mounts, Error **errp)
fp = setmntent(mtab, "r"); fp = setmntent(mtab, "r");
if (!fp) { if (!fp) {
error_setg(errp, "failed to open mtab file: '%s'", mtab); error_setg(errp, "failed to open mtab file: '%s'", mtab);
return; return false;
} }
while ((ment = getmntent(fp))) { while ((ment = getmntent(fp))) {
@ -714,6 +714,7 @@ static void build_fs_mount_list_from_mtab(FsMountList *mounts, Error **errp)
} }
endmntent(fp); endmntent(fp);
return true;
} }
static void decode_mntname(char *name, int len) static void decode_mntname(char *name, int len)
@ -738,7 +739,7 @@ static void decode_mntname(char *name, int len)
} }
} }
static void build_fs_mount_list(FsMountList *mounts, Error **errp) static bool build_fs_mount_list(FsMountList *mounts, Error **errp)
{ {
FsMount *mount; FsMount *mount;
char const *mountinfo = "/proc/self/mountinfo"; char const *mountinfo = "/proc/self/mountinfo";
@ -751,8 +752,7 @@ static void build_fs_mount_list(FsMountList *mounts, Error **errp)
fp = fopen(mountinfo, "r"); fp = fopen(mountinfo, "r");
if (!fp) { if (!fp) {
build_fs_mount_list_from_mtab(mounts, errp); return build_fs_mount_list_from_mtab(mounts, errp);
return;
} }
while (getline(&line, &n, fp) != -1) { while (getline(&line, &n, fp) != -1) {
@ -794,6 +794,7 @@ static void build_fs_mount_list(FsMountList *mounts, Error **errp)
free(line); free(line);
fclose(fp); fclose(fp);
return true;
} }
#endif #endif
@ -1592,8 +1593,7 @@ GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error **errp)
Error *local_err = NULL; Error *local_err = NULL;
QTAILQ_INIT(&mounts); QTAILQ_INIT(&mounts);
build_fs_mount_list(&mounts, &local_err); if (!build_fs_mount_list(&mounts, &local_err)) {
if (local_err) {
error_propagate(errp, local_err); error_propagate(errp, local_err);
return NULL; return NULL;
} }
@ -1716,8 +1716,7 @@ int64_t qmp_guest_fsfreeze_freeze_list(bool has_mountpoints,
} }
QTAILQ_INIT(&mounts); QTAILQ_INIT(&mounts);
build_fs_mount_list(&mounts, &local_err); if (!build_fs_mount_list(&mounts, &local_err)) {
if (local_err) {
error_propagate(errp, local_err); error_propagate(errp, local_err);
return -1; return -1;
} }
@ -1798,8 +1797,7 @@ int64_t qmp_guest_fsfreeze_thaw(Error **errp)
Error *local_err = NULL; Error *local_err = NULL;
QTAILQ_INIT(&mounts); QTAILQ_INIT(&mounts);
build_fs_mount_list(&mounts, &local_err); if (!build_fs_mount_list(&mounts, &local_err)) {
if (local_err) {
error_propagate(errp, local_err); error_propagate(errp, local_err);
return 0; return 0;
} }
@ -1872,15 +1870,12 @@ qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **errp)
FsMountList mounts; FsMountList mounts;
struct FsMount *mount; struct FsMount *mount;
int fd; int fd;
Error *local_err = NULL;
struct fstrim_range r; struct fstrim_range r;
slog("guest-fstrim called"); slog("guest-fstrim called");
QTAILQ_INIT(&mounts); QTAILQ_INIT(&mounts);
build_fs_mount_list(&mounts, &local_err); if (!build_fs_mount_list(&mounts, errp)) {
if (local_err) {
error_propagate(errp, local_err);
return NULL; return NULL;
} }