4736 }
4737 if ((res = zonecfg_get_snapshot_handle(zone_namep, handle)) != Z_OK) {
4738 zerror(zlogp, B_FALSE, "invalid configuration");
4739 goto out;
4740 }
4741
4742 if ((res = setup_zone_hostid(handle, zlogp, zoneid)) != Z_OK)
4743 goto out;
4744
4745 if ((res = setup_zone_fs_allowed(handle, zlogp, zoneid)) != Z_OK)
4746 goto out;
4747
4748 if ((res = setup_zone_secflags(handle, zlogp, zoneid)) != Z_OK)
4749 goto out;
4750
4751 out:
4752 zonecfg_fini_handle(handle);
4753 return (res);
4754 }
4755
4756 zoneid_t
4757 vplat_create(zlog_t *zlogp, zone_mnt_t mount_cmd)
4758 {
4759 zoneid_t rval = -1;
4760 priv_set_t *privs;
4761 char rootpath[MAXPATHLEN];
4762 char *rctlbuf = NULL;
4763 size_t rctlbufsz = 0;
4764 char *zfsbuf = NULL;
4765 size_t zfsbufsz = 0;
4766 zoneid_t zoneid = -1;
4767 int xerr;
4768 char *kzone;
4769 FILE *fp = NULL;
4770 tsol_zcent_t *zcent = NULL;
4771 int match = 0;
4772 int doi = 0;
4773 int flags;
4774 zone_iptype_t iptype;
4775
4776 if (zone_get_rootpath(zone_name, rootpath, sizeof (rootpath)) != Z_OK) {
4777 zerror(zlogp, B_TRUE, "unable to determine zone root");
4878 NULL, 0) == 0) {
4879 zerror(zlogp, B_FALSE, "scratch zone already running");
4880 goto error;
4881 }
4882 /* This is the preferred name */
4883 (void) snprintf(kernzone, sizeof (kernzone), "SUNWlu-%s",
4884 zone_name);
4885 srandom(getpid());
4886 while (zonecfg_reverse_scratch(fp, kernzone, NULL, 0, NULL,
4887 0) == 0) {
4888 /* This is just an arbitrary name; note "." usage */
4889 (void) snprintf(kernzone, sizeof (kernzone),
4890 "SUNWlu.%08lX%08lX", random(), random());
4891 }
4892 kzone = kernzone;
4893 }
4894
4895 xerr = 0;
4896 if ((zoneid = zone_create(kzone, rootpath, privs, rctlbuf,
4897 rctlbufsz, zfsbuf, zfsbufsz, &xerr, match, doi, zlabel,
4898 flags)) == -1) {
4899 if (xerr == ZE_AREMOUNTS) {
4900 if (zonecfg_find_mounts(rootpath, NULL, NULL) < 1) {
4901 zerror(zlogp, B_FALSE,
4902 "An unknown file-system is mounted on "
4903 "a subdirectory of %s", rootpath);
4904 } else {
4905
4906 zerror(zlogp, B_FALSE,
4907 "These file-systems are mounted on "
4908 "subdirectories of %s:", rootpath);
4909 (void) zonecfg_find_mounts(rootpath,
4910 prtmount, zlogp);
4911 }
4912 } else if (xerr == ZE_CHROOTED) {
4913 zerror(zlogp, B_FALSE, "%s: "
4914 "cannot create a zone from a chrooted "
4915 "environment", "zone_create");
4916 } else if (xerr == ZE_LABELINUSE) {
4917 char zonename[ZONENAME_MAX];
4918 (void) getzonenamebyid(getzoneidbylabel(zlabel),
|
4736 }
4737 if ((res = zonecfg_get_snapshot_handle(zone_namep, handle)) != Z_OK) {
4738 zerror(zlogp, B_FALSE, "invalid configuration");
4739 goto out;
4740 }
4741
4742 if ((res = setup_zone_hostid(handle, zlogp, zoneid)) != Z_OK)
4743 goto out;
4744
4745 if ((res = setup_zone_fs_allowed(handle, zlogp, zoneid)) != Z_OK)
4746 goto out;
4747
4748 if ((res = setup_zone_secflags(handle, zlogp, zoneid)) != Z_OK)
4749 goto out;
4750
4751 out:
4752 zonecfg_fini_handle(handle);
4753 return (res);
4754 }
4755
4756 /*
4757 * The zone_did is a persistent debug ID. Each zone should have a unique ID
4758 * in the kernel. This is used for things like DTrace which want to monitor
4759 * zones across reboots. They can't use the zoneid since that changes on
4760 * each boot.
4761 */
4762 zoneid_t
4763 vplat_create(zlog_t *zlogp, zone_mnt_t mount_cmd, zoneid_t zone_did)
4764 {
4765 zoneid_t rval = -1;
4766 priv_set_t *privs;
4767 char rootpath[MAXPATHLEN];
4768 char *rctlbuf = NULL;
4769 size_t rctlbufsz = 0;
4770 char *zfsbuf = NULL;
4771 size_t zfsbufsz = 0;
4772 zoneid_t zoneid = -1;
4773 int xerr;
4774 char *kzone;
4775 FILE *fp = NULL;
4776 tsol_zcent_t *zcent = NULL;
4777 int match = 0;
4778 int doi = 0;
4779 int flags;
4780 zone_iptype_t iptype;
4781
4782 if (zone_get_rootpath(zone_name, rootpath, sizeof (rootpath)) != Z_OK) {
4783 zerror(zlogp, B_TRUE, "unable to determine zone root");
4884 NULL, 0) == 0) {
4885 zerror(zlogp, B_FALSE, "scratch zone already running");
4886 goto error;
4887 }
4888 /* This is the preferred name */
4889 (void) snprintf(kernzone, sizeof (kernzone), "SUNWlu-%s",
4890 zone_name);
4891 srandom(getpid());
4892 while (zonecfg_reverse_scratch(fp, kernzone, NULL, 0, NULL,
4893 0) == 0) {
4894 /* This is just an arbitrary name; note "." usage */
4895 (void) snprintf(kernzone, sizeof (kernzone),
4896 "SUNWlu.%08lX%08lX", random(), random());
4897 }
4898 kzone = kernzone;
4899 }
4900
4901 xerr = 0;
4902 if ((zoneid = zone_create(kzone, rootpath, privs, rctlbuf,
4903 rctlbufsz, zfsbuf, zfsbufsz, &xerr, match, doi, zlabel,
4904 flags, zone_did)) == -1) {
4905 if (xerr == ZE_AREMOUNTS) {
4906 if (zonecfg_find_mounts(rootpath, NULL, NULL) < 1) {
4907 zerror(zlogp, B_FALSE,
4908 "An unknown file-system is mounted on "
4909 "a subdirectory of %s", rootpath);
4910 } else {
4911
4912 zerror(zlogp, B_FALSE,
4913 "These file-systems are mounted on "
4914 "subdirectories of %s:", rootpath);
4915 (void) zonecfg_find_mounts(rootpath,
4916 prtmount, zlogp);
4917 }
4918 } else if (xerr == ZE_CHROOTED) {
4919 zerror(zlogp, B_FALSE, "%s: "
4920 "cannot create a zone from a chrooted "
4921 "environment", "zone_create");
4922 } else if (xerr == ZE_LABELINUSE) {
4923 char zonename[ZONENAME_MAX];
4924 (void) getzonenamebyid(getzoneidbylabel(zlabel),
|