Bug 859529 - Give warning if virsh edit will define a new guest when UUID and name change
Give warning if virsh edit will define a new guest when UUID and name change
Status: CLOSED NOTABUG
Product: Virtualization Tools
Classification: Community
Component: libvirt (Show other bugs)
unspecified
Unspecified Unspecified
unspecified Severity unspecified
: ---
: ---
Assigned To: Libvirt Maintainers
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2012-09-21 14:38 EDT by Richard W.M. Jones
Modified: 2016-04-26 14:34 EDT (History)
13 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2015-09-09 09:27:58 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:


Attachments (Terms of Use)

  None (edit)
Description Richard W.M. Jones 2012-09-21 14:38:31 EDT
Description of problem:

I wanted to rename a guest, so I used virsh edit to edit the
<name> field.

The first time I tried it, I got an unexpected error message:

$ sudo virsh edit F18Rawhidex64
error: operation failed: domain 'F18Rawhidex64' is already defined with uuid 6cd95299-b1aa-449b-2321-314e0c4edc37
Failed. Try again? [y,n,f,?]:

but I persisted and edited the UUID as well, and it succeeded:
Domain F19Rawhidex64 XML configuration edited.

However what I ended up with was two guests sharing the same
disks etc:

$ sudo virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     F18Rawhidex64                  shut off     # original
 -     F19Rawhidex64                  shut off     # duplicate


Version-Release number of selected component (if applicable):

libvirt-0.10.1-2.fc18.x86_64
Comment 1 Jiri Denemark 2012-09-21 16:10:46 EDT
Rich, libvirt doesn't directly support renaming a domain, although we have a
longstanding bug for that. The reason is that domain name is unfortunately
used key for storing various domain related information. To rename a domain,
you need to dump its XML, undefine the domain, change the name in the XML and
use it to define the same domain with different name.

The steps you used work as desired. It's an undocumented feature of virsh edit
(coming from its use of virDomainDefine API) and can be used for cloning
domain definition.
Comment 2 Cole Robinson 2012-10-27 13:37:54 EDT
What to do here? We shouldn't change virDomainDefine behavior obviously, but maybe we can add a 'virsh edit' specific check like

if newname != oldname:
Comment 3 Cole Robinson 2012-10-27 13:40:43 EDT
Finishing that thought, basically if newname != oldname, print some message explaining you cannot rename a guest with edit command. can use virsh define w/ new name and uuid, but that has caveats like not moving over saved state, snapshots, etc.
Comment 4 Noella 2015-04-16 08:38:49 EDT
Hello, 

I will  love to work on this bug. I just need some more specifics on the files;  I should look at to fix this  bug.

Thanks,
Noella
Comment 5 Cole Robinson 2015-04-16 09:28:26 EDT
'virsh edit' handling is kind of confusing.

See tools/virsh-domain.c:cmdEdit for the 'virsh edit' entry point. But a lot of the edit support is generic infrastructure in tools/virsh-edit.c

If I was going to implement this, I'd extend tools/virsh-edit.c to take another macro like EDIT_XML_IDENTITY_CHANGED. It will need to take the original XML, and the new XML, and compare their name and UUID values. If both have changed, then prompt the user to ask if that's what they want. You can use the virXPathString function to help parsing the XML to get the name and UUID, look for other examples in virsh-domain.c

Unfortunately though the description of this bug makes it sound easier than the actual implementation would be...
Comment 6 Michal Privoznik 2015-04-16 10:03:09 EDT
I think this bug should be closed. Rich, this way of cloning domains is practically a misuse of virsh edit. I mean it's possible only because virsh uses virDomainDefine() underneath. If we ever come up with virDomainChangeXML() which would update anything but the domain name and UUID, virsh edit would have fail. The best we can do - to increase the virsh user-friendliness is to do what Cole suggested. But on the other hand, I know plenty of libvirt developers who misuse this behaviour (myself included) so I don't like to see it changed.

On the other hand, once libvirt supports object rename, virsh {net-,vol-,...}edit can adapt that. Until then, I think current behaviour should be preserved.
Comment 7 Cole Robinson 2015-04-16 10:26:41 EDT
(In reply to Michal Privoznik from comment #6)
> I think this bug should be closed. Rich, this way of cloning domains is
> practically a misuse of virsh edit. I mean it's possible only because virsh
> uses virDomainDefine() underneath. If we ever come up with
> virDomainChangeXML() which would update anything but the domain name and
> UUID, virsh edit would have fail. The best we can do - to increase the virsh
> user-friendliness is to do what Cole suggested. But on the other hand, I
> know plenty of libvirt developers who misuse this behaviour (myself
> included) so I don't like to see it changed.
> 

I was thinking that if we detected name + UUID change, we would print an error, but with a prompt option to continue anyways. So it wouldn't be blocking users who intentionally want to create a new VM definition, but we still warn people who might not know what they are doing.

That said the edit handling code is already quite intense, and I doubt many people make this mistake in practice, so personally I don't mind if this bug is closed
Comment 8 Noella 2015-04-19 10:35:04 EDT
Well in this case. I will prefer to work on another bug then.

Thanks for the assistance.
Noella
Comment 9 Michal Privoznik 2015-09-09 09:27:58 EDT
(In reply to Cole Robinson from comment #7)
> <snip/>
> That said the edit handling code is already quite intense, and I doubt many
> people make this mistake in practice, so personally I don't mind if this bug
> is closed

Okay, I'm closing this one then. It's worth mentioning that libvirt grew rename command as part of GSoC project:

virsh domrename $oldname $newname

Note You need to log in before you can comment on or make changes to this bug.