contd...
[util-vserver-pl.git] / src / planetlab.h
1 /* Copyright 2005 Princeton University
2
3 Redistribution and use in source and binary forms, with or without
4 modification, are permitted provided that the following conditions
5 are met: 
6
7     * Redistributions of source code must retain the above copyright
8       notice, this list of conditions and the following disclaimer.
9       
10     * Redistributions in binary form must reproduce the above
11       copyright notice, this list of conditions and the following
12       disclaimer in the documentation and/or other materials provided
13       with the distribution.
14       
15     * Neither the name of the copyright holder nor the names of its
16       contributors may be used to endorse or promote products derived
17       from this software without specific prior written permission.
18       
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PRINCETON
23 UNIVERSITY OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26 OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
29 WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE. 
31
32 */
33
34 #ifndef _LIB_PLANETLAB_H_
35 #define _LIB_PLANETLAB_H_
36
37 #ifndef VC_VXF_SCHED_SHARE
38 #  define VC_VXF_SCHED_SHARE    0x00000800ull
39 #endif
40
41 #define VC_VXF_SCHED_FLAGS  (VC_VXF_SCHED_HARD | VC_VXF_SCHED_SHARE)
42
43 struct sliver_resources {
44   unsigned long long vs_cpu;
45   struct vc_rlimit vs_rss;
46   struct vc_rlimit vs_as;
47   struct vc_rlimit vs_nproc;
48   struct vc_rlimit vs_openfd;
49   unsigned long int personality;
50 };
51
52 int adjust_lim(const struct vc_rlimit *vcr, struct rlimit *lim);
53
54 int
55 pl_chcontext(xid_t ctx, uint64_t bcaps, const struct sliver_resources *slr);
56
57 int
58 pl_setup_done(xid_t ctx);
59
60 int
61 pl_setsched(xid_t ctx, uint32_t cpu_min, uint32_t cpu_share);
62
63 /* Null byte made explicit */
64 #define NULLBYTE_SIZE                    1
65
66 void pl_get_limits(const char *, struct sliver_resources *);
67 int pl_set_ulimits(const struct sliver_resources *);
68
69 static inline int
70 _PERROR(const char *format, char *file, int line, int _errno, ...)
71 {
72         va_list ap;
73
74         va_start(ap, _errno);
75         fprintf(stderr, "%s:%d: ", file, line);
76         vfprintf(stderr, format, ap);
77         if (_errno)
78                 fprintf(stderr, ": %s (%d)", strerror(_errno), _errno);
79         fputs("\n", stderr);
80         fflush(stderr);
81
82         return _errno;
83 }
84
85 #define PERROR(format, args...) _PERROR(format, __FILE__, __LINE__, errno, ## args)
86 #endif