From patchwork Wed Oct 14 13:50:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 7395761 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 229E2BEEA4 for ; Wed, 14 Oct 2015 13:52:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5D47120802 for ; Wed, 14 Oct 2015 13:52:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AAF9D20574 for ; Wed, 14 Oct 2015 13:52:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753796AbbJNNuU (ORCPT ); Wed, 14 Oct 2015 09:50:20 -0400 Received: from mx2.suse.de ([195.135.220.15]:55371 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753692AbbJNNuP (ORCPT ); Wed, 14 Oct 2015 09:50:15 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 94D17AD53; Wed, 14 Oct 2015 13:50:12 +0000 (UTC) From: Johannes Thumshirn To: "James E.J. Bottomley" , Christoph Hellwig , Hannes Reinecke Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn Subject: [PATCH 3/3] SCSI: Rework list handling in __scsi_target_remove Date: Wed, 14 Oct 2015 15:50:08 +0200 Message-Id: <1cfe37e6cb89ede18c88e60578d4293a6eb7430b.1444829611.git.jthumshirn@suse.de> X-Mailer: git-send-email 1.8.5.6 In-Reply-To: References: In-Reply-To: References: Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Rework the list handling in __scsi_target_remove(). The new version introduces a reap list for devices. Devices that shall be removed are placed on the reap list and can then be removed later on. Signed-off-by: Johannes Thumshirn Reviewed-by: Hannes Reinecke --- drivers/scsi/scsi_sysfs.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c index b41dcb3..2bd88c6 100644 --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c @@ -1129,20 +1129,24 @@ static void __scsi_remove_target(struct scsi_target *starget) { struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); unsigned long flags; - struct scsi_device *sdev; + struct scsi_device *sdev, *tmp; + LIST_HEAD(reap_list); spin_lock_irqsave(&shost->device_lock, flags); restart: - list_for_each_entry(sdev, &shost->__devices, siblings) { + list_for_each_entry_safe(sdev, tmp, &shost->__devices, siblings) { if (sdev->channel != starget->channel || sdev->id != starget->id || scsi_device_get(sdev)) continue; - scsi_remove_device(sdev); + list_move_tail(&sdev->siblings, &reap_list); scsi_device_put(sdev); goto restart; } spin_unlock_irqrestore(&shost->device_lock, flags); + + list_for_each_entry_safe(sdev, tmp, &reap_list, siblings) + scsi_remove_device(sdev); } /**