qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC PATCH v3 7/9] repagent: Fixes after remarks for Patch


From: Ori Mamluk
Subject: [Qemu-devel] [RFC PATCH v3 7/9] repagent: Fixes after remarks for Patch v2, mainly license and style
Date: Thu, 5 Apr 2012 15:18:00 +0300

Added qemu license to all files

Changed int to bool for flags

---

block/repagent/qemu-repagent.txt |   16 ++++++++------

block/repagent/repagent.c        |   39 ++++++++++++++++++++++++++++++-------

block/repagent/repagent.h        |    7 +++--

block/repagent/repagent_client.c |   35 ++++++++++++++++++++++++++++-----

block/repagent/repagent_drv.c    |   23 ++++++++++++++++++++++

block/repagent/repcmd_listener.c |   38 ++++++++++++++++++++++++++++++------

block/repagent/rephub_defs.h     |    8 -------

7 files changed, 127 insertions(+), 39 deletions(-)

 

diff --git a/block/repagent/qemu-repagent.txt b/block/repagent/qemu-repagent.txt

index f8def3f..0f9dc03 100644

--- a/block/repagent/qemu-repagent.txt

+++ b/block/repagent/qemu-repagent.txt

@@ -4,20 +4,22 @@ Introduction

     This document describes a feature in Qemu - a replication agent (named Repagent).

     The Repagent is a new module that exposes an API to an external replication system (AKA Rephub).

     This API allows a Rephub to communicate with a Qemu VM and continuously replicate its volumes.

-    The imlementation of a Rephub is outside of the scope of this document. There may be several various Rephub

-    implenetations using the same repagent in Qemu.

-    The Repagent is storage driver that acts like a filter driver.

+    The implementation of a Rephub is outside of the scope of this document. There may be several various Rephub

+    implementations using the same Repagent in Qemu.

+    The Repagent acts like a filter driver.

     It can be regarded as a 'plugin' that is activated when the management system enables replication.

 Main feature of Repagent

     Repagent has the following main features:

     * Report volumes - report a list of all volumes in a VM to the Rephub.

    * Mirror writes - Report writes to a volume - send all writes made to a protected volume to the Rephub.

-        The reporting of an IO is asyncronuous - i.e. the IO is not delayed by the Repagent to get any acknowledgement from the Rephub.

+        The reporting of an IO is asynchronous - i.e. the IO is not delayed by the Repagent to get any acknowledgement from the Rephub.

         It is only copied to the Rephub.

-    * Remote IO - Read/write a  volume - allows the Rephub to read a protected volume, to enable the protected hub to syncronize

+    * Remote IO - Read/write a  volume - allows the Rephub to read a protected volume, to enable the protected hub to synchronize

        the content of a protected volume.

        Also used to read/write to a recovery volume - the replica of a protected volume.

+       Write operation is used to populate the recovery volume. Read is needed for fail-over-test scenarios, and for sync-related

+       optimizations.

 Description of the Repagent module

@@ -48,7 +50,7 @@ General description of a Rephub  - a replication system the repagent connects to

     Our Rephub is called SingleRephub - a Rephub protecting a single VM.

     Preparations

-    1. The user chooses a host to rub SingleRephub - a different host than PVM, call it Host2

+    1. The user chooses a host to run SingleRephub - a different host than PVM, call it Host2

     2. The user creates two volumes on Host2 - same sizes of V1 and V2, call them V1R (V1 recovery) and V2R.

     3. The user runs SingleRephub process on Host2, and gives V1R and V2R as command line arguments.

         From now on SingleRephub waits for the protected VM repagent to connect.

@@ -64,7 +66,7 @@ General description of a Rephub  - a replication system the repagent connects to

         and the Rephub performs the write on the matching recovery volume.

     * Note that during stage 3 writes to the protected volumes are not ignored - they're kept in a bitmap,

-        and will be read again when stage 3 ends, in an interative convergin process.

+        and will be read again when stage 3 ends, in an iterative convergence process.

     This flow continuously maintains an updated recovery volume.

     If the protected system is damaged, the user can create a new VM on Host2 with the replicated volumes attached to it.

diff --git a/block/repagent/repagent.c b/block/repagent/repagent.c

index bdc0117..2e70853 100644

