static int bnode_create(struct kv_bnode *bnode, uint32_t account_vid) { struct sd_inode *inode = xmalloc(sizeof(struct sd_inode)); uint32_t tmp_vid, idx; uint64_t hval, i; int ret; ret = sd_read_object(vid_to_vdi_oid(account_vid), (char *)inode, sizeof(*inode), 0); if (ret != SD_RES_SUCCESS) { sd_err("failed to read %" PRIx32 " %s", account_vid, sd_strerror(ret)); goto out; } hval = sd_hash(bnode->name, strlen(bnode->name)); for (i = 0; i < MAX_DATA_OBJS; i++) { idx = (hval + i) % MAX_DATA_OBJS; tmp_vid = INODE_GET_VID(inode, idx); if (tmp_vid) continue; else break; } if (i == MAX_DATA_OBJS) { ret = SD_RES_NO_SPACE; goto out; } ret = bnode_do_create(bnode, inode, idx); out: free(inode); return ret; }
static int bnode_create(struct kv_bnode *bnode, uint32_t account_vid) { struct sd_inode *inode = xmalloc(sizeof(struct sd_inode)); uint32_t tmp_vid, idx; uint64_t hval, i; int ret; bool create = true; ret = sd_read_object(vid_to_vdi_oid(account_vid), (char *)inode, sizeof(*inode), 0); if (ret != SD_RES_SUCCESS) { sd_err("failed to read %" PRIx32 " %s", account_vid, sd_strerror(ret)); goto out; } hval = sd_hash(bnode->name, strlen(bnode->name)); for (i = 0; i < MAX_DATA_OBJS; i++) { idx = (hval + i) % MAX_DATA_OBJS; tmp_vid = sd_inode_get_vid(inode, idx); if (tmp_vid) { uint64_t oid = vid_to_data_oid(account_vid, idx); char name[SD_MAX_BUCKET_NAME] = { }; ret = sd_read_object(oid, name, sizeof(name), 0); if (ret != SD_RES_SUCCESS) goto out; if (name[0] == 0) { create = false; goto create; } } else break; } if (i == MAX_DATA_OBJS) { ret = SD_RES_NO_SPACE; goto out; } create: ret = bnode_do_create(bnode, inode, idx, create); out: free(inode); return ret; }