Skip to contentSkip to conversation

add count-only option to DOM0_GETDOMAININFOLIST hypercall

PATCH In review Mike D. Day 2 participants 3 messages Mar 23, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 add count-only option to DOM0_GETDOMAININFOLIST hypercall

When retreiving a list of domain info structs it would be helpful to know the current domain count prior to making the hcall. This would make it simpler to allocate a return buffer of the appropriate size.

Adding the six lines to the case for the GETDOMAININFOLIST dom0 op allows the caller to retrieve only the count of the domains. The use model is as follows:

    int number_domains;
    struct dom0_op info;
    info.cmd = DOM0_GETDOMAININFOLIST;
    info.u.getdomaininfolist.max_domains = 0;

    HYPERCALL_dom0_op(&info);

    number_domains = info.u.getdomaininfolist.max_domains;

Having the number of domains, the caller can now allocate a buffer of the correct size to get the actual domain information.

# HG changeset patch
# User [email protected]
# Node ID cd6869742400411fdaf295cc4e0167361e967619
# Parent 5d3c2cb42ec41984cb1e586d3e47a8692eb8b132
modify domain infolist hypercall to optionally return only a count of domains

xen/common/dom0_ops.c +6 -0
diff -r 5d3c2cb42ec4 -r cd6869742400 xen/common/dom0_ops.c
@@ -416,6 +416,12 @@ long do_dom0_op(GUEST_HANDLE(dom0_op_t) 
 
         for_each_domain ( d )
         {
+            if (op->u.getdomaininfolist.max_domains == 0) 
+            {
+                num_domains++;
+                continue;
+            }
+                
             if ( d->domain_id < op->u.getdomaininfolist.first_domain )
                 continue;
             if ( num_domains == op->u.getdomaininfolist.max_domains )
#1 lore raw

There's a race condition here. There's no way of knowing that domains haven't been destroyed (or created) in between these calls.

Unfortunately, the only way to avoid this is grab them one at a time.

Regards,

Anthony Liguori

Quoted 48 lines · Mike D. Day

When retreiving a list of domain info structs it would be helpful
to know the current domain count prior to making the hcall. This would make it simpler to allocate a return buffer of the appropriate size.

Adding the six lines to the case for the GETDOMAININFOLIST dom0 op
allows the caller to retrieve only the count of the domains. The use model is as follows:

    int number_domains;
    struct dom0_op info;
    info.cmd = DOM0_GETDOMAININFOLIST;
    info.u.getdomaininfolist.max_domains = 0;

    HYPERCALL_dom0_op(&info);

    number_domains = info.u.getdomaininfolist.max_domains;

Having the number of domains, the caller can now allocate a buffer of the correct size to get the actual domain information.

# HG changeset patch
# User [email protected]
# Node ID cd6869742400411fdaf295cc4e0167361e967619
# Parent 5d3c2cb42ec41984cb1e586d3e47a8692eb8b132
modify domain infolist hypercall to optionally return only a count of domains

diff -r 5d3c2cb42ec4 -r cd6869742400 xen/common/dom0_ops.c

xen/common/dom0_ops.c +6 -0
@@ -416,6 +416,12 @@ long do_dom0_op(GUEST_HANDLE(dom0_op_t) 
 
         for_each_domain ( d )
         {
+            if (op->u.getdomaininfolist.max_domains == 0) 
+            {
+                num_domains++;
+                continue;
+            }
+                
             if ( d->domain_id < op->u.getdomaininfolist.first_domain )
                 continue;
             if ( num_domains == op->u.getdomaininfolist.max_domains )

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#2 lore raw
Quoted 3 lines · Anthony Liguori

There's a race condition here. There's no way of knowing that domains haven't been destroyed (or created) in between these calls.

Unfortunately, the only way to avoid this is grab them one at a time.

The race condition is harmless and the patch is an improvement over the current situation where you have to guess the number of domains (and hence the size of the buffer you allocate).

Most of the time the caller will be looking for a snapshot of domain information, not an up-to-the-instant comprehensive report.

And the pre-existing method of allocating a huge buffer and calling once still works.

Mike