[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL v4 03/11] rdma: introduce qemu_file_mode_is_not_valid
From: |
mrhines |
Subject: |
[Qemu-devel] [PULL v4 03/11] rdma: introduce qemu_file_mode_is_not_valid() |
Date: |
Wed, 17 Apr 2013 19:07:12 -0400 |
From: "Michael R. Hines" <address@hidden>
QEMUFileRDMA also has read and write modes. This function is now
shared to reduce code duplication.
Signed-off-by: Michael R. Hines <address@hidden>
---
include/migration/qemu-file.h | 2 ++
savevm.c | 20 +++++++++++++-------
2 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/include/migration/qemu-file.h b/include/migration/qemu-file.h
index 7519464..efc9970 100644
--- a/include/migration/qemu-file.h
+++ b/include/migration/qemu-file.h
@@ -81,6 +81,8 @@ void qemu_put_byte(QEMUFile *f, int v);
*/
void qemu_put_buffer_async(QEMUFile *f, const uint8_t *buf, int size);
+bool qemu_file_mode_is_not_valid(const char *mode);
+
static inline void qemu_put_ubyte(QEMUFile *f, unsigned int v)
{
qemu_put_byte(f, (int)v);
diff --git a/savevm.c b/savevm.c
index c2e61dd..45389f0 100644
--- a/savevm.c
+++ b/savevm.c
@@ -381,14 +381,23 @@ static const QEMUFileOps socket_write_ops = {
.close = socket_close
};
-QEMUFile *qemu_fopen_socket(int fd, const char *mode)
+bool qemu_file_mode_is_not_valid(const char *mode)
{
- QEMUFileSocket *s = g_malloc0(sizeof(QEMUFileSocket));
-
if (mode == NULL ||
(mode[0] != 'r' && mode[0] != 'w') ||
mode[1] != 'b' || mode[2] != 0) {
fprintf(stderr, "qemu_fopen: Argument validity check failed\n");
+ return true;
+ }
+
+ return false;
+}
+
+QEMUFile *qemu_fopen_socket(int fd, const char *mode)
+{
+ QEMUFileSocket *s = g_malloc0(sizeof(QEMUFileSocket));
+
+ if (qemu_file_mode_is_not_valid(mode)) {
return NULL;
}
@@ -406,10 +415,7 @@ QEMUFile *qemu_fopen(const char *filename, const char
*mode)
{
QEMUFileStdio *s;
- if (mode == NULL ||
- (mode[0] != 'r' && mode[0] != 'w') ||
- mode[1] != 'b' || mode[2] != 0) {
- fprintf(stderr, "qemu_fopen: Argument validity check failed\n");
+ if (qemu_file_mode_is_not_valid(mode)) {
return NULL;
}
--
1.7.10.4
- [Qemu-devel] [PULL v4 00/11] rdma: migration support, mrhines, 2013/04/17
- [Qemu-devel] [PULL v4 02/11] rdma: introduce qemu_ram_foreach_block(), mrhines, 2013/04/17
- [Qemu-devel] [PULL v4 03/11] rdma: introduce qemu_file_mode_is_not_valid(),
mrhines <=
- [Qemu-devel] [PULL v4 04/11] rdma: export ram_handle_compressed(), mrhines, 2013/04/17
- [Qemu-devel] [PULL v4 10/11] rdma: print out throughput while debugging, mrhines, 2013/04/17
- [Qemu-devel] [PULL v4 06/11] rdma: new QEMUFileOps hooks, mrhines, 2013/04/17
- [Qemu-devel] [PULL v4 01/11] rdma: export yield_until_fd_readable(), mrhines, 2013/04/17
- [Qemu-devel] [PULL v4 05/11] rdma: export qemu_fflush(), mrhines, 2013/04/17
- [Qemu-devel] [PULL v4 07/11] rdma: introduce capability for chunk registration, mrhines, 2013/04/17