--- a/block/repagent/repagent.c

+++ b/block/repagent/repagent.c

@@ -1,3 +1,26 @@

+/*

+ * QEMU System Emulator replication agent

+ *

+ * Copyright (c) 2003 Fabrice Bellard

+ *

+ * Permission is hereby granted, free of charge, to any person obtaining a copy

+ * of this software and associated documentation files (the "Software"), to deal

+ * in the Software without restriction, including without limitation the rights

+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

+ * copies of the Software, and to permit persons to whom the Software is

+ * furnished to do so, subject to the following conditions:

+ *

+ * The above copyright notice and this permission notice shall be included in

+ * all copies or substantial portions of the Software.

+ *

+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL

+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,

+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN

+ * THE SOFTWARE.

+ */

#include <string.h>

#include <stdlib.h>

#include <stdio.h>

@@ -22,7 +45,7 @@ typedef struct RepagentVolume {

} RepagentVolume;

 struct RepAgentState {

-    int is_init;

+    bool is_init;

     int num_volumes;

     RepagentVolume *volumes[REPAGENT_MAX_NUM_VOLUMES];

};

@@ -46,7 +69,7 @@ RepAgentState g_rep_agent = { 0 };

void repagent_init(const char *hubname, int port)

{

     /* It is the responsibility of the thread to free this struct */

-    rephub_params *pParams = (rephub_params *)g_malloc(sizeof(rephub_params));

+    rephub_params *pParams = g_malloc(sizeof(rephub_params));

     if (hubname == NULL) {

         hubname = "127.0.0.1";

     }

@@ -197,7 +220,7 @@ static void repagent_report_volumes_to_hub(void)

     }

}

-int repaget_start_protect(RepCmdStartProtect *pcmd,

+bool repaget_start_protect(RepCmdStartProtect *pcmd,

         RepCmdDataStartProtect *pcmd_data)

{

     printf("Start protect vol %s, ID %llu\n", pcmd_data->volume_name,

@@ -210,12 +233,12 @@ int repaget_start_protect(RepCmdStartProtect *pcmd,

     }

     if (vol_index < 0) {

         printf("The volume doesn't exist\n");

-        return TRUE;

+        return true;

     }

     /* orim todo protect */

     g_rep_agent.volumes[vol_index]->vol_id = pcmd->volume_id;

-    return TRUE;

+    return true;

}

 static int repagent_get_volume_by_name(const char *name)

@@ -242,7 +265,7 @@ static int repagent_get_volume_by_id(uint64_t vol_id)

     return -1;

}

-int repagent_remote_io(RepCmdRemoteIoReq *pcmd, uint8_t *pdata)

+bool repagent_remote_io(RepCmdRemoteIoReq *pcmd, uint8_t *pdata)

{

     int index = repagent_get_volume_by_id(pcmd->volume_id);

     int size_bytes = pcmd->size_sectors * 512;

@@ -255,7 +278,7 @@ int repagent_remote_io(RepCmdRemoteIoReq *pcmd, uint8_t *pdata)

         p_res_cmd->volume_id = pcmd->volume_id;

         p_res_cmd->io_status = -1;

         repagent_client_send((RepCmd *) p_res_cmd);

-        return TRUE;

+        return true;

     }

     printf("Vol read - driver %p, volId %llu, offset %llu, size %u\n",

@@ -294,7 +317,7 @@ int repagent_remote_io(RepCmdRemoteIoReq *pcmd, uint8_t *pdata)

         }

     }

-    return TRUE;

+    return true;

}

 static void repagent_remote_io_done(void *opaque, int ret)

diff --git a/block/repagent/repagent.h b/block/repagent/repagent.h

index 0f69820..2863ffc 100644

--- a/block/repagent/repagent.h

+++ b/block/repagent/repagent.h

@@ -38,14 +38,15 @@ extern int use_repagent;

 void repagent_init(const char *hubname, int port);

void repagent_handle_protected_write(BlockDriverState *bs,

-        int64_t sector_num, int nb_sectors, QEMUIOVector *qiov, int ret_status);

+        int64_t sector_num,

+        int nb_sectors, QEMUIOVector *qiov, int ret_status);

void repagent_register_drive(const char *drive_path,

         BlockDriverState *driver_ptr);

