From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:57838) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFle1-0004wu-Sj for qemu-devel@nongnu.org; Thu, 05 Apr 2012 08:18:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SFldr-0002gb-8L for qemu-devel@nongnu.org; Thu, 05 Apr 2012 08:18:28 -0400 Received: from mail-qa0-f46.google.com ([209.85.216.46]:44147) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFldr-0002e8-2k for qemu-devel@nongnu.org; Thu, 05 Apr 2012 08:18:19 -0400 Received: by mail-qa0-f46.google.com with SMTP id m19so1280381qat.12 for ; Thu, 05 Apr 2012 05:18:15 -0700 (PDT) From: Ori Mamluk MIME-Version: 1.0 Date: Thu, 5 Apr 2012 15:18:00 +0300 Message-ID: <14b288a7154e8590dc79f04d7edc154f@mail.gmail.com> Content-Type: multipart/alternative; boundary=20cf302ef8ced1358604bced8874 Subject: [Qemu-devel] [RFC PATCH v3 7/9] repagent: Fixes after remarks for Patch v2, mainly license and style List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Roni Luxenberg , Stefan Hajnoczi , dlaor@redhat.com, Anthony Liguori , Oded Kedem , Yair Kuszpet , Paolo Bonzini --20cf302ef8ced1358604bced8874 Content-Type: text/plain; charset=ISO-8859-1 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 #include #include @@ -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 #include #include 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 #include #include @@ -10,6 +33,7 @@ #include #include #include +#include /* 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 --20cf302ef8ced1358604bced8874 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

Added qemu license to all fil= es

Changed int to bool for flags

---

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

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

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

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

block/repagent/repage= nt_drv.c=A0=A0=A0 |=A0=A0 23 ++++++++++++++++++++++

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

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

7 files changed, 127 insertions(+), 3= 9 deletions(-)

=A0

diff= --git a/block/repagent/qemu-repagent.txt b/block/repagent/qemu-repagent.tx= t

index f8def3f..0f9dc03 100644

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

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

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

=A0=A0=A0=A0 This document describes a feature in Qe= mu - a replication agent (named Repagent).

=A0=A0= =A0=A0 The Repagent is a new module that exposes an API to an external repl= ication system (AKA Rephub).

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

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

-=A0=A0=A0 implenetations using the same repagent in= Qemu.

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

+=A0=A0=A0 The im= plementation of a Rephub is outside of the scope of this document. There ma= y be several various Rephub

+=A0=A0=A0 implementations using the same Repagent i= n Qemu.

+=A0=A0=A0 The Repagent acts like a filte= r driver.

=A0=A0=A0=A0 It can be regarded as a &#= 39;plugin' that is activated when the management system enables replica= tion.

=A0Main feature of Repag= ent

=A0=A0=A0=A0 Repagent has the following main = features:

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

=A0=A0=A0=A0* Mirror writes - Report writes to a vo= lume - send all writes made to a protected volume to the Rephub.

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

+=A0=A0=A0=A0=A0=A0=A0 The reporting of an IO is asy= nchronous - i.e. the IO is not delayed by the Repagent to get any acknowled= gement from the Rephub.

=A0=A0=A0=A0=A0=A0=A0=A0 = It is only copied to the Rephub.

-=A0=A0=A0 * Remote IO - Read/write a=A0 volume - al= lows the Rephub to read a protected volume, to enable the protected hub to = syncronize

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

=A0=A0=A0=A0=A0=A0=A0 the content of a protected vol= ume.

=A0=A0=A0=A0=A0=A0=A0 Also used to read/writ= e to a recovery volume - the replica of a protected volume.

+=A0=A0=A0=A0=A0=A0 Write operation is used to populate the reco= very volume. Read is needed for fail-over-test scenarios, and for sync-rela= ted

+=A0=A0=A0=A0=A0=A0 optimizations.

=A0Description of the Repagent module<= /p>

@@ -48,7 +50,7 @@ Gen= eral description of a Rephub=A0 - a replication system the repagent connect= s to

=A0=A0=A0=A0 Our Rephub is called SingleRephub - a R= ephub protecting a single VM.

=A0=A0=A0=A0=A0Preparations

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

