From my understanding virConnectListActiveDomains() is listing all the active (running) domains and virConnectListDefinedDomains() is listing all the inactive domains that are defined since if we create a domain directly from XML, i.e. non-persistent, we have the domain in active domains list but it's not defined. Only inactive but defined domains are in the defined list AFAIK.

I can't find the function virConnectListActiveDomains(), did you mean virConnectListActiveDomains()?

If we have 2 domains created *directly* from XML file, 3 persistent domains active and 4 domains inactive (but defined) we should be getting number 5 from virConnectListActiveDomains() since 2 + 3. For defined (inactive) domains we should be getting number for and total number should be 2 + 3 + 4 = 9 domains.

Confused, do you missed some words? Shouldn't it be:

2 active but not defined
3 active but defined
4 inactive and defined
2 + 3 = 5 active
3 + 4 = 7 defined
2 + 3 + 4 = 9 total

libvirt_list_domains() should gets 9;
libvirt_list_active_domains() gets 5
libivrt_list_inactive_domains() gets 4?
libvirt_list_defined_domains() (if there's such a function) gets 7?