Exemple #1
0
/**
 * @brief Release MD from NI.
 *
 * If this is the last reference to the MD destroy the object.
 *
 * @param md_handle the handle of the MD to release
 *
 * @return PTL_OK Indicates success.
 * @return PTL_NO_INIT Indicates that the portals API has not been
 * successfully initialized.
 * @return PTL_ARG_INVALID Indicates that an invalid argument was
 * passed. The definition of which arguments are checked is
 * implementation dependent.
 * @return PTL_IN_USE Indicates that md_handle has pending operations
 * and cannot be released.
 */
int _PtlMDRelease(PPEGBL ptl_handle_md_t md_handle)
{
    int err;
    md_t *md;

#ifndef NO_ARG_VALIDATION
    err = gbl_get();
    if (err)
        goto err0;

    md = to_md(MYGBL_ md_handle);
    if (!md) {
        err = PTL_ARG_INVALID;
        goto err1;
    }
#else
    md = to_obj(MYGBL_ POOL_ANY, md_handle);
#endif

    /* Ensure there is no in-flight transfer. */
    if (ref_cnt(&md->obj.obj_ref) > 2) {
        err = PTL_ARG_INVALID;
    } else {
        err = PTL_OK;
        md_put(md);
    }

    md_put(md);

#ifndef NO_ARG_VALIDATION
  err1:
    gbl_put();
  err0:
#endif

    return err;
}
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);
}
Exemple #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);
}
Exemple #4
0
static int init_file(char* path)
{
	/* initialize meta data for this file */
	int rt = 0;
	Meta_Data md;
	time_t t;
	bzero(&md,MD_SZ);
	t = time(NULL);
	md.atime = t;
	md.ctime = t;
	md.mtime = t;
	md.size = 0;
	md.dirty = MD_CLEAN;
	bzero(md.io_node_head,MAX_PATH);
	bzero(md.io_node_tail,MAX_PATH);
	if(md_put(path,&md) != 0){
		fprintf(stderr,"init file : md_put fail!\n");
		rt = 2;
	}
ret:
	return rt;
}
Exemple #5
0
/**
 * @brief Create a new MD and bind to NI.
 *
 * @param ni_handle
 * @param md_init
 * @param md_handle_p
 *
 * @return PTL_OK Indicates success.
 * @return PTL_NO_INIT Indicates that the portals API has not been
 * successfully initialized.
 * @return PTL_ARG_INVALID Indicates that an invalid argument was
 * passed. Argument checking is implementation dependent, but this
 * may indicate that an invalid ni_handle was used, an invalid event
 * queue was associated with the md, or other contents in the md
 * were illegal.
 * @return PTL_NO_SPACE Indicates that there is insufficient memory
 * to allocate the memory descriptor.
 */
