All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] qga: Add ZFS TRIM support for FreeBSD
@ 2022-11-15 18:45 Alexander Ivanov
  2022-11-15 18:45 ` [PATCH 1/2] qga: Move FS TRIM code to commands-linux.c Alexander Ivanov
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Alexander Ivanov @ 2022-11-15 18:45 UTC (permalink / raw)
  To: qemu-devel; +Cc: den, michael.roth, kkostiuk, marcandre.lureau

Move Linux-specific FS TRIM code to commands-linux.c and add support of
ZFS TRIM for FreeBSD.

Alexander Ivanov (2):
  qga: Move FS TRIM code to commands-linux.c
  qga: Add ZFS TRIM support for FreeBSD

 qga/commands-bsd.c    | 109 ++++++++++++++++++++++++++++++++++++++++++
 qga/commands-common.h |   1 +
 qga/commands-linux.c  |  73 ++++++++++++++++++++++++++++
 qga/commands-posix.c  |  72 ----------------------------
 4 files changed, 183 insertions(+), 72 deletions(-)

-- 
2.34.1



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] qga: Move FS TRIM code to commands-linux.c
  2022-11-15 18:45 [PATCH 0/2] qga: Add ZFS TRIM support for FreeBSD Alexander Ivanov
@ 2022-11-15 18:45 ` Alexander Ivanov
  2022-11-17  8:54   ` Konstantin Kostiuk
  2022-11-15 18:46 ` [PATCH 2/2] qga: Add ZFS TRIM support for FreeBSD Alexander Ivanov
  2022-12-26 14:05 ` [PATCH 0/2] " Konstantin Kostiuk
  2 siblings, 1 reply; 6+ messages in thread
From: Alexander Ivanov @ 2022-11-15 18:45 UTC (permalink / raw)
  To: qemu-devel; +Cc: den, michael.roth, kkostiuk, marcandre.lureau

In the next patch ZFS TRIM support for FreeBSD will be added. Move
Linux-specific TRIM code to commands-linux.c file.

Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
---
 qga/commands-linux.c | 73 ++++++++++++++++++++++++++++++++++++++++++++
 qga/commands-posix.c | 72 -------------------------------------------
 2 files changed, 73 insertions(+), 72 deletions(-)

diff --git a/qga/commands-linux.c b/qga/commands-linux.c
index 214e408fcd..fb01114153 100644
--- a/qga/commands-linux.c
+++ b/qga/commands-linux.c
@@ -13,6 +13,7 @@
 
 #include "qemu/osdep.h"
 #include "qapi/error.h"
+#include "qga-qapi-commands.h"
 #include "commands-common.h"
 #include "cutils.h"
 #include <mntent.h>
@@ -284,3 +285,75 @@ int qmp_guest_fsfreeze_do_thaw(Error **errp)
     return i;
 }
 #endif /* CONFIG_FSFREEZE */
+
+#if defined(CONFIG_FSTRIM)
+/*
+ * Walk list of mounted file systems in the guest, and trim them.
+ */
+GuestFilesystemTrimResponse *
+qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **errp)
+{
+    GuestFilesystemTrimResponse *response;
+    GuestFilesystemTrimResult *result;
+    int ret = 0;
+    FsMountList mounts;
+    struct FsMount *mount;
+    int fd;
+    struct fstrim_range r;
+
+    slog("guest-fstrim called");
+
+    QTAILQ_INIT(&mounts);
+    if (!build_fs_mount_list(&mounts, errp)) {
+        return NULL;
+    }
+
+    response = g_malloc0(sizeof(*response));
+
+    QTAILQ_FOREACH(mount, &mounts, next) {
+        result = g_malloc0(sizeof(*result));
+        result->path = g_strdup(mount->dirname);
+
+        QAPI_LIST_PREPEND(response->paths, result);
+
+        fd = qga_open_cloexec(mount->dirname, O_RDONLY, 0);
+        if (fd == -1) {
+            result->error = g_strdup_printf("failed to open: %s",
+                                            strerror(errno));
+            result->has_error = true;
+            continue;
+        }
+
+        /* We try to cull filesystems we know won't work in advance, but other
+         * filesystems may not implement fstrim for less obvious reasons.
+         * These will report EOPNOTSUPP; while in some other cases ENOTTY
+         * will be reported (e.g. CD-ROMs).
+         * Any other error means an unexpected error.
+         */
+        r.start = 0;
+        r.len = -1;
+        r.minlen = has_minimum ? minimum : 0;
+        ret = ioctl(fd, FITRIM, &r);
+        if (ret == -1) {
+            result->has_error = true;
+            if (errno == ENOTTY || errno == EOPNOTSUPP) {
+                result->error = g_strdup("trim not supported");
+            } else {
+                result->error = g_strdup_printf("failed to trim: %s",
+                                                strerror(errno));
+            }
+            close(fd);
+            continue;
+        }
+
+        result->has_minimum = true;
+        result->minimum = r.minlen;
+        result->has_trimmed = true;
+        result->trimmed = r.len;
+        close(fd);
+    }
+
+    free_fs_mount_list(&mounts);
+    return response;
+}
+#endif /* CONFIG_FSTRIM */
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 32493d6383..b2a6d8b227 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -1607,78 +1607,6 @@ GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error **errp)
 }
 #endif /* CONFIG_FSFREEZE */
 
-#if defined(CONFIG_FSTRIM)
-/*
- * Walk list of mounted file systems in the guest, and trim them.
- */
-GuestFilesystemTrimResponse *
-qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **errp)
-{
-    GuestFilesystemTrimResponse *response;
-    GuestFilesystemTrimResult *result;
-    int ret = 0;
-    FsMountList mounts;
-    struct FsMount *mount;
-    int fd;
-    struct fstrim_range r;
-
-    slog("guest-fstrim called");
-
-    QTAILQ_INIT(&mounts);
-    if (!build_fs_mount_list(&mounts, errp)) {
-        return NULL;
-    }
-
-    response = g_malloc0(sizeof(*response));
-
-    QTAILQ_FOREACH(mount, &mounts, next) {
-        result = g_malloc0(sizeof(*result));
-        result->path = g_strdup(mount->dirname);
-
-        QAPI_LIST_PREPEND(response->paths, result);
-
-        fd = qga_open_cloexec(mount->dirname, O_RDONLY, 0);
-        if (fd == -1) {
-            result->error = g_strdup_printf("failed to open: %s",
-                                            strerror(errno));
-            result->has_error = true;
-            continue;
-        }
-
-        /* We try to cull filesystems we know won't work in advance, but other
-         * filesystems may not implement fstrim for less obvious reasons.
-         * These will report EOPNOTSUPP; while in some other cases ENOTTY
-         * will be reported (e.g. CD-ROMs).
-         * Any other error means an unexpected error.
-         */
-        r.start = 0;
-        r.len = -1;
-        r.minlen = has_minimum ? minimum : 0;
-        ret = ioctl(fd, FITRIM, &r);
-        if (ret == -1) {
-            result->has_error = true;
-            if (errno == ENOTTY || errno == EOPNOTSUPP) {
-                result->error = g_strdup("trim not supported");
-            } else {
-                result->error = g_strdup_printf("failed to trim: %s",
-                                                strerror(errno));
-            }
-            close(fd);
-            continue;
-        }
-
-        result->has_minimum = true;
-        result->minimum = r.minlen;
-        result->has_trimmed = true;
-        result->trimmed = r.len;
-        close(fd);
-    }
-
-    free_fs_mount_list(&mounts);
-    return response;
-}
-#endif /* CONFIG_FSTRIM */
-
 
 #define LINUX_SYS_STATE_FILE "/sys/power/state"
 #define SUSPEND_SUPPORTED 0
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] qga: Add ZFS TRIM support for FreeBSD
  2022-11-15 18:45 [PATCH 0/2] qga: Add ZFS TRIM support for FreeBSD Alexander Ivanov
  2022-11-15 18:45 ` [PATCH 1/2] qga: Move FS TRIM code to commands-linux.c Alexander Ivanov
