static int do_sd_create(char *filename, int64_t vdi_size,

                        uint32_t base_vid, uint32_t *vdi_id, int snapshot,

                        const char *addr, const char *port)

{

    SheepdogVdiReq hdr;

    SheepdogVdiRsp *rsp = (SheepdogVdiRsp *)&hdr;

    int fd, ret;

    unsigned int wlen, rlen = 0;

    char buf[SD_MAX_VDI_LEN];



    fd = connect_to_sdog(addr, port);

    if (fd < 0) {

        return fd;

    }



    memset(buf, 0, sizeof(buf));

    strncpy(buf, filename, SD_MAX_VDI_LEN);



    memset(&hdr, 0, sizeof(hdr));

    hdr.opcode = SD_OP_NEW_VDI;

    hdr.base_vdi_id = base_vid;



    wlen = SD_MAX_VDI_LEN;



    hdr.flags = SD_FLAG_CMD_WRITE;

    hdr.snapid = snapshot;



    hdr.data_length = wlen;

    hdr.vdi_size = vdi_size;



    ret = do_req(fd, (SheepdogReq *)&hdr, buf, &wlen, &rlen);



    closesocket(fd);



    if (ret) {

        return ret;

    }



    if (rsp->result != SD_RES_SUCCESS) {

        error_report("%s, %s", sd_strerror(rsp->result), filename);

        return -EIO;

    }



    if (vdi_id) {

        *vdi_id = rsp->vdi_id;

    }



    return 0;

}

static int do_sd_create(char *filename, int64_t vdi_size,

                        uint32_t base_vid, uint32_t *vdi_id, int snapshot,

                        const char *addr, const char *port)

{

    SheepdogVdiReq hdr;

    SheepdogVdiRsp *rsp = (SheepdogVdiRsp *)&hdr;

    int fd, ret;

    unsigned int wlen, rlen = 0;

    char buf[SD_MAX_VDI_LEN];



    fd = connect_to_sdog(addr, port);

    if (fd < 0) {

        return fd;

    }



    memset(buf, 0, sizeof(buf));

    strncpy(buf, filename, SD_MAX_VDI_LEN);



    memset(&hdr, 0, sizeof(hdr));

    hdr.opcode = SD_OP_NEW_VDI;

    hdr.base_vdi_id = base_vid;



    wlen = SD_MAX_VDI_LEN;



    hdr.flags = SD_FLAG_CMD_WRITE;

    hdr.snapid = snapshot;



    hdr.data_length = wlen;

    hdr.vdi_size = vdi_size;



    ret = do_req(fd, (SheepdogReq *)&hdr, buf, &wlen, &rlen);



    closesocket(fd);



    if (ret) {

        return ret;

    }



    if (rsp->result != SD_RES_SUCCESS) {

        error_report("%s, %s", sd_strerror(rsp->result), filename);

        return -EIO;

    }



    if (vdi_id) {

        *vdi_id = rsp->vdi_id;

    }



    return 0;

}

    memset(buf, 0, sizeof(buf));     strncpy(buf, filename, SD_MAX_VDI_LEN);
static int FUNC_0(char *VAR_0, int64_t VAR_1,

                        uint32_t VAR_2, uint32_t *VAR_3, int VAR_4,

                        const char *VAR_5, const char *VAR_6)

{

    SheepdogVdiReq hdr;

    SheepdogVdiRsp *rsp = (SheepdogVdiRsp *)&hdr;

    int VAR_7, VAR_8;

    unsigned int VAR_9, VAR_10 = 0;

    char VAR_11[SD_MAX_VDI_LEN];



    VAR_7 = connect_to_sdog(VAR_5, VAR_6);

    if (VAR_7 < 0) {

        return VAR_7;

    }



    memset(VAR_11, 0, sizeof(VAR_11));

    strncpy(VAR_11, VAR_0, SD_MAX_VDI_LEN);



    memset(&hdr, 0, sizeof(hdr));

    hdr.opcode = SD_OP_NEW_VDI;

    hdr.base_vdi_id = VAR_2;



    VAR_9 = SD_MAX_VDI_LEN;



    hdr.flags = SD_FLAG_CMD_WRITE;

    hdr.snapid = VAR_4;



    hdr.data_length = VAR_9;

    hdr.VAR_1 = VAR_1;



    VAR_8 = do_req(VAR_7, (SheepdogReq *)&hdr, VAR_11, &VAR_9, &VAR_10);



    closesocket(VAR_7);



    if (VAR_8) {

        return VAR_8;

    }



    if (rsp->result != SD_RES_SUCCESS) {

        error_report("%s, %s", sd_strerror(rsp->result), VAR_0);

        return -EIO;

    }



    if (VAR_3) {

        *VAR_3 = rsp->VAR_3;

    }



    return 0;

}

static int FUNC_0(char *VAR_0, int64_t VAR_1,
uint32_t VAR_2, uint32_t *VAR_3, int VAR_4,
const char *VAR_5, const char *VAR_6)
{ SheepdogVdiReq hdr; SheepdogVdiRsp *rsp = (SheepdogVdiRsp *)&hdr; int VAR_7, VAR_8; unsigned int VAR_9, VAR_10 = 0; char VAR_11[SD_MAX_VDI_LEN]; VAR_7 = connect_to_sdog(VAR_5, VAR_6); if (VAR_7 < 0) { return VAR_7; } memset(VAR_11, 0, sizeof(VAR_11)); strncpy(VAR_11, VAR_0, SD_MAX_VDI_LEN); memset(&hdr, 0, sizeof(hdr)); hdr.opcode = SD_OP_NEW_VDI; hdr.base_vdi_id = VAR_2; VAR_9 = SD_MAX_VDI_LEN; hdr.flags = SD_FLAG_CMD_WRITE; hdr.snapid = VAR_4; hdr.data_length = VAR_9; hdr.VAR_1 = VAR_1; VAR_8 = do_req(VAR_7, (SheepdogReq *)&hdr, VAR_11, &VAR_9, &VAR_10); closesocket(VAR_7); if (VAR_8) { return VAR_8; } if (rsp->result != SD_RES_SUCCESS) { error_report("%s, %s", sd_strerror(rsp->result), VAR_0); return -EIO; } if (VAR_3) { *VAR_3 = rsp->VAR_3; } return 0; }