~ubuntu-branches/ubuntu/karmic/vzctl/karmic

« back to all changes in this revision

Viewing changes to src/vzctl.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2007-04-10 18:08:16 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070410180816-0uuzj9fnna7gmzxv
Tags: 3.0.16-4
Etch has been released which means that this version can be uploaded
to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *  Copyright (C) 2000-2006 SWsoft. All rights reserved.
 
2
 *  Copyright (C) 2000-2007 SWsoft. All rights reserved.
3
3
 *
4
4
 *  This program is free software; you can redistribute it and/or modify
5
5
 *  it under the terms of the GNU General Public License as published by
43
43
int parse_action_opt(envid_t veid, int action, int argc, char *argv[],
44
44
        vps_param *param, const char *name);
45
45
int run_action(envid_t veid, int action, vps_param *g_p, vps_param *vps_p,
46
 
        vps_param *cmd_p, int argc, char **argv, int skiplock);
 
46
        vps_param *cmd_p, int argc, char **argv, int skiplock);
47
47
 
48
48
void version()
49
49
{
55
55
        struct mod_action mod;
56
56
 
57
57
        version();
58
 
        fprintf(stdout, "Copyright (C) 2000-2005 SWsoft.\n");
 
58
        fprintf(stdout, "Copyright (C) 2000-2007 SWsoft.\n");
59
59
        fprintf(stdout, "This program may be distributed under the terms of the GNU GPL License.\n\n");
60
60
        fprintf(stdout, "Usage: vzctl [options] <command> <veid> [parameters]\n"
61
61
"vzctl destroy | mount | umount | stop | status | enter <veid>\n"
62
62
"vzctl create <veid> {--ostemplate <name>] [--config <name>]\n"
63
63
"   [--private <path>] [--root <path>] [--ipadd <addr>] | [--hostname <name>]\n"
64
 
"vzctl start <veid> [--force]\n"
 
64
"vzctl start <veid> [--force] [--wait]\n"
65
65
"vzctl exec | exec2 <veid> <command> [arg ...]\n"
66
66
"vzctl runscript <veid> <script>\n"
67
 
"vzctl chkpnt <vpsid> [--dumpfile <name>]\n"
68
 
"vzctl restore <vpsid> [--dumpfile <name>]\n"
 
67
"vzctl chkpnt <veid> [--dumpfile <name>]\n"
 
68
"vzctl restore <veid> [--dumpfile <name>]\n"
69
69
"vzctl set veid [--save] [--setmode restart|ignore]\n"
70
70
"   [--ipadd <addr>] [--ipdel <addr>|all] [--hostname <name>]\n"
71
71
"   [--nameserver <addr>] [--searchdomain <name>] [--onboot yes|no]\n"
75
75
"   [--noatime yes|no] [--capability <name>:on|off ...]\n"
76
76
"   [--devices b|c:major:minor|all:r|w|rw]\n"
77
77
"   [--devnodes device:r|w|rw|none]\n"
78
 
"   [--veth_add dev_name,dev_addr,dev_name_vps,dev_addr_vps]\n"
79
 
"   [--veth_del dev_name]\n"
80
 
"   [--applyconfig <name>]\n");
81
 
 
 
78
"   [--netif_add <ifname[,mac,host_ifname,host_mac]]>] [--netif_del <ifname>]\n"
 
79
"   [--applyconfig <name>] [--applyconfig_map <name>]\n"
 
80
"   [--features <name:on|off>] [--name <vename>]\n"
 
81
"   [--ioprio <N>]\n");
 
82
 
 
83
 
82
84
        fprintf(stdout, "   [--iptables <name>] [--disabled <yes|no>]\n");
