From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christof Schmitt Subject: [patch 08/15] zfcp: remove unit will fail if add unit is not finished Date: Fri, 17 Apr 2009 15:08:08 +0200 Message-ID: <20090417131122.870131000@de.ibm.com> References: <20090417130800.923944000@de.ibm.com> Return-path: Content-Disposition: inline; filename=708-zfcp-remove-unit.diff Sender: linux-scsi-owner@vger.kernel.org List-Archive: List-Post: To: James Bottomley Cc: linux-scsi@vger.kernel.org, linux-s390@vger.kernel.org, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, Martin Petermann , Christof Schmitt List-ID: From: Martin Petermann On some hardware it can take some time to add a unit. If some remove this unit during this process the remove will fail. Signed-off-by: Martin Petermann Signed-off-by: Christof Schmitt --- drivers/s390/scsi/zfcp_sysfs.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) --- a/drivers/s390/scsi/zfcp_sysfs.c 2009-04-17 15:03:20.000000000 +0200 +++ b/drivers/s390/scsi/zfcp_sysfs.c 2009-04-17 15:03:42.000000000 +0200 @@ -254,12 +254,21 @@ static ssize_t zfcp_sysfs_unit_remove_st write_lock_irq(&zfcp_data.config_lock); unit = zfcp_get_unit_by_lun(port, fcp_lun); - if (unit && (atomic_read(&unit->refcount) == 0)) { - zfcp_unit_get(unit); - atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status); - list_move(&unit->list, &unit_remove_lh); - } else - unit = NULL; + if (unit) { + write_unlock_irq(&zfcp_data.config_lock); + /* wait for possible timeout during SCSI probe */ + flush_work(&unit->scsi_work); + write_lock_irq(&zfcp_data.config_lock); + + if (atomic_read(&unit->refcount) == 0) { + zfcp_unit_get(unit); + atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, + &unit->status); + list_move(&unit->list, &unit_remove_lh); + } else { + unit = NULL; + } + } write_unlock_irq(&zfcp_data.config_lock);