static int sd_create_branch(BDRVSheepdogState *s)

{

    int ret, fd;

    uint32_t vid;

    char *buf;



    dprintf("%" PRIx32 " is snapshot.\n", s->inode.vdi_id);



    buf = g_malloc(SD_INODE_SIZE);



    ret = do_sd_create(s->name, s->inode.vdi_size, s->inode.vdi_id, &vid, 1,

                       s->addr, s->port);

    if (ret) {

        goto out;

    }



    dprintf("%" PRIx32 " is created.\n", vid);



    fd = connect_to_sdog(s->addr, s->port);

    if (fd < 0) {

        error_report("failed to connect");

        ret = fd;

        goto out;

    }



    ret = read_object(fd, buf, vid_to_vdi_oid(vid), s->inode.nr_copies,

                      SD_INODE_SIZE, 0, s->cache_enabled);



    closesocket(fd);



    if (ret < 0) {

        goto out;

    }



    memcpy(&s->inode, buf, sizeof(s->inode));



    s->is_snapshot = false;

    ret = 0;

    dprintf("%" PRIx32 " was newly created.\n", s->inode.vdi_id);



out:

    g_free(buf);



    return ret;

}

static int sd_create_branch(BDRVSheepdogState *s)

{

    int ret, fd;

    uint32_t vid;

    char *buf;



    dprintf("%" PRIx32 " is snapshot.\n", s->inode.vdi_id);



    buf = g_malloc(SD_INODE_SIZE);



    ret = do_sd_create(s->name, s->inode.vdi_size, s->inode.vdi_id, &vid, 1,

                       s->addr, s->port);

    if (ret) {

        goto out;

    }



    dprintf("%" PRIx32 " is created.\n", vid);



    fd = connect_to_sdog(s->addr, s->port);

    if (fd < 0) {

        error_report("failed to connect");

        ret = fd;

        goto out;

    }



    ret = read_object(fd, buf, vid_to_vdi_oid(vid), s->inode.nr_copies,

                      SD_INODE_SIZE, 0, s->cache_enabled);



    closesocket(fd);



    if (ret < 0) {

        goto out;

    }



    memcpy(&s->inode, buf, sizeof(s->inode));



    s->is_snapshot = false;

    ret = 0;

    dprintf("%" PRIx32 " was newly created.\n", s->inode.vdi_id);



out:

    g_free(buf);



    return ret;

}

static int FUNC_0(BDRVSheepdogState *VAR_0)

{

    int VAR_1, VAR_2;

    uint32_t vid;

    char *VAR_3;



    dprintf("%" PRIx32 " is snapshot.\n", VAR_0->inode.vdi_id);



    VAR_3 = g_malloc(SD_INODE_SIZE);



    VAR_1 = do_sd_create(VAR_0->name, VAR_0->inode.vdi_size, VAR_0->inode.vdi_id, &vid, 1,

                       VAR_0->addr, VAR_0->port);

    if (VAR_1) {

        goto out;

    }



    dprintf("%" PRIx32 " is created.\n", vid);



    VAR_2 = connect_to_sdog(VAR_0->addr, VAR_0->port);

    if (VAR_2 < 0) {

        error_report("failed to connect");

        VAR_1 = VAR_2;

        goto out;

    }



    VAR_1 = read_object(VAR_2, VAR_3, vid_to_vdi_oid(vid), VAR_0->inode.nr_copies,

                      SD_INODE_SIZE, 0, VAR_0->cache_enabled);



    closesocket(VAR_2);



    if (VAR_1 < 0) {

        goto out;

    }



    memcpy(&VAR_0->inode, VAR_3, sizeof(VAR_0->inode));



    VAR_0->is_snapshot = false;

    VAR_1 = 0;

    dprintf("%" PRIx32 " was newly created.\n", VAR_0->inode.vdi_id);



out:

    g_free(VAR_3);



    return VAR_1;

}

static int FUNC_0(BDRVSheepdogState *VAR_0)
{ int VAR_1, VAR_2; uint32_t vid; char *VAR_3; dprintf("%" PRIx32 " is snapshot.\n", VAR_0->inode.vdi_id); VAR_3 = g_malloc(SD_INODE_SIZE); VAR_1 = do_sd_create(VAR_0->name, VAR_0->inode.vdi_size, VAR_0->inode.vdi_id, &vid, 1,
VAR_0->addr, VAR_0->port); if (VAR_1) { goto out; } dprintf("%" PRIx32 " is created.\n", vid); VAR_2 = connect_to_sdog(VAR_0->addr, VAR_0->port); if (VAR_2 < 0) { error_report("failed to connect"); VAR_1 = VAR_2; goto out; } VAR_1 = read_object(VAR_2, VAR_3, vid_to_vdi_oid(vid), VAR_0->inode.nr_copies,
SD_INODE_SIZE, 0, VAR_0->cache_enabled); closesocket(VAR_2); if (VAR_1 < 0) { goto out; } memcpy(&VAR_0->inode, VAR_3, sizeof(VAR_0->inode)); VAR_0->is_snapshot = false; VAR_1 = 0; dprintf("%" PRIx32 " was newly created.\n", VAR_0->inode.vdi_id); out:
g_free(VAR_3); return VAR_1; }