Ejemplo n.º 1
0
static int
drd_rcm_mem_op(rcm_op_t op, uint64_t change)
{
	int		rv = -1;
	int		pgsize;
	long		oldpages;
	long		newpages;
	nvlist_t	*nvl = NULL;
	rcm_info_t	*rinfo;

	/* allocate an nvlist for the RCM call */
	if (nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0) != 0)
		goto done;

	if ((pgsize = sysconf(_SC_PAGE_SIZE)) == -1 ||
	    (newpages = sysconf(_SC_PHYS_PAGES)) == -1)
		goto done;

	/*
	 * If this is a notify add, the capacity change
	 * was positive and the current page count reflects
	 * the new capacity level.
	 *
	 * If this is a request del, the capacity change
	 * is negative and the current page count will
	 * reflect the old capacity level.
	 */
	assert(change % pgsize == 0);
	if (change > 0) {
		oldpages = newpages - (long)(change / pgsize);
	} else {
		assert(newpages >= change / pgsize);
		oldpages = newpages;
		newpages = oldpages + (long)(change / pgsize);
	}

	drd_dbg("oldpages=%lld newpages=%lld delta=%lld",
	    oldpages, newpages, newpages - oldpages);

	/* setup the nvlist for the RCM call */
	if (nvlist_add_string(nvl, "state", "capacity") != 0 ||
	    nvlist_add_int32(nvl, "page_size", pgsize) != 0 ||
	    nvlist_add_int32(nvl, "old_pages", oldpages) != 0 ||
	    nvlist_add_int32(nvl, "new_pages", newpages) != 0) {
		goto done;
	}

	rv = (*op)(rcm_hdl, RCM_MEM_ALL, 0, nvl, &rinfo);
	rv = (rv == RCM_SUCCESS) ? 0 : -1;

done:
	s_nvfree(nvl);

	return (rv);
}
Ejemplo n.º 2
0
static int
ippctl_set_rc(
	int		val)
{
	nvlist_t	*nvlp;
	int		rc;

	/*
	 * Create an nvlist to store the return code,
	 */

	if ((rc = nvlist_alloc(&nvlp, NV_UNIQUE_NAME, KM_SLEEP)) != 0)
		return (ENOMEM);

	if ((rc = nvlist_add_int32(nvlp, IPPCTL_RC, val)) != 0) {
		nvlist_free(nvlp);
		return (rc);
	}

	/*
	 * Add it at the beginning of the array.
	 */

	rc = ippctl_add_nvlist(nvlp, 0);

	nvlist_free(nvlp);
	return (rc);
}
Ejemplo n.º 3
0
int
topo_prop_getpgrp(tnode_t *node, const char *pgname, nvlist_t **pgrp,
    int *err)
{
	int ret;
	topo_hdl_t *thp = node->tn_hdl;
	nvlist_t *nvl, *pvnvl;
	topo_pgroup_t *pg;
	topo_propval_t *pv;
	topo_proplist_t *pvl;

	if (topo_hdl_nvalloc(thp, &nvl, 0) != 0) {
		*err = ETOPO_NOMEM;
		return (-1);
	}

	topo_node_lock(node);
	for (pg = topo_list_next(&node->tn_pgroups); pg != NULL;
	    pg = topo_list_next(pg)) {

		if (strcmp(pgname, pg->tpg_info->tpi_name) != 0)
			continue;

		if (nvlist_add_string(nvl, TOPO_PROP_GROUP_NAME,
		    pg->tpg_info->tpi_name) != 0 ||
		    nvlist_add_string(nvl, TOPO_PROP_GROUP_NSTAB,
		    topo_stability2name(pg->tpg_info->tpi_namestab)) != 0 ||
		    nvlist_add_string(nvl, TOPO_PROP_GROUP_DSTAB,
		    topo_stability2name(pg->tpg_info->tpi_datastab)) != 0 ||
		    nvlist_add_int32(nvl, TOPO_PROP_GROUP_VERSION,
		    pg->tpg_info->tpi_version) != 0)
			return (get_pgrp_seterror(node, nvl, err,
			    ETOPO_PROP_NVL));

		for (pvl = topo_list_next(&pg->tpg_pvals); pvl != NULL;
		    pvl = topo_list_next(pvl)) {

			pv = pvl->tp_pval;
			if (prop_val_add(node, &pvnvl, pv, err) < 0) {
				return (get_pgrp_seterror(node, nvl, err,
				    *err));
			}
			if ((ret = nvlist_add_nvlist(nvl, TOPO_PROP_VAL,
			    pvnvl)) != 0) {
				nvlist_free(pvnvl);
				return (get_pgrp_seterror(node, nvl, err, ret));
			}

			nvlist_free(pvnvl);
		}
		topo_node_unlock(node);
		*pgrp = nvl;
		return (0);
	}

	topo_node_unlock(node);
	*err = ETOPO_PROP_NOENT;
	return (-1);
}
Ejemplo n.º 4
0
void
nsc_do_sysevent(char *driver_name, char *trap_messages, int errorno,
	int alertlevel, char *component, dev_info_t *info_dip)
{
#if !defined(DS_DDICT) && !defined(_SunOS_5_6) && \
	!defined(_SunOS_5_7) && !defined(_SunOS_5_8)

	nvlist_t *attr_list;
	int rc;

	attr_list = NULL;
	rc = nvlist_alloc(&attr_list, NV_UNIQUE_NAME_TYPE, KM_SLEEP);
	if (rc != 0) {
		goto out;
	}
	rc = nvlist_add_int32(attr_list, "alertlevel", alertlevel);
	if (rc != 0) {
		goto out;
	}
	rc = nvlist_add_string(attr_list, "messagevalue", trap_messages);
	if (rc != 0) {
		goto out;
	}
	rc = nvlist_add_int32(attr_list, "errorno", errorno);
	if (rc != 0) {
		goto out;
	}
	if (strcmp(driver_name, "sdbc") == 0)
		rc = ddi_log_sysevent(info_dip, DDI_VENDOR_SUNW,
		    SVE_CACHE_CLASS, component, attr_list, NULL, DDI_SLEEP);
	else if (strcmp(driver_name, "ste") == 0)
		rc = ddi_log_sysevent(info_dip, DDI_VENDOR_SUNW,
		    SVE_STE_CLASS, component, attr_list, NULL, DDI_SLEEP);
	else if (strcmp(driver_name, "ii") == 0)
		rc = ddi_log_sysevent(info_dip, DDI_VENDOR_SUNW,
		    SVE_II_CLASS, component, attr_list, NULL, DDI_SLEEP);
out:
	if (attr_list)
		nvlist_free(attr_list);

	if (rc != 0) {
		cmn_err(CE_WARN, "!%s: unable to log sysevent %d:%s and %d",
		    driver_name, errorno, trap_messages, alertlevel);
	}
#endif  /* which O/S? */
}
Ejemplo n.º 5
0
/*
 * Generate reply event from resource registration information
 */
