[PATCH] qga: implement 'guest-get-fsinfo' for NetBSD and OpenBSD

Brad Smith posted 1 patch 1 week ago
qga/commands-bsd.c    | 19 +++++++++++++------
qga/commands-common.h | 12 +++++++-----
qga/commands-posix.c  |  4 ++--
qga/qapi-schema.json  | 12 ++++++------
4 files changed, 28 insertions(+), 19 deletions(-)
[PATCH] qga: implement 'guest-get-fsinfo' for NetBSD and OpenBSD
Posted by Brad Smith 1 week ago
qga: implement 'guest-get-fsinfo' for NetBSD and OpenBSD

Signed-off-by: Brad Smith <brad@comstyle.com>
---
 qga/commands-bsd.c    | 19 +++++++++++++------
 qga/commands-common.h | 12 +++++++-----
 qga/commands-posix.c  |  4 ++--
 qga/qapi-schema.json  | 12 ++++++------
 4 files changed, 28 insertions(+), 19 deletions(-)

diff --git a/qga/commands-bsd.c b/qga/commands-bsd.c
index 1c51d099eb..0c6caec4a3 100644
--- a/qga/commands-bsd.c
+++ b/qga/commands-bsd.c
@@ -28,12 +28,20 @@
 #include <net/ethernet.h>
 #endif
 #include <paths.h>
+#ifdef __FreeBSD__
+#include <ufs/ffs/fs.h>
+#endif
+
+#ifdef __NetBSD__
+typedef struct statvfs bsd_fsinfo_t;
+#else
+typedef struct statfs bsd_fsinfo_t;
+#endif
 
-#if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM) || defined(__FreeBSD__)
 bool build_fs_mount_list(FsMountList *mounts, Error **errp)
 {
     FsMount *mount;
-    struct statfs *mntbuf, *mntp;
+    bsd_fsinfo_t *mntbuf, *mntp;
     struct stat statbuf;
     int i, count, ret;
 
@@ -57,16 +65,17 @@ bool build_fs_mount_list(FsMountList *mounts, Error **errp)
         mount->dirname = g_strdup(mntp->f_mntonname);
         mount->devtype = g_strdup(mntp->f_fstypename);
         mount->fromname = g_strdup(mntp->f_mntfromname);
+        mount->dev = statbuf.st_dev;
         mount->devmajor = major(mount->dev);
         mount->devminor = minor(mount->dev);
+#ifdef CONFIG_FSFREEZE
         mount->fsid = mntp->f_fsid;
-        mount->dev = statbuf.st_dev;
+#endif
 
         QTAILQ_INSERT_TAIL(mounts, mount, next);
     }
     return true;
 }
-#endif /* CONFIG_FSFREEZE || CONFIG_FSTRIM */
 
 #if defined(CONFIG_FSFREEZE)
 static int ufssuspend_fd = -1;
@@ -181,7 +190,6 @@ bool guest_get_hw_addr(struct ifaddrs *ifa, unsigned char *buf,
 }
 #endif /* HAVE_GETIFADDRS */
 
-#if defined(__FreeBSD__)
 static GuestFilesystemInfo *build_guest_fsinfo(struct FsMount *mount)
 {
     GuestFilesystemInfo *fs = g_new0(GuestFilesystemInfo, 1);
@@ -228,4 +236,3 @@ GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error **errp)
     free_fs_mount_list(&mounts);
     return ret;
 }
-#endif /* __FreeBSD__ */
diff --git a/qga/commands-common.h b/qga/commands-common.h
index a07d0885f5..0d3c69b480 100644
--- a/qga/commands-common.h
+++ b/qga/commands-common.h
@@ -18,17 +18,19 @@
 #endif /* __linux__ */
 
 #ifdef __FreeBSD__
-#include <ufs/ffs/fs.h>
+#include <sys/mount.h>
 #endif /* __FreeBSD__ */
 
-#if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM)
+#if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM) || defined(CONFIG_BSD)
 typedef struct FsMount {
     char *dirname;
     char *devtype;
     unsigned int devmajor, devminor;
-#if defined(__FreeBSD__)
-    dev_t dev;
+#ifdef __FreeBSD__
     fsid_t fsid;
+#endif
+#ifdef CONFIG_BSD
+    dev_t dev;
     char *fromname;
 #endif
     QTAILQ_ENTRY(FsMount) next;
@@ -38,7 +40,7 @@ typedef QTAILQ_HEAD(FsMountList, FsMount) FsMountList;
 
 bool build_fs_mount_list(FsMountList *mounts, Error **errp);
 void free_fs_mount_list(FsMountList *mounts);
-#endif /* CONFIG_FSFREEZE || CONFIG_FSTRIM */
+#endif /* CONFIG_FSFREEZE || CONFIG_FSTRIM || CONFIG_BSD */
 
 #if defined(CONFIG_FSFREEZE)
 int64_t qmp_guest_fsfreeze_do_freeze_list(bool has_mountpoints,
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 837e285b6d..dcc683f6c9 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -718,7 +718,7 @@ void qmp_guest_file_flush(int64_t handle, Error **errp)
     }
 }
 
