Migration Stream v2
v5 cover Migration Stream v2
Hello,
Presented here for review is v5 of the Migration Stream v2 work.
Major work in v5 is the legacy conversion python script which is capable of converting from legacy to v2 format on the fly. It was tested using live migration saving in the legacy format, piping through the script and restoring using the v2 code.
Other work includes a substantial refactoring of the code structure, allowing for a single generic save() and restore() functions, with function pointer hooks for each type of guest to implement. The spec has been updated to include PV MSRs in the migration stream.
This series depends on several prerequisite fixes which have recently been committed into staging (and have not passed the push gate at the time of writing). The series also depends on the VM Generation ID series from David.
I now consider the core of the v2 code stable. I do not expect it to change much too much, other than the identified TODOs (and code review of course).
The next area of work is the libxl integration, which will seek to undo the current layering violations. It will involve introducing a new libxl framing format (which will happen to look curiously similar to the libxc framing format), as well as providing legacy compatibility using the legacy conversion scripts so migrations from older libxl/libxc toolstacks will continue to work.
The code is presented here for comment/query/critism.
~Andrew
RFC PATCH v5 1/14 docs: libxc migration stream specification
The pandoc markdown format is a superset of plain markdown, and while markdown is capable of making plausible documents from it, the results are not fantastic.
Differentiate the two via file extension to avoid running markdown on a pandoc document.
---
In some copious free time (a doc day perhaps), I will see about getting pandoc -> html working, but I don't have time right now.
--- docs/Makefile | 9 +- docs/specs/libxc-migration-stream.pandoc | 640 ++++++++++++++++++++++++++++++ 2 files changed, 648 insertions(+), 1 deletion(-) create mode 100644 docs/specs/libxc-migration-stream.pandoc
docs/Makefile +8 -1
@@ -14,6 +14,8 @@ MAN5SRC-y := $(wildcard man/xl*.pod.5) MARKDOWNSRC-y := $(wildcard misc/*.markdown) +PANDOCSRC-y += $(wildcard specs/*.pandoc) + TXTSRC-y := $(wildcard misc/*.txt)
@@ -28,7 +30,8 @@ DOC_TXT := $(patsubst %.txt,txt/%.txt,$(TXTSRC-y)) \ $(patsubst %.markdown,txt/%.txt,$(MARKDOWNSRC-y)) \ $(patsubst man/%.pod.1,txt/man/%.1.txt,$(MAN1SRC-y)) \ $(patsubst man/%.pod.5,txt/man/%.5.txt,$(MAN5SRC-y)) -DOC_PDF := $(patsubst %.markdown,pdf/%.pdf,$(MARKDOWNSRC-y)) +DOC_PDF := $(patsubst %.markdown,pdf/%.pdf,$(MARKDOWNSRC-y)) \ + $(patsubst %.pandoc,pdf/%.pdf,$(PANDOCSRC-y)) .PHONY: all all: build
@@ -191,6 +194,10 @@ pdf/%.pdf: %.markdown $(INSTALL_DIR) $(@D) pandoc -N --toc --standalone $< --output $@ +pdf/%.pdf: %.pandoc + $(INSTALL_DIR) $(@D) + pandoc --number-sections --toc --standalone $< --output $@ + ifeq (,$(findstring clean,$(MAKECMDGOALS))) $(XEN_ROOT)/config/Docs.mk: $(error You have to run ./configure before building docs)
docs/specs/libxc-migration-stream.pandoc new file +640 -0
640 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [PATCH v5 RFC 01/14] docs: libxc migration stream specification
Add the specification for a new migration stream format. The document includes all the details but to summarize:
The existing (legacy) format is dependant on the word size of the toolstack. This prevents domains from migrating from hosts running 32-bit toolstacks to hosts running 64-bit toolstacks (and vice-versa).
The legacy format lacks any version information making it difficult to extend in compatible way.
The new format has a header (the image header) with version information, a domain header with basic information of the domain and a stream of records for the image data.
The format will be used for future domain types (such as on ARM).
The specification is pandoc format (and extended markdown format) and the documentation build system is extended to generate PDFs from pandoc documents.
Re: [PATCH v5 RFC 01/14] docs: libxc migration stream specification
In reply to Andrew CooperQuoted 6 lines · Andrew Cooper
The pandoc markdown format is a superset of plain markdown, and while
markdownis capable of making plausible documents from it, the results are not fantastic.Differentiate the two via file extension to avoid running
markdownon a pandoc document.
...
Quoted 2 lines
+Image Header
+------------
...
docs/specs/libxc-migration-stream.pandoc line 130
Quoted 8 lines
+--------------------------------------------------------------------
docs/specs/libxc-migration-stream.pandoc new file +7
-0+Field Description +----------- -------------------------------------------------------- +marker 0xFFFFFFFFFFFFFFFF. + +id 0x58454E46 ("XENF" in ASCII). + +version 0x00000001. The version of this specification.
Suggest version 2 here since that's what we've ended up calling it and will reduce confusion if people mistakenly call the legacy format "version 1".
At some point before the 4.5 release we'll want to update the version on the title page to version 2 to match.
docs/specs/libxc-migration-stream.pandoc line 580
Quoted 11 lines
docs/specs/libxc-migration-stream.pandoc new file +11
-0+x86 PV Guest +------------ + +An x86 PV guest image will have this order of records: + +1. Image header +2. Domain header +3. X86\_PV\_INFO record +4. Many PAGE\_DATA records +5. TSC\_INFO +6. X86\_PV\_P2M\_FRAMES record
This record is immediately after the X86_PV_INFO record and before the PAGE_DATA records.
docs/specs/libxc-migration-stream.pandoc line 587
Quoted 7 lines
+7. SHARED\_INFO record
+8. VCPU context records for each online VCPUdocs/specs/libxc-migration-stream.pandoc new file +5
-0+ a. X86\_PV\_VCPU\_BASIC record + b. X86\_PV\_VCPU\_EXTENDED record + c. X86\_PV\_VCPU\_XSAVE record + d. X86\_PV\_VCPU\_MSRS record +9. END record
David
Re: [PATCH v5 RFC 01/14] docs: libxc migration stream specification
In reply to Andrew CooperQuoted 3 lines · Andrew Cooper
The pandoc markdown format is a superset of plain markdown, and while
markdownis capable of making plausible documents from it, the results are not fantastic.
"not fantastic" doesn't sound like a reason to not generate the html and txt versions of it.
Ian.
Re: [PATCH v5 RFC 01/14] docs: libxc migration stream specification
Quoted 9 lines · Ian Campbell
Quoted 3 lines · Andrew Cooper
The pandoc markdown format is a superset of plain markdown, and while
markdownis capable of making plausible documents from it, the results are not fantastic."not fantastic" doesn't sound like a reason to not generate the html and txt versions of it.
Ian.
Actually it turns out that adding txt and html support with pandoc is trivial, so I have done.
~Andrew
Re: [PATCH v5 RFC 01/14] docs: libxc migration stream specification
In reply to Andrew Cooperdocs/specs/libxc-migration-stream.pandoc line 40
Quoted 4 lines · Andrew Cooper
docs/specs/libxc-migration-stream.pandoc new file +4
-0+The following features are not yet fully specified and will be +included in a future draft. + +* Remus
What is the plan for Remus here?
It has pretty large implications for the flow of a migration stream and therefore on the code in the final two patches, I suspect it will require high level changes to those functions, so I'm reluctant to spend a lot of time on them as they are.
docs/specs/libxc-migration-stream.pandoc line 546
Quoted 7 lines
docs/specs/libxc-migration-stream.pandoc new file +7
-0+TOOLSTACK +--------- + +An opaque blob provided by and supplied to the higher layers of the +toolstack (e.g., libxl) during save and restore. + +> This is only temporary -- the intension is the toolstack takes care
"intention"
(please run a spell checker over this document, if it's anything like the code comments I've seen while reviewing it will be full of spelling errors).
Quoted 3 lines
+> of this itself. This record is only present for early development +> purposes and will be removed before submissions, along with changes +> to libxl which cause libxl to handle this data itself.
How confident are you that this can be done before 4.5? I suspect that it's going to involve an awful lot of replumbing.
I also think it will interact in exciting ways with the remus stuff.
I think we need to start seeing the start of concrete plans for both of these things ASAP.
Ian.
Re: [PATCH v5 RFC 01/14] docs: libxc migration stream specification
Quoted 11 lines · Ian Campbell
docs/specs/libxc-migration-stream.pandoc line 40
Quoted 4 lines · Andrew Cooper
docs/specs/libxc-migration-stream.pandoc new file +4
-0+The following features are not yet fully specified and will be +included in a future draft. + +* RemusWhat is the plan for Remus here?
It has pretty large implications for the flow of a migration stream and therefore on the code in the final two patches, I suspect it will require high level changes to those functions, so I'm reluctant to spend a lot of time on them as they are.
I don't believe too much change will be required to the final two patches, but it does depend on fixing the current qemu record layer violations.
It will be much easier to do after a prototype to the libxl level fixes.
Quoted 5 lines
Quoted 3 lines
+> of this itself. This record is only present for early development +> purposes and will be removed before submissions, along with changes +> to libxl which cause libxl to handle this data itself.
How confident are you that this can be done before 4.5? I suspect that it's going to involve an awful lot of replumbing.
I suspect it will, and I frankly have no idea. It is my experience in the past that hacking on libxl turns out to be harder than expected.
Quoted 2 lines
I also think it will interact in exciting ways with the remus stuff.
Less so, I think. Remus mandates identical toolstacks on either side, so the problem of legacy remus to new remus doesn't exist.
Quoted 3 lines
I think we need to start seeing the start of concrete plans for both of these things ASAP.
Indeed.
The concrete plan is that it needs to be done, and it needs to be done to a sufficient extent with general upstream approval that I can be fairly confident that what upstream accepts isn't different to the version which gets shipped with XenServer.$NEXT. On the other hand, getting Xapi + libxc working for XenServer.$NEXT is critical as customers would like to be able to migrate their vms.
I would also like to sleep at some point.
~Andrew
Re: [PATCH v5 RFC 01/14] docs: libxc migration stream specification
Hi Andrew, Ian,
Quoted 13 lines · Andrew Cooper
Quoted 11 lines · Ian Campbell
docs/specs/libxc-migration-stream.pandoc line 40
Quoted 4 lines · Andrew Cooper
docs/specs/libxc-migration-stream.pandoc new file +4
-0+The following features are not yet fully specified and will be +included in a future draft. + +* RemusWhat is the plan for Remus here?
It has pretty large implications for the flow of a migration stream and therefore on the code in the final two patches, I suspect it will require high level changes to those functions, so I'm reluctant to spend a lot of time on them as they are.
Quoted 5 lines
I don't believe too much change will be required to the final two patches, but it does depend on fixing the current qemu record layer violations.
It will be much easier to do after a prototype to the libxl level fixes.
I'm trying to porting Remus to migration v2...
Quoted 38 lines
Quoted 6 lines
Quoted 4 lines
+> of this itself. This record is only present for early development +> purposes and will be removed before submissions, along with changes +> to libxl which cause libxl to handle this data itself.
How confident are you that this can be done before 4.5? I suspect that it's going to involve an awful lot of replumbing.
I suspect it will, and I frankly have no idea. It is my experience in the past that hacking on libxl turns out to be harder than expected.
Quoted 2 lines
I also think it will interact in exciting ways with the remus stuff.
Less so, I think. Remus mandates identical toolstacks on either side, so the problem of legacy remus to new remus doesn't exist.
Quoted 3 lines
I think we need to start seeing the start of concrete plans for both of these things ASAP.
Indeed.
The concrete plan is that it needs to be done, and it needs to be done to a sufficient extent with general upstream approval that I can be fairly confident that what upstream accepts isn't different to the version which gets shipped with XenServer.$NEXT. On the other hand, getting Xapi + libxc working for XenServer.$NEXT is critical as customers would like to be able to migrate their vms.
I would also like to sleep at some point.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Signature · 2 lines
Thanks, Yang.
Re: [PATCH v5 RFC 01/14] docs: libxc migration stream specification
Quoted 17 lines · Hongyang Yang
Hi Andrew, Ian,
Quoted 14 lines · Andrew Cooper
Quoted 12 lines · Ian Campbell
docs/specs/libxc-migration-stream.pandoc line 40
Quoted 4 lines · Andrew Cooper
docs/specs/libxc-migration-stream.pandoc new file +4
-0+The following features are not yet fully specified and will be +included in a future draft. + +* RemusWhat is the plan for Remus here?
It has pretty large implications for the flow of a migration stream and therefore on the code in the final two patches, I suspect it will require high level changes to those functions, so I'm reluctant to spend
a lot of time on them as they are.
Quoted 7 lines
Quoted 5 lines
I don't believe too much change will be required to the final two patches, but it does depend on fixing the current qemu record layer violations.
It will be much easier to do after a prototype to the libxl level fixes.
I'm trying to porting Remus to migration v2...
Ah fantastic! Here I was expecting to have eventually brave that code myself.
How is it going? How are you finding hacking on v2 compared to the legacy code? (I think you are the first person who isn't me trying to extend it) Is there anything I can do while still developing v2 to make things easier?
I really need to get a prototype libxl framing document sorted, but in principle my plan (given only a minimum understanding of the algorithm) is this:
...
* Write page data update
* Write vcpu context etc
* Write a REMUS_CHECKPOINT record (or appropriate name)
* Call the checkpoint callback, passing ownership of the fd to libxl ** libxl writes a libxl qemu record into the stream
* checkpoint callback returns to libxl, returning ownership of the fd
* libxc chooses between sending an END record or looping
...
The fd ownership is expected to work exactly the same on the receiving side, using the REMUS_CHECKPOINT record as an indicator.
Does this look plausible or sensible, or have I missed something?
~Andrew
Re: [PATCH v5 RFC 01/14] docs: libxc migration stream specification
Quoted 26 lines · Andrew Cooper
Quoted 17 lines · Hongyang Yang
Hi Andrew, Ian,
Quoted 14 lines · Andrew Cooper
Quoted 12 lines · Ian Campbell
docs/specs/libxc-migration-stream.pandoc line 40
Quoted 4 lines · Andrew Cooper
docs/specs/libxc-migration-stream.pandoc new file +4
-0+The following features are not yet fully specified and will be +included in a future draft. + +* RemusWhat is the plan for Remus here?
It has pretty large implications for the flow of a migration stream and therefore on the code in the final two patches, I suspect it will require high level changes to those functions, so I'm reluctant to spend
a lot of time on them as they are.Quoted 7 lines
Quoted 5 lines
I don't believe too much change will be required to the final two patches, but it does depend on fixing the current qemu record layer violations.
It will be much easier to do after a prototype to the libxl level fixes.
I'm trying to porting Remus to migration v2...
Quoted 7 lines
Ah fantastic! Here I was expecting to have eventually brave that code myself.
How is it going? How are you finding hacking on v2 compared to the legacy code? (I think you are the first person who isn't me trying to extend it) Is there anything I can do while still developing v2 to make things easier?
It's just starting, but only on libxc side based on your patch series. v2 code is more cleaner than legacy code, easy to understand, and yes, make hacking easier. Maybe I will need your help when the hacking goes on...
Quoted 16 lines
I really need to get a prototype libxl framing document sorted, but in principle my plan (given only a minimum understanding of the algorithm) is this:
...
* Write page data update
* Write vcpu context etc
* Write aREMUS_CHECKPOINTrecord (or appropriate name)
* Call the checkpoint callback, passing ownership of the fd to libxl ** libxl writes a libxl qemu record into the stream
* checkpoint callback returns to libxl, returning ownership of the fd
* libxc chooses between sending an END record or looping
...
Quoted 2 lines
The fd ownership is expected to work exactly the same on the receiving side, using the
REMUS_CHECKPOINTrecord as an indicator.
It mostly looks plausible, but the save side and restore side needs to be synchronised, otherwise, the following problem may exists:
sending side is in libxl and send qemu records, receiving side still in libxc, after it is switched to libxl, part of record may lose.
maybe a handshake will solve the problem, weather it's in libxl or libxc, but current migration frame dose not support send msgs from receiving side to sending side, so it need modifications. We should support this feature.
Quoted 6 lines
Does this look plausible or sensible, or have I missed something?
~Andrew
.
Signature · 2 lines
Thanks, Yang.
Re: [PATCH v5 RFC 01/14] docs: libxc migration stream specification
Quoted 61 lines · Hongyang Yang
Quoted 28 lines · Andrew Cooper
Quoted 18 lines · Hongyang Yang
Hi Andrew, Ian,
Quoted 15 lines · Andrew Cooper
Quoted 13 lines · Ian Campbell
docs/specs/libxc-migration-stream.pandoc line 40
Quoted 4 lines · Andrew Cooper
docs/specs/libxc-migration-stream.pandoc new file +4
-0+The following features are not yet fully specified and will be +included in a future draft. + +* RemusWhat is the plan for Remus here?
It has pretty large implications for the flow of a migration stream and
therefore on the code in the final two patches, I suspect it will require high level changes to those functions, so I'm reluctant to spend
a lot of time on them as they are.Quoted 8 lines
Quoted 6 lines
I don't believe too much change will be required to the final two patches, but it does depend on fixing the current qemu record layer violations.
It will be much easier to do after a prototype to the libxl level fixes.
I'm trying to porting Remus to migration v2...
Quoted 7 lines
Ah fantastic! Here I was expecting to have eventually brave that code myself.
How is it going? How are you finding hacking on v2 compared to the legacy code? (I think you are the first person who isn't me trying to extend it) Is there anything I can do while still developing v2 to make things easier?
It's just starting, but only on libxc side based on your patch series. v2 code is more cleaner than legacy code, easy to understand, and yes, make hacking easier. Maybe I will need your help when the hacking goes on...
Quoted 16 lines
I really need to get a prototype libxl framing document sorted, but in principle my plan (given only a minimum understanding of the algorithm) is this:
...
* Write page data update
* Write vcpu context etc
* Write aREMUS_CHECKPOINTrecord (or appropriate name)
* Call the checkpoint callback, passing ownership of the fd to libxl ** libxl writes a libxl qemu record into the stream
* checkpoint callback returns to libxl, returning ownership of the fd
* libxc chooses between sending an END record or looping
...Quoted 2 lines
The fd ownership is expected to work exactly the same on the receiving side, using the
REMUS_CHECKPOINTrecord as an indicator.
Quoted 9 lines
It mostly looks plausible, but the save side and restore side needs to be synchronised, otherwise, the following problem may exists:
sending side is in libxl and send qemu records, receiving side still in libxc, after it is switched to libxl, part of record may lose.
maybe a handshake will solve the problem, weather it's in libxl or libxc, but current migration frame dose not support send msgs from receiving side
to sending side, so it need modifications. We should support this feature.
Ah yes I see.
How about this?
Libxc REMUS_CHECKPOINT is defined as a 0-length record (like the current END record).
Libxl REMUS_CHECKPOINT is defined containing at least "last checkpoint" bit in the header.
Libxc writes a libxc REMUS_CHECKPOINT record into the stream and always hands the fd to libxl.
Libxl then writes a libxl REMUS_CHECKPOINT record, including the last checkpoint bit if needed.
This means that it is libxl on the receiving side which determines whether the last checkpoint has been reached, and libxc must always pass the fd up. This fixes the synchronisation issues, without requiring a back channel, but still maintaining appropriate layering.
~Andrew
Re: [PATCH v5 RFC 01/14] docs: libxc migration stream specification
Quoted 29 lines · Andrew Cooper
Quoted 27 lines · Hongyang Yang
Quoted 26 lines · Andrew Cooper
Quoted 25 lines · Hongyang Yang
Hi Andrew, Ian,
Quoted 21 lines · Andrew Cooper
Quoted 7 lines · Ian Campbell
Review
Quoted 4 lines · Andrew Cooper
(quoted diff) +4
-0+The following features are not yet fully specified and will be +included in a future draft. + +* RemusWhat is the plan for Remus here?
Quoted 6 lines
It has pretty large implications for the flow of a migration stream and
therefore on the code in the final two patches, I suspect it will require high level changes to those functions, so I'm reluctant to spend
a lot of time on them as they are.I don't believe too much change will be required to the final two patches, but it does depend on fixing the current qemu record layer violations.
It will be much easier to do after a prototype to the libxl level fixes.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
I'm trying to porting Remus to migration v2...
Ah fantastic! Here I was expecting to have eventually brave that code myself.
How is it going? How are you finding hacking on v2 compared to the legacy code? (I think you are the first person who isn't me trying to extend it) Is there anything I can do while still developing v2 to
make
Quoted 23 lines
Quoted 23 lines
Quoted 1 line
things easier?
It's just starting, but only on libxc side based on your patch series. v2 code is more cleaner than legacy code, easy to understand, and yes, make hacking easier. Maybe I will need your help when the hacking goes on...
Quoted 16 lines
I really need to get a prototype libxl framing document sorted, but in principle my plan (given only a minimum understanding of the algorithm) is this:
...
* Write page data update
* Write vcpu context etc
* Write aREMUS_CHECKPOINTrecord (or appropriate name)
* Call the checkpoint callback, passing ownership of the fd to libxl ** libxl writes a libxl qemu record into the stream
* checkpoint callback returns to libxl, returning ownership of the fd
* libxc chooses between sending an END record or looping
...
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
The fd ownership is expected to work exactly the same on the receiving side, using the
REMUS_CHECKPOINTrecord as an indicator.It mostly looks plausible, but the save side and restore side needs to be synchronised, otherwise, the following problem may exists:
sending side is in libxl and send qemu records, receiving side still in libxc, after it is switched to libxl, part of record may lose.
maybe a handshake will solve the problem, weather it's in libxl or
libxc,
Quoted 14 lines
Quoted 4 lines
but current migration frame dose not support send msgs from receiving side
to sending side, so it need modifications. We should support this feature.Ah yes I see.
How about this?
Libxc
REMUS_CHECKPOINTis defined as a 0-length record (like the current END record).
LibxlREMUS_CHECKPOINTis defined containing at least "last checkpoint" bit in the header.
Quoted 5 lines
Libxc writes a libxc
REMUS_CHECKPOINTrecord into the stream and always hands the fd to libxl.
Libxl then writes a libxlREMUS_CHECKPOINTrecord, including the last checkpoint bit if needed.
I am a bit lost on this part. A silly question: the last I recall (a long time ago), the v2 format didn't allow for the page compression to be done asynchronously. Has this limitation changed?
IOW, in the current migration process, the dirty page data is written out while the guest remains suspended. With remus, the compressed page data is written out after resuming the guest. This deferred write out logic needs to be incorporated into v2 code.
Quoted 5 lines
This means that it is libxl on the receiving side which determines whether the last checkpoint has been reached, and libxc must always pass the fd up. This fixes the synchronisation issues, without requiring a back channel, but still maintaining appropriate layering.
So there is a TODO item in the current libxl-remus patches. We need an explicit acknowledgement from the reveiver side that it has gotten the memory checkpoint. Whether it is from libxc or libxl on the receiver side does not matter, as long as the ack signifies reception of the memory checkpoint.
The need for an explicit memory ack is because the disk and memory checkpoint channels are independent.
We need both acks before releasing the buffered network output on the receiver side.
The disk channel (blktap2 or DRBD ) has always sent an explicit ack. But
not the memory channel. Though its over TCP, on a given iteration, memory checkpoint data may still reside on the sender side socket buffer while the disk checkpoint has reached the other end -- which isn't good.
Existing libxc code does a fdatasync or fsync on the fd at the end of each iteration. I don't think it works as intended on TCP sockets. Please correct me if I am wrong about this.
Quoted 6 lines
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v5 RFC 01/14] docs: libxc migration stream specification
Quoted 97 lines · Shriram Rajagopalan
Quoted 29 lines · On Jun 19, 2014 4:16 PM, "Andrew Cooper" <[email protected]…
Quoted 27 lines · Hongyang Yang
Quoted 26 lines · Andrew Cooper
Quoted 25 lines · Hongyang Yang
Hi Andrew, Ian,
Quoted 21 lines · Andrew Cooper
Quoted 7 lines · Ian Campbell
Review
Quoted 4 lines · Andrew Cooper
(quoted diff) +4
-0+The following features are not yet fully specified and will be +included in a future draft. + +* RemusWhat is the plan for Remus here?
Quoted 6 lines
It has pretty large implications for the flow of a migration stream and
therefore on the code in the final two patches, I suspect it will require high level changes to those functions, so I'm reluctant to spend
a lot of time on them as they are.I don't believe too much change will be required to the final two patches, but it does depend on fixing the current qemu record layer violations.
It will be much easier to do after a prototype to the libxl level fixes.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
I'm trying to porting Remus to migration v2...
Ah fantastic! Here I was expecting to have eventually brave that code myself.
How is it going? How are you finding hacking on v2 compared to the legacy code? (I think you are the first person who isn't me trying to extend it) Is there anything I can do while still developing v2
to make
Quoted 10 lines
Quoted 10 lines
Quoted 1 line
things easier?
It's just starting, but only on libxc side based on your patch series. v2 code is more cleaner than legacy code, easy to understand, and yes, make hacking easier. Maybe I will need your help when the hacking goes on...
Quoted 3 lines
I really need to get a prototype libxl framing document sorted,
but in
Quoted 1 line
Quoted 1 line
Quoted 1 line
principle my plan (given only a minimum understanding of the
algorithm)
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
is this:
...
* Write page data update
* Write vcpu context etc
* Write aREMUS_CHECKPOINTrecord (or appropriate name)
* Call the checkpoint callback, passing ownership of the fd to libxl ** libxl writes a libxl qemu record into the stream
* checkpoint callback returns to libxl, returning ownership of the fd
* libxc chooses between sending an END record or looping
...Quoted 1 line
Quoted 1 line
Quoted 1 line
The fd ownership is expected to work exactly the same on the
receiving
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
side, using the
REMUS_CHECKPOINTrecord as an indicator.It mostly looks plausible, but the save side and restore side needs to be synchronised, otherwise, the following problem may exists:
sending side is in libxl and send qemu records, receiving side still in libxc, after it is switched to libxl, part of record may lose.
maybe a handshake will solve the problem, weather it's in libxl orlibxc,
Quoted 14 lines
Quoted 4 lines
but current migration frame dose not support send msgs from receiving side
to sending side, so it need modifications. We should support this feature.Ah yes I see.
How about this?
Libxc
REMUS_CHECKPOINTis defined as a 0-length record (like the current END record).
LibxlREMUS_CHECKPOINTis defined containing at least "last checkpoint" bit in the header.Quoted 5 lines
Libxc writes a libxc
REMUS_CHECKPOINTrecord into the stream and always hands the fd to libxl.
Libxl then writes a libxlREMUS_CHECKPOINTrecord, including the last checkpoint bit if needed.
Quoted 4 lines
I am a bit lost on this part. A silly question: the last I recall (a long time ago), the v2 format didn't allow for the page compression to be done asynchronously. Has this limitation changed?
The v2 format specifies records in a stream; nothing more. It has no bearing on whether the page compression happens asynchronously wrt unpausing the domain or not.
I presume you actually mean the current implementation...
Quoted 5 lines
IOW, in the current migration process, the dirty page data is written out while the guest remains suspended. With remus, the compressed page data is written out after resuming the guest. This deferred write out logic needs to be incorporated into v2 code.
... which is the way it is because the first implementation was done with regular basic migration as a top priority. This can certainly be reworked when remus support is reintroduced.
Quoted 21 lines
Quoted 5 lines
This means that it is libxl on the receiving side which determines whether the last checkpoint has been reached, and libxc must always pass the fd up. This fixes the synchronisation issues, without requiring a back channel, but still maintaining appropriate layering.
So there is a TODO item in the current libxl-remus patches. We need an explicit acknowledgement from the reveiver side that it has gotten the memory checkpoint. Whether it is from libxc or libxl on the receiver side does not matter, as long as the ack signifies reception of the memory checkpoint.
The need for an explicit memory ack is because the disk and memory checkpoint channels are independent.
We need both acks before releasing the buffered network output on the receiver side.
The disk channel (blktap2 or DRBD ) has always sent an explicit ack.
But not the memory channel. Though its over TCP, on a given iteration, memory checkpoint data may still reside on the sender side socket buffer while the disk checkpoint has reached the other end -- which isn't good.
Quoted 4 lines
Existing libxc code does a fdatasync or fsync on the fd at the end of each iteration. I don't think it works as intended on TCP sockets. Please correct me if I am wrong about this.
That is a very sensible need for an explicit ack, although it would seem to make more sense at the libxl level rather than the libxc level.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
RFC PATCH v5 2/14 scripts: Scripts for inspection/valdiation of legacy and new streams
In reply to Andrew CooperTODO: move to tools/python and install properly...
--- tools/libxc/saverestore/scripts/legacy.py | 576 +++++++++++++++++++++++++ tools/libxc/saverestore/scripts/streamspec.py | 136 ++++++ tools/libxc/saverestore/scripts/verify.py | 377 ++++++++++++++++ 3 files changed, 1089 insertions(+) create mode 100755 tools/libxc/saverestore/scripts/legacy.py create mode 100644 tools/libxc/saverestore/scripts/streamspec.py create mode 100755 tools/libxc/saverestore/scripts/verify.py
tools/libxc/saverestore/scripts/legacy.py new file +576 -0
@@ -0,0 +1,576 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import sys +import struct +import streamspec +import os + +__version__ = 1 + +fin = None # Input file/fd +fout = None # Output file/fd +twidth = 0 # Legacy toolstack bitness (32 or 64) +pv = None # Boolean (pv or hvm) + +def stream_read(_ = None): + return fin.read(_) + +def stream_write(_): + return fout.write(_) + +class StreamError(StandardError): + pass + +class VM(object): + + def __init__(self): + # Common + self.p2m_size = 0 + + # PV + self.max_vcpu_id = 0 + self.online_vcpu_map = [] + self.width = 0 + self.levels = 0 + self.basic_len = 0 + self.extd = False + self.xsave_len = 0 + +def write_ihdr(): + stream_write(struct.pack(streamspec.IHDR_FORMAT, + streamspec.IHDR_MARKER, # Marker + streamspec.IHDR_IDENT, # Ident + 1, # Version + streamspec.IHDR_OPT_LE, # Options + 0, 0)) # Reserved + +def write_dhdr(): + if pv: + dtype = streamspec.DHDR_TYPE_x86_pv + else: + dtype = streamspec.DHDR_TYPE_x86_hvm + + stream_write(struct.pack(streamspec.DHDR_FORMAT, + dtype, # Type + 12, # Page size + 0, # Reserved + 0, # Xen major (converted) + __version__)) # Xen minor (converted) + +def write_record(rt, *argl): + alldata = ''.join(argl) + length = len(alldata) + + record = struct.pack(streamspec.RH_FORMAT, rt, length) + alldata + plen = (8 - (length & 7)) & 7 + record += '\x00' * plen + + stream_write(record) + +def write_pv_info(vm): + write_record(streamspec.REC_TYPE_x86_pv_info, + struct.pack(streamspec.X86_PV_INFO_FORMAT, + vm.width, vm.levels, 0, 0)) + +def write_pv_p2m_frames(vm, pfns): + write_record(streamspec.REC_TYPE_x86_pv_p2m_frames, + struct.pack(streamspec.X86_PV_P2M_FRAMES_FORMAT, + 0, vm.p2m_size - 1), + struct.pack("Q" * len(pfns), *pfns)) + +def write_pv_vcpu_basic(vcpu_id, data): + write_record(streamspec.REC_TYPE_x86_pv_vcpu_basic, + struct.pack(streamspec.X86_PV_VCPU_FORMAT_HDR, vcpu_id, 0), + data) + +def write_pv_vcpu_extd(vcpu_id, data): + write_record(streamspec.REC_TYPE_x86_pv_vcpu_extended, + struct.pack(streamspec.X86_PV_VCPU_FORMAT_HDR, vcpu_id, 0), + data) + +def write_pv_vcpu_xsave(vcpu_id, data): + write_record(streamspec.REC_TYPE_x86_pv_vcpu_xsave, + struct.pack(streamspec.X86_PV_VCPU_FORMAT_HDR, vcpu_id, 0), + data) + +def write_page_data(pfns, pages): + if fout is None: # Safe copying 1M buffers around for no reason + return + + new_pfns = [(((x & 0xf0000000) << 32) | (x & 0x0fffffff)) for x in pfns] + + # Optimise the needless buffer copying in write_record() + stream_write(struct.pack(streamspec.RH_FORMAT, + streamspec.REC_TYPE_page_data, + 8 + (len(new_pfns) * 8) + len(pages))) + stream_write(struct.pack(streamspec.PAGE_DATA_FORMAT, len(new_pfns), 0)) + stream_write(struct.pack("Q" * len(new_pfns), *new_pfns)) + stream_write(pages) + +def write_tsc_info(mode, khz, nsec, incarn): + write_record(streamspec.REC_TYPE_tsc_info, + struct.pack(streamspec.TSC_INFO_FORMAT, + mode, khz, nsec, incarn, 0)) + +def write_hvm_params(params): + if pv: + raise StreamError("HVM-only param in PV stream") + elif len(params) % 2: + raise RuntimeError("Expected even length list of hvm parameters") + + write_record(streamspec.REC_TYPE_hvm_params, + struct.pack(streamspec.HVM_PARAMS_FORMAT, len(params) / 2, 0), + struct.pack("Q" * len(params), *params)) + + +def rdexact(nr_bytes): + """Read exactly nr_bytes from fin""" + _ = stream_read(nr_bytes) + if len(_) != nr_bytes: + raise IOError("Stream truncated") + return _ + +def unpack_exact(fmt): + """Unpack a format from fin""" + sz = struct.calcsize(fmt) + return struct.unpack(fmt, rdexact(sz)) + +def unpack_ulongs(nr_ulongs): + if twidth == 32: + return unpack_exact("I" * nr_ulongs) + else: + return unpack_exact("Q" * nr_ulongs) + +def skip_xl_header(): + + hdr = rdexact(32) + if hdr != "Xen saved domain, xl format\n \0 \r": + raise StreamError("No xl header") + + opts = rdexact(16) + _, _, _, optlen = struct.unpack("=IIII", opts) + + optdata = rdexact(optlen) + + print "Skipped xl header" + + stream_write(hdr) + stream_write(opts) + stream_write(optdata) + +def read_pv_extended_info(vm): + + marker, = unpack_ulongs(1) + + if twidth == 32: + expected = 0xffffffff + else: + expected = 0xffffffffffffffff + + if marker != expected: + raise StreamError("Unexpected extended info marker 0x%x" % (marker, )) + + total_length, = unpack_exact("I") + so_far = 0 + + print "Extended Info: length 0x%x" % (total_length, ) + + while so_far < total_length: + + blkid, datasz = unpack_exact("=4sI") + so_far += 8 + + print " Record type: %s, size 0x%x" % (blkid, datasz) + + data = rdexact(datasz) + so_far += datasz + + # Eww, but this is how it is done :( + if blkid == "vcpu": + + vm.basic_len = datasz + + if datasz == 0x1430: + vm.width = 8 + vm.levels = 4 + print " 64bit domain, 4 levels" + elif datasz == 0xaf0: + vm.width = 4 + vm.levels = 3 + print " 32bit domain, 3 levels" + else: + raise StreamError("Unable to determine guest width/level") + + write_pv_info(vm) + + elif blkid == "extv": + vm.extd = True + + elif blkid == "xcnt": + vm.xsave_len, = struct.unpack_from("I", data, 0) + print "xcnt sz 0x%x" % (vm.xsave_len, ) + + else: + raise StreamError("Unrecognised extended block") + + + if so_far != total_length: + raise StreamError("Overshot Extended Info size by %d bytes" + % (so_far - total_length,)) + +def read_pv_p2m_frames(vm): + fpp = 4096 / vm.width + p2m_frame_len = (vm.p2m_size - 1) / fpp + 1 + + print "P2M frames: fpp %d, p2m_frame_len %d" % (fpp, p2m_frame_len) + write_pv_p2m_frames(vm, unpack_ulongs(p2m_frame_len)) + +def read_pv_tail(vm): + + nr_unmapped_pfns, = unpack_exact("I") + + if nr_unmapped_pfns != 0: + # "Unmapped" pfns are bogus + _ = unpack_ulongs(nr_unmapped_pfns) + print "discarding %d bogus 'unmapped pfns'" % (nr_unmapped_pfns, ) + #raise StreamError("Found bogus 'unmapped pfns'") + + for vcpu_id in vm.online_vcpu_map: + + basic = rdexact(vm.basic_len) + print "Got VCPU basic (size 0x%x)" % (vm.basic_len, ), + write_pv_vcpu_basic(vcpu_id, basic) + + if vm.extd: + extd = rdexact(128) + print "extd (size 0x%x)" % (128, ), + write_pv_vcpu_extd(vcpu_id, extd) + + if vm.xsave_len: + mask, size = unpack_exact("QQ") + assert vm.xsave_len - 16 == size + + xsave = rdexact(size) + print "xsave (mask 0x%x, size 0x%x)" % (mask, size), + write_pv_vcpu_xsave(vcpu_id, xsave) + print "" + + shinfo = rdexact(4096) + print "Got shinfo" + + write_record(streamspec.REC_TYPE_shared_info, shinfo) + write_record(streamspec.REC_TYPE_end, "") + + +def read_chunks(vm): + + hvm_params = [] + + while True: + + marker, = unpack_exact("=i") + if marker <= 0: + print "Chunk: type 0x%x" % (marker, ) + + if marker == 0: + print " End" + + if hvm_params: + write_hvm_params(hvm_params) + + return + + elif marker > 0: + + if marker > 1024: + raise StreamError("Page batch (%d) exceeded MAX_BATCH" + % (marker, )) + pfns = unpack_ulongs(marker) + + # xc_domain_save() leaves many XEN_DOMCTL_PFINFO_XTAB records for + # sequences of pfns it cant map. Drop these. + pfns = [ x for x in pfns if x != 0xf0000000 ] + + if len(set(pfns)) != len(pfns): + raise StreamError("Duplicate pfns in batch") + + # print "0x[", + # for pfn in pfns: + # print "%x" % (pfn, ), + # print "]" + + nr_pages = len([x for x in pfns if (x & 0xf0000000) < 0xd0000000]) + + #print " Page Batch, %d PFNs, %d pages" % (marker, nr_pages) + pages = rdexact(nr_pages * 4096) + + write_page_data(pfns, pages) + + elif marker == -1: # XC_SAVE_ID_ENABLE_VERIFY_MODE + # Verify mode... Seemingly nothing to do... + pass + + elif marker == -2: # XC_SAVE_ID_VCPU_INFO + max_id, = unpack_exact("i") + + if max_id > 4095: + raise StreamError("Vcpu max_id out of range: %d > 4095" + % (max_id, ) ) + + vm.max_vcpu_id = max_id + bitmap = unpack_exact("Q" * ((max_id/64) + 1)) + + for idx, word in enumerate(bitmap): + bit_idx = 0 + + while word > 0: + if word & 1: + vm.online_vcpu_map.append((idx * 64) + bit_idx) + + bit_idx += 1 + word >>= 1 + + print " Vcpu info: max_id %d, online map %s" % (vm.max_vcpu_id, + vm.online_vcpu_map) + + elif marker == -3: # XC_SAVE_ID_HVM_IDENT_PT + _, ident_pt = unpack_exact("=IQ") + print " EPT Identity Pagetable 0x%x" % (ident_pt, ) + hvm_params.extend([12, # HVM_PARAM_IDENT_PT + ident_pt]) + + elif marker == -4: # XC_SAVE_ID_HVM_VM86_TSS + _, vm86_tss = unpack_exact("=IQ") + print " VM86 TSS: 0x%x" % (vm86_tss, ) + hvm_params.extend([15, # HVM_PARAM_VM86_TSS + vm86_tss]) + + elif marker == -5: # XC_SAVE_ID_TMEM + raise RuntimeError("todo") + + elif marker == -6: # XC_SAVE_ID_TMEM_EXTRA + raise RuntimeError("todo") + + elif marker == -7: # XC_SAVE_ID_TSC_INFO + mode, nsec, khz, incarn = unpack_exact("=IQII") + print (" TSC_INFO: mode %s, %d ns, %d khz, %d incarn" + % (mode, nsec, khz, incarn)) + write_tsc_info(mode, khz, nsec, incarn) + + elif marker == -8: # XC_SAVE_ID_HVM_CONSOLE_PFN + _, console_pfn = unpack_exact("=IQ") + print " Console pfn 0x%x" % (console_pfn, ) + hvm_params.extend([17, # HVM_PARAM_CONSOLE_PFN + console_pfn]) + + elif marker == -9: # XC_SAVE_ID_LAST_CHECKPOINT + print " Last Checkpoint" + # Nothing to do + + elif marker == -10: # XC_SAVE_ID_HVM_ACPI_IOPORTS_LOCATION + _, loc = unpack_exact("=IQ") + print " ACPI ioport location 0x%x" % (loc, ) + hvm_params.extend([19, # HVM_PARAM_ACPI_IOPORTS_LOCATION + loc]) + + elif marker == -11: # XC_SAVE_ID_HVM_VIRIDIAN + _, loc = unpack_exact("=IQ") + print " Viridian location 0x%x" % (loc, ) + hvm_params.extend([9, # HVM_PARAM_VIRIDIAN + loc]) + + elif marker == -12: # XC_SAVE_ID_COMPRESSED_DATA + sz, = unpack_exact("I") + data = rdexact(sz) + print " Compressed Data: sz 0x%x" % (sz, ) + raise RuntimeError("todo") + + elif marker == -13: # XC_SAVE_ID_ENABLE_COMPRESSION + raise RuntimeError("todo") + + elif marker == -14: # XC_SAVE_ID_HVM_GENERATION_ID_ADDR + _, genid_loc = unpack_exact("=IQ") + print " Generation ID Address 0x%x" % (genid_loc, ) + hvm_params.extend([32, # HVM_PARAM_VM_GENERATION_ID_ADDR + genid_loc]) + + elif marker == -15: # XC_SAVE_ID_HVM_PAGING_RING_PFN + _, paging_ring_pfn = unpack_exact("=IQ") + print " Paging ring pfn 0x%x" % (paging_ring_pfn, ) + hvm_params.extend([27, # HVM_PARAM_PAGING_RING_PFN + paging_ring_pfn]) + + elif marker == -16: # XC_SAVE_ID_HVM_ACCESS_RING_PFN + _, access_ring_pfn = unpack_exact("=IQ") + print " Access ring pfn 0x%x" % (access_ring_pfn, ) + hvm_params.extend([28, # HVM_PARAM_ACCESS_RING_PFN + access_ring_pfn]) + + elif marker == -17: # XC_SAVE_ID_HVM_SHARING_RING_PFN + _, sharing_ring_pfn = unpack_exact("=IQ") + print " Sharing ring pfn 0x%x" % (sharing_ring_pfn, ) + hvm_params.extend([29, # HVM_PARAM_SHARING_RING_PFN + sharing_ring_pfn]) + + elif marker == -18: + sz, = unpack_exact("I") + data = rdexact(sz) + print " Toolstack Data: sz 0x%x" % (sz, ) + print >> sys.stderr, "TODO - fix libxl's use of this" + write_record(streamspec.REC_TYPE_toolstack, data) + + else: + raise StreamError("Unrecognised chunk") + +def read_hvm_tail(vm): + + io, bufio, store = unpack_exact("QQQ") + print "Magic pfns: 0x%x 0x%x 0x%x" % (io, bufio, store) + write_hvm_params([5, io, # HVM_PARAM_IOREQ_PFN + 6, bufio, # HVM_PARAM_BUFIOREQ_PFN + 1, store]) # HVM_PARAM_STORE_PFN + + blobsz, = unpack_exact("I") + print "Got HVM Context (0x%x bytes)" % (blobsz, ) + blob = rdexact(blobsz) + + write_record(streamspec.REC_TYPE_hvm_context, blob) + write_record(streamspec.REC_TYPE_end, "") + + + +def read_qemu(vm): + + rawsig = rdexact(21) + sig, = struct.unpack("21s", rawsig) + print "Qemu signature: %s" % (sig, ) + + if sig == "DeviceModelRecord0002": + rawsz = rdexact(4) + sz, = struct.unpack("I", rawsz) + qdata = rdexact(sz) + + stream_write(rawsig) + stream_write(rawsz) + stream_write(qdata) + + else: + raise RuntimeError("Unrecognised Qemu sig '%s'" % (sig, )) + + +def read_vm(vm): + + try: + + vm.p2m_size, = unpack_ulongs(1) + print "P2M Size: 0x%x" % (vm.p2m_size,) + + write_ihdr() + write_dhdr() + + if pv: + read_pv_extended_info(vm) + read_pv_p2m_frames(vm) + + read_chunks(vm) + + if pv: + read_pv_tail(vm) + else: + read_hvm_tail(vm) + read_qemu(vm) + + except (IOError, StreamError, ) as e: + print >> sys.stderr, "Error: ", e + return 1 + + except RuntimeError as e: + print >> sys.stderr, "Script error", e + print >> sys.stderr, "Please fix me" + return 2 + return 0 + +def open_file_or_fd(val, mode): + """ + If 'val' looks like a decimal integer, open it as an fd. If not, try to + open it as a regular file. + """ + + fd = -1 + try: + # Does it look like an integer? + try: + fd = int(val, 10) + except ValueError: + pass + + # Try to open it... + if fd != -1: + return os.fdopen(fd, mode) + else: + return open(val, mode) + + except StandardError, e: + if fd != -1: + print >> sys.stderr, "Unable to open fd %d: %s" % (fd, e) + else: + print >> sys.stderr, "Unable to open file '%s': %s" % (val, e) + + raise SystemExit(1) + + +def main(argv): + from optparse import OptionParser + global fin, fout, twidth, pv + + # Change stdout to be line-buffered. + sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 1) + + parser = OptionParser(version = __version__, + usage = ("%prog -i INPUT -o OUTPUT" + " -w WIDTH -g GUEST [-x]")) + + parser.add_option("-v", action = "store_true", default = False, + help = "More verbose") + + # Required options + parser.add_option("-i", "--in", dest = "fin", metavar = "<FD or FILE>", + help = "Legacy input to convert") + parser.add_option("-o", "--out", dest = "fout", metavar = "<FD or FILE>", + help = "v2 format output") + parser.add_option("-w", "--width", dest = "twidth", + metavar = "<32/64>", choices = ["32", "64"], + help = "Legacy toostack bitness") + parser.add_option("-g", "--guest-type", dest = "gtype", + metavar = "<pv/hvm>", choices = ["pv", "hvm"], + help = "Type of guest in stream") + + # Optional options + parser.add_option("-x", "--xl", action = "store_true", default = False, + help = ("Is an `xl` header present in the stream?" + " (default no)")) + + opts, args = parser.parse_args() + + if (opts.fin is None or opts.fout is None or + opts.twidth is None or opts.gtype is None): + + parser.print_help(sys.stderr) + raise SystemExit(1) + + fin = open_file_or_fd(opts.fin, "rb") + fout = open_file_or_fd(opts.fout, "wb") + twidth = int(opts.twidth) + pv = opts.gtype == "pv" + + if opts.xl: + skip_xl_header() + + rc = read_vm(VM()) + fout.close() + + return rc + +if __name__ == "__main__": + sys.exit(main(sys.argv))
tools/libxc/saverestore/scripts/streamspec.py new file +136 -0
136 lines not on this page · raw message
tools/libxc/saverestore/scripts/verify.py new file +377 -0
377 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [PATCH v5 RFC 02/14] scripts: Scripts for inspection/valdiation of legacy and new streams
Add python scripts to manage image formats.
legacy.py converts a legacy format image into the new format. This avoids having to retain the restore code for the legacy format. Toolstacks will identify a legacy image and call the conversion script prior to restoring the domain.
verify.py validates that a new format image complies with the specification.
RFC PATCH v5 3/14 tools/libxc: save/restore v2 framework
In reply to Andrew CooperFor testing purposes, the environmental variable "XG_MIGRATION_V2" allows the two save/restore codepaths to coexist, and have a runtime switch.
It is indended that once this series is less RFC, the v2 framework will completely replace v1.
--- tools/libxc/Makefile | 1 + tools/libxc/saverestore/common.h | 15 +++++++++++++++ tools/libxc/saverestore/restore.c | 23 +++++++++++++++++++++++ tools/libxc/saverestore/save.c | 19 +++++++++++++++++++ tools/libxc/xc_domain_restore.c | 8 ++++++++ tools/libxc/xc_domain_save.c | 6 ++++++ tools/libxc/xenguest.h | 13 +++++++++++++ 7 files changed, 85 insertions(+) create mode 100644 tools/libxc/saverestore/common.h create mode 100644 tools/libxc/saverestore/restore.c create mode 100644 tools/libxc/saverestore/save.c
tools/libxc/Makefile +1 -0
@@ -44,6 +44,7 @@ GUEST_SRCS-y := GUEST_SRCS-y += xg_private.c xc_suspend.c ifeq ($(CONFIG_MIGRATE),y) GUEST_SRCS-y += xc_domain_restore.c xc_domain_save.c +GUEST_SRCS-y += $(wildcard saverestore/*.c) GUEST_SRCS-y += xc_offline_page.c xc_compression.c else GUEST_SRCS-y += xc_nomigrate.c
tools/libxc/saverestore/common.h new file +15 -0
@@ -0,0 +1,15 @@ +#ifndef __COMMON__H +#define __COMMON__H + +#include "../xg_private.h" + +#endif +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
tools/libxc/saverestore/restore.c new file +23 -0
@@ -0,0 +1,23 @@ +#include "common.h" + +int xc_domain_restore2 (xc_interface *xch,int io_fd,uint32_t dom, +unsigned int store_evtchn,unsigned long *store_mfn, +domid_t store_domid,unsigned int console_evtchn, +unsigned long *console_mfn,domid_t console_domid, +unsigned int hvm,unsigned int pae,int superpages, +int checkpointed_stream, +struct restore_callbacks *callbacks) +{ +IPRINTF ("In experimental %s" , __func__); +return -1 ; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
tools/libxc/saverestore/save.c new file +19 -0
@@ -0,0 +1,19 @@ +#include "common.h" + +int xc_domain_save2 (xc_interface *xch,int io_fd,uint32_t dom,uint32_t max_iters, +uint32_t max_factor,uint32_t flags, +struct save_callbacks * callbacks,int hvm) +{ +IPRINTF ("In experimental %s" , __func__); +return -1 ; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
tools/libxc/xc_domain_restore.c +8 -0
@@ -1490,6 +1490,14 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,struct restore_ctx *ctx = &_ctx;struct domain_info_context *dinfo = &ctx->dinfo; +if (getenv ("XG_MIGRATION_V2" ) ) + { +return xc_domain_restore2 ( + xch, io_fd, dom, store_evtchn, store_mfn, + store_domid, console_evtchn, console_mfn, console_domid, + hvm, pae, superpages, checkpointed_stream, callbacks); + } +DPRINTF ("%s: starting restore of new domid %u" , __func__, dom);pagebuf_init (&pagebuf);
tools/libxc/xc_domain_save.c +6 -0
@@ -894,6 +894,12 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iterint completed =0 ; +if (getenv ("XG_MIGRATION_V2" ) ) + { +return xc_domain_save2 (xch, io_fd, dom, max_iters, + max_factor, flags, callbacks, hvm); + } +DPRINTF ("%s: starting save of domid %u" , __func__, dom);if ( hvm && !callbacks->switch_qemu_logdirty )
tools/libxc/xenguest.h +13 -0
@@ -88,6 +88,10 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter uint32_t max_factor, uint32_t flags /* XCFLAGS_xxx */, struct save_callbacks* callbacks, int hvm); +/* Domain Save v2 */ +int xc_domain_save2 (xc_interface *xch,int io_fd,uint32_t dom,uint32_t max_iters, +uint32_t max_factor,uint32_t flags, +struct save_callbacks * callbacks,int hvm);/* callbacks provided by xc_domain_restore */ struct restore_callbacks {
@@ -124,6 +128,15 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom, unsigned int hvm, unsigned int pae, int superpages, int checkpointed_stream, struct restore_callbacks *callbacks); + +/* Domain Restore v2 */ +int xc_domain_restore2 (xc_interface *xch,int io_fd,uint32_t dom, +unsigned int store_evtchn,unsigned long *store_mfn, +domid_t store_domid,unsigned int console_evtchn, +unsigned long *console_mfn,domid_t console_domid, +unsigned int hvm,unsigned int pae,int superpages, +int checkpointed_stream, +struct restore_callbacks *callbacks);/** * xc_domain_restore writes a file to disk that contains the device * model saved state.
Signature · 1 line
1.7.10.4
Re: [PATCH v5 RFC 03/14] [HACK] tools/libxc: save/restore v2 framework
Quoted 5 lines · Andrew Cooper
For testing purposes, the environmental variable "
XG_MIGRATION_V2" allows the two save/restore codepaths to coexist, and have a runtime switch.It is indended that once this series is less RFC, the v2 framework will completely replace v1.
When do you imagine that will be? It seems to me like it could/should reasonably happen now.
Re: [PATCH v5 RFC 03/14] [HACK] tools/libxc: save/restore v2 framework
Quoted 11 lines · Ian Campbell
Quoted 5 lines · Andrew Cooper
For testing purposes, the environmental variable "
XG_MIGRATION_V2" allows the two save/restore codepaths to coexist, and have a runtime switch.It is indended that once this series is less RFC, the v2 framework will completely replace v1.
When do you imagine that will be? It seems to me like it could/should reasonably happen now.
When I have some plausible libxl compatibility in the series, which is still ongoing work.
If this were to be done in two parts, we would end up with a single identifiable xl stream containing possibly the new or possibly the old libxc stream, which makes backwards compatibility much harder to retrofit.
~Andrew
Re: [PATCH v5 RFC 03/14] [HACK] tools/libxc: save/restore v2 framework
Quoted 13 lines · Andrew Cooper
Quoted 11 lines · Ian Campbell
Quoted 5 lines · Andrew Cooper
For testing purposes, the environmental variable "
XG_MIGRATION_V2" allows the two save/restore codepaths to coexist, and have a runtime switch.It is indended that once this series is less RFC, the v2 framework will completely replace v1.
When do you imagine that will be? It seems to me like it could/should reasonably happen now.
Quoted 6 lines
When I have some plausible libxl compatibility in the series, which is still ongoing work.
If this were to be done in two parts, we would end up with a single identifiable xl stream containing possibly the new or possibly the old libxc stream, which makes backwards compatibility much harder to retrofit.
I keep finding myself guessing whether weird wrinkles are due to this hack or are actual wrinkles which I should complain about.
Please make the change to the final form ASAP, otherwise the review effort is going onto the wrong thing.
Until this series is committed there is no need for any backwards compat with intermediate forms of the series. We won't commit to it until it is complete and non-RFC, so no need to worry about creating a halfway converted stream now.
Ian.
RFC PATCH v5 4/14 tools/libxc: C implementation of stream format
In reply to Andrew CooperStill TODO: Consider namespacing/prefixing
--- tools/libxc/saverestore/common.c | 79 +++++++++++++++++ tools/libxc/saverestore/common.h | 8 ++ tools/libxc/saverestore/stream_format.h | 147 +++++++++++++++++++++++++++++++ 3 files changed, 234 insertions(+) create mode 100644 tools/libxc/saverestore/common.c create mode 100644 tools/libxc/saverestore/stream_format.h
tools/libxc/saverestore/common.c new file +79 -0
@@ -0,0 +1,79 @@ +#include "common.h" + +static const char *dhdr_types[] = +{ + [DHDR_TYPE_X86_PV ] ="x86 PV" , + [DHDR_TYPE_X86_HVM ] ="x86 HVM" , + [DHDR_TYPE_X86_PVH ] ="x86 PVH" , + [DHDR_TYPE_ARM ] ="ARM" , +}; + +const char *dhdr_type_to_str (uint32_t type) +{ +if ( type <ARRAY_SIZE (dhdr_types) && dhdr_types[type] ) +return dhdr_types[type]; + +return "Reserved" ; +} + +static const char *mandatory_rec_types[] = +{ + [REC_TYPE_END ] ="End" , + [REC_TYPE_PAGE_DATA ] ="Page data" , + [REC_TYPE_X86_PV_INFO ] ="x86 PV info" , + [REC_TYPE_X86_PV_P2M_FRAMES ] ="x86 PV P2M frames" , + [REC_TYPE_X86_PV_VCPU_BASIC ] ="x86 PV vcpu basic" , + [REC_TYPE_X86_PV_VCPU_EXTENDED ] ="x86 PV vcpu extended" , + [REC_TYPE_X86_PV_VCPU_XSAVE ] ="x86 PV vcpu xsave" , + [REC_TYPE_SHARED_INFO ] ="Shared info" , + [REC_TYPE_TSC_INFO ] ="TSC info" , + [REC_TYPE_HVM_CONTEXT ] ="HVM context" , + [REC_TYPE_HVM_PARAMS ] ="HVM params" , + [REC_TYPE_TOOLSTACK ] ="Toolstack" , + [REC_TYPE_X86_PV_VCPU_MSRS ] ="x86 PV vcpu msrs" , +}; + +/* +static const char *optional_rec_types[] = +{ +None yet... +}; +*/ + +const char *rec_type_to_str (uint32_t type) +{ +if ( type &REC_TYPE_OPTIONAL ) +return "Reserved" ; + +if ( ((type &REC_TYPE_OPTIONAL ) ==0 ) && + (type <ARRAY_SIZE (mandatory_rec_types)) && + (mandatory_rec_types[type]) ) +return mandatory_rec_types[type]; + +return "Reserved" ; +} + +static void __attribute__((unused))build_assertions (void ) +{ +XC_BUILD_BUG_ON (sizeof (struct ihdr ) !=24 ); +XC_BUILD_BUG_ON (sizeof (struct dhdr ) !=16 ); +XC_BUILD_BUG_ON (sizeof (struct rhdr ) !=8 ); + +XC_BUILD_BUG_ON (sizeof (struct rec_page_data_header ) !=8 ); +XC_BUILD_BUG_ON (sizeof (struct rec_x86_pv_info ) !=8 ); +XC_BUILD_BUG_ON (sizeof (struct rec_x86_pv_p2m_frames ) !=8 ); +XC_BUILD_BUG_ON (sizeof (struct rec_x86_pv_vcpu_hdr ) !=8 ); +XC_BUILD_BUG_ON (sizeof (struct rec_tsc_info ) !=24 ); +XC_BUILD_BUG_ON (sizeof (struct rec_hvm_params_entry ) !=16 ); +XC_BUILD_BUG_ON (sizeof (struct rec_hvm_params ) !=8 ); +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
tools/libxc/saverestore/common.h +8 -0
@@ -3,6 +3,14 @@#include "../xg_private.h" +#include "stream_format.h" + +/* String representation of Domain Header types. */ +const char *dhdr_type_to_str (uint32_t type); + +/* String representation of Record types. */ +const char *rec_type_to_str (uint32_t type); +#endif /* * Local variables:
tools/libxc/saverestore/stream_format.h new file +147 -0
147 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [PATCH v5 RFC 04/14] tools/libxc: C implementation of stream format
Provide the C structures matching the binary (wire) format of the new stream format. All header/record fields are naturally aligned and explicit padding fields are used to ensure the correct layout (i.e., there is no need for any non-standard structure packing pragma or attribute).
Provide some helper functions for converting types to string for diagnostic purposes.
Re: [PATCH v5 RFC 04/14] tools/libxc: C implementation of stream format
In reply to Andrew CooperQuoted 1 line · Andrew Cooper
Still TODO: Consider namespacing/prefixing
Perhaps xc_sr_?
Otherwise:
Quoted 1 line
Signed-off-by David Vrabel <[email protected]>
Would prefer if you dropped this signed-off by throughout and instead include a reviewed-by where I've provided one.
David
Re: [PATCH v5 RFC 04/14] tools/libxc: C implementation of stream format
Quoted 4 lines · David Vrabel
Quoted 1 line · Andrew Cooper
Still TODO: Consider namespacing/prefixing
Perhaps
xc_sr_?
That's as good a colour for the shed as anything IMHO. It's all internal I think, so it's not as super critical as an external API, so long as it is sensible in the scope of the library.
Quoted 16 lines
Otherwise:
Reviewed-by David Vrabel <[email protected]>Quoted 1 line
Signed-off-by David Vrabel <[email protected]>Would prefer if you dropped this signed-off by throughout and instead include a reviewed-by where I've provided one.
David
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
RFC PATCH v5 5/14 tools/libxc: noarch common code
In reply to Andrew Cooper--- tools/libxc/saverestore/common.c | 50 +++++++ tools/libxc/saverestore/common.h | 269 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 319 insertions(+)
tools/libxc/saverestore/common.c +50 -0
@@ -1,3 +1,5 @@ +#include <assert.h> +#include "common.h" static const char *dhdr_types[] =
@@ -53,6 +55,54 @@ const char *rec_type_to_str(uint32_t type)return "Reserved" ; } +int write_split_record (struct context *ctx,struct record *rec, +void *buf,size_t sz) +{ +static const char zeroes[7 ] = {0 }; +xc_interface *xch = ctx->xch; +uint32_t combined_length = rec->length + sz; +size_t record_length =ROUNDUP (combined_length,REC_ALIGN_ORDER ); + +if ( record_length >REC_LENGTH_MAX ) + { +ERROR ("Record (0x%08" PRIx32", %s) length 0x%" PRIx32 +" exceeds max (0x%" PRIx32")" , rec->type, +rec_type_to_str (rec->type), rec->length,REC_LENGTH_MAX ); +return -1 ; + } + +if ( rec->length ) +assert (rec->data); +if ( sz ) +assert (buf); + +if (write_exact (ctx->fd, &rec->type,sizeof (rec->type)) || +write_exact (ctx->fd, &combined_length,sizeof (rec->length)) || + (rec->length &&write_exact (ctx->fd, rec->data, rec->length)) || + (sz &&write_exact (ctx->fd, buf, sz)) || +write_exact (ctx->fd, zeroes, record_length - combined_length) ) + { +PERROR ("Unable to write record to stream" ); +return -1 ; + } + +return 0 ; +} + +int write_record_header (struct context *ctx,struct record *rec) +{ +xc_interface *xch = ctx->xch; + +if (write_exact (ctx->fd, &rec->type,sizeof (rec->type)) || +write_exact (ctx->fd, &rec->length,sizeof (rec->length)) ) + { +PERROR ("Unable to write record to stream" ); +return -1 ; + } + +return 0 ; +} +static void __attribute__((unused))build_assertions (void ) {XC_BUILD_BUG_ON (sizeof (struct ihdr ) !=24 );
tools/libxc/saverestore/common.h +269 -0
282 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [PATCH v5 RFC 05/14] tools/libxc: noarch common code
Add the context structure used to keep state during the save/restore process.
Define the set of architecture or domain type specific operations with a set of callbacks (common_ops, save_ops, and restore_ops).
Add common functions for writing records.
Re: [PATCH v5 RFC 05/14] tools/libxc: noarch common code
In reply to Andrew Coopertools/libxc/saverestore/common.c const char *rec_type_to_str(uint32_t type) · line 64
Quoted 7 lines · Andrew Cooper
tools/libxc/saverestore/common.c +7
-0+int write_split_record (struct context *ctx,struct record *rec, +void *buf,size_t sz) +{ +static const char zeroes[7 ] = {0 }; +xc_interface *xch = ctx->xch; +uint32_t combined_length = rec->length + sz; +size_t record_length =ROUNDUP (combined_length,REC_ALIGN_ORDER );
I suppose the [7] must relate to REC_ALIGN_ORDER somehow, can you not derive it? (1<<REC_ALIGN_ORDER perhaps)
Quoted 9 lines
tools/libxc/saverestore/common.c +9
-0+ +if ( record_length >REC_LENGTH_MAX ) + { +ERROR ("Record (0x%08" PRIx32", %s) length 0x%" PRIx32 +" exceeds max (0x%" PRIx32")" , rec->type, +rec_type_to_str (rec->type), rec->length,REC_LENGTH_MAX ); +return -1 ; + } +
tools/libxc/saverestore/common.c const char *rec_type_to_str(uint32_t type) · line 83
Quoted 10 lines
tools/libxc/saverestore/common.c +10
-0+if ( rec->length ) +assert (rec->data); +if ( sz ) +assert (buf); + +if (write_exact (ctx->fd, &rec->type,sizeof (rec->type)) || +write_exact (ctx->fd, &combined_length,sizeof (rec->length)) || + (rec->length &&write_exact (ctx->fd, rec->data, rec->length)) || + (sz &&write_exact (ctx->fd, buf, sz)) || +write_exact (ctx->fd, zeroes, record_length - combined_length) )
For clarity I'd be inclined to split this into 4 separate ifs:
write type & length
optionally write data
optionally write extra buf
write padding.
either goto err or a context specific PERROR.
Quoted 4 lines
tools/libxc/saverestore/common.c +4
-0+ { +PERROR ("Unable to write record to stream" ); +return -1 ; + }
tools/libxc/saverestore/common.c const char *rec_type_to_str(uint32_t type) · line 97
Quoted 10 lines
tools/libxc/saverestore/common.c +10
-0+ +return 0 ; +} + +int write_record_header (struct context *ctx,struct record *rec) +{ +xc_interface *xch = ctx->xch; + +if (write_exact (ctx->fd, &rec->type,sizeof (rec->type)) || +write_exact (ctx->fd, &rec->length,sizeof (rec->length)) )
No need to round this one up? Or assert that it is already aligned?
Quoted 16 lines
tools/libxc/saverestore/common.c +8
-0+ { +PERROR ("Unable to write record to stream" ); +return -1 ; + } + +return 0 ; +} +static void __attribute__((unused))build_assertions (void ) {XC_BUILD_BUG_ON (sizeof (struct ihdr ) !=24 );tools/libxc/saverestore/common.h +0
-0
tools/libxc/saverestore/common.h line 6
Quoted 6 lines
tools/libxc/saverestore/common.h +3
-0@@ -1,7 +1,20 @@#ifndef __COMMON__H#define __COMMON__H +#include <stdbool.h> + +// Hack out junk from the namespace
Do you have a plan to not need these hacks?
tools/libxc/saverestore/common.h const char *dhdr_type_to_str(uint32_t type); · line 64
Quoted 1 line
tools/libxc/saverestore/common.h +1
-0+* required, the callee should leave '*pages' unouched.
untouched.
tools/libxc/saverestore/common.h const char *dhdr_type_to_str(uint32_t type); · line 70
Quoted 1 line
tools/libxc/saverestore/common.h +1
-0+* callee enounceters an error, it should *NOT* free() the memory it
encounters.
tools/libxc/saverestore/common.h const char *dhdr_type_to_str(uint32_t type); · line 253
Quoted 1 line
tools/libxc/saverestore/common.h +1
-0+* ensuring that they subseqently write the correct amount of data into the
subsequently.
Re: [PATCH v5 RFC 05/14] tools/libxc: noarch common code
Quoted 10 lines · Ian Campbell
tools/libxc/saverestore/common.c const char *rec_type_to_str(uint32_t type) · line 64
Quoted 7 lines · Andrew Cooper
tools/libxc/saverestore/common.c +7
-0+int write_split_record (struct context *ctx,struct record *rec, +void *buf,size_t sz) +{ +static const char zeroes[7 ] = {0 }; +xc_interface *xch = ctx->xch; +uint32_t combined_length = rec->length + sz; +size_t record_length =ROUNDUP (combined_length,REC_ALIGN_ORDER );I suppose the [7] must relate to
REC_ALIGN_ORDERsomehow, can you not derive it? (1<<REC_ALIGN_ORDER perhaps)
It does indeed. I will change it to a calculation.
Quoted 26 lines
Quoted 10 lines
tools/libxc/saverestore/common.c +9
-0+ +if ( record_length >REC_LENGTH_MAX ) + { +ERROR ("Record (0x%08" PRIx32", %s) length 0x%" PRIx32 +" exceeds max (0x%" PRIx32")" , rec->type, +rec_type_to_str (rec->type), rec->length,REC_LENGTH_MAX ); +return -1 ; + } +tools/libxc/saverestore/common.c const char *rec_type_to_str(uint32_t type) · line 83
Quoted 10 lines
tools/libxc/saverestore/common.c +10
-0+if ( rec->length ) +assert (rec->data); +if ( sz ) +assert (buf); + +if (write_exact (ctx->fd, &rec->type,sizeof (rec->type)) || +write_exact (ctx->fd, &combined_length,sizeof (rec->length)) || + (rec->length &&write_exact (ctx->fd, rec->data, rec->length)) || + (sz &&write_exact (ctx->fd, buf, sz)) || +write_exact (ctx->fd, zeroes, record_length - combined_length) )For clarity I'd be inclined to split this into 4 separate ifs:
write type & length
optionally write data
optionally write extra buf
write padding.
Quoted 1 line
either goto err or a context specific PERROR.
Ok.
Quoted 16 lines
Quoted 5 lines
tools/libxc/saverestore/common.c +4
-0+ { +PERROR ("Unable to write record to stream" ); +return -1 ; + }tools/libxc/saverestore/common.c const char *rec_type_to_str(uint32_t type) · line 97
Quoted 10 lines
tools/libxc/saverestore/common.c +10
-0+ +return 0 ; +} + +int write_record_header (struct context *ctx,struct record *rec) +{ +xc_interface *xch = ctx->xch; + +if (write_exact (ctx->fd, &rec->type,sizeof (rec->type)) || +write_exact (ctx->fd, &rec->length,sizeof (rec->length)) )No need to round this one up? Or assert that it is already aligned?
The comment by the prototype explains that this is for use by "callers doing complicated records" (i.e. PAGE_INFO) and that the caller is responsible for ensuring that length is correct.
Quoted 20 lines
Quoted 20 lines
tools/libxc/saverestore/common.c +8
-0+ { +PERROR ("Unable to write record to stream" ); +return -1 ; + } + +return 0 ; +} +static void __attribute__((unused))build_assertions (void ) {XC_BUILD_BUG_ON (sizeof (struct ihdr ) !=24 );tools/libxc/saverestore/common.h +0
-0@@ -1,7 +1,20 @@#ifndef __COMMON__H#define __COMMON__H
Quoted 4 lines
tools/libxc/saverestore/common.h line 6
Quoted 3 lines
tools/libxc/saverestore/common.h +3
-0+#include <stdbool.h> + +// Hack out junk from the namespace Do you have a plan to not need these hacks?
Not really. There are enough other areas of libxc which still use these macros, and I can't go and simply update all other areas as struct context is meaningless outside of libxc/saverestore.
Quoted 11 lines
tools/libxc/saverestore/common.h const char *dhdr_type_to_str(uint32_t type); · line 64
Quoted 2 lines
tools/libxc/saverestore/common.h +1
-0+* required, the callee should leave '*pages' unouched. untouched.
tools/libxc/saverestore/common.h const char *dhdr_type_to_str(uint32_t type); · line 70
Quoted 1 line
tools/libxc/saverestore/common.h +1
-0+* callee enounceters an error, it should *NOT* free() the memory it encounters.
tools/libxc/saverestore/common.h const char *dhdr_type_to_str(uint32_t type); · line 253
Quoted 1 line
tools/libxc/saverestore/common.h +1
-0+* ensuring that they subseqently write the correct amount of data into the subsequently.
Noted.
~Andrew
Re: [PATCH v5 RFC 05/14] tools/libxc: noarch common code
Quoted 5 lines · Andrew Cooper
Quoted 2 lines
Quoted 1 line
+// Hack out junk from the namespace
Do you have a plan to not need these hacks?
Not really. There are enough other areas of libxc which still use these macros, and I can't go and simply update all other areas as
I (or rather git grep) can't see the existing definitions/uses mfn_to_pfn and pfn_to_mfn outside of xc_domain_{save,restore}.c. Where are the defined and used outside of those?
(I see some in mini-os, but you specifically said libxc)
Likewise for the *_FIELD stuff which is used in ~2 places outside the save restore code according to grep.
Quoted 2 lines
struct
context is meaningless outside of libxc/saverestore.
So how are these used there?
Ian.
Re: [PATCH v5 RFC 05/14] tools/libxc: noarch common code
Quoted 8 lines · Ian Campbell
Quoted 4 lines · Andrew Cooper
Quoted 2 lines
Quoted 1 line
+// Hack out junk from the namespace
Do you have a plan to not need these hacks?
Not really. There are enough other areas of libxc which still use these macros, and I can't go and simply update all other areas as
I (or rather git grep) can't see the existing definitions/uses
mfn_to_pfnandpfn_to_mfnoutside of xc_domain_{save,restore}.c. Where are the defined and used outside of those?
mfn_to_pfn it turns out isn't. pfn_to_mfn is used once in xc_domain.c. Open coding it might be a solution.
Quoted 2 lines
(I see some in mini-os, but you specifically said libxc)
MiniOS will undoubtedly using its kernel versions of these functions, so is not relevant here.
Quoted 3 lines
Likewise for the
*_FIELDstuff which is used in ~2 places outside the save restore code according to grep.
xc_core_x86.c defines itself GET_FIELD() so clearly doesn't use xg_save_restore.h
xc_resume.c clearly uses xg_save_restore.h but could probably be converted to be similar to xc_core_x86.c
Quoted 7 lines
Quoted 3 lines
struct
context is meaningless outside of libxc/saverestore.So how are these used there?
Ian.
They are not. They are reimplemented in common_x86_pv.h so as to not take magic locally scoped variables with specific names.
~Andrew
Re: [PATCH v5 RFC 05/14] tools/libxc: noarch common code
Quoted 11 lines · Andrew Cooper
Quoted 8 lines · Ian Campbell
Quoted 4 lines · Andrew Cooper
Quoted 2 lines
Quoted 1 line
+// Hack out junk from the namespace
Do you have a plan to not need these hacks?
Not really. There are enough other areas of libxc which still use these macros, and I can't go and simply update all other areas as
I (or rather git grep) can't see the existing definitions/uses
mfn_to_pfnandpfn_to_mfnoutside of xc_domain_{save,restore}.c. Where are the defined and used outside of those?
mfn_to_pfnit turns out isn't.pfn_to_mfnis used once inxc_domain.c.
Ah, I grepped for mfn_to_pfn twice so never for pfn_to_mfn...
tools/libxc/xc_offline_page.c uses it too BTW.
I'd be inclined to namespace this existing function (i.e. prefix xc_*) which will stop it clashing with any use you want to make of the more generic name in the new migration code.
Quoted 8 lines
Quoted 2 lines
Likewise for the
*_FIELDstuff which is used in ~2 places outside the save restore code according to grep.
xc_core_x86.cdefines itselfGET_FIELD()so clearly doesn't usexg_save_restore.h
xc_resume.cclearly usesxg_save_restore.hbut could probably be converted to be similar toxc_core_x86.c
Arguably xc_domain_resume could/should be made part of the new migration infratructure anyway.
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
struct
context is meaningless outside of libxc/saverestore.So how are these used there?
Ian.
They are not. They are reimplemented in
common_x86_pv.hso as to not take magic locally scoped variables with specific names.
Either fix the existing ones to suit your tastes or just bite your tongue and use the existing macros, don't add hacks.
Ian.
RFC PATCH v5 6/14 tools/libxc: x86 common code
In reply to Andrew Cooper--- tools/libxc/saverestore/common_x86.c | 54 ++++++++++++++++++++++++++++++++++ tools/libxc/saverestore/common_x86.h | 26 ++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 tools/libxc/saverestore/common_x86.c create mode 100644 tools/libxc/saverestore/common_x86.h
tools/libxc/saverestore/common_x86.c new file +54 -0
@@ -0,0 +1,54 @@ +#include "common_x86.h" + +int write_tsc_info (struct context *ctx) +{ +xc_interface *xch = ctx->xch; +struct rec_tsc_info tsc = {0 }; +struct record rec = + { + .type =REC_TYPE_TSC_INFO , + .length =sizeof (tsc), + .data = &tsc + }; + +if (xc_domain_get_tsc_info (xch, ctx->domid, &tsc.mode, + &tsc.nsec, &tsc.khz, &tsc.incarnation) <0 ) + { +PERROR ("Unable to obtain TSC information" ); +return -1 ; + } + +return write_record (ctx, &rec); +} + +int handle_tsc_info (struct context *ctx,struct record *rec) +{ +xc_interface *xch = ctx->xch; +struct rec_tsc_info *tsc = rec->data; + +if ( rec->length !=sizeof (*tsc) ) + { +ERROR ("TSC_INFO record wrong size: length %" PRIu32", expected %zu" , + rec->length,sizeof (*tsc)); +return -1 ; + } + +if (xc_domain_set_tsc_info (xch, ctx->domid, tsc->mode, + tsc->nsec, tsc->khz, tsc->incarnation) ) + { +PERROR ("Unable to set TSC information" ); +return -1 ; + } + +return 0 ; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
tools/libxc/saverestore/common_x86.h new file +26 -0
@@ -0,0 +1,26 @@ +#ifndef __COMMON_X86__H +#define __COMMON_X86__H + +#include "common.h" + +/* +* Obtains a domains TSC information from Xen and writes a TSC_INFO record +* into the stream. +*/ +int write_tsc_info (struct context *ctx); + +/* +* Parses a TSC_INFO record and applies the result to the domain. +*/ +int handle_tsc_info (struct context *ctx,struct record *rec); + +#endif +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
1.7.10.4
Re: [PATCH v5 RFC 06/14] tools/libxc: x86 common code
Save/restore records common to all x86 domain types (HVM, PV).
This is only the TSC_INFO record.
Ian Campbell
Acked-byRe: [PATCH v5 RFC 06/14] tools/libxc: x86 common code
Quoted 3 lines · David Vrabel
Save/restore records common to all x86 domain types (HVM, PV).
This is only the
TSC_INFOrecord.
With this changelog in place:
RFC PATCH v5 7/14 tools/libxc: x86 PV common code
In reply to Andrew Cooper--- tools/libxc/saverestore/common.h | 5 + tools/libxc/saverestore/common_x86_pv.c | 250 +++++++++++++++++++++++++++++++ tools/libxc/saverestore/common_x86_pv.h | 144 ++++++++++++++++++ 3 files changed, 399 insertions(+) create mode 100644 tools/libxc/saverestore/common_x86_pv.c create mode 100644 tools/libxc/saverestore/common_x86_pv.h
tools/libxc/saverestore/common.h +5 -0
@@ -14,6 +14,10 @@#undef mfn_to_pfn#undef pfn_to_mfn +#undef GET_FIELD +#undef SET_FIELD +#undef MEMCPY_FIELD +#undef MEMSET_ARRAY_FIELD#include "stream_format.h"
@@ -240,6 +244,7 @@ struct context }; }; +extern struct common_ops common_ops_x86_pv;struct record {
tools/libxc/saverestore/common_x86_pv.c new file +250 -0
250 lines not on this page · raw message
tools/libxc/saverestore/common_x86_pv.h new file +144 -0
144 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [PATCH v5 RFC 07/14] tools/libxc: x86 PV common code
Add functions common to save and restore of x86 PV guests. This includes functions for dealing with the P2M and M2P and the VCPU context.
RFC PATCH v5 8/14 tools/libxc: x86 PV save code
In reply to Andrew Cooper--- tools/libxc/saverestore/common.h | 2 + tools/libxc/saverestore/save_x86_pv.c | 839 +++++++++++++++++++++++++++++++++ 2 files changed, 841 insertions(+) create mode 100644 tools/libxc/saverestore/save_x86_pv.c
tools/libxc/saverestore/common.h +2 -0
@@ -246,6 +246,8 @@ struct contextextern struct common_ops common_ops_x86_pv; +extern struct save_ops save_ops_x86_pv; +struct record {uint32_t type;
tools/libxc/saverestore/save_x86_pv.c new file +839 -0
839 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [PATCH v5 RFC 08/14] tools/libxc: x86 PV save code
Save the x86 PV specific parts of a domain. This is the X86_PV_INFO record, the P2M_FRAMES, the X86_PV_SHARED_INFO, the three different VCPU context records, and the MSR records.
The normalise_page callback used by the common code when writing the PAGE_DATA records, converts MFNs in page tables to PFNs.
RFC PATCH v5 9/14 tools/libxc: x86 PV restore code
In reply to Andrew Cooper--- tools/libxc/saverestore/common.h | 2 + tools/libxc/saverestore/restore_x86_pv.c | 965 ++++++++++++++++++++++++++++++ 2 files changed, 967 insertions(+) create mode 100644 tools/libxc/saverestore/restore_x86_pv.c
tools/libxc/saverestore/common.h +2 -0
@@ -248,6 +248,8 @@ extern struct common_ops common_ops_x86_pv;extern struct save_ops save_ops_x86_pv; +extern struct restore_ops restore_ops_x86_pv; +struct record {uint32_t type;
tools/libxc/saverestore/restore_x86_pv.c new file +965 -0
965 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [PATCH v5 RFC 09/14] tools/libxc: x86 PV restore code
Restore the x86 PV specific parts. The X86_PV_INFO, the P2M_FRAMES, SHARED_INFO, and VCPU context records.
The localise_page callback is called from the common PAGE_DATA code to convert PFNs in page tables to MFNs.
Page tables are pinned and the guest's P2M is updated when the stream is complete.
Re: [PATCH v5 RFC 09/14] tools/libxc: x86 PV restore code
In reply to Andrew CooperQuoted 2 lines · Andrew Cooper
tools/libxc/saverestore/restore_x86_pv.c new file +0
-0
...
Quoted 9 lines
tools/libxc/saverestore/restore_x86_pv.c new file +9
-0+static int x86_pv_process_record (struct context *ctx,struct record *rec) +{ +xc_interface *xch = ctx->xch; + +switch ( rec->type ) + { +case REC_TYPE_X86_PV_INFO : +return handle_x86_pv_info (ctx, rec); +
...
Quoted 6 lines
tools/libxc/saverestore/restore_x86_pv.c new file +6
-0+ +case REC_TYPE_X86_PV_VCPU_MSRS : +return handle_x86_pv_vcpu_msrs (ctx, rec); + +default : +if ( rec->type &REC_TYPE_OPTIONAL )
tools/libxc/saverestore/restore_x86_pv.c line 899
Quoted 10 lines
tools/libxc/saverestore/restore_x86_pv.c new file +10
-0+ { +IPRINTF ("Ignoring optional record (0x%" PRIx32", %s)" , + rec->type,rec_type_to_str (rec->type)); +return 0 ; + } + +ERROR ("Invalid record type (0x%" PRIx32", %s) for x86_pv domains" , + rec->type,rec_type_to_str (rec->type)); +return -1 ; + }
I think this default case can be moved to common code. Perhaps return XC_SR_RECORD_UNHANDLED (== 1) to indicate the record wasn't handled.
David
Re: [PATCH v5 RFC 09/14] tools/libxc: x86 PV restore code
Quoted 33 lines · David Vrabel
Quoted 2 lines · Andrew Cooper
tools/libxc/saverestore/restore_x86_pv.c new file +0
-0...
Quoted 9 lines
tools/libxc/saverestore/restore_x86_pv.c new file +9
-0+static int x86_pv_process_record (struct context *ctx,struct record *rec) +{ +xc_interface *xch = ctx->xch; + +switch ( rec->type ) + { +case REC_TYPE_X86_PV_INFO : +return handle_x86_pv_info (ctx, rec); +...
Quoted 6 lines
tools/libxc/saverestore/restore_x86_pv.c new file +6
-0+ +case REC_TYPE_X86_PV_VCPU_MSRS : +return handle_x86_pv_vcpu_msrs (ctx, rec); + +default : +if ( rec->type &REC_TYPE_OPTIONAL )tools/libxc/saverestore/restore_x86_pv.c line 899
Quoted 10 lines
tools/libxc/saverestore/restore_x86_pv.c new file +10
-0+ { +IPRINTF ("Ignoring optional record (0x%" PRIx32", %s)" , + rec->type,rec_type_to_str (rec->type)); +return 0 ; + } + +ERROR ("Invalid record type (0x%" PRIx32", %s) for x86_pv domains" , + rec->type,rec_type_to_str (rec->type)); +return -1 ; + }I think this default case can be moved to common code. Perhaps return
XC_SR_RECORD_UNHANDLED(== 1) to indicate the record wasn't handled.
Quoted 1 line
David
It am looking to not adversely affect any attempt to standardise libxc error reporting in the future, which is why all this code uses 0 or -1, even though errno might or might not be relevant. Even at the moment, there are callbacks into higher level toolstacks which can return any arbitrary error.
~Andrew
Re: [PATCH v5 RFC 09/14] tools/libxc: x86 PV restore code
Quoted 34 lines · Andrew Cooper
Quoted 33 lines · David Vrabel
Quoted 2 lines · Andrew Cooper
tools/libxc/saverestore/restore_x86_pv.c new file +0
-0...
Quoted 9 lines
tools/libxc/saverestore/restore_x86_pv.c new file +9
-0+static int x86_pv_process_record (struct context *ctx,struct record *rec) +{ +xc_interface *xch = ctx->xch; + +switch ( rec->type ) + { +case REC_TYPE_X86_PV_INFO : +return handle_x86_pv_info (ctx, rec); +...
Quoted 6 lines
tools/libxc/saverestore/restore_x86_pv.c new file +6
-0+ +case REC_TYPE_X86_PV_VCPU_MSRS : +return handle_x86_pv_vcpu_msrs (ctx, rec); + +default : +if ( rec->type &REC_TYPE_OPTIONAL )tools/libxc/saverestore/restore_x86_pv.c line 899
Quoted 10 lines
tools/libxc/saverestore/restore_x86_pv.c new file +10
-0+ { +IPRINTF ("Ignoring optional record (0x%" PRIx32", %s)" , + rec->type,rec_type_to_str (rec->type)); +return 0 ; + } + +ERROR ("Invalid record type (0x%" PRIx32", %s) for x86_pv domains" , + rec->type,rec_type_to_str (rec->type)); +return -1 ; + }I think this default case can be moved to common code. Perhaps return
XC_SR_RECORD_UNHANDLED(== 1) to indicate the record wasn't handled.
Quoted 7 lines
Quoted 1 line
David
It am looking to not adversely affect any attempt to standardise libxc error reporting in the future, which is why all this code uses 0 or -1, even though errno might or might not be relevant. Even at the moment, there are callbacks into higher level toolstacks which can return any arbitrary error.
That's fine but what David is suggesting is a sentinel value which is entirely between the common code and the arch hook, both of which you are defining here, it should never escape past that common caller AFAICT.
Wanting to clean things up and not wanting to make that harder is fine, but lets no hobble new code which could legitimately make good use of their return value, AFAICT this is one of those cases.
Ian.
RFC PATCH v5 10/14 tools/libxc: x86 HVM common code
In reply to Andrew Cooper--- tools/libxc/saverestore/common.h | 1 + tools/libxc/saverestore/common_x86_hvm.c | 39 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tools/libxc/saverestore/common_x86_hvm.c
tools/libxc/saverestore/common.h +1 -0
@@ -245,6 +245,7 @@ struct context };extern struct common_ops common_ops_x86_pv; +extern struct common_ops common_ops_x86_hvm;extern struct save_ops save_ops_x86_pv;
tools/libxc/saverestore/common_x86_hvm.c new file +39 -0
@@ -0,0 +1,39 @@ +#include "common.h" + +static bool x86_hvm_pfn_is_valid (const struct context *ctx,xen_pfn_t pfn) +{ +return true; +} + +static xen_pfn_t x86_hvm_pfn_to_gfn (const struct context *ctx,xen_pfn_t pfn) +{ +return pfn; +} + +static void x86_hvm_set_gfn (struct context *ctx,xen_pfn_t pfn, +xen_pfn_t gfn) +{ +/* no op */ +} + +static void x86_hvm_set_page_type (struct context *ctx,xen_pfn_t pfn,xen_pfn_t type) +{ +/* no-op */ +} + +struct common_ops common_ops_x86_hvm = { + .pfn_is_valid = x86_hvm_pfn_is_valid, + .pfn_to_gfn = x86_hvm_pfn_to_gfn, + .set_gfn = x86_hvm_set_gfn, + .set_page_type = x86_hvm_set_page_type, +}; + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
1.7.10.4
Re: [PATCH v5 RFC 10/14] tools/libxc: x86 HVM common code
The callbacks common to x86 HVM save and restore. Since HVM guests do not have a guest-maintained P2M, these are very trivial.
A similar implementation would be suitable for ARM guests.
Ian Campbell
Acked-byRe: [PATCH v5 RFC 10/14] tools/libxc: x86 HVM common code
Quoted 4 lines · David Vrabel
The callbacks common to x86 HVM save and restore. Since HVM guests do not have a guest-maintained P2M, these are very trivial.
A similar implementation would be suitable for ARM guests.
With this commit log in place:
RFC PATCH v5 11/14 tools/libxc: x86 HVM save code
In reply to Andrew Cooper--- tools/libxc/saverestore/common.h | 1 + tools/libxc/saverestore/save_x86_hvm.c | 223 ++++++++++++++++++++++++++++++++ 2 files changed, 224 insertions(+) create mode 100644 tools/libxc/saverestore/save_x86_hvm.c
tools/libxc/saverestore/common.h +1 -0
@@ -248,6 +248,7 @@ extern struct common_ops common_ops_x86_pv;extern struct common_ops common_ops_x86_hvm;extern struct save_ops save_ops_x86_pv; +extern struct save_ops save_ops_x86_hvm;extern struct restore_ops restore_ops_x86_pv;
tools/libxc/saverestore/save_x86_hvm.c new file +223 -0
223 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [PATCH v5 RFC 11/14] tools/libxc: x86 HVM save code
Save the x86 HVM specific parts of the domain. This is considerably simpler than an x86 PV domain. Only the HVM_CONTEXT and HVM_PARAMS records are needed.
There is no need for any page normalisation.
Re: [PATCH v5 RFC 11/14] tools/libxc: x86 HVM save code
In reply to Andrew CooperQuoted 2 lines · Andrew Cooper
tools/libxc/saverestore/save_x86_hvm.c new file +0
-0
...
Quoted 2 lines
tools/libxc/saverestore/save_x86_hvm.c new file +2
-0+static int write_hvm_params (struct context *ctx) +{
...
Quoted 7 lines
tools/libxc/saverestore/save_x86_hvm.c new file +7
-0+ +for ( i =0 ; i <ARRAY_SIZE (params); i++ ) + { +uint32_t index = params[i]; +uint64_t value; + + rc =xc_get_hvm_param (xch, ctx->domid, index, (unsigned long *)&value);
tools/libxc/saverestore/save_x86_hvm.c line 107
Quoted 10 lines
tools/libxc/saverestore/save_x86_hvm.c new file +10
-0+if ( rc ) + { +/* Gross XenServer hack. Consider HVM_PARAM_CONSOLE_PFN failure +* nonfatal. This is related to the fact it is impossible to +* distinguish "no console" from a console at pfn/evtchn 0. +* +* TODO - find a compatible way to fix this. +*/ +if ( index ==HVM_PARAM_CONSOLE_PFN ) +continue ;
Um. Is this really needed with upstream Xen?
David
Re: [PATCH v5 RFC 11/14] tools/libxc: x86 HVM save code
Quoted 26 lines · David Vrabel
Quoted 2 lines · Andrew Cooper
tools/libxc/saverestore/save_x86_hvm.c new file +0
-0...
Quoted 2 lines
tools/libxc/saverestore/save_x86_hvm.c new file +2
-0+static int write_hvm_params (struct context *ctx) +{...
Quoted 7 lines
tools/libxc/saverestore/save_x86_hvm.c new file +7
-0+ +for ( i =0 ; i <ARRAY_SIZE (params); i++ ) + { +uint32_t index = params[i]; +uint64_t value; + + rc =xc_get_hvm_param (xch, ctx->domid, index, (unsigned long *)&value);tools/libxc/saverestore/save_x86_hvm.c line 107
Quoted 10 lines
tools/libxc/saverestore/save_x86_hvm.c new file +10
-0+if ( rc ) + { +/* Gross XenServer hack. Consider HVM_PARAM_CONSOLE_PFN failure +* nonfatal. This is related to the fact it is impossible to +* distinguish "no console" from a console at pfn/evtchn 0. +* +* TODO - find a compatible way to fix this. +*/ +if ( index ==HVM_PARAM_CONSOLE_PFN ) +continue ;Um. Is this really needed with upstream Xen?
Quoted 1 line
David
What is needed with upstream Xen is way of representing "no console". The XenServer way of unconditionally failing the get_param hypercall with -EINVAL is not suitable.
This particular hack however shouldn't have slipped in. It comes as a side effect of testing this series under XenServer.
~Andrew
Re: [PATCH v5 RFC 11/14] tools/libxc: x86 HVM save code
Quoted 27 lines · Andrew Cooper
Quoted 26 lines · David Vrabel
Quoted 2 lines · Andrew Cooper
tools/libxc/saverestore/save_x86_hvm.c new file +0
-0...
Quoted 2 lines
tools/libxc/saverestore/save_x86_hvm.c new file +2
-0+static int write_hvm_params (struct context *ctx) +{...
Quoted 7 lines
tools/libxc/saverestore/save_x86_hvm.c new file +7
-0+ +for ( i =0 ; i <ARRAY_SIZE (params); i++ ) + { +uint32_t index = params[i]; +uint64_t value; + + rc =xc_get_hvm_param (xch, ctx->domid, index, (unsigned long *)&value);tools/libxc/saverestore/save_x86_hvm.c line 107
Quoted 10 lines
tools/libxc/saverestore/save_x86_hvm.c new file +10
-0+if ( rc ) + { +/* Gross XenServer hack. Consider HVM_PARAM_CONSOLE_PFN failure +* nonfatal. This is related to the fact it is impossible to +* distinguish "no console" from a console at pfn/evtchn 0. +* +* TODO - find a compatible way to fix this. +*/ +if ( index ==HVM_PARAM_CONSOLE_PFN ) +continue ;Um. Is this really needed with upstream Xen?
Quoted 3 lines
Quoted 1 line
David
What is needed with upstream Xen is way of representing "no console".
When and how does this situation arise?
AFAICT with upstream Xen there is always a console in the special pfn area.
Ian.
RFC PATCH v5 12/14 tools/libxc: x86 HVM restore code
In reply to Andrew Cooper--- tools/libxc/saverestore/common.h | 1 + tools/libxc/saverestore/restore_x86_hvm.c | 280 +++++++++++++++++++++++++++++ 2 files changed, 281 insertions(+) create mode 100644 tools/libxc/saverestore/restore_x86_hvm.c
tools/libxc/saverestore/common.h +1 -0
@@ -251,6 +251,7 @@ extern struct save_ops save_ops_x86_pv;extern struct save_ops save_ops_x86_hvm;extern struct restore_ops restore_ops_x86_pv; +extern struct restore_ops restore_ops_x86_hvm;struct record {
tools/libxc/saverestore/restore_x86_hvm.c new file +280 -0
280 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [PATCH v5 RFC 12/14] tools/libxc: x86 HVM restore code
Restore the x86 HVM specific parts of a domain. This is the HVM_CONTEXT and HVM_PARAMS records.
There is no need for any page localisation.
This also includes writing the trailing qemu save record to a file because this is what libxc currently does. This is intended to be moved into libxl proper in the future.
RFC PATCH v5 13/14 tools/libxc: noarch save code
In reply to Andrew Cooper--- tools/libxc/saverestore/save.c | 545 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 544 insertions(+), 1 deletion(-)
tools/libxc/saverestore/save.c +544 -1
@@ -1,11 +1,554 @@ +#include <assert.h> +#include <arpa/inet.h> +#include "common.h" +/* +* Writes an Image header and Domain header into the stream. +*/ +static int write_headers (struct context *ctx,uint16_t guest_type) +{ +xc_interface *xch = ctx->xch; +int32_t xen_version =xc_version (xch, XENVER_version,NULL ); +struct ihdr ihdr = + { + .marker =IHDR_MARKER , + .id =htonl (IHDR_ID ), + .version =htonl (IHDR_VERSION ), + .options =htons (IHDR_OPT_LITTLE_ENDIAN ), + }; +struct dhdr dhdr = + { + .type = guest_type, + .page_shift =XC_PAGE_SHIFT , + .xen_major = (xen_version >>16 ) &0xffff , + .xen_minor = (xen_version) &0xffff , + }; + +if ( xen_version <0 ) + { +PERROR ("Unable to obtain Xen Version" ); +return -1 ; + } + +if (write_exact (ctx->fd, &ihdr,sizeof (ihdr)) ) + { +PERROR ("Unable to write Image Header to stream" ); +return -1 ; + } + +if (write_exact (ctx->fd, &dhdr,sizeof (dhdr)) ) + { +PERROR ("Unable to write Domain Header to stream" ); +return -1 ; + } + +return 0 ; +} + +/* +* Writes an END record into the stream. +*/ +static int write_end_record (struct context *ctx) +{ +struct record end = {REC_TYPE_END ,0 ,NULL }; + +return write_record (ctx, &end); +} + +/* +* Writes a batch of memory as a PAGE_DATA record into the stream. The batch +* is constructed in ctx->save.batch_pfns. +* +* This function: +* - gets the types for each pfn in the batch. +* - for each pfn with real data: +* - maps and attempts to localise the pages. +* - construct and writes a PAGE_DATA record into the stream. +*/ +static int write_batch (struct context *ctx) +{ +xc_interface *xch = ctx->xch; +xen_pfn_t *mfns =NULL , *types =NULL ; +void *guest_mapping =NULL ; +void **guest_data =NULL ; +void **local_pages =NULL ; +int *errors =NULL , rc =-1 ; +unsigned i, p, nr_pages =0 ; +unsigned nr_pfns = ctx->save.nr_batch_pfns; +void *page, *orig_page; +uint64_t *rec_pfns =NULL ; +struct rec_page_data_header hdr = {0 }; +struct record rec = + { + .type =REC_TYPE_PAGE_DATA , + }; + +assert (nr_pfns !=0 ); + +/* Mfns of the batch pfns. */ + mfns =malloc (nr_pfns *sizeof (*mfns)); +/* Types of the batch pfns. */ + types =malloc (nr_pfns *sizeof (*types)); +/* Errors from attempting to map the mfns. */ + errors =malloc (nr_pfns *sizeof (*errors)); +/* Pointers to page data to send. Either mapped mfns or local allocations. */ + guest_data =calloc (nr_pfns,sizeof (*guest_data)); +/* Pointers to locally allocated pages. Need freeing. */ + local_pages =calloc (nr_pfns,sizeof (*local_pages)); + +if ( !mfns || !types || !errors || !guest_data || !local_pages ) + { +ERROR ("Unable to allocate arrays for a batch of %u pages" , + nr_pfns); + goto err; + } + +for ( i =0 ; i < nr_pfns; ++i ) + { + types[i] = mfns[i] = ctx->ops.pfn_to_gfn (ctx, ctx->save.batch_pfns[i]); + +/* Likely a ballooned page. */ +if ( mfns[i] ==INVALID_MFN ) +set_bit (ctx->save.batch_pfns[i], ctx->save.deferred_pages); + } + + rc =xc_get_pfn_type_batch (xch, ctx->domid, nr_pfns, types); +if ( rc ) + { +PERROR ("Failed to get types for pfn batch" ); + goto err; + } + rc =-1 ; + +for ( i =0 ; i < nr_pfns; ++i ) + { +switch ( types[i] ) + { +case XEN_DOMCTL_PFINFO_BROKEN : +case XEN_DOMCTL_PFINFO_XALLOC : +case XEN_DOMCTL_PFINFO_XTAB : +continue ; + } + + mfns[nr_pages++] = mfns[i]; + } + +if ( nr_pages >0 ) + { + guest_mapping =xc_map_foreign_bulk ( + xch, ctx->domid,PROT_READ , mfns, errors, nr_pages); +if ( !guest_mapping ) + { +PERROR ("Failed to map guest pages" ); + goto err; + } + } + +for ( i =0 , p =0 ; i < nr_pfns; ++i ) + { +switch ( types[i] ) + { +case XEN_DOMCTL_PFINFO_BROKEN : +case XEN_DOMCTL_PFINFO_XALLOC : +case XEN_DOMCTL_PFINFO_XTAB : +continue ; + } + +if ( errors[p] ) + { +ERROR ("Mapping of pfn %#lx (mfn %#lx) failed %d" , + ctx->save.batch_pfns[i], mfns[p], errors[p]); + goto err; + } + + orig_page = page = guest_mapping + (p *PAGE_SIZE ); + rc = ctx->save.ops.normalise_page (ctx, types[i], &page); +if ( rc ) + { +if ( rc ==-1 && errno ==EAGAIN ) + { +set_bit (ctx->save.batch_pfns[i], ctx->save.deferred_pages); + types[i] =XEN_DOMCTL_PFINFO_XTAB ; + --nr_pages; + } +else + goto err; + } +else + guest_data[i] = page; + +if ( page != orig_page ) + local_pages[i] = page; + rc =-1 ; + + ++p; + } + + rec_pfns =malloc (nr_pfns *sizeof (*rec_pfns)); +if ( !rec_pfns ) + { +ERROR ("Unable to allocate %zu bytes of memory for page data pfn list" , + nr_pfns *sizeof (*rec_pfns)); + goto err; + } + + hdr.count = nr_pfns; + + rec.length =sizeof (hdr); + rec.length += nr_pfns *sizeof (*rec_pfns); + rec.length += nr_pages *PAGE_SIZE ; + +for ( i =0 ; i < nr_pfns; ++i ) + rec_pfns[i] = ((uint64_t )(types[i]) <<32 ) | ctx->save.batch_pfns[i]; + +if (write_record_header (ctx, &rec) || +write_exact (ctx->fd, &hdr,sizeof (hdr)) || +write_exact (ctx->fd, rec_pfns, nr_pfns *sizeof (*rec_pfns)) ) + { +PERROR ("Failed to write page_type header to stream" ); + goto err; + } + +for ( i =0 ; i < nr_pfns; ++i ) + { +if ( guest_data[i] ) + { +if (write_exact (ctx->fd, guest_data[i],PAGE_SIZE ) ) + { +PERROR ("Failed to write page into stream" ); + goto err; + } + + --nr_pages; + } + } + +/* Sanity check we have sent all the pages we expected to. */ +assert (nr_pages ==0 ); + rc = ctx->save.nr_batch_pfns =0 ; + + err: +free (rec_pfns); +if ( guest_mapping ) +munmap (guest_mapping, nr_pages *PAGE_SIZE ); +for ( i =0 ; local_pages && i < nr_pfns; ++i ) +free (local_pages[i]); +free (local_pages); +free (guest_data); +free (errors); +free (types); +free (mfns); + +return rc; +} + +/* +* Flush a batch of pfns into the stream. +*/ +static int flush_batch (struct context *ctx) +{ +int rc =0 ; + +if ( ctx->save.nr_batch_pfns ==0 ) +return rc; + + rc =write_batch (ctx); + +if ( !rc ) + { +VALGRIND_MAKE_MEM_UNDEFINED (ctx->save.batch_pfns, +MAX_BATCH_SIZE *sizeof (*ctx->save.batch_pfns)); + } + +return rc; +} + +/* +* Add a single pfn to the batch, flushing the batch if full. +*/ +static int add_to_batch (struct context *ctx,xen_pfn_t pfn) +{ +int rc =0 ; + +if ( ctx->save.nr_batch_pfns ==MAX_BATCH_SIZE ) + rc =flush_batch (ctx); + +if ( rc ==0 ) + ctx->save.batch_pfns[ctx->save.nr_batch_pfns++] = pfn; + +return rc; +} + +/* +* Pause the domain. +*/ +static int pause_domain (struct context *ctx) +{ +xc_interface *xch = ctx->xch; +int rc; + +if ( !ctx->dominfo.paused ) + { +/* TODO: Properly specify the return value from this callback. */ + rc = (ctx->save.callbacks->suspend (ctx->save.callbacks->data) !=1 ); +if ( rc ) + { +ERROR ("Failed to suspend domain" ); +return rc; + } + } + +IPRINTF ("Domain now paused" ); +return 0 ; +} + +/* +* Send all domain memory. This is the heart of the live migration loop. +*/ +static int send_domain_memory (struct context *ctx) +{ +xc_interface *xch = ctx->xch; + DECLARE_HYPERCALL_BUFFER(unsigned long, to_send); +xc_shadow_op_stats_t stats = {-1 ,-1 }; +unsigned pages_written; +unsigned x, max_iter =5 , dirty_threshold =50 ; +xen_pfn_t p; +int rc =-1 ; + + to_send =xc_hypercall_buffer_alloc_pages ( + xch, to_send,NRPAGES (bitmap_size (ctx->save.p2m_size))); + + ctx->save.batch_pfns =malloc (MAX_BATCH_SIZE *sizeof (*ctx->save.batch_pfns)); + ctx->save.deferred_pages =calloc (1 ,bitmap_size (ctx->save.p2m_size)); + +if ( !ctx->save.batch_pfns || !to_send || !ctx->save.deferred_pages ) + { +ERROR ("Unable to allocate memory for to_{send,fix}/batch bitmaps" ); + goto out; + } + +if (xc_shadow_control (xch, ctx->domid, +XEN_DOMCTL_SHADOW_OP_ENABLE_LOGDIRTY , +NULL ,0 ,NULL ,0 ,NULL ) <0 ) + { +PERROR ("Failed to enable logdirty" ); + goto out; + } + +for ( x =0 , pages_written =0 ; x < max_iter ; ++x ) + { +if ( x ==0 ) + { +/* First iteration, send all pages. */ +memset (to_send,0xff ,bitmap_size (ctx->save.p2m_size)); + } +else + { +/* Else consult the dirty bitmap. */ +if (xc_shadow_control ( + xch, ctx->domid,XEN_DOMCTL_SHADOW_OP_CLEAN , +HYPERCALL_BUFFER (to_send), ctx->save.p2m_size, +NULL ,0 , &stats) != ctx->save.p2m_size ) + { +PERROR ("Failed to retrieve logdirty bitmap" ); + rc =-1 ; + goto out; + } +else +DPRINTF (" Wrote %u pages; stats: faults %" PRIu32", dirty %" PRIu32, + pages_written, stats.fault_count, stats.dirty_count); + pages_written =0 ; + +if ( stats.dirty_count < dirty_threshold ) +break ; + } + +DPRINTF ("Iteration %u" , x); + +for ( p =0 ; p < ctx->save.p2m_size; ++p ) + { +if (test_bit (p, to_send) ) + { + rc =add_to_batch (ctx, p); +if ( rc ) + goto out; + ++pages_written; + } + } + + rc =flush_batch (ctx); +if ( rc ) + goto out; + } + + rc =pause_domain (ctx); +if ( rc ) + goto out; + +if (xc_shadow_control ( + xch, ctx->domid,XEN_DOMCTL_SHADOW_OP_CLEAN , +HYPERCALL_BUFFER (to_send), ctx->save.p2m_size, +NULL ,0 , &stats) != ctx->save.p2m_size ) + { +PERROR ("Failed to retrieve logdirty bitmap" ); + rc =-1 ; + goto out; + } + +for ( p =0 , pages_written =0 ; p < ctx->save.p2m_size; ++p ) + { +if (test_bit (p, to_send) ||test_bit (p, ctx->save.deferred_pages) ) + { + rc =add_to_batch (ctx, p); +if ( rc ) + goto out; + ++pages_written; + } + } + + rc =flush_batch (ctx); +if ( rc ) + goto out; + +DPRINTF (" Wrote %u pages" , pages_written); +IPRINTF ("Sent all pages" ); + + out: +xc_hypercall_buffer_free_pages (xch, to_send, +NRPAGES (bitmap_size (ctx->save.p2m_size))); +free (ctx->save.deferred_pages); +free (ctx->save.batch_pfns); +return rc; +} + +/* +* Save a domain. +*/ +static int save (struct context *ctx,uint16_t guest_type) +{ +xc_interface *xch = ctx->xch; +int rc, saved_rc =0 , saved_errno =0 ; + +IPRINTF ("Saving domain %d, type %s" , + ctx->domid,dhdr_type_to_str (guest_type)); + + rc = ctx->save.ops.setup (ctx); +if ( rc ) + goto err; + + rc =write_headers (ctx, guest_type); +if ( rc ) + goto err; + + rc = ctx->save.ops.start_of_stream (ctx); +if ( rc ) + goto err; + + rc =send_domain_memory (ctx); +if ( rc ) + goto err; + +/* Refresh domain information now it has paused. */ +if ( (xc_domain_getinfo (xch, ctx->domid,1 , &ctx->dominfo) !=1 ) || + (ctx->dominfo.domid != ctx->domid) ) + { +PERROR ("Unable to refresh domain information" ); + rc =-1 ; + goto err; + } +else if ( (!ctx->dominfo.shutdown || + ctx->dominfo.shutdown_reason != SHUTDOWN_suspend ) && + !ctx->dominfo.paused ) + { +ERROR ("Domain has not been suspended" ); + rc =-1 ; + goto err; + } + + rc = ctx->save.ops.end_of_stream (ctx); +if ( rc ) + goto err; + + rc =write_end_record (ctx); +if ( rc ) + goto err; + +xc_shadow_control (xch, ctx->domid,XEN_DOMCTL_SHADOW_OP_OFF , +NULL ,0 ,NULL ,0 ,NULL ); + +IPRINTF ("Save successful" ); + goto done; + + err: + saved_errno = errno; + saved_rc = rc; +PERROR ("Save failed" ); + + done: + rc = ctx->save.ops.cleanup (ctx); +if ( rc ) +PERROR ("Failed to clean up" ); + +if ( saved_rc ) + { + rc = saved_rc; + errno = saved_errno; + } + +return rc; +}; +int xc_domain_save2 (xc_interface *xch,int io_fd,uint32_t dom,uint32_t max_iters,uint32_t max_factor,uint32_t flags,struct save_callbacks * callbacks,int hvm) { +struct context ctx = + { + .xch = xch, + .fd = io_fd, + }; + +/* GCC 4.4 (of CentOS 6.x vintage) can' t initialise anonymous unions :( */ + ctx.save.callbacks = callbacks; +IPRINTF ("In experimental %s" , __func__); -return -1 ; + +if (xc_domain_getinfo (xch, dom,1 , &ctx.dominfo) !=1 ) + { +PERROR ("Failed to get domain info" ); +return -1 ; + } + +if ( ctx.dominfo.domid != dom ) + { +ERROR ("Domain %d does not exist" , dom); +return -1 ; + } + + ctx.domid = dom; +IPRINTF ("Saving domain %d" , dom); + + ctx.save.p2m_size =xc_domain_maximum_gpfn (xch, dom) +1 ; +if ( ctx.save.p2m_size > ~XEN_DOMCTL_PFINFO_LTAB_MASK ) + { + errno =E2BIG ; +ERROR ("Cannot save this big a guest" ); +return -1 ; + } + +if ( ctx.dominfo.hvm ) + { + ctx.ops = common_ops_x86_hvm; + ctx.save.ops = save_ops_x86_hvm; +return save (&ctx,DHDR_TYPE_X86_HVM ); + } +else + { + ctx.ops = common_ops_x86_pv; + ctx.save.ops = save_ops_x86_pv; +return save (&ctx,DHDR_TYPE_X86_PV ); + } }/*
Signature · 1 line
1.7.10.4
Re: [PATCH v5 RFC 13/14] tools/libxc: noarch save code
Save a domain, calling domain type specific function at the appropriate points. This implements the xc_domain_save2() API function which is equivalent to the existing xc_domain_save().
This writes the image and domain headers, and writes all the PAGE_DATA records using a "live" process.
Re: [PATCH v5 RFC 13/14] tools/libxc: noarch save code
Quoted 6 lines · David Vrabel
Save a domain, calling domain type specific function at the appropriate points. This implements the
xc_domain_save2()API function which is equivalent to the existingxc_domain_save().This writes the image and domain headers, and writes all the
PAGE_DATArecords using a "live" process.
It doesn't do "dead" migrate at all?
Ian.
Re: [PATCH v5 RFC 13/14] tools/libxc: noarch save code
Quoted 9 lines · Ian Campbell
Quoted 6 lines · David Vrabel
Save a domain, calling domain type specific function at the appropriate points. This implements the
xc_domain_save2()API function which is equivalent to the existingxc_domain_save().This writes the image and domain headers, and writes all the
PAGE_DATArecords using a "live" process.It doesn't do "dead" migrate at all?
No, but I think it would be trivial to add. Do you think it is necessary?
David
Re: [PATCH v5 RFC 13/14] tools/libxc: noarch save code
Quoted 6 lines · David Vrabel
Quoted 5 lines · Ian Campbell
Quoted 4 lines · David Vrabel
Save a domain, calling domain type specific function at the appropriate points. This implements the
xc_domain_save2()API function which is equivalent to the existingxc_domain_save().
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
This writes the image and domain headers, and writes all the
PAGE_DATArecords using a "live" process.It doesn't do "dead" migrate at all?
No, but I think it would be trivial to add. Do you think it is necessary?
I think so. libxl offers it as an option I there might be occasions when you cared more about migrating ASAP rather than minimising the non-live downtime (e.g. if the h/w was about to catch fire).
Ian.
Re: [PATCH v5 RFC 13/14] tools/libxc: noarch save code
In reply to Andrew CooperQuoted 23 lines · Andrew Cooper
Signed-off-by Andrew Cooper <[email protected]>Signed-off-by Frediano Ziglio <[email protected]>Signed-off-by David Vrabel <[email protected]>--- tools/libxc/saverestore/save.c | 545 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 544 insertions(+), 1 deletion(-)tools/libxc/saverestore/save.c +9
-0@@ -1,11 +1,554 @@ +#include <assert.h> +#include <arpa/inet.h> +#include "common.h" +/* +* Writes an Image header and Domain header into the stream. +*/ +static int write_headers (struct context *ctx,uint16_t guest_type) +{ +xc_interface *xch = ctx->xch;
...snip...
Quoted 163 lines
tools/libxc/saverestore/save.c +163
-0+/* +* Send all domain memory. This is the heart of the live migration loop. +*/ +static int send_domain_memory (struct context *ctx) +{ +xc_interface *xch = ctx->xch; + DECLARE_HYPERCALL_BUFFER(unsigned long, to_send); +xc_shadow_op_stats_t stats = {-1 ,-1 }; +unsigned pages_written; +unsigned x, max_iter =5 , dirty_threshold =50 ; +xen_pfn_t p; +int rc =-1 ; + + to_send =xc_hypercall_buffer_alloc_pages ( + xch, to_send,NRPAGES (bitmap_size (ctx->save.p2m_size))); + + ctx->save.batch_pfns =malloc (MAX_BATCH_SIZE *sizeof (*ctx->save.batch_pfns)); + ctx->save.deferred_pages =calloc (1 ,bitmap_size (ctx->save.p2m_size)); + +if ( !ctx->save.batch_pfns || !to_send || !ctx->save.deferred_pages ) + { +ERROR ("Unable to allocate memory for to_{send,fix}/batch bitmaps" ); + goto out; + } + +if (xc_shadow_control (xch, ctx->domid, +XEN_DOMCTL_SHADOW_OP_ENABLE_LOGDIRTY , +NULL ,0 ,NULL ,0 ,NULL ) <0 ) + { +PERROR ("Failed to enable logdirty" ); + goto out; + } + +for ( x =0 , pages_written =0 ; x < max_iter ; ++x ) + { +if ( x ==0 ) + { +/* First iteration, send all pages. */ +memset (to_send,0xff ,bitmap_size (ctx->save.p2m_size)); + } +else + { +/* Else consult the dirty bitmap. */ +if (xc_shadow_control ( + xch, ctx->domid,XEN_DOMCTL_SHADOW_OP_CLEAN , +HYPERCALL_BUFFER (to_send), ctx->save.p2m_size, +NULL ,0 , &stats) != ctx->save.p2m_size ) + { +PERROR ("Failed to retrieve logdirty bitmap" ); + rc =-1 ; + goto out; + } +else +DPRINTF (" Wrote %u pages; stats: faults %" PRIu32", dirty %" PRIu32, + pages_written, stats.fault_count, stats.dirty_count); + pages_written =0 ; + +if ( stats.dirty_count < dirty_threshold ) +break ; + } + +DPRINTF ("Iteration %u" , x); + +for ( p =0 ; p < ctx->save.p2m_size; ++p ) + { +if (test_bit (p, to_send) ) + { + rc =add_to_batch (ctx, p); +if ( rc ) + goto out; + ++pages_written; + } + } + + rc =flush_batch (ctx); +if ( rc ) + goto out; + } + + rc =pause_domain (ctx); +if ( rc ) + goto out; + +if (xc_shadow_control ( + xch, ctx->domid,XEN_DOMCTL_SHADOW_OP_CLEAN , +HYPERCALL_BUFFER (to_send), ctx->save.p2m_size, +NULL ,0 , &stats) != ctx->save.p2m_size ) + { +PERROR ("Failed to retrieve logdirty bitmap" ); + rc =-1 ; + goto out; + } + +for ( p =0 , pages_written =0 ; p < ctx->save.p2m_size; ++p ) + { +if (test_bit (p, to_send) ||test_bit (p, ctx->save.deferred_pages) ) + { + rc =add_to_batch (ctx, p); +if ( rc ) + goto out; + ++pages_written; + } + } + + rc =flush_batch (ctx); +if ( rc ) + goto out; + +DPRINTF (" Wrote %u pages" , pages_written); +IPRINTF ("Sent all pages" ); + + out: +xc_hypercall_buffer_free_pages (xch, to_send, +NRPAGES (bitmap_size (ctx->save.p2m_size))); +free (ctx->save.deferred_pages); +free (ctx->save.batch_pfns); +return rc; +} + +/* +* Save a domain. +*/ +static int save (struct context *ctx,uint16_t guest_type) +{ +xc_interface *xch = ctx->xch; +int rc, saved_rc =0 , saved_errno =0 ; + +IPRINTF ("Saving domain %d, type %s" , + ctx->domid,dhdr_type_to_str (guest_type)); + + rc = ctx->save.ops.setup (ctx); +if ( rc ) + goto err; + + rc =write_headers (ctx, guest_type); +if ( rc ) + goto err; + + rc = ctx->save.ops.start_of_stream (ctx); +if ( rc ) + goto err; + + rc =send_domain_memory (ctx); +if ( rc ) + goto err; + +/* Refresh domain information now it has paused. */ +if ( (xc_domain_getinfo (xch, ctx->domid,1 , &ctx->dominfo) !=1 ) || + (ctx->dominfo.domid != ctx->domid) ) + { +PERROR ("Unable to refresh domain information" ); + rc =-1 ; + goto err; + } +else if ( (!ctx->dominfo.shutdown || + ctx->dominfo.shutdown_reason != SHUTDOWN_suspend ) && + !ctx->dominfo.paused ) + { +ERROR ("Domain has not been suspended" ); + rc =-1 ; + goto err; + } +
tools/libxc/saverestore/save.c
Quoted 10 lines
tools/libxc/saverestore/save.c +10
-0+ rc = ctx->save.ops.end_of_stream (ctx); +if ( rc ) + goto err; + + rc =write_end_record (ctx); +if ( rc ) + goto err; + +xc_shadow_control (xch, ctx->domid,XEN_DOMCTL_SHADOW_OP_OFF , +NULL ,0 ,NULL ,0 ,NULL );
If migration failed because log-dirty already been enabled or there's err after we enabled log-dirty, we should off shadow op. otherwise we will always fail when migration, so this op should under error path. The following patch fix it.
tools/libxc/saverestore/save.c +3 -3
@@ -474,9 +474,6 @@ static int save(struct context *ctx, uint16_t guest_type)if ( rc ) goto err; -xc_shadow_control (xch, ctx->domid,XEN_DOMCTL_SHADOW_OP_OFF , -NULL ,0 ,NULL ,0 ,NULL ); -IPRINTF ("Save successful" ); goto done;
@@ -490,6 +487,9 @@ static int save(struct context *ctx, uint16_t guest_type)if ( rc )PERROR ("Failed to clean up" ); +xc_shadow_control (xch, ctx->domid,XEN_DOMCTL_SHADOW_OP_OFF , +NULL ,0 ,NULL ,0 ,NULL ); +if ( saved_rc ) { rc = saved_rc;
Quoted 78 lines
tools/libxc/saverestore/save.c +68
-1+ +IPRINTF ("Save successful" ); + goto done; + + err: + saved_errno = errno; + saved_rc = rc; +PERROR ("Save failed" ); + + done: + rc = ctx->save.ops.cleanup (ctx); +if ( rc ) +PERROR ("Failed to clean up" ); + +if ( saved_rc ) + { + rc = saved_rc; + errno = saved_errno; + } + +return rc; +}; +int xc_domain_save2 (xc_interface *xch,int io_fd,uint32_t dom,uint32_t max_iters,uint32_t max_factor,uint32_t flags,struct save_callbacks * callbacks,int hvm) { +struct context ctx = + { + .xch = xch, + .fd = io_fd, + }; + +/* GCC 4.4 (of CentOS 6.x vintage) can' t initialise anonymous unions :( */ + ctx.save.callbacks = callbacks; +IPRINTF ("In experimental %s" , __func__); -return -1 ; + +if (xc_domain_getinfo (xch, dom,1 , &ctx.dominfo) !=1 ) + { +PERROR ("Failed to get domain info" ); +return -1 ; + } + +if ( ctx.dominfo.domid != dom ) + { +ERROR ("Domain %d does not exist" , dom); +return -1 ; + } + + ctx.domid = dom; +IPRINTF ("Saving domain %d" , dom); + + ctx.save.p2m_size =xc_domain_maximum_gpfn (xch, dom) +1 ; +if ( ctx.save.p2m_size > ~XEN_DOMCTL_PFINFO_LTAB_MASK ) + { + errno =E2BIG ; +ERROR ("Cannot save this big a guest" ); +return -1 ; + } + +if ( ctx.dominfo.hvm ) + { + ctx.ops = common_ops_x86_hvm; + ctx.save.ops = save_ops_x86_hvm; +return save (&ctx,DHDR_TYPE_X86_HVM ); + } +else + { + ctx.ops = common_ops_x86_pv; + ctx.save.ops = save_ops_x86_pv; +return save (&ctx,DHDR_TYPE_X86_PV ); + } }/*
Signature · 2 lines
Thanks, Yang.
Re: [PATCH v5 RFC 13/14] tools/libxc: noarch save code
Quoted 196 lines · Hongyang Yang
Quoted 23 lines · Andrew Cooper
Signed-off-by Andrew Cooper <[email protected]>Signed-off-by Frediano Ziglio <[email protected]>Signed-off-by David Vrabel <[email protected]>--- tools/libxc/saverestore/save.c | 545 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 544 insertions(+), 1 deletion(-)tools/libxc/saverestore/save.c +9
-0@@ -1,11 +1,554 @@ +#include <assert.h> +#include <arpa/inet.h> +#include "common.h" +/* +* Writes an Image header and Domain header into the stream. +*/ +static int write_headers (struct context *ctx,uint16_t guest_type) +{ +xc_interface *xch = ctx->xch;...snip...
Quoted 171 lines
tools/libxc/saverestore/save.c +17
-0+/* +* Send all domain memory. This is the heart of the live migration loop. +*/ +static int send_domain_memory (struct context *ctx) +{ +xc_interface *xch = ctx->xch; + DECLARE_HYPERCALL_BUFFER(unsigned long, to_send); +xc_shadow_op_stats_t stats = {-1 ,-1 }; +unsigned pages_written; +unsigned x, max_iter =5 , dirty_threshold =50 ; +xen_pfn_t p; +int rc =-1 ; + + to_send =xc_hypercall_buffer_alloc_pages ( + xch, to_send,NRPAGES (bitmap_size (ctx->save.p2m_size))); + + ctx->save.batch_pfns = malloc(MAX_BATCH_SIZE *
sizeof(*ctx->save.batch_pfns));tools/libxc/saverestore/save.c +37
-0+ ctx->save.deferred_pages = calloc(1, bitmap_size(ctx->save.p2m_size)); + + if ( !ctx->save.batch_pfns || !to_send || !ctx->save.deferred_pages ) + { + ERROR("Unable to allocate memory for to_{send,fix}/batch bitmaps"); + goto out; + } + + if ( xc_shadow_control(xch, ctx->domid, + XEN_DOMCTL_SHADOW_OP_ENABLE_LOGDIRTY, + NULL, 0, NULL, 0, NULL) < 0 ) + { + PERROR("Failed to enable logdirty"); + goto out; + } + + for ( x = 0, pages_written = 0; x < max_iter ; ++x ) + { + if ( x == 0 ) + { + /* First iteration, send all pages. */ + memset(to_send, 0xff, bitmap_size(ctx->save.p2m_size)); + } + else + { + /* Else consult the dirty bitmap. */ + if ( xc_shadow_control( + xch, ctx->domid, XEN_DOMCTL_SHADOW_OP_CLEAN, + HYPERCALL_BUFFER(to_send), ctx->save.p2m_size, + NULL, 0, &stats) != ctx->save.p2m_size ) + { + PERROR("Failed to retrieve logdirty bitmap"); + rc = -1; + goto out; + } + else + DPRINTF(" Wrote %u pages; stats: faults %"PRIu32", dirty%"PRIu32,
tools/libxc/saverestore/save.c +115
-0+ pages_written, stats.fault_count, stats.dirty_count); + pages_written =0 ; + +if ( stats.dirty_count < dirty_threshold ) +break ; + } + +DPRINTF ("Iteration %u" , x); + +for ( p =0 ; p < ctx->save.p2m_size; ++p ) + { +if (test_bit (p, to_send) ) + { + rc =add_to_batch (ctx, p); +if ( rc ) + goto out; + ++pages_written; + } + } + + rc =flush_batch (ctx); +if ( rc ) + goto out; + } + + rc =pause_domain (ctx); +if ( rc ) + goto out; + +if (xc_shadow_control ( + xch, ctx->domid,XEN_DOMCTL_SHADOW_OP_CLEAN , +HYPERCALL_BUFFER (to_send), ctx->save.p2m_size, +NULL ,0 , &stats) != ctx->save.p2m_size ) + { +PERROR ("Failed to retrieve logdirty bitmap" ); + rc =-1 ; + goto out; + } + +for ( p =0 , pages_written =0 ; p < ctx->save.p2m_size; ++p ) + { +if (test_bit (p, to_send) ||test_bit (p, ctx->save.deferred_pages) ) + { + rc =add_to_batch (ctx, p); +if ( rc ) + goto out; + ++pages_written; + } + } + + rc =flush_batch (ctx); +if ( rc ) + goto out; + +DPRINTF (" Wrote %u pages" , pages_written); +IPRINTF ("Sent all pages" ); + + out: +xc_hypercall_buffer_free_pages (xch, to_send, +NRPAGES (bitmap_size (ctx->save.p2m_size))); +free (ctx->save.deferred_pages); +free (ctx->save.batch_pfns); +return rc; +} + +/* +* Save a domain. +*/ +static int save (struct context *ctx,uint16_t guest_type) +{ +xc_interface *xch = ctx->xch; +int rc, saved_rc =0 , saved_errno =0 ; + +IPRINTF ("Saving domain %d, type %s" , + ctx->domid,dhdr_type_to_str (guest_type)); + + rc = ctx->save.ops.setup (ctx); +if ( rc ) + goto err; + + rc =write_headers (ctx, guest_type); +if ( rc ) + goto err; + + rc = ctx->save.ops.start_of_stream (ctx); +if ( rc ) + goto err; + + rc =send_domain_memory (ctx); +if ( rc ) + goto err; + +/* Refresh domain information now it has paused. */ +if ( (xc_domain_getinfo (xch, ctx->domid,1 , &ctx->dominfo) !=1 ) || + (ctx->dominfo.domid != ctx->domid) ) + { +PERROR ("Unable to refresh domain information" ); + rc =-1 ; + goto err; + } +else if ( (!ctx->dominfo.shutdown || + ctx->dominfo.shutdown_reason != SHUTDOWN_suspend ) && + !ctx->dominfo.paused ) + { +ERROR ("Domain has not been suspended" ); + rc =-1 ; + goto err; + } + + rc = ctx->save.ops.end_of_stream (ctx); +if ( rc ) + goto err; + + rc =write_end_record (ctx); +if ( rc )
Quoted 8 lines
tools/libxc/saverestore/save.c static int save(struct context *ctx, uint16_t guest_type) · line 491
Quoted 4 lines
tools/libxc/saverestore/save.c +4
-0+ goto err; + +xc_shadow_control (xch, ctx->domid,XEN_DOMCTL_SHADOW_OP_OFF , +NULL ,0 ,NULL ,0 ,NULL );If migration failed because log-dirty already been enabled or there's err after we enabled log-dirty, we should off shadow op. otherwise we will always fail when migration, so this op should under error path. The following patch fix it.
Or there's another solution, just like the old migration, try to re-enable log dirty if enable log dirty failed.
Quoted 107 lines
tools/libxc/saverestore/save.c +3
-3@@ -474,9 +474,6 @@ static int save(struct context *ctx, uint16_t guest_type)if ( rc ) goto err; -xc_shadow_control (xch, ctx->domid,XEN_DOMCTL_SHADOW_OP_OFF , -NULL ,0 ,NULL ,0 ,NULL ); -IPRINTF ("Save successful" ); goto done;@@ -490,6 +487,9 @@ static int save(struct context *ctx, uint16_t guest_type)if ( rc )PERROR ("Failed to clean up" ); +xc_shadow_control (xch, ctx->domid,XEN_DOMCTL_SHADOW_OP_OFF , +NULL ,0 ,NULL ,0 ,NULL ); +if ( saved_rc ) { rc = saved_rc;Quoted 81 lines
tools/libxc/saverestore/save.c +23
-0+ +IPRINTF ("Save successful" ); + goto done; + + err: + saved_errno = errno; + saved_rc = rc; +PERROR ("Save failed" ); + + done: + rc = ctx->save.ops.cleanup (ctx); +if ( rc ) +PERROR ("Failed to clean up" ); + +if ( saved_rc ) + { + rc = saved_rc; + errno = saved_errno; + } + +return rc; +}; + int xc_domain_save2(xc_interface *xch, int io_fd, uint32_t dom, uint32_t
max_iters,
uint32_tmax_factor,uint32_tflags, struct save_callbacks* callbacks, int hvm)
{tools/libxc/saverestore/save.c +45
-1+struct context ctx = + { + .xch = xch, + .fd = io_fd, + }; + +/* GCC 4.4 (of CentOS 6.x vintage) can' t initialise anonymous unions :( */ + ctx.save.callbacks = callbacks; +IPRINTF ("In experimental %s" , __func__); -return -1 ; + +if (xc_domain_getinfo (xch, dom,1 , &ctx.dominfo) !=1 ) + { +PERROR ("Failed to get domain info" ); +return -1 ; + } + +if ( ctx.dominfo.domid != dom ) + { +ERROR ("Domain %d does not exist" , dom); +return -1 ; + } + + ctx.domid = dom; +IPRINTF ("Saving domain %d" , dom); + + ctx.save.p2m_size =xc_domain_maximum_gpfn (xch, dom) +1 ; +if ( ctx.save.p2m_size > ~XEN_DOMCTL_PFINFO_LTAB_MASK ) + { + errno =E2BIG ; +ERROR ("Cannot save this big a guest" ); +return -1 ; + } + +if ( ctx.dominfo.hvm ) + { + ctx.ops = common_ops_x86_hvm; + ctx.save.ops = save_ops_x86_hvm; +return save (&ctx,DHDR_TYPE_X86_HVM ); + } +else + { + ctx.ops = common_ops_x86_pv; + ctx.save.ops = save_ops_x86_pv; +return save (&ctx,DHDR_TYPE_X86_PV ); + } }/*
Signature · 2 lines
Thanks, Yang.
Re: [PATCH v5 RFC 13/14] tools/libxc: noarch save code
In reply to Andrew CooperAt 06/12/2014 02:14 AM, Andrew Cooper Wrote:
Quoted 100 lines
Signed-off-by Andrew Cooper <[email protected]>Signed-off-by Frediano Ziglio <[email protected]>Signed-off-by David Vrabel <[email protected]>--- tools/libxc/saverestore/save.c | 545 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 544 insertions(+), 1 deletion(-)tools/libxc/saverestore/save.c +86
-0@@ -1,11 +1,554 @@ +#include <assert.h> +#include <arpa/inet.h> +#include "common.h" +/* +* Writes an Image header and Domain header into the stream. +*/ +static int write_headers (struct context *ctx,uint16_t guest_type) +{ +xc_interface *xch = ctx->xch; +int32_t xen_version =xc_version (xch, XENVER_version,NULL ); +struct ihdr ihdr = + { + .marker =IHDR_MARKER , + .id =htonl (IHDR_ID ), + .version =htonl (IHDR_VERSION ), + .options =htons (IHDR_OPT_LITTLE_ENDIAN ), + }; +struct dhdr dhdr = + { + .type = guest_type, + .page_shift =XC_PAGE_SHIFT , + .xen_major = (xen_version >>16 ) &0xffff , + .xen_minor = (xen_version) &0xffff , + }; + +if ( xen_version <0 ) + { +PERROR ("Unable to obtain Xen Version" ); +return -1 ; + } + +if (write_exact (ctx->fd, &ihdr,sizeof (ihdr)) ) + { +PERROR ("Unable to write Image Header to stream" ); +return -1 ; + } + +if (write_exact (ctx->fd, &dhdr,sizeof (dhdr)) ) + { +PERROR ("Unable to write Domain Header to stream" ); +return -1 ; + } + +return 0 ; +} + +/* +* Writes an END record into the stream. +*/ +static int write_end_record (struct context *ctx) +{ +struct record end = {REC_TYPE_END ,0 ,NULL }; + +return write_record (ctx, &end); +} + +/* +* Writes a batch of memory as a PAGE_DATA record into the stream. The batch +* is constructed in ctx->save.batch_pfns. +* +* This function: +* - gets the types for each pfn in the batch. +* - for each pfn with real data: +* - maps and attempts to localise the pages. +* - construct and writes a PAGE_DATA record into the stream. +*/ +static int write_batch (struct context *ctx) +{ +xc_interface *xch = ctx->xch; +xen_pfn_t *mfns =NULL , *types =NULL ; +void *guest_mapping =NULL ; +void **guest_data =NULL ; +void **local_pages =NULL ; +int *errors =NULL , rc =-1 ; +unsigned i, p, nr_pages =0 ; +unsigned nr_pfns = ctx->save.nr_batch_pfns; +void *page, *orig_page; +uint64_t *rec_pfns =NULL ; +struct rec_page_data_header hdr = {0 }; +struct record rec = + { + .type =REC_TYPE_PAGE_DATA , + }; + +assert (nr_pfns !=0 ); +
tools/libxc/saverestore/save.c line 98
Quoted 10 lines
tools/libxc/saverestore/save.c +10
-0+/* Mfns of the batch pfns. */ + mfns =malloc (nr_pfns *sizeof (*mfns)); +/* Types of the batch pfns. */ + types =malloc (nr_pfns *sizeof (*types)); +/* Errors from attempting to map the mfns. */ + errors =malloc (nr_pfns *sizeof (*errors)); +/* Pointers to page data to send. Either mapped mfns or local allocations. */ + guest_data =calloc (nr_pfns,sizeof (*guest_data)); +/* Pointers to locally allocated pages. Need freeing. */ + local_pages =calloc (nr_pfns,sizeof (*local_pages));
This function is called too many times, so we will allocate/free memory again and again. It may affect the performance.
I think we can allocate at setup stage, and only clear guest_data/ local_pages here.
Quoted 37 lines
tools/libxc/saverestore/save.c +37
-0+ +if ( !mfns || !types || !errors || !guest_data || !local_pages ) + { +ERROR ("Unable to allocate arrays for a batch of %u pages" , + nr_pfns); + goto err; + } + +for ( i =0 ; i < nr_pfns; ++i ) + { + types[i] = mfns[i] = ctx->ops.pfn_to_gfn (ctx, ctx->save.batch_pfns[i]); + +/* Likely a ballooned page. */ +if ( mfns[i] ==INVALID_MFN ) +set_bit (ctx->save.batch_pfns[i], ctx->save.deferred_pages); + } + + rc =xc_get_pfn_type_batch (xch, ctx->domid, nr_pfns, types); +if ( rc ) + { +PERROR ("Failed to get types for pfn batch" ); + goto err; + } + rc =-1 ; + +for ( i =0 ; i < nr_pfns; ++i ) + { +switch ( types[i] ) + { +case XEN_DOMCTL_PFINFO_BROKEN : +case XEN_DOMCTL_PFINFO_XALLOC : +case XEN_DOMCTL_PFINFO_XTAB : +continue ; + } + + mfns[nr_pages++] = mfns[i]; + }
tools/libxc/saverestore/save.c line 145
Quoted 10 lines
tools/libxc/saverestore/save.c +10
-0+ +if ( nr_pages >0 ) + { + guest_mapping =xc_map_foreign_bulk ( + xch, ctx->domid,PROT_READ , mfns, errors, nr_pages); +if ( !guest_mapping ) + { +PERROR ("Failed to map guest pages" ); + goto err; + }
To support remus, we will map/unmap guest memory again and again. It also affects the performance. We can cache guest mapping here.
Thanks
Wen Congyang
Quoted 411 lines
tools/libxc/saverestore/save.c +401
-1+ } + +for ( i =0 , p =0 ; i < nr_pfns; ++i ) + { +switch ( types[i] ) + { +case XEN_DOMCTL_PFINFO_BROKEN : +case XEN_DOMCTL_PFINFO_XALLOC : +case XEN_DOMCTL_PFINFO_XTAB : +continue ; + } + +if ( errors[p] ) + { +ERROR ("Mapping of pfn %#lx (mfn %#lx) failed %d" , + ctx->save.batch_pfns[i], mfns[p], errors[p]); + goto err; + } + + orig_page = page = guest_mapping + (p *PAGE_SIZE ); + rc = ctx->save.ops.normalise_page (ctx, types[i], &page); +if ( rc ) + { +if ( rc ==-1 && errno ==EAGAIN ) + { +set_bit (ctx->save.batch_pfns[i], ctx->save.deferred_pages); + types[i] =XEN_DOMCTL_PFINFO_XTAB ; + --nr_pages; + } +else + goto err; + } +else + guest_data[i] = page; + +if ( page != orig_page ) + local_pages[i] = page; + rc =-1 ; + + ++p; + } + + rec_pfns =malloc (nr_pfns *sizeof (*rec_pfns)); +if ( !rec_pfns ) + { +ERROR ("Unable to allocate %zu bytes of memory for page data pfn list" , + nr_pfns *sizeof (*rec_pfns)); + goto err; + } + + hdr.count = nr_pfns; + + rec.length =sizeof (hdr); + rec.length += nr_pfns *sizeof (*rec_pfns); + rec.length += nr_pages *PAGE_SIZE ; + +for ( i =0 ; i < nr_pfns; ++i ) + rec_pfns[i] = ((uint64_t )(types[i]) <<32 ) | ctx->save.batch_pfns[i]; + +if (write_record_header (ctx, &rec) || +write_exact (ctx->fd, &hdr,sizeof (hdr)) || +write_exact (ctx->fd, rec_pfns, nr_pfns *sizeof (*rec_pfns)) ) + { +PERROR ("Failed to write page_type header to stream" ); + goto err; + } + +for ( i =0 ; i < nr_pfns; ++i ) + { +if ( guest_data[i] ) + { +if (write_exact (ctx->fd, guest_data[i],PAGE_SIZE ) ) + { +PERROR ("Failed to write page into stream" ); + goto err; + } + + --nr_pages; + } + } + +/* Sanity check we have sent all the pages we expected to. */ +assert (nr_pages ==0 ); + rc = ctx->save.nr_batch_pfns =0 ; + + err: +free (rec_pfns); +if ( guest_mapping ) +munmap (guest_mapping, nr_pages *PAGE_SIZE ); +for ( i =0 ; local_pages && i < nr_pfns; ++i ) +free (local_pages[i]); +free (local_pages); +free (guest_data); +free (errors); +free (types); +free (mfns); + +return rc; +} + +/* +* Flush a batch of pfns into the stream. +*/ +static int flush_batch (struct context *ctx) +{ +int rc =0 ; + +if ( ctx->save.nr_batch_pfns ==0 ) +return rc; + + rc =write_batch (ctx); + +if ( !rc ) + { +VALGRIND_MAKE_MEM_UNDEFINED (ctx->save.batch_pfns, +MAX_BATCH_SIZE *sizeof (*ctx->save.batch_pfns)); + } + +return rc; +} + +/* +* Add a single pfn to the batch, flushing the batch if full. +*/ +static int add_to_batch (struct context *ctx,xen_pfn_t pfn) +{ +int rc =0 ; + +if ( ctx->save.nr_batch_pfns ==MAX_BATCH_SIZE ) + rc =flush_batch (ctx); + +if ( rc ==0 ) + ctx->save.batch_pfns[ctx->save.nr_batch_pfns++] = pfn; + +return rc; +} + +/* +* Pause the domain. +*/ +static int pause_domain (struct context *ctx) +{ +xc_interface *xch = ctx->xch; +int rc; + +if ( !ctx->dominfo.paused ) + { +/* TODO: Properly specify the return value from this callback. */ + rc = (ctx->save.callbacks->suspend (ctx->save.callbacks->data) !=1 ); +if ( rc ) + { +ERROR ("Failed to suspend domain" ); +return rc; + } + } + +IPRINTF ("Domain now paused" ); +return 0 ; +} + +/* +* Send all domain memory. This is the heart of the live migration loop. +*/ +static int send_domain_memory (struct context *ctx) +{ +xc_interface *xch = ctx->xch; + DECLARE_HYPERCALL_BUFFER(unsigned long, to_send); +xc_shadow_op_stats_t stats = {-1 ,-1 }; +unsigned pages_written; +unsigned x, max_iter =5 , dirty_threshold =50 ; +xen_pfn_t p; +int rc =-1 ; + + to_send =xc_hypercall_buffer_alloc_pages ( + xch, to_send,NRPAGES (bitmap_size (ctx->save.p2m_size))); + + ctx->save.batch_pfns =malloc (MAX_BATCH_SIZE *sizeof (*ctx->save.batch_pfns)); + ctx->save.deferred_pages =calloc (1 ,bitmap_size (ctx->save.p2m_size)); + +if ( !ctx->save.batch_pfns || !to_send || !ctx->save.deferred_pages ) + { +ERROR ("Unable to allocate memory for to_{send,fix}/batch bitmaps" ); + goto out; + } + +if (xc_shadow_control (xch, ctx->domid, +XEN_DOMCTL_SHADOW_OP_ENABLE_LOGDIRTY , +NULL ,0 ,NULL ,0 ,NULL ) <0 ) + { +PERROR ("Failed to enable logdirty" ); + goto out; + } + +for ( x =0 , pages_written =0 ; x < max_iter ; ++x ) + { +if ( x ==0 ) + { +/* First iteration, send all pages. */ +memset (to_send,0xff ,bitmap_size (ctx->save.p2m_size)); + } +else + { +/* Else consult the dirty bitmap. */ +if (xc_shadow_control ( + xch, ctx->domid,XEN_DOMCTL_SHADOW_OP_CLEAN , +HYPERCALL_BUFFER (to_send), ctx->save.p2m_size, +NULL ,0 , &stats) != ctx->save.p2m_size ) + { +PERROR ("Failed to retrieve logdirty bitmap" ); + rc =-1 ; + goto out; + } +else +DPRINTF (" Wrote %u pages; stats: faults %" PRIu32", dirty %" PRIu32, + pages_written, stats.fault_count, stats.dirty_count); + pages_written =0 ; + +if ( stats.dirty_count < dirty_threshold ) +break ; + } + +DPRINTF ("Iteration %u" , x); + +for ( p =0 ; p < ctx->save.p2m_size; ++p ) + { +if (test_bit (p, to_send) ) + { + rc =add_to_batch (ctx, p); +if ( rc ) + goto out; + ++pages_written; + } + } + + rc =flush_batch (ctx); +if ( rc ) + goto out; + } + + rc =pause_domain (ctx); +if ( rc ) + goto out; + +if (xc_shadow_control ( + xch, ctx->domid,XEN_DOMCTL_SHADOW_OP_CLEAN , +HYPERCALL_BUFFER (to_send), ctx->save.p2m_size, +NULL ,0 , &stats) != ctx->save.p2m_size ) + { +PERROR ("Failed to retrieve logdirty bitmap" ); + rc =-1 ; + goto out; + } + +for ( p =0 , pages_written =0 ; p < ctx->save.p2m_size; ++p ) + { +if (test_bit (p, to_send) ||test_bit (p, ctx->save.deferred_pages) ) + { + rc =add_to_batch (ctx, p); +if ( rc ) + goto out; + ++pages_written; + } + } + + rc =flush_batch (ctx); +if ( rc ) + goto out; + +DPRINTF (" Wrote %u pages" , pages_written); +IPRINTF ("Sent all pages" ); + + out: +xc_hypercall_buffer_free_pages (xch, to_send, +NRPAGES (bitmap_size (ctx->save.p2m_size))); +free (ctx->save.deferred_pages); +free (ctx->save.batch_pfns); +return rc; +} + +/* +* Save a domain. +*/ +static int save (struct context *ctx,uint16_t guest_type) +{ +xc_interface *xch = ctx->xch; +int rc, saved_rc =0 , saved_errno =0 ; + +IPRINTF ("Saving domain %d, type %s" , + ctx->domid,dhdr_type_to_str (guest_type)); + + rc = ctx->save.ops.setup (ctx); +if ( rc ) + goto err; + + rc =write_headers (ctx, guest_type); +if ( rc ) + goto err; + + rc = ctx->save.ops.start_of_stream (ctx); +if ( rc ) + goto err; + + rc =send_domain_memory (ctx); +if ( rc ) + goto err; + +/* Refresh domain information now it has paused. */ +if ( (xc_domain_getinfo (xch, ctx->domid,1 , &ctx->dominfo) !=1 ) || + (ctx->dominfo.domid != ctx->domid) ) + { +PERROR ("Unable to refresh domain information" ); + rc =-1 ; + goto err; + } +else if ( (!ctx->dominfo.shutdown || + ctx->dominfo.shutdown_reason != SHUTDOWN_suspend ) && + !ctx->dominfo.paused ) + { +ERROR ("Domain has not been suspended" ); + rc =-1 ; + goto err; + } + + rc = ctx->save.ops.end_of_stream (ctx); +if ( rc ) + goto err; + + rc =write_end_record (ctx); +if ( rc ) + goto err; + +xc_shadow_control (xch, ctx->domid,XEN_DOMCTL_SHADOW_OP_OFF , +NULL ,0 ,NULL ,0 ,NULL ); + +IPRINTF ("Save successful" ); + goto done; + + err: + saved_errno = errno; + saved_rc = rc; +PERROR ("Save failed" ); + + done: + rc = ctx->save.ops.cleanup (ctx); +if ( rc ) +PERROR ("Failed to clean up" ); + +if ( saved_rc ) + { + rc = saved_rc; + errno = saved_errno; + } + +return rc; +}; +int xc_domain_save2 (xc_interface *xch,int io_fd,uint32_t dom,uint32_t max_iters,uint32_t max_factor,uint32_t flags,struct save_callbacks * callbacks,int hvm) { +struct context ctx = + { + .xch = xch, + .fd = io_fd, + }; + +/* GCC 4.4 (of CentOS 6.x vintage) can' t initialise anonymous unions :( */ + ctx.save.callbacks = callbacks; +IPRINTF ("In experimental %s" , __func__); -return -1 ; + +if (xc_domain_getinfo (xch, dom,1 , &ctx.dominfo) !=1 ) + { +PERROR ("Failed to get domain info" ); +return -1 ; + } + +if ( ctx.dominfo.domid != dom ) + { +ERROR ("Domain %d does not exist" , dom); +return -1 ; + } + + ctx.domid = dom; +IPRINTF ("Saving domain %d" , dom); + + ctx.save.p2m_size =xc_domain_maximum_gpfn (xch, dom) +1 ; +if ( ctx.save.p2m_size > ~XEN_DOMCTL_PFINFO_LTAB_MASK ) + { + errno =E2BIG ; +ERROR ("Cannot save this big a guest" ); +return -1 ; + } + +if ( ctx.dominfo.hvm ) + { + ctx.ops = common_ops_x86_hvm; + ctx.save.ops = save_ops_x86_hvm; +return save (&ctx,DHDR_TYPE_X86_HVM ); + } +else + { + ctx.ops = common_ops_x86_pv; + ctx.save.ops = save_ops_x86_pv; +return save (&ctx,DHDR_TYPE_X86_PV ); + } }/*
Re: [PATCH v5 RFC 13/14] tools/libxc: noarch save code
Quoted 114 lines · Wen Congyang
At 06/12/2014 02:14 AM, Andrew Cooper Wrote:
Quoted 100 lines
Signed-off-by Andrew Cooper <[email protected]>Signed-off-by Frediano Ziglio <[email protected]>Signed-off-by David Vrabel <[email protected]>--- tools/libxc/saverestore/save.c | 545 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 544 insertions(+), 1 deletion(-)tools/libxc/saverestore/save.c +86
-0@@ -1,11 +1,554 @@ +#include <assert.h> +#include <arpa/inet.h> +#include "common.h" +/* +* Writes an Image header and Domain header into the stream. +*/ +static int write_headers (struct context *ctx,uint16_t guest_type) +{ +xc_interface *xch = ctx->xch; +int32_t xen_version =xc_version (xch, XENVER_version,NULL ); +struct ihdr ihdr = + { + .marker =IHDR_MARKER , + .id =htonl (IHDR_ID ), + .version =htonl (IHDR_VERSION ), + .options =htons (IHDR_OPT_LITTLE_ENDIAN ), + }; +struct dhdr dhdr = + { + .type = guest_type, + .page_shift =XC_PAGE_SHIFT , + .xen_major = (xen_version >>16 ) &0xffff , + .xen_minor = (xen_version) &0xffff , + }; + +if ( xen_version <0 ) + { +PERROR ("Unable to obtain Xen Version" ); +return -1 ; + } + +if (write_exact (ctx->fd, &ihdr,sizeof (ihdr)) ) + { +PERROR ("Unable to write Image Header to stream" ); +return -1 ; + } + +if (write_exact (ctx->fd, &dhdr,sizeof (dhdr)) ) + { +PERROR ("Unable to write Domain Header to stream" ); +return -1 ; + } + +return 0 ; +} + +/* +* Writes an END record into the stream. +*/ +static int write_end_record (struct context *ctx) +{ +struct record end = {REC_TYPE_END ,0 ,NULL }; + +return write_record (ctx, &end); +} + +/* +* Writes a batch of memory as a PAGE_DATA record into the stream. The batch +* is constructed in ctx->save.batch_pfns. +* +* This function: +* - gets the types for each pfn in the batch. +* - for each pfn with real data: +* - maps and attempts to localise the pages. +* - construct and writes a PAGE_DATA record into the stream. +*/ +static int write_batch (struct context *ctx) +{ +xc_interface *xch = ctx->xch; +xen_pfn_t *mfns =NULL , *types =NULL ; +void *guest_mapping =NULL ; +void **guest_data =NULL ; +void **local_pages =NULL ; +int *errors =NULL , rc =-1 ; +unsigned i, p, nr_pages =0 ; +unsigned nr_pfns = ctx->save.nr_batch_pfns; +void *page, *orig_page; +uint64_t *rec_pfns =NULL ; +struct rec_page_data_header hdr = {0 }; +struct record rec = + { + .type =REC_TYPE_PAGE_DATA , + }; + +assert (nr_pfns !=0 ); +tools/libxc/saverestore/save.c line 98
Quoted 10 lines
tools/libxc/saverestore/save.c +10
-0+/* Mfns of the batch pfns. */ + mfns =malloc (nr_pfns *sizeof (*mfns)); +/* Types of the batch pfns. */ + types =malloc (nr_pfns *sizeof (*types)); +/* Errors from attempting to map the mfns. */ + errors =malloc (nr_pfns *sizeof (*errors)); +/* Pointers to page data to send. Either mapped mfns or local allocations. */ + guest_data =calloc (nr_pfns,sizeof (*guest_data)); +/* Pointers to locally allocated pages. Need freeing. */ + local_pages =calloc (nr_pfns,sizeof (*local_pages));This function is called too many times, so we will allocate/free memory again and again. It may affect the performance.
Quoted 2 lines
I think we can allocate at setup stage, and only clear guest_data/
local_pageshere.
We likely can. It is currently like this because it allowed valgrind to do a fantastic job of spotting errors when flushing an incomplete batch at the end of each iteration.
It should be possible to consolidate the allocations and use valgrind client requests to achieve the same effect, although at this point my effort is far more focused to getting something which works correctly ready in the 4.5 timeframe.
Quoted 51 lines
Quoted 38 lines
tools/libxc/saverestore/save.c +37
-0+ +if ( !mfns || !types || !errors || !guest_data || !local_pages ) + { +ERROR ("Unable to allocate arrays for a batch of %u pages" , + nr_pfns); + goto err; + } + +for ( i =0 ; i < nr_pfns; ++i ) + { + types[i] = mfns[i] = ctx->ops.pfn_to_gfn (ctx, ctx->save.batch_pfns[i]); + +/* Likely a ballooned page. */ +if ( mfns[i] ==INVALID_MFN ) +set_bit (ctx->save.batch_pfns[i], ctx->save.deferred_pages); + } + + rc =xc_get_pfn_type_batch (xch, ctx->domid, nr_pfns, types); +if ( rc ) + { +PERROR ("Failed to get types for pfn batch" ); + goto err; + } + rc =-1 ; + +for ( i =0 ; i < nr_pfns; ++i ) + { +switch ( types[i] ) + { +case XEN_DOMCTL_PFINFO_BROKEN : +case XEN_DOMCTL_PFINFO_XALLOC : +case XEN_DOMCTL_PFINFO_XTAB : +continue ; + } + + mfns[nr_pages++] = mfns[i]; + }tools/libxc/saverestore/save.c line 145
Quoted 10 lines
tools/libxc/saverestore/save.c +10
-0+ +if ( nr_pages >0 ) + { + guest_mapping =xc_map_foreign_bulk ( + xch, ctx->domid,PROT_READ , mfns, errors, nr_pages); +if ( !guest_mapping ) + { +PERROR ("Failed to map guest pages" ); + goto err; + }To support remus, we will map/unmap guest memory again and again. It also affects the performance. We can cache guest mapping here.
Quoted 4 lines
Thanks
Wen Congyang
I am not aware of the current code caching mappings into the guest. 64bit toolstacks would be fine setting up mappings for every gfn and reusing the mappings, but this really won't work for 32bit toolstacks.
What remus does appear to do is have a limited cache of previously-written pages for XOR+RLE compression.
~Andrew
Re: [PATCH v5 RFC 13/14] tools/libxc: noarch save code
Quoted 8 lines · Andrew Cooper
Quoted 6 lines · Wen Congyang
At 06/12/2014 02:14 AM, Andrew Cooper Wrote:
Quoted 5 lines
Signed-off-by Andrew Cooper <[email protected]>Signed-off-by Frediano Ziglio <[email protected]>Signed-off-by David Vrabel <[email protected]>--- tools/libxc/saverestore/save.c | 545
+++++++++++++++++++++++++++++++++++++++-
Quoted 3 lines
Quoted 3 lines
Review
Quoted 3 lines
1 file changed, 544 insertions(+), 1 deletion(-)(quoted diff) +0
-0
b/tools/libxc/saverestore/save.c
Quoted 56 lines
Quoted 56 lines
Quoted 56 lines
index f6ad734..9ad43a5 100644
tools/libxc/saverestore/save.c +50
-0@@ -1,11 +1,554 @@ +#include <assert.h> +#include <arpa/inet.h> +#include "common.h" +/* +* Writes an Image header and Domain header into the stream. +*/ +static int write_headers (struct context *ctx,uint16_t guest_type) +{ +xc_interface *xch = ctx->xch; +int32_t xen_version =xc_version (xch, XENVER_version,NULL ); +struct ihdr ihdr = + { + .marker =IHDR_MARKER , + .id =htonl (IHDR_ID ), + .version =htonl (IHDR_VERSION ), + .options =htons (IHDR_OPT_LITTLE_ENDIAN ), + }; +struct dhdr dhdr = + { + .type = guest_type, + .page_shift =XC_PAGE_SHIFT , + .xen_major = (xen_version >>16 ) &0xffff , + .xen_minor = (xen_version) &0xffff , + }; + +if ( xen_version <0 ) + { +PERROR ("Unable to obtain Xen Version" ); +return -1 ; + } + +if (write_exact (ctx->fd, &ihdr,sizeof (ihdr)) ) + { +PERROR ("Unable to write Image Header to stream" ); +return -1 ; + } + +if (write_exact (ctx->fd, &dhdr,sizeof (dhdr)) ) + { +PERROR ("Unable to write Domain Header to stream" ); +return -1 ; + } + +return 0 ; +} + +/* +* Writes an END record into the stream. +*/ +static int write_end_record (struct context *ctx)
Quoted 8 lines
Quoted 8 lines
tools/libxc/saverestore/save.c
Quoted 8 lines
tools/libxc/saverestore/save.c +8
-0+{ +struct record end = {REC_TYPE_END ,0 ,NULL }; + +return write_record (ctx, &end); +} + +/* +* Writes a batch of memory as a PAGE_DATA record into the stream.
The batch
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
tools/libxc/saverestore/save.c +27
-0+* is constructed in ctx->save.batch_pfns. +* +* This function: +* - gets the types for each pfn in the batch. +* - for each pfn with real data: +* - maps and attempts to localise the pages. +* - construct and writes a PAGE_DATA record into the stream. +*/ +static int write_batch (struct context *ctx) +{ +xc_interface *xch = ctx->xch; +xen_pfn_t *mfns =NULL , *types =NULL ; +void *guest_mapping =NULL ; +void **guest_data =NULL ; +void **local_pages =NULL ; +int *errors =NULL , rc =-1 ; +unsigned i, p, nr_pages =0 ; +unsigned nr_pfns = ctx->save.nr_batch_pfns; +void *page, *orig_page; +uint64_t *rec_pfns =NULL ; +struct rec_page_data_header hdr = {0 }; +struct record rec = + { + .type =REC_TYPE_PAGE_DATA , + }; + +assert (nr_pfns !=0 );
Quoted 8 lines
Quoted 8 lines
tools/libxc/saverestore/save.c
Quoted 8 lines
tools/libxc/saverestore/save.c +8
-0+ +/* Mfns of the batch pfns. */ + mfns =malloc (nr_pfns *sizeof (*mfns)); +/* Types of the batch pfns. */ + types =malloc (nr_pfns *sizeof (*types)); +/* Errors from attempting to map the mfns. */ + errors =malloc (nr_pfns *sizeof (*errors)); +/* Pointers to page data to send. Either mapped mfns or local
allocations. */
Quoted 19 lines
Quoted 8 lines
tools/libxc/saverestore/save.c line 98
Quoted 3 lines
tools/libxc/saverestore/save.c +3
-0+ guest_data =calloc (nr_pfns,sizeof (*guest_data)); +/* Pointers to locally allocated pages. Need freeing. */ + local_pages =calloc (nr_pfns,sizeof (*local_pages));This function is called too many times, so we will allocate/free memory again and again. It may affect the performance.
I think we can allocate at setup stage, and only clear guest_data/
local_pageshere.We likely can. It is currently like this because it allowed valgrind to do a fantastic job of spotting errors when flushing an incomplete batch at the end of each iteration.
It should be possible to consolidate the allocations and use valgrind client requests to achieve the same effect, although at this point my effort is far more focused to getting something which works correctly ready in the 4.5 timeframe.
Quoted 1 line
Quoted 11 lines
Quoted 11 lines
tools/libxc/saverestore/save.c
Quoted 11 lines
tools/libxc/saverestore/save.c +11
-0+ +if ( !mfns || !types || !errors || !guest_data || !local_pages ) + { +ERROR ("Unable to allocate arrays for a batch of %u pages" , + nr_pfns); + goto err; + } + +for ( i =0 ; i < nr_pfns; ++i ) + { + types[i] = mfns[i] = ctx->ops.pfn_to_gfn(ctx,
ctx->save.batch_pfns[i]);
Quoted 4 lines
Quoted 4 lines
tools/libxc/saverestore/save.c
Quoted 4 lines
tools/libxc/saverestore/save.c +4
-0+ +/* Likely a ballooned page. */ +if ( mfns[i] ==INVALID_MFN ) + set_bit(ctx->save.batch_pfns[i],
ctx->save.deferred_pages);
Quoted 40 lines
Quoted 35 lines
Quoted 22 lines
tools/libxc/saverestore/save.c +22
-0+ } + + rc =xc_get_pfn_type_batch (xch, ctx->domid, nr_pfns, types); +if ( rc ) + { +PERROR ("Failed to get types for pfn batch" ); + goto err; + } + rc =-1 ; + +for ( i =0 ; i < nr_pfns; ++i ) + { +switch ( types[i] ) + { +case XEN_DOMCTL_PFINFO_BROKEN : +case XEN_DOMCTL_PFINFO_XALLOC : +case XEN_DOMCTL_PFINFO_XTAB : +continue ; + } + + mfns[nr_pages++] = mfns[i]; + }tools/libxc/saverestore/save.c line 145
Quoted 10 lines
tools/libxc/saverestore/save.c +10
-0+ +if ( nr_pages >0 ) + { + guest_mapping =xc_map_foreign_bulk ( + xch, ctx->domid,PROT_READ , mfns, errors, nr_pages); +if ( !guest_mapping ) + { +PERROR ("Failed to map guest pages" ); + goto err; + }To support remus, we will map/unmap guest memory again and again. It also affects the performance. We can cache guest mapping here.
Quoted 4 lines
Thanks
Wen Congyang
Quoted 7 lines
I am not aware of the current code caching mappings into the guest. 64bit toolstacks would be fine setting up mappings for every gfn and reusing the mappings, but this really won't work for 32bit toolstacks.
What remus does appear to do is have a limited cache of previously-written pages for XOR+RLE compression.
I think Wen is referring to the 'mapping/unmapping' in batches of 4MB. This slows down the time to checkpoint by 2X generally and tends to get worse as the guest's memory size increases beyond 1GB.
What we used to do earlier (not in mainline libxc code), is to map the entire domain memory into libxc before the infinite loop. This, as you said has some restrictions, but halves the checkpointing time (ie halves the time for which a guest execution is suspended).
Shriram
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
RFC PATCH v5 14/14 tools/libxc: noarch restore code
In reply to Andrew Cooper--- tools/libxc/saverestore/common.h | 6 + tools/libxc/saverestore/restore.c | 556 ++++++++++++++++++++++++++++++++++++- 2 files changed, 561 insertions(+), 1 deletion(-)
tools/libxc/saverestore/common.h +6 -0
@@ -292,6 +292,12 @@ static inline int write_record(struct context *ctx, struct record *rec) return write_split_record(ctx, rec, NULL, 0); } +/* TODO - find a better way of hiding this. It should be private to +* restore.c, but is needed by x86_pv_localise_page() +*/ +int populate_pfns (struct context *ctx,unsigned count, +const xen_pfn_t *original_pfns,const uint32_t *types); +#endif /* * Local variables:
tools/libxc/saverestore/restore.c +555 -1
568 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [PATCH v5 RFC 14/14] tools/libxc: noarch restore code
Restore a domain from the new format. This reads and validates the domain and image header and loads the guest memory from the PAGE_DATA records, populating the p2m as it does so.
This provides the xc_domain_restore2() function as an alternative to the existing xc_domain_restore().
Re: [PATCH v5 RFC 14/14] tools/libxc: noarch restore code
In reply to Andrew Coopertools/libxc/saverestore/common.h static inline int write_record(struct context *ctx, struct record *rec) · line 299
Quoted 11 lines · Andrew Cooper
tools/libxc/saverestore/common.h +5
-0@@ -292,6 +292,12 @@ static inline int write_record(struct context *ctx, struct record *rec)return write_split_record (ctx, rec,NULL ,0 ); } +/* TODO - find a better way of hiding this. It should be private to +* restore.c, but is needed by x86_pv_localise_page() +*/ +int populate_pfns (struct context *ctx,unsigned count, +const xen_pfn_t *original_pfns,const uint32_t *types);
I don't see a problem with this being here, if it's needed in those two places.
David
Re: [PATCH v5 RFC 14/14] tools/libxc: noarch restore code
Quoted 15 lines · David Vrabel
tools/libxc/saverestore/common.h static inline int write_record(struct context *ctx, struct record *rec) · line 299
Quoted 11 lines · Andrew Cooper
tools/libxc/saverestore/common.h +5
-0@@ -292,6 +292,12 @@ static inline int write_record(struct context *ctx, struct record *rec)return write_split_record (ctx, rec,NULL ,0 ); } +/* TODO - find a better way of hiding this. It should be private to +* restore.c, but is needed by x86_pv_localise_page() +*/ +int populate_pfns (struct context *ctx,unsigned count, +const xen_pfn_t *original_pfns,const uint32_t *types);I don't see a problem with this being here, if it's needed in those two places.
Quoted 2 lines
David
I was hoping to find a way of making it disappear as it is the one ugly lump in the otherwise clean partitioning of common and arch specific code.
I am however struggling...
~Andrew
Re: [PATCH v5 RFC 14/14] tools/libxc: noarch restore code
In reply to Andrew CooperQuoted 16 lines · Andrew Cooper
Signed-off-by Andrew Cooper <[email protected]>Signed-off-by Frediano Ziglio <[email protected]>Signed-off-by David Vrabel <[email protected]>--- tools/libxc/saverestore/common.h | 6 + tools/libxc/saverestore/restore.c | 556 ++++++++++++++++++++++++++++++++++++- 2 files changed, 561 insertions(+), 1 deletion(-)tools/libxc/saverestore/common.h +0
-0@@ -292,6 +292,12 @@ static inline int write_record(struct context *ctx, struct record *rec)return write_split_record (ctx, rec,NULL ,0 ); }
...snip...
Quoted 76 lines
tools/libxc/saverestore/common.h +76
-0+/* +* Given a list of pfns, their types, and a block of page data from the +* stream, populate and record their types, map the relevent subset and copy +* the data into the guest. +*/ +static int process_page_data (struct context *ctx,unsigned count, +xen_pfn_t *pfns,uint32_t *types,void *page_data) +{ +xc_interface *xch = ctx->xch; +xen_pfn_t *mfns =malloc (count *sizeof (*mfns)); +int *map_errs =malloc (count *sizeof (*map_errs)); +int rc =-1 ; +void *mapping =NULL , *guest_page =NULL ; +unsigned i,/* i indexes the pfns from the record. */ + j,/* j indexes the subset of pfns we decide to map. */ + nr_pages; + +if ( !mfns || !map_errs ) + { +ERROR ("Failed to allocate %zu bytes to process page data" , + count * (sizeof (*mfns) +sizeof (*map_errs))); + goto err; + } + + rc =populate_pfns (ctx, count, pfns, types); +if ( rc ) + { +ERROR ("Failed to populate pfns for batch of %u pages" , count); + goto err; + } + rc =-1 ; + +for ( i =0 , nr_pages =0 ; i < count; ++i ) + { + ctx->ops.set_page_type (ctx, pfns[i], types[i]); + +switch ( types[i] ) + { +case XEN_DOMCTL_PFINFO_NOTAB : + +case XEN_DOMCTL_PFINFO_L1TAB : +case XEN_DOMCTL_PFINFO_L1TAB |XEN_DOMCTL_PFINFO_LPINTAB : + +case XEN_DOMCTL_PFINFO_L2TAB : +case XEN_DOMCTL_PFINFO_L2TAB |XEN_DOMCTL_PFINFO_LPINTAB : + +case XEN_DOMCTL_PFINFO_L3TAB : +case XEN_DOMCTL_PFINFO_L3TAB |XEN_DOMCTL_PFINFO_LPINTAB : + +case XEN_DOMCTL_PFINFO_L4TAB : +case XEN_DOMCTL_PFINFO_L4TAB |XEN_DOMCTL_PFINFO_LPINTAB : + + mfns[nr_pages++] = ctx->ops.pfn_to_gfn (ctx, pfns[i]); +break ; + } + + } + +if ( nr_pages >0 ) + { + mapping = guest_page =xc_map_foreign_bulk ( + xch, ctx->domid,PROT_READ |PROT_WRITE , + mfns, map_errs, nr_pages); +if ( !mapping ) + { +PERROR ("Unable to map %u mfns for %u pages of data" , + nr_pages, count); + goto err; + } + } + +for ( i =0 , j =0 ; i < count; ++i ) + { +switch ( types[i] ) + { +case XEN_DOMCTL_PFINFO_XTAB :
tools/libxc/saverestore/common.h
Quoted 10 lines
tools/libxc/saverestore/common.h +10
-0+case XEN_DOMCTL_PFINFO_BROKEN : +case XEN_DOMCTL_PFINFO_XALLOC : +/* No page data to deal with. */ +continue ; + } + +if ( map_errs[j] ) + { +ERROR ("Mapping pfn %lx (mfn %lx, type %#" PRIx32")failed with %d" , + pfns[i], mfns[j], types[i], map_errs[j]);
missing rc = -1 here, rc could be 0 because in the following called:
rc = ctx->restore.ops.localise_page(ctx, types[i], guest_page);
Quoted 258 lines
tools/libxc/saverestore/common.h +245
-1+ goto err; + } + +memcpy (guest_page, page_data,PAGE_SIZE ); + +/* Undo page normalisation done by the saver. */ + rc = ctx->restore.ops.localise_page (ctx, types[i], guest_page); +if ( rc ) + { +DPRINTF ("Failed to localise" ); + goto err; + } + + ++j; + guest_page +=PAGE_SIZE ; + page_data +=PAGE_SIZE ; + } + + rc =0 ; + + err: +if ( mapping ) +munmap (mapping, nr_pages *PAGE_SIZE ); + +free (map_errs); +free (mfns); + +return rc; +} + +/* +* Validate a PAGE_DATA record from the stream, and pass the results to +* process_page_data() to actually perform the legwork. +*/ +static int handle_page_data (struct context *ctx,struct record *rec) +{ +xc_interface *xch = ctx->xch; +struct rec_page_data_header *pages = rec->data; +unsigned i, pages_of_data =0 ; +int rc =-1 ; + +xen_pfn_t *pfns =NULL , pfn; +uint32_t *types =NULL , type; + +if ( rec->length <sizeof (*pages) ) + { +ERROR ("PAGE_DATA record truncated: length %" PRIu32", min %zu" , + rec->length,sizeof (*pages)); + goto err; + } +else if ( pages->count <1 ) + { +ERROR ("Expected at least 1 pfn in PAGE_DATA record" ); + goto err; + } +else if ( rec->length <sizeof (*pages) + (pages->count *sizeof (uint64_t )) ) + { +ERROR ("PAGE_DATA record (length %" PRIu32") too short to contain %" + PRIu32" pfns worth of information" , rec->length, pages->count); + goto err; + } + + pfns =malloc (pages->count *sizeof (*pfns)); + types =malloc (pages->count *sizeof (*types)); +if ( !pfns || !types ) + { +ERROR ("Unable to allocate enough memory for %" PRIu32" pfns" , + pages->count); + goto err; + } + +for ( i =0 ; i < pages->count; ++i ) + { + pfn = pages->pfn[i] &PAGE_DATA_PFN_MASK ; +if ( !ctx->ops.pfn_is_valid (ctx, pfn) ) + { +ERROR ("pfn %#lx (index %u) outside domain maximum" , pfn, i); + goto err; + } + + type = (pages->pfn[i] &PAGE_DATA_TYPE_MASK ) >>32 ; +if ( ((type >>XEN_DOMCTL_PFINFO_LTAB_SHIFT ) >=5 ) && + ((type >>XEN_DOMCTL_PFINFO_LTAB_SHIFT ) <=8 ) ) + { +ERROR ("Invalid type %#" PRIx32" for pfn %#lx (index %u)" , type, pfn, i); + goto err; + } +else if ( type <XEN_DOMCTL_PFINFO_BROKEN ) +/* NOTAB and all L1 thru L4 tables (including pinned) should have +* a page worth of data in the record. */ + pages_of_data++; + + pfns[i] = pfn; + types[i] = type; + } + +if ( rec->length != (sizeof (*pages) + + (sizeof (uint64_t ) * pages->count) + + (PAGE_SIZE * pages_of_data)) ) + { +ERROR ("PAGE_DATA record wrong size: length %" PRIu32", expected " +"%zu + %zu + %zu" , rec->length,sizeof (*pages), + (sizeof (uint64_t ) * pages->count), (PAGE_SIZE * pages_of_data)); + goto err; + } + + rc =process_page_data (ctx, pages->count, pfns, types, + &pages->pfn[pages->count]); + err: +free (types); +free (pfns); + +return rc; +} + +/* +* Restore a domain. +*/ +static int restore (struct context *ctx) +{ +xc_interface *xch = ctx->xch; +struct record rec; +int rc, saved_rc =0 , saved_errno =0 ; + +IPRINTF ("Restoring domain" ); + + rc = ctx->restore.ops.setup (ctx); +if ( rc ) + goto err; + +do + { + rc =read_record (ctx, &rec); +if ( rc ) + goto err; + +switch ( rec.type ) + { +case REC_TYPE_END : +DPRINTF ("End record" ); +break ; + +case REC_TYPE_PAGE_DATA : + rc =handle_page_data (ctx, &rec); +break ; + +default : + rc = ctx->restore.ops.process_record (ctx, &rec); +break ; + } + +free (rec.data); +if ( rc ) + goto err; + + }while ( rec.type !=REC_TYPE_END ); + + rc = ctx->restore.ops.stream_complete (ctx); +if ( rc ) + goto err; + +IPRINTF ("Restore successful" ); + goto done; + + err: + saved_errno = errno; + saved_rc = rc; +PERROR ("Restore failed" ); + + done: +free (ctx->restore.populated_pfns); + rc = ctx->restore.ops.cleanup (ctx); +if ( rc ) +PERROR ("Failed to clean up" ); + +if ( saved_rc ) + { + rc = saved_rc; + errno = saved_errno; + } + +return rc; +} + int xc_domain_restore2(xc_interface *xch, int io_fd, uint32_t dom, unsigned int store_evtchn, unsigned long *store_mfn, domid_t store_domid, unsigned int console_evtchn,@@ -8,8 +502,68 @@ int xc_domain_restore2(xc_interface *xch, int io_fd, uint32_t dom,int checkpointed_stream, struct restore_callbacks *callbacks) { + struct context ctx = + { + .xch = xch, + .fd = io_fd, + }; + +/* GCC 4.4 (of CentOS 6.x vintage) can' t initialise anonymous unions :( */ + ctx.restore.console_evtchn = console_evtchn; + ctx.restore.console_domid = console_domid; + ctx.restore.xenstore_evtchn = store_evtchn; + ctx.restore.xenstore_domid = store_domid; + ctx.restore.callbacks = callbacks; +IPRINTF ("In experimental %s" , __func__); -return -1 ; + +if (xc_domain_getinfo (xch, dom,1 , &ctx.dominfo) !=1 ) + { +PERROR ("Failed to get domain info" ); +return -1 ; + } + +if ( ctx.dominfo.domid != dom ) + { +ERROR ("Domain %d does not exist" , dom); +return -1 ; + } + + ctx.domid = dom; +IPRINTF ("Restoring domain %d" , dom); + +if (read_headers (&ctx) ) +return -1 ; + +if ( ctx.dominfo.hvm ) + { + ctx.ops = common_ops_x86_hvm; + ctx.restore.ops = restore_ops_x86_hvm; +if (restore (&ctx) ) +return -1 ; + } +else + { + ctx.ops = common_ops_x86_pv; + ctx.restore.ops = restore_ops_x86_pv; +if (restore (&ctx) ) +return -1 ; + } + +DPRINTF ("XenStore: mfn %#lx, dom %d, evt %u" , + ctx.restore.xenstore_mfn, + ctx.restore.xenstore_domid, + ctx.restore.xenstore_evtchn); + +DPRINTF ("Console: mfn %#lx, dom %d, evt %u" , + ctx.restore.console_mfn, + ctx.restore.console_domid, + ctx.restore.console_evtchn); + + *console_mfn = ctx.restore.console_mfn; + *store_mfn = ctx.restore.xenstore_mfn; + +return 0 ; }/*
Signature · 2 lines
Thanks, Yang.
Re: [PATCH v5 RFC 14/14] tools/libxc: noarch restore code
Quoted 112 lines · Hongyang Yang
Quoted 19 lines · Andrew Cooper
Signed-off-by Andrew Cooper <[email protected]>Signed-off-by Frediano Ziglio <[email protected]>Signed-off-by David Vrabel <[email protected]>--- tools/libxc/saverestore/common.h | 6 + tools/libxc/saverestore/restore.c | 556 ++++++++++++++++++++++++++++++++++++- 2 files changed, 561 insertions(+), 1 deletion(-)tools/libxc/saverestore/common.h +0
-0@@ -292,6 +292,12 @@ static inline int write_record(struct context *ctx, struct record *rec)return write_split_record (ctx, rec,NULL ,0 ); }...snip...
Quoted 87 lines
+/*
+ * Given a list of pfns, their types, and a block of page data from the
+ * stream, populate and record their types, map the relevent subset and copy
+ * the data into the guest.
+ */tools/libxc/saverestore/common.h +2
-0+static int process_page_data (struct context *ctx,unsigned count, + xen_pfn_t *pfns, uint32_t *types, void
*page_data)tools/libxc/saverestore/common.h +78
-0+{ + xc_interface *xch = ctx->xch; + xen_pfn_t *mfns = malloc(count * sizeof(*mfns)); + int *map_errs = malloc(count * sizeof(*map_errs)); + int rc = -1; + void *mapping = NULL, *guest_page = NULL; + unsigned i, /* i indexes the pfns from the record. */ + j, /* j indexes the subset of pfns we decide to map. */ + nr_pages; + + if ( !mfns || !map_errs ) + { + ERROR("Failed to allocate %zu bytes to process page data", + count * (sizeof(*mfns) + sizeof(*map_errs))); + goto err; + } + + rc = populate_pfns(ctx, count, pfns, types); + if ( rc ) + { + ERROR("Failed to populate pfns for batch of %u pages", count); + goto err; + } + rc = -1; + + for ( i = 0, nr_pages = 0; i < count; ++i ) + { + ctx->ops.set_page_type(ctx, pfns[i], types[i]); + + switch ( types[i] ) + { + case XEN_DOMCTL_PFINFO_NOTAB: + + case XEN_DOMCTL_PFINFO_L1TAB: + case XEN_DOMCTL_PFINFO_L1TAB | XEN_DOMCTL_PFINFO_LPINTAB: + + case XEN_DOMCTL_PFINFO_L2TAB: + case XEN_DOMCTL_PFINFO_L2TAB | XEN_DOMCTL_PFINFO_LPINTAB: + + case XEN_DOMCTL_PFINFO_L3TAB: + case XEN_DOMCTL_PFINFO_L3TAB | XEN_DOMCTL_PFINFO_LPINTAB: + + case XEN_DOMCTL_PFINFO_L4TAB: + case XEN_DOMCTL_PFINFO_L4TAB | XEN_DOMCTL_PFINFO_LPINTAB: + + mfns[nr_pages++] = ctx->ops.pfn_to_gfn(ctx, pfns[i]); + break; + } + + } + + if ( nr_pages > 0 ) + { + mapping = guest_page = xc_map_foreign_bulk( + xch, ctx->domid, PROT_READ | PROT_WRITE, + mfns, map_errs, nr_pages); + if ( !mapping ) + { + PERROR("Unable to map %u mfns for %u pages of data", + nr_pages, count); + goto err; + } + } + + for ( i = 0, j = 0; i < count; ++i ) + { + switch ( types[i] ) + { + case XEN_DOMCTL_PFINFO_XTAB: + case XEN_DOMCTL_PFINFO_BROKEN: + case XEN_DOMCTL_PFINFO_XALLOC: + /* No page data to deal with. */ + continue; + } + + if ( map_errs[j] ) + { + ERROR("Mapping pfn %lx (mfn %lx, type %#"PRIx32")failedQuoted 2 lines
with %d",
+ pfns[i], mfns[j], types[i], map_errs[j]);missing rc = -1 here, rc could be 0 because in the following called:
Quoted 1 line
rc = ctx->restore.ops.localise_page(ctx, types[i], guest_page);
So it can - well spotted.
~Andrew
Hi, Andrew,
Quoted 23 lines · Andrew Cooper
Hello,
Presented here for review is v5 of the Migration Stream v2 work.
Major work in v5 is the legacy conversion python script which is capable of converting from legacy to v2 format on the fly. It was tested using live migration saving in the legacy format, piping through the script and restoring using the v2 code.
Other work includes a substantial refactoring of the code structure, allowing for a single generic
save()andrestore()functions, with function pointer hooks for each type of guest to implement. The spec has been updated to include PV MSRs in the migration stream.This series depends on several prerequisite fixes which have recently been committed into staging (and have not passed the push gate at the time of writing). The series also depends on the VM Generation ID series from David.
I now consider the core of the v2 code stable. I do not expect it to change much too much, other than the identified TODOs (and code review of course).
Quoted 5 lines
The next area of work is the libxl integration, which will seek to undo the current layering violations. It will involve introducing a new libxl framing format (which will happen to look curiously similar to the libxc framing format), as well as providing legacy compatibility using the legacy conversion scripts so migrations from older libxl/libxc toolstacks will continue to work.
What are your plans for libxl integration, do you have any design specs or is it already implemented in the early stage?
Quoted 12 lines
The code is presented here for comment/query/critism.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
.
Signature · 2 lines
Thanks, Yang.
Quoted 45 lines · Hongyang Yang
Hi, Andrew,
Quoted 32 lines · Andrew Cooper
Hello,
Presented here for review is v5 of the Migration Stream v2 work.
Major work in v5 is the legacy conversion python script which is capable of
converting from legacy to v2 format on the fly. It was tested using live
migration saving in the legacy format, piping through the script and restoring
using the v2 code.Other work includes a substantial refactoring of the code structure, allowing
for a single genericsave()andrestore()functions, with function pointer
hooks for each type of guest to implement. The spec has been updated to include PV MSRs in the migration stream.This series depends on several prerequisite fixes which have recently been
committed into staging (and have not passed the push gate at the time of writing). The series also depends on the VM Generation ID series from David.I now consider the core of the v2 code stable. I do not expect it to change
much too much, other than the identified TODOs (and code review of course).Quoted 9 lines
The next area of work is the libxl integration, which will seek to undo the
current layering violations. It will involve introducing a new libxl framing
format (which will happen to look curiously similar to the libxc framing format), as well as providing legacy compatibility using the legacy conversion
scripts so migrations from older libxl/libxc toolstacks will continue to work.
Quoted 3 lines
What are your plans for libxl integration, do you have any design specs or is
it already implemented in the early stage?
There is no code in place yet, and my first course of action is to design how this is going to look.
It is going to be conceptually similar, with libxl gaining a framing format. I also need to coordinate with Wei and his JSON series which is moving data from xl to libxl. There will be "save libxl v2", "restore libxl v2" and "automatically convert old libxl to new libxl" which will mostly involve the legacy conversion script.
~Andrew
Quoted 51 lines · Andrew Cooper
Quoted 45 lines · Hongyang Yang
Hi, Andrew,
Quoted 32 lines · Andrew Cooper
Hello,
Presented here for review is v5 of the Migration Stream v2 work.
Major work in v5 is the legacy conversion python script which is capable of
converting from legacy to v2 format on the fly. It was tested using live
migration saving in the legacy format, piping through the script and restoring
using the v2 code.Other work includes a substantial refactoring of the code structure, allowing
for a single genericsave()andrestore()functions, with function pointer
hooks for each type of guest to implement. The spec has been updated to include PV MSRs in the migration stream.This series depends on several prerequisite fixes which have recently been
committed into staging (and have not passed the push gate at the time of writing). The series also depends on the VM Generation ID series from David.I now consider the core of the v2 code stable. I do not expect it to change
much too much, other than the identified TODOs (and code review of course).Quoted 9 lines
The next area of work is the libxl integration, which will seek to undo the
current layering violations. It will involve introducing a new libxl framing
format (which will happen to look curiously similar to the libxc framing format), as well as providing legacy compatibility using the legacy conversion
scripts so migrations from older libxl/libxc toolstacks will continue to work.Quoted 3 lines
What are your plans for libxl integration, do you have any design specs or is
it already implemented in the early stage?
Quoted 9 lines
There is no code in place yet, and my first course of action is to design how this is going to look.
It is going to be conceptually similar, with libxl gaining a framing format. I also need to coordinate with Wei and his JSON series which is moving data from xl to libxl. There will be "save libxl v2", "restore libxl v2" and "automatically convert old libxl to new libxl" which will mostly involve the legacy conversion script.
AIUI you're going to use both the new JSON infrastructure and the configuration synchronisation bits, right? I shall upstream the rest of my JSON infrastructure when xen-unstable is unblocked, but the synchronisation bits will take longer.
Wei.
Quoted 1 line
~Andrew
Quoted 59 lines · Wei Liu
Quoted 49 lines · Andrew Cooper
Quoted 44 lines · Hongyang Yang
Hi, Andrew,
Quoted 32 lines · Andrew Cooper
Hello,
Presented here for review is v5 of the Migration Stream v2 work.
Major work in v5 is the legacy conversion python script which is capable of
converting from legacy to v2 format on the fly. It was tested using live
migration saving in the legacy format, piping through the script and restoring
using the v2 code.Other work includes a substantial refactoring of the code structure, allowing
for a single genericsave()andrestore()functions, with function pointer
hooks for each type of guest to implement. The spec has been updated to include PV MSRs in the migration stream.This series depends on several prerequisite fixes which have recently been
committed into staging (and have not passed the push gate at the time of writing). The series also depends on the VM Generation ID series from David.I now consider the core of the v2 code stable. I do not expect it to change
much too much, other than the identified TODOs (and code review of course).Quoted 9 lines
The next area of work is the libxl integration, which will seek to undo the
current layering violations. It will involve introducing a new libxl framing
format (which will happen to look curiously similar to the libxc framing format), as well as providing legacy compatibility using the legacy conversion
scripts so migrations from older libxl/libxc toolstacks will continue to work.Quoted 3 lines
What are your plans for libxl integration, do you have any design specs or is
it already implemented in the early stage?Quoted 9 lines
There is no code in place yet, and my first course of action is to design how this is going to look.
It is going to be conceptually similar, with libxl gaining a framing format. I also need to coordinate with Wei and his JSON series which is moving data from xl to libxl. There will be "save libxl v2", "restore libxl v2" and "automatically convert old libxl to new libxl" which will mostly involve the legacy conversion script.
Quoted 6 lines
AIUI you're going to use both the new JSON infrastructure and the configuration synchronisation bits, right? I shall upstream the rest of my JSON infrastructure when xen-unstable is unblocked, but the synchronisation bits will take longer.
Wei.
I care about which (hopefully singular) legacy libxl migration format needs to be converted, and what the new stream is going to look like.
Quoted 1 line
From my understanding (without any of your changes in place) the old
"libxl" stream has:
* xl header
- contains "last boot .cfg file"
* 'libxl bits' which are passed straight to libxc
At a guess, the new stream wants to look something like:
* xl header
* libxl header
* libxl json "current configuration"
* libxc bits
* libxl xenstore key-value pairs record
* qemu record
where the legacy conversion script will have to deal with reframing the old libxc bits in terms of the new libxl stream.
~Andrew
On Thu, Jun 12, 2014 at 03:18:55PM +0100, Andrew Cooper wrote:
[...]
Quoted 12 lines
I care about which (hopefully singular) legacy libxl migration format needs to be converted, and what the new stream is going to look like.
Quoted 1 line
From my understanding (without any of your changes in place) the old
"libxl" stream has:
* xl header
- contains "last boot .cfg file"
* 'libxl bits' which are passed straight to libxc
Quoted 9 lines
At a guess, the new stream wants to look something like:
* xl header
* libxl header
* libxl json "current configuration"
* libxc bits
* libxl xenstore key-value pairs record
* qemu record
Looks sensible to me. I hope I can manage to finish the configuration bit when you get there. ;-)
Wei.
Quoted 4 lines
where the legacy conversion script will have to deal with reframing the old libxc bits in terms of the new libxl stream.
~Andrew
Quoted 3 lines · Andrew Cooper
Hello,
Presented here for review is v5 of the Migration Stream v2 work.
The commit messages are rather bare. I shall go through and suggest some text to help other people reviewing.
David
Quoted 7 lines · David Vrabel
Quoted 3 lines · Andrew Cooper
Hello,
Presented here for review is v5 of the Migration Stream v2 work.
The commit messages are rather bare. I shall go through and suggest some text to help other people reviewing.
Thank you very much for doing this for Andrew.
The lack of intra-version commit logs is also rather annoying too. Andrew, can you fix that for v5->v6 please.
Ian.