static int storage_get_storage(int id, storage_info_h* storage_info) { if (storage_num < 1) { if (storage_initialize() != 0) { return STORAGE_ERROR_NOT_SUPPORTED; } } if (id <0 || id >= storage_num) { return STORAGE_ERROR_NOT_SUPPORTED; } *storage_info = &(storage_info_table[id]); return STORAGE_ERROR_NONE; }
int main(int argc, char **argv) { storage_t st; sid_t sid = 0; sstat_t sst; fid_t fid; //bin_t *bins; rozofs_initialize(LAYOUT_2_3_4); storage_initialize(&st, sid, "/tmp"); if (storage_stat(&st, &sst) != 0) { perror("failed to stat storage"); exit(-1); } printf("size: %" PRIu64 ", free: %" PRIu64 "\n", sst.size, sst.free); uuid_generate(fid); // Write some bins (15 prj) //bins = xmalloc(rozofs_psizes[0] * 15); /* if (storage_write(&st, fid, 0, 10, 15, bins) != 0) { perror("failed to write bins"); exit(-1); } */ if (storage_truncate(&st, fid, 0, 10) != 0) { perror("failed to truncate pfile"); exit(-1); } if (storage_rm_file(&st, fid) != 0) { perror("failed to remove pfile"); exit(-1); } storage_release(&st); exit(0); }
static int load_storages_conf(struct config_t *config) { int status = -1; int i = 0; struct config_setting_t *settings = NULL; if (!(settings = config_lookup(config, "storages"))) { errno = ENOKEY; fprintf(stderr, "can't locate the storages settings in conf file\n"); fatal("can't locate the storages settings in conf file"); goto out; } storaged_storages = xmalloc(config_setting_length(settings) * sizeof (storage_t)); for (i = 0; i < config_setting_length(settings); i++) { struct config_setting_t *ms = NULL; long int sid; const char *root; if (!(ms = config_setting_get_elem(settings, i))) { errno = EIO; //XXX fprintf(stderr, "cant't fetche storage at index %d\n", i); severe("cant't fetche storage at index %d", i); goto out; } if (config_setting_lookup_int(ms, "sid", &sid) == CONFIG_FALSE) { errno = ENOKEY; fprintf(stderr, "cant't look up sid for storage (idx=%d)\n", i); fatal("cant't look up sid for storage (idx=%d)", i); goto out; } if (storaged_lookup(sid) != NULL) { fprintf(stderr, "cant't add storage with sid %ld: already exists\n", sid); info("cant't add storage with sid %ld: already exists", sid); goto out; } if (config_setting_lookup_string(ms, "root", &root) == CONFIG_FALSE) { errno = ENOKEY; fprintf(stderr, "cant't look up root path for storage (idx=%d)\n", i); severe("cant't look up root path for storage (idx=%d)", i); goto out; } if (storage_initialize(storaged_storages + i, (uint16_t) sid, root) != 0) { fprintf(stderr, "can't initialize storage (sid:%ld) with path %s: %s\n", sid, root, strerror(errno)); severe("can't initialize storage (sid:%ld) with path %s: %s", sid, root, strerror(errno)); goto out; } storaged_nrstorages++; } status = 0; out: return status; }