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 bs_rdwr_open(struct scsi_lu *lu, char *path, int *fd, uint64_t *size) { uint32_t blksize = 0; *fd = backed_file_open(path, O_RDWR|O_LARGEFILE|lu->bsoflags, size, &blksize); /* If we get access denied, try opening the file in readonly mode */ if (*fd == -1 && (errno == EACCES || errno == EROFS)) { *fd = backed_file_open(path, O_RDONLY|O_LARGEFILE|lu->bsoflags, size, &blksize); lu->attrs.readonly = 1; } if (*fd < 0) return *fd; if (!lu->attrs.no_auto_lbppbe) update_lbppbe(lu, blksize); return 0; }