83
85
        fprintf(stdout, "   [UBC parameters]\n"
84
86
"UBC parameters (N - items, P - pages, B - bytes):\n"
102
104
{
103
105
        int action = 0;
104
106
        int verbose = 0;
 
107
        int verbose_tmp;
 
108
        int verbose_custom = 0;
105
109
        int quiet = 0;
106
110
        int veid, ret, skiplock = 0;
107
111
        char buf[256];
108
112
        vps_param *gparam = NULL, *vps_p = NULL, *cmd_p = NULL;
109
113
        const char *action_nm;
110
114
        struct sigaction act;
 
115
        char *name = NULL, *opt;
111
116
 
112
117
        _proc_title = argv[0];
113
118
        _proc_title_len = envp[0] - argv[0];
122
127
        sigaction(SIGPIPE, &act, NULL);
123
128
 
124
129
        while (argc > 1) {
125
 
                if (!strcmp(argv[1], "--verbose")) {
126
 
                        verbose = 2;
127
 
                } else if (!strcmp(argv[1], "--quiet"))
 
130
                opt = argv[1];
 
131
 
 
132
                if (!strcmp(opt, "--verbose")) {
 
133
                        if (argc > 2 &&
 
134
                            !parse_int(argv[2], &verbose_tmp))
 
135
                        {
 
136
                                verbose += verbose_tmp;
 
137
                                argc--; argv++;
 
138
                        } else {
 
139
                                verbose++;
 
140
                        }
 
141
                        verbose_custom = 1;
 
142
                } else if (!strncmp(opt, "--verbose=", 10)) {
 
143
                        if (parse_int(opt + 10, &verbose_tmp)) {
 
144
                                fprintf(stderr, "Invalid value for"
 
145
                                        " --verbose\n");
 
146
                                exit(VZ_INVALID_PARAMETER_VALUE);
 
147
                        }
 
148
                        verbose += verbose_tmp;
 
149
                        verbose_custom = 1;
 
150
                } else if (!strcmp(opt, "--quiet"))
128
151
                        quiet = 1;
129
 
                else if (!strcmp(argv[1], "--version")) {
 
152
                else if (!strcmp(opt, "--version")) {
130
153
                        version();
131
154
                        exit(0);
132
 
                } else if (!strcmp(argv[1], "--skiplock"))
 
155
                } else if (!strcmp(opt, "--skiplock"))
133
156
                        skiplock = YES;
134
157
                else
135
158
                        break;
205
228
                }
206
229
        }
207
230
        if (argc < 3) {
208
 
                fprintf(stderr, "VPS id is not given\n");
 
231
                fprintf(stderr, "VE id is not given\n");
209
232
                ret = VZ_INVALID_PARAMETER_VALUE;
210
233
                goto error;
211
234
        }
212
235
        if (parse_int(argv[2], &veid)) {
213
 
                veid = get_veid_by_name(argv[2]);
 
236
                name = strdup(argv[2]);
 
237
                veid = get_veid_by_name(name);
214
238
                if (veid < 0) {
215
 
                        fprintf(stderr, "Bad VPS id %s\n", argv[2]);
 
239
                        fprintf(stderr, "Bad VE id %s\n", argv[2]);
216
240
                        ret = VZ_INVALID_PARAMETER_VALUE;
217
241
                        goto error;
218
242
                }
226
250
                goto error;
227
251
        }
228
252
        init_log(gparam->log.log_file, veid, gparam->log.enable != NO,
229
 
                verbose ? gparam->log.level + 2 : gparam->log.level,
230
 
                quiet, "vzctl");
 
253
                gparam->log.level, quiet, "vzctl");
 
254
        /* Set verbose level from global config if not overwriten
 
255
           by --verbose 
 
256
        */
 
257
        if (!verbose_custom && gparam->log.verbose != NULL) {
 
258
                verbose = *gparam->log.verbose;
 
259
                verbose_custom = 1;
 
260
        }
 
261
        if (verbose < -1)
 
262
                verbose = -1;
 
263
        if (verbose_custom)
 
264
                set_log_verbose(verbose);
231
265
        if ((ret = parse_action_opt(veid, action, argc, argv, cmd_p,
232
266
                action_nm)))
233
267
        {
238
272
                ret = VZ_INVALID_PARAMETER_VALUE;
239
273
                goto error;
240
274
        } else if (veid < 0) {
241
 
                fprintf(stderr, "Bad VPS id %d\n", veid);
 
275
                fprintf(stderr, "Bad VE id %d\n", veid);
242
276
                ret = VZ_INVALID_PARAMETER_VALUE;
243
277
                goto error;
244
278
        }
245
279
        get_vps_conf_path(veid, buf, sizeof(buf));
246
280
        if (stat_file(buf)) {
247
281
                if (vps_parse_config(veid, buf, vps_p, &g_action)) {
248
 
                        logger(0, 0, "Error in config file %s",
 
282
                        logger(-1, 0, "Error in config file %s",
249
283
                                buf);
250
 
                        exit(VZ_NOCONFIG);
251
 
                }
 
284
                        ret = VZ_NOCONFIG;
 
285
                        goto error;
 
286
                }
 
287
                if (name != NULL &&
 
288
                    vps_p->res.name.name != NULL &&
 
289
                    strcmp(name, vps_p->res.name.name))
 
290
                {
 
291
                        logger(-1, 0, "Unable to find VE by name %s", name);
 
292
                        ret = VZ_INVALID_PARAMETER_VALUE;
 
293
                        goto error;
 
294
                }
252
295
        } else if (action != ACTION_CREATE &&
253
296
                        action != ACTION_STATUS &&
254
297
                        action != ACTION_SET)
255
298
        {
256
 
                logger(0, 0, "VPS config file does not exist");
 
299
                logger(-1, 0, "VE config file does not exist");
257
300
                ret = VZ_NOVECONFIG;
258
301
                goto error;
259
302
        }
268
311
        free_vps_param(vps_p);
269
312
        free_vps_param(cmd_p);
270
313
        free_log();
 
314
        if (name != NULL) free(name);
271
315
 
272
316
        return ret;
273
317
}