static int bs_rbd_open(struct scsi_lu *lu, char *path, int *fd, uint64_t *size) { uint32_t blksize = 0; int ret; rbd_image_info_t inf; char *poolname; char *imagename; char *snapname; struct active_rbd *rbd = NULL; int lfd; parse_imagepath(path, &poolname, &imagename, &snapname); for (lfd = 0; lfd < MAX_IMAGES; lfd++) { if (active_rbds[lfd].rbd_image == NULL) { rbd = &active_rbds[lfd]; *fd = lfd; break; } } if (!rbd) { *fd = -1; return -EMFILE; } rbd->poolname = poolname; rbd->imagename = imagename; rbd->snapname = snapname; eprintf("bs_rbd_open: pool: %s image: %s snap: %s\n", poolname, imagename, snapname); if ((ret == rados_ioctx_create(cluster, poolname, &rbd->ioctx)) < 0) { eprintf("bs_rbd_open: rados_ioctx_create: %d\n", ret); return -EIO; } /* null snap name */ ret = rbd_open(rbd->ioctx, imagename, &rbd->rbd_image, snapname); if (ret < 0) { eprintf("bs_rbd_open: rbd_open: %d\n", ret); return ret; } if (rbd_stat(rbd->rbd_image, &inf, sizeof(inf)) < 0) { eprintf("bs_rbd_open: rbd_stat: %d\n", ret); return ret; } *size = inf.size; blksize = inf.obj_size; if (!lu->attrs.no_auto_lbppbe) update_lbppbe(lu, blksize); return 0; }
static int tcmu_glfs_open(struct tcmu_device *dev) { struct glfs_state *gfsp; int ret = 0; char *config; struct stat st; int attribute; gfsp = calloc(1, sizeof(*gfsp)); if (!gfsp) return -ENOMEM; tcmu_set_dev_private(dev, gfsp); attribute = tcmu_get_attribute(dev, "hw_block_size"); if (attribute == -1) { errp("Could not get hw_block_size setting\n"); goto fail; } gfsp->block_size = attribute; config = strchr(tcmu_get_dev_cfgstring(dev), '/'); if (!config) { errp("no configuration found in cfgstring\n"); goto fail; } config += 1; /* get past '/' */ if (parse_imagepath(config, &gfsp->servername, &gfsp->volname, &gfsp->pathname) == -1) { errp("servername, volname, or pathname not set\n"); goto fail; } gfsp->fs = glfs_new(gfsp->volname); if (!gfsp->fs) { errp("glfs_new failed\n"); goto fail; } ret = glfs_set_volfile_server(gfsp->fs, "tcp", gfsp->servername, GLUSTER_PORT); if (ret) { errp("glfs_set_volfile_server failed: %m\n"); goto fail; } ret = glfs_init(gfsp->fs); if (ret) { errp("glfs_init failed: %m\n"); goto fail; } gfsp->gfd = glfs_open(gfsp->fs, gfsp->pathname, ALLOWED_BSOFLAGS); if (!gfsp->gfd) { errp("glfs_open failed: %m\n"); goto fail; } ret = glfs_lstat(gfsp->fs, gfsp->pathname, &st); if (ret) { errp("glfs_lstat failed: %m\n"); goto fail; } if (st.st_size != tcmu_get_device_size(dev)) { errp("device size and backing size disagree: " "device %lld backing %lld\n", tcmu_get_device_size(dev), (long long) st.st_size); goto fail; } return 0; fail: if (gfsp->gfd) glfs_close(gfsp->gfd); if (gfsp->fs) glfs_fini(gfsp->fs); free(gfsp->volname); free(gfsp->pathname); free(gfsp->servername); free(gfsp); return -EIO; }
static bool glfs_check_config(const char *cfgstring, char **reason) { char *path; char *servername = NULL; char *volname = NULL; char *pathname = NULL; glfs_t *fs = NULL; glfs_fd_t *gfd = NULL; struct stat st; int ret; bool result = true; path = strchr(cfgstring, '/'); if (!path) { if (asprintf(reason, "No path found") == -1) *reason = NULL; result = false; goto done; } path += 1; /* get past '/' */ if (parse_imagepath(path, &servername, &volname, &pathname) == -1) { if (asprintf(reason, "Invalid imagepath") == -1) *reason = NULL; result = false; goto done; } /* Actually attempt to open the volume to verify things are working */ /* TODO: consolidate this with v. similar tcmu_glfs_open code? */ fs = glfs_new(volname); if (!fs) { if (asprintf(reason, "glfs_new failed") == -1) *reason = NULL; result = false; goto done; } ret = glfs_set_volfile_server(fs, "tcp", servername, GLUSTER_PORT); if (ret) { if (asprintf(reason, "glfs_set_volfile_server failed: %m") == -1) *reason = NULL; result = false; goto done; } ret = glfs_init(fs); if (ret) { if (asprintf(reason, "glfs_init failed: %m") == -1) *reason = NULL; result = false; goto done; } gfd = glfs_open(fs, pathname, ALLOWED_BSOFLAGS); if (!gfd) { if (asprintf(reason, "glfs_open failed: %m") == -1) *reason = NULL; result = false; goto done; } ret = glfs_lstat(fs, pathname, &st); if (ret) { if (asprintf(reason, "glfs_lstat failed: %m") == -1) *reason = NULL; result = false; goto done; } done: if (gfd) glfs_close(gfd); if (fs) glfs_fini(fs); free(servername); free(volname); free(pathname); return result; }