Tagging module util-vserver-pl - util-vserver-pl-0.3-6
[util-vserver-pl.git] / src / planetlab.c
index 1c6cbcc..9a3e571 100644 (file)
@@ -48,11 +48,22 @@ POSSIBILITY OF SUCH DAMAGE.
 #include "vserver.h"
 #include "planetlab.h"
 
+#ifndef VC_NXC_RAW_SOCKET
+#  define VC_NXC_RAW_SOCKET    0x00000200ull
+#endif
+#ifndef VC_NXC_RAW_SEND
+#  define VC_NXC_RAW_SEND      0x00000400ull
+#endif
+#ifndef VC_NXF_LBACK_ALLOW
+#  define VC_NXF_LBACK_ALLOW   0x00000400ull
+#endif
+
 static int
 create_context(xid_t ctx, uint64_t bcaps)
 {
-  struct vc_ctx_caps  vc_caps;
+  struct vc_ctx_caps   vc_caps;
   struct vc_net_flags  vc_nf;
+  struct vc_net_caps   vc_ncaps;
 
   /* Create network context */
   if (vc_net_create(ctx) == VC_NOCTX) {
@@ -62,10 +73,15 @@ create_context(xid_t ctx, uint64_t bcaps)
   }
 
   /* Make the network context persistent */
-  vc_nf.mask = vc_nf.flagword = VC_NXF_PERSISTENT;
+  vc_nf.mask = vc_nf.flagword = VC_NXF_PERSISTENT | VC_NXF_LBACK_ALLOW;
   if (vc_set_nflags(ctx, &vc_nf))
     return -1;
 
+  /* Give it raw sockets capabilities */
+  vc_ncaps.ncaps = vc_ncaps.cmask = VC_NXC_RAW_ICMP | VC_NXC_RAW_SOCKET;
+  if (vc_set_ncaps(ctx, &vc_ncaps))
+    return -1;
+
 tag:
   /* Create tag context */
   if (vc_tag_create(ctx) == VC_NOCTX)
@@ -86,7 +102,7 @@ process:
   if (vc_set_ccaps(ctx, &vc_caps))
     return -1;
 
-  if (pl_setsched(ctx, 1, 0) < 0) {
+  if (pl_setsched(ctx, 0, 1) < 0) {
     PERROR("pl_setsched(%u)", ctx);
     exit(1);
   }
@@ -183,38 +199,33 @@ do                                                \
 while (0)
 
 int
-pl_setsched(xid_t ctx, uint32_t cpu_share, uint32_t cpu_sched_flags)
+pl_setsched(xid_t ctx, uint32_t cpu_min, uint32_t cpu_share)
 {
   struct vc_set_sched  vc_sched;
   struct vc_ctx_flags  vc_flags;
-  uint32_t  new_flags;
 
   vc_sched.set_mask = (VC_VXSM_FILL_RATE | VC_VXSM_INTERVAL | VC_VXSM_TOKENS |
                       VC_VXSM_TOKENS_MIN | VC_VXSM_TOKENS_MAX | VC_VXSM_MSEC |
-                      VC_VXSM_FILL_RATE2 | VC_VXSM_INTERVAL2 | VC_VXSM_FORCE |
-                      VC_VXSM_IDLE_TIME);
-  vc_sched.fill_rate = 0;
-  vc_sched.fill_rate2 = cpu_share;  /* tokens accumulated per interval */
-  vc_sched.interval = vc_sched.interval2 = 1000;  /* milliseconds */
+                      VC_VXSM_FILL_RATE2 | VC_VXSM_INTERVAL2 | VC_VXSM_FORCE);
+  vc_sched.fill_rate = cpu_min; /* percent reserved */
+  vc_sched.interval = 100;
+  vc_sched.fill_rate2 = cpu_share; /* best-effort fair share of unreserved */
+  vc_sched.interval2 = 1000;  /* milliseconds */
   vc_sched.tokens = 100;     /* initial allocation of tokens */
   vc_sched.tokens_min = 50;  /* need this many tokens to run */
   vc_sched.tokens_max = 100;  /* max accumulated number of tokens */
 
-  if (cpu_share == (uint32_t)VC_LIM_KEEP)
-    vc_sched.set_mask &= ~(VC_VXSM_FILL_RATE|VC_VXSM_FILL_RATE2);
-
-  /* guaranteed CPU corresponds to SCHED_SHARE flag being cleared */
-  if (cpu_sched_flags & VS_SCHED_CPU_GUARANTEED) {
-    new_flags = 0;
-    vc_sched.fill_rate = vc_sched.fill_rate2;
+  if (cpu_share) {
+    if (cpu_share == (uint32_t)VC_LIM_KEEP)
+      vc_sched.set_mask &= ~(VC_VXSM_FILL_RATE|VC_VXSM_FILL_RATE2);
+    else
+      vc_sched.set_mask |= VC_VXSM_IDLE_TIME;
   }
-  else
-    new_flags = VC_VXF_SCHED_SHARE;
 
   VC_SYSCALL(vc_set_sched(ctx, &vc_sched));
 
   vc_flags.mask = VC_VXF_SCHED_FLAGS;
-  vc_flags.flagword = new_flags | VC_VXF_SCHED_HARD;
+  vc_flags.flagword = VC_VXF_SCHED_HARD;
   VC_SYSCALL(vc_set_cflags(ctx, &vc_flags));
 
   return 0;