static void
generate_reply_event(int error, rcm_info_t *info, nvlist_t **ret)
{
	nvlist_t *nvl = NULL;
	rcm_info_t *tmp;
	char *buf = NULL;
	size_t buflen = 0;

	rcm_log_message(RCM_TRACE4, "generating reply event\n");

	/* Allocate an empty nvlist */
	if ((errno = nvlist_alloc(&nvl, 0, 0)) > 0) {
		rcm_log_message(RCM_ERROR,
		    gettext("nvlist_alloc failed: %s\n"), strerror(errno));
		rcmd_exit(errno);
	}

	/* Encode the result of the operation in the nvlist */
	if (errno = nvlist_add_int32(nvl, RCM_RESULT, error)) {
		rcm_log_message(RCM_ERROR,
		    gettext("nvlist_add(RESULT) failed: %s\n"),
		    strerror(errno));
		rcmd_exit(errno);
	}

	/* Go through the RCM info tuples, appending them all to the nvlist */
	tmp = info;
	while (tmp) {
		if (tmp->info) {
			buf = NULL;
			buflen = 0;
			if (errno = nvlist_pack(tmp->info, &buf, &buflen,
			    NV_ENCODE_NATIVE, 0)) {
				rcm_log_message(RCM_ERROR,
				    gettext("nvlist_pack(INFO) failed: %s\n"),
				    strerror(errno));
				rcmd_exit(errno);
			}
			if (errno = nvlist_add_byte_array(nvl, RCM_RESULT_INFO,
			    (uchar_t *)buf, buflen)) {
				rcm_log_message(RCM_ERROR,
				    gettext("nvlist_add(INFO) failed: %s\n"),
				    strerror(errno));
				rcmd_exit(errno);
			}
			(void) free(buf);
			nvlist_free(tmp->info);
		}
		info = tmp->next;
		(void) free(tmp);
		tmp = info;
	}

	/* Return the nvlist (unpacked) in the return argument */
	rcm_print_nvlist(nvl);
	*ret = nvl;
}
boolean_t
test_add_progress_handler()
{
	boolean_t	retval = B_FALSE;
	char		*loggername = "mylogger";
	const char	*host = "localhost";
	int		port = 2333;
	nvlist_t	*handler_args = NULL;
	logger_t	*pLogger = NULL;


	printf("Test: test_add_progress_handler\n");
	pLogger = (logger_t *)test_setup();
	if (pLogger == NULL) {
		printf("Failed to get a Logger\n");
		printf("Cannot proceed with test\n");
		return (retval);
	}

	if (nvlist_alloc(&handler_args, NVATTRS, 0) != 0) {
		printf("Cannot allocate space for handler args\n");
		return (retval);
	}

	if (handler_args == NULL) {
		printf("nvlist_alloc failed.\n");
		printf("Cannot proceed with test\n");
		return (retval);
	}

	/* Create a list of arguments for a ProgressHandler */
	if ((nvlist_add_string(handler_args, HANDLER, PROGRESS_HANDLER) != 0) ||
	    (nvlist_add_string(handler_args, HOST, host) != 0) ||
	    (nvlist_add_int32(handler_args, PORT, port) != 0)) {
		nvlist_free(handler_args);
		printf("Cannot create handler args\n");
		return (retval);
	}

	retval = add_handler(pLogger, handler_args, LOGGING_PROGRESS_HDLR);
	nvlist_free(handler_args);
	if (!retval) {
		printf("test_add_progress_handler: Fail\n");
	} else {
		printf("test_add_progress_handler: Pass\n");
		retval = B_TRUE;
	}

	Py_XDECREF(pLogger);
	return (retval);
}
Ejemplo n.º 7
0
int topo_fmri_setprop(topo_hdl_t *thp, nvlist_t *nvl, const char *pg,
    nvlist_t *prop, int flag, nvlist_t *args, int *err)
{
	int rv;
	nvlist_t *in = NULL, *out = NULL;
	tnode_t *rnode;
	char *scheme;

	if (nvlist_lookup_string(nvl, FM_FMRI_SCHEME, &scheme) != 0)
		return (set_error(thp, ETOPO_FMRI_MALFORM, err,
		    TOPO_METH_PROP_SET, in));

	if ((rnode = topo_hdl_root(thp, scheme)) == NULL)
		return (set_error(thp, ETOPO_METHOD_NOTSUP, err,
		    TOPO_METH_PROP_SET, in));

	if (topo_hdl_nvalloc(thp, &in, NV_UNIQUE_NAME) != 0)
		return (set_error(thp, ETOPO_FMRI_NVL, err,
		    TOPO_METH_PROP_SET, in));

	rv = nvlist_add_nvlist(in, TOPO_PROP_RESOURCE, nvl);
	rv |= nvlist_add_string(in, TOPO_PROP_GROUP, pg);
	rv |= nvlist_add_nvlist(in, TOPO_PROP_VAL, prop);
	rv |= nvlist_add_int32(in, TOPO_PROP_FLAG, (int32_t)flag);
	if (args != NULL)
		rv |= nvlist_add_nvlist(in, TOPO_PROP_PARGS, args);
	if (rv != 0)
		return (set_error(thp, ETOPO_FMRI_NVL, err,
		    TOPO_METH_PROP_SET, in));

	rv = topo_method_invoke(rnode, TOPO_METH_PROP_SET,
	    TOPO_METH_PROP_SET_VERSION, in, &out, err);

	nvlist_free(in);

	/* no return values */
	nvlist_free(out);

	if (rv)
		return (-1);

	return (0);

}
Ejemplo n.º 8
0
/*
 * define an integer property
 */
int
devctl_ddef_int(devctl_ddef_t ddef_hdl, char *name, int32_t value)
{

	int rv;

	if (ddef_hdl == NULL || name == NULL || *name == '\0') {
		errno = EINVAL;
		return (-1);
	}

	rv = nvlist_add_int32((nvlist_t *)ddef_hdl, name, value);

	if (_libdevice_debug)
		(void) printf("devctl_ddef_int: rv %d nvp %p name %s val %d\n",
		    rv, (void *)ddef_hdl, name, value);

	return (rv);
}
Ejemplo n.º 9
0
/*
 * cmd_private()
 *
 *	Implementation of the door command to set or get bus private options.
 *
 *	NOTE: requires 'modify' authorization for the 'set' command.
 */
