From patchwork Wed Oct 14 13:50:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 7395751 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 4C9729F37F for ; Wed, 14 Oct 2015 13:52:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 691CA206B0 for ; Wed, 14 Oct 2015 13:52:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8CB0120574 for ; Wed, 14 Oct 2015 13:52:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753866AbbJNNuU (ORCPT ); Wed, 14 Oct 2015 09:50:20 -0400 Received: from mx2.suse.de ([195.135.220.15]:55373 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753716AbbJNNuP (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 relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 94F91AD56; 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 2/3] SCSI: Rework list handling in scsi_target_remove Date: Wed, 14 Oct 2015 15:50:07 +0200 Message-Id: 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 targets. Targets that shall be removed are placed on the reap list and can then be reaped later on. Signed-off-by: Johannes Thumshirn Reviewed-by: Hannes Reinecke --- drivers/scsi/scsi_sysfs.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c index d7afea9..b41dcb3 100644 --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c @@ -1156,31 +1156,28 @@ static void __scsi_remove_target(struct scsi_target *starget) void scsi_remove_target(struct device *dev) { struct Scsi_Host *shost = dev_to_shost(dev->parent); - struct scsi_target *starget, *last = NULL; + struct scsi_target *starget, *tmp; unsigned long flags; + LIST_HEAD(reap_list); /* remove targets being careful to lookup next entry before * deleting the last */ spin_lock_irqsave(&shost->target_lock, flags); - list_for_each_entry(starget, &shost->__targets, siblings) { + list_for_each_entry_safe(starget, tmp, &shost->__targets, siblings) { if (starget->state == STARGET_DEL) continue; if (starget->dev.parent == dev || &starget->dev == dev) { - /* assuming new targets arrive at the end */ kref_get(&starget->reap_ref); - spin_unlock_irqrestore(&shost->target_lock, flags); - if (last) - scsi_target_reap(last); - last = starget; - __scsi_remove_target(starget); - spin_lock_irqsave(&shost->target_lock, flags); + list_move_tail(&starget->siblings, &reap_list); } } spin_unlock_irqrestore(&shost->target_lock, flags); - if (last) - scsi_target_reap(last); + list_for_each_entry_safe(starget, tmp, &reap_list, siblings) { + __scsi_remove_target(starget); + scsi_target_reap(starget); + } } EXPORT_SYMBOL(scsi_remove_target);