void repagent_deregister_drive(const char *drive_path,

         BlockDriverState *driver_ptr);

-int repaget_start_protect(RepCmdStartProtect *pcmd,

+bool repaget_start_protect(RepCmdStartProtect *pcmd,

         RepCmdDataStartProtect *pcmd_data);

-int repagent_remote_io(struct RepCmdRemoteIoReq *pcmd, uint8_t *pdata);

+bool repagent_remote_io(struct RepCmdRemoteIoReq *pcmd, uint8_t *pdata);

void repagent_client_connected(void);

 

diff --git a/block/repagent/repagent_client.c b/block/repagent/repagent_client.c

index ee4aeb7..9d826c4 100644

--- a/block/repagent/repagent_client.c

+++ b/block/repagent/repagent_client.c

@@ -1,3 +1,26 @@

+/*

+ * QEMU System Emulator replication agent - socket client

+ *

+ * Copyright (c) 2003 Fabrice Bellard

+ *

+ * Permission is hereby granted, free of charge, to any person obtaining a copy

+ * of this software and associated documentation files (the "Software"), to deal

+ * in the Software without restriction, including without limitation the rights

+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

+ * copies of the Software, and to permit persons to whom the Software is

+ * furnished to do so, subject to the following conditions:

+ *

+ * The above copyright notice and this permission notice shall be included in

+ * all copies or substantial portions of the Software.

+ *

+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL

+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,

+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN

+ * THE SOFTWARE.

+ */

#include "repcmd.h"

#include "rephub_cmds.h"

#include "repcmd_listener.h"

@@ -20,8 +43,8 @@

static void repagent_process_cmd(RepCmd *pCmd, uint8_t *pData, void *clientPtr);

 typedef struct repagent_client_state {

-    int is_connected;

-    int is_terminate_receive;

+    bool is_connected;

+    bool is_terminate_receive;

     int hsock;

} repagent_client_state;

@@ -34,7 +57,7 @@ static void repagent_client_read(void *opaque)

     if (bytes_read <= 0) {

         printf("repagent_client_read failed (%d), errno=%d\n",

         bytes_read, errno);

-        g_client_state.is_connected = 0;

+        g_client_state.is_connected = false;

     }

}

@@ -93,7 +116,7 @@ void *repagent_listen(void *pParam)

         retries = 0;

         printf("After connect\n");

-        g_client_state.is_connected = 1;

+        g_client_state.is_connected = true;

         repagent_client_connected();

         repcmd_listener_init(repagent_process_cmd, NULL);

         static int c;

@@ -108,7 +131,7 @@ void *repagent_listen(void *pParam)

         qemu_set_fd_handler(g_client_state.hsock, NULL, NULL, NULL);

         printf("Disconnected\n");

-        g_client_state.is_connected = 0;

+        g_client_state.is_connected = false;

         close(g_client_state.hsock);

     }

@@ -117,7 +140,7 @@ void *repagent_listen(void *pParam)

 void repagent_process_cmd(RepCmd *pcmd, uint8_t *pdata, void *clientPtr)

