zoneadm.c (c9f134eabbac5c231b6e7ca9ba96f45d88b95347) | zoneadm.c (71443f5a40b6c951461366ce28749d9df235c6ef) |
---|---|
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 --- 4259 unchanged lines hidden (view full) --- 4268 4269 return ((err == Z_OK) ? Z_OK : Z_ERR); 4270} 4271 4272/* ARGSUSED */ 4273static int 4274detach_func(int argc, char *argv[]) 4275{ | 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 --- 4259 unchanged lines hidden (view full) --- 4268 4269 return ((err == Z_OK) ? Z_OK : Z_ERR); 4270} 4271 4272/* ARGSUSED */ 4273static int 4274detach_func(int argc, char *argv[]) 4275{ |
4276 int lockfd; | 4276 int lockfd = -1; |
4277 int err, arg; 4278 char zonepath[MAXPATHLEN]; 4279 char cmdbuf[MAXPATHLEN]; 4280 char precmdbuf[MAXPATHLEN]; | 4277 int err, arg; 4278 char zonepath[MAXPATHLEN]; 4279 char cmdbuf[MAXPATHLEN]; 4280 char precmdbuf[MAXPATHLEN]; |
4281 zone_dochandle_t handle; | |
4282 boolean_t execute = B_TRUE; 4283 boolean_t brand_help = B_FALSE; 4284 brand_handle_t bh = NULL; 4285 int status; 4286 4287 if (zonecfg_in_alt_root()) { 4288 zerror(gettext("cannot detach zone in alternate root")); 4289 return (Z_ERR); --- 48 unchanged lines hidden (view full) --- 4338 4339 if ((err = zone_get_zonepath(target_zone, zonepath, sizeof (zonepath))) 4340 != Z_OK) { 4341 errno = err; 4342 zperror2(target_zone, gettext("could not get zone path")); 4343 return (Z_ERR); 4344 } 4345 | 4281 boolean_t execute = B_TRUE; 4282 boolean_t brand_help = B_FALSE; 4283 brand_handle_t bh = NULL; 4284 int status; 4285 4286 if (zonecfg_in_alt_root()) { 4287 zerror(gettext("cannot detach zone in alternate root")); 4288 return (Z_ERR); --- 48 unchanged lines hidden (view full) --- 4337 4338 if ((err = zone_get_zonepath(target_zone, zonepath, sizeof (zonepath))) 4339 != Z_OK) { 4340 errno = err; 4341 zperror2(target_zone, gettext("could not get zone path")); 4342 return (Z_ERR); 4343 } 4344 |
4346 if ((handle = zonecfg_init_handle()) == NULL) { 4347 zperror(cmd_to_str(CMD_DETACH), B_TRUE); 4348 return (Z_ERR); 4349 } 4350 4351 if ((err = zonecfg_get_handle(target_zone, handle)) != Z_OK) { 4352 errno = err; 4353 zperror(cmd_to_str(CMD_DETACH), B_TRUE); 4354 zonecfg_fini_handle(handle); 4355 return (Z_ERR); 4356 } 4357 | |
4358 /* Fetch the detach and predetach hooks from the brand configuration. */ 4359 if ((bh = brand_open(target_brand)) == NULL) { 4360 zerror(gettext("missing or invalid brand")); 4361 return (Z_ERR); 4362 } 4363 4364 if (get_hook(bh, cmdbuf, sizeof (cmdbuf), brand_get_detach, target_zone, 4365 zonepath) != Z_OK) { --- 17 unchanged lines hidden (view full) --- 4383 4384 /* Append all options to detach hook. */ 4385 if (addoptions(cmdbuf, argv, sizeof (cmdbuf)) != Z_OK) 4386 return (Z_ERR); 4387 4388 if (execute && zonecfg_grab_lock_file(target_zone, &lockfd) != Z_OK) { 4389 zerror(gettext("another %s may have an operation in progress."), 4390 "zoneadm"); | 4345 /* Fetch the detach and predetach hooks from the brand configuration. */ 4346 if ((bh = brand_open(target_brand)) == NULL) { 4347 zerror(gettext("missing or invalid brand")); 4348 return (Z_ERR); 4349 } 4350 4351 if (get_hook(bh, cmdbuf, sizeof (cmdbuf), brand_get_detach, target_zone, 4352 zonepath) != Z_OK) { --- 17 unchanged lines hidden (view full) --- 4370 4371 /* Append all options to detach hook. */ 4372 if (addoptions(cmdbuf, argv, sizeof (cmdbuf)) != Z_OK) 4373 return (Z_ERR); 4374 4375 if (execute && zonecfg_grab_lock_file(target_zone, &lockfd) != Z_OK) { 4376 zerror(gettext("another %s may have an operation in progress."), 4377 "zoneadm"); |
4391 zonecfg_fini_handle(handle); | |
4392 return (Z_ERR); 4393 } 4394 4395 /* If we have a brand predetach hook, run it. */ 4396 if (!brand_help && precmdbuf[0] != '\0') { 4397 status = do_subproc(precmdbuf); 4398 if (subproc_status(gettext("brand-specific predetach"), 4399 status, B_FALSE) != ZONE_SUBPROC_OK) { 4400 | 4378 return (Z_ERR); 4379 } 4380 4381 /* If we have a brand predetach hook, run it. */ 4382 if (!brand_help && precmdbuf[0] != '\0') { 4383 status = do_subproc(precmdbuf); 4384 if (subproc_status(gettext("brand-specific predetach"), 4385 status, B_FALSE) != ZONE_SUBPROC_OK) { 4386 |
4401 if (execute) | 4387 if (execute) { 4388 assert(lockfd >= 0); |
4402 zonecfg_release_lock_file(target_zone, lockfd); | 4389 zonecfg_release_lock_file(target_zone, lockfd); |
4390 lockfd = -1; 4391 } 4392 4393 assert(lockfd == -1); |
|
4403 return (Z_ERR); 4404 } 4405 } 4406 4407 if (cmdbuf[0] != '\0') { 4408 /* Run the detach hook */ 4409 status = do_subproc_interactive(cmdbuf); 4410 if ((status = subproc_status(gettext("brand-specific detach"), 4411 status, B_FALSE)) != ZONE_SUBPROC_OK) { 4412 if (status == ZONE_SUBPROC_USAGE && !brand_help) 4413 sub_usage(SHELP_DETACH, CMD_DETACH); 4414 | 4394 return (Z_ERR); 4395 } 4396 } 4397 4398 if (cmdbuf[0] != '\0') { 4399 /* Run the detach hook */ 4400 status = do_subproc_interactive(cmdbuf); 4401 if ((status = subproc_status(gettext("brand-specific detach"), 4402 status, B_FALSE)) != ZONE_SUBPROC_OK) { 4403 if (status == ZONE_SUBPROC_USAGE && !brand_help) 4404 sub_usage(SHELP_DETACH, CMD_DETACH); 4405 |
4415 if (execute) | 4406 if (execute) { 4407 assert(lockfd >= 0); |
4416 zonecfg_release_lock_file(target_zone, lockfd); | 4408 zonecfg_release_lock_file(target_zone, lockfd); |
4409 lockfd = -1; 4410 } |
|
4417 | 4411 |
4412 assert(lockfd == -1); |
|
4418 return (Z_ERR); 4419 } 4420 4421 } else { | 4413 return (Z_ERR); 4414 } 4415 4416 } else { |
4417 zone_dochandle_t handle; 4418 |
|
4422 /* If just help, we're done since there is no brand help. */ | 4419 /* If just help, we're done since there is no brand help. */ |
4423 if (brand_help) | 4420 if (brand_help) { 4421 assert(lockfd == -1); |
4424 return (Z_OK); | 4422 return (Z_OK); |
4423 } |
|
4425 4426 /* 4427 * Run the built-in detach support. Just generate a simple 4428 * zone definition XML file and detach. 4429 */ 4430 4431 /* Don't detach the zone if anything is still mounted there */ 4432 if (execute && zonecfg_find_mounts(zonepath, NULL, NULL)) { --- 8 unchanged lines hidden (view full) --- 4441 zperror(cmd_to_str(CMD_DETACH), B_TRUE); 4442 err = ZONE_SUBPROC_NOTCOMPLETE; 4443 goto done; 4444 } 4445 4446 if ((err = zonecfg_get_handle(target_zone, handle)) != Z_OK) { 4447 errno = err; 4448 zperror(cmd_to_str(CMD_DETACH), B_TRUE); | 4424 4425 /* 4426 * Run the built-in detach support. Just generate a simple 4427 * zone definition XML file and detach. 4428 */ 4429 4430 /* Don't detach the zone if anything is still mounted there */ 4431 if (execute && zonecfg_find_mounts(zonepath, NULL, NULL)) { --- 8 unchanged lines hidden (view full) --- 4440 zperror(cmd_to_str(CMD_DETACH), B_TRUE); 4441 err = ZONE_SUBPROC_NOTCOMPLETE; 4442 goto done; 4443 } 4444 4445 if ((err = zonecfg_get_handle(target_zone, handle)) != Z_OK) { 4446 errno = err; 4447 zperror(cmd_to_str(CMD_DETACH), B_TRUE); |
4449 zonecfg_fini_handle(handle); 4450 goto done; 4451 } | |
4452 | 4448 |
4453 if ((err = zonecfg_detach_save(handle, | 4449 } else if ((err = zonecfg_detach_save(handle, |
4454 (execute ? 0 : ZONE_DRY_RUN))) != Z_OK) { 4455 errno = err; 4456 zperror(gettext("saving the detach manifest failed"), 4457 B_TRUE); | 4450 (execute ? 0 : ZONE_DRY_RUN))) != Z_OK) { 4451 errno = err; 4452 zperror(gettext("saving the detach manifest failed"), 4453 B_TRUE); |
4458 goto done; | |
4459 } 4460 4461 zonecfg_fini_handle(handle); | 4454 } 4455 4456 zonecfg_fini_handle(handle); |
4457 if (err != Z_OK) 4458 goto done; |
|
4462 } 4463 4464 /* 4465 * Set the zone state back to configured unless we are running with the 4466 * no-execute option. 4467 */ 4468 if (execute && (err = zone_set_state(target_zone, 4469 ZONE_STATE_CONFIGURED)) != Z_OK) { 4470 errno = err; 4471 zperror(gettext("could not reset state"), B_TRUE); 4472 } 4473 4474done: | 4459 } 4460 4461 /* 4462 * Set the zone state back to configured unless we are running with the 4463 * no-execute option. 4464 */ 4465 if (execute && (err = zone_set_state(target_zone, 4466 ZONE_STATE_CONFIGURED)) != Z_OK) { 4467 errno = err; 4468 zperror(gettext("could not reset state"), B_TRUE); 4469 } 4470 4471done: |
4475 zonecfg_fini_handle(handle); 4476 if (execute) | 4472 if (execute) { 4473 assert(lockfd >= 0); |
4477 zonecfg_release_lock_file(target_zone, lockfd); | 4474 zonecfg_release_lock_file(target_zone, lockfd); |
4475 lockfd = -1; 4476 } |
|
4478 | 4477 |
4478 assert(lockfd == -1); |
|
4479 return ((err == Z_OK) ? Z_OK : Z_ERR); 4480} 4481 4482/* 4483 * Determine the brand when doing a dry-run attach. The zone does not have to 4484 * exist, so we have to read the incoming manifest to determine the zone's 4485 * brand. 4486 * --- 119 unchanged lines hidden (view full) --- 4606 4607 return ((res == Z_OK) ? Z_OK : Z_ERR); 4608} 4609 4610/* ARGSUSED */ 4611static int 4612attach_func(int argc, char *argv[]) 4613{ | 4479 return ((err == Z_OK) ? Z_OK : Z_ERR); 4480} 4481 4482/* 4483 * Determine the brand when doing a dry-run attach. The zone does not have to 4484 * exist, so we have to read the incoming manifest to determine the zone's 4485 * brand. 4486 * --- 119 unchanged lines hidden (view full) --- 4606 4607 return ((res == Z_OK) ? Z_OK : Z_ERR); 4608} 4609 4610/* ARGSUSED */ 4611static int 4612attach_func(int argc, char *argv[]) 4613{ |
4614 int lockfd; | 4614 int lockfd = -1; |
4615 int err, arg; 4616 boolean_t force = B_FALSE; 4617 zone_dochandle_t handle; 4618 char zonepath[MAXPATHLEN]; 4619 char cmdbuf[MAXPATHLEN]; 4620 char postcmdbuf[MAXPATHLEN]; 4621 boolean_t execute = B_TRUE; 4622 boolean_t brand_help = B_FALSE; --- 61 unchanged lines hidden (view full) --- 4684 4685 if ((err = zone_get_zonepath(target_zone, zonepath, 4686 sizeof (zonepath))) != Z_OK) { 4687 errno = err; 4688 zperror2(target_zone, 4689 gettext("could not get zone path")); 4690 return (Z_ERR); 4691 } | 4615 int err, arg; 4616 boolean_t force = B_FALSE; 4617 zone_dochandle_t handle; 4618 char zonepath[MAXPATHLEN]; 4619 char cmdbuf[MAXPATHLEN]; 4620 char postcmdbuf[MAXPATHLEN]; 4621 boolean_t execute = B_TRUE; 4622 boolean_t brand_help = B_FALSE; --- 61 unchanged lines hidden (view full) --- 4684 4685 if ((err = zone_get_zonepath(target_zone, zonepath, 4686 sizeof (zonepath))) != Z_OK) { 4687 errno = err; 4688 zperror2(target_zone, 4689 gettext("could not get zone path")); 4690 return (Z_ERR); 4691 } |
4692 4693 if ((handle = zonecfg_init_handle()) == NULL) { 4694 zperror(cmd_to_str(CMD_ATTACH), B_TRUE); 4695 return (Z_ERR); 4696 } 4697 4698 if ((err = zonecfg_get_handle(target_zone, handle)) != Z_OK) { 4699 errno = err; 4700 zperror(cmd_to_str(CMD_ATTACH), B_TRUE); 4701 zonecfg_fini_handle(handle); 4702 return (Z_ERR); 4703 } 4704 | |
4705 } else { 4706 if (dryrun_get_brand(manifest_path, tmpmanifest, 4707 sizeof (tmpmanifest)) != Z_OK) 4708 return (Z_ERR); 4709 4710 argv[manifest_pos] = tmpmanifest; 4711 target_zone = "-"; 4712 (void) strlcpy(zonepath, "-", sizeof (zonepath)); --- 34 unchanged lines hidden (view full) --- 4747 /* Append all options to postattach hook. */ 4748 if (addoptions(postcmdbuf, argv, sizeof (postcmdbuf)) != Z_OK) 4749 return (Z_ERR); 4750 4751 if (execute && !brand_help) { 4752 if (zonecfg_grab_lock_file(target_zone, &lockfd) != Z_OK) { 4753 zerror(gettext("another %s may have an operation in " 4754 "progress."), "zoneadm"); | 4692 } else { 4693 if (dryrun_get_brand(manifest_path, tmpmanifest, 4694 sizeof (tmpmanifest)) != Z_OK) 4695 return (Z_ERR); 4696 4697 argv[manifest_pos] = tmpmanifest; 4698 target_zone = "-"; 4699 (void) strlcpy(zonepath, "-", sizeof (zonepath)); --- 34 unchanged lines hidden (view full) --- 4734 /* Append all options to postattach hook. */ 4735 if (addoptions(postcmdbuf, argv, sizeof (postcmdbuf)) != Z_OK) 4736 return (Z_ERR); 4737 4738 if (execute && !brand_help) { 4739 if (zonecfg_grab_lock_file(target_zone, &lockfd) != Z_OK) { 4740 zerror(gettext("another %s may have an operation in " 4741 "progress."), "zoneadm"); |
4755 zonecfg_fini_handle(handle); | |
4756 return (Z_ERR); 4757 } 4758 } 4759 | 4742 return (Z_ERR); 4743 } 4744 } 4745 |
4760 if (force) 4761 goto done; | 4746 if (!force) { 4747 /* 4748 * Not a force-attach, so we need to actually do the work. 4749 */ 4750 if (cmdbuf[0] != '\0') { 4751 /* Run the attach hook */ 4752 status = do_subproc_interactive(cmdbuf); 4753 if ((status = subproc_status(gettext("brand-specific " 4754 "attach"), status, B_FALSE)) != ZONE_SUBPROC_OK) { 4755 if (status == ZONE_SUBPROC_USAGE && !brand_help) 4756 sub_usage(SHELP_ATTACH, CMD_ATTACH); |
4762 | 4757 |
4763 if (cmdbuf[0] != '\0') { 4764 /* Run the attach hook */ 4765 status = do_subproc_interactive(cmdbuf); 4766 if ((status = subproc_status(gettext("brand-specific attach"), 4767 status, B_FALSE)) != ZONE_SUBPROC_OK) { 4768 if (status == ZONE_SUBPROC_USAGE && !brand_help) 4769 sub_usage(SHELP_ATTACH, CMD_ATTACH); | 4758 if (execute && !brand_help) { 4759 assert(lockfd >= 0); 4760 zonecfg_release_lock_file(target_zone, 4761 lockfd); 4762 lockfd = -1; 4763 } |
4770 | 4764 |
4771 if (execute && !brand_help) 4772 zonecfg_release_lock_file(target_zone, lockfd); 4773 4774 return (Z_ERR); | 4765 assert(lockfd == -1); 4766 return (Z_ERR); 4767 } |
4775 } 4776 | 4768 } 4769 |
4770 /* 4771 * Else run the built-in attach support. 4772 * This is a no-op since there is nothing to validate. 4773 */ 4774 4775 /* If dry-run or help, then we're done. */ 4776 if (!execute || brand_help) { 4777 if (!execute) 4778 (void) unlink(tmpmanifest); 4779 assert(lockfd == -1); 4780 return (Z_OK); 4781 } |
|
4777 } 4778 | 4782 } 4783 |
4779 /* 4780 * Else run the built-in attach support. 4781 * This is a no-op since there is nothing to validate. 4782 */ 4783 4784 /* If dry-run or help, then we're done. */ 4785 if (!execute || brand_help) { 4786 if (!execute) 4787 (void) unlink(tmpmanifest); 4788 return (Z_OK); | 4784 if ((handle = zonecfg_init_handle()) == NULL) { 4785 zperror(cmd_to_str(CMD_ATTACH), B_TRUE); 4786 err = Z_ERR; 4787 } else if ((err = zonecfg_get_handle(target_zone, handle)) != Z_OK) { 4788 errno = err; 4789 zperror(cmd_to_str(CMD_ATTACH), B_TRUE); 4790 zonecfg_fini_handle(handle); 4791 } else { 4792 zonecfg_rm_detached(handle, force); 4793 zonecfg_fini_handle(handle); |
4789 } 4790 | 4794 } 4795 |
4791done: 4792 zonecfg_rm_detached(handle, force); 4793 4794 if ((err = zone_set_state(target_zone, ZONE_STATE_INSTALLED)) != Z_OK) { | 4796 if (err == Z_OK && 4797 (err = zone_set_state(target_zone, ZONE_STATE_INSTALLED)) != Z_OK) { |
4795 errno = err; 4796 zperror(gettext("could not reset state"), B_TRUE); 4797 } 4798 | 4798 errno = err; 4799 zperror(gettext("could not reset state"), B_TRUE); 4800 } 4801 |
4799 zonecfg_fini_handle(handle); | 4802 assert(lockfd >= 0); |
4800 zonecfg_release_lock_file(target_zone, lockfd); | 4803 zonecfg_release_lock_file(target_zone, lockfd); |
4804 lockfd = -1; |
|
4801 4802 /* If we have a brand postattach hook, run it. */ 4803 if (err == Z_OK && !force && postcmdbuf[0] != '\0') { 4804 status = do_subproc(postcmdbuf); 4805 if (subproc_status(gettext("brand-specific postattach"), 4806 status, B_FALSE) != ZONE_SUBPROC_OK) { 4807 if ((err = zone_set_state(target_zone, 4808 ZONE_STATE_CONFIGURED)) != Z_OK) { 4809 errno = err; 4810 zperror(gettext("could not reset state"), 4811 B_TRUE); 4812 } | 4805 4806 /* If we have a brand postattach hook, run it. */ 4807 if (err == Z_OK && !force && postcmdbuf[0] != '\0') { 4808 status = do_subproc(postcmdbuf); 4809 if (subproc_status(gettext("brand-specific postattach"), 4810 status, B_FALSE) != ZONE_SUBPROC_OK) { 4811 if ((err = zone_set_state(target_zone, 4812 ZONE_STATE_CONFIGURED)) != Z_OK) { 4813 errno = err; 4814 zperror(gettext("could not reset state"), 4815 B_TRUE); 4816 } |
4813 return (Z_ERR); | |
4814 } 4815 } 4816 | 4817 } 4818 } 4819 |
4820 assert(lockfd == -1); |
|
4817 return ((err == Z_OK) ? Z_OK : Z_ERR); 4818} 4819 4820/* 4821 * On input, TRUE => yes, FALSE => no. 4822 * On return, TRUE => 1, FALSE => 0, could not ask => -1. 4823 */ 4824 --- 773 unchanged lines hidden --- | 4821 return ((err == Z_OK) ? Z_OK : Z_ERR); 4822} 4823 4824/* 4825 * On input, TRUE => yes, FALSE => no. 4826 * On return, TRUE => 1, FALSE => 0, could not ask => -1. 4827 */ 4828 --- 773 unchanged lines hidden --- |