/* * Perform operation on all targets */ static int isns_op_all(uint16_t op) { int so; tgt_node_t *tgt = NULL; char *iname; if (isns_server_connection_thr_running == False) { syslog(LOG_ERR, "isns_op_all: iSNS discovery is not running." " Check the previous iSNS initialization error."); return (-1); } if ((so = isns_open(isns_args.server)) == -1) { syslog(LOG_ERR, "isns_op_all: failed to open isns server %s", isns_args.server); return (-1); } while ((tgt = tgt_node_next_child(targets_config, XML_ELEMENT_TARG, tgt)) != NULL) { if (tgt_find_value_str(tgt, XML_ELEMENT_INAME, &iname) == FALSE) { continue; } switch (op) { case ISNS_DEV_DEREG: if (isns_dev_attr_dereg(so, iname) == -1) { syslog(LOG_ERR, "ISNS de-register failed\n"); } num_reg = 0; break; case ISNS_SCN_DEREG: if (isns_scn_dereg(so, iname) == -1) { syslog(LOG_ERR, "ISNS SCN de-register failed\n"); } break; case ISNS_SCN_REG: if (isns_scn_reg(so, iname) == -1) { syslog(LOG_ERR, "ISNS SCN register failed\n"); } break; case ISNS_TGT_LOGOUT: logout_targ(iname); break; default: break; } free(iname); } isns_close(so); return (0); }
/* * remove_zfs -- unshare a ZVOL from the target */ static char * remove_zfs(tgt_node_t *x, ucred_t *cred) { char *prop; char *msg = NULL; tgt_node_t *targ = NULL; libzfs_handle_t *zh = NULL; const priv_set_t *eset; if (tgt_find_value_str(x, XML_ELEMENT_NAME, &prop) == False) { xml_rtn_msg(&msg, ERR_SYNTAX_MISSING_NAME); return (msg); } if ((zh = libzfs_init()) == NULL) { xml_rtn_msg(&msg, ERR_INTERNAL_ERROR); free(prop); return (msg); } eset = ucred_getprivset(cred, PRIV_EFFECTIVE); if (eset != NULL ? !priv_ismember(eset, PRIV_SYS_CONFIG) : ucred_geteuid(cred) != 0) { /* * See if user has ZFS dataset permissions to do operation */ if (zfs_iscsi_perm_check(zh, prop, cred) != 0) { xml_rtn_msg(&msg, ERR_NO_PERMISSION); free(prop); libzfs_fini(zh); return (msg); } } libzfs_fini(zh); while ((targ = tgt_node_next(targets_config, XML_ELEMENT_TARG, targ)) != NULL) { if (strcmp(targ->x_value, prop) == 0) break; } free(prop); if (targ == NULL) { /* * We're unsharing a target. If we don't have a reference * then there's no problem. */ xml_rtn_msg(&msg, ERR_SUCCESS); return (msg); } if (tgt_find_value_str(targ, XML_ELEMENT_INAME, &prop) == False) { xml_rtn_msg(&msg, ERR_TARGCFG_MISSING_INAME); return (msg); } tgt_node_remove(targets_config, targ, MatchBoth); /* * Wait until here to issue a logout to any initiators that * might be logged into the target. Certain initiators are * sneaky in that if asked to logout they will, but turn right * around and log back into the target. By waiting until here * to issue the logout we'll have removed reference to the target * such that this can't happen. */ if (isns_enabled() == True) { if (isns_dereg(prop) != 0) syslog(LOG_INFO, "ISNS dereg failed\n"); } logout_targ(prop); free(prop); xml_rtn_msg(&msg, ERR_SUCCESS); return (msg); }
static char * remove_target(tgt_node_t *x) { char *msg = NULL; char *prop = NULL; tgt_node_t *targ = NULL; tgt_node_t *list; tgt_node_t *c = NULL; Boolean_t change_made = False; int lun_num; if (tgt_find_value_str(x, XML_ELEMENT_NAME, &prop) == False) { xml_rtn_msg(&msg, ERR_SYNTAX_MISSING_NAME); return (msg); } while ((targ = tgt_node_next(targets_config, XML_ELEMENT_TARG, targ)) != NULL) { if (strcmp(targ->x_value, prop) == 0) break; } free(prop); if (targ == NULL) { xml_rtn_msg(&msg, ERR_TARG_NOT_FOUND); return (msg); } if (tgt_find_value_str(x, XML_ELEMENT_ACL, &prop) == True) { if (prop == NULL) { xml_rtn_msg(&msg, ERR_SYNTAX_EMPTY_ACL); return (msg); } if ((list = tgt_node_next(targ, XML_ELEMENT_ACLLIST, NULL)) == NULL) { free(prop); xml_rtn_msg(&msg, ERR_ACL_NOT_FOUND); return (msg); } c = tgt_node_alloc(XML_ELEMENT_ACLINIT, String, prop); if (tgt_node_remove(list, c, MatchBoth) == False) { xml_rtn_msg(&msg, ERR_INIT_NOT_FOUND); goto error; } tgt_node_free(c); if (list->x_child == NULL) (void) tgt_node_remove(targ, list, MatchName); free(prop); change_made = True; } if (tgt_find_value_str(x, XML_ELEMENT_TPGT, &prop) == True) { if (prop == NULL) { xml_rtn_msg(&msg, ERR_SYNTAX_EMPTY_TPGT); return (msg); } if ((list = tgt_node_next(targ, XML_ELEMENT_TPGTLIST, NULL)) == NULL) { free(prop); xml_rtn_msg(&msg, ERR_ACL_NOT_FOUND); return (msg); } c = tgt_node_alloc(XML_ELEMENT_TPGT, String, prop); if (tgt_node_remove(list, c, MatchBoth) == False) { xml_rtn_msg(&msg, ERR_TPGT_NOT_FOUND); goto error; } tgt_node_free(c); if (list->x_child == NULL) (void) tgt_node_remove(targ, list, MatchName); free(prop); /* update isns */ if (isns_enabled()) { if (isns_dev_update(targ->x_value, ISNS_MOD_TPGT) != 0) syslog(LOG_ALERT, "ISNS register failed\n"); } change_made = True; } if (tgt_find_value_int(x, XML_ELEMENT_LUN, &lun_num) == True) { if (tgt_find_value_intchk(x, XML_ELEMENT_LUN, &lun_num) == False) { xml_rtn_msg(&msg, ERR_LUN_INVALID_RANGE); return (msg); } /* * Save the iscsi-name which we'll need to remove LUNs. */ if (tgt_find_value_str(targ, XML_ELEMENT_INAME, &prop) == False) { xml_rtn_msg(&msg, ERR_TARGCFG_MISSING_INAME); return (msg); } logout_targ(prop); thick_provo_stop(prop, lun_num); remove_target_common(targ->x_value, lun_num, &msg); if (msg != NULL) goto error; /* ISNS de-register target if it's the last lun */ if (lun_num == 0 && isns_enabled() == True) { if (isns_dereg(prop) != 0) syslog(LOG_INFO, "ISNS dereg failed\n"); } iscsi_inventory_change(prop); free(prop); change_made = True; } if (change_made == True) { if (mgmt_config_save2scf() == True) xml_rtn_msg(&msg, ERR_SUCCESS); } else { xml_rtn_msg(&msg, ERR_SYNTAX_MISSING_OPERAND); } return (msg); error: if (c != NULL) tgt_node_free(c); if (prop != NULL) free(prop); return (msg); }
/* * process_scn() * -Added/Updated object: nop, initiator is verified during connect * * -Removed object: logout_targ if still connected * * RFC 4171 section 5.6.5.9 * destination attribute is always the 1st attribute in the SCN message, * then follows by SCN_BITMAP(35) & Source_Attribute(32) */ static void process_scn(int so, isns_pdu_t *scn) { uint8_t *ptr = scn->payload; isns_tlv_t *tlv; uint16_t cnt = 0; uint32_t got_dest = 0; uint32_t got_source = 0; uint32_t bitmap = 0; uint32_t got_bitmap = 0; char dest[MAXNAMELEN]; char source[MAXNAMELEN]; queue_prt(mgmtq, Q_ISNS_DBG, "PROCESS_SCN %u\n", scn->payload_len); if (scn->payload_len < TAG_LEN_SZ) { syslog(LOG_ALERT, "ISNS SCN message error\n"); return; } while (cnt < scn->payload_len) { /* LINTED */ tlv = (isns_tlv_t *)ptr; tlv->attr_id = ntohl(tlv->attr_id); tlv->attr_len = ntohl(tlv->attr_len); queue_prt(mgmtq, Q_ISNS_DBG, "PROCESS_SCN %u %u\n", tlv->attr_id, tlv->attr_len); /* * devAttrQry the source attribute, process if node_type * is initiator */ switch (tlv->attr_id) { case ISNS_ISCSI_NAME_ATTR_ID: if (got_dest == 0) { bcopy(tlv->attr_value, dest, tlv->attr_len); queue_prt(mgmtq, Q_ISNS_DBG, "PROCESS_SCN dest %s\n", dest); got_dest = 1; } else { bcopy(tlv->attr_value, source, tlv->attr_len); queue_prt(mgmtq, Q_ISNS_DBG, "PROCESS_SCN source %s\n", source); got_source = 1; } break; case ISNS_ISCSI_SCN_BITMAP_ATTR_ID: bcopy(tlv->attr_value, &bitmap, tlv->attr_len); bitmap = ntohl(bitmap); queue_prt(mgmtq, Q_ISNS_DBG, "PROCESS_SCN bitmap %u\n", bitmap); got_bitmap = 1; break; default: queue_prt(mgmtq, Q_ISNS_DBG, "PROCESS_SCN DEFAULT\n"); break; } if (got_source && !got_bitmap) { queue_prt(mgmtq, Q_ISNS_DBG, "process_scn: message out-of-order\n"); return; } if (got_source && got_bitmap) { switch (bitmap) { case ISNS_OBJ_ADDED: case ISNS_OBJ_UPDATED: queue_prt(mgmtq, Q_ISNS_DBG, "PROCESS_SCN OBJ ADDED"); (void) isns_update(); break; case ISNS_OBJ_REMOVED: queue_prt(mgmtq, Q_ISNS_DBG, "PROCESS_SCN OBJ REMOVED"); /* logout target */ if (got_dest == 0) { syslog(LOG_ALERT, "ISNS protocol error\n"); continue; } logout_targ(dest); break; default: break; } /* clear got_xxx */ got_source = 0; got_bitmap = 1; } /* next attribute */ cnt += ISNS_ATTR_SZ(tlv->attr_len); ptr += ISNS_ATTR_SZ(tlv->attr_len); } queue_prt(mgmtq, Q_ISNS_DBG, "DONE PROCESS_SCN\n"); }