{

-    int is_free_data = 1;

+    bool is_free_data = true;

     printf("Repagent got cmd %d\n", pcmd->hdr.cmdid);

     switch (pcmd->hdr.cmdid) {

     case REPHUB_CMD_START_PROTECT: {

diff --git a/block/repagent/repagent_drv.c b/block/repagent/repagent_drv.c

index 8c9f2b6..4775166 100644

--- a/block/repagent/repagent_drv.c

+++ b/block/repagent/repagent_drv.c

@@ -1,3 +1,26 @@

+/*

+ * QEMU System Emulator replication agent - repagent block driver

+ *

+ * Copyright (c) 2003 Fabrice Bellard

+ *

+ * Permission is hereby granted, free of charge, to any person obtaining a copy

+ * of this software and associated documentation files (the "Software"), to deal

+ * in the Software without restriction, including without limitation the rights

+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

+ * copies of the Software, and to permit persons to whom the Software is

+ * furnished to do so, subject to the following conditions:

+ *

+ * The above copyright notice and this permission notice shall be included in

+ * all copies or substantial portions of the Software.

+ *

+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL

+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,

+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN

+ * THE SOFTWARE.

+ */

#include <string.h>

#include <stdlib.h>

#include <stdio.h>

diff --git a/block/repagent/repcmd_listener.c b/block/repagent/repcmd_listener.c

index 54d3f60..e6b4d74 100644

--- a/block/repagent/repcmd_listener.c

+++ b/block/repagent/repcmd_listener.c

@@ -1,3 +1,26 @@

+/*

+ * QEMU System Emulator replication agent - socket commands layer

+ *

+ * Copyright (c) 2003 Fabrice Bellard

+ *

+ * Permission is hereby granted, free of charge, to any person obtaining a copy

+ * of this software and associated documentation files (the "Software"), to deal

+ * in the Software without restriction, including without limitation the rights

+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

+ * copies of the Software, and to permit persons to whom the Software is

+ * furnished to do so, subject to the following conditions:

+ *

+ * The above copyright notice and this permission notice shall be included in

+ * all copies or substantial portions of the Software.

+ *

+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL

+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,

+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN

+ * THE SOFTWARE.

+ */

#include <fcntl.h>

#include <string.h>

#include <stdlib.h>

@@ -10,6 +33,7 @@

#include <unistd.h>

#include <pthread.h>

#include <assert.h>

+#include <stdbool.h>

 /* Use the CONFIG_REPAGENT flag to determine whether

  * we're under qemu build or a hub When under

@@ -32,12 +56,12 @@ typedef struct RepCmdRxCmdState {

     uint8_t *pReadBuf;

     int bytesToGet;

     int bytesGotten;

-    int isGotHeader;

+    bool isGotHeader;

     uint8_t *pdata;

} RepCmdRxCmdState;

 typedef struct RepCmdListenerState {

-    int is_terminate_receive;

+    bool is_terminate_receive;

     pfn_received_cmd_cb  receive_cb;

     void *opaque;

     int hsock;

@@ -111,11 +135,11 @@ static int repcmd_listener_process_rx(int bytecount)

     }

     assert(cmd_state->bytesGotten <= cmd_state->bytesToGet);

     if (cmd_state->bytesGotten == cmd_state->bytesToGet) {

-        int isGotData = 0;

+        bool isGotData = false;

         cmd_state->bytesGotten = 0;

         if (!cmd_state->isGotHeader) {

             /* We just got the header */

-            cmd_state->isGotHeader = 1;

+            cmd_state->isGotHeader = true;

             assert(cmd_state->curCmd.hdr.magic1 == REPCMD_MAGIC1);

             assert(cmd_state->curCmd.magic2 == REPCMD_MAGIC2);

@@ -126,12 +150,12 @@ static int repcmd_listener_process_rx(int bytecount)

                 cmd_state->pReadBuf = cmd_state->pdata;

             } else {

                 /* no data */

-                isGotData = 1;

+                isGotData = true;

                 cmd_state->pdata = NULL;

             }

             cmd_state->bytesToGet = cmd_state->curCmd.hdr.data_size_bytes;

         } else {

-            isGotData = 1;

+            isGotData = true;

         }

         if (isGotData) {

@@ -145,7 +169,7 @@ static int repcmd_listener_process_rx(int bytecount)

             cmd_state->pReadBuf = (uint8_t *) &cmd_state->curCmd;

             cmd_state->bytesGotten = 0;

             cmd_state->bytesToGet = sizeof(RepCmd);

-            cmd_state->isGotHeader = 0;

+            cmd_state->isGotHeader = false;

         }

     }

     return bytecount;

diff --git a/block/repagent/rephub_defs.h b/block/repagent/rephub_defs.h

index e34e0ce..f036f58 100644

--- a/block/repagent/rephub_defs.h

+++ b/block/repagent/rephub_defs.h

@@ -29,12 +29,4 @@

#define REPHUB_MAX_VOL_NAME_LEN (1024)

#define REPHUB_MAX_NUM_VOLUMES (512)

-#ifndef TRUE

-    #define TRUE (1)

-#endif

-

-#ifndef FALSE

-    #define FALSE (0)

-#endif

-

#endif /* REP_HUB_DEFS_H */

--

1.7.6.5


reply via email to

[Prev in Thread] Current Thread [Next in Thread]