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

Re: [Xen-devel] [RFC v2] vm snapshot documents

Hi, Ian

thanks your reply. sorry reply late.
> On Fri, 2014-04-18 at 04:10 -0600, Bamvor Jian Zhang wrote:
> > Hi,
> >
> > here is the second version about vm snapshot documents, the first version is
> > here[1]
> Have you considered attending the hackathon and proposing this as a
> topic? See http://wiki.xen.org/wiki/Hackathon/May2014 for details, there
> are not a lot of places remaining...
> > thanks Ian Jackson suggestion, i write this doc about vm snapshot including
> > new
> > command, struct and api. currently, the disk snapshot(create, delete, list)
> > worked(patch is already sent[2]), and vm snapshot(create, delete, list) 
> > work.
> > but i have some questions about snapshot apply(see the last section).
> >
> > feel free to comment it. thanks.
> >
> > 1, new command
> > =head1 SNAPSHOT
> >
> > there are two types of snapshots supported by libxl: disk snapshot and vm
> > snapshot. The following subcommands management the snapshot of a domain,
> > including create, delete, list and apply.
> > a domain snapshot(or a vm snapshot) means save the domain config, memory and
> > disk snapshot. currently, only support qcow2 and internal disk snapshot.
> >
> > the vm snapshot information will store in the follow path:
> > /var/lib/xen/snapshots/<domain_uuid>/snapshotdata-<snapshot_name>.xl
> >
> > here is an example for snapshot information file:
> > snapshot_name="1397207577"
> > snapshot_creationtime="1397207577"
> > snapshot_save="/var/lib/xen/snapshots/5c84adcc-bd59-788a-96d2-195f9b599cfe/1397207577.save"
> >
> > the user could give a snapshot name when vm snapshot created. if not, the
> > epoch
> > seconds will set as name as the above examples.
> This all sounds like internal libxl implementation detail. What might be
> interesting to see would be the libxl library API for causing this stuff
> to happen.
yes, lots of function is implemented in libxl. except the top level of vm
snapshot. the latter one is implemented in the xl_cmdimpl.c. 
> At an implementation level I think this could profitably use the
> autogenerated json generators and parsers which the libxl IDL can
> provide (Wei is working on the parsing side now).
the struct is generated by libxl IDL. meanwhile for the snapshot information
file, i use the xlu_cfg_get_xxx for parse the file. i write the file with
my own function. is there some apis for generating xen config like file?
> > =over 4
> >
> > =item B<vm-snapshot-create> [I<OPTIONS>] I<domain-id>
> >
> > create vm snapshot.
> Which aspects of the VM are snapshotted? Disk you mention. What about
> memory?
vm snapshot include disk and memory.
> > it will call the qmp transaction for creating the disk snapshot in order to
> > ensure the disk snapshot is coherence.
> I'm not sure if you intend this document to literally become the xl
> manpage at some point or if it is an outline with implementation notes
> sprinkled around.
> If this is the manpage then talking about qmp (an implementation detail)
> isn't appropriate here.
sorry for confuse. i want to discuss the implementation. i will write the
dedicated man page with my code.
> If this is a implementation note then
yes, it is an implementation notes.
> it is worth considering non-qdisk
> backed snapshots and/or the mechanisms for configuring a domain such
> that it is "snapshotable" (which might for instance put constraints on
> which disk backend is used).
yes, it is worth, but i am not how to deal with non-qdisk backed. currently,
for the qdisk backed: if all the image in a domain support snapshot(qcow2,
qed?), the code support both internal and external snapshot. for others (e.g.
the domain includes raw image disk), only external snapshot is supported.
could i only consider qdisk right now?
> > vm is paused during snapshot create, and is unpause after take snapshot
> > finished.
> Is there any possibility of a live snapshot?
compare with libvirt qemu case, i guess the live snapshot is live memory save
and external disk snapshot.
> (Might make sense in the
> context of snapshotting memory at the same time)
do you mean do the disk snapshot with memory save at the same time?
> > =item B<vm-snapshot-apply> [I<OPTIONS>] I<domain-id>
> >
> > apply vm snapshot for the dedicated domain.
> What does "apply" mean here? DO you mean some sort of rollback for a
> running domain? Or just "start this snapshot as a fresh domain"?
it called revert in libvirt. currently, i implement the "apply" for the latter
one. which one do you prefer? in qemu, it seems a rollback. but it will lead
to do more about restore domain memory, i mean i need to write a function like
create_domain(xl_cmdimpl.c) without domain id changes.
> It's a bit unusual for an xl level API to provide this sort of
> management of a list of resources. Would it make more sense to structure
> this more like save/restore (where the user provides the filename)?
if i do not save the snapshot list for such domain, i could not provide the vm 
snapshot list command in xl level.
> That doesn't constrain other toolstack from providing higher level
> management functionality, providing you design the libxl layer
> correctly.
> > =item B<disk-snapshot-create> [I<OPTIONS>] I<domain-id>
> >
> > create disk snapshot.
> Hrm. so I got the impression that vm-snapshot was creating disk
> snapshots too. Maybe one is a subset of the other?
yes. i disk-snapshot will be the subset of vm snapshot. and i will add
the --disk-only parameter in vm snapshot command.
> Since this is described here in terms of xl and not libxl then how do
> you envisage this working in the absence of any kind of "storage
> manager" like functionality, e.g. describe where the snapshots disks
> should go etc.
for internal snapshot, there is no need to provide the filename.
for external snapshot, the user should provide the filename.
> > 2, new struct and new api
> It would have been less confusing for me if you would have started at
> the low level (libxl) and then done the higher level stuff (xl) rather
> than vice versa.
thanks your advice. i will rewrite the whole doc to make it more clearer.
> > 1), new struct
> > (1), libxl_snapshot struct store a disk snapshot information, which get from
> > qcow2 image through "query-block" qmp command.
> This all seems very specific to a particular backend. The API should be
> designed so that it can work with multiple backends, even if the
> implementation only supports qdisk at first.
yeah, understand. these struct are only used by disk snapshot list. it is
useless if we do not need the dedicate disk snapshot list. in fact, the user
could get it with qemu-img command for qcow2.
> > libxl_snapshot = Struct("snapshot",[
> >     ("device",        string),
> What is this? Which device?
the disk device in vm, such as sda, hda...
> >     ("name",          string),
> >     ("id",            string),
> ID of what?
the snapshot ID. it is a unique sequence number of each disk snapshot file.
it will be created by qemu when taking disk snapshot.
> >     ("vm_state_size", uint64),
> >     ("date_sec",      uint64),
> >     ("date_nsec",     uint64),
> >     ("vm_clock_sec",  uint64),
> >     ("vm_clock_nsec", uint64),
> Sounds like we need a time and/or date meta types.
> > (2), libxl_vm_snapshot store vm snapshot information which store in the path
> > shown above. i add some api for create, delete and list these information.
> > at first, i want to add these information to xenstore, but it will lose when
> > xenstore reboot or dom0 reboot.
> >
> > libxl_vm_snapshot = Struct("vm_snapshot",[
> >     ("name",          string),
> >     ("creation_time", uint64),
> >     ("save",          string),
> What is "save"?
the image path for save vm memory. it is named snapshot_save in snapshot file. 
as i wrote above, the path will be
> >     ])
> >
> > 2), new api
> > (1), in libxl/libxl.h
> > /* disk snapshot api
> >  * support create, delete and list for internal snapshot of a single disk
> >  * only support internal snapshot rigt now.
> >  */
> > /* create disk snapshot according to the device name in snapshot array. nb 
> > is
> >  * the number of snapshot array.
> So the user must supply one of these per guest disk?
yes, if user want to take specific disk snapshot. meanwhile as you Ian Jackson
said, maybe we do not need export these disk snapshot operation for users.
> Is libxl_snapshot really libxl_disk_snapshot?
> Should there be some mechanisms to convert from libxl_disk_snapshot to a
> libxl_device_disk so that it can then be attached to a domain? Either a
> utility function or there should be a field in the snapshot.
yeah, i have a api for convert from libxl_device_disk to libxl_disk_snapshot.
it will be called in vm snapshot command.
> >  * use the qmp transaction to ensure all snapshot of disk is coherence.
> >  */
> > int libxl_disk_snapshot_create(libxl_ctx *ctx, int domid,
> >                                libxl_snapshot *snapshot, int nb);
> None of these seem to have support for async. What if the disk backend
> might take a few seconds to take a snapshot.
> (as a thought experiment you might consider taking a snapshot with "dd")
thanks, do you mean ao in create and save?
> > /* delete number of nb disk snapshot describe in snapshot array
> >  */
> > int libxl_disk_snapshot_delete(libxl_ctx *ctx, int domid,
> >                                libxl_snapshot *snapshot, int nb);
> > int libxl__disk_snapshot_delete(libxl_ctx *ctx, int domid,
> >                                 libxl_snapshot *snapshot);
> > /* apply the disk snapshot by qemu-img command
> There's that "apply" again. What does it mean?
revert. reference my comment above.
> >  */
> > int libxl_disk_snapshot_apply(libxl_ctx *ctx, int domid,
> >                               libxl_snapshot *snapshot, int nb);
> > /* list disk snapshot by qmp query-block command
> >  */
> > int libxl__disk_snapshot_list(libxl_ctx *ctx, int domid,
> >                               libxl_snapshot **snapshotp);
> I think the resource management aspect here needs careful thought. i.e.
> the management of the backing storage, should it be the responsibility
> of libxl or the toolstack (xl, libvirt) etc.
> I have a feeling that libxl should be providing the mechanisms but the
> actual management (i.e. lists of snapshots) will be the toolstack's
> doing -- i.e. doesn't libvirt already have a storage and snapshot
> manager?
libvirt already have such snapshot manager: user need provide filename for
external snapshot file. so as to xl.
for other resource do not provided by libvirt, libxl should manage it.
e.g. the memory file saved by xen, should managed by libxl as i mentioned in
snapshot information file.
> > (2), libxl/xl_cmdimpl.c
> > /* get disk device name (hda, hdc..) and image path through
> >  * libxl_device_disk_list and libxl_device_disk_getinfo
> >  */
> > static int get_disk(uint32_t domid, libxl_snapshot **snapshotp, char *name);
> What is this?
as we talk above, it convert libxl_device_disk to libxl_disk_snapshot for
> > 3, question
> > 1), how to do disk snapshot apply?
> > when i apply the vm snapshot, i need to revert the disk snapshot. in qemu, 
> > it
> > is
> > done by bdrv_snapshot_goto api. this api is only called by loadvm hmp or
> > qemu-img commands.
> > there is no hmp api in libxl. so the only choice is using qemu-img command.
> "hmp"? Did you mean "qmp"? I don't think so because there is definitely
> a qmp api in libxl, but I can't htink of anything else.
hmp is another channel for qemu operation. it could be called through qmp i
know this after i send this email.
there are loadvm and savevm hmp in qemu, libxl. it is useful for doing the
internal snapshot. savevm means save qemu memory and do internal disk snapshot.
and loadvm mean revert the snapshot state the one of savevm state.
but it will almost save qemu state twice if the vm snapshot create flow is as
1, save memory, the core function will be libxl_domain_suspend. it will save
domain memory and qemu state.
after memory save, the domain should remain pause for savevm.
2, call savevm hmp through qemu qmp. the save vm will save qemu memory
(including qemu state saved by step 1) and do internal disk snapshot.

the qemu state is very small, it will not waste a lot. is it ok?

> > i know usually i should call qmp for qemu operation. but there is not qmp at
> > the moment, could i call qemu-img in libxl for disk snapshot apply?
> In general I think it would be useful to go back and define what you
> actually mean by all these things at a higher semantic layer. i.e. what
> does it mean to "apply" a disk snapshot?
yes, it seems that i need write a new version of this doc for review.
i will update api, struct and implementation details for distinguish
non-live, live snapshot, internal and external snapshot.
meanwhile, IIUC, libvirt/qemu only support revert the non-live, internal
snapshot revert. could i fosus on non-live internal snapshot operations for
the first version of code in next steps?



> Ian.

Xen-devel mailing list



Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.