parse.y 9.69 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/*
 * Copyright IBM Corporation. 2007
 *
 * Authors:	Balbir Singh <balbir@linux.vnet.ibm.com>
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2.1 of the GNU Lesser General Public License
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it would be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * NOTE: The grammar has been modified, not to be the most efficient, but
 * to allow easy updation of internal data structures.
 */
%{
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <libcgroup.h>
#include <libcgroup-internal.h>

int yylex(void);
extern int line_no;
extern char *yytext;

27
static void yyerror(const char *s)
28
{
29
	fprintf(stderr, "error at line number %d at %s:%s\n", line_no, yytext,
30 31 32 33 34 35 36 37 38 39
		s);
}

int yywrap(void)
{
	return 1;
}

%}

40
%token ID MOUNT GROUP PERM TASK ADMIN NAMESPACE DEFAULT TEMPLATE
41 42 43 44 45

%union {
	char *name;
	char chr;
	int val;
Jon Bernard's avatar
Jon Bernard committed
46
	struct cgroup_dictionary *values;
47
}
Jon Bernard's avatar
Jon Bernard committed
48
%type <name> ID
49 50
%type <val> mountvalue_conf mount task_namevalue_conf admin_namevalue_conf
%type <val> admin_conf task_conf task_or_admin group_conf group start
Jon Bernard's avatar
Jon Bernard committed
51
%type <val> namespace namespace_conf default default_conf
Jon Bernard's avatar
Jon Bernard committed
52
%type <values> namevalue_conf
53 54
%type <val> template template_conf
%type <val> template_task_or_admin template_task_namevalue_conf
55 56
%type <val> template_admin_namevalue_conf template_task_conf
%type <val> template_admin_conf
57 58 59 60 61 62 63 64 65 66 67
%start start
%%

start   : start group
	{
		$$ = $1;
	}
        | start mount
	{
		$$ = $1;
	}
Jon Bernard's avatar
Jon Bernard committed
68 69 70 71
	| start default
	{
	  $$ = $1;
	}
72 73 74 75
        | start namespace
	{
		$$ = $1;
	}
76 77 78 79
	| start template
	{
		$$ = $1;
	}
80
	|
81 82 83 84 85
	{
		$$ = 1;
	}
        ;

Jon Bernard's avatar
Jon Bernard committed
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
default :       DEFAULT '{' default_conf '}'
	{
		$$ = $3;
		if ($$) {
			cgroup_config_define_default();
		}
	}
	;

default_conf
	:       PERM '{' task_or_admin '}'
	{
		$$ = $3;
	}
	;

102 103 104
group   :       GROUP ID '{' group_conf '}'
	{
		$$ = $4;
105 106 107 108 109 110 111 112 113
		if ($$) {
			$$ = cgroup_config_insert_cgroup($2);
			if (!$$) {
				fprintf(stderr, "failed to insert group"
					" check size and memory");
				$$ = ECGOTHER;
				return $$;
			}
		} else {
114 115
			fprintf(stderr, "parsing failed at line number %d\n",
				line_no);
116
			$$ = ECGCONFIGPARSEFAIL;
117 118 119 120 121 122 123 124 125
			return $$;
		}
	}
        ;

group_conf
        :       ID '{' namevalue_conf '}'
	{
		$$ = cgroup_config_parse_controller_options($1, $3);
Jon Bernard's avatar
Jon Bernard committed
126
		cgroup_dictionary_free($3);
127 128 129
		if (!$$) {
			fprintf(stderr, "parsing failed at line number %d\n",
				line_no);
130
			$$ = ECGCONFIGPARSEFAIL;
131 132 133
			return $$;
		}
	}
134
        |       group_conf ID '{' namevalue_conf '}'
135 136
	{
		$$ = cgroup_config_parse_controller_options($2, $4);
Jon Bernard's avatar
Jon Bernard committed
137
		cgroup_dictionary_free($4);
138 139 140
		if (!$$) {
			fprintf(stderr, "parsing failed at line number %d\n",
				line_no);
141
			$$ = ECGCONFIGPARSEFAIL;
142 143 144 145 146 147 148 149 150
			return $$;
		}
	}
        |       PERM '{' task_or_admin '}'
	{
		$$ = $3;
		if (!$$) {
			fprintf(stderr, "parsing failed at line number %d\n",
				line_no);
151
			$$ = ECGCONFIGPARSEFAIL;
152 153 154 155 156
			return $$;
		}
	}
        ;

157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
template  :     TEMPLATE ID '{' template_conf '}'
	{
		$$ = $4;
		if ($$) {
			$$ = template_config_insert_cgroup($2);
			if (!$$) {
				fprintf(stderr, "parsing failed at line number %d\n",
					line_no);
				$$ = ECGOTHER;
				return $$;
			}
		} else {
			fprintf(stderr, "parsing failed at line number %d\n",
				line_no);
			$$ = ECGCONFIGPARSEFAIL;
			return $$;
		}
	}
	;