static int
cmd_private(hp_cmd_t cmd, nvlist_t *args, nvlist_t **resultsp)
{
    nvlist_t	*results = NULL;
    ucred_t		*uc = NULL;
    char		*path, *connection, *options;
    char		*values = NULL;
    int		status;

    dprintf("cmd_private:\n");

    /* Get caller's credentials */
    if ((cmd == HP_CMD_SETPRIVATE) && (door_ucred(&uc) != 0)) {
        log_err("Cannot get door credentials (%s)\n", strerror(errno));
        return (EACCES);
    }

    /* Get arguments */
    if ((nvlist_lookup_string(args, HPD_PATH, &path) != 0) ||
            (nvlist_lookup_string(args, HPD_CONNECTION, &connection) != 0) ||
            (nvlist_lookup_string(args, HPD_OPTIONS, &options) != 0)) {
        dprintf("cmd_private: invalid arguments.\n");
        return (EINVAL);
    }

    /* Check authorization */
    if ((cmd == HP_CMD_SETPRIVATE) &&
            (check_auth(uc, HP_MODIFY_AUTH) != 0)) {
        dprintf("cmd_private: access denied.\n");
        audit_setprivate(uc, HP_MODIFY_AUTH, path, connection, options,
                         ADT_FAIL_VALUE_AUTH);
        ucred_free(uc);
        return (EACCES);
    }

    /* Perform the operation */
    status = private_options(path, connection, cmd, options, &values);
    dprintf("cmd_private: private_options() == %d\n", status);

    /* Audit the operation */
    if (cmd == HP_CMD_SETPRIVATE) {
        audit_setprivate(uc, HP_MODIFY_AUTH, path, connection, options,
                         status);
        ucred_free(uc);
    }

    /* Construct an nvlist if values were returned */
    if (values != NULL) {

        /* Allocate nvlist for results */
        if (nvlist_alloc(&results, NV_UNIQUE_NAME_TYPE, 0) != 0) {
            dprintf("cmd_private: nvlist_alloc() failed.\n");
            free(values);
            return (ENOMEM);
        }

        /* Add values and status to the results */
        if ((nvlist_add_int32(results, HPD_STATUS, status) != 0) ||
                (nvlist_add_string(results, HPD_OPTIONS, values) != 0)) {
            dprintf("cmd_private: nvlist add failed.\n");
            nvlist_free(results);
            free(values);
            return (ENOMEM);
        }

        /* The values string is no longer needed */
        free(values);

        *resultsp = results;
    }

    return (status);
}
Ejemplo n.º 10
0
/* --- tapealert_sysevent - send a tapealert sysevent to n event handlers */
static int		/* 0 successful */
tapealert_sysevent(
	char *src_fn,		/* source filename */
	int src_ln,		/* source file line number */
	dev_ent_t *un,		/* device */
	int flags_len,		/* num valid tapealert flags */
	uint64_t flags,		/* tapealert flags */
	uint64_t *seq_no)	/* sysevent sequence number */
{
	int			rtn = 1;
	time_t			tm;
	nvlist_t		*attr_list = NULL;
	sysevent_id_t		eid;
	boolean_t		free_attr_list = B_FALSE;
	char			*str;

	*seq_no = 0;


	/*
	 * build and send sysevent with active tapealert flags
	 */
	if (nvlist_alloc(&attr_list, 0, 0)) {
		DevLog(DL_DEBUG(12008), "alloc", strerror(errno));
		goto done;
	}
	free_attr_list = B_TRUE;

#ifdef DEBUG
	if (nvlist_add_string(attr_list, TAPEALERT_SRC_FILE, src_fn)) {
		DevLog(DL_DEBUG(12008), TAPEALERT_SRC_FILE, strerror(errno));
		goto done;
	}
	if (nvlist_add_int32(attr_list, TAPEALERT_SRC_LINE, src_ln)) {
		DevLog(DL_DEBUG(12008), TAPEALERT_SRC_LINE, strerror(errno));
		goto done;
	}
#endif /* DEBUG */
	if (nvlist_add_string(attr_list, TAPEALERT_VENDOR,
	    (char *)un->vendor_id)) {
		DevLog(DL_DEBUG(12008), TAPEALERT_VENDOR, strerror(errno));
		goto done;
	}
	if (nvlist_add_string(attr_list, TAPEALERT_PRODUCT,
	    (char *)un->product_id)) {
		DevLog(DL_DEBUG(12008), TAPEALERT_PRODUCT, strerror(errno));
		goto done;
	}
	if (nvlist_add_string(attr_list, TAPEALERT_USN, (char *)un->serial)) {
		DevLog(DL_DEBUG(12008), TAPEALERT_USN, strerror(errno));
		goto done;
	}
	if (nvlist_add_string(attr_list, TAPEALERT_REV, (char *)un->revision)) {
		DevLog(DL_DEBUG(12008), TAPEALERT_REV, strerror(errno));
		goto done;
	}
	time(&tm);
	if (nvlist_add_int32(attr_list, TAPEALERT_TOD, tm)) {
		DevLog(DL_DEBUG(12008), TAPEALERT_TOD, strerror(errno));
		goto done;
	}
	if (nvlist_add_int16(attr_list, TAPEALERT_EQ_ORD, un->eq)) {
		DevLog(DL_DEBUG(12008), TAPEALERT_EQ_ORD, strerror(errno));
		goto done;
	}
	if (nvlist_add_string(attr_list, TAPEALERT_NAME, un->name)) {
		DevLog(DL_DEBUG(12008), TAPEALERT_NAME, strerror(errno));
		goto done;
	}
	if (nvlist_add_byte(attr_list, TAPEALERT_VERSION, un->version)) {
		DevLog(DL_DEBUG(12008), TAPEALERT_VERSION, strerror(errno));
		goto done;
	}
	if (nvlist_add_byte(attr_list, TAPEALERT_INQ_TYPE, un->scsi_type)) {
		DevLog(DL_DEBUG(12008), TAPEALERT_INQ_TYPE, strerror(errno));
		goto done;
	}
	if (strlen(str = (char *)un->set) < 1) {
		str = TAPEALERT_EMPTY_STR;
	}
	if (nvlist_add_string(attr_list, TAPEALERT_SET, str)) {
		DevLog(DL_DEBUG(12008), TAPEALERT_SET, strerror(errno));
		goto done;
	}
	if (nvlist_add_int16(attr_list, TAPEALERT_FSEQ, un->fseq)) {
		DevLog(DL_DEBUG(12008), TAPEALERT_FSEQ, strerror(errno));
		goto done;
	}
	if (strlen(str = (char *)un->vsn) < 1) {
		str = TAPEALERT_EMPTY_STR;
	}
	if (nvlist_add_string(attr_list, TAPEALERT_VSN, str)) {
		DevLog(DL_DEBUG(12008), TAPEALERT_VSN, strerror(errno));
		goto done;
	}
	if (nvlist_add_int16(attr_list, TAPEALERT_FLAGS_LEN, flags_len)) {
		DevLog(DL_DEBUG(12008), TAPEALERT_FLAGS_LEN, strerror(errno));
		goto done;
	}
	if (nvlist_add_uint64(attr_list, TAPEALERT_FLAGS, flags)) {
		DevLog(DL_DEBUG(12008), TAPEALERT_FLAGS,
		    strerror(errno));
		goto done;
	}

	/* class, subclass, vendor, publisher, attribute list, event id */
	if (sysevent_post_event(TAPEALERT_SE_CLASS, TAPEALERT_SE_SUBCLASS,
	    TAPEALERT_SE_VENDOR, TAPEALERT_SE_PUBLISHER, attr_list, &eid)
	    != 0) {
		DevLog(DL_DEBUG(12008), TAPEALERT_SE_PUBLISHER,
		    strerror(errno));
		goto done;
	}
	*seq_no = eid.eid_seq;

	/*
	 * tapealert sysevent successfully sent.
	 */
	rtn = 0;

done:
	if (free_attr_list == B_TRUE) {
		nvlist_free(attr_list);
	}

	return (rtn);
}
Ejemplo n.º 11
0
/*
 * cmd_getinfo()
 *
 *	Implements the door command to get a hotplug information snapshot.
 */
static int
cmd_getinfo(nvlist_t *args, nvlist_t **resultsp)
{
    hp_node_t	root;
    nvlist_t	*results;
    char		*path;
    char		*connection;
    char		*buf = NULL;
    size_t		len = 0;
    uint_t		flags;
    int		rv;

    dprintf("cmd_getinfo:\n");

    /* Get arguments */
    if (nvlist_lookup_string(args, HPD_PATH, &path) != 0) {
        dprintf("cmd_getinfo: invalid arguments.\n");
        return (EINVAL);
    }
    if (nvlist_lookup_string(args, HPD_CONNECTION, &connection) != 0)
        connection = NULL;
    if (nvlist_lookup_uint32(args, HPD_FLAGS, (uint32_t *)&flags) != 0)
        flags = 0;

    /* Get and pack the requested snapshot */
    if ((rv = getinfo(path, connection, flags, &root)) == 0) {
        rv = hp_pack(root, &buf, &len);
        hp_fini(root);
    }
    dprintf("cmd_getinfo: getinfo(): rv = %d, buf = %p.\n", rv,
            (void *)buf);

    /*
     * If the above failed or there is no snapshot,
     * then only return a status code.
     */
    if (rv != 0)
        return (rv);
    if (buf == NULL)
        return (EFAULT);

    /* Allocate nvlist for results */
    if (nvlist_alloc(&results, NV_UNIQUE_NAME_TYPE, 0) != 0) {
        dprintf("cmd_getinfo: nvlist_alloc() failed.\n");
        free(buf);
        return (ENOMEM);
    }

    /* Add snapshot and successful status to results */
    if ((nvlist_add_int32(results, HPD_STATUS, 0) != 0) ||
            (nvlist_add_byte_array(results, HPD_INFO,
                                   (uchar_t *)buf, len) != 0)) {
        dprintf("cmd_getinfo: nvlist add failure.\n");
        nvlist_free(results);
        free(buf);
        return (ENOMEM);
    }

    /* Packed snapshot no longer needed */
    free(buf);

    /* Success */
    *resultsp = results;
    return (0);
}
Ejemplo n.º 12
0
/*
 * cmd_changestate()
 *
 *	Implements the door command to initate a state change operation.
 *
 *	NOTE: requires 'modify' authorization.
 */
