usr/src/cmd/zonecfg/zonecfg.c
changeset 12633 9f2cda0ed938
parent 12626 eba16697f6c1
child 12715 cdbca398ec82
equal deleted inserted replaced
12632:2e5ce9dbe1f9 12633:9f2cda0ed938
   181 	"scheduling-class",
   181 	"scheduling-class",
   182 	"ip-type",
   182 	"ip-type",
   183 	"capped-cpu",
   183 	"capped-cpu",
   184 	"hostid",
   184 	"hostid",
   185 	"admin",
   185 	"admin",
       
   186 	"fs-allowed",
   186 	NULL
   187 	NULL
   187 };
   188 };
   188 
   189 
   189 /* These *must* match the order of the PT_ define's from zonecfg.h */
   190 /* These *must* match the order of the PT_ define's from zonecfg.h */
   190 char *prop_types[] = {
   191 char *prop_types[] = {
   225 	"ip-type",
   226 	"ip-type",
   226 	"defrouter",
   227 	"defrouter",
   227 	"hostid",
   228 	"hostid",
   228 	"user",
   229 	"user",
   229 	"auths",
   230 	"auths",
       
   231 	"fs-allowed",
   230 	NULL
   232 	NULL
   231 };
   233 };
   232 
   234 
   233 /* These *must* match the order of the PROP_VAL_ define's from zonecfg.h */
   235 /* These *must* match the order of the PROP_VAL_ define's from zonecfg.h */
   234 static char *prop_val_types[] = {
   236 static char *prop_val_types[] = {
   340 	"set " ALIAS_MAXSHMIDS "=",
   342 	"set " ALIAS_MAXSHMIDS "=",
   341 	"set " ALIAS_MAXMSGIDS "=",
   343 	"set " ALIAS_MAXMSGIDS "=",
   342 	"set " ALIAS_MAXSEMIDS "=",
   344 	"set " ALIAS_MAXSEMIDS "=",
   343 	"set " ALIAS_SHARES "=",
   345 	"set " ALIAS_SHARES "=",
   344 	"set hostid=",
   346 	"set hostid=",
       
   347 	"set fs-allowed=",
   345 	NULL
   348 	NULL
   346 };
   349 };
   347 
   350 
   348 static const char *info_cmds[] = {
   351 static const char *info_cmds[] = {
   349 	"info fs ",
   352 	"info fs ",
   371 	"info max-msg-ids",
   374 	"info max-msg-ids",
   372 	"info max-sem-ids",
   375 	"info max-sem-ids",
   373 	"info cpu-shares",
   376 	"info cpu-shares",
   374 	"info hostid",
   377 	"info hostid",
   375 	"info admin",
   378 	"info admin",
       
   379 	"info fs-allowed",
   376 	NULL
   380 	NULL
   377 };
   381 };
   378 
   382 
   379 static const char *fs_res_scope_cmds[] = {
   383 static const char *fs_res_scope_cmds[] = {
   380 	"add options ",
   384 	"add options ",
  1217 		(void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"),
  1221 		(void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"),
  1218 		    pt_to_str(PT_IPTYPE));
  1222 		    pt_to_str(PT_IPTYPE));
  1219 		(void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"),
  1223 		(void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"),
  1220 		    pt_to_str(PT_HOSTID));
  1224 		    pt_to_str(PT_HOSTID));
  1221 		(void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"),
  1225 		(void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"),
       
  1226 		    pt_to_str(PT_FS_ALLOWED));
       
  1227 		(void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"),
  1222 		    pt_to_str(PT_MAXLWPS));
  1228 		    pt_to_str(PT_MAXLWPS));
  1223 		(void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"),
  1229 		(void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"),
  1224 		    pt_to_str(PT_MAXSHMMEM));
  1230 		    pt_to_str(PT_MAXSHMMEM));
  1225 		(void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"),
  1231 		(void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"),
  1226 		    pt_to_str(PT_MAXSHMIDS));
  1232 		    pt_to_str(PT_MAXSHMIDS));
  1704 	char zonepath[MAXPATHLEN], outfile[MAXPATHLEN], pool[MAXNAMELEN];
  1710 	char zonepath[MAXPATHLEN], outfile[MAXPATHLEN], pool[MAXNAMELEN];
  1705 	char bootargs[BOOTARGS_MAX];
  1711 	char bootargs[BOOTARGS_MAX];
  1706 	char sched[MAXNAMELEN];
  1712 	char sched[MAXNAMELEN];
  1707 	char brand[MAXNAMELEN];
  1713 	char brand[MAXNAMELEN];
  1708 	char hostidp[HW_HOSTID_LEN];
  1714 	char hostidp[HW_HOSTID_LEN];
       
  1715 	char fsallowedp[ZONE_FS_ALLOWED_MAX];
  1709 	char *limitpriv;
  1716 	char *limitpriv;
  1710 	FILE *of;
  1717 	FILE *of;
  1711 	boolean_t autoboot;
  1718 	boolean_t autoboot;
  1712 	zone_iptype_t iptype;
  1719 	zone_iptype_t iptype;
  1713 	boolean_t need_to_close = B_FALSE;
  1720 	boolean_t need_to_close = B_FALSE;
  1810 	}
  1817 	}
  1811 
  1818 
  1812 	if (zonecfg_get_hostid(handle, hostidp, sizeof (hostidp)) == Z_OK) {
  1819 	if (zonecfg_get_hostid(handle, hostidp, sizeof (hostidp)) == Z_OK) {
  1813 		(void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET),
  1820 		(void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET),
  1814 		    pt_to_str(PT_HOSTID), hostidp);
  1821 		    pt_to_str(PT_HOSTID), hostidp);
       
  1822 	}
       
  1823 
       
  1824 	if (zonecfg_get_fs_allowed(handle, fsallowedp,
       
  1825 	    sizeof (fsallowedp)) == Z_OK) {
       
  1826 		(void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET),
       
  1827 		    pt_to_str(PT_FS_ALLOWED), fsallowedp);
  1815 	}
  1828 	}
  1816 
  1829 
  1817 	if ((err = zonecfg_setipdent(handle)) != Z_OK) {
  1830 	if ((err = zonecfg_setipdent(handle)) != Z_OK) {
  1818 		zone_perror(zone, err, B_FALSE);
  1831 		zone_perror(zone, err, B_FALSE);
  1819 		goto done;
  1832 		goto done;
  2381 gz_invalid_rt_property(int type)
  2394 gz_invalid_rt_property(int type)
  2382 {
  2395 {
  2383 	return (global_zone && (type == RT_ZONENAME || type == RT_ZONEPATH ||
  2396 	return (global_zone && (type == RT_ZONENAME || type == RT_ZONEPATH ||
  2384 	    type == RT_AUTOBOOT || type == RT_LIMITPRIV ||
  2397 	    type == RT_AUTOBOOT || type == RT_LIMITPRIV ||
  2385 	    type == RT_BOOTARGS || type == RT_BRAND || type == RT_SCHED ||
  2398 	    type == RT_BOOTARGS || type == RT_BRAND || type == RT_SCHED ||
  2386 	    type == RT_IPTYPE || type == RT_HOSTID));
  2399 	    type == RT_IPTYPE || type == RT_HOSTID || type == RT_FS_ALLOWED));
  2387 }
  2400 }
  2388 
  2401 
  2389 static boolean_t
  2402 static boolean_t
  2390 gz_invalid_property(int type)
  2403 gz_invalid_property(int type)
  2391 {
  2404 {
  2392 	return (global_zone && (type == PT_ZONENAME || type == PT_ZONEPATH ||
  2405 	return (global_zone && (type == PT_ZONENAME || type == PT_ZONEPATH ||
  2393 	    type == PT_AUTOBOOT || type == PT_LIMITPRIV ||
  2406 	    type == PT_AUTOBOOT || type == PT_LIMITPRIV ||
  2394 	    type == PT_BOOTARGS || type == PT_BRAND || type == PT_SCHED ||
  2407 	    type == PT_BOOTARGS || type == PT_BRAND || type == PT_SCHED ||
  2395 	    type == PT_IPTYPE || type == PT_HOSTID));
  2408 	    type == PT_IPTYPE || type == PT_HOSTID || type == PT_FS_ALLOWED));
  2396 }
  2409 }
  2397 
  2410 
  2398 void
  2411 void
  2399 add_func(cmd_t *cmd)
  2412 add_func(cmd_t *cmd)
  2400 {
  2413 {
  3674 		remove_aliased_rctl(PT_SHARES, ALIAS_SHARES);
  3687 		remove_aliased_rctl(PT_SHARES, ALIAS_SHARES);
  3675 		return;
  3688 		return;
  3676 	case PT_HOSTID:
  3689 	case PT_HOSTID:
  3677 		if ((err = zonecfg_set_hostid(handle, NULL)) != Z_OK)
  3690 		if ((err = zonecfg_set_hostid(handle, NULL)) != Z_OK)
  3678 			z_cmd_rt_perror(CMD_CLEAR, RT_HOSTID, err, B_TRUE);
  3691 			z_cmd_rt_perror(CMD_CLEAR, RT_HOSTID, err, B_TRUE);
       
  3692 		else
       
  3693 			need_to_commit = B_TRUE;
       
  3694 		return;
       
  3695 	case PT_FS_ALLOWED:
       
  3696 		if ((err = zonecfg_set_fs_allowed(handle, NULL)) != Z_OK)
       
  3697 			z_cmd_rt_perror(CMD_CLEAR, RT_FS_ALLOWED, err, B_TRUE);
  3679 		else
  3698 		else
  3680 			need_to_commit = B_TRUE;
  3699 			need_to_commit = B_TRUE;
  3681 		return;
  3700 		return;
  3682 	default:
  3701 	default:
  3683 		zone_perror(pt_to_str(type), Z_NO_PROPERTY_TYPE, B_TRUE);
  3702 		zone_perror(pt_to_str(type), Z_NO_PROPERTY_TYPE, B_TRUE);
  4144 			res_type = RT_MAXSEMIDS;
  4163 			res_type = RT_MAXSEMIDS;
  4145 		} else if (prop_type == PT_SHARES) {
  4164 		} else if (prop_type == PT_SHARES) {
  4146 			res_type = RT_SHARES;
  4165 			res_type = RT_SHARES;
  4147 		} else if (prop_type == PT_HOSTID) {
  4166 		} else if (prop_type == PT_HOSTID) {
  4148 			res_type = RT_HOSTID;
  4167 			res_type = RT_HOSTID;
       
  4168 		} else if (prop_type == PT_FS_ALLOWED) {
       
  4169 			res_type = RT_FS_ALLOWED;
  4149 		} else {
  4170 		} else {
  4150 			zerr(gettext("Cannot set a resource-specific property "
  4171 			zerr(gettext("Cannot set a resource-specific property "
  4151 			    "from the global scope."));
  4172 			    "from the global scope."));
  4152 			saw_error = B_TRUE;
  4173 			saw_error = B_TRUE;
  4153 			return;
  4174 			return;
  4358 				zone_perror(pt_to_str(prop_type), err, B_TRUE);
  4379 				zone_perror(pt_to_str(prop_type), err, B_TRUE);
  4359 			}
  4380 			}
  4360 			return;
  4381 			return;
  4361 		}
  4382 		}
  4362 		need_to_commit = B_TRUE;
  4383 		need_to_commit = B_TRUE;
       
  4384 		return;
       
  4385 	case RT_FS_ALLOWED:
       
  4386 		if ((err = zonecfg_set_fs_allowed(handle, prop_id)) != Z_OK)
       
  4387 			zone_perror(zone, err, B_TRUE);
       
  4388 		else
       
  4389 			need_to_commit = B_TRUE;
  4363 		return;
  4390 		return;
  4364 	case RT_FS:
  4391 	case RT_FS:
  4365 		switch (prop_type) {
  4392 		switch (prop_type) {
  4366 		case PT_DIR:
  4393 		case PT_DIR:
  4367 			(void) strlcpy(in_progress_fstab.zone_fs_dir, prop_id,
  4394 			(void) strlcpy(in_progress_fstab.zone_fs_dir, prop_id,
  4894 
  4921 
  4895 static void
  4922 static void
  4896 info_hostid(zone_dochandle_t handle, FILE *fp)
  4923 info_hostid(zone_dochandle_t handle, FILE *fp)
  4897 {
  4924 {
  4898 	char hostidp[HW_HOSTID_LEN];
  4925 	char hostidp[HW_HOSTID_LEN];
  4899 
  4926 	int err;
  4900 	/*
  4927 
  4901 	 * This will display "hostid: " if there isn't a hostid or an
  4928 	if ((err = zonecfg_get_hostid(handle, hostidp,
  4902 	 * error occurs while retrieving the hostid from the configuration
  4929 	    sizeof (hostidp))) == Z_OK) {
  4903 	 * file.
  4930 		(void) fprintf(fp, "%s: %s\n", pt_to_str(PT_HOSTID), hostidp);
  4904 	 */
  4931 	} else if (err == Z_BAD_PROPERTY) {
  4905 	if (zonecfg_get_hostid(handle, hostidp, sizeof (hostidp)) != Z_OK)
  4932 		(void) fprintf(fp, "%s: \n", pt_to_str(PT_HOSTID));
  4906 		hostidp[0] = '\0';
  4933 	} else {
  4907 	(void) fprintf(fp, "%s: %s\n", pt_to_str(PT_HOSTID), hostidp);
  4934 		zone_perror(zone, err, B_TRUE);
       
  4935 	}
       
  4936 }
       
  4937 
       
  4938 static void
       
  4939 info_fs_allowed(zone_dochandle_t handle, FILE *fp)
       
  4940 {
       
  4941 	char fsallowedp[ZONE_FS_ALLOWED_MAX];
       
  4942 	int err;
       
  4943 
       
  4944 	if ((err = zonecfg_get_fs_allowed(handle, fsallowedp,
       
  4945 	    sizeof (fsallowedp))) == Z_OK) {
       
  4946 		(void) fprintf(fp, "%s: %s\n", pt_to_str(PT_FS_ALLOWED),
       
  4947 		    fsallowedp);
       
  4948 	} else if (err == Z_BAD_PROPERTY) {
       
  4949 		(void) fprintf(fp, "%s: \n", pt_to_str(PT_FS_ALLOWED));
       
  4950 	} else {
       
  4951 		zone_perror(zone, err, B_TRUE);
       
  4952 	}
  4908 }
  4953 }
  4909 
  4954 
  4910 static void
  4955 static void
  4911 output_fs(FILE *fp, struct zone_fstab *fstab)
  4956 output_fs(FILE *fp, struct zone_fstab *fstab)
  4912 {
  4957 {
  5506 		if (!global_zone) {
  5551 		if (!global_zone) {
  5507 			info_limitpriv(handle, fp);
  5552 			info_limitpriv(handle, fp);
  5508 			info_sched(handle, fp);
  5553 			info_sched(handle, fp);
  5509 			info_iptype(handle, fp);
  5554 			info_iptype(handle, fp);
  5510 			info_hostid(handle, fp);
  5555 			info_hostid(handle, fp);
       
  5556 			info_fs_allowed(handle, fp);
  5511 		}
  5557 		}
  5512 		info_aliased_rctl(handle, fp, ALIAS_MAXLWPS);
  5558 		info_aliased_rctl(handle, fp, ALIAS_MAXLWPS);
  5513 		info_aliased_rctl(handle, fp, ALIAS_MAXSHMMEM);
  5559 		info_aliased_rctl(handle, fp, ALIAS_MAXSHMMEM);
  5514 		info_aliased_rctl(handle, fp, ALIAS_MAXSHMIDS);
  5560 		info_aliased_rctl(handle, fp, ALIAS_MAXSHMIDS);
  5515 		info_aliased_rctl(handle, fp, ALIAS_MAXMSGIDS);
  5561 		info_aliased_rctl(handle, fp, ALIAS_MAXMSGIDS);
  5610 		info_hostid(handle, fp);
  5656 		info_hostid(handle, fp);
  5611 		break;
  5657 		break;
  5612 	case RT_ADMIN:
  5658 	case RT_ADMIN:
  5613 		info_auth(handle, fp, cmd);
  5659 		info_auth(handle, fp, cmd);
  5614 		break;
  5660 		break;
       
  5661 	case RT_FS_ALLOWED:
       
  5662 		info_fs_allowed(handle, fp);
       
  5663 		break;
  5615 	default:
  5664 	default:
  5616 		zone_perror(rt_to_str(cmd->cmd_res_type), Z_NO_RESOURCE_TYPE,
  5665 		zone_perror(rt_to_str(cmd->cmd_res_type), Z_NO_RESOURCE_TYPE,
  5617 		    B_TRUE);
  5666 		    B_TRUE);
  5618 	}
  5667 	}
  5619 
  5668 
  5749 	struct zone_admintab admintab;
  5798 	struct zone_admintab admintab;
  5750 	char zonepath[MAXPATHLEN];
  5799 	char zonepath[MAXPATHLEN];
  5751 	char sched[MAXNAMELEN];
  5800 	char sched[MAXNAMELEN];
  5752 	char brand[MAXNAMELEN];
  5801 	char brand[MAXNAMELEN];
  5753 	char hostidp[HW_HOSTID_LEN];
  5802 	char hostidp[HW_HOSTID_LEN];
       
  5803 	char fsallowedp[ZONE_FS_ALLOWED_MAX];
  5754 	int err, ret_val = Z_OK, arg;
  5804 	int err, ret_val = Z_OK, arg;
  5755 	int pset_res;
  5805 	int pset_res;
  5756 	boolean_t save = B_FALSE;
  5806 	boolean_t save = B_FALSE;
  5757 	boolean_t arg_err = B_FALSE;
  5807 	boolean_t arg_err = B_FALSE;
  5758 	zone_iptype_t iptype;
  5808 	zone_iptype_t iptype;
  5823 	while (zonecfg_getipdent(handle, &fstab) == Z_OK) {
  5873 	while (zonecfg_getipdent(handle, &fstab) == Z_OK) {
  5824 		check_reqd_prop(fstab.zone_fs_dir, RT_IPD, PT_DIR, &ret_val);
  5874 		check_reqd_prop(fstab.zone_fs_dir, RT_IPD, PT_DIR, &ret_val);
  5825 	}
  5875 	}
  5826 	(void) zonecfg_endipdent(handle);
  5876 	(void) zonecfg_endipdent(handle);
  5827 
  5877 
  5828 	if (zonecfg_get_hostid(handle, hostidp, sizeof (hostidp)) == Z_OK &&
  5878 	if (zonecfg_get_hostid(handle, hostidp,
  5829 	    (err = zonecfg_valid_hostid(hostidp)) != Z_OK) {
  5879 	    sizeof (hostidp)) == Z_INVALID_PROPERTY) {
  5830 		zone_perror(zone, err, B_TRUE);
  5880 		zerr(gettext("%s: invalid hostid: %s"),
       
  5881 		    zone, hostidp);
       
  5882 		return;
       
  5883 	}
       
  5884 
       
  5885 	if (zonecfg_get_fs_allowed(handle, fsallowedp,
       
  5886 	    sizeof (fsallowedp)) == Z_INVALID_PROPERTY) {
       
  5887 		zerr(gettext("%s: invalid fs-allowed: %s"),
       
  5888 		    zone, fsallowedp);
  5831 		return;
  5889 		return;
  5832 	}
  5890 	}
  5833 
  5891 
  5834 	if ((err = zonecfg_setfsent(handle)) != Z_OK) {
  5892 	if ((err = zonecfg_setfsent(handle)) != Z_OK) {
  5835 		zone_perror(zone, err, B_TRUE);
  5893 		zone_perror(zone, err, B_TRUE);