[libvirt] Re: [PATCH alternative 1/2] virDomainGetID2

Daniel P. Berrange berrange at redhat.com
Thu Sep 18 08:44:39 UTC 2008

On Wed, Sep 03, 2008 at 05:19:20PM +0100, Richard W.M. Jones wrote:
> On Wed, Sep 03, 2008 at 05:18:16PM +0100, Richard W.M. Jones wrote:
> > This adds virDomainGetID2 which uses a pointer to int parameter,
> > allowing the -1 (non-running) domain ID to be returned safely.
> With the patch this time ...

I don't particularly like this because it is implying that an inactive
domain has an ID number, which is not correct.  I think we primarily
have to make the documentation for the existing API clearer.

If there's a compelling need for applications to be able to determine
whether a domain has an ID, then I think an API explicitly answering
that question would be preferrable. eg something like

       * Return a non-zero positive number if the domain is active
       * and has a valid ID. Return zero if the domain is inactive
       * and does not have any ID number. Return -1 upon error
      int virDomainHasID(virDomainPtr dom) {
          if (!VIR_IS_DOMAIN(domain)) {
              virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
              return -1;

          if (dom->id == -1)
             return 0;
             return 1;

|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

More information about the libvir-list mailing list