Main Page | Modules | Data Structures | File List | Data Fields | Globals

vserver.h

Go to the documentation of this file.
00001 /* $Id: vserver.h,v 1.59 2004/12/28 12:00:05 ensc Exp $
00002 
00003 *  Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
00004 *   
00005 *  This program is free software; you can redistribute it and/or modify
00006 *  it under the terms of the GNU General Public License as published by
00007 *  the Free Software Foundation; either version 2, or (at your option)
00008 *  any later version.
00009 *   
00010 *  This program is distributed in the hope that it will be useful,
00011 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 *  GNU General Public License for more details.
00014 *   
00015 *  You should have received a copy of the GNU General Public License
00016 *  along with this program; if not, write to the Free Software
00017 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018 */
00019 
00024 #ifndef H_VSERVER_SYSCALL_H
00025 #define H_VSERVER_SYSCALL_H
00026 
00027 #include <stdint.h>
00028 #include <stdlib.h>
00029 #include <stdbool.h>
00030 #include <sys/types.h>
00031 
00032 #ifndef IS_DOXYGEN
00033 #if defined(__GNUC__)
00034 #  define VC_ATTR_UNUSED                __attribute__((__unused__))
00035 #  define VC_ATTR_NORETURN              __attribute__((__noreturn__))
00036 #  define VC_ATTR_CONST                 __attribute__((__const__))
00037 #  define VC_ATTR_DEPRECATED            __attribute__((__deprecated__))
00038 #  if __GNUC__*0x10000 + __GNUC_MINOR__*0x100 + __GNUC_PATCHLEVEL__ >= 0x30300
00039 #    define VC_ATTR_NONNULL(ARGS)       __attribute__((__nonnull__ ARGS))
00040 #    define VC_ATTR_ALWAYSINLINE        __attribute__((__always_inline__))
00041 #  else
00042 #    define VC_ATTR_NONNULL(ARGS)
00043 #    define VC_ATTR_ALWAYSINLINE
00044 #  endif
00045 #  if __GNUC__*0x10000 + __GNUC_MINOR__*0x100 + __GNUC_PATCHLEVEL__ >= 0x30303
00046 #    define VC_ATTR_PURE                __attribute__((__pure__))
00047 #  else
00048 #    define VC_ATTR_PURE
00049 #  endif
00050 #else
00051 #  define VC_ATTR_NONNULL(ARGS)
00052 #  define VC_ATTR_UNUSED
00053 #  define VC_ATTR_NORETURN
00054 #  define VC_ATTR_ALWAYSINLINE
00055 #  define VC_ATTR_DEPRECATED
00056 #  define VC_ATTR_PURE
00057 #  define VC_ATTR_CONST
00058 #endif
00059 #endif  // IS_DOXYGEN
00060 
00062 #define VC_NOCTX                ((xid_t)(-1))
00063 #define VC_NOXID                ((xid_t)(-1))
00064 
00065 #define VC_DYNAMIC_XID          ((xid_t)(-1))
00066 
00067 #define VC_SAMECTX              ((xid_t)(-2))
00068 
00069 #define VC_NONID                ((nid_t)(-1))
00070 #define VC_DYNAMIC_NID          ((nid_t)(-1))
00071 
00072 #define VC_LIM_INFINITY         (~0ULL)
00073 #define VC_LIM_KEEP             (~1ULL)
00074 
00075   
00076 #ifndef S_CTX_INFO_LOCK
00077 #  define S_CTX_INFO_LOCK       1
00078 #endif
00079 
00080 #ifndef S_CTX_INFO_SCHED
00081 #  define S_CTX_INFO_SCHED      2
00082 #endif
00083 
00084 #ifndef S_CTX_INFO_NPROC
00085 #  define S_CTX_INFO_NPROC      4
00086 #endif
00087 
00088 #ifndef S_CTX_INFO_PRIVATE
00089 #  define S_CTX_INFO_PRIVATE    8
00090 #endif
00091 
00092 #ifndef S_CTX_INFO_INIT
00093 #  define S_CTX_INFO_INIT       16
00094 #endif
00095 
00096 #ifndef S_CTX_INFO_HIDEINFO
00097 #  define S_CTX_INFO_HIDEINFO   32
00098 #endif
00099 
00100 #ifndef S_CTX_INFO_ULIMIT
00101 #  define S_CTX_INFO_ULIMIT     64
00102 #endif
00103 
00104 #ifndef S_CTX_INFO_NAMESPACE
00105 #  define S_CTX_INFO_NAMESPACE  128
00106 #endif
00107 
00108 #define VC_CAP_CHOWN                     0
00109 #define VC_CAP_DAC_OVERRIDE              1
00110 #define VC_CAP_DAC_READ_SEARCH           2
00111 #define VC_CAP_FOWNER                    3
00112 #define VC_CAP_FSETID                    4
00113 #define VC_CAP_KILL                      5
00114 #define VC_CAP_SETGID                    6
00115 #define VC_CAP_SETUID                    7
00116 #define VC_CAP_SETPCAP                   8
00117 #define VC_CAP_LINUX_IMMUTABLE           9
00118 #define VC_CAP_NET_BIND_SERVICE         10
00119 #define VC_CAP_NET_BROADCAST            11
00120 #define VC_CAP_NET_ADMIN                12
00121 #define VC_CAP_NET_RAW                  13
00122 #define VC_CAP_IPC_LOCK                 14
00123 #define VC_CAP_IPC_OWNER                15
00124 #define VC_CAP_SYS_MODULE               16
00125 #define VC_CAP_SYS_RAWIO                17
00126 #define VC_CAP_SYS_CHROOT               18
00127 #define VC_CAP_SYS_PTRACE               19
00128 #define VC_CAP_SYS_PACCT                20
00129 #define VC_CAP_SYS_ADMIN                21
00130 #define VC_CAP_SYS_BOOT                 22
00131 #define VC_CAP_SYS_NICE                 23
00132 #define VC_CAP_SYS_RESOURCE             24
00133 #define VC_CAP_SYS_TIME                 25
00134 #define VC_CAP_SYS_TTY_CONFIG           26
00135 #define VC_CAP_MKNOD                    27
00136 #define VC_CAP_LEASE                    28
00137 #define VC_CAP_QUOTACTL                 29
00138 
00139 #define VC_IMMUTABLE_FILE_FL            0x0000010lu
00140 #define VC_IMMUTABLE_LINK_FL            0x0008000lu
00141 #define VC_IMMUTABLE_ALL                (VC_IMMUTABLE_LINK_FL|VC_IMMUTABLE_FILE_FL)
00142 
00143 #define VC_IATTR_XID                    0x01000000u
00144 
00145 #define VC_IATTR_ADMIN                  0x00000001u
00146 #define VC_IATTR_WATCH                  0x00000002u
00147 #define VC_IATTR_HIDE                   0x00000004u
00148 #define VC_IATTR_FLAGS                  0x00000007u
00149 
00150 #define VC_IATTR_BARRIER                0x00010000u
00151 #define VC_IATTR_IUNLINK                0x00020000u
00152 #define VC_IATTR_IMMUTABLE              0x00040000u
00153 
00154 
00155 // the flags
00156 #define VC_VXF_INFO_LOCK                0x00000001ull
00157 #define VC_VXF_INFO_NPROC               0x00000004ull
00158 #define VC_VXF_INFO_PRIVATE             0x00000008ull
00159 #define VC_VXF_INFO_INIT                0x00000010ull
00160 
00161 #define VC_VXF_INFO_HIDEINFO            0x00000020ull
00162 #define VC_VXF_INFO_ULIMIT              0x00000040ull
00163 #define VC_VXF_INFO_NAMESPACE           0x00000080ull
00164 
00165 #define VC_VXF_SCHED_HARD               0x00000100ull
00166 #define VC_VXF_SCHED_PRIO               0x00000200ull
00167 #define VC_VXF_SCHED_PAUSE              0x00000400ull
00168 
00169 #define VC_VXF_VIRT_MEM                 0x00010000ull
00170 #define VC_VXF_VIRT_UPTIME              0x00020000ull
00171 #define VC_VXF_VIRT_CPU                 0x00040000ull
00172 #define VC_VXF_VIRT_LOAD                0x00080000ull
00173 
00174 #define VC_VXF_HIDE_MOUNT               0x01000000ull
00175 #define VC_VXF_HIDE_NETIF               0x02000000ull
00176 
00177 #define VC_VXF_STATE_SETUP              (1ULL<<32)
00178 #define VC_VXF_STATE_INIT               (1ULL<<33)
00179 
00180 #define VC_VXF_FORK_RSS                 (1ULL<<48)
00181 #define VC_VXF_PROLIFIC                 (1ULL<<49)
00182 
00183 #define VC_VXF_IGNEG_NICE               (1ULL<<52)
00184 
00185 
00186 // the ccapabilities
00187 #define VC_VXC_SET_UTSNAME              0x00000001ull
00188 #define VC_VXC_SET_RLIMIT               0x00000002ull
00189 
00190 #define VC_VXC_RAW_ICMP                 0x00000100ull
00191 
00192 #define VC_VXC_SECURE_MOUNT             0x00010000ull
00193 #define VC_VXC_SECURE_REMOUNT           0x00020000ull
00194 
00195 
00196 #define VC_VXSM_FILL_RATE               0x0001
00197 #define VC_VXSM_INTERVAL                0x0002
00198 #define VC_VXSM_TOKENS                  0x0010
00199 #define VC_VXSM_TOKENS_MIN              0x0020
00200 #define VC_VXSM_TOKENS_MAX              0x0040
00201 #define VC_VXSM_PRIO_BIAS               0x0100
00202 
00203 
00204 
00214 #ifdef IS_DOXYGEN
00215 typedef an_unsigned_integer_type        xid_t;
00216 typedef an_unsigned_integer_type        nid_t;
00217 #endif
00218 
00219 #ifdef __cplusplus
00220 extern "C" {
00221 #endif
00222 
00223   struct vc_ip_mask_pair {
00224       uint32_t  ip;
00225       uint32_t  mask;
00226   };
00227 
00240   int   vc_syscall(uint32_t cmd, xid_t xid, void *data);
00241 
00246   int   vc_get_version();
00247   
00265   xid_t vc_new_s_context(xid_t ctx, unsigned int remove_cap, unsigned int flags);
00266 
00270   int   vc_set_ipv4root(uint32_t  bcast, size_t nb,
00271                         struct vc_ip_mask_pair const *ips) VC_ATTR_NONNULL((3));
00272 
00279   size_t        vc_get_nb_ipv4root() VC_ATTR_CONST VC_ATTR_PURE;
00280 
00292   xid_t vc_ctx_create(xid_t xid);
00293 
00299   int   vc_ctx_migrate(xid_t xid);
00300   
00301     /* rlimit related functions */
00302   
00312   typedef uint_least64_t        vc_limit_t;
00313 
00317   struct vc_rlimit {
00318       vc_limit_t        min;    
00319       vc_limit_t        soft;   
00320       vc_limit_t        hard;   
00321   };
00322 
00324   struct  vc_rlimit_mask {
00325       uint_least32_t    min;    
00326       uint_least32_t    soft;   
00327       uint_least32_t    hard;   
00328   };
00329 
00338   int   vc_get_rlimit(xid_t xid, int resource,
00339                       struct vc_rlimit       /*@out@*/ *lim) VC_ATTR_NONNULL((3));
00348   int   vc_set_rlimit(xid_t xid, int resource,
00349                       struct vc_rlimit const /*@in@*/  *lim) VC_ATTR_NONNULL((3));
00350   int   vc_get_rlimit_mask(xid_t xid,
00351                            struct vc_rlimit_mask *lim)       VC_ATTR_NONNULL((2));
00371   bool  vc_parseLimit(char const /*@in@*/ *str, vc_limit_t /*@out@*/ *res)      VC_ATTR_NONNULL((1,2));
00372 
00373 
00380   int   vc_ctx_kill(xid_t ctx, pid_t pid, int sig);
00381 
00382 
00383   struct vc_nx_info {
00384       nid_t     nid;
00385   };
00386 
00387   nid_t         vc_get_task_nid(pid_t pid);
00388   int           vc_get_nx_info(nid_t nid, struct vc_nx_info *) VC_ATTR_NONNULL((2));
00389 
00390   typedef enum { vcNET_IPV4, vcNET_IPV6, vcNET_IPV4R, vcNET_IPV6R }     vc_net_nx_type;
00391   
00392   struct vc_net_nx {
00393       vc_net_nx_type    type;
00394       size_t            count;
00395       uint32_t          ip;
00396       uint32_t          mask;
00397   };
00398 
00399   nid_t         vc_net_create(nid_t nid);
00400   int           vc_net_migrate(nid_t nid);
00401 
00402   int           vc_net_add(nid_t nid, struct vc_net_nx const *info);
00403   int           vc_net_remove(nid_t nid, struct vc_net_nx const *info);
00404 
00405   struct vc_net_flags {
00406       uint_least64_t    flagword;
00407       uint_least64_t    mask;
00408   };
00409   
00410   int           vc_get_nflags(nid_t, struct vc_net_flags *);
00411   int           vc_set_nflags(nid_t, struct vc_net_flags const *);
00412 
00413   
00414   struct vc_net_caps {
00415       uint_least64_t    ncaps;
00416       uint_least64_t    cmask;
00417   };
00418 
00419   int           vc_get_ncaps(nid_t, struct vc_net_caps *);
00420   int           vc_set_ncaps(nid_t, struct vc_net_caps const *);
00421 
00422 
00423   
00424 
00425   int           vc_set_iattr(char const *filename, xid_t xid,
00426                              uint_least32_t flags, uint_least32_t mask) VC_ATTR_NONNULL((1));
00427 
00454   int           vc_get_iattr(char const *filename, xid_t * /*@null@*/ xid,
00455                              uint_least32_t * /*@null@*/ flags,
00456                              uint_least32_t * /*@null@*/ mask) VC_ATTR_NONNULL((1));
00457 
00458   struct vc_vx_info {
00459       xid_t     xid;
00460       pid_t     initpid;
00461   };
00462   
00470   xid_t         vc_get_task_xid(pid_t pid);
00471   int           vc_get_vx_info(xid_t xid, struct vc_vx_info *info) VC_ATTR_NONNULL((2));
00472 
00473 
00474   typedef enum { vcVHI_CONTEXT, vcVHI_SYSNAME, vcVHI_NODENAME,
00475                  vcVHI_RELEASE, vcVHI_VERSION, vcVHI_MACHINE,
00476                  vcVHI_DOMAINNAME }             vc_uts_type;
00477   
00478   int           vc_set_vhi_name(xid_t xid, vc_uts_type type,
00479                                 char const *val, size_t len) VC_ATTR_NONNULL((3));
00480   int           vc_get_vhi_name(xid_t xid, vc_uts_type type,
00481                                 char *val, size_t len)       VC_ATTR_NONNULL((3));
00482 
00484   bool          vc_is_dynamic_xid(xid_t xid);
00485 
00486   int           vc_enter_namespace(xid_t xid);
00487   int           vc_set_namespace();
00488   int           vc_cleanup_namespace();
00489 
00490   
00493   struct  vc_ctx_flags {
00495       uint_least64_t    flagword;
00499       uint_least64_t    mask;
00500   };
00501 
00503   struct  vc_ctx_caps {
00505       uint_least64_t    bcaps;
00509       uint_least64_t    bmask;
00511       uint_least64_t    ccaps;
00515       uint_least64_t    cmask;
00516   };
00517 
00521   struct vc_err_listparser {
00522       char const        *ptr;           
00523       size_t            len;            
00524   };
00525  
00526   int                   vc_get_cflags(xid_t xid, struct vc_ctx_flags *)       VC_ATTR_NONNULL((2));
00527   int                   vc_set_cflags(xid_t xid, struct vc_ctx_flags const *) VC_ATTR_NONNULL((2));
00528 
00529   int                   vc_get_ccaps(xid_t xid, struct vc_ctx_caps *);
00530   int                   vc_set_ccaps(xid_t xid, struct vc_ctx_caps const *);
00531 
00542   uint_least64_t        vc_text2bcap(char const *str, size_t len);
00543 
00558   char const *  vc_lobcap2text(uint_least64_t *val) VC_ATTR_NONNULL((1));
00559 
00587   int                   vc_list2bcap(char const *str, size_t len,
00588                                      struct vc_err_listparser *err,
00589                                      struct vc_ctx_caps *cap) VC_ATTR_NONNULL((1,4));
00590 
00591   uint_least64_t        vc_text2ccap(char const *, size_t len);
00592   char const *          vc_loccap2text(uint_least64_t *);
00593   int                   vc_list2ccap(char const *, size_t len,
00594                                      struct vc_err_listparser *err,
00595                                      struct vc_ctx_caps *);
00596 
00597   int                   vc_list2cflag(char const *, size_t len,
00598                                      struct vc_err_listparser *err,
00599                                      struct vc_ctx_flags *flags);
00600   uint_least64_t        vc_text2cflag(char const *, size_t len);
00601   char const *          vc_locflag2text(uint_least64_t *);
00602   
00603   uint_least32_t        vc_list2cflag_compat(char const *, size_t len,
00604                                             struct vc_err_listparser *err);
00605   uint_least32_t        vc_text2cflag_compat(char const *, size_t len);
00606   char const *          vc_hicflag2text_compat(uint_least32_t);
00607 
00608   int                   vc_text2cap(char const *);
00609   char const *          vc_cap2text(unsigned int);
00610 
00611   
00612   int                   vc_list2nflag(char const *, size_t len,
00613                                      struct vc_err_listparser *err,
00614                                      struct vc_net_flags *flags);
00615   uint_least64_t        vc_text2nflag(char const *, size_t len);
00616   char const *          vc_lonflag2text(uint_least64_t *);
00617 
00618   uint_least64_t        vc_text2ncap(char const *, size_t len);
00619   char const *          vc_loncap2text(uint_least64_t *);
00620   int                   vc_list2ncap(char const *, size_t len,
00621                                      struct vc_err_listparser *err,
00622                                      struct vc_net_caps *);
00623 
00624   uint_least64_t                vc_get_insecurebcaps() VC_ATTR_CONST;
00625   inline static uint_least64_t  vc_get_insecureccaps() {
00626     return ~(VC_VXC_SET_UTSNAME|VC_VXC_RAW_ICMP);
00627   }
00628   
00629   inline static int     vc_setfilecontext(char const *filename, xid_t xid) {
00630     return vc_set_iattr(filename, xid, 0, VC_IATTR_XID);
00631   }
00632   
00646   xid_t         vc_getfilecontext(char const *filename) VC_ATTR_NONNULL((1));
00647 
00648 
00649   struct vc_set_sched {
00650       uint_least32_t    set_mask;
00651       int_least32_t     fill_rate;
00652       int_least32_t     interval;
00653       int_least32_t     tokens;
00654       int_least32_t     tokens_min;
00655       int_least32_t     tokens_max;
00656       int_least32_t     priority_bias;
00657   };
00658 
00659   int           vc_set_sched(xid_t xid, struct vc_set_sched const *);
00660   
00661   
00662   typedef enum { vcFEATURE_VKILL,  vcFEATURE_IATTR,   vcFEATURE_RLIMIT,
00663                  vcFEATURE_COMPAT, vcFEATURE_MIGRATE, vcFEATURE_NAMESPACE,
00664                  vcFEATURE_SCHED,  vcFEATURE_VINFO,   vcFEATURE_VHI,
00665                  vcFEATURE_VSHELPER0, vcFEATURE_VSHELPER }
00666     vcFeatureSet;
00667 
00668   bool          vc_isSupported(vcFeatureSet) VC_ATTR_CONST;
00669   bool          vc_isSupportedString(char const *);
00670 
00671   /* The management part */
00672 
00673 #define VC_LIMIT_VSERVER_NAME_LEN       1024
00674   
00675   typedef enum { vcCFG_NONE, vcCFG_AUTO,
00676                  vcCFG_LEGACY,
00677                  vcCFG_RECENT_SHORT,
00678                  vcCFG_RECENT_FULL }            vcCfgStyle;
00679 
00680 
00682   xid_t         vc_xidopt2xid(char const *, bool honor_static, char const **err_info);
00683 
00684   vcCfgStyle    vc_getVserverCfgStyle(char const *id);
00685   
00688   char *        vc_getVserverName(char const *id, vcCfgStyle style);
00689 
00694   char *        vc_getVserverCfgDir(char const *id, vcCfgStyle style);
00695 
00699   char *        vc_getVserverAppDir(char const *id, vcCfgStyle style, char const *app);
00700 
00703   char *        vc_getVserverVdir(char const *id, vcCfgStyle style, bool physical);
00704 
00712   xid_t         vc_getVserverCtx(char const *id, vcCfgStyle style,
00713                                  bool honor_static, bool /*@null@*/ *is_running);
00714 
00719   char *        vc_getVserverByCtx(xid_t ctx, /*@null@*/vcCfgStyle *style,
00720                                    /*@null@*/char const *revdir);
00721 
00722 #define vcSKEL_INTERFACES       1u
00723 #define vcSKEL_PKGMGMT          2u
00724 #define vcSKEL_FILESYSTEM       4u
00725   
00728   int           vc_createSkeleton(char const *id, vcCfgStyle style, int flags);
00729   
00730 #ifdef __cplusplus
00731 }
00732 #endif
00733 
00734 #undef VC_ATTR_PURE
00735 #undef VC_ATTR_ALWAYSINLINE
00736 #undef VC_ATTR_NORETURN
00737 #undef VC_ATTR_UNUSED
00738 #undef VC_ATTR_NONNULL
00739 
00740 #endif

Generated on Fri Jan 28 17:47:53 2005 for util-vserver (libvserver) by  doxygen 1.4.1