static int
cmd_changestate(nvlist_t *args, nvlist_t **resultsp)
{
    hp_node_t	root = NULL;
    nvlist_t	*results = NULL;
    char		*path, *connection;
    ucred_t		*uc = NULL;
    uint_t		flags;
    int		rv, state, old_state, status;

    dprintf("cmd_changestate:\n");

    /* Get arguments */
    if ((nvlist_lookup_string(args, HPD_PATH, &path) != 0) ||
            (nvlist_lookup_string(args, HPD_CONNECTION, &connection) != 0) ||
            (nvlist_lookup_int32(args, HPD_STATE, &state) != 0)) {
        dprintf("cmd_changestate: invalid arguments.\n");
        return (EINVAL);
    }
    if (nvlist_lookup_uint32(args, HPD_FLAGS, (uint32_t *)&flags) != 0)
        flags = 0;

    /* Get caller's credentials */
    if (door_ucred(&uc) != 0) {
        log_err("Cannot get door credentials (%s)\n", strerror(errno));
        return (EACCES);
    }

    /* Check authorization */
    if (check_auth(uc, HP_MODIFY_AUTH) != 0) {
        dprintf("cmd_changestate: access denied.\n");
        audit_changestate(uc, HP_MODIFY_AUTH, path, connection,
                          state, -1, ADT_FAIL_VALUE_AUTH);
        ucred_free(uc);
        return (EACCES);
    }

    /* Perform the state change operation */
    status = changestate(path, connection, state, flags, &old_state, &root);
    dprintf("cmd_changestate: changestate() == %d\n", status);

    /* Audit the operation */
    audit_changestate(uc, HP_MODIFY_AUTH, path, connection, state,
                      old_state, status);

    /* Caller's credentials no longer needed */
    ucred_free(uc);

    /*
     * Pack the results into an nvlist if there is an error snapshot.
     *
     * If any error occurs while packing the results, the original
     * error code from changestate() above is still returned.
     */
    if (root != NULL) {
        char	*buf = NULL;
        size_t	len = 0;

        dprintf("cmd_changestate: results nvlist required.\n");

        /* Pack and discard the error snapshot */
        rv = hp_pack(root, &buf, &len);
        hp_fini(root);
        if (rv != 0) {
            dprintf("cmd_changestate: hp_pack() failed (%s).\n",
                    strerror(rv));
            return (status);
        }

        /* Allocate nvlist for results */
        if (nvlist_alloc(&results, NV_UNIQUE_NAME_TYPE, 0) != 0) {
            dprintf("cmd_changestate: nvlist_alloc() failed.\n");
            free(buf);
            return (status);
        }

        /* Add the results into the nvlist */
        if ((nvlist_add_int32(results, HPD_STATUS, status) != 0) ||
                (nvlist_add_byte_array(results, HPD_INFO, (uchar_t *)buf,
                                       len) != 0)) {
            dprintf("cmd_changestate: nvlist add failed.\n");
            nvlist_free(results);
            free(buf);
            return (status);
        }

        *resultsp = results;
    }

    return (status);
}
Ejemplo n.º 13
0
static int
drd_rcm_del_cpu_notify(drctl_rsrc_t *rsrcs, int nrsrc)
{
	cpuid_t		*cpus = NULL;
	int		rv = -1;
	cpuid_t		*oldcpus = NULL;
	cpuid_t		*newcpus = NULL;
	int		oldncpus = 0;
	int		newncpus = 0;
	nvlist_t	*nvl = NULL;
	int		idx;
	int		cidx;
	rcm_info_t	*rinfo;

	drd_dbg("drd_rcm_del_cpu_notify...");

	if ((rsrcs == NULL) || (nrsrc == 0)) {
		drd_err("del_cpu_notify: cpu list empty");
		goto done;
	}

	cpus = (cpuid_t *)malloc(nrsrc * sizeof (cpuid_t));

	/*
	 * Filter out the CPUs that could not be unconfigured.
	 */
	for (idx = 0, cidx = 0; idx < nrsrc; idx++) {
		if (rsrcs[idx].status != DRCTL_STATUS_CONFIG_SUCCESS)
			continue;
		drd_dbg("  cpu[%d] = %d", idx, rsrcs[idx].res_cpu_id);
		cpus[cidx] = rsrcs[idx].res_cpu_id;
		cidx++;
	}

	drd_dbg("  ncpus = %d", cidx);

	/* nothing to do */
	if (cidx == 0) {
		rv = 0;
		goto done;
	}

	/* allocate an nvlist for the RCM call */
	if (nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0) != 0) {
		goto done;
	}

	/*
	 * Removed CPU capacity, so newcpus is the current list
	 * of CPUs in the system.
	 */
	if (get_sys_cpuids(&newcpus, &newncpus) == -1) {
		goto done;
	}

	/*
	 * Since the operation removed CPU capacity, the old CPU
	 * list is the new CPU list with the CPUs involved in
	 * the operation added.
	 */
	oldcpus = (cpuid_t *)calloc(newncpus + cidx, sizeof (cpuid_t));
	if (oldcpus == NULL) {
		goto done;
	}

	for (idx = 0; idx < newncpus; idx++) {
		if (!is_cpu_in_list(newcpus[idx], cpus, cidx))
			oldcpus[oldncpus++] = newcpus[idx];
	}

	for (idx = 0; idx < cidx; idx++) {
		oldcpus[oldncpus++] = cpus[idx];
	}

	/* dump pre and post lists */
	dump_cpu_list("oldcpus: ", oldcpus, oldncpus);
	dump_cpu_list("newcpus: ", newcpus, newncpus);
	dump_cpu_list("delta:   ", cpus, cidx);

	/* setup the nvlist for the RCM call */
	if (nvlist_add_string(nvl, "state", "capacity") ||
	    nvlist_add_int32(nvl, "old_total", oldncpus) ||
	    nvlist_add_int32(nvl, "new_total", newncpus) ||
	    nvlist_add_int32_array(nvl, "old_cpu_list", oldcpus, oldncpus) ||
	    nvlist_add_int32_array(nvl, "new_cpu_list", newcpus, newncpus)) {
		goto done;
	}

	rv = rcm_notify_capacity_change(rcm_hdl, RCM_CPU_ALL, 0, nvl, &rinfo);
	rv = (rv == RCM_SUCCESS) ? 0 : -1;