template_conf
	:       ID '{' namevalue_conf '}'
	{
		$$ = template_config_parse_controller_options($1, $3);
		cgroup_dictionary_free($3);
		if (!$$) {
			fprintf(stderr, "parsing failed at line number %d\n",
				line_no);
			$$ = ECGCONFIGPARSEFAIL;
			return $$;
		}
	}
	|       template_conf ID '{' namevalue_conf '}'
	{
		$$ = template_config_parse_controller_options($2, $4);
		cgroup_dictionary_free($4);
		if (!$$) {
			fprintf(stderr, "parsing failed at line number %d\n",
				line_no);
			$$ = ECGCONFIGPARSEFAIL;
			return $$;
		}
	}
	|       PERM '{' template_task_or_admin '}'
	{
		$$ = $3;
		if (!$$) {
			fprintf(stderr, "parsing failed at line number %d\n",
				line_no);
			$$ = ECGCONFIGPARSEFAIL;
			return $$;
		}
	}
	;

template_task_or_admin
214
	:	TASK '{' template_task_namevalue_conf '}' template_admin_conf
215 216 217 218 219 220 221 222 223
	{
	$$ = $3 && $5;
		if (!$$) {
			fprintf(stderr, "parsing failed at line number %d\n",
				line_no);
			$$ = ECGCONFIGPARSEFAIL;
			return $$;
		}
	}
224
	|       ADMIN '{' template_admin_namevalue_conf '}' template_task_conf
225 226 227 228 229 230 231 232 233 234 235 236
	{
		$$ = $3 && $5;
		if (!$$) {
			fprintf(stderr, "parsing failed at line number %d\n",
				line_no);
			$$ = ECGCONFIGPARSEFAIL;
		return $$;
		}
	}
	;


237 238 239
namevalue_conf
        :       ID '=' ID ';'
	{
Jon Bernard's avatar
Jon Bernard committed
240 241 242 243 244 245 246 247 248
		struct cgroup_dictionary *dict;
		int ret;
		ret = cgroup_dictionary_create(&dict, 0);
		if (ret == 0)
			ret = cgroup_dictionary_add(dict, $1, $3);
		if (ret) {
			fprintf(stderr, "parsing failed at line number %d:%s\n",
				line_no, cgroup_strerror(ret));
			$$ = NULL;
Jon Bernard's avatar
Jon Bernard committed
249
			cgroup_dictionary_free(dict);
Jon Bernard's avatar
Jon Bernard committed
250 251 252
			return ECGCONFIGPARSEFAIL;
		}
		$$ = dict;
253 254 255
	}
        |       namevalue_conf ID '=' ID ';'
	{
Jon Bernard's avatar
Jon Bernard committed
256 257 258 259 260 261 262
		int ret = 0;
		ret = cgroup_dictionary_add($1, $2, $4);
		if (ret != 0) {
			fprintf(stderr, "parsing failed at line number %d: %s\n",
				line_no, cgroup_strerror(ret));
			$$ = NULL;
			return ECGCONFIGPARSEFAIL;
263
		}
Jon Bernard's avatar
Jon Bernard committed
264
		$$ = $1;
265 266 267 268 269 270 271 272 273 274 275 276 277 278
	}
	|
	{
		$$ = NULL;
	}
        ;

task_namevalue_conf
        :       ID '=' ID ';'
	{
		$$ = cgroup_config_group_task_perm($1, $3);
		if (!$$) {
			fprintf(stderr, "parsing failed at line number %d\n",
				line_no);
279
			$$ = ECGCONFIGPARSEFAIL;
280 281 282 283 284 285 286 287 288
			return $$;
		}
	}
        |       task_namevalue_conf ID '=' ID ';'
	{
		$$ = $1 && cgroup_config_group_task_perm($2, $4);
		if (!$$) {
			fprintf(stderr, "parsing failed at line number %d\n",
				line_no);
289
			$$ = ECGCONFIGPARSEFAIL;
290 291 292 293 294 295 296 297 298 299 300 301
			return $$;
		}
	}
        ;

admin_namevalue_conf
        :       ID '=' ID ';'
	{
		$$ = cgroup_config_group_admin_perm($1, $3);
		if (!$$) {
			fprintf(stderr, "parsing failed at line number %d\n",
				line_no);
302
			$$ = ECGCONFIGPARSEFAIL;
303 304 305 306 307 308 309 310 311
			return $$;
		}
	}
        |       admin_namevalue_conf ID '=' ID ';'
	{
		$$ = $1 && cgroup_config_group_admin_perm($2, $4);
		if (!$$) {
			fprintf(stderr, "parsing failed at line number %d\n",
				line_no);
312
			$$ = ECGCONFIGPARSEFAIL;
313 314 315 316 317
			return $$;
		}
	}
        ;

318 319 320 321 322 323 324 325 326 327 328
template_task_namevalue_conf
        :       ID '=' ID ';'
	{
		$$ = template_config_group_task_perm($1, $3);
		if (!$$) {
			fprintf(stderr, "parsing failed at line number %d\n",
				line_no);
			$$ = ECGCONFIGPARSEFAIL;
			return $$;
		}
	}
