Lines Matching refs:sh
91 suri_file_map_and_lookup_mapping(struct suri_handle *sh, boolean_t lookup_only)
94 suri_file_t *suri_file = SURIH2FILE(sh);
97 ret = suri_enforce_reg_file(sh, suri_file->sf_prop_path);
100 return (suri_lofi_map(sh, lookup_only));
104 suri_file_map(struct suri_handle *sh)
106 return (suri_file_map_and_lookup_mapping(sh, B_FALSE));
110 suri_file_lookup_mapping(struct suri_handle *sh)
112 return (suri_file_map_and_lookup_mapping(sh, B_TRUE));
121 suri_file_lookup_uri(struct suri_handle *sh, struct suri_handle ***ppsh)
124 suri_file_t *suri_file = SURIH2FILE(sh);
127 if ((ret = suri_lofi_lookup_uri(sh)) != ESURI_OK)
129 (void) snprintf(sh->sh_uri, SURI_MAX_URI_LEN, "file://%s",
136 return (suri_err_set_static_desc(sh, ESURI_NOMEM));
139 * suri_clone(). 'sh' is just a helper handler.
141 sh->sh_state = SURI_STATE_MAPPED;
142 if ((ret = suri_clone(sh, *ppsh)) != ESURI_OK) {
155 suri_file_unmap(struct suri_handle *sh)
157 return (suri_lofi_unmap(sh));
176 suri_file_dev_prop_defined(struct suri_handle *sh, suri_prop_t sp)
178 assert(suri_prop_valid((suri_handle_t)sh, sp));
199 suri_common_set_prop_str(struct suri_handle *sh, suri_prop_t sp,
215 suri_common_set_prop_uint64(struct suri_handle *sh, suri_prop_t sp, uint64_t n)
230 suri_common_set_prop_bool(struct suri_handle *sh, suri_prop_t sp, boolean_t b)
241 suri_file_get_prop_str(struct suri_handle *sh, suri_prop_t sp)
243 suri_file_t *suri_file = SURIH2FILE(sh);
245 assert(suri_prop_valid((suri_handle_t)sh, sp));
258 suri_file_get_prop_bool(struct suri_handle *sh, suri_prop_t sp)
260 assert(suri_prop_valid((suri_handle_t)sh, sp));
279 suri_create_get_nvprop_int64(struct suri_handle *sh, nvlist_t *l, char *name,
297 suri_err_set_desc(sh, "%s: %s: \"%s\"",
322 suri_file_create(struct suri_handle *sh, uint64_t size, nvlist_t *create_props)
329 suri_file_t *suri_file = SURIH2FILE(sh);
333 if (suri_create_get_nvprop_int64(sh, create_props,
338 if (suri_create_get_nvprop_int64(sh, create_props,
343 if (suri_create_get_nvprop_int64(sh, create_props,
351 return (suri_err_set_static_desc(sh, ESURI_NOMEM));
360 suri_err_set_desc(sh, "%s: %s: \"%s\"",
374 suri_err_set_desc(sh, "%s: %s: \"%s\"",
381 suri_err_set_desc(sh,
400 suri_file_destroy(struct suri_handle *sh)
402 suri_file_t *suri_file = SURIH2FILE(sh);
405 suri_err_set_desc(sh, "%s: %s: \"%s\"",
427 suri_lu_map(struct suri_handle *sh)
429 return (devinfo_target_mapping(sh, SURI_LU_MAP, NULL));
436 suri_lu_lookup_uri(struct suri_handle *sh, struct suri_handle ***ppsh)
438 return (devinfo_target_mapping(sh, SURI_LU_LOOKUP_URI, ppsh));
456 suri_lu_get_prop_str(struct suri_handle *sh, suri_prop_t sp)
458 suri_lu_t *suri_lu = SURIH2LU(sh);
460 assert(suri_prop_valid((suri_handle_t)sh, sp));
477 suri_lu_get_prop_bool(struct suri_handle *sh, suri_prop_t sp)
479 assert(suri_prop_valid((suri_handle_t)sh, sp));
497 suri_lu_prop_defined(struct suri_handle *sh, suri_prop_t sp)
499 suri_lu_t *suri_lu = SURIH2LU(sh);
501 assert(suri_prop_valid((suri_handle_t)sh, sp));
535 suri_iscsi_map(struct suri_handle *sh)
539 suri_iscsi_t *suri_iscsi = SURIH2ISCSI(sh);
541 if ((ret = suri_enable_service(sh,
551 if ((ret = suri_resolve_hostname(sh, &daddrs)) != ESURI_OK)
553 if ((ret = suri_iscsi_add_disc_addrs(sh, daddrs)) != ESURI_OK) {
566 return (devinfo_target_mapping(sh, SURI_ISCSI_MAP, NULL));
574 suri_iscsi_lookup_mapping(struct suri_handle *sh)
576 return (devinfo_target_mapping(sh, SURI_ISCSI_MAP, NULL));
583 suri_iscsi_lookup_uri(struct suri_handle *sh, struct suri_handle ***ppsh)
589 if ((ret = suri_enable_service(sh,
594 if ((ret = devinfo_target_mapping(sh, SURI_ISCSI_LOOKUP_URI, ppsh))
640 suri_iscsi_unmap(struct suri_handle *sh)
644 suri_iscsi_t *suri_iscsi = SURIH2ISCSI(sh);
646 if ((ret = suri_enable_service(sh,
651 if ((ret = suri_iscsi_lookup_mapping(sh)) != ESURI_OK)
658 if ((ret = suri_resolve_hostname(sh, &tgt)) != ESURI_OK)
660 ret = suri_iscsi_remove_disc_addrs(sh, tgt);
686 suri_iscsi_prop_defined(struct suri_handle *sh, suri_prop_t sp)
688 suri_iscsi_t *suri_iscsi = SURIH2ISCSI(sh);
690 assert(suri_prop_valid((suri_handle_t)sh, sp));
716 suri_iscsi_get_prop_str(struct suri_handle *sh, suri_prop_t sp)
718 suri_iscsi_t *suri_iscsi = SURIH2ISCSI(sh);
720 assert(suri_prop_valid((suri_handle_t)sh, sp));
734 suri_iscsi_get_prop_uint64(struct suri_handle *sh, suri_prop_t sp)
736 suri_iscsi_t *suri_iscsi = SURIH2ISCSI(sh);
738 assert(suri_prop_valid((suri_handle_t)sh, sp));
751 suri_iscsi_get_prop_bool(struct suri_handle *sh, suri_prop_t sp)
753 assert(suri_prop_valid((suri_handle_t)sh, sp));
780 suri_dev_map(struct suri_handle *sh)
785 suri_dev_t *suri_dev = SURIH2DEV(sh);
799 if ((ret = suri_enforce_block_dev(sh, path, B_FALSE)) != ESURI_OK)
801 if ((ret = suri_enforce_real_devpath(sh, path, B_FALSE)) != ESURI_OK)
807 (void) strlcpy(sh->sh_mdev, path, sizeof (sh->sh_mdev));
815 suri_dev_lookup_uri(struct suri_handle *sh, struct suri_handle ***ppsh)
818 suri_dev_t *suri_dev = SURIH2DEV(sh);
821 * We know we fit since sh->sh_mdev fits in MAXPATHLEN. That is what is
826 (void) snprintf(sh->sh_uri, SURI_MAX_URI_LEN, "dev:%s",
827 sh->sh_mdev + strlen(_PATH_DEV));
830 sh->sh_mdev + strlen(_PATH_DEV),
837 return (suri_err_set_static_desc(sh, ESURI_NOMEM));
840 * suri_clone(). 'sh' is just a helper handler.
842 sh->sh_state = SURI_STATE_MAPPED;
843 if ((ret = suri_clone(sh, *ppsh)) != ESURI_OK)
849 suri_dev_get_prop_str(struct suri_handle *sh, suri_prop_t sp)
851 suri_dev_t *suri_dev = SURIH2DEV(sh);
853 assert(suri_prop_valid((suri_handle_t)sh, sp));
866 suri_dev_get_prop_bool(struct suri_handle *sh, suri_prop_t sp)
868 assert(suri_prop_valid((suri_handle_t)sh, sp));
892 suri_init(struct suri_handle *sh, const suri_gen_uri_t *gen_uri)
897 switch (sh->sh_uri_type) {
900 sh->sh_data = calloc(1, sizeof (suri_file_t));
901 if (sh->sh_data == NULL)
902 return (suri_err_set_static_desc(sh, ESURI_NOMEM));
903 sh->sh_ops = &suri_file_ops;
906 sh->sh_data = calloc(1, sizeof (suri_lu_t));
907 if (sh->sh_data == NULL)
908 return (suri_err_set_static_desc(sh, ESURI_NOMEM));
909 sh->sh_ops = &suri_lu_ops;
912 sh->sh_data = calloc(1, sizeof (suri_iscsi_t));
913 if (sh->sh_data == NULL)
914 return (suri_err_set_static_desc(sh, ESURI_NOMEM));
915 sh->sh_ops = &suri_iscsi_ops;
918 sh->sh_data = calloc(1, sizeof (suri_dev_t));
919 if (sh->sh_data == NULL)
920 return (suri_err_set_static_desc(sh, ESURI_NOMEM));
921 sh->sh_ops = &suri_dev_ops;
931 sh->sh_mdev[0] = '\0';
936 if ((ret = SURI_OP_PARSE(sh, gen_uri)) != ESURI_OK) {
937 free(sh->sh_data);
938 sh->sh_data = NULL;
939 sh->sh_ops = &suri_null_ops;
991 suri_alloc_init(struct suri_handle *sh)
993 (void) memset(sh, '\0', sizeof (struct suri_handle));
994 sh->sh_state = SURI_STATE_ALLOCATED;
995 sh->sh_uri_type = SURI_TYPE_ANY; /* URI not parsed yet */
996 sh->sh_data = NULL;
997 sh->sh_ops = &suri_null_ops;
1007 struct suri_handle *sh;
1009 if ((sh = malloc(sizeof (struct suri_handle))) == NULL)
1011 suri_alloc_init(sh);
1012 return ((suri_handle_t)sh);
1021 struct suri_handle *sh = (struct suri_handle *)h;
1022 assert(SURI_VALID_STATE(sh->sh_state));
1023 return (sh->sh_state);
1032 struct suri_handle *sh = (struct suri_handle *)h;
1034 assert(SURI_VALID_TYPE(sh->sh_uri_type));
1035 return (sh->sh_uri_type);
1044 struct suri_handle *sh = (struct suri_handle *)h;
1046 assert(SURI_VALID_STATE(sh->sh_state));
1048 if (sh->sh_state >= SURI_STATE_PARSED) {
1049 assert(sh->sh_ops != &suri_null_ops);
1050 assert(sh->sh_data != NULL);
1057 if (sh->sh_data != NULL)
1058 free(sh->sh_data);
1059 free(sh);
1068 suri_clean(struct suri_handle *sh)
1074 assert(sh->sh_state == SURI_STATE_PARSED);
1075 if (sh->sh_data != NULL)
1076 free(sh->sh_data);
1077 suri_alloc_init(sh);
1089 struct suri_handle *sh = (struct suri_handle *)h;
1092 assert(SURI_VALID_STATE(sh->sh_state));
1093 suri_err_clear(sh);
1096 suri_err_set_desc(sh, "%s", ERR_SURI_EMPTY_URI);
1097 suri_err_set_action(sh, "%s \"\"", ERR_SURI_PARSE_FAILED);
1098 return ((sh->sh_err_code = ESURI_ERR));
1102 if (sh->sh_state == SURI_STATE_PARSED)
1103 suri_clean(sh);
1104 assert(sh->sh_state == SURI_STATE_ALLOCATED);
1110 if (strlcpy(sh->sh_uri, uri, sizeof (sh->sh_uri)) >=
1111 sizeof (sh->sh_uri)) {
1112 (void) suri_err_set_static_desc(sh, ESURI_NAMETOOLONG);
1113 suri_err_set_action(sh, "%s \"%s\"",
1115 return ((sh->sh_err_code = ESURI_NAMETOOLONG));
1117 if ((ret = suri_get_uri_type(sh, &gen_uri)) != ESURI_OK)
1119 if ((ret = suri_init(sh, &gen_uri)) != ESURI_OK)
1121 sh->sh_state = SURI_STATE_PARSED;
1122 return ((sh->sh_err_code = ESURI_OK));
1124 suri_err_set_action(sh, "%s \"%s\"", ERR_SURI_PARSE_FAILED, sh->sh_uri);
1125 return ((sh->sh_err_code = ret));
1136 struct suri_handle *sh = (struct suri_handle *)h;
1138 assert(SURI_VALID_STATE(sh->sh_state));
1139 assert(SURI_VALID_TYPE(sh->sh_uri_type));
1140 suri_err_clear(sh);
1143 switch (sh->sh_state) {
1145 if ((ret = SURI_OP_MAP(sh)) != ESURI_OK) {
1146 suri_err_set_action(sh, "%s \"%s\"",
1147 ERR_SURI_MAP_FAILED, sh->sh_uri);
1150 sh->sh_state = SURI_STATE_MAPPED;
1155 return ((sh->sh_err_code = ret));
1168 struct suri_handle *sh = (struct suri_handle *)h;
1170 assert(SURI_VALID_STATE(sh->sh_state));
1171 assert(SURI_VALID_TYPE(sh->sh_uri_type));
1172 suri_err_clear(sh);
1174 switch (sh->sh_state) {
1176 if ((ret = SURI_OP_LOOKUP_MAPPING(sh)) != ESURI_OK) {
1177 suri_err_set_action(sh, "%s: \"%s\"",
1178 ERR_SURI_LOOKUP_MAPPING_FAILED, sh->sh_uri);
1181 sh->sh_state = SURI_STATE_MAPPED;
1186 return ((sh->sh_err_code = ret));
1198 struct suri_handle *sh = (struct suri_handle *)h;
1200 assert(SURI_VALID_STATE(sh->sh_state));
1201 assert(SURI_VALID_TYPE(sh->sh_uri_type));
1202 suri_err_clear(sh);
1205 switch (sh->sh_state) {
1208 if ((ret = SURI_OP_UNMAP(sh)) != ESURI_OK) {
1209 suri_err_set_action(sh, "%s \"%s\"",
1210 ERR_SURI_UNMAP_FAILED, sh->sh_uri);
1213 sh->sh_mdev[0] = '\0';
1214 sh->sh_state = SURI_STATE_PARSED;
1219 return ((sh->sh_err_code = ret));
1230 suri_lookup_uri_common(struct suri_handle *sh, const char *mdev)
1235 suri_err_set_desc(sh, "%s", ERR_SURI_NAMETOOLONG);
1236 suri_err_set_action(sh, "%s: \"%s\"",
1241 if ((ret = suri_enforce_block_dev(sh, mdev, B_TRUE)) != ESURI_OK) {
1242 suri_err_set_action(sh, "%s: \"%s\"",
1247 if ((ret = suri_enforce_real_devpath(sh, mdev, B_TRUE)) != ESURI_OK) {
1248 suri_err_set_action(sh, "%s: \"%s\"",
1308 struct suri_handle *sh, **tmp_psh = NULL;
1316 if ((ret = suri_alloc_psh(&sh, ppsh)) != ESURI_OK)
1318 if ((ret = suri_lookup_uri_common(sh, mdev)) != ESURI_OK)
1319 return ((sh->sh_err_code = ret));
1321 sh->sh_uri_type = type;
1330 return (suri_err_set_static_desc(sh, ESURI_NOMEM));
1336 if ((ret = suri_init(sh, NULL)) != ESURI_OK) {
1337 suri_err_set_action(sh, format, suri_type_to_name(type), mdev);
1339 return ((sh->sh_err_code = ret));
1341 (void) strlcpy(sh->sh_mdev, mdev, sizeof (sh->sh_mdev));
1349 * In case of error, it is set in sh and *ppsh must be empty. This is
1352 if ((ret = SURI_OP_LOOKUP_URI(sh, ppsh)) != ESURI_OK) {
1354 suri_err_set_action(sh, format, suri_type_to_name(type), mdev);
1356 /* Use our sh handle we allocated before to return an error. */
1358 return ((sh->sh_err_code = ret));
1362 suri_free((suri_handle_t)sh);
1395 struct suri_handle *sh;
1403 if ((ret = suri_alloc_psh(&sh, ppsh)) != ESURI_OK)
1409 if ((ret = suri_lookup_uri_common(sh, mdev)) != ESURI_OK) {
1410 sh->sh_err_code = ret;
1413 suri_free((suri_handle_t)sh);
1493 struct suri_handle *sh = (struct suri_handle *)h;
1495 assert(SURI_VALID_STATE(sh->sh_state));
1496 suri_err_clear(sh);
1499 suri_err_set_desc(sh, "%s",
1501 suri_err_set_action(sh, "%s \"%s\"", ERR_SURI_CREATE_FAILED,
1502 sh->sh_uri);
1503 return ((sh->sh_err_code = ESURI_ERR));
1511 assert(sh->sh_state == SURI_STATE_PARSED);
1512 if ((ret = SURI_OP_CREATE(sh, size, create_props)) != ESURI_OK) {
1513 suri_err_set_action(sh, "%s \"%s\"", ERR_SURI_CREATE_FAILED,
1514 sh->sh_uri);
1516 return ((sh->sh_err_code = ret));
1528 struct suri_handle *sh = (struct suri_handle *)h;
1530 assert(SURI_VALID_STATE(sh->sh_state));
1531 suri_err_clear(sh);
1538 assert(sh->sh_state >= SURI_STATE_PARSED);
1540 if ((ret = SURI_OP_DESTROY(sh)) != ESURI_OK) {
1541 suri_err_set_action(sh, "%s \"%s\"", ERR_SURI_DESTROY_FAILED,
1542 sh->sh_uri);
1544 return ((sh->sh_err_code = ret));
1557 struct suri_handle *sh = (struct suri_handle *)h;
1561 assert(SURI_VALID_STATE(sh->sh_state));
1562 assert(sh->sh_state >= SURI_STATE_PARSED);
1576 return (SURI_OP_PROP_VALID(sh, sp));
1588 struct suri_handle *sh = (struct suri_handle *)h;
1592 assert(SURI_VALID_STATE(sh->sh_state));
1594 assert(sh->sh_state >= SURI_STATE_PARSED);
1600 if (suri_prop_valid((suri_handle_t)sh, sp) == B_FALSE)
1612 if (sh->sh_state == SURI_STATE_MAPPED)
1616 return (SURI_OP_PROP_DEFINED(sh, sp));
1627 struct suri_handle *sh = (struct suri_handle *)h;
1629 assert(suri_prop_defined((suri_handle_t)sh, sp));
1632 return (sh->sh_uri);
1634 return (sh->sh_mdev);
1635 return (SURI_OP_GET_PROP_STR(sh, sp));
1641 struct suri_handle *sh = (struct suri_handle *)h;
1643 assert(suri_prop_defined((suri_handle_t)sh, sp));
1646 return (sh->sh_uri_type);
1647 return (SURI_OP_GET_PROP_UINT64(sh, sp));
1653 struct suri_handle *sh = (struct suri_handle *)h;
1655 assert(suri_prop_defined((suri_handle_t)sh, sp));
1656 return (SURI_OP_GET_PROP_BOOL(sh, sp));
1660 suri_set_prop_check(struct suri_handle *sh, suri_prop_t sp)
1667 assert(sh->sh_state == SURI_STATE_PARSED);
1668 suri_err_clear(sh);
1677 struct suri_handle *sh = (struct suri_handle *)h;
1680 suri_set_prop_check(sh, sp);
1681 sh->sh_err_code = SURI_OP_SET_PROP_STR(sh, sp, str);
1682 if (sh->sh_err_code != ESURI_OK)
1683 suri_err_set_action(sh, "%s", ERR_SURI_SET_PROP);
1684 return (sh->sh_err_code);
1690 struct suri_handle *sh = (struct suri_handle *)h;
1692 suri_set_prop_check(sh, sp);
1693 sh->sh_err_code = SURI_OP_SET_PROP_UINT64(sh, sp, val);
1694 if (sh->sh_err_code != ESURI_OK)
1695 suri_err_set_action(sh, "%s", ERR_SURI_SET_PROP);
1696 return (sh->sh_err_code);
1702 struct suri_handle *sh = (struct suri_handle *)h;
1705 suri_set_prop_check(sh, sp);
1706 sh->sh_err_code = SURI_OP_SET_PROP_BOOL(sh, sp, val);
1707 if (sh->sh_err_code != ESURI_OK)
1708 suri_err_set_action(sh, "%s", ERR_SURI_SET_PROP);
1709 return (sh->sh_err_code);
1768 * specific error. In that case, use 'sh' to set the error description string.
1775 suri_clone(struct suri_handle *sh, struct suri_handle **cloned_sh)
1781 assert(SURI_VALID_STATE(sh->sh_state));
1783 assert(suri_err_check_null_errors(sh));
1785 assert(suri_err_check_null_warnings(sh));
1789 suri_err_set_desc(sh, "%s", strerror(errno));
1792 (void) memcpy(tsh, sh, sizeof (struct suri_handle));
1801 (void) memcpy(tsh->sh_data, sh->sh_data, sizeof (suri_file_t));
1804 (void) memcpy(tsh->sh_data, sh->sh_data, sizeof (suri_lu_t));
1807 (void) memcpy(tsh->sh_data, sh->sh_data, sizeof (suri_iscsi_t));
1810 (void) memcpy(tsh->sh_data, sh->sh_data, sizeof (suri_dev_t));
1933 suri_notsup_op(struct suri_handle *sh)
1935 suri_err_set_desc(sh, "%s: \"%s\"",
1937 suri_type_to_name(suri_get_type((suri_handle_t)sh)));
1938 return ((sh->sh_err_code = ESURI_NOTSUP));
1946 suri_create_notsup_op(struct suri_handle *sh, uint64_t s, nvlist_t *props)
1948 suri_err_set_desc(sh, "%s: \"%s\"",
1950 suri_type_to_name(suri_get_type((suri_handle_t)sh)));
1951 return ((sh->sh_err_code = ESURI_NOTSUP));
1959 suri_null_get_prop_uint64(struct suri_handle *sh, suri_prop_t sp)