Patchwork [07/10] qemu-ga: qmp_guest_fstrim(): get rid of sprintf() + error_set()

login
register
mail settings
Submitter Luiz Capitulino
Date Nov. 27, 2012, 1:02 p.m.
Message ID <1354021324-31561-8-git-send-email-lcapitulino@redhat.com>
Download mbox | patch
Permalink /patch/202210/
State New
Headers show

Comments

Luiz Capitulino - Nov. 27, 2012, 1:02 p.m.
Convert them to error_setg_errno().

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 qga/commands-posix.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
Michael Roth - Nov. 28, 2012, 7:41 p.m.
On Tue, Nov 27, 2012 at 11:02:01AM -0200, Luiz Capitulino wrote:
> Convert them to error_setg_errno().
> 
> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>

Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>

> ---
>  qga/commands-posix.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/qga/commands-posix.c b/qga/commands-posix.c
> index 9325433..72ef8ba 100644
> --- a/qga/commands-posix.c
> +++ b/qga/commands-posix.c
> @@ -565,7 +565,6 @@ void qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **err)
>      struct FsMount *mount;
>      int fd;
>      Error *local_err = NULL;
> -    char err_msg[512];
>      struct fstrim_range r = {
>          .start = 0,
>          .len = -1,
> @@ -584,9 +583,7 @@ void qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **err)
>      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);
> +            error_setg_errno(err, errno, "failed to open %s", mount->dirname);
>              goto error;
>          }
> 
> @@ -599,9 +596,8 @@ void qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **err)
>          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);
> +                error_setg_errno(err, errno, "failed to trim %s",
> +                                 mount->dirname);
>                  close(fd);
>                  goto error;
>              }
> -- 
> 1.8.0
>

Patch

diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 9325433..72ef8ba 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -565,7 +565,6 @@  void qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **err)
     struct FsMount *mount;
     int fd;
     Error *local_err = NULL;
-    char err_msg[512];
     struct fstrim_range r = {
         .start = 0,
         .len = -1,
@@ -584,9 +583,7 @@  void qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **err)
     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);
+            error_setg_errno(err, errno, "failed to open %s", mount->dirname);
             goto error;
         }
 
@@ -599,9 +596,8 @@  void qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **err)
         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);
+                error_setg_errno(err, errno, "failed to trim %s",
+                                 mount->dirname);
                 close(fd);
                 goto error;
             }