Bug 437216 - virConnectListDefinedDomains isn't returning the names of active domains
virConnectListDefinedDomains isn't returning the names of active domains
Status: CLOSED NOTABUG
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: libvirt (Show other bugs)
5.2
All Linux
medium Severity medium
: rc
: ---
Assigned To: Daniel Veillard
Virtualization Bugs
: Reopened
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2008-03-12 18:31 EDT by Ryan McCabe
Modified: 2009-12-14 16:13 EST (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2008-03-18 16:07:03 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
little reproducer program (910 bytes, text/x-csrc)
2008-03-12 18:33 EDT, Ryan McCabe
no flags Details

  None (edit)
Description Ryan McCabe 2008-03-12 18:31:45 EDT
(using libvirt-0.3.3-5.el5 on x86_64)

virConnectListDefinedDomains returns only the number of inactive domains when
called, and only stores the names of the inactive domains in the char **
argument passed.

virConnectNumOfDefinedDomains returns the expected number of domains (the sum of
active and inactive domains) when called.
Comment 1 Ryan McCabe 2008-03-12 18:33:34 EDT
Created attachment 297859 [details]
little reproducer program

output for me:

[root@celaeno tmp]# ./rhbz437216a1
virConnectNumOfDefinedDomains ret 7
virConnectListDefinedDomains ret 5
0 -> rhel46v3
1 -> r52_4
2 -> r52_3
3 -> r52_2
4 -> r52_1
5 is NULL
6 is NULL
Comment 2 Daniel Veillard 2008-03-17 04:48:06 EDT
That's normal, it really is the semantic of "defined domain", i.e.
there is a definition for them but they are not running. Also it's
way easier to have 2 entry point in the API doing a partition of the
domain set than having to compute the diff between two lists if you
want to be able to display the list of domain defined but not running.

  Not a bug, a misunderstanding of "DefinedDomains" semantic,

Daniel
Comment 3 Daniel Veillard 2008-03-17 04:49:35 EDT
For virConnectNumOfDefinedDomains this looks like a bug, yes

Daniel
Comment 4 Ryan McCabe 2008-03-17 12:19:47 EDT
It'd be helpful to update the docs to reflect that
virConnectListDefinedDomains() is not supposed to return the active domains. For
the other virConnectListDefined* functions, the docs explicitly state that only
inactive entities are to be returned.
Comment 5 Daniel Veillard 2008-03-17 12:42:31 EDT
I think the bug is in xenXMNumOfDefinedDomains() affecting basically only
Xen in RHEL-5.x (x >= 1), as it lists the number of files but doesn't check
that the domain is not running. it's a bug, but of limited consequence,
basically that function is used to allocate the array for the subsequent
virConnectListDefinedDomains() call in most scenario i can think of and a
slightly too big array is not a problem in practice (and why this was never
detected :-) . Fixing it would require xenXMNumOfDefinedDomains() to check 
for each of them it's not running, which means calling xend which we know
is fairly expensive. Maybe this should be fixed, maybe this is not worth it.
The XM stuff is really RHEL/Xen specific ...
Fixing the comments makes perfect sense, I fixed as
    * Provides the number of defined but inactive domains.
and
    * list the defined but inactive domains, stores ...

  and will commit this shortly upstream,

  thanks !

Daniel
Comment 6 Daniel Berrange 2008-03-18 16:07:03 EDT
This is the intended behaviour of  virConnectNumOfDefinedDomains().

You cannot assume that the number of domains counted by
virConnectNumOfDefinedDonmains() necccessarily matches the number of domains
returned by virConnectListDefinedDomains(). Between the time you call the 2
APIs, new domains may have started and existing domains may have shut down.  
The value of the NumOfDefinedDomains() API is basically reasonably hint at a
size for array needed to call the ListDefinedDomains() API. As such a over-sized
value is perfectly legitimate.

The XM driver impl delibrately returns a virConnectNumOfDefinedDonmains() value
which is sometimes too large, for efficency reasons - filtering out the active
domains is expensive, so only done when we actually list them, not when we count
them. So if you need to know the actual number of domain names you need to look
at the return value for virConnectListDefinedDomains to see how many members of
the array it actually filled in. You can not assume all array members are non-NULL.

As such there is no bug here.

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