-#if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM)
+#if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM) || defined(CONFIG_BSD)
 void free_fs_mount_list(FsMountList *mounts)
 {
      FsMount *mount, *temp;
@@ -731,7 +731,7 @@ void free_fs_mount_list(FsMountList *mounts)
          QTAILQ_REMOVE(mounts, mount, next);
          g_free(mount->dirname);
          g_free(mount->devtype);
-#if defined(__FreeBSD__)
+#ifdef CONFIG_BSD
          g_free(mount->fromname);
 #endif
          g_free(mount);
diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json
index 8cd0ba048b..fb640ea1bc 100644
--- a/qga/qapi-schema.json
+++ b/qga/qapi-schema.json
@@ -874,7 +874,7 @@
   'data': [ 'ide', 'fdc', 'scsi', 'virtio', 'xen', 'usb', 'uml', 'sata',
             'sd', 'unknown', 'ieee1394', 'ssa', 'fibre', 'raid', 'iscsi',
             'sas', 'mmc', 'virtual', 'file-backed-virtual', 'nvme' ],
-  'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX', 'CONFIG_FREEBSD' ] } }
+  'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX', 'CONFIG_BSD' ] } }
 
 ##
 # @GuestPCIAddress:
@@ -892,7 +892,7 @@
 { 'struct': 'GuestPCIAddress',
   'data': {'domain': 'int', 'bus': 'int',
            'slot': 'int', 'function': 'int'},
-  'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX', 'CONFIG_FREEBSD' ] } }
+  'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX', 'CONFIG_BSD' ] } }
 
 ##
 # @GuestCCWAddress:
@@ -912,7 +912,7 @@
            'ssid': 'int',
            'subchno': 'int',
            'devno': 'int'},
-  'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX', 'CONFIG_FREEBSD' ] } }
+  'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX', 'CONFIG_BSD' ] } }
 
 ##
 # @GuestDiskAddress:
@@ -942,7 +942,7 @@
            'bus': 'int', 'target': 'int', 'unit': 'int',
            '*serial': 'str', '*dev': 'str',
            '*ccw-address': 'GuestCCWAddress'},
-  'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX', 'CONFIG_FREEBSD' ] } }
+  'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX', 'CONFIG_BSD' ] } }
 
 ##
 # @GuestNVMeSmart:
@@ -1063,7 +1063,7 @@
   'data': {'name': 'str', 'mountpoint': 'str', 'type': 'str',
            '*used-bytes': 'uint64', '*total-bytes': 'uint64',
            '*total-bytes-privileged': 'uint64', 'disk': ['GuestDiskAddress']},
-  'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX', 'CONFIG_FREEBSD' ] } }
+  'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX', 'CONFIG_BSD' ] } }
 
 ##
 # @guest-get-fsinfo:
@@ -1077,7 +1077,7 @@
 ##
 { 'command': 'guest-get-fsinfo',
   'returns': ['GuestFilesystemInfo'],
-  'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX', 'CONFIG_FREEBSD' ] } }
+  'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX', 'CONFIG_BSD' ] } }
 
 ##
 # @guest-set-user-password:
-- 
2.55.0
Re: [PATCH] qga: implement 'guest-get-fsinfo' for NetBSD and OpenBSD
Posted by Roman Bogorodskiy 1 week ago
  Brad Smith wrote:

> qga: implement 'guest-get-fsinfo' for NetBSD and OpenBSD
> 
> Signed-off-by: Brad Smith <brad@comstyle.com>
> ---
>  qga/commands-bsd.c    | 19 +++++++++++++------
>  qga/commands-common.h | 12 +++++++-----
>  qga/commands-posix.c  |  4 ++--
>  qga/qapi-schema.json  | 12 ++++++------
>  4 files changed, 28 insertions(+), 19 deletions(-)

Look reasonable and does not introduce regressions to the FreeBSD
implementation, so:

Reviewed-by: Roman Bogorodskiy <bogorodskiy@gmail.com>