[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 12/22] block/archipelago: Implement bdrv_truncate()
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 12/22] block/archipelago: Implement bdrv_truncate() |
Date: |
Fri, 12 Sep 2014 17:56:56 +0200 |
From: Chrysostomos Nanakos <address@hidden>
Signed-off-by: Chrysostomos Nanakos <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/archipelago.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 61 insertions(+), 2 deletions(-)
diff --git a/block/archipelago.c b/block/archipelago.c
index 22a7daa..40e5f76 100644
--- a/block/archipelago.c
+++ b/block/archipelago.c
@@ -63,8 +63,6 @@
#include <xseg/xseg.h>
#include <xseg/protocol.h>
-#define ARCHIP_FD_READ 0
-#define ARCHIP_FD_WRITE 1
#define MAX_REQUEST_SIZE 524288
#define ARCHIPELAGO_OPT_VOLUME "volume"
@@ -84,6 +82,7 @@ typedef enum {
ARCHIP_OP_WRITE,
ARCHIP_OP_FLUSH,
ARCHIP_OP_VOLINFO,
+ ARCHIP_OP_TRUNCATE,
} ARCHIPCmd;
typedef struct ArchipelagoAIOCB {
@@ -248,6 +247,7 @@ static void xseg_request_handler(void *state)
}
break;
case ARCHIP_OP_VOLINFO:
+ case ARCHIP_OP_TRUNCATE:
s->is_signaled = true;
qemu_cond_signal(&s->archip_cond);
break;
@@ -995,6 +995,64 @@ static int64_t qemu_archipelago_getlength(BlockDriverState
*bs)
return ret;
}
+static int qemu_archipelago_truncate(BlockDriverState *bs, int64_t offset)
+{
+ int ret, targetlen;
+ struct xseg_request *req;
+ BDRVArchipelagoState *s = bs->opaque;
+ AIORequestData *reqdata = g_new(AIORequestData, 1);
+
+ const char *volname = s->volname;
+ targetlen = strlen(volname);
+ req = xseg_get_request(s->xseg, s->srcport, s->mportno, X_ALLOC);
+ if (!req) {
+ archipelagolog("Cannot get XSEG request\n");
+ return err_exit2;
+ }
+
+ ret = xseg_prep_request(s->xseg, req, targetlen, 0);
+ if (ret < 0) {
+ archipelagolog("Cannot prepare XSEG request\n");
+ goto err_exit;
+ }
+ char *target = xseg_get_target(s->xseg, req);
+ if (!target) {
+ archipelagolog("Cannot get XSEG target\n");
+ goto err_exit;
+ }
+ memcpy(target, volname, targetlen);
+ req->offset = offset;
+ req->op = X_TRUNCATE;
+
+ reqdata->op = ARCHIP_OP_TRUNCATE;
+ reqdata->volname = volname;
+
+ xseg_set_req_data(s->xseg, req, reqdata);
+
+ xport p = xseg_submit(s->xseg, req, s->srcport, X_ALLOC);
+ if (p == NoPort) {
+ archipelagolog("Cannot submit XSEG request\n");
+ goto err_exit;
+ }
+
+ xseg_signal(s->xseg, p);
+ qemu_mutex_lock(&s->archip_mutex);
+ while (!s->is_signaled) {
+ qemu_cond_wait(&s->archip_cond, &s->archip_mutex);
+ }
+ s->is_signaled = false;
+ qemu_mutex_unlock(&s->archip_mutex);
+ xseg_put_request(s->xseg, req, s->srcport);
+ g_free(reqdata);
+ return 0;
+
+err_exit:
+ xseg_put_request(s->xseg, req, s->srcport);
+err_exit2:
+ g_free(reqdata);
+ return -EIO;
+}
+
static QemuOptsList qemu_archipelago_create_opts = {
.name = "archipelago-create-opts",
.head = QTAILQ_HEAD_INITIALIZER(qemu_archipelago_create_opts.head),
@@ -1024,6 +1082,7 @@ static BlockDriver bdrv_archipelago = {
.bdrv_close = qemu_archipelago_close,
.bdrv_create = qemu_archipelago_create,
.bdrv_getlength = qemu_archipelago_getlength,
+ .bdrv_truncate = qemu_archipelago_truncate,
.bdrv_aio_readv = qemu_archipelago_aio_readv,
.bdrv_aio_writev = qemu_archipelago_aio_writev,
.bdrv_aio_flush = qemu_archipelago_aio_flush,
--
1.8.3.1
- [Qemu-devel] [PULL 03/22] qemu-io: Clean up openfile() after commit 2e40134, (continued)
- [Qemu-devel] [PULL 03/22] qemu-io: Clean up openfile() after commit 2e40134, Kevin Wolf, 2014/09/12
- [Qemu-devel] [PULL 04/22] xen_disk: Plug memory leak on error path, Kevin Wolf, 2014/09/12
- [Qemu-devel] [PULL 05/22] xen: Drop redundant bdrv_close() from pci_piix3_xen_ide_unplug(), Kevin Wolf, 2014/09/12
- [Qemu-devel] [PULL 09/22] block: Extract the block accounting code, Kevin Wolf, 2014/09/12
- [Qemu-devel] [PULL 01/22] block: extend BLOCK_IO_ERROR event with nospace indicator, Kevin Wolf, 2014/09/12
- [Qemu-devel] [PULL 07/22] IDE: MMIO IDE device control should be little endian, Kevin Wolf, 2014/09/12
- [Qemu-devel] [PULL 10/22] block: rename BlockAcctType members to start with BLOCK_ instead of BDRV_, Kevin Wolf, 2014/09/12
- [Qemu-devel] [PULL 11/22] block: Make the block accounting functions operate on BlockAcctStats, Kevin Wolf, 2014/09/12
- [Qemu-devel] [PULL 06/22] thread-pool: Drop unnecessary includes, Kevin Wolf, 2014/09/12
- [Qemu-devel] [PULL 08/22] block: Extract the BlockAcctStats structure, Kevin Wolf, 2014/09/12
- [Qemu-devel] [PULL 12/22] block/archipelago: Implement bdrv_truncate(),
Kevin Wolf <=
- [Qemu-devel] [PULL 13/22] qemu-iotests: Run 025 for Archipelago block driver, Kevin Wolf, 2014/09/12
- [Qemu-devel] [PULL 14/22] dataplane: fix virtio_blk_data_plane_create() op blocker error path, Kevin Wolf, 2014/09/12
- [Qemu-devel] [PULL 17/22] iotests: Send the correct fd in socket_scm_helper, Kevin Wolf, 2014/09/12
- [Qemu-devel] [PULL 18/22] block: round up file size to nearest sector, Kevin Wolf, 2014/09/12
- [Qemu-devel] [PULL 16/22] blockdev: Refuse to drive_del something added with blockdev-add, Kevin Wolf, 2014/09/12
- [Qemu-devel] [PULL 19/22] block: don't convert file size to sector size, Kevin Wolf, 2014/09/12
- [Qemu-devel] [PULL 15/22] block: extend BLOCK_IO_ERROR with reason string, Kevin Wolf, 2014/09/12
- [Qemu-devel] [PULL 20/22] qapi: introduce PreallocMode and new PreallocModes full and falloc., Kevin Wolf, 2014/09/12
- [Qemu-devel] [PULL 21/22] raw-posix: Add falloc and full preallocation option, Kevin Wolf, 2014/09/12
- [Qemu-devel] [PULL 22/22] qcow2: Add falloc and full preallocation option, Kevin Wolf, 2014/09/12