Exemplo n.º 1
0
static int
vnex_attach(device_t dev)
{
    struct vnex_devinfo  *vndi;
    struct vnex_softc    *sc;
    device_t              cdev;
    phandle_t             node;
    mde_cookie_t          rootnode, *listp = NULL;
    int                   i, listsz, num_nodes, num_devices;
    md_t                 *mdp;


    node = ofw_bus_get_node(dev);
    if (node == -1)
        panic("%s: ofw_bus_get_node failed.", __func__);

    sc = device_get_softc(dev);
    sc->sc_intr_rman.rm_type = RMAN_ARRAY;
    sc->sc_intr_rman.rm_descr = "Interrupts";
    sc->sc_mem_rman.rm_type = RMAN_ARRAY;
    sc->sc_mem_rman.rm_descr = "Device Memory";
    if (rman_init(&sc->sc_intr_rman) != 0 ||
            rman_init(&sc->sc_mem_rman) != 0 ||
            rman_manage_region(&sc->sc_intr_rman, 0, IV_MAX - 1) != 0 ||
            rman_manage_region(&sc->sc_mem_rman, 0ULL, ~0ULL) != 0)
        panic("%s: failed to set up rmans.", __func__);

    if ((mdp = md_get()) == NULL)
        return (ENXIO);

    num_nodes = md_node_count(mdp);
    listsz = num_nodes * sizeof(mde_cookie_t);
    listp = (mde_cookie_t *)malloc(listsz, M_DEVBUF, M_WAITOK);
    rootnode = md_root_node(mdp);

    /*
     * scan the machine description for virtual devices
     */
    num_devices = md_scan_dag(mdp, rootnode,
                              md_find_name(mdp, "virtual-device"),
                              md_find_name(mdp, "fwd"), listp);

    for (i = 0; i < num_devices; i++) {
        if ((vndi = vnex_setup_dinfo(dev, listp[i])) == NULL)
            continue;

        cdev = device_add_child(dev, NULL, -1);
        if (cdev == NULL) {
            device_printf(dev, "<%s>: device_add_child failed\n",
                          vndi->vndi_mbdinfo.mbd_name);
            vnex_destroy_dinfo(vndi);
            continue;
        }
        device_set_ivars(cdev, vndi);
    }
    bus_generic_attach(dev);
    free(listp, M_DEVBUF);

    return (0);
}
int
md_vdev_find_node(device_t dev, mde_cookie_t *valp)
{
	uint64_t              cfg_handle;
	mde_cookie_t          rootnode, node, *listp = NULL;
	int                   i, listsz, num_nodes, num_devices, error;
	md_t                 *mdp;

	cfg_handle = mdesc_bus_get_handle(dev);

	error = EINVAL;

	if ((mdp = md_get()) == NULL) 
		return (ENXIO);

	num_nodes = md_node_count(mdp);
	listsz = num_nodes * sizeof(mde_cookie_t);
	listp = (mde_cookie_t *)malloc(listsz, M_DEVBUF, M_WAITOK);
	rootnode = md_root_node(mdp);
	node = error = 0;

	num_devices = md_scan_dag(mdp, rootnode, 
				  md_find_name(mdp, "virtual-device"),
				  md_find_name(mdp, "fwd"), listp);
	
	if (num_devices == 0) {
		error = ENOENT;
		goto done;
	}
		
	for (i = 0; i < num_devices; i++) {
		uint64_t thandle;

		node = listp[i];
		md_get_prop_val(mdp, node, "cfg-handle", &thandle);
		if (thandle == cfg_handle) {
			*valp = node;
			break;
		}
	}

done:
	md_put(mdp);

	return (error);
}
Exemplo n.º 3
0
int
mdesc_bus_gen_setup_devinfo(struct mdesc_bus_devinfo *mbd, mde_cookie_t node)
{
	md_t *mdp;
	
        if (mbd == NULL)
                return (ENOMEM);
	
	mdp = md_get();
	
        /* The 'name' property is considered mandatory. */
        if ((md_get_prop_alloc(mdp, node, "name", MDET_PROP_STR, (uint8_t **)&mbd->mbd_name)) == -1)
                return (EINVAL);
        md_get_prop_alloc(mdp, node, "compatible", MDET_PROP_DAT, (uint8_t **)&mbd->mbd_compat);
        md_get_prop_alloc(mdp, node, "device-type", MDET_PROP_STR, (uint8_t **)&mbd->mbd_type);
        md_get_prop_val(mdp, node, "cfg-handle", &mbd->mbd_handle);

	md_put(mdp);
        return (0);
}
Exemplo n.º 4
0
static int de_init_file(char *path)
{
	/* called when delete a file 
	 * 1) delete all the io_nodes and io_data of this file 
	 * 2) delete meta data of this file 
	 * 3) as for file_node,just leave it alone,
	 * so every time before updating file according file node list,
	 * check if this file still exist. 
	 * So here no strong consitency is ensured,just handle it. */
	int rt = 0;
	int len;
	char ionp[MAX_ION_PATH];
	Meta_Data md;
	IO_Node ion;
	if(md_get(path,&md) != 0){
		rt = 1;
		goto ret;
	}
	if(md.dirty == MD_CLEAN){
		goto del_md;
	}
	len = strlen(md.io_node_head);
	strncpy(ionp,md.io_node_head,len);
	while(len != 0){
		/* delete io_node and io_data */
		ion_get(ionp,&ion);
		ion_out(ionp);
		iod_out(ionp);
		len = strlen(ion.next);
		strncpy(ionp,ion.next,len);
	}
	/* delete meta data */
del_md:
	md_out(path);
ret:
	return rt;
}
Exemplo n.º 5
0
Arquivo: xml.c Projeto: b409/b409
int list_buckets_objects(user_dir_t * user,char * xml_file,const char gu_flag)
{
	int rt = 0;
	struct list_head * l,*x;
	bucket_t * bucket;
	object_t * object;
	xmlDocPtr doc = NULL;
	xmlNodePtr root_node = NULL,bnode,onode;
	Meta_Data md;
	char full_path[MAX_PATH];
	char md5c[MD5_CHECKSUM_SZ];
	char md5s[MD5_STRING_LEN];
	int full_path_len;
	if(!(GU_FLAG_VALID(gu_flag))){
		fprintf(stderr,"invalid get_user flag!\n");
		return 1;
	}
	doc = xmlNewDoc(BAD_CAST "1.0");
	root_node = xmlNewNode(NULL,BAD_CAST *(user->user_name));
	xmlDocSetRootElement(doc,root_node);
	if(pthread_mutex_lock(&user->mutex) != 0){
		perror("list_buckets_objects : pthread_mutex_lock u->mutex");
		rt = 2;
		goto ret;
	}
	if(list_empty(&user->buckets)){
		goto unlock_and_ret;
	}
	for_each_bucket(l,user){
		bucket = container_of(l,bucket_t,b_list);
		bnode = xmlNewChild(root_node,NULL,BAD_CAST *(bucket->bucket_name),BAD_CAST buf_null);
		if(gu_flag == GU_LIST_BUCKETS){
			continue;
		}
		if(pthread_mutex_lock(&bucket->mutex) != 0){
			fprintf(stderr,"lock bucket->mutex fail!\n");
			rt = 3;
			goto unlock_and_ret;
		}
		if(list_empty(&bucket->objects)){
			goto unlock_and_continue;
		}
		for_each_object(x,bucket){
			object = container_of(x,object_t,o_list);
			onode = xmlNewChild(bnode,NULL,BAD_CAST *(object->object_name),BAD_CAST buf_null);
			get_absolute_path_of_object(object,full_path);
			full_path_len = strlen(full_path);
			md5(full_path,full_path_len,md5c);
			bzero(md5s,MD5_STRING_LEN);
			md5_2_str(md5c,md5s);
			/* md5 string now in md5s */
			if(md_get(md5s,&md) != 0){
				continue;
			}
			xmlNewChild(onode,NULL,BAD_CAST O_XML_HASH,BAD_CAST md5s);
			u32_to_str(md.atime,buf,BUFSIZ);
			xmlNewChild(onode,NULL,BAD_CAST O_XML_ATIME,BAD_CAST buf);
			u32_to_str(md.mtime,buf,BUFSIZ);
			xmlNewChild(onode,NULL,BAD_CAST O_XML_MTIME,BAD_CAST buf);
			u32_to_str(md.ctime,buf,BUFSIZ);
			xmlNewChild(onode,NULL,BAD_CAST O_XML_CTIME,BAD_CAST buf);
			u64_to_str(md.size,buf,BUFSIZ);
			xmlNewChild(onode,NULL,BAD_CAST O_XML_SIZE,BAD_CAST buf);
			xmlNewChild(onode,NULL,BAD_CAST O_XML_IP,BAD_CAST md.replica[0].rep_ip);
		}