done:
	s_nvfree(nvl);
	s_free(cpus);
	s_free(oldcpus);
	s_free(newcpus);

	return (rv);
}
Ejemplo n.º 14
0
static int
drd_rcm_del_cpu_request(drctl_rsrc_t *rsrcs, int nrsrc)
{
	cpuid_t		*cpus = NULL;
	int		ncpus;
	int		rv = -1;
	cpuid_t		*oldcpus = NULL;
	cpuid_t		*newcpus = NULL;
	int		oldncpus = 0;
	int		newncpus = 0;
	nvlist_t	*nvl = NULL;
	int		idx;
	rcm_info_t	*rinfo;

	drd_dbg("drd_rcm_del_cpu_request...");

	if ((rsrcs == NULL) || (nrsrc == 0)) {
		drd_err("del_cpu_request: cpu list empty");
		goto done;
	}

	ncpus = nrsrc;
	cpus = (cpuid_t *)malloc(nrsrc * sizeof (cpuid_t));

	for (idx = 0; idx < nrsrc; idx++) {
		cpus[idx] = rsrcs[idx].res_cpu_id;
	}

	/* allocate an nvlist for the RCM call */
	if (nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0) != 0) {
		goto done;
	}

	/*
	 * Removing CPU capacity, so oldcpus is the current
	 * list of CPUs in the system.
	 */
	if (get_sys_cpuids(&oldcpus, &oldncpus) == -1) {
		goto done;
	}

	/*
	 * Since this is a request to remove CPU capacity,
	 * the new CPU list is the old CPU list with the CPUs
	 * involved in the operation removed.
	 */
	newcpus = (cpuid_t *)calloc(oldncpus, sizeof (cpuid_t));
	if (newcpus == NULL) {
		goto done;
	}

	for (idx = 0; idx < oldncpus; idx++) {
		if (!is_cpu_in_list(oldcpus[idx], cpus, ncpus))
			newcpus[newncpus++] = oldcpus[idx];
	}

	/* dump pre and post lists */
	dump_cpu_list("oldcpus: ", oldcpus, oldncpus);
	dump_cpu_list("newcpus: ", newcpus, newncpus);
	dump_cpu_list("delta:   ", cpus, ncpus);

	/* setup the nvlist for the RCM call */
	if (nvlist_add_string(nvl, "state", "capacity") ||
	    nvlist_add_int32(nvl, "old_total", oldncpus) ||
	    nvlist_add_int32(nvl, "new_total", newncpus) ||
	    nvlist_add_int32_array(nvl, "old_cpu_list", oldcpus, oldncpus) ||
	    nvlist_add_int32_array(nvl, "new_cpu_list", newcpus, newncpus)) {
		goto done;
	}

	rv = rcm_request_capacity_change(rcm_hdl, RCM_CPU_ALL, 0, nvl, &rinfo);
	if (rv != RCM_SUCCESS) {
		drd_dbg("RCM call failed: %d", rv);
		/*
		 * Since the capacity change was blocked, we
		 * mark all CPUs as blocked. It is up to the
		 * user to reframe the query so that it can
		 * succeed.
		 */
		for (idx = 0; idx < nrsrc; idx++) {
			rsrcs[idx].status = DRCTL_STATUS_DENY;
		}

		/* tack on message to first resource */
		rsrcs[0].offset = (uintptr_t)strdup("unable to remove "
		    "specified number of CPUs");
		drd_dbg("  unable to remove specified number of CPUs");
		goto done;
	}

	rv = 0;

