Skip to contentSkip to conversation

Add the upper/lower limit checking for xm sched-credit

PATCH In review Masaki Kanno 1 participant 2 messages Sep 8, 2006 – Sep 14, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add the upper/lower limit checking for xm sched-credit

Hi,

The "xm sched-credit" command has no checking function for a value of its "weight" and "cap" option. I tested them with wrong values and the results were as follows.

Weight option:

 # xm list
 Name                              ID Mem(MiB) VCPUs State  Time(s)
 Domain-0                           0      873     2 r-----    65.0
 vm1                                1      128     1 -b----     0.3
 # xm sched-credit -d vm1
 {'cap': 0, 'weight': 256}
 # xm sched-credit -d vm1 -w -1
 # xm sched-credit -d vm1
 {'cap': 0, 'weight': 65535}
 # xm sched-credit -d vm1 -w 0
 # xm sched-credit -d vm1
 {'cap': 0, 'weight': 65535}
 # xm sched-credit -d vm1 -w -2
 # xm sched-credit -d vm1
 {'cap': 0, 'weight': 65534}
 # xm sched-credit -d vm1 -w 65536
 # xm sched-credit -d vm1
 {'cap': 0, 'weight': 65534}
 # xm sched-credit -d vm1 -w 65537
 # xm sched-credit -d vm1
 {'cap': 0, 'weight': 1}

Cap option:

 # xm list
 Name                              ID Mem(MiB) VCPUs State  Time(s)
 Domain-0                           0      873     2 r-----    73.3
 vm1                                1      128     1 -b----    25.4
 # xm sched-credit -d vm1
 {'cap': 0, 'weight': 256}
 # xm sched-credit -d vm1 -c -1
 # xm sched-credit -d vm1
 {'cap': 0, 'weight': 256}
 # xm sched-credit -d vm1 -c -2
 # xm sched-credit -d vm1
 {'cap': 65534, 'weight': 256}
 # xm sched-credit -d vm1 -c 101
 # xm sched-credit -d vm1
 {'cap': 101, 'weight': 256}

This patch adds value checking of options. The results of this patch are as follows.

Weigth option:

 # xm list
 Name                              ID Mem(MiB) VCPUs State  Time(s)
 Domain-0                           0      874     2 r-----    76.9
 vm1                                1      128     1 -b----    26.6
 # xm sched-credit -d vm1
 {'cap': 0, 'weight': 256}
 # xm sched-credit -d vm1 -w -1
 Error: weight is out of range
 # xm sched-credit -d vm1
 {'cap': 0, 'weight': 256}
 # xm sched-credit -d vm1 -w 0
 Error: weight is out of range
 # xm sched-credit -d vm1
 {'cap': 0, 'weight': 256}
 # xm sched-credit -d vm1 -w -2
 Error: weight is out of range
 # xm sched-credit -d vm1
 {'cap': 0, 'weight': 256}
 # xm sched-credit -d vm1 -w 65536
 Error: weight is out of range
 # xm sched-credit -d vm1
 {'cap': 0, 'weight': 256}
 # xm sched-credit -d vm1 -w 65537
 Error: weight is out of range
 # xm sched-credit -d vm1
 {'cap': 0, 'weight': 256}
 # xm sched-credit -d vm1 -w 65535
 # xm sched-credit -d vm1
 {'cap': 0, 'weight': 65535}
 # xm sched-credit -d vm1 -w 1
 # xm sched-credit -d vm1
 {'cap': 0, 'weight': 1}

Cap option:

 # xm list
 Name                              ID Mem(MiB) VCPUs State  Time(s)
 Domain-0                           0      874     2 r-----    80.5
 vm1                                1      128     1 -b----    26.6
 # xm sched-credit -d vm1
 {'cap': 0, 'weight': 256}
 # xm sched-credit -d vm1 -c -1
 Error: cap is out of range
 # xm sched-credit -d vm1
 {'cap': 0, 'weight': 256}
 # xm sched-credit -d vm1 -c -2
 Error: cap is out of range
 # xm sched-credit -d vm1
 {'cap': 0, 'weight': 256}
 # xm sched-credit -d vm1 -c 101
 Error: cap is out of range
 # xm sched-credit -d vm1
 {'cap': 0, 'weight': 256}
 # xm sched-credit -d vm1 -c 100
 # xm sched-credit -d vm1
 {'cap': 100, 'weight': 256}

Best regards,
Kan

tools/python/xen/xend/XendDomain.py +11 -1
diff -r 1de184deaa9c tools/python/xen/xend/XendDomain.py
@@ -540,13 +540,23 @@ class XendDomain:
         except Exception, ex:
             raise XendError(str(ex))
     
-    def domain_sched_credit_set(self, domid, weight, cap):
+    def domain_sched_credit_set(self, domid, weight = None, cap = None):
         """Set credit scheduler parameters for a domain.
         """
         dominfo = self.domain_lookup_by_name_or_id_nr(domid)
         if not dominfo:
             raise XendInvalidDomain(str(domid))
         try:
+            if weight is None:
+                weight = int(0)
+            elif weight < 1 or weight > 65535:
+                raise XendError("weight is out of range")
+
+            if cap is None:
+                cap = int(~0)
+            elif cap < 0 or cap > dominfo.getVCpuCount() * 100:
+                raise XendError("cap is out of range")
+
             return xc.sched_credit_domain_set(dominfo.getDomid(), weight, cap)
         except Exception, ex:
             raise XendError(str(ex))
tools/python/xen/xm/main.py +0 -5
diff -r 1de184deaa9c tools/python/xen/xm/main.py
@@ -780,11 +780,6 @@ def xm_sched_credit(args):
     if weight is None and cap is None:
         print server.xend.domain.sched_credit_get(domain)
     else:
-        if weight is None:
-            weight = int(0)
-        if cap is None:
-            cap = int(~0)
-
         err = server.xend.domain.sched_credit_set(domain, weight, cap)
         if err != 0:
             print err

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

#1 lore raw

Re: [PATCH] Add the upper/lower limit checking for xmsched-credit

Hi,

Could you comment about this patch?

http://lists.xensource.com/archives/html/xen-devel/2006-09/msg00245.html

Best regards,
Kan

Quoted 119 lines

Hi,

The "xm sched-credit" command has no checking function for a value of its "weight" and "cap" option. I tested them with wrong values and the results were as follows.

Weight option:

# xm list
Name                              ID Mem(MiB) VCPUs State  Time(s)
Domain-0                           0      873     2 r-----    65.0
vm1                                1      128     1 -b----     0.3
# xm sched-credit -d vm1
{'cap': 0, 'weight': 256}
# xm sched-credit -d vm1 -w -1
# xm sched-credit -d vm1
{'cap': 0, 'weight': 65535}
# xm sched-credit -d vm1 -w 0
# xm sched-credit -d vm1
{'cap': 0, 'weight': 65535}
# xm sched-credit -d vm1 -w -2
# xm sched-credit -d vm1
{'cap': 0, 'weight': 65534}
# xm sched-credit -d vm1 -w 65536
# xm sched-credit -d vm1
{'cap': 0, 'weight': 65534}
# xm sched-credit -d vm1 -w 65537
# xm sched-credit -d vm1
{'cap': 0, 'weight': 1}

Cap option:

# xm list
Name                              ID Mem(MiB) VCPUs State  Time(s)
Domain-0                           0      873     2 r-----    73.3
vm1                                1      128     1 -b----    25.4
# xm sched-credit -d vm1
{'cap': 0, 'weight': 256}
# xm sched-credit -d vm1 -c -1
# xm sched-credit -d vm1
{'cap': 0, 'weight': 256}
# xm sched-credit -d vm1 -c -2
# xm sched-credit -d vm1
{'cap': 65534, 'weight': 256}
# xm sched-credit -d vm1 -c 101
# xm sched-credit -d vm1
{'cap': 101, 'weight': 256}

This patch adds value checking of options. The results of this patch are as follows.

Weigth option:

# xm list
Name                              ID Mem(MiB) VCPUs State  Time(s)
Domain-0                           0      874     2 r-----    76.9
vm1                                1      128     1 -b----    26.6
# xm sched-credit -d vm1
{'cap': 0, 'weight': 256}
# xm sched-credit -d vm1 -w -1
Error: weight is out of range
# xm sched-credit -d vm1
{'cap': 0, 'weight': 256}
# xm sched-credit -d vm1 -w 0
Error: weight is out of range
# xm sched-credit -d vm1
{'cap': 0, 'weight': 256}
# xm sched-credit -d vm1 -w -2
Error: weight is out of range
# xm sched-credit -d vm1
{'cap': 0, 'weight': 256}
# xm sched-credit -d vm1 -w 65536
Error: weight is out of range
# xm sched-credit -d vm1
{'cap': 0, 'weight': 256}
# xm sched-credit -d vm1 -w 65537
Error: weight is out of range
# xm sched-credit -d vm1
{'cap': 0, 'weight': 256}
# xm sched-credit -d vm1 -w 65535
# xm sched-credit -d vm1
{'cap': 0, 'weight': 65535}
# xm sched-credit -d vm1 -w 1
# xm sched-credit -d vm1
{'cap': 0, 'weight': 1}

Cap option:

# xm list
Name                              ID Mem(MiB) VCPUs State  Time(s)
Domain-0                           0      874     2 r-----    80.5
vm1                                1      128     1 -b----    26.6
# xm sched-credit -d vm1
{'cap': 0, 'weight': 256}
# xm sched-credit -d vm1 -c -1
Error: cap is out of range
# xm sched-credit -d vm1
{'cap': 0, 'weight': 256}
# xm sched-credit -d vm1 -c -2
Error: cap is out of range
# xm sched-credit -d vm1
{'cap': 0, 'weight': 256}
# xm sched-credit -d vm1 -c 101
Error: cap is out of range
# xm sched-credit -d vm1
{'cap': 0, 'weight': 256}
# xm sched-credit -d vm1 -c 100
# xm sched-credit -d vm1
{'cap': 100, 'weight': 256}

Best regards,
Kan

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