+=A0=A0=A0 1. The user chooses a host to run SingleR= ephub - a different host than PVM, call it Host2

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

=A0=A0=A0=A0 3. The user runs SingleRephub process o= n Host2, and gives V1R and V2R as command line arguments.

=A0=A0=A0=A0=A0=A0=A0=A0 From now on SingleRephub waits for the pr= otected VM repagent to connect.

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

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

=A0=A0=A0=A0=A0* Note th= at during stage 3 writes to the protected volumes are not ignored - they= 9;re kept in a bitmap,

-=A0=A0=A0=A0=A0=A0=A0 and= will be read again when stage 3 ends, in an interative convergin process.<= /p>

+=A0=A0=A0=A0=A0=A0=A0 and will be read again when s= tage 3 ends, in an iterative convergence process.

=A0=A0=A0=A0=A0This flow continuously maintain= s an updated recovery volume.

=A0=A0=A0=A0 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/bloc= k/repagent/repagent.c

index bdc0117..2e70853 100644

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

+++ b/block/r= epagent/repagent.c

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

+/*

+ * QEMU System Emulator replication agent

+ *

+ * Copyright (c) 200= 3 Fabrice Bellard

+ *

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

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

+ * in th= e Software without restriction, including without limitation the rights

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

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

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

+ *

+ * The above copyright notice an= d this permission notice shall be included in

+ *= all copies or substantial portions of the Software.

+ *

+ * THE SOFTWARE IS PR= OVIDED "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 NONINFRINGE= MENT. IN NO EVENT SHALL

+ * THE AUTHORS OR COPYRI= GHT 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 SOFTW= ARE OR THE USE OR OTHER DEALINGS IN

+ * THE SOFTW= ARE.

+ */

#include <string.= h>

#include <stdlib.h>

#include <stdio.h>

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

} RepagentVolume;

=A0struct RepAgentState {

-= =A0=A0=A0 int is_init;

+=A0=A0=A0 bool is_init;

=A0=A0=A0=A0 int num_volumes;

=A0=A0=A0=A0 Repage= ntVolume *volumes[REPAGENT_MAX_NUM_VOLUMES];

};<= /p>

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

void repagent_init(const char *hubname, int port)

{

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

-=A0=A0=A0 reph= ub_params *pParams =3D (rephub_params *)g_malloc(sizeof(rephub_params));

+=A0=A0=A0 rephub_params *pParams =3D g_malloc(sizeo= f(rephub_params));

=A0=A0=A0=A0 if (hubname =3D= =3D NULL) {

=A0=A0=A0=A0=A0=A0=A0=A0 hubname =3D = "127.0.0.1";

=A0=A0=A0=A0 }

@@ -197,7 +220,7 @@ static void re= pagent_report_volumes_to_hub(void)

=A0=A0=A0=A0 }=

}