done:
	s_nvfree(nvl);
	s_free(cpus);
	s_free(oldcpus);
	s_free(newcpus);

	return (rv);
}
Ejemplo n.º 15
0
static int
topo_prop_set(tnode_t *node, const char *pgname, const char *pname,
    topo_type_t type, int flag, void *val, int nelems, int *err)
{
	int ret;
	topo_hdl_t *thp = node->tn_hdl;
	nvlist_t *nvl;

	if (topo_hdl_nvalloc(thp, &nvl, NV_UNIQUE_NAME) < 0) {
		*err = ETOPO_PROP_NVL;
		return (-1);
	}

	ret = nvlist_add_string(nvl, TOPO_PROP_VAL_NAME, pname);
	ret |= nvlist_add_uint32(nvl, TOPO_PROP_VAL_TYPE, type);
	switch (type) {
		case TOPO_TYPE_INT32:
			ret |= nvlist_add_int32(nvl, TOPO_PROP_VAL_VAL,
			    *(int32_t *)val);
			break;
		case TOPO_TYPE_UINT32:
			ret |= nvlist_add_uint32(nvl, TOPO_PROP_VAL_VAL,
			    *(uint32_t *)val);
			break;
		case TOPO_TYPE_INT64:
			ret |= nvlist_add_int64(nvl, TOPO_PROP_VAL_VAL,
			    *(int64_t *)val);
			break;
		case TOPO_TYPE_UINT64:
			ret |= nvlist_add_uint64(nvl, TOPO_PROP_VAL_VAL,
			    *(uint64_t *)val);
			break;
		case TOPO_TYPE_DOUBLE:
			ret |= nvlist_add_double(nvl, TOPO_PROP_VAL_VAL,
			    *(double *)val);
			break;
		case TOPO_TYPE_STRING:
			ret |= nvlist_add_string(nvl, TOPO_PROP_VAL_VAL,
			    (char *)val);
			break;
		case TOPO_TYPE_FMRI:
			ret |= nvlist_add_nvlist(nvl, TOPO_PROP_VAL_VAL,
			    (nvlist_t *)val);
			break;
		case TOPO_TYPE_INT32_ARRAY:
			ret |= nvlist_add_int32_array(nvl,
			    TOPO_PROP_VAL_VAL, (int32_t *)val, nelems);
			break;
		case TOPO_TYPE_UINT32_ARRAY:
			ret |= nvlist_add_uint32_array(nvl,
			    TOPO_PROP_VAL_VAL, (uint32_t *)val, nelems);
			break;
		case TOPO_TYPE_INT64_ARRAY:
			ret |= nvlist_add_int64_array(nvl,
			    TOPO_PROP_VAL_VAL, (int64_t *)val, nelems);
			break;
		case TOPO_TYPE_UINT64_ARRAY:
			ret |= nvlist_add_uint64_array(nvl,
			    TOPO_PROP_VAL_VAL, (uint64_t *)val, nelems);
			break;
		case TOPO_TYPE_STRING_ARRAY:
			ret |= nvlist_add_string_array(nvl,
			    TOPO_PROP_VAL_VAL, (char **)val, nelems);
			break;
		case TOPO_TYPE_FMRI_ARRAY:
			ret |= nvlist_add_nvlist_array(nvl,
			    TOPO_PROP_VAL_VAL, (nvlist_t **)val, nelems);
			break;
		default:
			*err = ETOPO_PROP_TYPE;
			return (-1);
	}

	if (ret != 0) {
		nvlist_free(nvl);
		if (ret == ENOMEM) {
			*err = ETOPO_PROP_NOMEM;
			return (-1);
		} else {
			*err = ETOPO_PROP_NVL;
			return (-1);
		}
	}

	if (topo_prop_setprop(node, pgname, nvl, flag, nvl, err) != 0) {
		nvlist_free(nvl);
		return (-1); /* err set */
	}
	nvlist_free(nvl);
	return (ret);
}
Ejemplo n.º 16
0
static void
set_prop(topo_hdl_t *thp, tnode_t *node, nvlist_t *fmri, struct prop_args *pp)
{
	int ret, err = 0;
	topo_type_t type;
	nvlist_t *nvl, *f = NULL;
	char *end;

	if (pp->prop == NULL || pp->type == NULL || pp->value == NULL)
		return;

	if ((type = str2type(pp->type)) == TOPO_TYPE_INVALID) {
		(void) fprintf(stderr, "%s: invalid property type %s for %s\n",
		    g_pname, pp->type, pp->prop);
		return;
	}

	if (nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0) != 0) {
		(void) fprintf(stderr, "%s: nvlist allocation failed for "
		    "%s=%s:%s\n", g_pname, pp->prop, pp->type, pp->value);
		return;
	}
	ret = nvlist_add_string(nvl, TOPO_PROP_VAL_NAME, pp->prop);
	ret |= nvlist_add_uint32(nvl, TOPO_PROP_VAL_TYPE, type);
	if (ret != 0) {
		(void) fprintf(stderr, "%s: invalid property type %s for %s\n",
		    g_pname, pp->type, pp->prop);
		nvlist_free(nvl);
		return;
	}

	errno = 0;
	switch (type) {
		case TOPO_TYPE_INT32:
		{
			int32_t val;

			val = strtol(pp->value, &end, 0);
			if (errno == ERANGE) {
				ret = -1;
				break;
			}
			ret = nvlist_add_int32(nvl, TOPO_PROP_VAL_VAL, val);
			break;
		}
		case TOPO_TYPE_UINT32:
		{
			uint32_t val;

			val = strtoul(pp->value, &end, 0);
			if (errno == ERANGE) {
				ret = -1;
				break;
			}
			ret = nvlist_add_uint32(nvl, TOPO_PROP_VAL_VAL, val);
			break;
		}
		case TOPO_TYPE_INT64:
		{
			int64_t val;

			val = strtoll(pp->value, &end, 0);
			if (errno == ERANGE) {
				ret = -1;
				break;
			}
			ret = nvlist_add_int64(nvl, TOPO_PROP_VAL_VAL, val);
			break;
		}
		case TOPO_TYPE_UINT64:
		{
			uint64_t val;

			val = strtoull(pp->value, &end, 0);
			if (errno == ERANGE) {
				ret = -1;
				break;
			}
			ret = nvlist_add_uint64(nvl, TOPO_PROP_VAL_VAL, val);
			break;
		}
		case TOPO_TYPE_STRING:
		{
			ret = nvlist_add_string(nvl, TOPO_PROP_VAL_VAL,
			    pp->value);
			break;
		}
		case TOPO_TYPE_FMRI:
		{
			if ((ret = topo_fmri_str2nvl(thp, pp->value, &f, &err))
			    < 0)
				break;

			if ((ret = nvlist_add_nvlist(nvl, TOPO_PROP_VAL_VAL,
			    f)) != 0)
				err = ETOPO_PROP_NVL;
			break;
		}
		default:
			ret = -1;
	}

	if (ret != 0) {
		(void) fprintf(stderr, "%s: unable to set property value for "
		    "%s: %s\n", g_pname, pp->prop,  topo_strerror(err));
		nvlist_free(nvl);
		return;
	}

	if (node != NULL) {
		if (topo_prop_setprop(node, pp->group, nvl, TOPO_PROP_MUTABLE,
		    f, &ret) < 0) {
			(void) fprintf(stderr, "%s: unable to set property "
			    "value for " "%s=%s:%s: %s\n", g_pname, pp->prop,
			    pp->type, pp->value, topo_strerror(ret));
			nvlist_free(nvl);
			nvlist_free(f);
			return;
		}
	} else {
		if (topo_fmri_setprop(thp, fmri,  pp->group, nvl,
		    TOPO_PROP_MUTABLE, f, &ret) < 0) {
			(void) fprintf(stderr, "%s: unable to set property "
			    "value for " "%s=%s:%s: %s\n", g_pname, pp->prop,
			    pp->type, pp->value, topo_strerror(ret));
			nvlist_free(nvl);
			nvlist_free(f);
			return;
		}
	}

	nvlist_free(nvl);

	/*
	 * Now, get the property back for printing
	 */
	if (node != NULL) {
		if (topo_prop_getprop(node, pp->group, pp->prop, f, &nvl,
		    &err) < 0) {
			(void) fprintf(stderr, "%s: failed to get %s.%s: %s\n",
			    g_pname, pp->group, pp->prop, topo_strerror(err));
			nvlist_free(f);
			return;
		}
	} else {
		if (topo_fmri_getprop(thp, fmri, pp->group, pp->prop,
		    f, &nvl, &err) < 0) {
			(void) fprintf(stderr, "%s: failed to get %s.%s: %s\n",
			    g_pname, pp->group, pp->prop, topo_strerror(err));
			nvlist_free(f);
			return;
		}
	}

	print_pgroup(thp, node, pp->group, NULL, NULL, 0);
	print_prop_nameval(thp, node, nvl);
	nvlist_free(nvl);

	nvlist_free(f);
}
Ejemplo n.º 17
0
static int
ap_rcm_cap_cpu(apd_t *a, rcmd_t *rcm, rcm_handle_t *hd, uint_t flags,
	rcm_info_t **rinfo, int cmd, int change)
{
	int i;
	int rv = RCM_FAILURE;
	int ncpuids;
	int oldncpuids;
	int newncpuids;
	char buf[32];
	const char *fmt;
	size_t size;
	nvlist_t *nvl = NULL;
	cpuid_t *cpuids = NULL;
	cpuid_t *oldcpuids = NULL;
	cpuid_t *newcpuids = NULL;

	DBG("ap_rcm_cap_cpu(%p)\n", (void *)a);

	/*
	 * Get the current number of configured cpus.
	 */
	if (getsyscpuids(&ncpuids, &cpuids) == -1)
		return (rv);
	else if (nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0) != 0) {
		free(cpuids);
		goto done;
	}

	if (change == 1)
		fmt = "(%d cpu)";
	else
		fmt = "(%d cpus)";

	size = sizeof (cpuid_t);

	if (cmd == CMD_RCM_CAP_DEL) {
		/*
		 * A delete request. rcm->cpuids represents the
		 * cpus that will be unconfigured. The current
		 * set of cpus, before the unconfigure operation,
		 * are the old CPUs. The new CPUs are those
		 * that would remain.
		 */
		oldncpuids = ncpuids;
		oldcpuids = cpuids;

		/*
		 * Fill newcpuids with the CPU IDs in the cpuids array,
		 * but not in rcm->cpuids.
		 */
		newcpuids = (cpuid_t *)calloc(ncpuids, size);
		if (newcpuids == NULL)
			goto done;

		newncpuids = 0;
		for (i = 0; i < ncpuids; i++) {
			if (!is_cpu_in_list(cpuids[i], rcm->cpuids, change))
				newcpuids[newncpuids++] = cpuids[i];
		}
	} else if (cmd == CMD_RCM_CAP_NOTIFY) {
		/*
		 * An unconfigure capacity change notification. This
		 * notification is sent after a DR unconfigure, whether
		 * or not the DR was successful. rcm->cpuids represents
		 * the CPUs that have been unconfigured.
		 */

		/* New CPU IDs are the CPUs configured right now. */
		newncpuids = ncpuids;
		newcpuids = cpuids;

		/*
		 * Old CPU IDs are the CPUs configured right now
		 * in addition to those that have been unconfigured.
		 * We build the old CPU ID list by concatenating
		 * cpuids and rcm->cpuids.
		 */
		oldcpuids = (cpuid_t *)calloc(ncpuids + change, size);
		if (oldcpuids == NULL)
			goto done;

		oldncpuids = 0;
		for (i = 0; i < ncpuids; i++) {
			if (!is_cpu_in_list(cpuids[i], rcm->cpuids, change))
				oldcpuids[oldncpuids++] = cpuids[i];
		}
		for (i = 0; i < change; i++)
			oldcpuids[oldncpuids++] = rcm->cpuids[i];
	} else {
		DBG("ap_rcm_cap_cpu: CPU capacity, old = %d, new = %d \n",
		    rcm->capcpus, ncpuids);
		if (rcm->capcpus == ncpuids) {
			/* No real change in CPU capacity */
			rv = RCM_SUCCESS;
			goto done;
		}

		/*
		 * An add notification.  rcm->cpuids represents the
		 * cpus that have been configured.  The current
		 * set of cpus, after the configure operation,
		 * are the new CPU IDs.
		 */
		newncpuids = ncpuids;
		newcpuids = cpuids;

		/*
		 * Fill oldcpuids with the CPU IDs in the cpuids array,
		 * but not in rcm->cpuids.
		 */
		oldcpuids = (cpuid_t *)calloc(ncpuids, size);
		if (oldcpuids == NULL)
			goto done;

		oldncpuids = 0;
		for (i = 0; i < ncpuids; i++) {
			if (!is_cpu_in_list(cpuids[i], rcm->cpuids, change))
				oldcpuids[oldncpuids++] = cpuids[i];
		}
	}

	DBG("oldcpuids: ");
	for (i = 0; i < oldncpuids; i++)
		DBG("%d ", oldcpuids[i]);
	DBG("\n");
	DBG("change   : ");
	for (i = 0; i < change; i++)
		DBG("%d ", rcm->cpuids[i]);
	DBG("\n");
	DBG("newcpuids: ");
	for (i = 0; i < newncpuids; i++)
		DBG("%d ", newcpuids[i]);
	DBG("\n");

	if (nvlist_add_string(nvl, "state", "capacity") != 0 ||
	    nvlist_add_int32(nvl, "old_total", oldncpuids) != 0 ||
	    nvlist_add_int32(nvl, "new_total", newncpuids) != 0 ||
	    nvlist_add_int32_array(nvl, "old_cpu_list", oldcpuids,
	    oldncpuids) != 0 ||
	    nvlist_add_int32_array(nvl, "new_cpu_list", newcpuids,
	    newncpuids) != 0)
		goto done;

	(void) snprintf(buf, sizeof (buf), fmt, change);
	ap_msg(a, MSG_ISSUE, cmd, buf);

	if (cmd == CMD_RCM_CAP_DEL) {
		rv = (*rcm->request_capacity_change)(hd, "SUNW_cpu",
		    flags, nvl, rinfo);
	} else {
		rv = (*rcm->notify_capacity_change)(hd, "SUNW_cpu",
		    flags & ~RCM_FORCE, nvl, rinfo);
	}

