示例#1
0
void get_fans_present(am_node_t *cm)
{
	jipmi_msg_t req = { {0} };

	am_node_t *tz = node_lookup(cm, TZONE_NODE);
	tzone_data_t *tz_data = (tzone_data_t *)tz->priv_data;
	cm_data_t *cm_data = (cm_data_t *)cm->priv_data;
	func_tbl_t func = fn_tbl[cm_data->func_idx];

	if (func_not_ready(tz, tz_data->get_fans_present, func.once))
		goto next;

	FILL_INT(req.netfn,		IPMI_CM_NETFN);
	FILL_INT(req.cmd,		FAN_PRESENCE_CMD);
	FILL_STR(req.name,		am_rmcp_username);
	FILL_STR(req.password,	am_rmcp_password);
	FILL_INT(req.data_len,	0);

	tz_data->get_fans_present.expire = get_current_tick() + func.timeout;
	libjipmi_rmcp_cmd(cm_data->ip_address, IPMI_RMCP_PORT, &req, func.callback, tz, JIPMI_NON_SYNC);
	return;

next:
	process_next_func(cm);
	return;
}
示例#2
0
void set_tzone_pwm(am_node_t *cm)
{
	jipmi_msg_t req = { {0} };
	am_node_t *tzone = node_lookup(cm, TZONE_NODE);
	tzone_data_t *tzone_data = (tzone_data_t *)tzone->priv_data;
	cm_data_t *cm_data = (cm_data_t *)cm->priv_data;
	func_tbl_t func = fn_tbl[cm_data->func_idx];
	int32 tz_num = 1;

	if (func_not_ready(tzone, tzone_data->set_tzone_pwm, func.once))
		goto next;

	if (update_pwm_ready(tzone_data) == false)
		goto next;

	FILL_INT(req.netfn,		IPMI_CM_NETFN);
	FILL_INT(req.cmd,		SET_DEFAULT_PWM_CMD);
	FILL_STR(req.name,		am_rmcp_username);
	FILL_STR(req.password,	am_rmcp_password);
	FILL_INT(req.data_len,	2);
	req.data[0] = 0xff;
	req.data[1] = tzone_data->pwm[tz_num - 1];

	rmm_log(DBG, "set pwm is %d\n", tzone_data->pwm[0]);

	tzone_data->set_tzone_pwm.expire = get_current_tick() + func.timeout;
	libjipmi_rmcp_cmd(cm_data->ip_address, IPMI_RMCP_PORT, &req, func.callback, tzone, JIPMI_NON_SYNC);
	return;

next:
	process_next_func(cm);
	return;
}
示例#3
0
void *
data_lookup(struct hashtable *h, const char *string_to_lookup)
{
	struct hashnode *hn = NULL;
	void *r = NULL;
	unsigned int hv;  /* dummy - not used in this function */

	if (NULL != (hn = node_lookup(h, string_to_lookup, &hv)))
		r = hn->data;

	return r;
}
const char *
add_string(struct hashtable *h, const char *string)
{
	struct hashnode *n, *head;
	int bucket_index;
	unsigned int hv;

	if((n = node_lookup(h, string, &hv)))
		return n->string;

	bucket_index = MOD(hv, h->maxp);
	if (bucket_index < h->p)
		bucket_index = MOD(hv, (2*h->maxp));

	/* allocate new node */
	n = (struct hashnode *)malloc(sizeof(*n));

	/* fill in newly allocated node */
	n->value = hv;
	n->string_length = strlen(string);
	n->string = malloc(n->string_length+1);
	n->data = NULL;
	memcpy(n->string, string, n->string_length+1);

	/* add newly allocated node to appropriate chain */
	head = h->buckets[bucket_index];

	/* just push it on the chain */
	n->next = head->next;
	head->next = n;
	n->next->prev = n;
	n->prev = head;

	++h->buckets[bucket_index]->nodes_in_chain;

	++h->node_cnt;

	/* "load" on hashtable too high? */
	if (h->node_cnt/h->currentsize > h->maxload)
		rehash_hashtable(h);

	return n->string;
}
示例#5
0
void lookup_entry(struct fuse *fuse, struct node *node,
                  const char *name, __u64 unique)
{
    struct fuse_entry_out out;
    
    memset(&out, 0, sizeof(out));

    node = node_lookup(fuse, node, name, &out.attr);
    if (!node) {
        fuse_status(fuse, unique, -ENOENT);
        return;
    }
    
    node->refcount++;
//    fprintf(stderr,"ACQUIRE %p (%s) rc=%d\n", node, node->name, node->refcount);
    out.nodeid = node->nid;
    out.generation = node->gen;
    out.entry_valid = 10;
    out.attr_valid = 10;
    
    fuse_reply(fuse, unique, &out, sizeof(out));
}
示例#6
0
void get_fans_speed(am_node_t *cm)
{
	jipmi_msg_t req = { {0} };
	am_node_t *fans = node_lookup(cm, FANS_NODE);
	fans_data_t *fans_data = (fans_data_t *)fans->priv_data;
	cm_data_t *cm_data = (cm_data_t *)cm->priv_data;
	func_tbl_t func = fn_tbl[cm_data->func_idx];

	if (func_not_ready(fans, fans_data->get_fans_speed, func.once))
		goto next;

	FILL_INT(req.netfn,		IPMI_CM_NETFN);
	FILL_INT(req.cmd,		FAN_TACH_METER_CMD);
	FILL_STR(req.name,		am_rmcp_username);
	FILL_STR(req.password,	am_rmcp_password);
	FILL_INT(req.data_len,	0);
	fans_data->get_fans_speed.expire = get_current_tick() + func.timeout;
	libjipmi_rmcp_cmd(cm_data->ip_address, IPMI_RMCP_PORT, &req, func.callback, fans, JIPMI_NON_SYNC);
	return;

next:
	process_next_func(cm);
	return;
}
示例#7
0
static int trie_insert(struct trie *trie, struct trie_node *node, const char *search,
                       const char *key, const char *value) {
        size_t i = 0;
        int err = 0;

        for (;;) {
                size_t p;
                uint8_t c;
                struct trie_node *child;

                for (p = 0; (c = trie->strings->buf[node->prefix_off + p]); p++) {
                        _cleanup_free_ char *s = NULL;
                        ssize_t off;
                        _cleanup_free_ struct trie_node *new_child = NULL;

                        if (c == search[i + p])
                                continue;

                        /* split node */
                        new_child = calloc(sizeof(struct trie_node), 1);
                        if (!new_child)
                                return -ENOMEM;

                        /* move values from parent to child */
                        new_child->prefix_off = node->prefix_off + p+1;
                        new_child->children = node->children;
                        new_child->children_count = node->children_count;
                        new_child->values = node->values;
                        new_child->values_count = node->values_count;

                        /* update parent; use strdup() because the source gets realloc()d */
                        s = strndup(trie->strings->buf + node->prefix_off, p);
                        if (!s)
                                return -ENOMEM;

                        off = strbuf_add_string(trie->strings, s, p);
                        if (off < 0)
                                return off;

                        node->prefix_off = off;
                        node->children = NULL;
                        node->children_count = 0;
                        node->values = NULL;
                        node->values_count = 0;
                        err = node_add_child(trie, node, new_child, c);
                        if (err)
                                return err;

                        new_child = NULL; /* avoid cleanup */
                        break;
                }
                i += p;

                c = search[i];
                if (c == '\0')
                        return trie_node_add_value(trie, node, key, value);

                child = node_lookup(node, c);
                if (!child) {
                        ssize_t off;

                        /* new child */
                        child = calloc(sizeof(struct trie_node), 1);
                        if (!child)
                                return -ENOMEM;

                        off = strbuf_add_string(trie->strings, search + i+1, strlen(search + i+1));
                        if (off < 0) {
                                free(child);
                                return off;
                        }

                        child->prefix_off = off;
                        err = node_add_child(trie, node, child, c);
                        if (err) {
                                free(child);
                                return err;
                        }

                        return trie_node_add_value(trie, child, key, value);
                }

                node = child;
                i++;
        }
}
示例#8
0
void *
add_data(struct hashtable *h, const char *string, void *data)
{
	struct hashnode *n, *head;
	int bucket_index;
	unsigned int hv;
	int hash_mod;

	if((n = node_lookup(h, string, &hv)))
	{
		void *r = NULL;
		if (data)
		{
			r = (void *)n->data;
			n->data = data;
		} else {
			r = (void *)n->string;
		}
		return r;
	}

	bucket_index = MOD(hv, h->maxp);
	hash_mod = h->maxp;
	if (bucket_index < h->p)
	{
		bucket_index = MOD(hv, (2*h->maxp));
		hash_mod = 2*h->maxp;
	}

	if (h->flags > 1)
		printf("# \"%s\": hash value %u, base %d, bucket %d\n", string, hv, hash_mod, bucket_index);

	/* allocate new node */
	n = (struct hashnode *)malloc(sizeof(*n));

	/* fill in newly allocated node */
	n->value = hv;
	n->string_length = strlen(string);
	n->string = malloc(n->string_length+1);
	memcpy(n->string, string, n->string_length+1);
	n->data = data;

	/* add newly allocated node to appropriate chain */
	head = h->buckets[bucket_index];

	/* just push it on the chain */
	n->next = head->next;
	head->next = n;
	n->next->prev = n;
	n->prev = head;

	++h->buckets[bucket_index]->nodes_in_chain;

	++h->node_cnt;

	/* "load" on hashtable too high? */
	if (h->node_cnt/h->currentsize > h->maxload)
		rehash_hashtable(h);

	return (NULL == data)? (void *)n->string: NULL;
}
示例#9
0
/*! \brief Read list of group mapping.  If SID == 0 read the default group mapping
 *  from CONFIG_DIR/group/default else read the special mapping for node SID. 
 *  \return true on success
 *  \return false on fail*/
