From 1dca074d616d67dbc8171934b18d40e2c917baab Mon Sep 17 00:00:00 2001
Message-Id: <1dca074d616d67dbc8171934b18d40e2c917baab.1367947969.git.minovotn@redhat.com>
In-Reply-To: <707b9b97153063374d2530e72c49b1499fc21af9.1367947969.git.minovotn@redhat.com>
References: <707b9b97153063374d2530e72c49b1499fc21af9.1367947969.git.minovotn@redhat.com>
From: Michal Novotny <minovotn@redhat.com>
Date: Tue, 7 May 2013 18:38:39 +0200
Subject: [PATCH 056/114] Revert "qemu-ga: add guest-fstrim command"

This reverts commit 2a4fc2755f61bd633a6b736987824b5435ff06e3.

Reverting as asked by Laszlo in message <51892739.2030807@redhat.com>
because of the ordering issue (most likely) related to supersed
testing.

Signed-off-by: Michal Novotny <minovotn@redhat.com>
---
 qapi-schema-guest.json | 20 -------------
 qga/commands-posix.c   | 78 ++------------------------------------------------
 qga/commands-win32.c   | 11 -------
 3 files changed, 3 insertions(+), 106 deletions(-)

diff --git a/qapi-schema-guest.json b/qapi-schema-guest.json
index d955cf1..d4055d2 100644
--- a/qapi-schema-guest.json
+++ b/qapi-schema-guest.json
@@ -351,26 +351,6 @@
   'returns': 'int' }
 
 ##
-# @guest-fstrim:
-#
-# Discard (or "trim") blocks which are not in use by the filesystem.
-#
-# @minimum:
-#       Minimum contiguous free range to discard, in bytes. Free ranges
-#       smaller than this may be ignored (this is a hint and the guest
-#       may not respect it).  By increasing this value, the fstrim
-#       operation will complete more quickly for filesystems with badly
-#       fragmented free space, although not all blocks will be discarded.
-#       The default value is zero, meaning "discard every free block".
-#
-# Returns: Nothing.
-#
-# Since: 1.2
-##
-{ 'command': 'guest-fstrim',
-  'data': { '*minimum': 'int' } }
-
-##
 # @guest-suspend-disk
 #
 # Suspend guest to disk.
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index f1b8c5b..05f477d 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -17,12 +17,9 @@
 #include <mntent.h>
 #include <linux/fs.h>
 
-#ifdef FIFREEZE
+#if defined(__linux__) && defined(FIFREEZE)
 #define CONFIG_FSFREEZE
 #endif
-#ifdef FITRIM
-#define CONFIG_FSTRIM
-#endif
 #endif
 
 #include <sys/types.h>
@@ -316,7 +313,8 @@ static void guest_file_init(void)
 /* linux-specific implementations. avoid this if at all possible. */
 #if defined(__linux__)
 
-#if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM)
+#if defined(CONFIG_FSFREEZE)
+
 typedef struct FsMount {
     char *dirname;
     char *devtype;
@@ -381,9 +379,6 @@ static int build_fs_mount_list(FsMountList *mounts)
 
     return 0;
 }
-#endif
-
-#if defined(CONFIG_FSFREEZE)
 
 /*
  * Return status of freeze/thaw
@@ -531,65 +526,6 @@ static void guest_fsfreeze_cleanup(void)
 }
 #endif /* CONFIG_FSFREEZE */
 
-#if defined(CONFIG_FSTRIM)
-/*
- * Walk list of mounted file systems in the guest, and trim them.
- */
-void qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **err)
-{
-    int ret = 0;
-    FsMountList mounts;
-    struct FsMount *mount;
-    int fd;
-    char err_msg[512];
-    struct fstrim_range r = {
-        .start = 0,
-        .len = -1,
-        .minlen = has_minimum ? minimum : 0,
-    };
-
-    slog("guest-fstrim called");
-
-    QTAILQ_INIT(&mounts);
-    ret = build_fs_mount_list(&mounts);
-    if (ret < 0) {
-        return;
-    }
-
-    QTAILQ_FOREACH(mount, &mounts, next) {
-        fd = qemu_open(mount->dirname, O_RDONLY);
-        if (fd == -1) {
-            sprintf(err_msg, "failed to open %s, %s", mount->dirname,
-                    strerror(errno));
-            error_set(err, QERR_QGA_COMMAND_FAILED, err_msg);
-            goto error;
-        }
-
-        /* We try to cull filesytems we know won't work in advance, but other
-         * filesytems may not implement fstrim for less obvious reasons.  These
-         * will report EOPNOTSUPP; we simply ignore these errors.  Any other
-         * error means an unexpected error, so return it in those cases.  In
-         * some other cases ENOTTY will be reported (e.g. CD-ROMs).
-         */
-        ret = ioctl(fd, FITRIM, &r);
-        if (ret == -1) {
-            if (errno != ENOTTY && errno != EOPNOTSUPP) {
-                sprintf(err_msg, "failed to trim %s, %s",
-                        mount->dirname, strerror(errno));
-                error_set(err, QERR_QGA_COMMAND_FAILED, err_msg);
-                close(fd);
-                goto error;
-            }
-        }
-        close(fd);
-    }
-
-error:
-    free_fs_mount_list(&mounts);
-}
-#endif /* CONFIG_FSTRIM */
-
-
 #define LINUX_SYS_STATE_FILE "/sys/power/state"
 #define SUSPEND_SUPPORTED 0
 #define SUSPEND_NOT_SUPPORTED 1
@@ -983,15 +919,7 @@ int64_t qmp_guest_fsfreeze_thaw(Error **err)
 
     return 0;
 }
-#endif /* CONFIG_FSFREEZE */
-
-#if !defined(CONFIG_FSTRIM)
-void qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **err)
-{
-    error_set(err, QERR_UNSUPPORTED);
 
-    return;
-}
 #endif
 
 /* register init/cleanup routines for stateful command groups */
diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 54bc546..eb8d140 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -173,17 +173,6 @@ int64_t qmp_guest_fsfreeze_thaw(Error **err)
     return 0;
 }
 
-/*
- * Walk list of mounted file systems in the guest, and discard unused
- * areas.
- */
-void qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **err)
-{
-    error_set(err, QERR_UNSUPPORTED);
-
-    return;
-}
-
 typedef enum {
     GUEST_SUSPEND_MODE_DISK,
     GUEST_SUSPEND_MODE_RAM
-- 
1.7.11.7