done:
	nvlist_free(nvl);
	s_free(oldcpuids);
	s_free(newcpuids);
	return (rv);
}
Ejemplo n.º 18
0
static int
ap_rcm_cap_mem(apd_t *a, rcmd_t *rcm, rcm_handle_t *hd, uint_t flags,
	rcm_info_t **rinfo, int cmd, long change)
{
	int rv;
	int pgsize;
	long oldpages;
	long newpages;
	long currpages;
	char buf[32];
	nvlist_t *nvl;

	DBG("ap_rcm_cap_mem(%p)\n", (void *)a);

	/*
	 * Get the current amount of configured memory.
	 */
	if ((pgsize = sysconf(_SC_PAGE_SIZE)) == -1 ||
	    (currpages = sysconf(_SC_PHYS_PAGES)) == -1 ||
	    nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0) > 0)
		return (RCM_FAILURE);

	/*
	 * If this is a (delete) request, change represents
	 * the amount of capacity that will be deleted from the
	 * system.  If this is an (add) notification, change
	 * represents the amount of capacity that has already
	 * been added to the system.
	 */
	if (cmd == CMD_RCM_CAP_DEL) {
		oldpages = currpages;
		newpages = currpages - change;
	} else if (cmd == CMD_RCM_CAP_NOTIFY) {
		newpages = currpages;
		oldpages = rcm->cappages;
	} else {
		if (rcm->cappages == currpages) {
			/* No real change in memory capacity */
			DBG("ap_rcm_cap_mem: no change in capacity.\n");
			nvlist_free(nvl);
			return (RCM_SUCCESS);
		}

		oldpages = currpages - change;
		newpages = currpages;
	}

	DBG("ap_rcm_cap_mem: Memory capacity, old = %ld, new = %ld\n",
	    oldpages, newpages);

	if (nvlist_add_string(nvl, "state", "capacity") != 0 ||
	    nvlist_add_int32(nvl, "page_size", pgsize) != 0 ||
	    nvlist_add_int32(nvl, "old_pages", oldpages) != 0 ||
	    nvlist_add_int32(nvl, "new_pages", newpages) != 0) {
		nvlist_free(nvl);
		return (RCM_FAILURE);
	}

	(void) snprintf(buf, sizeof (buf), "(%ld pages)", change);
	ap_msg(a, MSG_ISSUE, cmd, buf);

	if (cmd == CMD_RCM_CAP_DEL) {
		rv = (*rcm->request_capacity_change)(hd, "SUNW_memory",
		    flags, nvl, rinfo);
	} else {
		rv = (*rcm->notify_capacity_change)(hd, "SUNW_memory",
		    flags & ~RCM_FORCE, nvl, rinfo);
	}

	nvlist_free(nvl);

	return (rv);
}
Ejemplo n.º 19
0
void
fnvlist_add_int32(nvlist_t *nvl, const char *name, int32_t val)
{
	VERIFY0(nvlist_add_int32(nvl, name, val));
}
Ejemplo n.º 20
0
static cfga_sata_ret_t
setup_for_devctl_cmd(
	const char *ap_id,
	devctl_hdl_t *devctl_hdl,
	nvlist_t **user_nvlistp,
	uint_t oflag)
{

	uint_t	port;
	cfga_sata_ret_t	rv = CFGA_SATA_OK;
	char *lap_id, *pdyn;

	lap_id = strdup(ap_id);
	if (lap_id == NULL)
		return (CFGA_SATA_ALLOC_FAIL);
	if ((pdyn = GET_DYN(lap_id)) != NULL) {
		*pdyn = '\0';
	}

	/* Get a devctl handle to pass to the devctl_ap_XXX functions */
	if ((*devctl_hdl = devctl_ap_acquire((char *)lap_id, oflag)) == NULL) {
		(void) fprintf(stderr, "[libcfgadm:sata] "
		    "setup_for_devctl_cmd: devctl_ap_acquire failed: %s\n",
		    strerror(errno));
		rv = CFGA_SATA_DEVCTL;
		goto bailout;
	}

	/* Set up nvlist to pass the port number down to the driver */
	if (nvlist_alloc(user_nvlistp, NV_UNIQUE_NAME_TYPE, NULL) != 0) {
		*user_nvlistp = NULL;
		rv = CFGA_SATA_NVLIST;
		(void) printf("nvlist_alloc failed\n");
		goto bailout;
	}

	/*
	 * Get port id, for Port Multiplier port, things could be a little bit
	 * complicated because of "port.port" format in ap_id, thus for
	 * port multiplier port, port number should be coded as 32bit int
	 * with the sig 16 bit as sata channel number, least 16 bit as
	 * the port number of sata port multiplier port.
	 */
	if ((rv = get_port_num(lap_id, &port)) != CFGA_SATA_OK) {
		(void) printf(
			"setup_for_devctl_cmd: get_port_num, errno: %d\n",
			errno);
		goto bailout;
	}

	/* Creates an int32_t entry */
	if (nvlist_add_int32(*user_nvlistp, PORT, port) == -1) {
		(void) printf("nvlist_add_int32 failed\n");
		rv = CFGA_SATA_NVLIST;
		goto bailout;
	}

	free(lap_id);
	return (rv);

bailout:
	free(lap_id);
	(void) cleanup_after_devctl_cmd(*devctl_hdl, *user_nvlistp);

	return (rv);
}
boolean_t
test_report_progress(void)
{
	boolean_t	retval = B_FALSE;
	boolean_t	handler_ret = B_FALSE;
	char		*loggername = "mylogger";
	const char	*host = "localhost";
	int		port = 2333;
	logger_t	*pLogger = NULL;
	nvlist_t	*handler_args = NULL;


	printf("Test: test_report_progress\n");
	pLogger = (logger_t *)test_setup();
	if (pLogger == NULL) {
		printf("Failed to get a Logger\n");
		return (retval);
	}

	if (nvlist_alloc(&handler_args, NVATTRS, 0) != 0) {
		printf("Cannot allocate space for handler args\n");
		goto cleanup;
	}

	if (handler_args == NULL) {
		printf("nvlist_alloc failed.\n");
		goto cleanup;
	}

	/* Create a list of arguments for a ProgressHandler */
	if ((nvlist_add_string(handler_args, HANDLER, PROGRESS_HANDLER) != 0) ||
	    (nvlist_add_string(handler_args, HOST, host) != 0) ||
	    (nvlist_add_int32(handler_args, PORT, port) != 0)) {
		nvlist_free(handler_args);
		printf("Cannot create handler args\n");
		goto cleanup;
	}

	handler_ret = add_handler(pLogger, handler_args, LOGGING_PROGRESS_HDLR);
	nvlist_free(handler_args);
	if (!handler_ret) {
		printf("Adding progress handler failed cannot continue\n");
		goto cleanup;
	} else {

		retval = report_progress(pLogger, 0, "Test: 0 done");
		if (!retval) {
			printf("test_report_progress: Fail 0\n");
			goto cleanup;
		}

		retval = report_progress(pLogger, 20, "Test 20 done");
		if (!retval) {
			printf("test_report_progress: Fail 20\n");
			goto cleanup;
		}

		retval = report_progress(pLogger, 40, "Test: 40 done");
		if (!retval) {
			printf("test_report_progress: Fail 40\n");
			goto cleanup;
		}

		retval = report_progress(pLogger, 60, "Test: 60 done");
		if (!retval) {
			printf("test_report_progress: Fail 60\n");
			goto cleanup;
		}

		retval = report_progress(pLogger, 80, "Test:80 done");
		if (!retval) {
			printf("test_report_progress: Fail 80\n");
			goto cleanup;
		}

		retval = report_progress(pLogger, 100, "Test:100 done");
		if (!retval) {
			printf("test_log_message: Fail 100\n");
			goto cleanup;
		}
	}
	printf("test_report_progress: Pass\n");

cleanup:
	Py_XDECREF(pLogger);
	return (retval);
}
Ejemplo n.º 22
0
/*
 * Add a profile rule.
 * tgt represents a device name matching expression,
 * matching device names are to be either included or excluded.
 */
