5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2015, Syneto S.R.L. All rights reserved.
25 */
26
27 /*
28 * graph.c - master restarter graph engine
29 *
30 * The graph engine keeps a dependency graph of all service instances on the
31 * system, as recorded in the repository. It decides when services should
32 * be brought up or down based on service states and dependencies and sends
33 * commands to restarters to effect any changes. It also executes
34 * administrator commands sent by svcadm via the repository.
35 *
36 * The graph is stored in uu_list_t *dgraph and its vertices are
37 * graph_vertex_t's, each of which has a name and an integer id unique to
38 * its name (see dict.c). A vertex's type attribute designates the type
39 * of object it represents: GVT_INST for service instances, GVT_SVC for
40 * service objects (since service instances may depend on another service,
41 * rather than service instance), GVT_FILE for files (which services may
42 * depend on), and GVT_GROUP for dependencies on multiple objects. GVT_GROUP
43 * vertices are necessary because dependency lists may have particular
44 * grouping types (require any, require all, optional, or exclude) and
1280
1281 satisfiable = B_FALSE;
1282
1283 for (edge = uu_list_first(groupv->gv_dependencies);
1284 edge != NULL;
1285 edge = uu_list_next(groupv->gv_dependencies, edge)) {
1286 s = dependency_satisfied(edge->ge_vertex, satbility);
1287
1288 if (s == 1)
1289 return (1);
1290
1291 log_framework2(LOG_DEBUG, DEBUG_DEPENDENCIES,
1292 "require_any(%s): %s is unsatisfi%s.\n",
1293 groupv->gv_name, edge->ge_vertex->gv_name,
1294 s == 0 ? "ed" : "able");
1295
1296 if (satbility && s == 0)
1297 satisfiable = B_TRUE;
1298 }
1299
1300 return (!satbility || satisfiable ? 0 : -1);
1301 }
1302
1303 /*
1304 * An optional_all dependency only considers elements which are configured,
1305 * enabled, and not in maintenance. If any are unsatisfied, then the dependency
1306 * is unsatisfied.
1307 *
1308 * Offline dependencies which are waiting for a dependency to come online are
1309 * unsatisfied. Offline dependences which cannot possibly come online
1310 * (unsatisfiable) are always considered satisfied.
1311 */
1312 static int
1313 optional_all_satisfied(graph_vertex_t *groupv, boolean_t satbility)
1314 {
1315 graph_edge_t *edge;
1316 graph_vertex_t *v;
1317 boolean_t any_qualified;
1318 boolean_t any_unsatisfied;
1319 int i;
1320
|
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2015, Syneto S.R.L. All rights reserved.
25 * Copyright 2016 RackTop Systems.
26 */
27
28 /*
29 * graph.c - master restarter graph engine
30 *
31 * The graph engine keeps a dependency graph of all service instances on the
32 * system, as recorded in the repository. It decides when services should
33 * be brought up or down based on service states and dependencies and sends
34 * commands to restarters to effect any changes. It also executes
35 * administrator commands sent by svcadm via the repository.
36 *
37 * The graph is stored in uu_list_t *dgraph and its vertices are
38 * graph_vertex_t's, each of which has a name and an integer id unique to
39 * its name (see dict.c). A vertex's type attribute designates the type
40 * of object it represents: GVT_INST for service instances, GVT_SVC for
41 * service objects (since service instances may depend on another service,
42 * rather than service instance), GVT_FILE for files (which services may
43 * depend on), and GVT_GROUP for dependencies on multiple objects. GVT_GROUP
44 * vertices are necessary because dependency lists may have particular
45 * grouping types (require any, require all, optional, or exclude) and
1281
1282 satisfiable = B_FALSE;
1283
1284 for (edge = uu_list_first(groupv->gv_dependencies);
1285 edge != NULL;
1286 edge = uu_list_next(groupv->gv_dependencies, edge)) {
1287 s = dependency_satisfied(edge->ge_vertex, satbility);
1288
1289 if (s == 1)
1290 return (1);
1291
1292 log_framework2(LOG_DEBUG, DEBUG_DEPENDENCIES,
1293 "require_any(%s): %s is unsatisfi%s.\n",
1294 groupv->gv_name, edge->ge_vertex->gv_name,
1295 s == 0 ? "ed" : "able");
1296
1297 if (satbility && s == 0)
1298 satisfiable = B_TRUE;
1299 }
1300
1301 if (!satbility)
1302 return (0);
1303
1304 return (satisfiable ? 0 : -1);
1305 }
1306
1307 /*
1308 * An optional_all dependency only considers elements which are configured,
1309 * enabled, and not in maintenance. If any are unsatisfied, then the dependency
1310 * is unsatisfied.
1311 *
1312 * Offline dependencies which are waiting for a dependency to come online are
1313 * unsatisfied. Offline dependences which cannot possibly come online
1314 * (unsatisfiable) are always considered satisfied.
1315 */
1316 static int
1317 optional_all_satisfied(graph_vertex_t *groupv, boolean_t satbility)
1318 {
1319 graph_edge_t *edge;
1320 graph_vertex_t *v;
1321 boolean_t any_qualified;
1322 boolean_t any_unsatisfied;
1323 int i;
1324
|