Changeset 613

Show
Ignore:
Timestamp:
05/27/07 00:32:04 (2 years ago)
Author:
chtekk
Message:

Complete CPUSET support:
- update TODO
- add vce vx.cpuset.{get,remove,set} commands
- add vxdb.vx.cpuset.{get,remove,set} methods
- add vx_cpuset table to VXDB
- add functions to validate cpus and mems for a CPUSET
- add creation/destruction of CPUSETs to helper.{startup,shutdown}

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/TODO

    r598 r613  
    88WANTED FEATURES: 
    99- vx.move method to also move the VServer around on the disk 
    10 - cpuset support 
    1110- sysctl support 
  • trunk/src/vcc/vce/Makefile.am

    r561 r613  
    3131                   vx_bcaps.c \ 
    3232                   vx_ccaps.c \ 
     33                   vx_cpuset.c \ 
    3334                   vx_flags.c \ 
    3435                   vx_limit.c \ 
  • trunk/src/vcc/vce/cmd.c

    r595 r613  
    4545        { "vx.ccaps.get",        cmd_vx_ccaps_get }, 
    4646        { "vx.ccaps.remove",     cmd_vx_ccaps_remove }, 
     47        { "vx.cpuset.get",       cmd_vx_cpuset_get }, 
     48        { "vx.cpuset.remove",    cmd_vx_cpuset_remove }, 
     49        { "vx.cpuset.set",       cmd_vx_cpuset_set }, 
    4750        { "vx.flags.add",        cmd_vx_flags_add }, 
    4851        { "vx.flags.get",        cmd_vx_flags_get }, 
     
    104107                        "   vx.limit.set        <name> <limit> <soft> [<max>]\n" 
    105108                        "\n" 
     109                        "   vx.cpuset.get        <name>\n" 
     110                        "   vx.cpuset.remove     <name>\n" 
     111                        "   vx.cpuset.set        <name> <cpus> <mems> [<virtualize>]\n" 
     112                        "\n" 
    106113                        "   vx.sched.get        <name> [<cpuid>]\n" 
    107114                        "   vx.sched.remove     <name> [<cpuid>]\n" 
  • trunk/src/vcc/vce/cmd.h

    r561 r613  
    4242void cmd_vx_ccaps_get       (xmlrpc_env *env, int argc, char **argv); 
    4343void cmd_vx_ccaps_remove    (xmlrpc_env *env, int argc, char **argv); 
     44void cmd_vx_cpuset_get      (xmlrpc_env *env, int argc, char **argv); 
     45void cmd_vx_cpuset_remove   (xmlrpc_env *env, int argc, char **argv); 
     46void cmd_vx_cpuset_set      (xmlrpc_env *env, int argc, char **argv); 
    4447void cmd_vx_flags_add       (xmlrpc_env *env, int argc, char **argv); 
    4548void cmd_vx_flags_get       (xmlrpc_env *env, int argc, char **argv); 
  • trunk/src/vcd/methods.c

    r589 r613  
    144144        MREGISTER("vxdb.vx.ccaps.get",        m_vxdb_vx_ccaps_get); 
    145145        MREGISTER("vxdb.vx.ccaps.remove",     m_vxdb_vx_ccaps_remove); 
     146        MREGISTER("vxdb.vx.cpuset.get",       m_vxdb_vx_cpuset_get); 
     147        MREGISTER("vxdb.vx.cpuset.remove",    m_vxdb_vx_cpuset_remove); 
     148        MREGISTER("vxdb.vx.cpuset.set",       m_vxdb_vx_cpuset_set); 
    146149        MREGISTER("vxdb.vx.flags.add",        m_vxdb_vx_flags_add); 
    147150        MREGISTER("vxdb.vx.flags.get",        m_vxdb_vx_flags_get); 
  • trunk/src/vcd/methods.h

    r589 r613  
    188188MPROTO(m_vxdb_vx_ccaps_get); 
    189189MPROTO(m_vxdb_vx_ccaps_remove); 
     190MPROTO(m_vxdb_vx_cpuset_get); 
     191MPROTO(m_vxdb_vx_cpuset_remove); 
     192MPROTO(m_vxdb_vx_cpuset_set); 
    190193MPROTO(m_vxdb_vx_flags_add); 
    191194MPROTO(m_vxdb_vx_flags_get); 
  • trunk/src/vcd/methods/Makefile.am

    r589 r613  
    8282         vxdb/vxdb_vx_ccaps_get.c \ 
    8383         vxdb/vxdb_vx_ccaps_remove.c \ 
     84         vxdb/vxdb_vx_cpuset_get.c \ 
     85         vxdb/vxdb_vx_cpuset_remove.c \ 
     86         vxdb/vxdb_vx_cpuset_set.c \ 
    8487         vxdb/vxdb_vx_flags_add.c \ 
    8588         vxdb/vxdb_vx_flags_get.c \ 
  • trunk/src/vcd/methods/helper/helper_shutdown.c

    r611 r613  
    2525 
    2626#include <lucid/log.h> 
     27#include <lucid/misc.h> 
     28#include <lucid/printf.h> 
    2729 
    2830/* helper.shutdown(int xid) */ 
     
    4749        if (!(name = vxdb_getname(xid))) 
    4850                method_return_fault(env, MENOVPS); 
     51 
     52        /* Remove the cpuset on shutdown, if it exists */ 
     53        if (ismount("/dev/cpuset")) { 
     54                char *cpusetpath; 
     55 
     56                asprintf(&cpusetpath, "/dev/cpuset/xid%d", xid); 
     57 
     58                if (isdir(cpusetpath)) 
     59                        rmdir(cpusetpath); 
     60        } 
    4961 
    5062        rc = vxdb_exec("DELETE FROM restart WHERE xid = %d", xid); 
  • trunk/src/vcd/methods/helper/helper_startup.c

    r557 r613  
    3535#include <lucid/log.h> 
    3636#include <lucid/mem.h> 
     37#include <lucid/misc.h> 
    3738#include <lucid/open.h> 
    3839#include <lucid/printf.h> 
     
    4445   2) setup disk limits 
    4546   3) setup resource limits 
    46    4) setup scheduler 
    47    5) setup unames 
    48    6) setup filesystem namespace 
     47   4) setup cpuset 
     48   5) setup scheduler 
     49   6) setup unames 
     50   7) setup filesystem namespace 
    4951*/ 
    5052 
     
    313315 
    314316static 
     317xmlrpc_value *context_cpuset(xmlrpc_env *env) 
     318{ 
     319        LOG_TRACEME 
     320 
     321        /* We need the cpuset fs mounted */ 
     322        if (ismount("/dev/cpuset")) { 
     323                char *cpusetpath; 
     324                int rc; 
     325 
     326                asprintf(&cpusetpath, "/dev/cpuset/xid%d", xid); 
     327 
     328                /* First remove the cpuset, if it exists */ 
     329                if (isdir(cpusetpath)) 
     330                        rmdir(cpusetpath); 
     331 
     332                /* Then query the database */ 
     333                rc = vxdb_prepare(&dbr, 
     334                                "SELECT cpus,mems,virtualize " 
     335                                "FROM vx_cpuset WHERE xid = %d", 
     336                                xid); 
     337 
     338                if (rc != VXDB_OK) 
     339                        method_return_vxdb_fault(env); 
     340 
     341                /* Lastly setup the new cpuset (or do nothing) */ 
     342                rc = vxdb_step(dbr); 
     343 
     344                if (rc == VXDB_ROW) { 
     345                        if (!isdir(cpusetpath)) 
     346                                mkdir(cpusetpath, 0755); 
     347 
     348                        int cscpusfd; 
     349                        char *cscpus = str_path_concat(cpusetpath, "/cpus"); 
     350 
     351                        if ((cscpusfd = open_append(cscpus)) == -1) { 
     352                                method_set_sys_faultf(env, "open_append(%s)", cscpus); 
     353                        } 
     354 
     355                        else { 
     356                                dprintf(cscpusfd, "%s", vxdb_column_text(dbr, 0)); 
     357                                close(cscpusfd); 
     358                        } 
     359 
     360                        int csmemsfd; 
     361                        char *csmems = str_path_concat(cpusetpath, "/mems"); 
     362 
     363                        if ((csmemsfd = open_append(csmems)) == -1) { 
     364                                method_set_sys_faultf(env, "open_append(%s)", csmems); 
     365                        } 
     366 
     367                        else { 
     368                                dprintf(csmemsfd, "%s", vxdb_column_text(dbr, 1)); 
     369                                close(csmemsfd); 
     370                        } 
     371 
     372                        int csvirtfd; 
     373                        char *csvirt = str_path_concat(cpusetpath, "/virtualize"); 
     374 
     375                        if (ispath(csvirt)) { 
     376                                if ((csvirtfd = open_append(csvirt)) == -1) { 
     377                                        method_set_sys_faultf(env, "open_append(%s)", csvirt); 
     378                                } 
     379 
     380                                else { 
     381                                        dprintf(csvirtfd, "%d", vxdb_column_int(dbr, 2)); 
     382                                        close(csvirtfd); 
     383                                } 
     384                        } 
     385                } 
     386 
     387                else if (rc != VXDB_DONE) 
     388                        method_set_vxdb_fault(env); 
     389 
     390                vxdb_finalize(dbr); 
     391        } 
     392 
     393        return NULL; 
     394} 
     395 
     396static 
    315397xmlrpc_value *context_scheduler(xmlrpc_env *env) 
    316398{ 
     
    374456 
    375457        vxdb_finalize(dbr); 
     458 
    376459        return NULL; 
    377460} 
     
    623706        method_return_if_fault(env); 
    624707 
     708        context_cpuset(env); 
     709        method_return_if_fault(env); 
     710 
    625711        context_scheduler(env); 
    626712        method_return_if_fault(env); 
  • trunk/src/vcd/methods/vxdb/vxdb_vx_sched_remove.c

    r610 r613  
    5252         * since it has special meaning in helper.startup */ 
    5353        if (cpuid == -2) 
    54                 rc = vxdb_exec("DELETE FROM vx_sched WHERE xid = %d", 
     54                rc = vxdb_exec( 
     55                                "DELETE FROM vx_sched WHERE xid = %d", 
    5556                                xid); 
    5657 
  • trunk/src/vcd/validate.c

    r597 r613  
    1717 
    1818#include <unistd.h> 
     19#include <stdlib.h> 
     20#include <dirent.h> 
    1921 
    2022#include "lists.h" 
     
    2325#include <lucid/addr.h> 
    2426#include <lucid/log.h> 
     27#include <lucid/scanf.h> 
    2528#include <lucid/str.h> 
     29#include <lucid/strtok.h> 
     30 
     31static 
     32int max_mem_node(void) 
     33{ 
     34        DIR *ndir; 
     35        struct dirent *dent; 
     36        int maxmemnode = 0; 
     37 
     38        ndir = opendir("/sys/devices/system/node"); 
     39        if (!ndir) 
     40                return 0; 
     41 
     42        while ((dent = readdir(ndir))) { 
     43                if (str_cmpn(dent->d_name, "node", 4)) 
     44                        continue; 
     45 
     46                int node = atoi(dent->d_name+4); 
     47                if (maxmemnode < node) 
     48                        maxmemnode = node; 
     49        } 
     50 
     51        closedir(ndir); 
     52 
     53        return maxmemnode; 
     54} 
    2655 
    2756static 
     
    153182} 
    154183 
     184int validate_cpuset(const char *cpuset, int type) 
     185{ 
     186        LOG_TRACEME 
     187 
     188        if (str_isempty(cpuset)) 
     189                return 0; 
     190 
     191        int cpusetlen = str_len(cpuset)-1; 
     192 
     193        if (str_cmpn(cpuset, ",", 1) == 0 || str_cmpn(cpuset+cpusetlen, ",", 1) == 0) 
     194                return 0; 
     195 
     196        strtok_t _st, *st = &_st, *p; 
     197 
     198        if (!strtok_init_str(st, cpuset, ",", 0)) 
     199                return 0; 
     200 
     201        int maxcpus = 0, maxmems = 0; 
     202 
     203        if (type == 0) 
     204                maxcpus = sysconf(_SC_NPROCESSORS_ONLN); 
     205        else if (type == 1) 
     206                maxmems = max_mem_node(); 
     207        else 
     208                return 0; 
     209 
     210        int errorout = 0; 
     211 
     212        strtok_for_each(st, p) { 
     213                if (!str_isdigit(p->token)) { 
     214                        errorout = 1; 
     215                        break; 
     216                } 
     217 
     218                int id; 
     219                sscanf(p->token, "%d", &id); 
     220 
     221                if (type == 0) { 
     222                        if (!(id >= 0 && id < maxcpus)) { 
     223                                errorout = 1; 
     224                                break; 
     225                        } 
     226                } 
     227 
     228                else if (type == 1) { 
     229                        if (!(id >= 0 && id <= maxmems)) { 
     230                                errorout = 1; 
     231                                break; 
     232                        } 
     233                } 
     234 
     235                else { 
     236                        errorout = 1; 
     237                        break; 
     238                } 
     239        } 
     240 
     241        strtok_free(st); 
     242 
     243        return (errorout == 0) ? 1 : 0; 
     244} 
     245 
    155246int validate_uname(const char *uname) 
    156247{ 
  • trunk/src/vcd/validate.h

    r551 r613  
    5151                          int tokensmin, int tokensmax); 
    5252 
     53int validate_cpuset(const char *cpuset, int type); 
     54 
    5355int validate_uname(const char *uname); 
    5456int validate_uname_value(const char *value); 
  • trunk/src/vcd/vxdb-tables.h

    r561 r613  
    8989VXDB_UNIQUE_NEW(vx_ccaps, "xid,ccap") 
    9090 
     91VXDB_COLUMNS_NEW(vx_cpuset, "xid", "cpus", "mems", "virtualize") 
     92VXDB_UNIQUE_NEW(vx_cpuset, "xid") 
     93 
    9194VXDB_COLUMNS_NEW(vx_flags, "xid", "flag") 
    9295VXDB_UNIQUE_NEW(vx_flags, "xid,flag") 
     
    128131VXDB_TABLE_NEW(vx_bcaps) 
    129132VXDB_TABLE_NEW(vx_ccaps) 
     133VXDB_TABLE_NEW(vx_cpuset) 
    130134VXDB_TABLE_NEW(vx_flags) 
    131135VXDB_TABLE_NEW(vx_limit)