zoneadmd.c (ff17c8bf86c3e567734be83f90267edee20f580f) | zoneadmd.c (c5cd6260c3d6c06a9359df595ad9dddbfd00a80e) |
---|---|
1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 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 --- 10 unchanged lines hidden (view full) --- 19 * CDDL HEADER END 20 */ 21 22/* 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 | 1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 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 --- 10 unchanged lines hidden (view full) --- 19 * CDDL HEADER END 20 */ 21 22/* 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 |
27#pragma ident "%Z%%M% %I% %E% SMI" 28 | |
29/* 30 * zoneadmd manages zones; one zoneadmd process is launched for each 31 * non-global zone on the system. This daemon juggles four jobs: 32 * 33 * - Implement setup and teardown of the zone "virtual platform": mount and 34 * unmount filesystems; create and destroy network interfaces; communicate 35 * with devfsadmd to lay out devices for the zone; instantiate the zone 36 * console device; configure process runtime attributes such as resource --- 67 unchanged lines hidden (view full) --- 104 105static char *progname; 106char *zone_name; /* zone which we are managing */ 107char brand_name[MAXNAMELEN]; 108boolean_t zone_isnative; 109boolean_t zone_iscluster; 110static zoneid_t zone_id; 111 | 27/* 28 * zoneadmd manages zones; one zoneadmd process is launched for each 29 * non-global zone on the system. This daemon juggles four jobs: 30 * 31 * - Implement setup and teardown of the zone "virtual platform": mount and 32 * unmount filesystems; create and destroy network interfaces; communicate 33 * with devfsadmd to lay out devices for the zone; instantiate the zone 34 * console device; configure process runtime attributes such as resource --- 67 unchanged lines hidden (view full) --- 102 103static char *progname; 104char *zone_name; /* zone which we are managing */ 105char brand_name[MAXNAMELEN]; 106boolean_t zone_isnative; 107boolean_t zone_iscluster; 108static zoneid_t zone_id; 109 |
110static char pre_statechg_hook[2 * MAXPATHLEN]; 111static char post_statechg_hook[2 * MAXPATHLEN]; 112char query_hook[2 * MAXPATHLEN]; 113 |
|
112zlog_t logsys; 113 114mutex_t lock = DEFAULTMUTEX; /* to serialize stuff */ 115mutex_t msglock = DEFAULTMUTEX; /* for calling setlocale() */ 116 117static sema_t scratch_sem; /* for scratch zones */ 118 119static char zone_door_path[MAXPATHLEN]; --- 316 unchanged lines hidden (view full) --- 436 zerror(zlogp, B_TRUE, "'%s' is not a directory", ZONES_TMPDIR); 437 return (-1); 438 } 439 (void) chmod(ZONES_TMPDIR, S_IRWXU); 440 return (0); 441} 442 443/* | 114zlog_t logsys; 115 116mutex_t lock = DEFAULTMUTEX; /* to serialize stuff */ 117mutex_t msglock = DEFAULTMUTEX; /* for calling setlocale() */ 118 119static sema_t scratch_sem; /* for scratch zones */ 120 121static char zone_door_path[MAXPATHLEN]; --- 316 unchanged lines hidden (view full) --- 438 zerror(zlogp, B_TRUE, "'%s' is not a directory", ZONES_TMPDIR); 439 return (-1); 440 } 441 (void) chmod(ZONES_TMPDIR, S_IRWXU); 442 return (0); 443} 444 445/* |
446 * Run the brand's pre-state change callback, if it exists. 447 */ 448static int 449brand_prestatechg(zlog_t *zlogp, int state, int cmd) 450{ 451 char cmdbuf[2 * MAXPATHLEN]; 452 453 if (pre_statechg_hook[0] == '\0') 454 return (0); 455 456 if (snprintf(cmdbuf, sizeof (cmdbuf), "%s %d %d", pre_statechg_hook, 457 state, cmd) > sizeof (cmdbuf)) 458 return (-1); 459 460 if (do_subproc(zlogp, cmdbuf, NULL) != 0) 461 return (-1); 462 463 return (0); 464} 465 466/* 467 * Run the brand's post-state change callback, if it exists. 468 */ 469static int 470brand_poststatechg(zlog_t *zlogp, int state, int cmd) 471{ 472 char cmdbuf[2 * MAXPATHLEN]; 473 474 if (post_statechg_hook[0] == '\0') 475 return (0); 476 477 if (snprintf(cmdbuf, sizeof (cmdbuf), "%s %d %d", post_statechg_hook, 478 state, cmd) > sizeof (cmdbuf)) 479 return (-1); 480 481 if (do_subproc(zlogp, cmdbuf, NULL) != 0) 482 return (-1); 483 484 return (0); 485} 486 487/* |
|
444 * Bring a zone up to the pre-boot "ready" stage. The mount_cmd argument is 445 * 'true' if this is being invoked as part of the processing for the "mount" 446 * subcommand. 447 */ 448static int | 488 * Bring a zone up to the pre-boot "ready" stage. The mount_cmd argument is 489 * 'true' if this is being invoked as part of the processing for the "mount" 490 * subcommand. 491 */ 492static int |
449zone_ready(zlog_t *zlogp, zone_mnt_t mount_cmd) | 493zone_ready(zlog_t *zlogp, zone_mnt_t mount_cmd, int zstate) |
450{ 451 int err; 452 | 494{ 495 int err; 496 |
497 if (brand_prestatechg(zlogp, zstate, Z_READY) != 0) 498 return (-1); 499 |
|
453 if ((err = zonecfg_create_snapshot(zone_name)) != Z_OK) { 454 zerror(zlogp, B_FALSE, "unable to create snapshot: %s", 455 zonecfg_strerror(err)); 456 return (-1); 457 } 458 459 if ((zone_id = vplat_create(zlogp, mount_cmd)) == -1) { 460 if ((err = zonecfg_destroy_snapshot(zone_name)) != Z_OK) --- 5 unchanged lines hidden (view full) --- 466 bringup_failure_recovery = B_TRUE; 467 (void) vplat_teardown(NULL, (mount_cmd != Z_MNT_BOOT), B_FALSE); 468 if ((err = zonecfg_destroy_snapshot(zone_name)) != Z_OK) 469 zerror(zlogp, B_FALSE, "destroying snapshot: %s", 470 zonecfg_strerror(err)); 471 return (-1); 472 } 473 | 500 if ((err = zonecfg_create_snapshot(zone_name)) != Z_OK) { 501 zerror(zlogp, B_FALSE, "unable to create snapshot: %s", 502 zonecfg_strerror(err)); 503 return (-1); 504 } 505 506 if ((zone_id = vplat_create(zlogp, mount_cmd)) == -1) { 507 if ((err = zonecfg_destroy_snapshot(zone_name)) != Z_OK) --- 5 unchanged lines hidden (view full) --- 513 bringup_failure_recovery = B_TRUE; 514 (void) vplat_teardown(NULL, (mount_cmd != Z_MNT_BOOT), B_FALSE); 515 if ((err = zonecfg_destroy_snapshot(zone_name)) != Z_OK) 516 zerror(zlogp, B_FALSE, "destroying snapshot: %s", 517 zonecfg_strerror(err)); 518 return (-1); 519 } 520 |
521 if (brand_poststatechg(zlogp, zstate, Z_READY) != 0) 522 return (-1); 523 |
|
474 return (0); 475} 476 477int 478init_template(void) 479{ 480 int fd; 481 int err = 0; --- 152 unchanged lines hidden (view full) --- 634 errno = WEXITSTATUS(child_status); 635 zerror(zlogp, B_TRUE, "mount of %s failed", dir); 636 return (-1); 637 } 638 639 return (0); 640} 641 | 524 return (0); 525} 526 527int 528init_template(void) 529{ 530 int fd; 531 int err = 0; --- 152 unchanged lines hidden (view full) --- 684 errno = WEXITSTATUS(child_status); 685 zerror(zlogp, B_TRUE, "mount of %s failed", dir); 686 return (-1); 687 } 688 689 return (0); 690} 691 |
692/* 693 * If retstr is not NULL, the output of the subproc is returned in the str, 694 * otherwise it is output using zerror(). Any memory allocated for retstr 695 * should be freed by the caller. 696 */ |
|
642int | 697int |
643do_subproc(zlog_t *zlogp, char *cmdbuf) | 698do_subproc(zlog_t *zlogp, char *cmdbuf, char **retstr) |
644{ | 699{ |
645 char inbuf[1024]; /* arbitrary large amount */ | 700 char buf[1024]; /* arbitrary large amount */ 701 char *inbuf; |
646 FILE *file; 647 int status; | 702 FILE *file; 703 int status; |
704 int rd_cnt; |
|
648 | 705 |
706 if (retstr != NULL) { 707 if ((*retstr = malloc(1024)) == NULL) { 708 zerror(zlogp, B_FALSE, "out of memory"); 709 return (-1); 710 } 711 inbuf = *retstr; 712 rd_cnt = 0; 713 } else { 714 inbuf = buf; 715 } 716 |
|
649 file = popen(cmdbuf, "r"); 650 if (file == NULL) { 651 zerror(zlogp, B_TRUE, "could not launch: %s", cmdbuf); 652 return (-1); 653 } 654 | 717 file = popen(cmdbuf, "r"); 718 if (file == NULL) { 719 zerror(zlogp, B_TRUE, "could not launch: %s", cmdbuf); 720 return (-1); 721 } 722 |
655 while (fgets(inbuf, sizeof (inbuf), file) != NULL) 656 if (zlogp != &logsys) | 723 while (fgets(inbuf, 1024, file) != NULL) { 724 if (retstr == NULL && zlogp != &logsys) { |
657 zerror(zlogp, B_FALSE, "%s", inbuf); | 725 zerror(zlogp, B_FALSE, "%s", inbuf); |
726 } else { 727 char *p; 728 729 rd_cnt += 1024 - 1; 730 if ((p = realloc(*retstr, rd_cnt + 1024)) == NULL) { 731 zerror(zlogp, B_FALSE, "out of memory"); 732 (void) pclose(file); 733 return (-1); 734 } 735 736 *retstr = p; 737 inbuf = *retstr + rd_cnt; 738 } 739 } |
|
658 status = pclose(file); 659 660 if (WIFSIGNALED(status)) { 661 zerror(zlogp, B_FALSE, "%s unexpectedly terminated due to " 662 "signal %d", cmdbuf, WTERMSIG(status)); 663 return (-1); 664 } 665 assert(WIFEXITED(status)); 666 if (WEXITSTATUS(status) == ZEXIT_EXEC) { 667 zerror(zlogp, B_FALSE, "failed to exec %s", cmdbuf); 668 return (-1); 669 } 670 return (WEXITSTATUS(status)); 671} 672 673static int | 740 status = pclose(file); 741 742 if (WIFSIGNALED(status)) { 743 zerror(zlogp, B_FALSE, "%s unexpectedly terminated due to " 744 "signal %d", cmdbuf, WTERMSIG(status)); 745 return (-1); 746 } 747 assert(WIFEXITED(status)); 748 if (WEXITSTATUS(status) == ZEXIT_EXEC) { 749 zerror(zlogp, B_FALSE, "failed to exec %s", cmdbuf); 750 return (-1); 751 } 752 return (WEXITSTATUS(status)); 753} 754 755static int |
674zone_bootup(zlog_t *zlogp, const char *bootargs) | 756zone_bootup(zlog_t *zlogp, const char *bootargs, int zstate) |
675{ 676 zoneid_t zoneid; 677 struct stat st; 678 char zpath[MAXPATHLEN], initpath[MAXPATHLEN], init_file[MAXPATHLEN]; 679 char nbootargs[BOOTARGS_MAX]; 680 char cmdbuf[MAXPATHLEN]; 681 fs_callback_t cb; 682 brand_handle_t bh; 683 int err; 684 | 757{ 758 zoneid_t zoneid; 759 struct stat st; 760 char zpath[MAXPATHLEN], initpath[MAXPATHLEN], init_file[MAXPATHLEN]; 761 char nbootargs[BOOTARGS_MAX]; 762 char cmdbuf[MAXPATHLEN]; 763 fs_callback_t cb; 764 brand_handle_t bh; 765 int err; 766 |
767 if (brand_prestatechg(zlogp, zstate, Z_BOOT) != 0) 768 return (-1); 769 |
|
685 if (init_console_slave(zlogp) != 0) 686 return (-1); 687 reset_slave_terminal(zlogp); 688 689 if ((zoneid = getzoneidbyname(zone_name)) == -1) { 690 zerror(zlogp, B_TRUE, "unable to get zoneid"); 691 return (-1); 692 } --- 75 unchanged lines hidden (view full) --- 768 } 769 770 /* 771 * If there is a brand 'boot' callback, execute it now to give the 772 * brand one last chance to do any additional setup before the zone 773 * is booted. 774 */ 775 if ((strlen(cmdbuf) > EXEC_LEN) && | 770 if (init_console_slave(zlogp) != 0) 771 return (-1); 772 reset_slave_terminal(zlogp); 773 774 if ((zoneid = getzoneidbyname(zone_name)) == -1) { 775 zerror(zlogp, B_TRUE, "unable to get zoneid"); 776 return (-1); 777 } --- 75 unchanged lines hidden (view full) --- 853 } 854 855 /* 856 * If there is a brand 'boot' callback, execute it now to give the 857 * brand one last chance to do any additional setup before the zone 858 * is booted. 859 */ 860 if ((strlen(cmdbuf) > EXEC_LEN) && |
776 (do_subproc(zlogp, cmdbuf) != Z_OK)) { | 861 (do_subproc(zlogp, cmdbuf, NULL) != Z_OK)) { |
777 zerror(zlogp, B_FALSE, "%s failed", cmdbuf); 778 return (-1); 779 } 780 781 if (zone_setattr(zoneid, ZONE_ATTR_INITNAME, init_file, 0) == -1) { 782 zerror(zlogp, B_TRUE, "could not set zone boot file"); 783 return (-1); 784 } 785 786 if (zone_setattr(zoneid, ZONE_ATTR_BOOTARGS, nbootargs, 0) == -1) { 787 zerror(zlogp, B_TRUE, "could not set zone boot arguments"); 788 return (-1); 789 } 790 791 if (zone_boot(zoneid) == -1) { 792 zerror(zlogp, B_TRUE, "unable to boot zone"); 793 return (-1); 794 } 795 | 862 zerror(zlogp, B_FALSE, "%s failed", cmdbuf); 863 return (-1); 864 } 865 866 if (zone_setattr(zoneid, ZONE_ATTR_INITNAME, init_file, 0) == -1) { 867 zerror(zlogp, B_TRUE, "could not set zone boot file"); 868 return (-1); 869 } 870 871 if (zone_setattr(zoneid, ZONE_ATTR_BOOTARGS, nbootargs, 0) == -1) { 872 zerror(zlogp, B_TRUE, "could not set zone boot arguments"); 873 return (-1); 874 } 875 876 if (zone_boot(zoneid) == -1) { 877 zerror(zlogp, B_TRUE, "unable to boot zone"); 878 return (-1); 879 } 880 |
881 if (brand_poststatechg(zlogp, zstate, Z_BOOT) != 0) 882 return (-1); 883 |
|
796 return (0); 797} 798 799static int | 884 return (0); 885} 886 887static int |
800zone_halt(zlog_t *zlogp, boolean_t unmount_cmd, boolean_t rebooting) | 888zone_halt(zlog_t *zlogp, boolean_t unmount_cmd, boolean_t rebooting, int zstate) |
801{ 802 int err; 803 | 889{ 890 int err; 891 |
892 if (brand_prestatechg(zlogp, zstate, Z_HALT) != 0) 893 return (-1); 894 |
|
804 if (vplat_teardown(zlogp, unmount_cmd, rebooting) != 0) { 805 if (!bringup_failure_recovery) 806 zerror(zlogp, B_FALSE, "unable to destroy zone"); 807 return (-1); 808 } 809 810 if ((err = zonecfg_destroy_snapshot(zone_name)) != Z_OK) 811 zerror(zlogp, B_FALSE, "destroying snapshot: %s", 812 zonecfg_strerror(err)); 813 | 895 if (vplat_teardown(zlogp, unmount_cmd, rebooting) != 0) { 896 if (!bringup_failure_recovery) 897 zerror(zlogp, B_FALSE, "unable to destroy zone"); 898 return (-1); 899 } 900 901 if ((err = zonecfg_destroy_snapshot(zone_name)) != Z_OK) 902 zerror(zlogp, B_FALSE, "destroying snapshot: %s", 903 zonecfg_strerror(err)); 904 |
905 if (brand_poststatechg(zlogp, zstate, Z_HALT) != 0) 906 return (-1); 907 |
|
814 return (0); 815} 816 817/* 818 * Generate AUE_zone_state for a command that boots a zone. 819 */ 820static void 821audit_put_record(zlog_t *zlogp, ucred_t *uc, int return_val, --- 205 unchanged lines hidden (view full) --- 1027 zerror(zlogp, B_FALSE, 1028 "%s operation is invalid for zones in state '%s'", 1029 z_cmd_name(cmd), zone_state_str(zstate)); 1030 break; 1031 1032 case ZONE_STATE_INSTALLED: 1033 switch (cmd) { 1034 case Z_READY: | 908 return (0); 909} 910 911/* 912 * Generate AUE_zone_state for a command that boots a zone. 913 */ 914static void 915audit_put_record(zlog_t *zlogp, ucred_t *uc, int return_val, --- 205 unchanged lines hidden (view full) --- 1121 zerror(zlogp, B_FALSE, 1122 "%s operation is invalid for zones in state '%s'", 1123 z_cmd_name(cmd), zone_state_str(zstate)); 1124 break; 1125 1126 case ZONE_STATE_INSTALLED: 1127 switch (cmd) { 1128 case Z_READY: |
1035 rval = zone_ready(zlogp, Z_MNT_BOOT); | 1129 rval = zone_ready(zlogp, Z_MNT_BOOT, zstate); |
1036 if (rval == 0) 1037 eventstream_write(Z_EVT_ZONE_READIED); 1038 break; 1039 case Z_BOOT: 1040 case Z_FORCEBOOT: 1041 eventstream_write(Z_EVT_ZONE_BOOTING); | 1130 if (rval == 0) 1131 eventstream_write(Z_EVT_ZONE_READIED); 1132 break; 1133 case Z_BOOT: 1134 case Z_FORCEBOOT: 1135 eventstream_write(Z_EVT_ZONE_BOOTING); |
1042 if ((rval = zone_ready(zlogp, Z_MNT_BOOT)) == 0) 1043 rval = zone_bootup(zlogp, zargp->bootbuf); | 1136 if ((rval = zone_ready(zlogp, Z_MNT_BOOT, zstate)) 1137 == 0) { 1138 rval = zone_bootup(zlogp, zargp->bootbuf, 1139 zstate); 1140 } |
1044 audit_put_record(zlogp, uc, rval, "boot"); 1045 if (rval != 0) { 1046 bringup_failure_recovery = B_TRUE; | 1141 audit_put_record(zlogp, uc, rval, "boot"); 1142 if (rval != 0) { 1143 bringup_failure_recovery = B_TRUE; |
1047 (void) zone_halt(zlogp, B_FALSE, B_FALSE); | 1144 (void) zone_halt(zlogp, B_FALSE, B_FALSE, 1145 zstate); |
1048 eventstream_write(Z_EVT_ZONE_BOOTFAILED); 1049 } 1050 break; 1051 case Z_HALT: 1052 if (kernelcall) /* Invalid; can't happen */ 1053 abort(); 1054 /* 1055 * We could have two clients racing to halt this --- 30 unchanged lines hidden (view full) --- 1086 "%s operation is invalid for branded " 1087 "zones", z_cmd_name(cmd)); 1088 rval = -1; 1089 break; 1090 } 1091 1092 rval = zone_ready(zlogp, 1093 strcmp(zargp->bootbuf, "-U") == 0 ? | 1146 eventstream_write(Z_EVT_ZONE_BOOTFAILED); 1147 } 1148 break; 1149 case Z_HALT: 1150 if (kernelcall) /* Invalid; can't happen */ 1151 abort(); 1152 /* 1153 * We could have two clients racing to halt this --- 30 unchanged lines hidden (view full) --- 1184 "%s operation is invalid for branded " 1185 "zones", z_cmd_name(cmd)); 1186 rval = -1; 1187 break; 1188 } 1189 1190 rval = zone_ready(zlogp, 1191 strcmp(zargp->bootbuf, "-U") == 0 ? |
1094 Z_MNT_UPDATE : Z_MNT_SCRATCH); | 1192 Z_MNT_UPDATE : Z_MNT_SCRATCH, zstate); |
1095 if (rval != 0) 1096 break; 1097 1098 eventstream_write(Z_EVT_ZONE_READIED); 1099 1100 /* Get a handle to the brand info for this zone */ 1101 if ((bh = brand_open(brand_name)) == NULL) { 1102 rval = -1; --- 44 unchanged lines hidden (view full) --- 1147 */ 1148 zerror(zlogp, B_FALSE, "zone is already ready"); 1149 rval = 0; 1150 break; 1151 case Z_BOOT: 1152 (void) strlcpy(boot_args, zargp->bootbuf, 1153 sizeof (boot_args)); 1154 eventstream_write(Z_EVT_ZONE_BOOTING); | 1193 if (rval != 0) 1194 break; 1195 1196 eventstream_write(Z_EVT_ZONE_READIED); 1197 1198 /* Get a handle to the brand info for this zone */ 1199 if ((bh = brand_open(brand_name)) == NULL) { 1200 rval = -1; --- 44 unchanged lines hidden (view full) --- 1245 */ 1246 zerror(zlogp, B_FALSE, "zone is already ready"); 1247 rval = 0; 1248 break; 1249 case Z_BOOT: 1250 (void) strlcpy(boot_args, zargp->bootbuf, 1251 sizeof (boot_args)); 1252 eventstream_write(Z_EVT_ZONE_BOOTING); |
1155 rval = zone_bootup(zlogp, zargp->bootbuf); | 1253 rval = zone_bootup(zlogp, zargp->bootbuf, zstate); |
1156 audit_put_record(zlogp, uc, rval, "boot"); 1157 if (rval != 0) { 1158 bringup_failure_recovery = B_TRUE; | 1254 audit_put_record(zlogp, uc, rval, "boot"); 1255 if (rval != 0) { 1256 bringup_failure_recovery = B_TRUE; |
1159 (void) zone_halt(zlogp, B_FALSE, B_TRUE); | 1257 (void) zone_halt(zlogp, B_FALSE, B_TRUE, 1258 zstate); |
1160 eventstream_write(Z_EVT_ZONE_BOOTFAILED); 1161 } 1162 boot_args[0] = '\0'; 1163 break; 1164 case Z_HALT: 1165 if (kernelcall) /* Invalid; can't happen */ 1166 abort(); | 1259 eventstream_write(Z_EVT_ZONE_BOOTFAILED); 1260 } 1261 boot_args[0] = '\0'; 1262 break; 1263 case Z_HALT: 1264 if (kernelcall) /* Invalid; can't happen */ 1265 abort(); |
1167 if ((rval = zone_halt(zlogp, B_FALSE, B_FALSE)) != 0) | 1266 if ((rval = zone_halt(zlogp, B_FALSE, B_FALSE, zstate)) 1267 != 0) |
1168 break; 1169 eventstream_write(Z_EVT_ZONE_HALTED); 1170 break; 1171 case Z_REBOOT: 1172 case Z_NOTE_UNINSTALLING: 1173 case Z_MOUNT: 1174 case Z_UNMOUNT: 1175 if (kernelcall) /* Invalid; can't happen */ --- 6 unchanged lines hidden (view full) --- 1182 } 1183 break; 1184 1185 case ZONE_STATE_MOUNTED: 1186 switch (cmd) { 1187 case Z_UNMOUNT: 1188 if (kernelcall) /* Invalid; can't happen */ 1189 abort(); | 1268 break; 1269 eventstream_write(Z_EVT_ZONE_HALTED); 1270 break; 1271 case Z_REBOOT: 1272 case Z_NOTE_UNINSTALLING: 1273 case Z_MOUNT: 1274 case Z_UNMOUNT: 1275 if (kernelcall) /* Invalid; can't happen */ --- 6 unchanged lines hidden (view full) --- 1282 } 1283 break; 1284 1285 case ZONE_STATE_MOUNTED: 1286 switch (cmd) { 1287 case Z_UNMOUNT: 1288 if (kernelcall) /* Invalid; can't happen */ 1289 abort(); |
1190 rval = zone_halt(zlogp, B_TRUE, B_FALSE); | 1290 rval = zone_halt(zlogp, B_TRUE, B_FALSE, zstate); |
1191 if (rval == 0) { 1192 eventstream_write(Z_EVT_ZONE_HALTED); 1193 (void) sema_post(&scratch_sem); 1194 } 1195 break; 1196 default: 1197 if (kernelcall) /* Invalid; can't happen */ 1198 abort(); --- 5 unchanged lines hidden (view full) --- 1204 } 1205 break; 1206 1207 case ZONE_STATE_RUNNING: 1208 case ZONE_STATE_SHUTTING_DOWN: 1209 case ZONE_STATE_DOWN: 1210 switch (cmd) { 1211 case Z_READY: | 1291 if (rval == 0) { 1292 eventstream_write(Z_EVT_ZONE_HALTED); 1293 (void) sema_post(&scratch_sem); 1294 } 1295 break; 1296 default: 1297 if (kernelcall) /* Invalid; can't happen */ 1298 abort(); --- 5 unchanged lines hidden (view full) --- 1304 } 1305 break; 1306 1307 case ZONE_STATE_RUNNING: 1308 case ZONE_STATE_SHUTTING_DOWN: 1309 case ZONE_STATE_DOWN: 1310 switch (cmd) { 1311 case Z_READY: |
1212 if ((rval = zone_halt(zlogp, B_FALSE, B_TRUE)) != 0) | 1312 if ((rval = zone_halt(zlogp, B_FALSE, B_TRUE, zstate)) 1313 != 0) |
1213 break; | 1314 break; |
1214 if ((rval = zone_ready(zlogp, Z_MNT_BOOT)) == 0) | 1315 if ((rval = zone_ready(zlogp, Z_MNT_BOOT, zstate)) == 0) |
1215 eventstream_write(Z_EVT_ZONE_READIED); 1216 else 1217 eventstream_write(Z_EVT_ZONE_HALTED); 1218 break; 1219 case Z_BOOT: 1220 /* 1221 * We could have two clients racing to boot this 1222 * zone; the second client loses, but his request 1223 * doesn't fail, since the zone is now in the desired 1224 * state. 1225 */ 1226 zerror(zlogp, B_FALSE, "zone is already booted"); 1227 rval = 0; 1228 break; 1229 case Z_HALT: | 1316 eventstream_write(Z_EVT_ZONE_READIED); 1317 else 1318 eventstream_write(Z_EVT_ZONE_HALTED); 1319 break; 1320 case Z_BOOT: 1321 /* 1322 * We could have two clients racing to boot this 1323 * zone; the second client loses, but his request 1324 * doesn't fail, since the zone is now in the desired 1325 * state. 1326 */ 1327 zerror(zlogp, B_FALSE, "zone is already booted"); 1328 rval = 0; 1329 break; 1330 case Z_HALT: |
1230 if ((rval = zone_halt(zlogp, B_FALSE, B_FALSE)) != 0) | 1331 if ((rval = zone_halt(zlogp, B_FALSE, B_FALSE, zstate)) 1332 != 0) |
1231 break; 1232 eventstream_write(Z_EVT_ZONE_HALTED); 1233 break; 1234 case Z_REBOOT: 1235 (void) strlcpy(boot_args, zargp->bootbuf, 1236 sizeof (boot_args)); 1237 eventstream_write(Z_EVT_ZONE_REBOOTING); | 1333 break; 1334 eventstream_write(Z_EVT_ZONE_HALTED); 1335 break; 1336 case Z_REBOOT: 1337 (void) strlcpy(boot_args, zargp->bootbuf, 1338 sizeof (boot_args)); 1339 eventstream_write(Z_EVT_ZONE_REBOOTING); |
1238 if ((rval = zone_halt(zlogp, B_FALSE, B_TRUE)) != 0) { | 1340 if ((rval = zone_halt(zlogp, B_FALSE, B_TRUE, zstate)) 1341 != 0) { |
1239 eventstream_write(Z_EVT_ZONE_BOOTFAILED); 1240 boot_args[0] = '\0'; 1241 break; 1242 } | 1342 eventstream_write(Z_EVT_ZONE_BOOTFAILED); 1343 boot_args[0] = '\0'; 1344 break; 1345 } |
1243 if ((rval = zone_ready(zlogp, Z_MNT_BOOT)) != 0) { | 1346 if ((rval = zone_ready(zlogp, Z_MNT_BOOT, zstate)) 1347 != 0) { |
1244 eventstream_write(Z_EVT_ZONE_BOOTFAILED); 1245 boot_args[0] = '\0'; 1246 break; 1247 } | 1348 eventstream_write(Z_EVT_ZONE_BOOTFAILED); 1349 boot_args[0] = '\0'; 1350 break; 1351 } |
1248 rval = zone_bootup(zlogp, zargp->bootbuf); | 1352 rval = zone_bootup(zlogp, zargp->bootbuf, zstate); |
1249 audit_put_record(zlogp, uc, rval, "reboot"); 1250 if (rval != 0) { | 1353 audit_put_record(zlogp, uc, rval, "reboot"); 1354 if (rval != 0) { |
1251 (void) zone_halt(zlogp, B_FALSE, B_TRUE); | 1355 (void) zone_halt(zlogp, B_FALSE, B_TRUE, 1356 zstate); |
1252 eventstream_write(Z_EVT_ZONE_BOOTFAILED); 1253 } 1254 boot_args[0] = '\0'; 1255 break; 1256 case Z_NOTE_UNINSTALLING: 1257 case Z_MOUNT: 1258 case Z_UNMOUNT: 1259 zerror(zlogp, B_FALSE, "%s operation is invalid " --- 165 unchanged lines hidden (view full) --- 1425 goto top; 1426 } 1427 ret = 0; 1428out: 1429 (void) close(doorfd); 1430 return (ret); 1431} 1432 | 1357 eventstream_write(Z_EVT_ZONE_BOOTFAILED); 1358 } 1359 boot_args[0] = '\0'; 1360 break; 1361 case Z_NOTE_UNINSTALLING: 1362 case Z_MOUNT: 1363 case Z_UNMOUNT: 1364 zerror(zlogp, B_FALSE, "%s operation is invalid " --- 165 unchanged lines hidden (view full) --- 1530 goto top; 1531 } 1532 ret = 0; 1533out: 1534 (void) close(doorfd); 1535 return (ret); 1536} 1537 |
1538/* 1539 * Setup the brand's pre and post state change callbacks, as well as the 1540 * query callback, if any of these exist. 1541 */ 1542static int 1543brand_callback_init(brand_handle_t bh, char *zone_name) 1544{ 1545 char zpath[MAXPATHLEN]; 1546 1547 if (zone_get_zonepath(zone_name, zpath, sizeof (zpath)) != Z_OK) 1548 return (-1); 1549 1550 (void) strlcpy(pre_statechg_hook, EXEC_PREFIX, 1551 sizeof (pre_statechg_hook)); 1552 1553 if (brand_get_prestatechange(bh, zone_name, zpath, 1554 pre_statechg_hook + EXEC_LEN, 1555 sizeof (pre_statechg_hook) - EXEC_LEN) != 0) 1556 return (-1); 1557 1558 if (strlen(pre_statechg_hook) <= EXEC_LEN) 1559 pre_statechg_hook[0] = '\0'; 1560 1561 (void) strlcpy(post_statechg_hook, EXEC_PREFIX, 1562 sizeof (post_statechg_hook)); 1563 1564 if (brand_get_poststatechange(bh, zone_name, zpath, 1565 post_statechg_hook + EXEC_LEN, 1566 sizeof (post_statechg_hook) - EXEC_LEN) != 0) 1567 return (-1); 1568 1569 if (strlen(post_statechg_hook) <= EXEC_LEN) 1570 post_statechg_hook[0] = '\0'; 1571 1572 (void) strlcpy(query_hook, EXEC_PREFIX, 1573 sizeof (query_hook)); 1574 1575 if (brand_get_query(bh, zone_name, zpath, query_hook + EXEC_LEN, 1576 sizeof (query_hook) - EXEC_LEN) != 0) 1577 return (-1); 1578 1579 if (strlen(query_hook) <= EXEC_LEN) 1580 query_hook[0] = '\0'; 1581 1582 return (0); 1583} 1584 |
|
1433int 1434main(int argc, char *argv[]) 1435{ 1436 int opt; 1437 zoneid_t zid; 1438 priv_set_t *privset; 1439 zone_state_t zstate; 1440 char parents_locale[MAXPATHLEN]; --- 110 unchanged lines hidden (view full) --- 1551 /* Get a handle to the brand info for this zone */ 1552 if ((zone_get_brand(zone_name, brand_name, sizeof (brand_name)) 1553 != Z_OK) || (bh = brand_open(brand_name)) == NULL) { 1554 zerror(zlogp, B_FALSE, "unable to determine zone brand"); 1555 return (1); 1556 } 1557 zone_isnative = brand_is_native(bh); 1558 zone_iscluster = (strcmp(brand_name, CLUSTER_BRAND_NAME) == 0); | 1585int 1586main(int argc, char *argv[]) 1587{ 1588 int opt; 1589 zoneid_t zid; 1590 priv_set_t *privset; 1591 zone_state_t zstate; 1592 char parents_locale[MAXPATHLEN]; --- 110 unchanged lines hidden (view full) --- 1703 /* Get a handle to the brand info for this zone */ 1704 if ((zone_get_brand(zone_name, brand_name, sizeof (brand_name)) 1705 != Z_OK) || (bh = brand_open(brand_name)) == NULL) { 1706 zerror(zlogp, B_FALSE, "unable to determine zone brand"); 1707 return (1); 1708 } 1709 zone_isnative = brand_is_native(bh); 1710 zone_iscluster = (strcmp(brand_name, CLUSTER_BRAND_NAME) == 0); |
1711 1712 /* Get state change brand hooks. */ 1713 if (brand_callback_init(bh, zone_name) == -1) { 1714 zerror(zlogp, B_TRUE, 1715 "failed to initialize brand state change hooks"); 1716 brand_close(bh); 1717 return (1); 1718 } 1719 |
|
1559 brand_close(bh); 1560 1561 /* 1562 * Check that we have all privileges. It would be nice to pare 1563 * this down, but this is at least a first cut. 1564 */ 1565 if ((privset = priv_allocset()) == NULL) { 1566 zerror(zlogp, B_TRUE, "%s failed", "priv_allocset"); --- 277 unchanged lines hidden --- | 1720 brand_close(bh); 1721 1722 /* 1723 * Check that we have all privileges. It would be nice to pare 1724 * this down, but this is at least a first cut. 1725 */ 1726 if ((privset = priv_allocset()) == NULL) { 1727 zerror(zlogp, B_TRUE, "%s failed", "priv_allocset"); --- 277 unchanged lines hidden --- |