rdma: migration support
v8 cover rdma: migration support
From: "Michael R. Hines" <[email protected]>
Please pull.
Changes since v7:
This fixes the problems experienced by others when the x-rdma-pin-all feature appeared to freeze the VM.
By moving this operation out of the connection setup time and instead moving it to ram_save_setup() code, we no longer execute pinning inside the BQL and thus the pinning is parallelized with the VM execution and also properly accounted for inside the QMP migrate total time statistics.
Wiki: http://wiki.qemu.org/Features/RDMALiveMigration
Github: [email protected]:hinesmr/qemu.git
Here is a brief summary of total migration time and downtime using RDMA:
Using a 40gbps infiniband link performing a worst-case stress test, using an 8GB RAM virtual machine:
Using the following command:
$ apt-get install stress $ stress --vm-bytes 7500M --vm 1 --vm-keep
RESULTS:
1. Migration throughput: 26 gigabits/second.
2. Downtime (stop time) varies between 15 and 100 milliseconds.
EFFECTS of memory registration on bulk phase round:
For example, in the same 8GB RAM example with all 8GB of memory in active use and the VM itself is completely idle using the same 40 gbps infiniband link:
1. x-rdma-pin-all disabled total time: approximately 7.5 seconds @ 9.5 Gbps
2. x-rdma-pin-all enabled total time: approximately 4 seconds @ 26 Gbps
These numbers would of course scale up to whatever size virtual machine you have to migrate using RDMA.
Enabling this feature does *not* have any measurable affect on migration *downtime*. This is because, without this feature, all of the memory will have already been registered already in advance during the bulk round and does not need to be re-registered during the successive iteration rounds.
The following changes since commit f3aa844bbb2922a5b8393d17620eca7d7e921ab3:
build: include config-{, all-}devices.mak after defining CONFIG_SOFTMMU and CONFIG_USER_ONLY (2013-04-24 12:18:41 -0500)
are available in the git repository at:
[email protected]:hinesmr/qemu.git rdma_patch_v6
for you to fetch changes up to 75e6fac1f642885b93cefe6e1874d648e9850f8f:
rdma: send pc.ram (2013-04-24 14:55:01 -0400)
----------------------------------------------------------------
Michael R. Hines (13):
rdma: add documentation
rdma: introduce qemu_update_position()
rdma: export yield_until_fd_readable()
rdma: export throughput w/ MigrationStats QMP
rdma: introduce qemu_file_mode_is_not_valid()
rdma: export qemu_fflush()
rdma: introduce ram_handle_compressed()
rdma: introduce qemu_ram_foreach_block()
rdma: new QEMUFileOps hooks
rdma: introduce capability x-rdma-pin-all
rdma: core logic
rdma: send pc.ram
rdma: fix mlock() freezes and accounting
Makefile.objs | 1 + arch_init.c | 69 +- configure | 29 + docs/rdma.txt | 415 ++++++ exec.c | 9 + hmp.c | 2 + include/block/coroutine.h | 6 + include/exec/cpu-common.h | 5 + include/migration/migration.h | 31 + include/migration/qemu-file.h | 32 + migration-rdma.c | 2812 +++++++++++++++++++++++++++++++++++++++++ migration.c | 23 + qapi-schema.json | 12 +- qemu-coroutine-io.c | 23 + savevm.c | 114 +- 15 files changed, 3536 insertions(+), 47 deletions(-) create mode 100644 docs/rdma.txt create mode 100644 migration-rdma.c
Signature · 1 line
1.7.10.4
PATCH v8 1/13 rdma: add documentation
From: "Michael R. Hines" <[email protected]>
docs/rdma.txt contains full documentation, wiki links, github url and contact information.
--- docs/rdma.txt | 404 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 404 insertions(+) create mode 100644 docs/rdma.txt
docs/rdma.txt new file +404 -0
@@ -0,0 +1,404 @@ +(RDMA: Remote Direct Memory Access) +RDMA Live Migration Specification, Version # 1 +============================================== +Wiki: http://wiki.qemu.org/Features/RDMALiveMigration +Github: [email protected]:hinesmr/qemu.git, 'rdma' branch + +Copyright (C) 2013 Michael R. Hines <[email protected]> + +An *exhaustive* paper (2010) shows additional performance details +linked on the QEMU wiki above. + +Contents: +========= +* Introduction +* Before running +* Running +* Performance +* RDMA Migration Protocol Description +* Versioning and Capabilities +* QEMUFileRDMA Interface +* Migration of pc.ram +* Error handling +* TODO + +Introduction: +============= + +RDMA helps make your migration more deterministic under heavy load because +of the significantly lower latency and higher throughput over TCP/IP. This is +because the RDMA I/O architecture reduces the number of interrupts and +data copies by bypassing the host networking stack. In particular, a TCP-based +migration, under certain types of memory-bound workloads, may take a more +unpredicatable amount of time to complete the migration if the amount of +memory tracked during each live migration iteration round cannot keep pace +with the rate of dirty memory produced by the workload. + +RDMA currently comes in two flavors: both Ethernet based (RoCE, or RDMA +over Convered Ethernet) as well as Infiniband-based. This implementation of +migration using RDMA is capable of using both technologies because of +the use of the OpenFabrics OFED software stack that abstracts out the +programming model irrespective of the underlying hardware. + +Refer to openfabrics.org or your respective RDMA hardware vendor for +an understanding on how to verify that you have the OFED software stack +installed in your environment. You should be able to successfully link +against the "librdmacm" and "libibverbs" libraries and development headers +for a working build of QEMU to run successfully using RDMA Migration. + +BEFORE RUNNING: +=============== + +Use of RDMA during migration requires pinning and registering memory +with the hardware. This means that memory must be physically resident +before the hardware can transmit that memory to another machine. +If this is not acceptable for your application or product, then the use +of RDMA migration may in fact be harmful to co-located VMs or other +software on the machine if there is not sufficient memory available to +relocate the entire footprint of the virtual machine. If so, then the +use of RDMA is discouraged and it is recommended to use standard TCP migration. + +Experimental: Next, decide if you want dynamic page registration. +For example, if you have an 8GB RAM virtual machine, but only 1GB +is in active use, then enabling this feature will cause all 8GB to +be pinned and resident in memory. This feature mostly affects the +bulk-phase round of the migration and can be enabled for extremely +high-performance RDMA hardware using the following command: + +QEMU Monitor Command: +$ migrate_set_capability x-rdma-pin-all on # disabled by default + +Performing this action will cause all 8GB to be pinned, so if that's +not what you want, then please ignore this step altogether. + +On the other hand, this will also significantly speed up the bulk round +of the migration, which can greatly reduce the "total" time of your migration. +Example performance of this using an idle VM in the previous example +can be found in the "Performance" section. + +RUNNING: +======== + +First, set the migration speed to match your hardware's capabilities: + +QEMU Monitor Command: +$ migrate_set_speed 40g # or whatever is the MAX of your RDMA device + +Next, on the destination machine, add the following to the QEMU command line: + +qemu ..... -incoming x-rdma:host:port + +Finally, perform the actual migration on the source machine: + +QEMU Monitor Command: +$ migrate -d x-rdma:host:port + +PERFORMANCE +=========== + +Here is a brief summary of total migration time and downtime using RDMA: +Using a 40gbps infiniband link performing a worst-case stress test, +using an 8GB RAM virtual machine: + +Using the following command: +$ apt-get install stress +$ stress --vm-bytes 7500M --vm 1 --vm-keep + +1. Migration throughput: 26 gigabits/second. +2. Downtime (stop time) varies between 15 and 100 milliseconds. + +EFFECTS of memory registration on bulk phase round: + +For example, in the same 8GB RAM example with all 8GB of memory in +active use and the VM itself is completely idle using the same 40 gbps +infiniband link: + +1. x-rdma-pin-all disabled total time: approximately 7.5 seconds @ 9.5 Gbps +2. x-rdma-pin-all enabled total time: approximately 4 seconds @ 26 Gbps + +These numbers would of course scale up to whatever size virtual machine +you have to migrate using RDMA. + +Enabling this feature does *not* have any measurable affect on +migration *downtime*. This is because, without this feature, all of the +memory will have already been registered already in advance during +the bulk round and does not need to be re-registered during the successive +iteration rounds. + +RDMA Protocol Description: +========================== + +Migration with RDMA is separated into two parts: + +1. The transmission of the pages using RDMA +2. Everything else (a control channel is introduced) + +"Everything else" is transmitted using a formal +protocol now, consisting of infiniband SEND messages. + +An infiniband SEND message is the standard ibverbs +message used by applications of infiniband hardware. +The only difference between a SEND message and an RDMA +message is that SEND messages cause notifications +to be posted to the completion queue (CQ) on the +infiniband receiver side, whereas RDMA messages (used +for pc.ram) do not (to behave like an actual DMA). + +Messages in infiniband require two things: + +1. registration of the memory that will be transmitted +2. (SEND only) work requests to be posted on both + sides of the network before the actual transmission + can occur. + +RDMA messages are much easier to deal with. Once the memory +on the receiver side is registered and pinned, we're +basically done. All that is required is for the sender +side to start dumping bytes onto the link. + +(Memory is not released from pinning until the migration +completes, given that RDMA migrations are very fast.) + +SEND messages require more coordination because the +receiver must have reserved space (using a receive +work request) on the receive queue (RQ) before QEMUFileRDMA +can start using them to carry all the bytes as +a control transport for migration of device state. + +To begin the migration, the initial connection setup is +as follows (migration-rdma.c): + +1. Receiver and Sender are started (command line or libvirt): +2. Both sides post two RQ work requests +3. Receiver does listen() +4. Sender does connect() +5. Receiver accept() +6. Check versioning and capabilities (described later) + +At this point, we define a control channel on top of SEND messages +which is described by a formal protocol. Each SEND message has a +header portion and a data portion (but together are transmitted +as a single SEND message). + +Header: + * Length (of the data portion, uint32, network byte order) + * Type (what command to perform, uint32, network byte order) + * Repeat (Number of commands in data portion, same type only) + +The 'Repeat' field is here to support future multiple page registrations +in a single message without any need to change the protocol itself +so that the protocol is compatible against multiple versions of QEMU. +Version #1 requires that all server implementations of the protocol must +check this field and register all requests found in the array of commands located +in the data portion and return an equal number of results in the response. +The maximum number of repeats is hard-coded to 4096. This is a conservative +limit based on the maximum size of a SEND message along with emperical +observations on the maximum future benefit of simultaneous page registrations. + +The 'type' field has 9 different command values: + 1. Unused + 2. Error (sent to the source during bad things) + 3. Ready (control-channel is available) + 4. QEMU File (for sending non-live device state) + 5. RAM Blocks (used right after connection setup) + 6. Compress page (zap zero page and skip registration) + 7. Register request (dynamic chunk registration) + 8. Register result ('rkey' to be used by sender) + 9. Register finished (registration for current iteration finished) + +A single control message, as hinted above, can contain within the data +portion an array of many commands of the same type. If there is more than +one command, then the 'repeat' field will be greater than 1. + +After connection setup is completed, we have two protocol-level +functions, responsible for communicating control-channel commands +using the above list of values: + +Logically: + +qemu_rdma_exchange_recv(header, expected command type) + +1. We transmit a READY command to let the sender know that + we are *ready* to receive some data bytes on the control channel. +2. Before attempting to receive the expected command, we post another + RQ work request to replace the one we just used up. +3. Block on a CQ event channel and wait for the SEND to arrive. +4. When the send arrives, librdmacm will unblock us. +5. Verify that the command-type and version received matches the one we expected. + +qemu_rdma_exchange_send(header, data, optional response header & data): + +1. Block on the CQ event channel waiting for a READY command + from the receiver to tell us that the receiver + is *ready* for us to transmit some new bytes. +2. Optionally: if we are expecting a response from the command + (that we have no yet transmitted), let's post an RQ + work request to receive that data a few moments later. +3. When the READY arrives, librdmacm will + unblock us and we immediately post a RQ work request + to replace the one we just used up. +4. Now, we can actually post the work request to SEND + the requested command type of the header we were asked for. +5. Optionally, if we are expecting a response (as before), + we block again and wait for that response using the additional + work request we previously posted. (This is used to carry + 'Register result' commands #6 back to the sender which + hold the rkey need to perform RDMA. Note that the virtual address + corresponding to this rkey was already exchanged at the beginning + of the connection (described below). + +All of the remaining command types (not including 'ready') +described above all use the aformentioned two functions to do the hard work: + +1. After connection setup, RAMBlock information is exchanged using + this protocol before the actual migration begins. This information includes + a description of each RAMBlock on the server side as well as the virtual addresses + and lengths of each RAMBlock. This is used by the client to determine the + start and stop locations of chunks and how to register them dynamically + before performing the RDMA operations. +2. During runtime, once a 'chunk' becomes full of pages ready to + be sent with RDMA, the registration commands are used to ask the + other side to register the memory for this chunk and respond + with the result (rkey) of the registration. +3. Also, the QEMUFile interfaces also call these functions (described below) + when transmitting non-live state, such as devices or to send + its own protocol information during the migration process. +4. Finally, zero pages are only checked if a page has not yet been registered + using chunk registration (or not checked at all and unconditionally + written if chunk registration is disabled. This is accomplished using + the "Compress" command listed above. If the page *has* been registered + then we check the entire chunk for zero. Only if the entire chunk is + zero, then we send a compress command to zap the page on the other side. + +Versioning and Capabilities +=========================== +Current version of the protocol is version #1. + +The same version applies to both for protocol traffic and capabilities +negotiation. (i.e. There is only one version number that is referred to +by all communication). + +librdmacm provides the user with a 'private data' area to be exchanged +at connection-setup time before any infiniband traffic is generated. + +Header: + * Version (protocol version validated before send/recv occurs), uint32, network byte order + * Flags (bitwise OR of each capability), uint32, network byte order + +There is no data portion of this header right now, so there is +no length field. The maximum size of the 'private data' section +is only 192 bytes per the Infiniband specification, so it's not +very useful for data anyway. This structure needs to remain small. + +This private data area is a convenient place to check for protocol +versioning because the user does not need to register memory to +transmit a few bytes of version information. + +This is also a convenient place to negotiate capabilities +(like dynamic page registration). + +If the version is invalid, we throw an error. + +If the version is new, we only negotiate the capabilities that the +requested version is able to perform and ignore the rest. + +Currently there is only *one* capability in Version #1: dynamic page registration + +Finally: Negotiation happens with the Flags field: If the primary-VM +sets a flag, but the destination does not support this capability, it +will return a zero-bit for that flag and the primary-VM will understand +that as not being an available capability and will thus disable that +capability on the primary-VM side. + +QEMUFileRDMA Interface: +======================= + +QEMUFileRDMA introduces a couple of new functions: + +1. qemu_rdma_get_buffer() (QEMUFileOps rdma_read_ops) +2. qemu_rdma_put_buffer() (QEMUFileOps rdma_write_ops) + +These two functions are very short and simply use the protocol +describe above to deliver bytes without changing the upper-level +users of QEMUFile that depend on a bytestream abstraction. + +Finally, how do we handoff the actual bytes to get_buffer()? + +Again, because we're trying to "fake" a bytestream abstraction +using an analogy not unlike individual UDP frames, we have +to hold on to the bytes received from control-channel's SEND +messages in memory. + +Each time we receive a complete "QEMU File" control-channel +message, the bytes from SEND are copied into a small local holding area. + +Then, we return the number of bytes requested by get_buffer() +and leave the remaining bytes in the holding area until get_buffer() +comes around for another pass. + +If the buffer is empty, then we follow the same steps +listed above and issue another "QEMU File" protocol command, +asking for a new SEND message to re-fill the buffer. + +Migration of pc.ram: +==================== + +At the beginning of the migration, (migration-rdma.c), +the sender and the receiver populate the list of RAMBlocks +to be registered with each other into a structure. +Then, using the aforementioned protocol, they exchange a +description of these blocks with each other, to be used later +during the iteration of main memory. This description includes +a list of all the RAMBlocks, their offsets and lengths, virtual +addresses and possibly includes pre-registered RDMA keys in case dynamic +page registration was disabled on the server-side, otherwise not. + +Main memory is not migrated with the aforementioned protocol, +but is instead migrated with normal RDMA Write operations. + +Pages are migrated in "chunks" (hard-coded to 1 Megabyte right now). +Chunk size is not dynamic, but it could be in a future implementation. +There's nothing to indicate that this is useful right now. + +When a chunk is full (or a flush() occurs), the memory backed by +the chunk is registered with librdmacm is pinned in memory on +both sides using the aforementioned protocol. +After pinning, an RDMA Write is generated and transmitted +for the entire chunk. + +Chunks are also transmitted in batches: This means that we +do not request that the hardware signal the completion queue +for the completion of *every* chunk. The current batch size +is about 64 chunks (corresponding to 64 MB of memory). +Only the last chunk in a batch must be signaled. +This helps keep everything as asynchronous as possible +and helps keep the hardware busy performing RDMA operations. + +Error-handling: +=============== + +Infiniband has what is called a "Reliable, Connected" +link (one of 4 choices). This is the mode in which +we use for RDMA migration. + +If a *single* message fails, +the decision is to abort the migration entirely and +cleanup all the RDMA descriptors and unregister all +the memory. + +After cleanup, the Virtual Machine is returned to normal +operation the same way that would happen if the TCP +socket is broken during a non-RDMA based migration. + +TODO: +===== +1. 'migrate x-rdma:host:port' and '-incoming x-rdma' options will be + renamed to 'rdma' after the experimental phase of this work has + completed upstream. +2. Currently, 'ulimit -l' mlock() limits as well as cgroups swap limits + are not compatible with infinband memory pinning and will result in + an aborted migration (but with the source VM left unaffected). +3. Use of the recent /proc/<pid>/pagemap would likely speed up + the use of KSM and ballooning while using RDMA. +4. Also, some form of balloon-device usage tracking would also + help alleviate some issues.
Signature · 1 line
1.7.10.4
PATCH v8 3/13 rdma: export yield_until_fd_readable()
In reply to [email protected]From: "Michael R. Hines" <[email protected]>
The RDMA event channel can be made non-blocking just like a TCP socket. Exporting this function allows us to yield so that the QEMU monitor remains available.
--- include/block/coroutine.h | 6 ++++++ qemu-coroutine-io.c | 23 +++++++++++++++++++++++ savevm.c | 28 ---------------------------- 3 files changed, 29 insertions(+), 28 deletions(-)
include/block/coroutine.h +6 -0
@@ -209,4 +209,10 @@ void qemu_co_rwlock_unlock(CoRwlock *lock);*/ void coroutine_fn co_sleep_ns(QEMUClock *clock, int64_t ns); +/** +* Yield until a file descriptor becomes readable +* +* Note that this function clobbers the handlers for the file descriptor. +*/ +void coroutine_fn yield_until_fd_readable(int fd);#endif /* QEMU_COROUTINE_H */
qemu-coroutine-io.c +23 -0
@@ -63,3 +63,26 @@ qemu_co_send_recv(int sockfd, void *buf, size_t bytes, bool do_send)struct iovec iov = { .iov_base = buf, .iov_len = bytes };return qemu_co_sendv_recvv (sockfd, &iov,1 ,0 , bytes, do_send); } + +typedef struct { +Coroutine *co; +int fd; +}FDYieldUntilData ; + +static void fd_coroutine_enter (void *opaque) +{ +FDYieldUntilData *data = opaque; +qemu_set_fd_handler (data->fd,NULL ,NULL ,NULL ); +qemu_coroutine_enter (data->co,NULL ); +} + +void coroutine_fn yield_until_fd_readable(int fd) +{ +FDYieldUntilData data; + +assert (qemu_in_coroutine ()); + data.co =qemu_coroutine_self (); + data.fd = fd; +qemu_set_fd_handler (fd, fd_coroutine_enter,NULL , &data); +qemu_coroutine_yield (); +}
savevm.c +0 -28
@@ -149,34 +149,6 @@ typedef struct QEMUFileSocketQEMUFile *file; } QEMUFileSocket; -typedef struct { -Coroutine *co; -int fd; -}FDYieldUntilData ; - -static void fd_coroutine_enter (void *opaque) -{ -FDYieldUntilData *data = opaque; -qemu_set_fd_handler (data->fd,NULL ,NULL ,NULL ); -qemu_coroutine_enter (data->co,NULL ); -} - -/** -* Yield until a file descriptor becomes readable -* -* Note that this function clobbers the handlers for the file descriptor. -*/ -static void coroutine_fn yield_until_fd_readable(int fd) -{ -FDYieldUntilData data; - -assert (qemu_in_coroutine ()); - data.co =qemu_coroutine_self (); - data.fd = fd; -qemu_set_fd_handler (fd, fd_coroutine_enter,NULL , &data); -qemu_coroutine_yield (); -} -static ssize_t socket_writev_buffer (void *opaque,struct iovec *iov,int iovcnt,int64_t pos) {
Signature · 1 line
1.7.10.4
PATCH v8 4/13 rdma: export throughput w/ MigrationStats QMP
In reply to [email protected]From: "Michael R. Hines" <[email protected]>
This exposes throughput (in megabits/sec) through QMP.
--- hmp.c | 2 ++ include/migration/migration.h | 1 + migration.c | 6 ++++++ qapi-schema.json | 5 ++++- 4 files changed, 13 insertions(+), 1 deletion(-)
hmp.c +2 -0
@@ -169,6 +169,8 @@ void hmp_info_migrate(Monitor *mon, const QDict *qdict)if (info->has_ram) {monitor_printf (mon,"transferred ram: %" PRIu64" kbytes\n" , info->ram->transferred >>10 ); +monitor_printf (mon,"throughput: %0.2f mbps\n" , + info->ram->mbps);monitor_printf (mon,"remaining ram: %" PRIu64" kbytes\n" , info->ram->remaining >>10 ); monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
include/migration/migration.h +1 -0
@@ -47,6 +47,7 @@ struct MigrationStateint64_t dirty_bytes_rate;bool enabled_capabilities[MIGRATION_CAPABILITY_MAX ];int64_t xbzrle_cache_size; +double mbps; };void process_incoming_migration (QEMUFile *f);
migration.c +6 -0
@@ -66,6 +66,7 @@ MigrationState *migrate_get_current(void) .state = MIG_STATE_SETUP, .bandwidth_limit = MAX_THROTTLE, .xbzrle_cache_size = DEFAULT_MIGRATE_CACHE_SIZE, + .mbps = -1, };return ¤t_migration;
@@ -201,6 +202,7 @@ MigrationInfo *qmp_query_migrate(Error **errp) info->ram->normal =norm_mig_pages_transferred (); info->ram->normal_bytes =norm_mig_bytes_transferred (); info->ram->dirty_pages_rate = s->dirty_pages_rate; + info->ram->mbps = s->mbps;if (blk_mig_active ()) { info->has_disk = true;
@@ -230,6 +232,7 @@ MigrationInfo *qmp_query_migrate(Error **errp) info->ram->skipped =skipped_mig_pages_transferred (); info->ram->normal =norm_mig_pages_transferred (); info->ram->normal_bytes =norm_mig_bytes_transferred (); + info->ram->mbps = s->mbps;break ;case MIG_STATE_ERROR : info->has_status = true;
@@ -543,6 +546,9 @@ static void *migration_thread(void *opaque)double bandwidth = transferred_bytes / time_spent; max_size = bandwidth *migrate_max_downtime () /1000000 ; + s->mbps = time_spent ? (((double ) transferred_bytes *8.0 ) / + ((double ) time_spent /1000.0 )) /1000.0 /1000.0 :-1 ; +DPRINTF ("transferred %" PRIu64" time_spent %" PRIu64" bandwidth %g max_size %" PRId64"\n" , transferred_bytes, time_spent, bandwidth, max_size);
qapi-schema.json +4 -1
@@ -513,12 +513,15 @@ # @dirty-pages-rate: number of pages dirtied by second by the # guest (since 1.3) # +# @mbps: throughput in megabits/sec. (since 1.5) +# # Since: 0.14.0 ## { 'type': 'MigrationStats', 'data': {'transferred': 'int', 'remaining': 'int', 'total': 'int' , 'duplicate': 'int', 'skipped': 'int', 'normal': 'int', - 'normal-bytes': 'int', 'dirty-pages-rate' : 'int' } } + 'normal-bytes': 'int', 'dirty-pages-rate' : 'int', + 'mbps' : 'number' } } ## # @XBZRLECacheStats
Signature · 1 line
1.7.10.4
PATCH v8 6/13 rdma: export qemu_fflush()
In reply to [email protected]From: "Michael R. Hines" <[email protected]>
RDMA uses this to flush the control channel before sending its own message to handle page registrations.
--- include/migration/qemu-file.h | 1 + savevm.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
include/migration/qemu-file.h +1 -0
@@ -112,6 +112,7 @@ void qemu_file_reset_rate_limit(QEMUFile *f);void qemu_file_set_rate_limit (QEMUFile *f,int64_t new_rate);int64_t qemu_file_get_rate_limit (QEMUFile *f);int qemu_file_get_error (QEMUFile *f); +void qemu_fflush (QEMUFile *f);static inline void qemu_put_be64s (QEMUFile *f,const uint64_t *pv) {
savevm.c +1 -1
@@ -588,7 +588,7 @@ static inline bool qemu_file_is_writable(QEMUFile *f)* If there is writev_buffer QEMUFileOps it uses it otherwise uses * put_buffer ops. */ -static void qemu_fflush (QEMUFile *f) +void qemu_fflush (QEMUFile *f) {ssize_t ret =0 ;
Signature · 1 line
1.7.10.4
PATCH v8 7/13 rdma: introduce ram_handle_compressed()
In reply to [email protected]From: "Michael R. Hines" <[email protected]>
This gives RDMA shared access to madvise() on the destination side when an entire chunk is found to be zero.
--- arch_init.c | 24 ++++++++++++++++-------- include/migration/migration.h | 2 ++ 2 files changed, 18 insertions(+), 8 deletions(-)
arch_init.c +16 -8
@@ -782,6 +782,21 @@ static inline void *host_from_stream_offset(QEMUFile *f,return NULL ; } +/* +* If a page (or a whole RDMA chunk) has been +* determined to be zero, then zap it. +*/ +void ram_handle_compressed (void *host,uint8_t ch,uint64_t size) +{ +memset (host, ch,TARGET_PAGE_SIZE ); +#ifndef _WIN32 +if (ch ==0 && (!kvm_enabled () ||kvm_has_sync_mmu ()) && +getpagesize () <=TARGET_PAGE_SIZE ) { +qemu_madvise (host, size,QEMU_MADV_DONTNEED ); + } +#endif +} +static int ram_load (QEMUFile *f,void *opaque,int version_id) {ram_addr_t addr;
@@ -849,14 +864,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) } ch =qemu_get_byte (f); -memset (host, ch,TARGET_PAGE_SIZE ); -#ifndef _WIN32 -if (ch ==0 && - (!kvm_enabled () ||kvm_has_sync_mmu ()) && -getpagesize () <=TARGET_PAGE_SIZE ) { -qemu_madvise (host,TARGET_PAGE_SIZE ,QEMU_MADV_DONTNEED ); - } -#endif +ram_handle_compressed (host, ch,TARGET_PAGE_SIZE ); }else if (flags &RAM_SAVE_FLAG_PAGE ) {void *host;
include/migration/migration.h +2 -0
@@ -108,6 +108,8 @@ uint64_t xbzrle_mig_pages_transferred(void);uint64_t xbzrle_mig_pages_overflow (void );uint64_t xbzrle_mig_pages_cache_miss (void ); +void ram_handle_compressed (void *host,uint8_t ch,uint64_t size); +/** * @migrate_add_blocker - prevent migration from proceeding *
Signature · 1 line
1.7.10.4
PATCH v8 8/13 rdma: introduce qemu_ram_foreach_block()
In reply to [email protected]From: "Michael R. Hines" <[email protected]>
This is used during RDMA initialization in order to transmit a description of all the RAM blocks to the peer for later dynamic chunk registration purposes.
--- exec.c | 9 +++++++++ include/exec/cpu-common.h | 5 +++++ 2 files changed, 14 insertions(+)
exec.c +9 -0
@@ -2604,3 +2604,12 @@ bool cpu_physical_memory_is_io(hwaddr phys_addr) memory_region_is_romd(section->mr)); }#endif + +void qemu_ram_foreach_block (RAMBlockIterFunc func,void *opaque) +{ +RAMBlock *block; + + QTAILQ_FOREACH(block, &ram_list.blocks, next) { +func (block->host, block->offset, block->length, opaque); + } +}
include/exec/cpu-common.h +5 -0
@@ -113,6 +113,11 @@ void cpu_physical_memory_write_rom(hwaddr addr,extern struct MemoryRegion io_mem_rom;extern struct MemoryRegion io_mem_notdirty; +typedef void (RAMBlockIterFunc )(void *host_addr, +ram_addr_t offset,ram_addr_t length,void *opaque); + +void qemu_ram_foreach_block (RAMBlockIterFunc func,void *opaque); +#endif #endif /* !CPU_COMMON_H */
Signature · 1 line
1.7.10.4
PATCH v8 10/13 rdma: introduce capability x-rdma-pin-all
In reply to [email protected]From: "Michael R. Hines" <[email protected]>
This capability allows you to disable dynamic chunk registration for better throughput on high-performance links.
For example, using an 8GB RAM virtual machine with all 8GB of memory in active use and the VM itself is completely idle using a 40 gbps infiniband link:
1. x-rdma-pin-all disabled total time: approximately 7.5 seconds @ 9.5 Gbps
2. x-rdma-pin-all enabled total time: approximately 4 seconds @ 26 Gbps
These numbers would of course scale up to whatever size virtual machine you have to migrate using RDMA.
Enabling this feature does *not* have any measurable affect on migration *downtime*. This is because, without this feature, all of the memory will have already been registered already in advance during the bulk round and does not need to be re-registered during the successive iteration rounds.
--- include/migration/migration.h | 2 ++ migration.c | 9 +++++++++ qapi-schema.json | 7 ++++++- 3 files changed, 17 insertions(+), 1 deletion(-)
include/migration/migration.h +2 -0
@@ -125,6 +125,8 @@ void migrate_add_blocker(Error *reason);*/ void migrate_del_blocker (Error *reason); +bool migrate_rdma_pin_all (void ); +int xbzrle_encode_buffer (uint8_t *old_buf,uint8_t *new_buf,int slen,uint8_t *dst,int dlen);int xbzrle_decode_buffer (uint8_t *src,int slen,uint8_t *dst,int dlen);
migration.c +9 -0
@@ -476,6 +476,15 @@ void qmp_migrate_set_downtime(double value, Error **errp) max_downtime = (uint64_t )value; } +bool migrate_rdma_pin_all (void ) +{ +MigrationState *s; + + s =migrate_get_current (); + +return s->enabled_capabilities[MIGRATION_CAPABILITY_X_RDMA_PIN_ALL ]; +} +int migrate_use_xbzrle (void ) {MigrationState *s;
qapi-schema.json +6 -1
@@ -608,10 +608,15 @@ # This feature allows us to minimize migration traffic for certain work # loads, by sending compressed difference of the pages # +# @x-rdma-pin-all: Controls whether or not the entire VM memory footprint is +# mlock()'d on demand or all at once. Refer to docs/rdma.txt for usage. +# Disabled by default. Experimental: may (or may not) be renamed after +# further testing is complete. (since 1.5) +# # Since: 1.2 ## { 'enum': 'MigrationCapability', - 'data': ['xbzrle'] } + 'data': ['xbzrle', 'x-rdma-pin-all'] } ## # @MigrationCapabilityStatus
Signature · 1 line
1.7.10.4
PATCH v8 9/13 rdma: new QEMUFileOps hooks
In reply to [email protected]From: "Michael R. Hines" <[email protected]>
These are the prototypes and implementation of new hooks that RDMA takes advantage of to perform dynamic page registration.
An optional hook is also introduced for a custom function to be able to override the default save_page function.
Also included are the prototypes and accessor methods used by arch_init.c which invoke funtions inside savevm.c to call out to the hooks that may or may not have been overridden inside of QEMUFileOps.
--- include/migration/migration.h | 20 ++++++++++++++ include/migration/qemu-file.h | 29 ++++++++++++++++++++ savevm.c | 59 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+)
include/migration/migration.h +20 -0
@@ -21,6 +21,7 @@#include "qapi/error.h" #include "migration/vmstate.h" #include "qapi-types.h" +#include "exec/cpu-common.h" struct MigrationParams {bool blk;
@@ -132,4 +133,23 @@ int migrate_use_xbzrle(void);int64_t migrate_xbzrle_cache_size (void );int64_t xbzrle_cache_resize (int64_t new_size); + +void ram_control_before_iterate (QEMUFile *f,uint64_t flags); +void ram_control_after_iterate (QEMUFile *f,uint64_t flags); +void ram_control_load_hook (QEMUFile *f,uint64_t flags); + +/* Whenever this is found in the data stream, the flags +* will be passed to ram_control_load_hook in the incoming-migration +* side. This lets before_ram_iterate/after_ram_iterate add +* transport-specific sections to the RAM migration data. +*/ +#define RAM_SAVE_FLAG_HOOK 0x80 + +#define RAM_SAVE_CONTROL_NOT_SUPP -1000 +#define RAM_SAVE_CONTROL_DELAYED -2000 + +size_t ram_control_save_page (QEMUFile *f,ram_addr_t block_offset, +ram_addr_t offset,size_t size, +int *bytes_sent); +#endif
include/migration/qemu-file.h +29 -0
@@ -23,6 +23,7 @@*/ #ifndef QEMU_FILE_H #define QEMU_FILE_H 1 +#include "exec/cpu-common.h" /* This function writes a chunk of data to a file at the given position. * The pos argument can be ignored if the file is only being used for
@@ -57,12 +58,40 @@ typedef int (QEMUFileGetFD)(void *opaque);typedef ssize_t (QEMUFileWritevBufferFunc )(void *opaque,struct iovec *iov,int iovcnt,int64_t pos); +/* +* This function provides hooks around different +* stages of RAM migration. +*/ +typedef int (QEMURamHookFunc )(QEMUFile *f,void *opaque,uint64_t flags); + +/* +* Constants used by ram_control_* hooks +*/ +#define RAM_CONTROL_SETUP 0 +#define RAM_CONTROL_ROUND 1 +#define RAM_CONTROL_HOOK 2 +#define RAM_CONTROL_FINISH 3 + +/* +* This function allows override of where the RAM page +* is saved (such as RDMA, for example.) +*/ +typedef size_t (QEMURamSaveFunc )(QEMUFile *f,void *opaque, +ram_addr_t block_offset, +ram_addr_t offset, +size_t size, +int *bytes_sent); +typedef struct QEMUFileOps {QEMUFilePutBufferFunc *put_buffer;QEMUFileGetBufferFunc *get_buffer;QEMUFileCloseFunc *close;QEMUFileGetFD *get_fd;QEMUFileWritevBufferFunc *writev_buffer; +QEMURamHookFunc *before_ram_iterate; +QEMURamHookFunc *after_ram_iterate; +QEMURamHookFunc *hook_ram_load; +QEMURamSaveFunc *save_page; }QEMUFileOps ;QEMUFile *qemu_fopen_ops (void *opaque,const QEMUFileOps *ops);
savevm.c +59 -0
65 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH v8 12/13 rdma: send pc.ram
In reply to [email protected]From: "Michael R. Hines" <[email protected]>
This takes advantages of the previous patches:
1. use the new QEMUFileOps hook 'save_page'
2. call out to the right accessor methods to invoke the iteration hooks defined in QEMUFileOps
--- arch_init.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-)
arch_init.c +37 -1
@@ -115,6 +115,7 @@ const uint32_t arch_type = QEMU_ARCH;#define RAM_SAVE_FLAG_EOS 0x10#define RAM_SAVE_FLAG_CONTINUE 0x20#define RAM_SAVE_FLAG_XBZRLE 0x40 +/* 0x80 is reserved in migration.h start with 0x100 next */ static struct defconfig_file {
@@ -447,6 +448,7 @@ static int ram_save_block(QEMUFile *f, bool last_stage) ram_bulk_stage = false; } }else { +int ret;uint8_t *p;int cont = (block == last_sent_block) ?RAM_SAVE_FLAG_CONTINUE :0 ;
@@ -455,7 +457,18 @@ static int ram_save_block(QEMUFile *f, bool last_stage)/* In doubt sent page as normal */ bytes_sent =-1 ; -if (is_zero_page (p)) { + ret =ram_control_save_page (f, block->offset, + offset,TARGET_PAGE_SIZE , &bytes_sent); + +if (ret !=RAM_SAVE_CONTROL_NOT_SUPP ) { +if (ret !=RAM_SAVE_CONTROL_DELAYED ) { +if (bytes_sent >0 ) { + acct_info.norm_pages++; + }else if (bytes_sent ==0 ) { + acct_info.dup_pages++; + } + } + }else if (is_zero_page (p)) { acct_info.dup_pages++;if (!ram_bulk_stage) { bytes_sent = save_block_hdr(f, block, offset, cont,
@@ -610,6 +623,15 @@ static int ram_save_setup(QEMUFile *f, void *opaque) }qemu_mutex_unlock_ramlist (); + +/* +* Please leave in place. These calls generate reserved messages in +* the RDMA protocol in order to pre-register RDMA memory in the +* future before the bulk round begins. +*/ +ram_control_before_iterate (f,RAM_CONTROL_SETUP ); +ram_control_after_iterate (f,RAM_CONTROL_SETUP ); +qemu_put_be64 (f,RAM_SAVE_FLAG_EOS );return 0 ;
@@ -628,6 +650,8 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)reset_ram_globals (); } +ram_control_before_iterate (f,RAM_CONTROL_ROUND ); + t0 =qemu_get_clock_ns (rt_clock); i =0 ;while ((ret =qemu_file_rate_limit (f)) ==0 ) {
@@ -658,6 +682,12 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)qemu_mutex_unlock_ramlist (); +/* +* Must occur before EOS (or any QEMUFile operation) +* because of RDMA protocol. +*/ +ram_control_after_iterate (f,RAM_CONTROL_ROUND ); +if (ret <0 ) { bytes_transferred += total_sent;return ret;
@@ -675,6 +705,8 @@ static int ram_save_complete(QEMUFile *f, void *opaque)qemu_mutex_lock_ramlist ();migration_bitmap_sync (); +ram_control_before_iterate (f,RAM_CONTROL_FINISH ); +/* try transferring iterative blocks of memory */ /* flush all remaining blocks regardless of rate limiting */
@@ -688,6 +720,8 @@ static int ram_save_complete(QEMUFile *f, void *opaque) } bytes_transferred += bytes_sent; } + +ram_control_after_iterate (f,RAM_CONTROL_FINISH );migration_end ();qemu_mutex_unlock_ramlist ();
@@ -884,6 +918,8 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) ret = -EINVAL ; goto done; } + }else if (flags &RAM_SAVE_FLAG_HOOK ) { +ram_control_load_hook (f, flags); } error =qemu_file_get_error (f);if (error) {
Signature · 1 line
1.7.10.4
PATCH v8 13/13 rdma: fix mlock() freezes and accounting
In reply to [email protected]From: "Michael R. Hines" <[email protected]>
This patch is contained to migration-rdma.c and fixes the problems experienced by others when the x-rdma-pin-all feature appeared to freeze the VM. By moving this operation out of the connection setup time and instead moving it to ram_save_setup() code, we no longer execute pinning inside the BQL and thus the pinning is parallelized with the VM execution and also properly accounted for inside the QMP migrate total time statistics.
--- arch_init.c | 5 -- docs/rdma.txt | 31 +++++--- migration-rdma.c | 211 +++++++++++++++++++++++++++--------------------------- 3 files changed, 128 insertions(+), 119 deletions(-)
arch_init.c +0 -5
@@ -624,11 +624,6 @@ static int ram_save_setup(QEMUFile *f, void *opaque)qemu_mutex_unlock_ramlist (); -/* -* Please leave in place. These calls generate reserved messages in -* the RDMA protocol in order to pre-register RDMA memory in the -* future before the bulk round begins. -*/ ram_control_before_iterate (f,RAM_CONTROL_SETUP );ram_control_after_iterate (f,RAM_CONTROL_SETUP );
docs/rdma.txt +21 -10
@@ -76,6 +76,13 @@ of the migration, which can greatly reduce the "total" time of your migration. Example performance of this using an idle VM in the previous example can be found in the "Performance" section. +Note: for very large virtual machines (hundreds of GBs), pinning all +*all* of the memory of your virtual machine in the kernel is very expensive +may extend the initial bulk iteration time by many seconds, +and thus extending the total migration time. However, this will not +affect the determinism or predictability of your migration you will +still gain from the benefits of advanced pinning with RDMA. + RUNNING: ========
@@ -195,22 +202,26 @@ The maximum number of repeats is hard-coded to 4096. This is a conservative limit based on the maximum size of a SEND message along with emperical observations on the maximum future benefit of simultaneous page registrations. -The 'type' field has 9 different command values: +The 'type' field has 10 different command values: 1. Unused - 2. Error (sent to the source during bad things) - 3. Ready (control-channel is available) - 4. QEMU File (for sending non-live device state) - 5. RAM Blocks (used right after connection setup) - 6. Compress page (zap zero page and skip registration) - 7. Register request (dynamic chunk registration) - 8. Register result ('rkey' to be used by sender) - 9. Register finished (registration for current iteration finished) + 2. Error (sent to the source during bad things) + 3. Ready (control-channel is available) + 4. QEMU File (for sending non-live device state) + 5. RAM Blocks request (used right after connection setup) + 6. RAM Blocks result (used right after connection setup) + 7. Compress page (zap zero page and skip registration) + 8. Register request (dynamic chunk registration) + 9. Register result ('rkey' to be used by sender) + 10. Register finished (registration for current iteration finished) A single control message, as hinted above, can contain within the data portion an array of many commands of the same type. If there is more than one command, then the 'repeat' field will be greater than 1. -After connection setup is completed, we have two protocol-level +After connection setup, message 5 & 6 are used to exchange ram block +information and optionally pin all the memory if requested by the user. + +After ram block exchange is completed, we have two protocol-level functions, responsible for communicating control-channel commands using the above list of values:
migration-rdma.c +107 -104
346 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH v8 11/13 rdma: core logic
In reply to [email protected]From: "Michael R. Hines" <[email protected]>
Code that does need to be visible is kept
well contained inside this file and this is the only new additional file to the entire patch - good progress.
This file includes the entire protocol and interfaces required to perform RDMA migration.
Also, the configure and Makefile modifications to link this file are included.
Full documentation is in docs/rdma.txt
--- Makefile.objs | 1 + configure | 29 + include/migration/migration.h | 4 + migration-rdma.c | 2809 +++++++++++++++++++++++++++++++++++++++++ migration.c | 8 + 5 files changed, 2851 insertions(+) create mode 100644 migration-rdma.c
Makefile.objs +1 -0
@@ -51,6 +51,7 @@ common-obj-$(CONFIG_POSIX) += os-posix.o common-obj-$(CONFIG_LINUX) += fsdev/ common-obj-y += migration.o migration-tcp.o +common-obj-$(CONFIG_RDMA) += migration-rdma.o common-obj-y += qemu-char.o #aio.o common-obj-y += block-migration.o common-obj-y += page_cache.o xbzrle.o
configure +29 -0
@@ -180,6 +180,7 @@ xfs="" vhost_net="no" vhost_scsi="no" kvm="no" +rdma="" gprof="no" debug_tcg="no" debug="no"
@@ -929,6 +930,10 @@ for opt do ;; --enable-gtk) gtk="yes" ;; + --enable-rdma) rdma="yes" + ;; + --disable-rdma) rdma="no" + ;; --with-gtkabi=*) gtkabi="$optarg" ;; --enable-tpm) tpm="yes"
@@ -1087,6 +1092,8 @@ echo " --enable-bluez enable bluez stack connectivity" echo " --disable-slirp disable SLIRP userspace network connectivity" echo " --disable-kvm disable KVM acceleration support" echo " --enable-kvm enable KVM acceleration support" +echo " --disable-rdma disable RDMA-based migration support" +echo " --enable-rdma enable RDMA-based migration support" echo " --enable-tcg-interpreter enable TCG with bytecode interpreter (TCI)" echo " --disable-nptl disable usermode NPTL support" echo " --enable-nptl enable usermode NPTL support"
@@ -1789,6 +1796,23 @@ EOF libs_softmmu="$sdl_libs $libs_softmmu" fi +if test "$rdma" != "no" ; then + cat > $TMPC <<EOF +#include <rdma/rdma_cma.h> +int main(void) { return 0; } +EOF + rdma_libs="-lrdmacm -libverbs" + if compile_prog "-Werror" "$rdma_libs" ; then + rdma="yes" + libs_softmmu="$libs_softmmu $rdma_libs" + else + if test "$rdma" = "yes" ; then + feature_not_found "rdma" + fi + rdma="no" + fi +fi + ########################################## # VNC TLS/WS detection if test "$vnc" = "yes" -a \( "$vnc_tls" != "no" -o "$vnc_ws" != "no" \) ; then
@@ -3518,6 +3542,7 @@ echo "Linux AIO support $linux_aio" echo "ATTR/XATTR support $attr" echo "Install blobs $blobs" echo "KVM support $kvm" +echo "RDMA support $rdma" echo "TCG interpreter $tcg_interpreter" echo "fdt support $fdt" echo "preadv support $preadv"
@@ -4468,6 +4493,10 @@ if [ "$pixman" = "internal" ]; then echo "config-host.h: subdir-pixman" >> $config_host_mak fi +if test "$rdma" = "yes" ; then +echo "CONFIG_RDMA=y" >> $config_host_mak +fi + if [ "$dtc_internal" = "yes" ]; then echo "config-host.h: subdir-dtc" >> $config_host_mak fi
include/migration/migration.h +4 -0
@@ -77,6 +77,10 @@ void fd_start_incoming_migration(const char *path, Error **errp);void fd_start_outgoing_migration (MigrationState *s,const char *fdname,Error **errp); +void rdma_start_outgoing_migration (void *opaque,const char *host_port,Error **errp); + +void rdma_start_incoming_migration (const char *host_port,Error **errp); +void migrate_fd_error (MigrationState *s);void migrate_fd_connect (MigrationState *s);
migration-rdma.c new file +2809 -0
2,809 lines not on this page · raw message
migration.c +8 -0
@@ -78,6 +78,10 @@ void qemu_start_incoming_migration(const char *uri, Error **errp)if (strstart (uri,"tcp:" , &p))tcp_start_incoming_migration (p, errp); +#ifdef CONFIG_RDMA + else if (strstart(uri, "x-rdma:", &p)) +rdma_start_incoming_migration (p, errp); +#endif #if !defined(WIN32 ) else if (strstart(uri, "exec:", &p)) exec_start_incoming_migration(p, errp);
@@ -407,6 +411,10 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,if (strstart (uri,"tcp:" , &p)) {tcp_start_outgoing_migration (s, p, &local_err); +#ifdef CONFIG_RDMA + }else if (strstart (uri,"x-rdma:" , &p)) { +rdma_start_outgoing_migration (s, p, &local_err); +#endif #if !defined(WIN32 ) } else if (strstart(uri, "exec:", &p)) {exec_start_outgoing_migration (s, p, &local_err);
Signature · 1 line
1.7.10.4
PATCH v8 2/13 rdma: introduce qemu_update_position()
In reply to [email protected]From: "Michael R. Hines" <[email protected]>
RDMA writes happen asynchronously, and thus the performance accounting also needs to be able to occur asynchronously. This allows anybody to call into savevm.c to update both f->pos as well as into arch_init.c to update the acct_info structure with up-to-date values when the RDMA transfer actually completes.
--- arch_init.c | 12 ++++++++++++ include/migration/migration.h | 2 ++ include/migration/qemu-file.h | 1 + savevm.c | 5 +++++ 4 files changed, 20 insertions(+)
arch_init.c +12 -0
@@ -498,6 +498,18 @@ static int ram_save_block(QEMUFile *f, bool last_stage)static uint64_t bytes_transferred; +void acct_update_position (QEMUFile *f,size_t size,bool zero) +{ +uint64_t pages = size /TARGET_PAGE_SIZE ; +if (zero) { + acct_info.dup_pages += pages; + }else { + acct_info.norm_pages += pages; + bytes_transferred += size; +qemu_update_position (f, size); + } +} +static ram_addr_t ram_save_remaining (void ) {return migration_dirty_pages;
include/migration/migration.h +2 -0
@@ -92,6 +92,8 @@ uint64_t ram_bytes_remaining(void);uint64_t ram_bytes_transferred (void );uint64_t ram_bytes_total (void ); +void acct_update_position (QEMUFile *f,size_t size,bool zero); +extern SaveVMHandlers savevm_ram_handlers;uint64_t dup_mig_bytes_transferred (void );
include/migration/qemu-file.h +1 -0
@@ -93,6 +93,7 @@ void qemu_put_be32(QEMUFile *f, unsigned int v);void qemu_put_be64 (QEMUFile *f,uint64_t v);int qemu_get_buffer (QEMUFile *f,uint8_t *buf,int size);int qemu_get_byte (QEMUFile *f); +void qemu_update_position (QEMUFile *f,size_t size);static inline unsigned int qemu_get_ubyte (QEMUFile *f) {
savevm.c +5 -0
@@ -670,6 +670,11 @@ int qemu_get_fd(QEMUFile *f)return -1 ; } +void qemu_update_position (QEMUFile *f,size_t size) +{ + f->pos += size; +} +/** Closes the file * * Returns negative error value if any error happened on previous operations or
Signature · 1 line
1.7.10.4
PATCH v8 5/13 rdma: introduce qemu_file_mode_is_not_valid()
In reply to [email protected]From: "Michael R. Hines" <[email protected]>
QEMUFileRDMA also has read and write modes. This function is now shared to reduce code duplication.
--- include/migration/qemu-file.h | 1 + savevm.c | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-)
include/migration/qemu-file.h +1 -0
@@ -80,6 +80,7 @@ void qemu_put_byte(QEMUFile *f, int v);* The buffer should be available till it is sent asynchronously. */ 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) {
savevm.c +13 -7
@@ -449,14 +449,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 ; }
@@ -474,10 +483,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 ; }
Signature · 1 line
1.7.10.4