@ 2022-11-15 18:46 ` Alexander Ivanov
  2022-11-17  8:55   ` Konstantin Kostiuk
  2022-12-26 14:05 ` [PATCH 0/2] " Konstantin Kostiuk
  2 siblings, 1 reply; 6+ messages in thread
From: Alexander Ivanov @ 2022-11-15 18:46 UTC (permalink / raw)
  To: qemu-devel; +Cc: den, michael.roth, kkostiuk, marcandre.lureau

Use zpool tool for ZFS pools trimming in FreeBSD.

Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
---
 qga/commands-bsd.c    | 109 ++++++++++++++++++++++++++++++++++++++++++
 qga/commands-common.h |   1 +
 2 files changed, 110 insertions(+)

diff --git a/qga/commands-bsd.c b/qga/commands-bsd.c
index 15cade2d4c..960c4209e5 100644
--- a/qga/commands-bsd.c
+++ b/qga/commands-bsd.c
@@ -170,6 +170,115 @@ GuestCpuStatsList *qmp_guest_get_cpustats(Error **errp)
 }
 #endif /* CONFIG_FSFREEZE */
 
+#if defined(CONFIG_FSTRIM)
+typedef struct FsPool {
+    char *name;
+    QTAILQ_ENTRY(FsPool) next;
+} FsPool;
+
+typedef QTAILQ_HEAD(FsPoolList, FsPool) FsPoolList;
+
+static void build_fs_pool_list(FsPoolList *pools, Error **errp)
+{
+    FILE *fp;
+    char *line = NULL, *p;
+    size_t linecap = 0;
+    ssize_t linelen;
+    FsPool *pool;
+
+    fp = popen("/sbin/zpool list -H", "r");
+    if (fp == NULL) {
+        error_setg_errno(errp, errno, "failed to run zpool");
+        return;
+    }
+
+    while ((linelen = getline(&line, &linecap, fp)) > 0) {
+        p = strchr(line, '\t');
+        if (!p) {
+            continue;
+        }
+
+        *p = '\0';
+
+        pool = g_new0(FsPool, 1);
+        pool->name = g_strdup(line);
+        QTAILQ_INSERT_TAIL(pools, pool, next);
+    }
+
+    free(line);
+    pclose(fp);
+}
+
+static void free_fs_pool_list(FsPoolList *pools)
+{
+    FsPool *pool, *temp;
+
+    if (!pools) {
+        return;
+    }
+
+    QTAILQ_FOREACH_SAFE(pool, pools, next, temp) {
+        QTAILQ_REMOVE(pools, pool, next);
+        g_free(pool->name);
+        g_free(pool);
+    }
+}
+
+/*
+ * Walk the list of ZFS pools in the guest, and trim them.
+ */
+GuestFilesystemTrimResponse *
+qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **errp)
+{
+    GuestFilesystemTrimResponse *response;
+    GuestFilesystemTrimResultList *list;
+    GuestFilesystemTrimResult *result;
+    int ret;
+    FsPoolList pools;
+    FsPool *pool;
+    char cmd[256];
+    Error *local_err = NULL;
+
+    slog("guest-fstrim called");
+
+    QTAILQ_INIT(&pools);
+    build_fs_pool_list(&pools, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return NULL;
+    }
+
+    response = g_malloc0(sizeof(*response));
+
+    QTAILQ_FOREACH(pool, &pools, next) {
+        result = g_malloc0(sizeof(*result));
+        result->path = g_strdup(pool->name);
+
+        list = g_malloc0(sizeof(*list));
+        list->value = result;
+        list->next = response->paths;
+        response->paths = list;
+
+        snprintf(cmd, sizeof(cmd), "/sbin/zpool trim %s", pool->name);
+        ret = system(cmd);
+        if (ret != 0) {
+            result->error = g_strdup_printf("failed to trim %s: %s",
+                                            pool->name, strerror(errno));
+            result->has_error = true;
+            continue;
+        }
+
+        result->has_minimum = true;
+        result->minimum = 0;
+        result->has_trimmed = true;
+        result->trimmed = 0;
+    }
+
+    free_fs_pool_list(&pools);
+    return response;
+}
+#endif /* CONFIG_FSTRIM */
+
 #ifdef HAVE_GETIFADDRS
 /*
  * Fill "buf" with MAC address by ifaddrs. Pointer buf must point to a
diff --git a/qga/commands-common.h b/qga/commands-common.h
index 8c1c56aac9..922f9c479b 100644
--- a/qga/commands-common.h
+++ b/qga/commands-common.h
@@ -28,6 +28,7 @@
 #ifdef UFSSUSPEND
 #define CONFIG_FSFREEZE
 #endif
+#define CONFIG_FSTRIM
 #endif /* __FreeBSD__ */
 
 #if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM)
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] qga: Move FS TRIM code to commands-linux.c
  2022-11-15 18:45 ` [PATCH 1/2] qga: Move FS TRIM code to commands-linux.c Alexander Ivanov