-int repaget_start_protect(RepCmdStartProtect *pcmd,

+bool repaget_start_protect(RepCmdStartProtect *pcmd= ,

=A0=A0=A0=A0=A0=A0=A0=A0 RepCmdDataStartProtect= *pcmd_data)

{

=A0=A0= =A0=A0 printf("Start protect vol %s, ID %llu\n", pcmd_data->vo= lume_name,

@@ -210,12 +233,12 @@ int repaget_start_protect(RepC= mdStartProtect *pcmd,

=A0=A0=A0=A0 }

=A0=A0=A0=A0 if (vol_index < 0) {

=A0=A0=A0=A0=A0=A0=A0=A0 printf("The volume doesn't exist\n&quo= t;);

-=A0=A0=A0=A0=A0=A0=A0 return TRUE;

+=A0=A0=A0=A0=A0=A0=A0 return true;

=A0= =A0=A0=A0 }

=A0=A0=A0=A0 /* orim todo protect */<= /p>

=A0=A0=A0=A0 g_rep_agent.volumes[vol_index]->v= ol_id =3D pcmd->volume_id;

-=A0=A0=A0 return TRUE;<= /p>

+=A0=A0=A0 return true;

}

=A0static int rep= agent_get_volume_by_name(const char *name)

@@ -242,7 +265,7 @@ static int repagent_get_volume_b= y_id(uint64_t vol_id)

=A0=A0=A0=A0 return -1;

=

}

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

+bool repagent_remote_io(RepCmdRemoteIoReq *pcmd, ui= nt8_t *pdata)

{

=A0=A0= =A0=A0 int index =3D repagent_get_volume_by_id(pcmd->volume_id);

=A0=A0=A0=A0 int size_bytes =3D pcmd->size_sectors * 512;

@@ -255,7 +278,7 @@ int repagent_remote_io(RepCmdRemoteIoReq *p= cmd, uint8_t *pdata)

=A0=A0=A0=A0=A0=A0=A0=A0 p_r= es_cmd->volume_id =3D pcmd->volume_id;

=A0=A0=A0=A0=A0=A0=A0=A0 p_res_cmd->io_status =3D= -1;

=A0=A0=A0=A0=A0=A0=A0=A0 repagent_client_sen= d((RepCmd *) p_res_cmd);

-=A0=A0=A0=A0=A0=A0=A0 r= eturn TRUE;

+=A0=A0=A0=A0=A0=A0=A0 return true;

=A0=A0=A0=A0 }

=A0=A0=A0=A0=A0printf("Vol read - driver %p, volId %l= lu, offset %llu, size %u\n",

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

=A0=A0=A0=A0=A0=A0=A0=A0 }

=A0=A0=A0=A0 }

-=A0= =A0=A0 return TRUE;

+=A0=A0=A0 return true;

}

=A0static void repagent_remote_io_done(void *op= aque, int ret)

diff --git a/block/repagent/repage= nt.h b/block/repagent/repagent.h

index 0f69820..2= 863ffc 100644

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

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

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

=A0void repagent_init(const char *hubname, int port);

