Skip to contentSkip to conversation

sysctl: adjust XEN_SYSCTL_numainfo behavior

PATCH In review Jan Beulich 4 participants 5 messages Jul 14, 2015 – Jul 15, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sysctl: adjust XEN_SYSCTL_numainfo behavior

... to match XEN_SYSCTL_cputopoinfo, allowing the caller to get what it needs (if e.g. it's after the data for just one specific node) with just one hypercall, without caring about the total number of nodes in the system.

xen/common/sysctl.c +4 -10
@@ -285,15 +285,9 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xe
         {
             xen_sysctl_meminfo_t meminfo = { 0 };
 
-            if ( ni->num_nodes < num_nodes )
-            {
-                ret = -ENOBUFS;
-                i = num_nodes;
-            }
-            else
-                i = 0;
-
-            for ( ; i < num_nodes; i++ )
+            if ( num_nodes > ni->num_nodes )
+                num_nodes = ni->num_nodes;
+            for ( i = 0; i < num_nodes; ++i )
             {
                 static uint32_t distance[MAX_NUMNODES];
 
@@ -335,7 +329,7 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xe
         else
             i = num_nodes;
 
-        if ( (!ret || (ret == -ENOBUFS)) && (ni->num_nodes != i) )
+        if ( !ret && (ni->num_nodes != i) )
         {
             ni->num_nodes = i;
             if ( __copy_field_to_guest(u_sysctl, op,
xen/include/public/sysctl.h +5 -4
@@ -515,10 +515,11 @@ DEFINE_XEN_GUEST_HANDLE(xen_sysctl_memin
  *    non-null)
  *
  * OUT:
- *  - If 'num_nodes' is less than the number Xen needs to write, -ENOBUFS shall
- *    be returned and 'num_nodes' updated to reflect the intended number.
- *  - On success, 'num_nodes' shall indicate the number of entries written, which
- *    may be less than the maximum.
+ *  - If 'num_nodes' is less than the number Xen wants to write but either
+ *    handle is not a NULL one, partial data gets returned and 'num_nodes'
+ *    gets updated to reflect the intended number.
+ *  - Otherwise, 'num_nodes' shall indicate the number of entries written, which
+ *    may be less than the input value.
  */
 
 struct xen_sysctl_numainfo {

sysctl: adjust XEN_SYSCTL_numainfo behavior

... to match XEN_SYSCTL_cputopoinfo, allowing the caller to get what it needs (if e.g. it's after the data for just one specific node) with just one hypercall, without caring about the total number of nodes in the system.

xen/common/sysctl.c +4 -10
@@ -285,15 +285,9 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xe
         {
             xen_sysctl_meminfo_t meminfo = { 0 };
 
-            if ( ni->num_nodes < num_nodes )
-            {
-                ret = -ENOBUFS;
-                i = num_nodes;
-            }
-            else
-                i = 0;
-
-            for ( ; i < num_nodes; i++ )
+            if ( num_nodes > ni->num_nodes )
+                num_nodes = ni->num_nodes;
+            for ( i = 0; i < num_nodes; ++i )
             {
                 static uint32_t distance[MAX_NUMNODES];
 
@@ -335,7 +329,7 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xe
         else
             i = num_nodes;
 
-        if ( (!ret || (ret == -ENOBUFS)) && (ni->num_nodes != i) )
+        if ( !ret && (ni->num_nodes != i) )
         {
             ni->num_nodes = i;
             if ( __copy_field_to_guest(u_sysctl, op,
xen/include/public/sysctl.h +5 -4
@@ -515,10 +515,11 @@ DEFINE_XEN_GUEST_HANDLE(xen_sysctl_memin
  *    non-null)
  *
  * OUT:
- *  - If 'num_nodes' is less than the number Xen needs to write, -ENOBUFS shall
- *    be returned and 'num_nodes' updated to reflect the intended number.
- *  - On success, 'num_nodes' shall indicate the number of entries written, which
- *    may be less than the maximum.
+ *  - If 'num_nodes' is less than the number Xen wants to write but either
+ *    handle is not a NULL one, partial data gets returned and 'num_nodes'
+ *    gets updated to reflect the intended number.
+ *  - Otherwise, 'num_nodes' shall indicate the number of entries written, which
+ *    may be less than the input value.
  */
 
 struct xen_sysctl_numainfo {

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

Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Jan Beulich

... to match XEN_SYSCTL_cputopoinfo, allowing the caller to get what it needs (if e.g. it's after the data for just one specific node) with just one hypercall, without caring about the total number of nodes in the system.

One question:

xen/common/sysctl.c long do_sysctl(XEN_GUEST_HANDLE_PARAM(xe · line 333

Quoted 10 lines
xen/common/sysctl.c +1 -1
@@ -335,7 +329,7 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xe
         else
             i = num_nodes;
 
-        if ( (!ret || (ret == -ENOBUFS)) && (ni->num_nodes != i) )
+        if ( !ret && (ni->num_nodes != i) )
         {

Can't we kill the parentheses around the second argument of the && ?

Regards,
Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

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

#2 lore raw
Quoted 16 lines · Dario Faggioli
Quoted 8 lines · Jan Beulich

... to match XEN_SYSCTL_cputopoinfo, allowing the caller to get what it needs (if e.g. it's after the data for just one specific node) with just one hypercall, without caring about the total number of nodes in the system.

One question:

Quoted 3 lines
xen/common/sysctl.c +0 -0
Quoted 8 lines

xen/common/sysctl.c long do_sysctl(XEN_GUEST_HANDLE_PARAM(xe · line 333

Quoted 7 lines
xen/common/sysctl.c +1 -1
@@ -335,7 +329,7 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xe
         else
             i = num_nodes;
 
-        if ( (!ret || (ret == -ENOBUFS)) && (ni->num_nodes != i) )
+        if ( !ret && (ni->num_nodes != i) )
         {

Can't we kill the parentheses around the second argument of the && ?

No. The coding style requires binary operators as part of larger statements to have brackets.

~Andrew

#3 lore raw
Quoted 22 lines
Quoted 1 line
Quoted 1 line · On 14.07.15 at 14:43, <[email protected]> wrote:
Quoted 20 lines · Dario Faggioli
Quoted 8 lines · Jan Beulich

... to match XEN_SYSCTL_cputopoinfo, allowing the caller to get what it needs (if e.g. it's after the data for just one specific node) with just one hypercall, without caring about the total number of nodes in the system.

One question:

Quoted 7 lines
xen/common/sysctl.c +0 -0
@@ -335,7 +329,7 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xe
         else
             i = num_nodes;
 
Quoted 7 lines
Quoted 4 lines

xen/common/sysctl.c long do_sysctl(XEN_GUEST_HANDLE_PARAM(xe · line 333

Quoted 3 lines
xen/common/sysctl.c +1 -1
-        if ( (!ret || (ret == -ENOBUFS)) && (ni->num_nodes != i) )
+        if ( !ret && (ni->num_nodes != i) )
         {

Can't we kill the parentheses around the second argument of the && ?

No. The coding style requires binary operators as part of larger statements to have brackets.

I don't see it requires this, and I can't even find it recommending such - it just so happens that some people prefer using the extra parentheses. I personally dislike them for all operators where the precedence is "natural", i.e. here I wouldn't have added them if I had written the code anew. Since I modified existing code, I decided to retain previous style.

Jan