@ 2022-11-17  8:54   ` Konstantin Kostiuk
  0 siblings, 0 replies; 6+ messages in thread
From: Konstantin Kostiuk @ 2022-11-17  8:54 UTC (permalink / raw)
  To: Alexander Ivanov; +Cc: qemu-devel, den, michael.roth, marcandre.lureau

[-- Attachment #1: Type: text/plain, Size: 6164 bytes --]

Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com>

On Tue, Nov 15, 2022 at 8:46 PM Alexander Ivanov <
alexander.ivanov@virtuozzo.com> wrote:

> In the next patch ZFS TRIM support for FreeBSD will be added. Move
> Linux-specific TRIM code to commands-linux.c file.
>
> Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
> ---
>  qga/commands-linux.c | 73 ++++++++++++++++++++++++++++++++++++++++++++
>  qga/commands-posix.c | 72 -------------------------------------------
>  2 files changed, 73 insertions(+), 72 deletions(-)
>
> diff --git a/qga/commands-linux.c b/qga/commands-linux.c
> index 214e408fcd..fb01114153 100644
> --- a/qga/commands-linux.c
> +++ b/qga/commands-linux.c
> @@ -13,6 +13,7 @@
>
>  #include "qemu/osdep.h"
>  #include "qapi/error.h"
> +#include "qga-qapi-commands.h"
>  #include "commands-common.h"
>  #include "cutils.h"
>  #include <mntent.h>
> @@ -284,3 +285,75 @@ int qmp_guest_fsfreeze_do_thaw(Error **errp)
>      return i;
>  }
>  #endif /* CONFIG_FSFREEZE */
> +
> +#if defined(CONFIG_FSTRIM)
> +/*
> + * Walk list of mounted file systems in the guest, and trim them.
> + */
> +GuestFilesystemTrimResponse *
> +qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **errp)
> +{
> +    GuestFilesystemTrimResponse *response;
> +    GuestFilesystemTrimResult *result;
> +    int ret = 0;
> +    FsMountList mounts;
> +    struct FsMount *mount;
> +    int fd;
> +    struct fstrim_range r;
> +
> +    slog("guest-fstrim called");
> +
> +    QTAILQ_INIT(&mounts);
> +    if (!build_fs_mount_list(&mounts, errp)) {
> +        return NULL;
> +    }
> +
> +    response = g_malloc0(sizeof(*response));
> +
> +    QTAILQ_FOREACH(mount, &mounts, next) {
> +        result = g_malloc0(sizeof(*result));
> +        result->path = g_strdup(mount->dirname);
> +
> +        QAPI_LIST_PREPEND(response->paths, result);
> +
> +        fd = qga_open_cloexec(mount->dirname, O_RDONLY, 0);
> +        if (fd == -1) {
> +            result->error = g_strdup_printf("failed to open: %s",
> +                                            strerror(errno));
> +            result->has_error = true;
> +            continue;
> +        }
> +
> +        /* We try to cull filesystems we know won't work in advance, but
> other
> +         * filesystems may not implement fstrim for less obvious reasons.
> +         * These will report EOPNOTSUPP; while in some other cases ENOTTY
> +         * will be reported (e.g. CD-ROMs).
> +         * Any other error means an unexpected error.
> +         */
> +        r.start = 0;
> +        r.len = -1;
> +        r.minlen = has_minimum ? minimum : 0;
> +        ret = ioctl(fd, FITRIM, &r);
> +        if (ret == -1) {
> +            result->has_error = true;
> +            if (errno == ENOTTY || errno == EOPNOTSUPP) {
> +                result->error = g_strdup("trim not supported");
> +            } else {
> +                result->error = g_strdup_printf("failed to trim: %s",
> +                                                strerror(errno));
> +            }
> +            close(fd);
> +            continue;
> +        }
> +
> +        result->has_minimum = true;
> +        result->minimum = r.minlen;
> +        result->has_trimmed = true;
> +        result->trimmed = r.len;
> +        close(fd);
> +    }
> +
> +    free_fs_mount_list(&mounts);
> +    return response;
> +}
> +#endif /* CONFIG_FSTRIM */
> diff --git a/qga/commands-posix.c b/qga/commands-posix.c
> index 32493d6383..b2a6d8b227 100644
> --- a/qga/commands-posix.c
> +++ b/qga/commands-posix.c
> @@ -1607,78 +1607,6 @@ GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error
> **errp)
>  }
>  #endif /* CONFIG_FSFREEZE */
>
> -#if defined(CONFIG_FSTRIM)
> -/*
> - * Walk list of mounted file systems in the guest, and trim them.
> - */
> -GuestFilesystemTrimResponse *
> -qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **errp)
> -{
> -    GuestFilesystemTrimResponse *response;
> -    GuestFilesystemTrimResult *result;
> -    int ret = 0;
> -    FsMountList mounts;
> -    struct FsMount *mount;
> -    int fd;
> -    struct fstrim_range r;
> -
> -    slog("guest-fstrim called");
> -
> -    QTAILQ_INIT(&mounts);
> -    if (!build_fs_mount_list(&mounts, errp)) {
> -        return NULL;
> -    }
> -
> -    response = g_malloc0(sizeof(*response));
> -
> -    QTAILQ_FOREACH(mount, &mounts, next) {
> -        result = g_malloc0(sizeof(*result));
> -        result->path = g_strdup(mount->dirname);
> -
> -        QAPI_LIST_PREPEND(response->paths, result);
> -
> -        fd = qga_open_cloexec(mount->dirname, O_RDONLY, 0);
> -        if (fd == -1) {
> -            result->error = g_strdup_printf("failed to open: %s",
> -                                            strerror(errno));
> -            result->has_error = true;
> -            continue;
> -        }
> -
> -        /* We try to cull filesystems we know won't work in advance, but
> other
> -         * filesystems may not implement fstrim for less obvious reasons.
> -         * These will report EOPNOTSUPP; while in some other cases ENOTTY
> -         * will be reported (e.g. CD-ROMs).
> -         * Any other error means an unexpected error.
> -         */
> -        r.start = 0;
> -        r.len = -1;
> -        r.minlen = has_minimum ? minimum : 0;
> -        ret = ioctl(fd, FITRIM, &r);
> -        if (ret == -1) {
> -            result->has_error = true;
> -            if (errno == ENOTTY || errno == EOPNOTSUPP) {
> -                result->error = g_strdup("trim not supported");
> -            } else {
> -                result->error = g_strdup_printf("failed to trim: %s",
> -                                                strerror(errno));
> -            }
> -            close(fd);
> -            continue;
> -        }
> -
> -        result->has_minimum = true;
> -        result->minimum = r.minlen;
> -        result->has_trimmed = true;
> -        result->trimmed = r.len;
> -        close(fd);
> -    }
> -
> -    free_fs_mount_list(&mounts);
> -    return response;
> -}
> -#endif /* CONFIG_FSTRIM */
> -
>
>  #define LINUX_SYS_STATE_FILE "/sys/power/state"
>  #define SUSPEND_SUPPORTED 0
> --
> 2.34.1
>
>

[-- Attachment #2: Type: text/html, Size: 7925 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] qga: Add ZFS TRIM support for FreeBSD
  2022-11-15 18:46 ` [PATCH 2/2] qga: Add ZFS TRIM support for FreeBSD Alexander Ivanov
