static int init_vdi_copy_number(uint64_t oid) { char path[PATH_MAX]; int fd, flags = get_open_flags(oid, false), ret; struct sheepdog_inode *inode = xzalloc(sizeof(*inode)); snprintf(path, sizeof(path), "%s%016" PRIx64, obj_path, oid); fd = open(path, flags); if (fd < 0) { eprintf("failed to open %s, %m\n", path); ret = SD_RES_EIO; goto out; } ret = xpread(fd, inode, SD_INODE_HEADER_SIZE, 0); if (ret != SD_INODE_HEADER_SIZE) { eprintf("failed to read inode header, path=%s, %m\n", path); ret = SD_RES_EIO; goto out; } add_vdi_copy_number(oid_to_vid(oid), inode->nr_copies); ret = SD_RES_SUCCESS; out: free(inode); return SD_RES_SUCCESS; }
static int get_vdis_from(struct sd_node *node) { struct sd_req hdr; struct sd_rsp *rsp = (struct sd_rsp *)&hdr; struct vdi_copy *vc = NULL; int i, ret = SD_RES_SUCCESS; unsigned int rlen; int count; if (node_is_local(node)) goto out; rlen = SD_DATA_OBJ_SIZE; /* FIXME */ vc = zalloc(rlen); if (!vc) { sd_printf(SDOG_ERR, "unable to allocate memory\n"); ret = SD_RES_NO_MEM; goto out; } sd_init_req(&hdr, SD_OP_GET_VDI_COPIES); hdr.data_length = rlen; ret = sheep_exec_req(&node->nid, &hdr, (char *)vc); if (ret != SD_RES_SUCCESS) goto out; count = rsp->data_length / sizeof(*vc); for (i = 0; i < count; i++) { set_bit(vc[i].vid, sys->vdi_inuse); add_vdi_copy_number(vc[i].vid, vc[i].nr_copies); } out: free(vc); return ret; }