Example #1
0
File: fsx.c Project: athanatos/ceph
void
check_trunc_hack(void)
{
	rbd_image_info_t statbuf;

	rbd_resize(image, (off_t)0);
	rbd_resize(image, (off_t)100000);
	rbd_stat(image, &statbuf, sizeof(statbuf));
	if (statbuf.size != (off_t)100000) {
 		prt("no extend on truncate! not posix!\n");
 		exit(130);
 	}
	rbd_resize(image, (off_t)0);
}
Example #2
0
static int qemu_rbd_getinfo(BlockDriverState *bs, BlockDriverInfo *bdi)
{
    BDRVRBDState *s = bs->opaque;
    rbd_image_info_t info;
    int r;

    r = rbd_stat(s->image, &info, sizeof(info));
    if (r < 0) {
        return r;
    }

    bdi->cluster_size = info.obj_size;
    return 0;
}
static int volStorageBackendRBDRefreshVolInfo(virStorageVolDefPtr vol,
                                              virStoragePoolObjPtr pool,
                                              virStorageBackendRBDStatePtr ptr)
{
    int ret = -1;
    int r = 0;
    rbd_image_t image;

    r = rbd_open(ptr->ioctx, vol->name, &image, NULL);
    if (r < 0) {
        virReportSystemError(-r, _("failed to open the RBD image '%s'"),
                             vol->name);
        return ret;
    }

    rbd_image_info_t info;
    r = rbd_stat(image, &info, sizeof(info));
    if (r < 0) {
        virReportSystemError(-r, _("failed to stat the RBD image '%s'"),
                             vol->name);
        goto cleanup;
    }

    VIR_DEBUG("Refreshed RBD image %s/%s (size: %llu obj_size: %llu num_objs: %llu)",
              pool->def->source.name, vol->name, (unsigned long long)info.size,
              (unsigned long long)info.obj_size,
              (unsigned long long)info.num_objs);

    vol->capacity = info.size;
    vol->allocation = info.obj_size * info.num_objs;
    vol->type = VIR_STORAGE_VOL_NETWORK;

    VIR_FREE(vol->target.path);
    if (virAsprintf(&vol->target.path, "%s/%s",
                    pool->def->source.name,
                    vol->name) == -1)
        goto cleanup;

    VIR_FREE(vol->key);
    if (virAsprintf(&vol->key, "%s/%s",
                    pool->def->source.name,
                    vol->name) == -1)
        goto cleanup;

    ret = 0;

cleanup:
    rbd_close(image);
    return ret;
}
Example #4
0
void
check_size(void)
{
	rbd_image_info_t statbuf;
	int ret;

	if ((ret = rbd_stat(image, &statbuf, sizeof(statbuf))) < 0) {
		prterrcode("check_size: fstat", ret);
	}
	if ((uint64_t)file_size != statbuf.size) {
		prt("Size error: expected 0x%llx stat 0x%llx\n",
		    (unsigned long long)file_size,
		    (unsigned long long)statbuf.size);
		report_failure(120);
	}
}
Example #5
0
File: fsx.c Project: CzBiX/ceph
int
librbd_get_size(struct rbd_ctx *ctx, uint64_t *size)
{
	rbd_image_info_t info;
	int ret;

	ret = rbd_stat(ctx->image, &info, sizeof(info));
	if (ret < 0) {
		prt("rbd_stat failed\n");
		return ret;
	}

	*size = info.size;

	return 0;
}
Example #6
0
int
open_rbd_image(const char *image_name)
{
    struct rbd_image *im;
    struct rbd_openimage *rbd;
    int fd;

    if (image_name == (char *)NULL)
        return -1;

    // relies on caller to keep rbd_images up to date
    for (im = rbd_images; im != NULL; im = im->next) {
        if (strcmp(im->image_name, image_name) == 0) {
            break;
        }
    }
    if (im == NULL)
        return -1;

    /* find in opentbl[] entry if already open */
    if ((fd = find_openrbd(image_name)) != -1) {
        rbd = &opentbl[fd];
    } else {
        int i;
        // allocate an opentbl[] and open the image
        for (i = 0; i < MAX_RBD_IMAGES; i++) {
            if (opentbl[i].image == NULL) {
                fd = i;
                rbd = &opentbl[fd];
                rbd->image_name = strdup(image_name);
                break;
            }
        }
        if (i == MAX_RBD_IMAGES)
            return -1;
        int ret = rbd_open(ioctx, rbd->image_name, &(rbd->image), NULL);
        if (ret < 0) {
            simple_err("open_rbd_image: can't open: ", ret);
            return ret;
        }
    }
    rbd_stat(rbd->image, &(rbd->rbd_stat.rbd_info),
             sizeof(rbd_image_info_t));
    rbd->rbd_stat.valid = 1;
    return fd;
}
Example #7
0
int
rbdfs_truncate(const char *path, off_t size)
{
    int fd;
    int r;
    struct rbd_openimage *rbd;

    if ((fd = open_rbd_image(path+1)) < 0)
        return -ENOENT;

    rbd = &opentbl[fd];
    fprintf(stderr, "truncate %s to %"PRIdMAX" (0x%"PRIxMAX")\n", path, size, size);
    r = rbd_resize(rbd->image, size);
    if (r < 0)
        return r;

    r = rbd_stat(rbd->image, &(rbd->rbd_stat.rbd_info),
                 sizeof(rbd_image_info_t));
    if (r < 0)
        return r;
    return 0;
}
Example #8
0
static int rbdfs_write(const char *path, const char *buf, size_t size,
                       off_t offset, struct fuse_file_info *fi)
{
    size_t numwritten;
    struct rbd_openimage *rbd;

    if (!gotrados)
        return -ENXIO;

    rbd = &opentbl[fi->fh];
    numwritten = 0;
    while (size > 0) {
        ssize_t ret;

        if (offset + size > rbdsize(fi->fh)) {
            int r;
            fprintf(stderr, "rbdfs_write resizing %s to 0x%"PRIxMAX"\n",
                    path, offset+size);
            r = rbd_resize(rbd->image, offset+size);
            if (r < 0)
                return r;

            r = rbd_stat(rbd->image, &(rbd->rbd_stat.rbd_info),
                         sizeof(rbd_image_info_t));
            if (r < 0)
                return r;
        }
        ret = rbd_write(rbd->image, offset, size, buf);

        if (ret < 0)
            break;
        buf += ret;
        size -= ret;
        offset += ret;
        numwritten += ret;
    }

    return numwritten;
}