@ 2022-11-17  8:55   ` Konstantin Kostiuk
  0 siblings, 0 replies; 6+ messages in thread
From: Konstantin Kostiuk @ 2022-11-17  8:55 UTC (permalink / raw)
  To: Alexander Ivanov; +Cc: qemu-devel, den, michael.roth, marcandre.lureau

[-- Attachment #1: Type: text/plain, Size: 4023 bytes --]

Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com>

On Tue, Nov 15, 2022 at 8:46 PM Alexander Ivanov <
alexander.ivanov@virtuozzo.com> wrote:

> Use zpool tool for ZFS pools trimming in FreeBSD.
>
> Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
> ---
>  qga/commands-bsd.c    | 109 ++++++++++++++++++++++++++++++++++++++++++
>  qga/commands-common.h |   1 +
>  2 files changed, 110 insertions(+)
>
> diff --git a/qga/commands-bsd.c b/qga/commands-bsd.c
> index 15cade2d4c..960c4209e5 100644
> --- a/qga/commands-bsd.c
> +++ b/qga/commands-bsd.c
> @@ -170,6 +170,115 @@ GuestCpuStatsList *qmp_guest_get_cpustats(Error
> **errp)
>  }
>  #endif /* CONFIG_FSFREEZE */
>
> +#if defined(CONFIG_FSTRIM)
> +typedef struct FsPool {
> +    char *name;
> +    QTAILQ_ENTRY(FsPool) next;
> +} FsPool;
> +
> +typedef QTAILQ_HEAD(FsPoolList, FsPool) FsPoolList;
> +
> +static void build_fs_pool_list(FsPoolList *pools, Error **errp)
> +{
> +    FILE *fp;
> +    char *line = NULL, *p;
> +    size_t linecap = 0;
> +    ssize_t linelen;
> +    FsPool *pool;
> +
> +    fp = popen("/sbin/zpool list -H", "r");
> +    if (fp == NULL) {
> +        error_setg_errno(errp, errno, "failed to run zpool");
> +        return;
> +    }
> +
> +    while ((linelen = getline(&line, &linecap, fp)) > 0) {
> +        p = strchr(line, '\t');
> +        if (!p) {
> +            continue;
> +        }
> +
> +        *p = '\0';
> +
> +        pool = g_new0(FsPool, 1);
> +        pool->name = g_strdup(line);
> +        QTAILQ_INSERT_TAIL(pools, pool, next);
> +    }
> +
> +    free(line);
> +    pclose(fp);
> +}
> +
> +static void free_fs_pool_list(FsPoolList *pools)
> +{
> +    FsPool *pool, *temp;
> +
> +    if (!pools) {
> +        return;
> +    }
> +
> +    QTAILQ_FOREACH_SAFE(pool, pools, next, temp) {
> +        QTAILQ_REMOVE(pools, pool, next);
> +        g_free(pool->name);
> +        g_free(pool);
> +    }
> +}
> +
> +/*
> + * Walk the list of ZFS pools in the guest, and trim them.
> + */
> +GuestFilesystemTrimResponse *
> +qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **errp)
> +{
> +    GuestFilesystemTrimResponse *response;
> +    GuestFilesystemTrimResultList *list;
> +    GuestFilesystemTrimResult *result;
> +    int ret;
> +    FsPoolList pools;
> +    FsPool *pool;
> +    char cmd[256];
> +    Error *local_err = NULL;
> +
> +    slog("guest-fstrim called");
> +
> +    QTAILQ_INIT(&pools);
> +    build_fs_pool_list(&pools, &local_err);
> +    if (local_err) {
> +        error_propagate(errp, local_err);
> +        return NULL;
> +    }
> +
> +    response = g_malloc0(sizeof(*response));
> +
> +    QTAILQ_FOREACH(pool, &pools, next) {
> +        result = g_malloc0(sizeof(*result));
> +        result->path = g_strdup(pool->name);
> +
> +        list = g_malloc0(sizeof(*list));
> +        list->value = result;
> +        list->next = response->paths;
> +        response->paths = list;
> +
> +        snprintf(cmd, sizeof(cmd), "/sbin/zpool trim %s", pool->name);
> +        ret = system(cmd);
> +        if (ret != 0) {
> +            result->error = g_strdup_printf("failed to trim %s: %s",
> +                                            pool->name, strerror(errno));
> +            result->has_error = true;
> +            continue;
> +        }
> +
> +        result->has_minimum = true;
> +        result->minimum = 0;
> +        result->has_trimmed = true;
> +        result->trimmed = 0;
> +    }
> +
> +    free_fs_pool_list(&pools);
> +    return response;
> +}
> +#endif /* CONFIG_FSTRIM */
> +
>  #ifdef HAVE_GETIFADDRS
>  /*
>   * Fill "buf" with MAC address by ifaddrs. Pointer buf must point to a
> diff --git a/qga/commands-common.h b/qga/commands-common.h
> index 8c1c56aac9..922f9c479b 100644
> --- a/qga/commands-common.h
> +++ b/qga/commands-common.h
> @@ -28,6 +28,7 @@
>  #ifdef UFSSUSPEND
>  #define CONFIG_FSFREEZE
>  #endif
> +#define CONFIG_FSTRIM
>  #endif /* __FreeBSD__ */
>
>  #if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM)
> --
> 2.34.1
>
>

[-- Attachment #2: Type: text/html, Size: 5298 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2] qga: Add ZFS TRIM support for FreeBSD
  2022-11-15 18:45 [PATCH 0/2] qga: Add ZFS TRIM support for FreeBSD Alexander Ivanov
  2022-11-15 18:45 ` [PATCH 1/2] qga: Move FS TRIM code to commands-linux.c Alexander Ivanov
  2022-11-15 18:46 ` [PATCH 2/2] qga: Add ZFS TRIM support for FreeBSD Alexander Ivanov
@ 2022-12-26 14:05 ` Konstantin Kostiuk
  2 siblings, 0 replies; 6+ messages in thread
