Skip to contentSkip to conversation

Improve xm sched-credit command for inactive managed domains

PATCH New Masaki Kanno 1 participant 1 message Jul 6, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Improve xm sched-credit command for inactive managed domains

Hi,

This patch improves xm sched-credit command for inactive managed domains. You can see and change the scheduler parameters of inactive managed domains.

# xm sched-credit
Name                                ID Weight  Cap
Domain-0                             0    256    0
vm1                                  1    512  100
vm2                                       128   50
# xm sched-credit -d vm2 -w 256 -c 75
# xm sched-credit
Name                                ID Weight  Cap
Domain-0                             0    256    0
vm1                                  1    512  100
vm2                                       256   75

Best regards,
Kan

tools/python/xen/xend/XendDomain.py +12 -5
diff -r d54d47fc8c6c tools/python/xen/xend/XendDomain.py
@@ -1399,10 +1399,15 @@ class XendDomain:
         dominfo = self.domain_lookup_nr(domid)
         if not dominfo:
             raise XendInvalidDomain(str(domid))
-        try:
-            return xc.sched_credit_domain_get(dominfo.getDomid())
-        except Exception, ex:
-            raise XendError(str(ex))
+        
+        if dominfo._stateGet() in (DOM_STATE_RUNNING, DOM_STATE_PAUSED):
+            try:
+                return xc.sched_credit_domain_get(dominfo.getDomid())
+            except Exception, ex:
+                raise XendError(str(ex))
+        else:
+            return {'weight' : dominfo.getWeight(),
+                    'cap'    : dominfo.getCap()} 
     
     def domain_sched_credit_set(self, domid, weight = None, cap = None):
         """Set credit scheduler parameters for a domain.
@@ -1436,7 +1441,9 @@ class XendDomain:
             assert type(weight) == int
             assert type(cap) == int
 
-            rc = xc.sched_credit_domain_set(dominfo.getDomid(), weight, cap)
+            rc = 0
+            if dominfo._stateGet() in (DOM_STATE_RUNNING, DOM_STATE_PAUSED):
+                rc = xc.sched_credit_domain_set(dominfo.getDomid(), weight, cap)
             if rc == 0:
                 if set_weight:
                     dominfo.setWeight(weight)
tools/python/xen/xm/main.py +22 -12
diff -r d54d47fc8c6c tools/python/xen/xm/main.py
@@ -1529,7 +1529,7 @@ def xm_sched_credit(args):
 
     doms = filter(lambda x : domid_match(domid, x),
                   [parse_doms_info(dom)
-                  for dom in getDomains(None, 'running')])
+                  for dom in getDomains(None, 'all')])
 
     if weight is None and cap is None:
         if domid is not None and doms == []: 
@@ -1545,7 +1545,7 @@ def xm_sched_credit(args):
                         server.xenapi.VM.get_metrics(
                             get_single_vm(d['name'])))
                 else:
-                    info = server.xend.domain.sched_credit_get(d['domid'])
+                    info = server.xend.domain.sched_credit_get(d['name'])
             except xmlrpclib.Fault:
                 pass
 
@@ -1557,8 +1557,8 @@ def xm_sched_credit(args):
             info['cap']    = int(info['cap'])
             
             info['name']  = d['name']
-            info['domid'] = int(d['domid'])
-            print( ("%(name)-32s %(domid)5d %(weight)6d %(cap)4d") % info)
+            info['domid'] = str(d['domid'])
+            print( ("%(name)-32s %(domid)5s %(weight)6d %(cap)4d") % info)
     else:
         if domid is None:
             # place holder for system-wide scheduler parameters
@@ -1566,14 +1566,24 @@ def xm_sched_credit(args):
             usage('sched-credit')
 
         if serverType == SERVER_XEN_API:
-            server.xenapi.VM.add_to_VCPUs_params_live(
-                get_single_vm(domid),
-                "weight",
-                weight)
-            server.xenapi.VM.add_to_VCPUs_params_live(
-                get_single_vm(domid),
-                "cap",
-                cap)            
+            if doms[0]['domid']:
+                server.xenapi.VM.add_to_VCPUs_params_live(
+                    get_single_vm(domid),
+                    "weight",
+                    weight)
+                server.xenapi.VM.add_to_VCPUs_params_live(
+                    get_single_vm(domid),
+                    "cap",
+                    cap)
+            else:
+                server.xenapi.VM.add_to_VCPUs_params(
+                    get_single_vm(domid),
+                    "weight",
+                    weight)
+                server.xenapi.VM.add_to_VCPUs_params(
+                    get_single_vm(domid),
+                    "cap",
+                    cap)
         else:
             result = server.xend.domain.sched_credit_set(domid, weight, cap)
             if result != 0:

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