static void
prof_add_rule(char *name, char *tgt, struct sdev_node *dir, int type)
{
	int error;
	nvlist_t **nvlp = NULL;
	int rv;

	ASSERT(SDEVTOV(dir)->v_type == VDIR);

	rw_enter(&dir->sdev_contents, RW_WRITER);

	switch (type) {
	case PROFILE_TYPE_INCLUDE:
		if (tgt)
			nvlp = &(dir->sdev_prof.dev_glob_incdir);
		else
			nvlp = &(dir->sdev_prof.dev_name);
		break;
	case PROFILE_TYPE_EXCLUDE:
		if (tgt)
			nvlp = &(dir->sdev_prof.dev_glob_excdir);
		else
			nvlp = &(dir->sdev_prof.dev_name);
		break;
	case PROFILE_TYPE_MAP:
		nvlp = &(dir->sdev_prof.dev_map);
		break;
	case PROFILE_TYPE_SYMLINK:
		nvlp = &(dir->sdev_prof.dev_symlink);
		break;
	};

	/* initialize nvlist */
	if (*nvlp == NULL) {
		error = nvlist_alloc(nvlp, NV_UNIQUE_NAME, KM_SLEEP);
		ASSERT(error == 0);
	}

	if (tgt) {
		rv = nvlist_add_string(*nvlp, name, tgt);
	} else {
		rv = nvlist_add_int32(*nvlp, name, type);
	}
	ASSERT(rv == 0);
	/* rebuild directory content */
	dir->sdev_flags |= SDEV_BUILD;

	if ((type == PROFILE_TYPE_INCLUDE) &&
	    (strpbrk(name, "*?[]") != NULL)) {
			dir->sdev_prof.has_glob = 1;
	}

	rw_exit(&dir->sdev_contents);

	/* additional details for glob pattern and exclusion */
	switch (type) {
	case PROFILE_TYPE_INCLUDE:
	case PROFILE_TYPE_EXCLUDE:
		apply_dir_pattern(dir, name, tgt, type);
		break;
	};
}
Ejemplo n.º 23
0
/*ARGSUSED3*/
static nvlist_t *
fmevt_detector(nvlist_t *attr, char *ruleset, int user, int priv,
    fmev_pri_t pri)
{
	char buf[FMEV_MAX_RULESET_LEN + 1];
	char *ns, *subsys;
	nvlist_t *obj, *dtcr, *site, *ctxt;
	char *execname = NULL;
	int32_t i32;
	int64_t i64;
	int err = 0;
	char *str;

	(void) strncpy(buf, ruleset, sizeof (buf));
	if (!fmevt_rs_burst(NULL, buf, &ns, &subsys, B_FALSE))
		return (NULL);

	obj = fmd_nvl_alloc(fmevt_hdl, FMD_SLEEP);
	dtcr = fmd_nvl_alloc(fmevt_hdl, FMD_SLEEP);
	site = fmd_nvl_alloc(fmevt_hdl, FMD_SLEEP);
	ctxt = fmd_nvl_alloc(fmevt_hdl, FMD_SLEEP);

	if (obj == NULL || dtcr == NULL || site == NULL || ctxt == NULL) {
		err++;
		goto done;
	}

	/*
	 * Build up 'object' nvlist.
	 */
	if (nvlist_lookup_string(attr, "__fmev_execname", &execname) == 0)
		err += nvlist_add_string(obj, FM_FMRI_SW_OBJ_PATH, execname);

	/*
	 * Build up 'site' nvlist.  We should have source file and line
	 * number and, if the producer was compiled with C99, function name.
	 */
	if (nvlist_lookup_string(attr, "__fmev_file", &str) == 0) {
		err += nvlist_add_string(site, FM_FMRI_SW_SITE_FILE, str);
		(void) nvlist_remove(attr, "__fmev_file", DATA_TYPE_STRING);
	}

	if (nvlist_lookup_string(attr, "__fmev_func", &str) == 0) {
		err += nvlist_add_string(site, FM_FMRI_SW_SITE_FUNC, str);
		(void) nvlist_remove(attr, "__fmev_func", DATA_TYPE_STRING);
	}

	if (nvlist_lookup_int64(attr, "__fmev_line", &i64) == 0) {
		err += nvlist_add_int64(site, FM_FMRI_SW_SITE_LINE, i64);
		(void) nvlist_remove(attr, "__fmev_line", DATA_TYPE_INT64);
	}

	/*
	 * Build up 'context' nvlist.  We do not include contract id at
	 * this time.
	 */

	err += nvlist_add_string(ctxt, FM_FMRI_SW_CTXT_ORIGIN,
	    user ? "userland" : "kernel");

	if (execname) {
		err += nvlist_add_string(ctxt, FM_FMRI_SW_CTXT_EXECNAME,
		    execname);
		(void) nvlist_remove(attr, "__fmev_execname", DATA_TYPE_STRING);
	}

	if (nvlist_lookup_int32(attr, "__fmev_pid", &i32) == 0) {
		err += nvlist_add_int32(ctxt, FM_FMRI_SW_CTXT_PID, i32);
		(void) nvlist_remove(attr, "__fmev_pid", DATA_TYPE_INT32);
	}

	if (!isglobalzone)
		err += nvlist_add_string(ctxt, FM_FMRI_SW_CTXT_ZONE, zonename);

	/* Put it all together */

	err += nvlist_add_uint8(dtcr, FM_VERSION, SW_SCHEME_VERSION0);
	err += nvlist_add_string(dtcr, FM_FMRI_SCHEME, FM_FMRI_SCHEME_SW);
	err += nvlist_add_nvlist(dtcr, FM_FMRI_SW_OBJ, obj);
	err += nvlist_add_nvlist(dtcr, FM_FMRI_SW_SITE, site);
	err += nvlist_add_nvlist(dtcr, FM_FMRI_SW_CTXT, ctxt);

done:
	nvlist_free(obj);
	nvlist_free(site);
	nvlist_free(ctxt);

	if (err == 0) {
		return (dtcr);
	} else {
		nvlist_free(dtcr);
		return (NULL);
	}
}