void shut_down(void) { free_modules(); memset(&conf, 0, sizeof(struct configure)); memset(&mods, 0, sizeof(struct module) * MAX_MOD_NUM); memset(&statis, 0, sizeof(struct statistic)); }
asmlinkage int sys_delete_module(char *module_name) { struct module *mp; char name[MOD_MAX_NAME]; int error; if (!suser()) return -EPERM; /* else */ if (module_name != NULL) { if ((error = get_mod_name(module_name, name)) != 0) return error; if ((mp = find_module(name)) == NULL) return -ENOENT; if ((mp->ref != NULL) || ((GET_USE_COUNT(mp) & ~(MOD_AUTOCLEAN | MOD_VISITED)) != 0)) return -EBUSY; GET_USE_COUNT(mp) &= ~(MOD_AUTOCLEAN | MOD_VISITED); if (mp->state == MOD_RUNNING) (*mp->cleanup)(); mp->state = MOD_DELETED; free_modules(); } /* for automatic reaping */ else { struct module *mp_next; for (mp = module_list; mp != &kernel_module; mp = mp_next) { mp_next = mp->next; if ((mp->ref == NULL) && (mp->state == MOD_RUNNING) && ((GET_USE_COUNT(mp) & ~MOD_VISITED) == MOD_AUTOCLEAN)) { if ((GET_USE_COUNT(mp) & MOD_VISITED)) { /* Don't reap until one "cycle" after last _use_ */ GET_USE_COUNT(mp) &= ~MOD_VISITED; } else { GET_USE_COUNT(mp) &= ~(MOD_AUTOCLEAN | MOD_VISITED); (*mp->cleanup)(); mp->state = MOD_DELETED; free_modules(); } } } } return 0; }
void usage(int rc) { struct mod_action mod; FILE *fp = rc ? stderr : stdout; version(fp); fprintf(fp, "Copyright (C) 2000-2008, Parallels, Inc.\n"); fprintf(fp, "This program may be distributed under the terms of the GNU GPL License.\n\n"); fprintf(fp, "Usage: vzctl [options] <command> <veid> [parameters]\n" "vzctl destroy | mount | umount | stop | restart | status | enter <veid>\n" "vzctl create <veid> [--ostemplate <name>] [--config <name>]\n" " [--private <path>] [--root <path>] [--ipadd <addr>] | [--hostname <name>]\n" "vzctl start <veid> [--force] [--wait]\n" "vzctl exec | exec2 <veid> <command> [arg ...]\n" "vzctl runscript <veid> <script>\n" "vzctl chkpnt <veid> [--dumpfile <name>]\n" "vzctl restore <veid> [--dumpfile <name>]\n" "vzctl set <veid> [--save] [--setmode restart|ignore]\n" " [--ipadd <addr>] [--ipdel <addr>|all] [--hostname <name>]\n" " [--nameserver <addr>] [--searchdomain <name>] [--onboot yes|no]\n" " [--userpasswd <user>:<passwd>] [--cpuunits <N>] [--cpulimit <N>] [--cpus <N>]\n" " [--diskspace <soft>[:<hard>]] [--diskinodes <soft>[:<hard>]]\n" " [--quotatime <N>] [--quotaugidlimit <N>]\n" " [--noatime yes|no] [--capability <name>:on|off ...]\n" " [--devices b|c:major:minor|all:r|w|rw]\n" " [--devnodes device:r|w|rw|none]\n" " [--netif_add <ifname[,mac,host_ifname,host_mac]]>] [--netif_del <ifname>]\n" " [--applyconfig <name>] [--applyconfig_map <name>]\n" " [--features <name:on|off>] [--name <vename>]\n" " [--ioprio <N>]\n"); fprintf(fp, " [--iptables <name>] [--disabled <yes|no>]\n"); fprintf(fp, " [UBC parameters]\n" "UBC parameters (N - items, P - pages, B - bytes):\n" "Two numbers divided by colon means barrier:limit.\n" "In case the limit is not given it is set to the same value as the barrier.\n" " --numproc N[:N] --numtcpsock N[:N] --numothersock N[:N]\n" " --vmguarpages P[:P] --kmemsize B[:B] --tcpsndbuf B[:B]\n" " --tcprcvbuf B[:B] --othersockbuf B[:B] --dgramrcvbuf B[:B]\n" " --oomguarpages P[:P] --lockedpages P[:P] --privvmpages P[:P]\n" " --shmpages P[:P] --numfile N[:N] --numflock N[:N]\n" " --numpty N[:N] --numsiginfo N[:N] --dcachesize N[:N]\n" " --numiptent N[:N] --physpages P[:P] --avnumproc N[:N]\n"); memset(&mod, 0, sizeof(mod)); set_log_level(0); init_modules(&mod, NULL); mod_print_usage(&mod); free_modules(&mod); exit(rc); }
asmlinkage int sys_delete_module(char *module_name) { struct module *mp; char name[MOD_MAX_NAME]; int error; if (!suser()) return -EPERM; if (module_name != NULL) { if ((error = get_mod_name(module_name, name)) != 0) return error; if ((mp = find_module(name)) == NULL) return -ENOENT; if (mp->state == MOD_RUNNING) (*mp->cleanup)(); mp->state = MOD_DELETED; } free_modules(); return 0; }
int main(int argc, char *argv[]) { if (argc < 2) return (-1); const char *mod = argv[1]; int fd = -1; init_modules(); polysome *p = get_module(mod); if (p == NULL) { printf("%s invalid\n", mod); } else { printf("%s valid\n", p->name); ovvar_t ov; memset(&ov, 0, sizeof(ov)); init_ov(&ov); printf("path %s\n", ov.path); p->ss(&ov); printf("path %s be read\n", ov.fpath); printf("ov.a: %d, ov.b: %d\n", ov.a, ov.b); p->gs(&ov); for (rci_t i = 0; i < (ov.a + ov.b); i ++) printf("%ld ", ov.signature[i]); printf("\n"); free_ov(&ov); } free_modules(); return (0); }
/* * Initialize a module. */ asmlinkage int sys_init_module(char *module_name, char *code, unsigned codesize, struct mod_routines *routines) { struct module *mp; char name[MOD_MAX_NAME]; int error; struct mod_routines rt; if (!suser()) return -EPERM; /* * First reclaim any memory from dead modules that where not * freed when deleted. Should I think be done by timers when * the module was deleted - Jon. */ free_modules(); if ((error = get_mod_name(module_name, name)) != 0) return error; printk( "initializing module `%s', %d (0x%x) bytes\n", name, codesize, codesize); memcpy_fromfs(&rt, routines, sizeof rt); if ((mp = find_module(name)) == NULL) return -ENOENT; if ((codesize + sizeof (int) + 4095) / 4096 > mp->size) return -EINVAL; memcpy_fromfs((char *)mp->addr + sizeof (int), code, codesize); memset((char *)mp->addr + sizeof (int) + codesize, 0, mp->size * 4096 - (codesize + sizeof (int))); printk( " init entry @ 0x%08lx, cleanup entry @ 0x%08lx\n", (unsigned long) rt.init, (unsigned long) rt.cleanup); mp->cleanup = rt.cleanup; if ((*rt.init)() != 0) return -EBUSY; mp->state = MOD_RUNNING; return 0; }
static void usage(int rc) { struct mod_action mod; FILE *fp = rc ? stderr : stdout; version(fp); fprintf(fp, "Copyright (C) 2000-2013, Parallels, Inc.\n" "This program may be distributed under the terms of the GNU GPL License.\n" "\n" "Usage: vzctl [options] <command> <ctid> [parameters]\n" "\n" "vzctl create <ctid> [--ostemplate <name>] [--config <name>]\n" " [--layout ploop|simfs] [--hostname <name>] [--name <name>] [--ipadd <addr>]\n" " [--diskspace <kbytes>] [--private <path>] [--root <path>]\n" " [--local_uid <UID>] [--local_gid <GID>]\n" "vzctl start <ctid> [--force] [--wait] [--skip-fsck]\n" "vzctl destroy | mount | umount | stop | restart | status <ctid>\n" #ifdef HAVE_PLOOP "vzctl convert <ctid> [--layout ploop[:mode]]\n" "vzctl compact <ctid>\n" "vzctl snapshot <ctid> [--id <uuid>] [--name <name>] [--description <desc>]\n" " [--skip-suspend]\n" "vzctl snapshot-switch | snapshot-delete <ctid> --id <uuid>\n" "vzctl snapshot-mount <ctid> --id <uuid> --target <dir>\n" "vzctl snapshot-umount <ctid> --id <uuid>\n" "vzctl snapshot-list <ctid> [-H] [-o field[,field...]] [--id <uuid>]\n" #endif "vzctl quotaon | quotaoff | quotainit <ctid>\n" "vzctl console <ctid> [ttyno]\n" "vzctl enter <ctid> [--exec <command> [arg ...]]\n" "vzctl exec | exec2 <ctid> <command> [arg ...]\n" "vzctl runscript <ctid> <script>\n" "vzctl suspend | resume <ctid> [--dumpfile <name>]\n" "vzctl set <ctid> [--save] [--force] [--setmode restart|ignore]\n" " [--ram <bytes>[KMG]] [--swap <bytes>[KMG]]\n" " [--ipadd <addr>] [--ipdel <addr>|all] [--hostname <name>]\n" " [--nameserver <addr>] [--searchdomain <name>]\n" " [--onboot yes|no] [--bootorder <N>]\n" " [--userpasswd <user>:<passwd>]\n" " [--cpuunits <N>] [--cpulimit <N>] [--cpus <N>] [--cpumask <cpus>]\n" " [--diskspace <soft>[:<hard>]] [--diskinodes <soft>[:<hard>]]\n" " [--quotatime <N>] [--quotaugidlimit <N>] [--mount_opts <opt>[,<opt>...]]\n" " [--capability <name>:on|off ...]\n" " [--devices b|c:major:minor|all:r|w|rw]\n" " [--devnodes device:r|w|rw|none]\n" " [--netif_add <ifname[,mac,host_ifname,host_mac,bridge]]>]\n" " [--netif_del <ifname>]\n" " [--applyconfig <name>] [--applyconfig_map <name>]\n" " [--features <name:on|off>] [--name <vename>]\n" " [--ioprio <N>] [--iolimit <N>] --iopslimit <N>\n" " [--pci_add [<domain>:]<bus>:<slot>.<func>] [--pci_del <d:b:s.f>]\n" " [--iptables <name>] [--disabled <yes|no>]\n" " [--stop-timeout <seconds>\n" " [UBC parameters]\n" "\n" "UBC parameters (N - items, P - pages, B - bytes):\n" "Two numbers divided by colon means barrier:limit.\n" "In case the limit is not given it is set to the same value as the barrier.\n" " --numproc N[:N] --numtcpsock N[:N] --numothersock N[:N]\n" " --vmguarpages P[:P] --kmemsize B[:B] --tcpsndbuf B[:B]\n" " --tcprcvbuf B[:B] --othersockbuf B[:B] --dgramrcvbuf B[:B]\n" " --oomguarpages P[:P] --lockedpages P[:P] --privvmpages P[:P]\n" " --shmpages P[:P] --numfile N[:N] --numflock N[:N]\n" " --numpty N[:N] --numsiginfo N[:N] --dcachesize N[:N]\n" " --numiptent N[:N] --physpages P[:P] --avnumproc N[:N]\n" " --swappages P[:P]\n" ); memset(&mod, 0, sizeof(mod)); set_log_level(0); init_modules(&mod, NULL); mod_print_usage(&mod); free_modules(&mod); exit(rc); }
int main(int argc, char *argv[], char *envp[]) { act_t action = -1; int verbose = 0; int verbose_custom = 0; int quiet = 0; int veid, ret, skiplock = 0; char buf[256]; vps_param *gparam = NULL, *vps_p = NULL, *cmd_p = NULL; const char *action_nm; struct sigaction act; char *name = NULL, *opt; _proc_title = argv[0]; _proc_title_len = envp[0] - argv[0]; gparam = init_vps_param(); vps_p = init_vps_param(); cmd_p = init_vps_param(); sigemptyset(&act.sa_mask); act.sa_handler = SIG_IGN; act.sa_flags = 0; sigaction(SIGPIPE, &act, NULL); while (argc > 1) { opt = argv[1]; if (!strcmp(opt, "--verbose")) { verbose++; verbose_custom = 1; } else if (!strcmp(opt, "--quiet")) quiet = 1; else if (!strcmp(opt, "--version")) { version(stdout); exit(0); } else if (!strcmp(opt, "--skiplock")) skiplock = YES; else break; argc--; argv++; } if (argc <= 1) usage(VZ_INVALID_PARAMETER_SYNTAX); action_nm = argv[1]; init_log(NULL, 0, 1, verbose, quiet, NULL); if (!strcmp(argv[1], "set")) { init_modules(&g_action, "set"); action = ACTION_SET; } else if (!strcmp(argv[1], "create")) { init_modules(&g_action, "create"); action = ACTION_CREATE; } else if (!strcmp(argv[1], "start")) { init_modules(&g_action, "set"); action = ACTION_START; } else if (!strcmp(argv[1], "stop")) { init_modules(&g_action, "set"); action = ACTION_STOP; } else if (!strcmp(argv[1], "restart")) { action = ACTION_RESTART; } else if (!strcmp(argv[1], "destroy") || !strcmp(argv[1], "delete")) { action = ACTION_DESTROY; } else if (!strcmp(argv[1], "mount")) { action = ACTION_MOUNT; } else if (!strcmp(argv[1], "umount")) { action = ACTION_UMOUNT; } else if (!strcmp(argv[1], "exec3")) { action = ACTION_EXEC3; } else if (!strcmp(argv[1], "exec2")) { action = ACTION_EXEC2; } else if (!strcmp(argv[1], "exec")) { action = ACTION_EXEC; } else if (!strcmp(argv[1], "runscript")) { action = ACTION_RUNSCRIPT; } else if (!strcmp(argv[1], "enter")) { action = ACTION_ENTER; } else if (!strcmp(argv[1], "console")) { action = ACTION_CONSOLE; #ifdef HAVE_PLOOP } else if (!strcmp(argv[1], "convert")) { action = ACTION_CONVERT; } else if (!strcmp(argv[1], "compact")) { action = ACTION_COMPACT; #endif } else if (!strcmp(argv[1], "status")) { action = ACTION_STATUS; quiet = 1; } else if (!strcmp(argv[1], "suspend") || !strcmp(argv[1], "chkpnt")) { action = ACTION_SUSPEND; } else if (!strcmp(argv[1], "resume") || !strcmp(argv[1], "restore")) { action = ACTION_RESUME; } else if (!strcmp(argv[1], "quotaon")) { action = ACTION_QUOTAON; } else if (!strcmp(argv[1], "quotaoff")) { action = ACTION_QUOTAOFF; } else if (!strcmp(argv[1], "quotainit")) { action = ACTION_QUOTAINIT; #ifdef HAVE_PLOOP } else if (!strcmp(argv[1], "snapshot")) { action = ACTION_SNAPSHOT_CREATE; } else if (!strcmp(argv[1], "snapshot-switch")) { action = ACTION_SNAPSHOT_SWITCH; } else if (!strcmp(argv[1], "snapshot-delete")) { action = ACTION_SNAPSHOT_DELETE; } else if (!strcmp(argv[1], "snapshot-list")) { action = ACTION_SNAPSHOT_LIST; } else if (!strcmp(argv[1], "snapshot-mount")) { action = ACTION_SNAPSHOT_MOUNT; } else if (!strcmp(argv[1], "snapshot-umount")) { action = ACTION_SNAPSHOT_UMOUNT; #endif } else if (!strcmp(argv[1], "--help")) { usage(0); } else { init_modules(&g_action, action_nm); action = ACTION_CUSTOM; if (!g_action.mod_count) { fprintf(stderr, "Bad command: %s\n", argv[1]); ret = VZ_INVALID_PARAMETER_SYNTAX; goto error; } } if (argc < 3) { fprintf(stderr, "CT ID missing\n"); ret = VZ_INVALID_PARAMETER_VALUE; goto error; } if (parse_int(argv[2], &veid)) { name = strdup(argv[2]); veid = get_veid_by_name(name); } if (veid < 0 || veid > VEID_MAX) { fprintf(stderr, "Bad CT ID %s\n", argv[2]); ret = VZ_INVALID_PARAMETER_VALUE; goto error; } argc -= 2; argv += 2; /* getopt_long() prints argv[0] when reporting errors */ argv[0] = _proc_title; /* Read global config file */ if (vps_parse_config(veid, GLOBAL_CFG, gparam, &g_action)) { ret = VZ_NOCONFIG; goto error; } init_log(gparam->log.log_file, veid, gparam->log.enable != NO, gparam->log.level, quiet, "vzctl"); /* Set verbose level from global config if not overwriten by --verbose */ if (!verbose_custom && gparam->log.verbose != NULL) { verbose = *gparam->log.verbose; verbose_custom = 1; } if (verbose < -1) verbose = -1; if (verbose_custom) set_log_verbose(verbose); if ((ret = parse_action_opt(veid, action, argc, argv, cmd_p, action_nm))) { goto error; } if (veid == 0 && action != ACTION_SET) { fprintf(stderr, "Only set actions are allowed for CT0\n"); ret = VZ_INVALID_PARAMETER_VALUE; goto error; } else if (veid < 0) { fprintf(stderr, "Bad CT ID %d\n", veid); ret = VZ_INVALID_PARAMETER_VALUE; goto error; } get_vps_conf_path(veid, buf, sizeof(buf)); if (stat_file(buf) == 1) { if (vps_parse_config(veid, buf, vps_p, &g_action)) { ret = VZ_NOCONFIG; goto error; } if (name != NULL && vps_p->res.name.name != NULL && strcmp(name, vps_p->res.name.name)) { logger(-1, 0, "Unable to find container by name %s", name); ret = VZ_INVALID_PARAMETER_VALUE; goto error; } } else if (action != ACTION_CREATE && action != ACTION_STATUS && action != ACTION_SET) { logger(-1, 0, "Container config file does not exist"); ret = VZ_NOVECONFIG; goto error; } merge_vps_param(gparam, vps_p); merge_global_param(cmd_p, gparam); ret = run_action(veid, action, gparam, vps_p, cmd_p, argc, argv, skiplock); error: free_modules(&g_action); free_vps_param(gparam); free_vps_param(vps_p); free_vps_param(cmd_p); free_log(); free(name); return ret; }
int main(int argc, char *argv[], char *envp[]) { int action = 0; int verbose = 0; int verbose_tmp; int verbose_custom = 0; int quiet = 0; int veid, ret, skiplock = 0; char buf[256]; vps_param *gparam = NULL, *vps_p = NULL, *cmd_p = NULL; const char *action_nm; struct sigaction act; char *name = NULL, *opt; _proc_title = argv[0]; _proc_title_len = envp[0] - argv[0]; gparam = init_vps_param(); vps_p = init_vps_param(); cmd_p = init_vps_param(); sigemptyset(&act.sa_mask); act.sa_handler = SIG_IGN; act.sa_flags = 0; sigaction(SIGPIPE, &act, NULL); while (argc > 1) { opt = argv[1]; if (!strcmp(opt, "--verbose")) { if (argc > 2 && !parse_int(argv[2], &verbose_tmp)) { verbose += verbose_tmp; argc--; argv++; } else { verbose++; } verbose_custom = 1; } else if (!strncmp(opt, "--verbose=", 10)) { if (parse_int(opt + 10, &verbose_tmp)) { fprintf(stderr, "Invalid value for" " --verbose\n"); exit(VZ_INVALID_PARAMETER_VALUE); } verbose += verbose_tmp; verbose_custom = 1; } else if (!strcmp(opt, "--quiet")) quiet = 1; else if (!strcmp(opt, "--version")) { version(stdout); exit(0); } else if (!strcmp(opt, "--skiplock")) skiplock = YES; else break; argc--; argv++; } if (argc <= 1) usage(VZ_INVALID_PARAMETER_SYNTAX); action_nm = argv[1]; init_log(NULL, 0, 1, verbose, 0, NULL); if (!strcmp(argv[1], "set")) { init_modules(&g_action, "set"); action = ACTION_SET; // status = ST_SET; } else if (!strcmp(argv[1], "create")) { init_modules(&g_action, "create"); action = ACTION_CREATE; // status = ST_CREATE; } else if (!strcmp(argv[1], "start")) { init_modules(&g_action, "set"); action = ACTION_START; // status = ST_START; } else if (!strcmp(argv[1], "stop")) { init_modules(&g_action, "set"); action = ACTION_STOP; // status = ST_STOP; } else if (!strcmp(argv[1], "restart")) { action = ACTION_RESTART; // status = ST_RESTART; } else if (!strcmp(argv[1], "destroy")) { action = ACTION_DESTROY; // status = ST_DESTROY; } else if (!strcmp(argv[1], "mount")) { action = ACTION_MOUNT; // status = ST_MOUNT; } else if (!strcmp(argv[1], "umount")) { action = ACTION_UMOUNT; // status = ST_UMOUNT; } else if (!strcmp(argv[1], "exec3")) { action = ACTION_EXEC3; } else if (!strcmp(argv[1], "exec2")) { action = ACTION_EXEC2; } else if (!strcmp(argv[1], "exec")) { action = ACTION_EXEC; } else if (!strcmp(argv[1], "runscript")) { action = ACTION_RUNSCRIPT; } else if (!strcmp(argv[1], "enter")) { action = ACTION_ENTER; } else if (!strcmp(argv[1], "status")) { action = ACTION_STATUS; quiet = 1; } else if (!strcmp(argv[1], "chkpnt")) { action = ACTION_CHKPNT; } else if (!strcmp(argv[1], "restore")) { action = ACTION_RESTORE; } else if (!strcmp(argv[1], "quotaon")) { action = ACTION_QUOTAON; } else if (!strcmp(argv[1], "quotaoff")) { action = ACTION_QUOTAOFF; } else if (!strcmp(argv[1], "quotainit")) { action = ACTION_QUOTAINIT; } else if (!strcmp(argv[1], "--help")) { usage(0); } else { init_modules(&g_action, action_nm); action = ACTION_CUSTOM; if (!g_action.mod_count) { fprintf(stderr, "Bad command: %s\n", argv[1]); ret = VZ_INVALID_PARAMETER_SYNTAX; goto error; } } if (argc < 3) { fprintf(stderr, "CT ID missing\n"); ret = VZ_INVALID_PARAMETER_VALUE; goto error; } if (parse_int(argv[2], &veid)) { name = strdup(argv[2]); veid = get_veid_by_name(name); if (veid < 0) { fprintf(stderr, "Bad CT ID %s\n", argv[2]); ret = VZ_INVALID_PARAMETER_VALUE; goto error; } } argc -= 2; argv += 2; /* Read global config file */ if (vps_parse_config(veid, GLOBAL_CFG, gparam, &g_action)) { fprintf(stderr, "Global configuration file %s not found\n", GLOBAL_CFG); ret = VZ_NOCONFIG; goto error; } init_log(gparam->log.log_file, veid, gparam->log.enable != NO, gparam->log.level, quiet, "vzctl"); /* Set verbose level from global config if not overwriten by --verbose */ if (!verbose_custom && gparam->log.verbose != NULL) { verbose = *gparam->log.verbose; verbose_custom = 1; } if (verbose < -1) verbose = -1; if (verbose_custom) set_log_verbose(verbose); if ((ret = parse_action_opt(veid, action, argc, argv, cmd_p, action_nm))) { goto error; } if (veid == 0 && action != ACTION_SET) { fprintf(stderr, "Only set actions are allowed for CT0\n"); ret = VZ_INVALID_PARAMETER_VALUE; goto error; } else if (veid < 0) { fprintf(stderr, "Bad CT ID %d\n", veid); ret = VZ_INVALID_PARAMETER_VALUE; goto error; } get_vps_conf_path(veid, buf, sizeof(buf)); if (stat_file(buf)) { if (vps_parse_config(veid, buf, vps_p, &g_action)) { logger(-1, 0, "Error in config file %s", buf); ret = VZ_NOCONFIG; goto error; } if (name != NULL && vps_p->res.name.name != NULL && strcmp(name, vps_p->res.name.name)) { logger(-1, 0, "Unable to find container by name %s", name); ret = VZ_INVALID_PARAMETER_VALUE; goto error; } } else if (action != ACTION_CREATE && action != ACTION_STATUS && action != ACTION_SET) { logger(-1, 0, "Container config file does not exist"); ret = VZ_NOVECONFIG; goto error; } merge_vps_param(gparam, vps_p); merge_global_param(cmd_p, gparam); ret = run_action(veid, action, gparam, vps_p, cmd_p, argc-1, argv+1, skiplock); error: free_modules(&g_action); free_vps_param(gparam); free_vps_param(vps_p); free_vps_param(cmd_p); free_log(); if (name != NULL) free(name); return ret; }