int _PtlMDBind(PPEGBL ptl_handle_ni_t ni_handle, const ptl_md_t *md_init,
               ptl_handle_md_t *md_handle_p)
{
    int err;
    ni_t *ni;
    md_t *md;

#ifndef NO_ARG_VALIDATION
    err = gbl_get();
    if (err)
        goto err0;

    err = to_ni(MYGBL_ ni_handle, &ni);
    if (err)
        goto err1;

    if (!ni) {
        err = PTL_ARG_INVALID;
        goto err1;
    }

    if (md_init->options & ~PTL_MD_OPTIONS_MASK) {
        err = PTL_ARG_INVALID;
        goto err2;
    }

    if (md_init->options & PTL_IOVEC) {
        if (md_init->length > ni->limits.max_iovecs) {
            err = PTL_ARG_INVALID;
            goto err2;
        }
    }
#else
    ni = to_obj(MYGBL_ POOL_ANY, ni_handle);
#endif

    err = md_alloc(ni, &md);
    if (unlikely(err))
        goto err2;

    if (md_init->options & PTL_IOVEC) {
#if IS_PPE
        /* Lookup the IOVEC list. */
        err =
            mr_lookup_app(ni, md_init->start,
                          md_init->length * sizeof(ptl_iovec_t),
                          &md->ppe.mr_start);
        if (err)
            goto err3;

        /* start from the client has no further use. */
        md->start = addr_to_ppe(md_init->start, md->ppe.mr_start);
#else
        md->start = md_init->start;
#endif

        err = init_iovec(md, (ptl_iovec_t *)md->start, md_init->length);
        if (err)
            goto err3;
    } else {
        md->start = md_init->start;
        md->length = md_init->length;
        md->num_iov = 0;
    }

#ifndef NO_ARG_VALIDATION
    err = to_eq(MYGBL_ md_init->eq_handle, &md->eq);
    if (err)
        goto err3;

    if (md->eq && (obj_to_ni(md->eq) != ni)) {
        err = PTL_ARG_INVALID;
        goto err3;
    }

    err = to_ct(MYGBL_ md_init->ct_handle, &md->ct);
    if (err)
        goto err3;

    if (md->ct && (obj_to_ni(md->ct) != ni)) {
        err = PTL_ARG_INVALID;
        goto err3;
    }
#else
    md->eq =
        (md_init->eq_handle != PTL_EQ_NONE) ? to_obj(MYGBL_ POOL_ANY,
                                                     md_init->eq_handle) :
        NULL;
    md->ct =
        (md_init->ct_handle != PTL_CT_NONE) ? to_obj(MYGBL_ POOL_ANY,
                                                     md_init->ct_handle) :
        NULL;
#endif

    md->options = md_init->options;

    /* account for the number of MDs allocated */
    if (unlikely
        (__sync_add_and_fetch(&ni->current.max_mds, 1) >
         ni->limits.max_mds)) {
        (void)__sync_sub_and_fetch(&ni->current.max_mds, 1);
        err = PTL_NO_SPACE;
        goto err3;
    }

    *md_handle_p = md_to_handle(md);

    ni_put(ni);
#ifndef NO_ARG_VALIDATION
    gbl_put();
#endif
    return PTL_OK;

  err3:
    md_put(md);
  err2:
    ni_put(ni);
#ifndef NO_ARG_VALIDATION
  err1:
    gbl_put();
  err0:
#endif
    return err;
}
Exemple #6
0
//cache file
int PutInCacheFile(char *fileName,char *xmlFileName)
{
    FILE *fp;
    if ((fp=fopen(fileName,"w"))==NULL)
    {
        printf("cannot open file\n");
        exit(0);
    }
    xmlDocPtr doc; // djf定义解析文档指针
    xmlNodePtr rootNode,bucNode,objNode;//定义节点指针(在各个节点之间移动)

    char *szDocName;
    szDocName = (char *)xmlFileName;
    doc = xmlReadFile(szDocName,"GB2312",XML_PARSE_RECOVER);
    if (doc == NULL)
    {
        printf("document not parsed successfully");
        return -1;
    }

    //确定文档根元素
    rootNode = xmlDocGetRootElement(doc);
    if (rootNode == NULL)
    {
        printf("empty document");
        xmlFreeDoc(doc);
        return -1;
    }

    //curNode=curNode->xmlChildrenNode;
    bucNode = rootNode->children;
    printf("--------------------------------\n");
    while (bucNode != NULL) //打印第一层节点
    {
        objNode = bucNode->children;
        while (objNode!=NULL)//打印第二层节点
        {
            unsigned char temp[50];
            strcpy(temp,rootNode->name);
            strcat(temp,"/");
            strcat(temp,bucNode->name);
            strcat(temp,"/");
            strcat(temp,objNode->name);
            int len = strlen(temp);

            //生成md5值
            unsigned char md5sum[16]={0};
            unsigned char md5_str[33]={0};
            md5(temp,len,md5sum);
            md5_2_str(md5sum,md5_str);

                //生成value值
            Meta_Data *metaData = (Meta_Data *)malloc(sizeof(Meta_Data));
            Meta_Data *meta1 = (Meta_Data *)malloc(sizeof(Meta_Data));
            strcpy(metaData->replica[0].rep_ip,"192.168.0.18");

            md_put(md5_str,metaData);
                GetValue(md5_str,meta1);
            printf("the value  is %s\n",meta1->replica[0].rep_ip);
            //printf("%s\t%s\n",temp,md5_str);
            fprintf(fp,"%s\t%s\t%s\n",temp,md5_str,meta1->replica[0].rep_ip);
            // PutValue(temp,md5_str);

            objNode=objNode->next;
        }

        bucNode = bucNode->next;
    }
    xmlFreeDoc(doc);
    fclose(fp);


}