create_context(xid_t ctx, uint64_t bcaps, struct sliver_resources *slr)
{
struct vc_ctx_caps vc_caps;
- struct vc_net_nx vc_net;
struct vc_net_flags vc_nf;
/* Create network context */
- if (vc_net_create(ctx) == VC_NOCTX)
+ if (vc_net_create(ctx) == VC_NOCTX) {
+ if (errno == EEXIST)
+ goto process;
return -1;
+ }
/* Make the network context persistent */
vc_nf.mask = vc_nf.flagword = VC_NXF_PERSISTENT;
if (vc_set_nflags(ctx, &vc_nf))
return -1;
- /* XXX: Allow access to all IPv4 addresses (for now) */
- vc_net.type = vcNET_IPV4;
- vc_net.count = 1;
- vc_net.ip[0] = 0;
- vc_net.mask[0] = 0;
- if (vc_net_add(ctx, &vc_net) == -1)
- return -1;
-
+process:
/*
* Create context info - this sets the STATE_SETUP and STATE_INIT flags.
*/
int retry_count = 0;
int net_migrated = 0;
+ pl_set_ulimits(slr);
+
for (;;)
{
struct vc_ctx_flags vc_flags;
return -1;
/* context doesn't exist - create it */
- if (create_context(ctx, bcaps,slr))
+ if (create_context(ctx, bcaps, slr))
{
if (errno == EEXIST)
/* another process beat us in a race */
{"rlimits/openfd.soft", &slr->vs_openfd.soft},
{"rlimits/openfd.min", &slr->vs_openfd.min},
- {"whitelisted", &slr->vs_whitelisted},
-
{"bcapabilities", NULL},
{0,0}
};
slr->vs_openfd.soft = VC_LIM_KEEP;
slr->vs_openfd.min = VC_LIM_KEEP;
- slr->vs_whitelisted = 1;
-
slr->vs_capabilities.bcaps = 0;
slr->vs_capabilities.bmask = 0;
slr->vs_capabilities.ccaps = 0;
return adjusted;
}
+static inline void
+set_one_ulimit(int resource, struct vc_rlimit *limit)
+{
+ struct rlimit lim;
+ getrlimit(resource, &lim);
+ adjust_lim(limit, &lim);
+ setrlimit(resource, &lim);
+}
+
+void
+pl_set_ulimits(struct sliver_resources *slr)
+{
+ if (!slr)
+ return;
+
+ set_one_ulimit(RLIMIT_RSS, &slr->vs_rss);
+ set_one_ulimit(RLIMIT_AS, &slr->vs_as);
+ set_one_ulimit(RLIMIT_NPROC, &slr->vs_nproc);
+ set_one_ulimit(RLIMIT_NOFILE, &slr->vs_openfd);
+}
+
void
pl_set_limits(xid_t ctx, struct sliver_resources *slr)
{
- struct rlimit lim; /* getrlimit values */
unsigned long long vs_cpu;
uint32_t cpu_sched_flags;
if (slr != 0) {
/* set memory limits */
- getrlimit(RLIMIT_RSS,&lim);
- if (adjust_lim(&slr->vs_rss, &lim)) {
- setrlimit(RLIMIT_RSS, &lim);
- if (vc_set_rlimit(ctx, RLIMIT_RSS, &slr->vs_rss))
- {
- PERROR("pl_setrlimit(%u, RLIMIT_RSS)", ctx);
- exit(1);
- }
+ if (vc_set_rlimit(ctx, RLIMIT_RSS, &slr->vs_rss)) {
+ PERROR("pl_setrlimit(%u, RLIMIT_RSS)", ctx);
+ exit(1);
}
/* set address space limits */
- getrlimit(RLIMIT_AS,&lim);
- if (adjust_lim(&slr->vs_as, &lim)) {
- setrlimit(RLIMIT_AS, &lim);
- if (vc_set_rlimit(ctx, RLIMIT_AS, &slr->vs_as))
- {
- PERROR("pl_setrlimit(%u, RLIMIT_AS)", ctx);
- exit(1);
- }
+ if (vc_set_rlimit(ctx, RLIMIT_AS, &slr->vs_as)) {
+ PERROR("pl_setrlimit(%u, RLIMIT_AS)", ctx);
+ exit(1);
}
+
/* set nrpoc limit */
- getrlimit(RLIMIT_NPROC,&lim);
- if (adjust_lim(&slr->vs_nproc, &lim)) {
- setrlimit(RLIMIT_NPROC, &lim);
- if (vc_set_rlimit(ctx, RLIMIT_NPROC, &slr->vs_nproc))
- {
- PERROR("pl_setrlimit(%u, RLIMIT_NPROC)", ctx);
- exit(1);
- }
+ if (vc_set_rlimit(ctx, RLIMIT_NPROC, &slr->vs_nproc)) {
+ PERROR("pl_setrlimit(%u, RLIMIT_NPROC)", ctx);
+ exit(1);
}
/* set openfd limit */
- getrlimit(RLIMIT_NOFILE,&lim);
- if (adjust_lim(&slr->vs_openfd, &lim)) {
- setrlimit(RLIMIT_NOFILE, &lim);
- if (vc_set_rlimit(ctx, RLIMIT_NOFILE, &slr->vs_openfd))
- {
- PERROR("pl_setrlimit(%u, RLIMIT_NOFILE)", ctx);
- exit(1);
- }
- if (vc_set_rlimit(ctx, VC_VLIMIT_OPENFD, &slr->vs_openfd))
- {
- PERROR("pl_setrlimit(%u, VLIMIT_OPENFD)", ctx);
- exit(1);
- }
+ if (vc_set_rlimit(ctx, RLIMIT_NOFILE, &slr->vs_openfd)) {
+ PERROR("pl_setrlimit(%u, RLIMIT_NOFILE)", ctx);
+ exit(1);
+ }
+ if (vc_set_rlimit(ctx, VC_VLIMIT_OPENFD, &slr->vs_openfd)) {
+ PERROR("pl_setrlimit(%u, VLIMIT_OPENFD)", ctx);
+ exit(1);
}
+
vs_cpu = slr->vs_cpu;
cpu_sched_flags = slr->vs_cpuguaranteed & VS_SCHED_CPU_GUARANTEED;