On 08/10/2018 03:33 PM, clem@xxxxxxxxxxxx wrote: > From: Clementine Hayat <clem@xxxxxxxxxxxx> > > Change set volume capacity to get volume capacity and put the connection > and helpers in one function to avoid code duplicates. > > Signed-off-by: Clementine Hayat <clem@xxxxxxxxxxxx> > --- > > Set BLOCK_PER_PACKET to 128. Not sure about this value. Should be > potentially tuned. > > src/storage/storage_backend_iscsi_direct.c | 173 ++++++++++++++++++--- > 1 file changed, 152 insertions(+), 21 deletions(-) Apart from Jano's comments .... > > diff --git a/src/storage/storage_backend_iscsi_direct.c b/src/storage/storage_backend_iscsi_direct.c > index 0764356b62..958f5937f9 100644 > --- a/src/storage/storage_backend_iscsi_direct.c > +++ b/src/storage/storage_backend_iscsi_direct.c > @@ -41,6 +41,8 @@ > > #define ISCSI_DEFAULT_TARGET_PORT 3260 > #define VIR_ISCSI_TEST_UNIT_TIMEOUT 30 * 1000 > +#define BLOCK_PER_PACKET 128 > +#define VOL_NAME_PREFIX "unit:0:0:" > > VIR_LOG_INIT("storage.storage_backend_iscsi_direct"); > > @@ -225,7 +227,7 @@ virISCSIDirectSetVolumeAttributes(virStoragePoolObjPtr pool, > { > virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); > > - if (virAsprintf(&vol->name, "unit:0:0:%u", lun) < 0) > + if (virAsprintf(&vol->name, "%s%u", VOL_NAME_PREFIX, lun) < 0) > return -1; > if (virAsprintf(&vol->key, "ip-%s-iscsi-%s-lun-%u", portal, > def->source.devices[0].path, lun) < 0) > @@ -237,13 +239,13 @@ virISCSIDirectSetVolumeAttributes(virStoragePoolObjPtr pool, > } > > static int > -virISCSIDirectSetVolumeCapacity(struct iscsi_context *iscsi, > - virStorageVolDefPtr vol, > - int lun) > +virISCSIDirectGetVolumeCapacity(struct iscsi_context *iscsi, > + int lun, > + uint32_t *block_size, > + uint32_t *nb_block) > { > struct scsi_task *task = NULL; > struct scsi_inquiry_standard *inq = NULL; > - long long size = 0; > int ret = -1; > > if (!(task = iscsi_inquiry_sync(iscsi, lun, 0, 0, 64)) || > @@ -282,10 +284,8 @@ virISCSIDirectSetVolumeCapacity(struct iscsi_context *iscsi, > goto cleanup; > } > > - size = rc10->block_size; > - size *= rc10->lba; > - vol->target.capacity = size; > - vol->target.allocation = size; > + *block_size = rc10->block_size; > + *nb_block = rc10->lba; > > } > > @@ -303,6 +303,8 @@ virISCSIDirectRefreshVol(virStoragePoolObjPtr pool, > { > virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); > virStorageVolDefPtr vol = NULL; > + uint32_t block_size; > + uint32_t nb_block; > int ret = -1; > > virStoragePoolObjClearVols(pool); > @@ -314,9 +316,12 @@ virISCSIDirectRefreshVol(virStoragePoolObjPtr pool, > > vol->type = VIR_STORAGE_VOL_NETWORK; > > - if (virISCSIDirectSetVolumeCapacity(iscsi, vol, lun) < 0) > + if (virISCSIDirectGetVolumeCapacity(iscsi, lun, > + &block_size, &nb_block) < 0) > goto cleanup; > > + vol->target.capacity = block_size * nb_block; > + vol->target.allocation = block_size * nb_block; > def->capacity += vol->target.capacity; > def->allocation += vol->target.allocation; > > @@ -553,24 +558,33 @@ virStorageBackendISCSIDirectFindPoolSources(const char *srcSpec, > virStoragePoolSourceFree(source); > return ret; > } > +static int > +virStorageBackendISCSIDirectSetConnection(virStoragePoolObjPtr pool, > + struct iscsi_context **iscsi, > + char **portal) > +{ > + virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); > + > + if (!(*iscsi = virISCSIDirectCreateContext(def->source.initiator.iqn))) > + return -1; > + if (!(*portal = virStorageBackendISCSIDirectPortal(&def->source))) > + return -1; > + if (virStorageBackendISCSIDirectSetAuth(*iscsi, &def->source) < 0) > + return -1; > + if (virISCSIDirectSetContext(*iscsi, def->source.devices[0].path, ISCSI_SESSION_NORMAL) < 0) > + return -1; > + if (virISCSIDirectConnect(*iscsi, *portal) < 0) > + return -1; > + return 0; This function can return iscsi directly. And can accept @portal to be NULL (in which case caller says "I don't care about portal"). Apart from that the patch looks good. Michal -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list