this patch adds iscsi_truncate which effectively allows for online
resizing of iscsi volumes. for this to work you have to resize
the volume on your storage and then call block_resize command
in qemu which will issue a readcapacity16 to update the capacity.
Signed-off-by: Peter Lieven <address@hidden>
---
block/iscsi.c | 74
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 74 insertions(+)
diff --git a/block/iscsi.c b/block/iscsi.c
index deb3b68..37f12b3 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -67,6 +67,12 @@ typedef struct IscsiAIOCB {
#endif
} IscsiAIOCB;
+struct IscsiTask {
+ IscsiLun *iscsilun;
+ int status;
+ int complete;
+};
+
#define NOP_INTERVAL 5000
#define MAX_NOP_FAILURES 3
@@ -700,6 +706,73 @@ iscsi_getlength(BlockDriverState *bs)
return len;
}
+static void
+iscsi_readcapacity16_cb(struct iscsi_context *iscsi, int status,
+ void *command_data, void *opaque)
+{
+ struct IscsiTask *itask = opaque;
+ struct scsi_readcapacity16 *rc16;
+ struct scsi_task *task = command_data;
+
+ if (status != 0) {
+ error_report("iSCSI: Failed to read capacity of iSCSI lun. %s",
+ iscsi_get_error(iscsi));
+ itask->status = 1;
+ itask->complete = 1;
+ scsi_free_scsi_task(task);
+ return;
+ }
+
+ rc16 = scsi_datain_unmarshall(task);
+ if (rc16 == NULL) {
+ error_report("iSCSI: Failed to unmarshall readcapacity16 data.");
+ itask->status = 1;
+ itask->complete = 1;
+ scsi_free_scsi_task(task);
+ return;
+ }
+
+ itask->iscsilun->block_size = rc16->block_length;
+ itask->iscsilun->num_blocks = rc16->returned_lba + 1;
+
+ itask->status = 0;
+ itask->complete = 1;
+ scsi_free_scsi_task(task);
+}
+
+static int iscsi_truncate(BlockDriverState *bs, int64_t offset)
+{
+ IscsiLun *iscsilun = bs->opaque;
+ struct IscsiTask itask;
+ struct scsi_task *task = NULL;
+
+ if (iscsilun->type != TYPE_DISK) {
+ return -ENOTSUP;
+ }
+
+ itask.iscsilun = iscsilun;
+ itask.status = 0;
+ itask.complete = 0;
+
+ task = iscsi_readcapacity16_task(iscsilun->iscsi, iscsilun->lun,
+ iscsi_readcapacity16_cb, &itask);