bool read_group_mapping(zfs_fh * group_dir, uint32_t sid)
{
	dir_op_res group_mapping_res;
	int32_t r;
	string node_name_;

	if (sid == 0)
	{
		node_name_.str = "default";
		node_name_.len = strlen("default");
	}
	else
	{
		node nod;

		nod = node_lookup(sid);
		if (!nod)
			return false;

		xstringdup(&node_name_, &nod->name);
		zfsd_mutex_unlock(&nod->mutex);
	}

	r = zfs_extended_lookup(&group_mapping_res, group_dir, node_name_.str);
	if (r != ZFS_OK)
	{
		if (sid != 0)
			free(node_name_.str);
		return true;
	}

	zfs_file * file = zfs_fopen(&group_mapping_res.file);
	if (file == NULL)
	{
		message(LOG_ERROR, FACILITY_CONFIG, "Failed to read shared group mapping.\n");
		return false;
	}

	config_t config;
	config_init(&config);
	int rv;
	rv =  config_read(&config, zfs_fdget(file));
	if (rv != CONFIG_TRUE)
	{
		message(LOG_ERROR, FACILITY_CONFIG, "Failed to parse shared group mapping.\n");
		zfs_fclose(file);
		return false;
	}

	varray groups_mappings;
	varray_create(&groups_mappings, sizeof(group_mapping), 4);

	rv = read_group_mapping_shared_config(&config, node_name_.str, &groups_mappings);
	if (rv != CONFIG_TRUE)
	{
		message(LOG_ERROR, FACILITY_CONFIG, "Failed to process shared group mapping.\n");
	}

	update_group_mappings(&groups_mappings, sid);

	varray_destroy(&groups_mappings);

	config_destroy(&config);
	zfs_fclose(file);

	if (sid != 0)
		free(node_name_.str);

	return (rv == CONFIG_TRUE);
}