329
        |       template_task_namevalue_conf ID '=' ID ';'
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
	{
		$$ = $1 && template_config_group_task_perm($2, $4);
		if (!$$) {
			fprintf(stderr, "parsing failed at line number %d\n",
				line_no);
			$$ = ECGCONFIGPARSEFAIL;
			return $$;
		}
	}
	;

template_admin_namevalue_conf
        :       ID '=' ID ';'
	{
		$$ = template_config_group_admin_perm($1, $3);
		if (!$$) {
			fprintf(stderr, "parsing failed at line number %d\n",
				line_no);
			$$ = ECGCONFIGPARSEFAIL;
			return $$;
		}
	}
352
        |       template_admin_namevalue_conf ID '=' ID ';'
353 354 355 356 357 358 359 360 361 362 363 364
	{
		$$ = $1 && template_config_group_admin_perm($2, $4);
		if (!$$) {
			fprintf(stderr, "parsing failed at line number %d\n",
				line_no);
			$$ = ECGCONFIGPARSEFAIL;
			return $$;
		}
	}
        ;


365 366 367 368 369 370 371
task_or_admin
        :       TASK '{' task_namevalue_conf '}' admin_conf
	{
		$$ = $3 && $5;
		if (!$$) {
			fprintf(stderr, "parsing failed at line number %d\n",
				line_no);
372
			$$ = ECGCONFIGPARSEFAIL;
373 374 375 376 377 378 379 380 381
			return $$;
		}
	}
        |       ADMIN '{' admin_namevalue_conf '}' task_conf
	{
		$$ = $3 && $5;
		if (!$$) {
			fprintf(stderr, "parsing failed at line number %d\n",
				line_no);
382
			$$ = ECGCONFIGPARSEFAIL;
383 384 385 386 387 388 389 390 391 392 393
			return $$;
		}
	}
        ;

admin_conf:	ADMIN '{' admin_namevalue_conf '}'
	{
		$$ = $3;
		if (!$$) {
			fprintf(stderr, "parsing failed at line number %d\n",
				line_no);
394
			$$ = ECGCONFIGPARSEFAIL;
395 396 397 398 399 400 401 402 403 404 405
			return $$;
		}
	}
	;

task_conf:	TASK '{' task_namevalue_conf '}'
	{
		$$ = $3;
		if (!$$) {
			fprintf(stderr, "parsing failed at line number %d\n",
				line_no);
406
			$$ = ECGCONFIGPARSEFAIL;
407 408 409 410 411
			return $$;
		}
	}
	;

412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435
template_admin_conf:	ADMIN '{' template_admin_namevalue_conf '}'
	{
		$$ = $3;
		if (!$$) {
			fprintf(stderr, "parsing failed at line number %d\n",
				line_no);
			$$ = ECGCONFIGPARSEFAIL;
			return $$;
		}
	}
	;

template_task_conf:	TASK '{' template_task_namevalue_conf '}'
	{
		$$ = $3;
		if (!$$) {
			fprintf(stderr, "parsing failed at line number %d\n",
				line_no);
			$$ = ECGCONFIGPARSEFAIL;
			return $$;
		}
	}
	;

436 437 438 439 440
mountvalue_conf
        :       ID '=' ID ';'
	{
		if (!cgroup_config_insert_into_mount_table($1, $3)) {
			cgroup_config_cleanup_mount_table();
441
			$$ = ECGCONFIGPARSEFAIL;
442 443 444 445 446 447 448 449
			return $$;
		}
		$$ = 1;
	}
        |       mountvalue_conf ID '=' ID ';'
	{
		if (!cgroup_config_insert_into_mount_table($2, $4)) {
			cgroup_config_cleanup_mount_table();
450
			$$ = ECGCONFIGPARSEFAIL;
451 452 453 454 455 456 457 458 459 460 461 462
			return $$;
		}
		$$ = 1;
	}
        ;

mount   :       MOUNT '{' mountvalue_conf '}'
	{
		$$ = $3;
		if (!$$) {
			fprintf(stderr, "parsing failed at line number %d\n",
				line_no);
463 464 465 466 467 468 469 470 471 472 473
			$$ = ECGCONFIGPARSEFAIL;
			return $$;
		}
	}
        ;

namespace_conf
        :       ID '=' ID ';'
	{
		if (!cgroup_config_insert_into_namespace_table($1, $3)) {
			cgroup_config_cleanup_namespace_table();
474
			$$ = ECGCONFIGPARSEFAIL;
475 476 477 478 479 480 481 482
			return $$;
		}
		$$ = 1;
	}
        |       namespace_conf ID '=' ID ';'
	{
		if (!cgroup_config_insert_into_namespace_table($2, $4)) {
			cgroup_config_cleanup_namespace_table();
483
			$$ = ECGCONFIGPARSEFAIL;
484 485
			return $$;
		}
486
		$$ = 1;
487 488 489
	}
        ;

490 491 492 493 494 495
namespace   :       NAMESPACE '{' namespace_conf '}'
	{
		$$ = $3;
		if (!$$) {
			fprintf(stderr, "parsing failed at line number %d\n",
				line_no);
496
			$$ = ECGCONFIGPARSEFAIL;
497 498 499 500
			return $$;
		}
	}
        ;
501 502

%%