0a122b
From e7b184d50f2723ae82e35251ad8f05ec1cddb034 Mon Sep 17 00:00:00 2001
0a122b
Message-Id: <e7b184d50f2723ae82e35251ad8f05ec1cddb034.1387382496.git.minovotn@redhat.com>
0a122b
In-Reply-To: <c5386144fbf09f628148101bc674e2421cdd16e3.1387382496.git.minovotn@redhat.com>
0a122b
References: <c5386144fbf09f628148101bc674e2421cdd16e3.1387382496.git.minovotn@redhat.com>
0a122b
From: Nigel Croxon <ncroxon@redhat.com>
0a122b
Date: Thu, 14 Nov 2013 22:52:44 +0100
0a122b
Subject: [PATCH 08/46] rdma: introduce qemu_file_mode_is_not_valid()
0a122b
0a122b
RH-Author: Nigel Croxon <ncroxon@redhat.com>
0a122b
Message-id: <1384469598-13137-9-git-send-email-ncroxon@redhat.com>
0a122b
Patchwork-id: 55692
0a122b
O-Subject: [RHEL7.0 PATCH 08/42] rdma: introduce qemu_file_mode_is_not_valid()
0a122b
Bugzilla: 1011720
0a122b
RH-Acked-by: Orit Wasserman <owasserm@redhat.com>
0a122b
RH-Acked-by: Amit Shah <amit.shah@redhat.com>
0a122b
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
0a122b
0a122b
Bugzilla: 1011720
0a122b
https://bugzilla.redhat.com/show_bug.cgi?id=1011720
0a122b
0a122b
>From commit ID:
0a122b
commit bc1256f7f187cc7d491bfe3861249a60873adbbc
0a122b
Author: Michael R. Hines <mrhines@us.ibm.com>
0a122b
Date:   Tue Jun 25 21:35:31 2013 -0400
0a122b
0a122b
    rdma: introduce qemu_file_mode_is_not_valid()
0a122b
0a122b
    QEMUFileRDMA also has read and write modes. This function is now
0a122b
    shared to reduce code duplication.
0a122b
0a122b
    Reviewed-by: Juan Quintela <quintela@redhat.com>
0a122b
    Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
0a122b
    Reviewed-by: Chegu Vinod <chegu_vinod@hp.com>
0a122b
    Tested-by: Chegu Vinod <chegu_vinod@hp.com>
0a122b
    Tested-by: Michael R. Hines <mrhines@us.ibm.com>
0a122b
    Signed-off-by: Michael R. Hines <mrhines@us.ibm.com>
0a122b
    Signed-off-by: Juan Quintela <quintela@redhat.com>
0a122b
---
0a122b
 include/migration/qemu-file.h |    1 +
0a122b
 savevm.c                      |   20 +++++++++++++-------
0a122b
 2 files changed, 14 insertions(+), 7 deletions(-)
0a122b
0a122b
Signed-off-by: Michal Novotny <minovotn@redhat.com>
0a122b
---
0a122b
 include/migration/qemu-file.h |  1 +
0a122b
 savevm.c                      | 20 +++++++++++++-------
0a122b
 2 files changed, 14 insertions(+), 7 deletions(-)
0a122b
0a122b
diff --git a/include/migration/qemu-file.h b/include/migration/qemu-file.h
0a122b
index fb1cf40..37d1604 100644
0a122b
--- a/include/migration/qemu-file.h
0a122b
+++ b/include/migration/qemu-file.h
0a122b
@@ -80,6 +80,7 @@ void qemu_put_byte(QEMUFile *f, int v);
0a122b
  * The buffer should be available till it is sent asynchronously.
0a122b
  */
0a122b
 void qemu_put_buffer_async(QEMUFile *f, const uint8_t *buf, int size);
0a122b
+bool qemu_file_mode_is_not_valid(const char *mode);
0a122b
 
0a122b
 static inline void qemu_put_ubyte(QEMUFile *f, unsigned int v)
0a122b
 {
0a122b
diff --git a/savevm.c b/savevm.c
0a122b
index 9304788..26d5607 100644
0a122b
--- a/savevm.c
0a122b
+++ b/savevm.c
0a122b
@@ -449,14 +449,23 @@ static const QEMUFileOps socket_write_ops = {
0a122b
     .close =      socket_close
0a122b
 };
0a122b
 
0a122b
-QEMUFile *qemu_fopen_socket(int fd, const char *mode)
0a122b
+bool qemu_file_mode_is_not_valid(const char *mode)
0a122b
 {
0a122b
-    QEMUFileSocket *s;
0a122b
-
0a122b
     if (mode == NULL ||
0a122b
         (mode[0] != 'r' && mode[0] != 'w') ||
0a122b
         mode[1] != 'b' || mode[2] != 0) {
0a122b
         fprintf(stderr, "qemu_fopen: Argument validity check failed\n");
0a122b
+        return true;
0a122b
+    }
0a122b
+
0a122b
+    return false;
0a122b
+}
0a122b
+
0a122b
+QEMUFile *qemu_fopen_socket(int fd, const char *mode)
0a122b
+{
0a122b
+    QEMUFileSocket *s;
0a122b
+
0a122b
+    if (qemu_file_mode_is_not_valid(mode)) {
0a122b
         return NULL;
0a122b
     }
0a122b
 
0a122b
@@ -475,10 +484,7 @@ QEMUFile *qemu_fopen(const char *filename, const char *mode)
0a122b
 {
0a122b
     QEMUFileStdio *s;
0a122b
 
0a122b
-    if (mode == NULL ||
0a122b
-	(mode[0] != 'r' && mode[0] != 'w') ||
0a122b
-	mode[1] != 'b' || mode[2] != 0) {
0a122b
-        fprintf(stderr, "qemu_fopen: Argument validity check failed\n");
0a122b
+    if (qemu_file_mode_is_not_valid(mode)) {
0a122b
         return NULL;
0a122b
     }
0a122b
 
0a122b
-- 
0a122b
1.7.11.7
0a122b