示例#1
0
文件: rbd.c 项目: RafaelRMachado/qemu
static int qemu_rbd_truncate(BlockDriverState *bs, int64_t offset)
{
    BDRVRBDState *s = bs->opaque;
    int r;

    r = rbd_resize(s->image, offset);
    if (r < 0) {
        return r;
    }

    return 0;
}
示例#2
0
文件: fsx.c 项目: CzBiX/ceph
int
__librbd_resize(struct rbd_ctx *ctx, uint64_t size)
{
	int ret;

	ret = rbd_resize(ctx->image, size);
	if (ret < 0) {
		prt("rbd_resize(%llu) failed\n", size);
		return ret;
	}

	return 0;
}
示例#3
0
static int virStorageBackendRBDResizeVol(virConnectPtr conn ATTRIBUTE_UNUSED,
        virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
        virStorageVolDefPtr vol,
        unsigned long long capacity,
        unsigned int flags)
{
    virStorageBackendRBDStatePtr ptr;
    ptr.cluster = NULL;
    ptr.ioctx = NULL;
    rbd_image_t image = NULL;
    int ret = -1;

    virCheckFlags(0, -1);

    if (virStorageBackendRBDOpenRADOSConn(&ptr, conn, pool) < 0) {
        goto cleanup;
    }

    if (rados_ioctx_create(ptr.cluster,
                           pool->def->source.name, &ptr.ioctx) < 0) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("failed to create the RBD IoCTX. Does the pool '%s' exist?"),
                       pool->def->source.name);
        goto cleanup;
    }

    if (rbd_open(ptr.ioctx, vol->name, &image, NULL) < 0) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("failed to open the RBD image '%s'"),
                       vol->name);
        goto cleanup;
    }

    if (rbd_resize(image, capacity) < 0) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("failed to resize the RBD image '%s'"),
                       vol->name);
        goto cleanup;
    }

    ret = 0;

cleanup:
    if (image != NULL)
        rbd_close(image);
    virStorageBackendRBDCloseRADOSConn(ptr);
    return ret;
}
示例#4
0
static int virStorageBackendRBDResizeVol(virConnectPtr conn ATTRIBUTE_UNUSED,
                                     virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
                                     virStorageVolDefPtr vol,
                                     unsigned long long capacity,
                                     unsigned int flags)
{
    virStorageBackendRBDState ptr;
    ptr.cluster = NULL;
    ptr.ioctx = NULL;
    rbd_image_t image = NULL;
    int ret = -1;
    int r = 0;

    virCheckFlags(0, -1);

    if (virStorageBackendRBDOpenRADOSConn(&ptr, conn, pool) < 0) {
        goto cleanup;
    }

    if (virStorageBackendRBDOpenIoCTX(&ptr, pool) < 0) {
        goto cleanup;
    }

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

    r = rbd_resize(image, capacity);
    if (r < 0) {
        virReportSystemError(-r, _("failed to resize the RBD image '%s'"),
                             vol->name);
        goto cleanup;
    }

    ret = 0;

cleanup:
    if (image != NULL)
       rbd_close(image);
    virStorageBackendRBDCloseRADOSConn(&ptr);
    return ret;
}
示例#5
0
文件: fsx.c 项目: BillTheBest/ceph
void
writefileimage()
{
	ssize_t ret;

	ret = rbd_write(image, 0, file_size, good_buf);
	if (ret != file_size) {
		if (ret < 0)
			prterrcode("writefileimage: write", ret);
		else
			prt("short write: 0x%x bytes instead of 0x%llx\n",
			    ret, (unsigned long long)file_size);
		report_failure(172);
	}
	if (lite ? 0 : (ret = rbd_resize(image, file_size)) < 0) {
		prt("rbd_resize: %llx\n", (unsigned long long)file_size);
		prterrcode("writefileimage: rbd_resize", ret);
		report_failure(173);
	}
}
示例#6
0
文件: rbd.c 项目: nikunjad/qemu
static int qemu_rbd_truncate(BlockDriverState *bs, int64_t offset,
                             PreallocMode prealloc, Error **errp)
{
    BDRVRBDState *s = bs->opaque;
    int r;

    if (prealloc != PREALLOC_MODE_OFF) {
        error_setg(errp, "Unsupported preallocation mode '%s'",
                   PreallocMode_str(prealloc));
        return -ENOTSUP;
    }

    r = rbd_resize(s->image, offset);
    if (r < 0) {
        error_setg_errno(errp, -r, "Failed to resize file");
        return r;
    }

    return 0;
}
示例#7
0
文件: rbd-fuse.c 项目: hufman/ceph
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;
}
示例#8
0
文件: rbd-fuse.c 项目: hufman/ceph
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;
}