void repagent_handle_protected_write(BlockDriverState *bs,

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

+=A0=A0=A0=A0=A0=A0=A0 int64_t sector_num,

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

void repagent_register_drive(c= onst char *drive_path,

=A0=A0=A0=A0=A0=A0=A0=A0 BlockDriverState *driver_ptr);

void repagent_deregister_drive(const char *drive_path,

=A0=A0=A0=A0=A0=A0=A0=A0 BlockDriverState *driver_ptr);

<= p class=3D"MsoNormal">-int repaget_start_protect(RepCmdStartProtect *pcmd,<= /p>

+bool repaget_start_protect(RepCmdStartProtect *pcmd= ,

=A0=A0=A0=A0=A0=A0=A0=A0 RepCmdDataStartProtect= *pcmd_data);

-int repagent_remote_io(struct RepC= mdRemoteIoReq *pcmd, uint8_t *pdata);

+bool repagent_remote_io(struct RepCmdRemoteIoReq *p= cmd, uint8_t *pdata);

void repagent_client_conne= cted(void);

=A0

diff --git a/block/repagent/repagent_client.c b/block/repagent/repagent_cli= ent.c

index ee4aeb7..9d826c4 100644

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

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

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

+/*

+ * QEMU Sys= tem Emulator replication agent - socket client

+ = *

+ * Copyright (c) 2003 Fabrice Bellard

+ *

+ * Permission is hereby grant= ed, free of charge, to any person obtaining a copy

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

+ * in the Software without restriction, including w= ithout limitation the rights

+ * to use, copy, mo= dify, 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 c= onditions:

+ *

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

+ * all copies or substantial portions of the Softwa= re.

+ *

+ * THE SOFTWAR= E IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRAN= TIES OF MERCHANTABILITY,

+ * FITNESS FOR A PARTIC= ULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL

+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER

+ * LIABILITY, WHETHER IN AN ACTION OF CONTRA= CT, TORT OR OTHERWISE, ARISING FROM,

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

+ * THE SOFTWARE.

+ */

=

#include "repcmd.h"

#include "rephub_cmds.h"

#includ= e "repcmd_listener.h"

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

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

=A0typedef struct repa= gent_client_state {

-=A0=A0=A0 int is_connected;

-=A0=A0=A0 int is_terminate_receive;

+=A0=A0= =A0 bool is_connected;

+=A0=A0=A0 bool is_termina= te_receive;

=A0=A0=A0=A0 int hsock;

} repagent_client_state;=

@@ -34,7 +57,7 @@ st= atic void repagent_client_read(void *opaque)

=A0= =A0=A0=A0 if (bytes_read <=3D 0) {

=A0=A0=A0=A0=A0=A0=A0=A0 printf("repagent_clien= t_read failed (%d), errno=3D%d\n",

=A0=A0=A0= =A0=A0=A0=A0=A0 bytes_read, errno);

-=A0=A0=A0=A0= =A0=A0=A0 g_client_state.is_connected =3D 0;

+=A0=A0=A0=A0=A0=A0=A0 g_client_state.is_connected =3D false;

=A0=A0=A0=A0 }

}

@@ -93,7 +116,7 @@ void *repagent_lis= ten(void *pParam)

=A0=A0=A0=A0=A0=A0=A0=A0 retries =3D 0;

=A0=A0=A0=A0=A0=A0=A0=A0=A0printf("After connect\n&= quot;);

-=A0=A0=A0=A0=A0=A0=A0 g_client_state.is_= connected =3D 1;

+=A0=A0=A0=A0=A0=A0=A0 g_client_= state.is_connected =3D true;

=A0=A0=A0=A0=A0=A0=A0=A0 repagent_client_connected()= ;

=A0=A0=A0 =A0=A0=A0=A0=A0repcmd_listener_init(r= epagent_process_cmd, NULL);

=A0=A0=A0=A0=A0=A0=A0= =A0 static int c;

@@ -108,7 +131,7 @@ void *repag= ent_listen(void *pParam)

=A0=A0=A0=A0=A0=A0=A0=A0 qemu_set_fd_handler(g_clien= t_state.hsock, NULL, NULL, NULL);

=A0=A0=A0=A0=A0=A0=A0=A0=A0printf("Disconnected\n"= );

-=A0=A0=A0=A0=A0=A0=A0 g_client_state.is_conne= cted =3D 0;

+=A0=A0=A0=A0=A0=A0=A0 g_client_state.is_connected = =3D false;

=A0=A0=A0=A0=A0=A0=A0=A0 close(g_clien= t_state.hsock);

=A0= =A0=A0=A0=A0}

@@ -117,7 +140,7 @@ void *repagent_= listen(void *pParam)

=A0void repagent_process= _cmd(RepCmd *pcmd, uint8_t *pdata, void *clientPtr)

{

-=A0=A0=A0 int is_free_data =3D 1;

+=A0=A0=A0 bool is_free_data =3D true;

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

=A0=A0=A0=A0 switch (pcmd->hdr.cmdid) {

=A0=A0=A0=A0 case REPHUB_CMD_START_PROTECT: {

diff --git a/block/repagent/repagent_drv.c b/block/r= epagent/repagent_drv.c

index 8c9f2b6..4775166 100= 644

--- 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 grant= ed, free of charge, to any person obtaining a copy

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

+ * in the Software without restriction, including w= ithout limitation the rights

+ * to use, copy, mo= dify, 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 c= onditions:

+ *

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

+ * all copies or substantial portions of the Softwa= re.

+ *

+ * THE SOFTWAR= E IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRAN= TIES OF MERCHANTABILITY,

+ * FITNESS FOR A PARTIC= ULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL

+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER

+ * LIABILITY, WHETHER IN AN ACTION OF CONTRA= CT, TORT OR OTHERWISE, ARISING FROM,

+ * OUT OF O= R 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/bloc= k/repagent/repcmd_listener.c

index 54d3f60..e6b4d= 74 100644

--- a/block/repagent/repcmd_listener.c<= /p>

+++ 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 c= opy

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

+ * in th= e Software without restriction, including without limitation the rights

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

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

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

+ *

+ * The above copyright notice an= d this permission notice shall be included in

+ *= all copies or substantial portions of the Software.

+ *

+ * THE SOFTWARE IS PR= OVIDED "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 NONINFRINGE= MENT. IN NO EVENT SHALL

+ * THE AUTHORS OR COPYRI= GHT 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 SOFTW= ARE OR THE USE OR OTHER DEALINGS IN

+ * THE SOFTW= ARE.

+ */

#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>

=A0/* Use the CONFIG_REPAGENT flag to determine= whether

=A0 * we're under qemu build or a hu= b When under

@@ -32,12 +56,12 @@ typedef struct R= epCmdRxCmdState {

=A0=A0=A0=A0 uint8_t *pReadBuf;

=A0=A0=A0=A0 int bytesToGet;

=A0=A0=A0=A0 i= nt bytesGotten;

-=A0=A0=A0 int isGotHeader;

+=A0=A0=A0 bool isGotHeader;

=A0=A0=A0=A0 uint8_t *pdata;

} RepCmdRxCmdState;

=A0typedef struct RepCmdListenerState {

-=A0= =A0=A0 int is_terminate_receive;

+=A0=A0=A0 bool is_terminate_receive;

=A0=A0=A0=A0 pfn_received_cmd_cb=A0 receive_cb;

=A0=A0=A0=A0 void *opaque;

=A0=A0=A0= =A0 int hsock;

@@ -111,11 +135,11 @@ static int repcmd_listener_process_rx(int bytecount)<= /p>

=A0=A0=A0=A0 }

=A0=A0= =A0=A0 assert(cmd_state->bytesGotten <=3D cmd_state->bytesToGet);<= /p>

=A0=A0=A0=A0 if (cmd_state->bytesGotten =3D=3D cmd_state->bytesToGet)= {

-=A0=A0=A0=A0=A0=A0=A0 int isGotData =3D 0;

+=A0=A0=A0=A0=A0=A0=A0 bool isGotData =3D false;

=A0=A0=A0=A0=A0=A0=A0=A0 cmd_state->bytesGotten = =3D 0;

=A0=A0=A0=A0=A0=A0=A0=A0 if (!cmd_state->isGotHea= der) {

=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 /* We= just got the header */

-=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0 cmd_state->isGotHeader =3D 1;

+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 cmd_state->isGotHeader =3D true;

<= p class=3D"MsoNormal">

=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0assert(cmd_state->curCmd.hdr.magic1 =3D=3D REPCMD_MAGIC1)= ;

=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 assert(cmd= _state->curCmd.magic2 =3D=3D REPCMD_MAGIC2);

@@ -126,12 +150,12 @@ static int repcmd_listener_pro= cess_rx(int bytecount)

=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0 cmd_state->pReadBuf =3D cmd_state->pdata;

=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 } else {

=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =A0=A0=A0=A0=A0=A0/* = no data */

-=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0 isGotData =3D 1;

+=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0 isGotData =3D true;

=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 cmd_state->pdata =3D NULL;=

=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 }

=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 cmd_state->bytesToGe= t =3D cmd_state->curCmd.hdr.data_size_bytes;

= =A0=A0=A0=A0=A0=A0=A0=A0 } else {

-=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0 isGotData =3D 1;

+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 isGotData =3D tru= e;

=A0=A0=A0=A0=A0=A0=A0=A0 }

=A0=A0=A0=A0=A0=A0=A0=A0=A0if (isGotData= ) {

@@ -145,7 +169,7 @@ static int repcmd_listene= r_process_rx(int bytecount)

=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 cmd_state->p= ReadBuf =3D (uint8_t *) &cmd_state->curCmd;

=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 cmd_state->bytesGotten =3D 0;

=

=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 cmd_state->b= ytesToGet =3D sizeof(RepCmd);

-=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 cmd_state->isG= otHeader =3D 0;

+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0 cmd_state->isGotHeader =3D false;

=A0=A0= =A0=A0=A0=A0=A0=A0 }

=A0=A0=A0=A0 }

=A0=A0=A0=A0 return bytecount;

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

index e34e0ce..f036f58 100644

--- a/block/r= epagent/rephub_defs.h

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

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

#define REPHUB_MAX_V= OL_NAME_LEN (1024)

#define REPHUB_MAX_NUM_VOLUME= S (512)

-#ifndef TRUE

-=A0=A0=A0 #define TRUE (1)

-#end= if

-

-#ifndef FALSE

=

-=A0=A0=A0 #define FALSE (0)

-#endif

-

#endif /* REP_HUB_DEFS_H */

=

--

1.7.6.5

--20cf302ef8ced1358604bced8874--