Exemple #1
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 #2
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 #3
0
int client_realeasedir(DIR_INFO *dirinfo)
{
    pthread_mutex_destroy(&(dirinfo->dir_lock));
    if(dirinfo->p != NULL)
        def_free(dirinfo->p);
    def_free(dirinfo);
    
    dirinfo = NULL;
    return 0;
}
Exemple #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
0
int  rpc_result_check(int rpc_ret, char *outbuf, int outbuflen)
{
    int ret = STATUS_OK;
    if(rpc_ret != STATUS_OK)
        ret = EIO;
        
    if(outbuflen == 4)
    {
        const uint8_t * retbuf = (const uint8_t *) outbuf;
        ret = get32bit(&retbuf);
    }
    else
    {
        ret = EIO;
    }
    if(outbuf)
        def_free(outbuf);
    return ret;
}
Exemple #11
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 #12
0
void *client_hb_thread(void *p)
{
    client_hb_net_t *p_cn_client = (client_hb_net_t *)p;
    int ret = 0;
    pthread_t  threadid = pthread_self();
    pthread_detach(threadid);
    
    while(1)
    {    
        if(p_cn_client->heartbeat_para.thread_status == state_stop)
        {
            p_cn_client->heartbeat_para.thread_status = state_stoped;
            //return NULL;
        }
        
        if(p_cn_client->heartbeat_send_fun)
        {
            char *sendbuf, *in_buf;
            int  iSendbufLen, iOutLength;
            
            ret = p_cn_client->heartbeat_send_fun(&sendbuf, &iSendbufLen);
            if(ret == 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,
                                            sendbuf, iSendbufLen, &in_buf, &iOutLength);
                def_free(sendbuf);
                
                if(ret == 0 && p_cn_client->heartbeat_recv_fun)
                {
                    p_cn_client->heartbeat_recv_fun(in_buf, iOutLength);
                }   
            }
        }
        
        sleep(p_cn_client->gap_time);
    }

}
Exemple #13
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;
}
Exemple #14
0
void
nvlist_free(nvlist_t *nvl)
{
    def_free(nvl);
}