Exemple #1
0
/*---------------------------------------------------------------------*/
int client_mknod(char szmac[12], uint64_t parent, uint8_t nleng, const uint8_t *name, uint8_t type, 
             uint32_t mode, uint32_t uid, uint32_t gid, uint32_t rdev,
             uint64_t *inode, uint8_t attr[FILE_ATTR_LEN], uint8_t **dslist, uint32_t *dslistlen)
{            
    int iSendLeng = 8 + 38 + nleng;
    uint8_t *szCommand = (uint8_t *)def_calloc(iSendLeng, sizeof(char));
    char *curr = (char *)szCommand;
    put32bit(&szCommand, CLTODI_FUSE_MKNOD);
    put32bit(&szCommand, 38 + nleng);
    
    memcpy(szCommand, szmac, 12);
    szCommand += 12;
    put64bit(&szCommand, parent);
    put8bit(&szCommand, nleng);
    memcpy(szCommand, name, nleng);
    szCommand += nleng;
    put8bit(&szCommand, type);
    put32bit(&szCommand, mode);
    put32bit(&szCommand, uid);
    put32bit(&szCommand, gid);
    put32bit(&szCommand, rdev);
    
    char *szOutBuf = NULL;
    int iOutLength = 0;

    int ret = net_client_rpc(p_cn_client->p_client,
                            p_cn_client->namenode_info[0].namenode_ip,
                            p_cn_client->namenode_info[0].namenode_port,
                            curr, iSendLeng, &szOutBuf, &iOutLength);
    def_free(curr);
    if (ret != 0)
    {
        if(szOutBuf)
            def_free(szOutBuf);
        ret =  EIO;
    }
    else
    {
        if (iOutLength == 4) 
        {
            const uint8_t * result = (const uint8_t *) szOutBuf;
            ret = get32bit(&result);
        } 
        else 
        {
            uint8_t *out = (uint8_t *) szOutBuf;
            uint64_t t64 = get64bit((const uint8_t **)&out);
            *inode = t64;
            memcpy(attr, out, FILE_ATTR_LEN);
            out += FILE_ATTR_LEN;
            *dslistlen = iOutLength - 8 - FILE_ATTR_LEN;
            *dslist = def_calloc(*dslistlen, sizeof(char));
            memcpy(*dslist, out, *dslistlen);
            ret = STATUS_OK;
        }
        def_free(szOutBuf);
    }
    
    return ret;
}
Exemple #2
0
fmd_event_t *
fmd_create_ereport(fmd_t *pfmd, const char *eclass, char *id, nvlist_t *p_nvl)
{
    fmd_event_t *pevt = NULL;
    pevt = (fmd_event_t *)def_calloc(sizeof(fmd_event_t), 1);

	pevt->dev_name = strdup(p_nvl->name);
	pevt->dev_id = p_nvl->dev_id;
	pevt->evt_id = p_nvl->evt_id;
	
    pevt->ev_create = time(NULL);
    pevt->ev_class = strdup(eclass);
    pevt->data = p_nvl->data;

	/* added for test by guanhj : todo every src module */
	pevt->repaired_N = REPAIRED_N;
	pevt->repaired_T = REPAIRED_T; // 2 min

    list_del(&p_nvl->nvlist);
    //def_free(p_nvl->data);
    def_free(p_nvl);

    //wanghuan 
    INIT_LIST_HEAD(&pevt->ev_list);
    return pevt;
}
Exemple #3
0
int client_unlink(uint64_t parent, uint32_t nleng, const uint8_t* name, uint32_t uid, uint32_t gid)
{
    int iSendLeng = 8 + 20 + nleng ;
    uint8_t *szCommand = (uint8_t *)def_calloc(iSendLeng, sizeof(uint8_t));
    char *curr = (char *)szCommand;
    put32bit(&szCommand, CLTODI_UNLINK);
    put32bit(&szCommand, 20 + nleng);
        
    put64bit(&szCommand, parent);
    put32bit(&szCommand, uid);
    put32bit(&szCommand, gid);
    put32bit(&szCommand, nleng);
    memcpy(szCommand, name, nleng);
    
    char *szOutBuf = NULL;
    int iOutLength = 0;
    int ret = net_client_rpc(p_cn_client->p_client,
                            p_cn_client->namenode_info[0].namenode_ip,
                            p_cn_client->namenode_info[0].namenode_port,
                            curr, iSendLeng, &szOutBuf, &iOutLength);
    
    def_free(curr);
    
    int ret2 = rpc_result_check(ret, szOutBuf, iOutLength);     
    return ret2;
}
Exemple #4
0
int start_hb_thread(client_net_t *p_net, char *nn_ip, uint32_t nn_port,
                        int time_gap, hb_send_data send_fun, hb_recv_callback recv_fun)
{

    p_hb_client = def_calloc(1,sizeof(client_cn_net_t));
    p_hb_client->namenode_info[0].namenode_ip = nn_ip;
    p_hb_client->namenode_info[0].namenode_port = nn_port;
    p_hb_client->p_client = p_net;
    
    p_hb_client->gap_time = time_gap;
    
    p_hb_client->heartbeat_send_fun = send_fun;
    p_hb_client->heartbeat_recv_fun = recv_fun;

    /*
    int ret = pthread_create(&p_cn_client->heartbeat_para.thread_id, NULL,
                                        &client_hb_thread, (void *)p_cn_client);
    if(ret != 0)
    {
        nb_log("hb thread", NB_LOG_ERROR, "create hb thread is error.");
        return -1;
    }
    */

    p_hb_client->heartbeat_para.thread_status = state_running;
    
    return 0;
}
Exemple #5
0
int client_statfs(struct statvfs *outstat)
{
    int iSendLeng = 8 ;
    uint8_t *szCommand = (uint8_t *)def_calloc(iSendLeng, sizeof(char));
    char *curr = (char *)szCommand;
    put32bit(&szCommand, CLTODI_STATFS);
    put32bit(&szCommand, 0);
    
    char *szOutBuf = NULL ;
    int iOutLength = 0;

    int ret = net_client_rpc(p_cn_client->p_client,
                            p_cn_client->namenode_info[0].namenode_ip,
                            p_cn_client->namenode_info[0].namenode_port,
                            curr, iSendLeng, &szOutBuf, &iOutLength);

    def_free(curr);
    if (ret != 0)
    {  
        if(szOutBuf)
            def_free(szOutBuf);
        return EIO;
    }
    else
    {
        // 解析数据
        buf_to_statvfs((const uint8_t *)szOutBuf, iOutLength, outstat);
    
        def_free (szOutBuf);
        return STATUS_OK;
    }
}
Exemple #6
0
nvlist_t *nvlist_alloc()
{
    nvlist_t *p_nvl = NULL;

    p_nvl = (nvlist_t *)def_calloc(1, sizeof(nvlist_t));
    p_nvl->data = NULL;
    //INIT_LIST_HEAD(&p_nvl->nvlist);

    return p_nvl;
}
Exemple #7
0
struct list_head *
nvlist_head_alloc(void)
{
    struct list_head *head = NULL;

    head = (struct list_head *)def_calloc(1, sizeof(struct list_head));
    INIT_LIST_HEAD(head);

    return head;
}
Exemple #8
0
int client_lookup(uint64_t parent, uint8_t nleng, const uint8_t *name, uint32_t uid, uint32_t gid,
              uint64_t *inode, uint8_t attr[FILE_ATTR_LEN]) 
{

    int iSendLeng = 8 + 20 + nleng;
    uint8_t *szCommand = (uint8_t *)def_calloc(iSendLeng, sizeof(char));
    char *curr = (char *)szCommand;
    put32bit(&szCommand, CLTODI_FUSE_LOOKUP);
    put32bit(&szCommand, 20 + nleng);
    
    put64bit(&szCommand, parent);
    put32bit(&szCommand, nleng);
    memcpy(szCommand, name, nleng);
    szCommand += nleng;
    put32bit(&szCommand, uid);
    put32bit(&szCommand, gid);
    
    char *szOutBuf = NULL;
    int iOutLength = 0;
    int ret = net_client_rpc(p_cn_client->p_client,
                            p_cn_client->namenode_info[0].namenode_ip,
                            p_cn_client->namenode_info[0].namenode_port,
                            curr, iSendLeng,  &szOutBuf, &iOutLength);
    def_free(curr);
    if (ret != 0)
    {   
        nb_log("client lookup", NB_LOG_ERROR, "nn --->cli rpc is error.");
        if(szOutBuf)
            def_free(szOutBuf);
        ret =  EIO;
    }
    else
    {
        if(iOutLength == 4)
        {
            const uint8_t * result = (const uint8_t *) szOutBuf;
            ret = get32bit(&result);
        }
        else if (iOutLength != FILE_ATTR_LEN + 8)
        {   
            ret = EIO;
        }
        else
        {
            const uint8_t *out = (const uint8_t *) szOutBuf;
            *inode = get64bit(&out);
            memcpy(attr, out, FILE_ATTR_LEN);
            ret = STATUS_OK;
        }
        
        def_free(szOutBuf);   
    }
    
    return ret;
}
Exemple #9
0
int fs_setattr(uint8_t *parm, uint32_t parmlen, uint8_t attr[FILE_ATTR_LEN]) 
{
    int iSendLeng = 8 + parmlen;
    uint8_t *szCommand = (uint8_t *)def_calloc(iSendLeng, sizeof(char));
    char *curr = (char *)szCommand;
    put32bit(&szCommand, CLTODI_FUSE_SETATTR);
    put32bit(&szCommand, parmlen);
    if(parmlen > 0)
        memcpy(szCommand, parm, parmlen);

    char *szOutBuf = NULL;
    int iOutLength = 0;
    int ret = net_client_rpc(p_cn_client->p_client,
                            p_cn_client->namenode_info[0].namenode_ip,
                            p_cn_client->namenode_info[0].namenode_port,
                            curr, iSendLeng, &szOutBuf, &iOutLength);
    def_free(curr);
    if (ret != 0)
    {
        if(szOutBuf)
            def_free(szOutBuf);
        ret =  EIO;
    }
    else
    {
        if (iOutLength == 4) 
        {
            const uint8_t * result = (const uint8_t *) szOutBuf;
            ret = get32bit(&result);
        } 
        else if (iOutLength != FILE_ATTR_LEN) 
        {
            ret = EIO;
        }
        else 
        {
            memcpy(attr, szOutBuf, FILE_ATTR_LEN);
            ret = STATUS_OK;
        }
        def_free(szOutBuf);
    }
    
    return ret;
}
Exemple #10
0
static int hb_send_data_fun(char **buf, int *ibufLeng)
{
    char szHostname[300] = {0};
    gethostname(szHostname, sizeof(szHostname));
    int hostlen = strlen(szHostname);

    uint8_t *outbuf = (uint8_t *)def_calloc(8 + 4 + hostlen, sizeof(uint8_t));
    uint8_t *buf_ori = outbuf;
    *ibufLeng = 8 + 4 + hostlen;
    put32bit(&outbuf, CLTODI_HEARTBEAT);
    put32bit(&outbuf, 0);

    put32bit(&outbuf, hostlen);
    memcpy(outbuf, szHostname, hostlen);
    outbuf += hostlen;

    *buf = (char *)buf_ori;
    return 0;
}
Exemple #11
0
int client_opendir(uint64_t inode, uint32_t uid, uint32_t gid, DIR_INFO **outdirinfo)
{

/*
    check check and return .
    int status = fs_access(inode, uid, gid, MODE_MASK_R);
    if (status != 0) 
        return status;
*/    
    DIR_INFO *dirinfo = def_calloc(1, sizeof(DIR_INFO));
    pthread_mutex_init(&(dirinfo->dir_lock),NULL);
    pthread_mutex_lock(&(dirinfo->dir_lock));
    dirinfo->p = NULL;
    dirinfo->size = 0;
    dirinfo->dcache = NULL;
    dirinfo->wasread = 0;
    pthread_mutex_unlock(&(dirinfo->dir_lock));    
    *outdirinfo = dirinfo;
    return 0;
}
Exemple #12
0
// 获取dslist 列表
int client_get_dslist(char szmac[12], uint64_t inode, uint8_t **szOutBuf, uint32_t *iOutLength)
{
    int iSendLeng = 8 + 12 + 8 ;
    uint8_t *szCommand = (uint8_t *)def_calloc(iSendLeng, sizeof(char));

    char *curr = (char *)szCommand;
    put32bit(&szCommand, CLTODI_GET_DSLIST);
    put32bit(&szCommand, 12 + 8 );

    memcpy(szCommand, szmac, 12);
    szCommand += 12;
    put64bit(&szCommand, inode);

    int ret = net_client_rpc(p_cn_client->p_client,
                            p_cn_client->namenode_info[0].namenode_ip,
                            p_cn_client->namenode_info[0].namenode_port,
                            curr, iSendLeng, (char **)&szOutBuf, &iOutLength);
    def_free(curr);

    return ret;
}
Exemple #13
0
int client_readdir(uint64_t inode,uint32_t uid,uint32_t gid,const uint8_t **retbuff,uint32_t *retbuffsize)
{    
    *retbuffsize = 0;
    int ret = 0;
    int iSendLeng = 8 + 16;
    uint8_t *szCommand = (uint8_t *)def_calloc(iSendLeng, sizeof(char));
    char *curr = (char *)szCommand;
    put32bit(&szCommand, CLTODI_FUSE_GETDIR);
    put32bit(&szCommand, 16);
    
    put64bit(&szCommand,inode);
    put32bit(&szCommand,uid);
    put32bit(&szCommand,gid);
    
    char *szOutBuf = NULL;
    int iOutLength = 0;
    ret = net_client_rpc(p_cn_client->p_client,
                            p_cn_client->namenode_info[0].namenode_ip,
                            p_cn_client->namenode_info[0].namenode_port,
                            curr, iSendLeng, &szOutBuf, &iOutLength);

    
    def_free(curr);
    
    if (ret != 0 || iOutLength <= 4) 
    {   
        if(szOutBuf)
            def_free(szOutBuf);
        ret = EIO;
    }
    else
    {
        *retbuff = (uint8_t *)szOutBuf;
        *retbuffsize = iOutLength;
        ret = STATUS_OK;
    }
    
    return ret;
}
Exemple #14
0
/*
*  prototcol 
*  prototcol num(4) + len(4) + inode(8) +
*  16  protocol =  num + len + inode
*  uid(4) + gid(4)
*
*/
int client_getattr(uint64_t inode,uint32_t uid,uint32_t gid,
                                    char attr[FILE_ATTR_LEN]) 
{    
    //packet header len 24
    int ret = 0;
    int send_len = 4+4+8+4+4;
    uint8_t *command = (uint8_t *)def_calloc(send_len, sizeof(char));
    char *curr = (char *)command;
    put32bit(&command, CLTODI_FUSE_GETATTR);// (4)
    // 16  data length
    put32bit(&command, 16); //(4)
    
    put64bit(&command,inode);
    put32bit(&command,uid);
    put32bit(&command,gid);
         
    char *szOutBuf = NULL;
    int iOutLength = 0;

    ret = net_client_rpc(p_cn_client->p_client,
                            p_cn_client->namenode_info[0].namenode_ip,
                            p_cn_client->namenode_info[0].namenode_port,
                            curr, send_len, &szOutBuf, &iOutLength);
    
    def_free(curr);
    if (ret != 0 || iOutLength != FILE_ATTR_LEN)
    {
        if(szOutBuf)
            def_free(szOutBuf);
        return EIO;
    }
    else
    {
        memcpy(attr, szOutBuf, FILE_ATTR_LEN);
        def_free(szOutBuf);
        return STATUS_OK;
    }
}
Exemple #15
0
fmd_event_t *
fmd_create_listevent(fmd_event_t *pevt, int action)
{
    char eclass[128] = {0};
    char *p;
    fmd_event_t *listevt = def_calloc(sizeof(fmd_event_t), 1);

    p = strchr(pevt->ev_class, '.');
    sprintf(eclass, "list%s", p);

    listevt->dev_name = strdup(pevt->dev_name);
    listevt->ev_create = time(NULL);
    listevt->ev_class = strdup(eclass);
    listevt->agent_result = action;
	listevt->dev_id = pevt->dev_id;
	listevt->evt_id = pevt->evt_id;
	listevt->repaired_N = pevt->repaired_N;
	listevt->repaired_T = pevt->repaired_T;
	listevt->ev_refs = pevt->ev_refs;
    listevt->data = pevt->data;

    return listevt;
}
Exemple #16
0
int client_open(char szmac[12], uint64_t inode, int open_flag, char **szOutBuf, uint32_t *iOutLength)
{
    int iSendLeng = 8 + 12 + 8 + 4 ;
    uint8_t *szCommand = (uint8_t *)def_calloc(iSendLeng, sizeof(char));
    
    char *curr = (char *)szCommand;
    put32bit(&szCommand, CLTODI_OPEN);
    put32bit(&szCommand, 12 + 8 + 4);
    
    memcpy(szCommand, szmac, 12);
    szCommand += 12;
    
    put64bit(&szCommand, inode);
    put32bit(&szCommand, open_flag);
    int ret = net_client_rpc(p_cn_client->p_client,
                            p_cn_client->namenode_info[0].namenode_ip,
                            p_cn_client->namenode_info[0].namenode_port,
                            curr, iSendLeng, &szOutBuf, &iOutLength);
    
    def_free(curr);
  
    return ret;
}