From: Konstantin Kostiuk @ 2022-12-26 14:05 UTC (permalink / raw)
  To: Alexander Ivanov; +Cc: qemu-devel, den

[-- Attachment #1: Type: text/plain, Size: 751 bytes --]

Hi Alexander,

Can you please rebase your changes to the current master?
I failed to apply these patches.

Best Regards,
Konstantin Kostiuk.


On Tue, Nov 15, 2022 at 8:46 PM Alexander Ivanov <
alexander.ivanov@virtuozzo.com> wrote:

> Move Linux-specific FS TRIM code to commands-linux.c and add support of
> ZFS TRIM for FreeBSD.
>
> Alexander Ivanov (2):
>   qga: Move FS TRIM code to commands-linux.c
>   qga: Add ZFS TRIM support for FreeBSD
>
>  qga/commands-bsd.c    | 109 ++++++++++++++++++++++++++++++++++++++++++
>  qga/commands-common.h |   1 +
>  qga/commands-linux.c  |  73 ++++++++++++++++++++++++++++
>  qga/commands-posix.c  |  72 ----------------------------
>  4 files changed, 183 insertions(+), 72 deletions(-)
>
> --
> 2.34.1
>
>

[-- Attachment #2: Type: text/html, Size: 1318 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-12-26 14:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-15 18:45 [PATCH 0/2] qga: Add ZFS TRIM support for FreeBSD Alexander Ivanov
2022-11-15 18:45 ` [PATCH 1/2] qga: Move FS TRIM code to commands-linux.c Alexander Ivanov
2022-11-17  8:54   ` Konstantin Kostiuk
2022-11-15 18:46 ` [PATCH 2/2] qga: Add ZFS TRIM support for FreeBSD Alexander Ivanov
2022-11-17  8:55   ` Konstantin Kostiuk
2022-12-26 14:05 ` [PATCH 0/2] " Konstantin Kostiuk

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.