~ubuntu-branches/ubuntu/vivid/slurm-llnl/vivid

« back to all changes in this revision

Viewing changes to src/scontrol/update_node.c

  • Committer: Bazaar Package Importer
  • Author(s): Gennaro Oliva
  • Date: 2009-09-24 23:28:15 UTC
  • mfrom: (1.1.11 upstream) (3.2.4 sid)
  • Revision ID: james.westby@ubuntu.com-20090924232815-enh65jn32q1ebg07
Tags: 2.0.5-1
* New upstream release 
* Changed dependecy from lib-mysqlclient15 to lib-mysqlclient 
* Added Default-Start for runlevel 2 and 4 and $remote_fs requirement in
  init.d scripts (Closes: #541252)
* Postinst checks for wrong runlevels 2 and 4 links
* Upgraded to standard version 3.8.3
* Add lintian overrides for missing slurm-llnl-configurator.html in doc
  base registration
* modified postrm scripts to ignore pkill return value in order to avoid
  postrm failure when no slurm process is running
* Checking for slurmctld.pid before cancelling running and pending
  jobs during package removal 

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 *  Copyright (C) 2002-2007 The Regents of the University of California.
5
5
 *  Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
6
6
 *  Written by Morris Jette <jette1@llnl.gov>
7
 
 *  LLNL-CODE-402394.
 
7
 *  CODE-OCEC-09-009. All rights reserved.
8
8
 *  
9
9
 *  This file is part of SLURM, a resource management program.
10
 
 *  For details, see <http://www.llnl.gov/linux/slurm/>.
 
10
 *  For details, see <https://computing.llnl.gov/linux/slurm/>.
 
11
 *  Please also read the included file: DISCLAIMER.
11
12
 *  
12
13
 *  SLURM is free software; you can redistribute it and/or modify it under
13
14
 *  the terms of the GNU General Public License as published by the Free
49
50
scontrol_update_node (int argc, char *argv[]) 
50
51
{
51
52
        int i, j, k, rc = 0, update_cnt = 0;
 
53
 
52
54
        uint16_t state_val;
53
55
        update_node_msg_t node_msg;
54
56
        char *reason_str = NULL;
55
57
        char *user_name;
 
58
        char *tag, *val;
 
59
        int taglen, vallen;
56
60
 
57
 
        node_msg.node_names = NULL;
58
 
        node_msg.features = NULL;
59
 
        node_msg.reason = NULL;
60
 
        node_msg.node_state = (uint16_t) NO_VAL;
 
61
        slurm_init_update_node_msg(&node_msg);
61
62
        for (i=0; i<argc; i++) {
62
 
                if (strncasecmp(argv[i], "NodeName=", 9) == 0)
63
 
                        node_msg.node_names = &argv[i][9];
64
 
                else if (strncasecmp(argv[i], "Features=", 9) == 0) {
65
 
                        node_msg.features = &argv[i][9];
66
 
                        update_cnt++;
67
 
                } else if (strncasecmp(argv[i], "Reason=", 7) == 0) {
 
63
                tag = argv[i];
 
64
                val = strchr(argv[i], '=');
 
65
                if (val) {
 
66
                        taglen = val - argv[i];
 
67
                        val++;
 
68
                        vallen = strlen(val);
 
69
                } else {
 
70
                        exit_code = 1;
 
71
                        error("Invalid input: %s  Request aborted", argv[i]);
 
72
                        return -1;
 
73
                }
 
74
                if (strncasecmp(tag, "NodeName", MAX(taglen, 1)) == 0)
 
75
                        node_msg.node_names = val;
 
76
                else if (strncasecmp(tag, "Features", MAX(taglen, 1)) == 0) {
 
77
                        node_msg.features = val;
 
78
                        update_cnt++;
 
79
                } else if (strncasecmp(tag, "Weight", MAX(taglen,1)) == 0) {
 
80
                        /* Logic borrowed from function _handle_uint32 */
 
81
                        char *endptr;
 
82
                        unsigned long num;
 
83
                        errno = 0;
 
84
                        num = strtoul(val, &endptr, 0);
 
85
                        if ((endptr[0] == 'k') || (endptr[0] == 'K')) {
 
86
                                num *= 1024;
 
87
                                endptr++;
 
88
                        }
 
89
                        if ((num == 0 && errno == EINVAL)
 
90
                                    || (*endptr != '\0')) {
 
91
                                if ((strcasecmp(val, "UNLIMITED") == 0) ||
 
92
                                    (strcasecmp(val, "INFINITE")  == 0)) {
 
93
                                        num = (uint32_t) INFINITE;
 
94
                                } else {
 
95
                                        error("Weight value (%s) is not a "
 
96
                                              "valid number", val);
 
97
                                        break;
 
98
                                }
 
99
                        } else if (errno == ERANGE) {
 
100
                                error("Weight value (%s) is out of range", 
 
101
                                      val);
 
102
                                break;
 
103
                        } else if (val[0] == '-') {
 
104
                                error("Weight value (%s) is less than zero", 
 
105
                                      val);
 
106
                                break;
 
107
                        } else if (num > 0xfffffff0) {
 
108
                                error("Weight value (%s) is greater than %u",
 
109
                                        val, 0xfffffff0);
 
110
                                break;
 
111
                        }
 
112
                        node_msg.weight = num;
 
113
                        update_cnt++;
 
114
                } else if (strncasecmp(tag, "Reason", MAX(taglen, 1)) == 0) {
68
115
                        char time_buf[64], time_str[32];
69
116
                        time_t now;
70
 
                        int len = strlen(&argv[i][7]);
 
117
                        int len = strlen(val);
71
118
                        reason_str = xmalloc(len+1);
72
 
                        if (argv[i][7] == '"')
73
 
                                strcpy(reason_str, &argv[i][8]);
 
119
                        if (*val == '"')
 
120
                                strcpy(reason_str, val+1);
74
121
                        else
75
 
                                strcpy(reason_str, &argv[i][7]);
 
122
                                strcpy(reason_str, val);
76
123
 
77
124
                        len = strlen(reason_str) - 1;
78
125
                        if ((len >= 0) && (reason_str[len] == '"'))
89
136
                        }
90
137
                        now = time(NULL);
91
138
                        slurm_make_time_str(&now, time_str, sizeof(time_str));
92
 
                        snprintf(time_buf, sizeof(time_buf), "@%s]", time_str); 
 
139
                        snprintf(time_buf, sizeof(time_buf), "@%s]", time_str);
93
140
                        xstrcat(reason_str, time_buf);
94
141
                                
95
142
                        node_msg.reason = reason_str;
96
143
                        update_cnt++;
97
144
                }
98
 
                else if (strncasecmp(argv[i], "State=NoResp", 12) == 0) {
99
 
                        node_msg.node_state = NODE_STATE_NO_RESPOND;
100
 
                        update_cnt++;
101
 
                }
102
 
                else if (strncasecmp(argv[i], "State=DRAIN", 11) == 0) {
103
 
                        node_msg.node_state = NODE_STATE_DRAIN;
104
 
                        update_cnt++;
105
 
                }
106
 
                else if (strncasecmp(argv[i], "State=FAIL", 10) == 0) {
107
 
                        node_msg.node_state = NODE_STATE_FAIL;
108
 
                        update_cnt++;
109
 
                }
110
 
                else if (strncasecmp(argv[i], "State=RES", 9) == 0) {
111
 
                        node_msg.node_state = NODE_RESUME;
112
 
                        update_cnt++;
113
 
                }
114
 
                else if (strncasecmp(argv[i], "State=", 6) == 0) {
115
 
                        state_val = (uint16_t) NO_VAL;
116
 
                        for (j = 0; j <= NODE_STATE_END; j++) {
117
 
                                if (strcasecmp (node_state_string(j), 
118
 
                                                &argv[i][6]) == 0) {
119
 
                                        state_val = (uint16_t) j;
120
 
                                        break;
 
145
                else if (strncasecmp(tag, "State", MAX(taglen, 1)) == 0) {
 
146
                        if (strncasecmp(val, "NoResp", 
 
147
                                        MAX(vallen, 3)) == 0) {
 
148
                                node_msg.node_state = NODE_STATE_NO_RESPOND;
 
149
                                update_cnt++;
 
150
                        } else if (strncasecmp(val, "DRAIN", 
 
151
                                   MAX(vallen, 3)) == 0) {
 
152
                                node_msg.node_state = NODE_STATE_DRAIN;
 
153
                                update_cnt++;
 
154
                        } else if (strncasecmp(val, "FAIL", 
 
155
                                   MAX(vallen, 3)) == 0) {
 
156
                                node_msg.node_state = NODE_STATE_FAIL;
 
157
                                update_cnt++;
 
158
                        } else if (strncasecmp(val, "RESUME", 
 
159
                                   MAX(vallen, 3)) == 0) {
 
160
                                node_msg.node_state = NODE_RESUME;
 
161
                                update_cnt++;
 
162
                        } else if (strncasecmp(val, "POWER_DOWN", 
 
163
                                   MAX(vallen, 7)) == 0) {
 
164
                                node_msg.node_state = NODE_STATE_POWER_SAVE;
 
165
                                update_cnt++;
 
166
                        } else if (strncasecmp(val, "POWER_UP", 
 
167
                                   MAX(vallen, 7)) == 0) {
 
168
                                node_msg.node_state = NODE_STATE_POWER_UP;
 
169
                                update_cnt++;
 
170
                        } else {
 
171
                                state_val = (uint16_t) NO_VAL;
 
172
                                for (j = 0; j < NODE_STATE_END; j++) {
 
173
                                        if (strncasecmp (node_state_string(j), 
 
174
                                                         val, 
 
175
                                                         MAX(vallen, 3)) == 0) {
 
176
                                                state_val = (uint16_t) j;
 
177
                                                break;
 
178
                                        }
121
179
                                }
122
180
                                if (j == NODE_STATE_END) {
123
181
                                        exit_code = 1;
125
183
                                                argv[i]);
126
184
                                        fprintf (stderr, "Request aborted\n");
127
185
                                        fprintf (stderr, "Valid states are: ");
128
 
                                        fprintf (stderr, "NoResp DRAIN FAIL RESUME ");
 
186
                                        fprintf (stderr,
 
187
                                                 "NoResp DRAIN FAIL RESUME "
 
188
                                                 "POWER_DOWN POWER_UP ");
129
189
                                        for (k = 0; k < NODE_STATE_END; k++) {
130
190
                                                fprintf (stderr, "%s ", 
131
191
                                                         node_state_string(k));
132
192
                                        }
133
193
                                        fprintf (stderr, "\n");
134
 
                                        fprintf (stderr, "Not all states are valid given a "
135
 
                                                 "node's prior state\n");
 
194
                                        fprintf (stderr, 
 
195
                                                 "Not all states are valid "
 
196
                                                 "given a node's prior "
 
197
                                                 "state\n");
136
198
                                        goto done;
137
199
                                }
 
200
                                node_msg.node_state = state_val;
 
201
                                update_cnt++;
138
202
                        }
139
 
                        node_msg.node_state = state_val;
140
 
                        update_cnt++;
141
 
                }
142
 
                else {
 
203
                } else {
143
204
                        exit_code = 1;
144
205
                        fprintf (stderr, "Invalid input: %s\n", argv[i]);
145
206
                        fprintf (stderr, "Request aborted\n");