Received: by 2002:ab2:6c55:0:b0:1fd:c486:4f03 with SMTP id v21csp294729lqp; Wed, 12 Jun 2024 01:34:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX2XTyYwW5xSTUo4kRAncgUj3eiiQpBB55Bpu3lU8FLfLcdtI8TkjbPr6j27jS632UVu8Ov3nNsjd2dYSJK45DMzQVI8W5IIfSOiAZW9Q== X-Google-Smtp-Source: AGHT+IGB3PGF5VaWpXAdHF7q8UAlopo2qv4IPkLCVySWowuM299qdKiMn0r+HDFnHQibwLBozrS2 X-Received: by 2002:a05:6808:17a6:b0:3d2:1b8a:be60 with SMTP id 5614622812f47-3d23e107323mr1383968b6e.42.1718181244414; Wed, 12 Jun 2024 01:34:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718181244; cv=pass; d=google.com; s=arc-20160816; b=NSH06yy3uZHwnwLpCFBF810LiRlYqGr874csj5D98KS7jVCEcTa4IUj/IXiFOOY+zL Id5yv8H/u/bO4BwQfjAEtp3TdjujLl/eU2hAFm6aVOZYVQ5ipTFZc6EIQBidehexRtTe 9N7ntM+YSmFhuC6GvWJgiDEKxTciVSwMxyO2MMBG5YnOOLY+3E9tneZXieB1jfrETQn3 a0fNsPkiyP8rqgUqNsJ8u0ea2orEA0em9VEVYGSdqNkRGU8w8cRHrCSD+aDzzz3cKxWT JfKu48J1H0xUmzhS7UvhXLyeO9DZhOaAt3cjPCXgrBeKQU4zBn7RJsSkk6WH8qmnAENO G8OA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature :dkim-signature:dkim-signature:dkim-signature; bh=ueJMaSkE900pfLLr+27qj+1ZIC482XYU/yIHmHljQ/4=; fh=n0sOl15TccyvXnP3jeDpUea26/MHQHfjh5YbMtD4cCE=; b=Xc3P26MfzebKADjkIAeEYhgYVRR23Qc1YTzIdqTgyDTnDXdBfyxUU98BboavNImoG3 9UPxaUpMwcdrVO3nPdiSGp/KHDMBdMepsnmWoceJ/k7AJfcnjq5cznolhTVzmmeeXAYD PrdkUsY80QIEYvPHrbZaAK8o2qrZUSNjqxLzxZUD4gbgc1orqjsZrTg5ZreCBD3sHakI XbAFPkfaCh/xw5FfO4bpQK3BqRjzzJDL2QDaCsUb3y+GlICycimFD+SOZqkxpDxZON71 CihzvSN0852WKNNR4Hw8BATEeJyb5II+Xf/uaC5l058f0AYNEEdjR9n2GIH1DUrQ0hNP Gvzg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=t1AnBKfU; dkim=neutral (no key) header.i=@suse.de; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=t1AnBKfU; dkim=neutral (no key) header.i=@suse.de; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-211186-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-211186-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d2e1a72fcca58-704322a1083si6398949b3a.360.2024.06.12.01.34.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 01:34:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-211186-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=t1AnBKfU; dkim=neutral (no key) header.i=@suse.de; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=t1AnBKfU; dkim=neutral (no key) header.i=@suse.de; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-211186-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-211186-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 09CE6283701 for ; Wed, 12 Jun 2024 08:33:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5AA7A16D322; Wed, 12 Jun 2024 08:33:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="t1AnBKfU"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="t8nVDWOx"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="t1AnBKfU"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="t8nVDWOx" Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B4E7484A22; Wed, 12 Jun 2024 08:33:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718181226; cv=none; b=iIdbp2xJSC+BMXBhiDEFb0ibCFNvZONoOfhMGic3gNFI/D11oMQ8BUc+Rcw8dQ1GgzOTREYf+je21YZcAEnBHakTJPwaeIwrRzgW3suMw5uHjkiH020rNadIR23xEITEGj7ASbcWGSef7LDQSAdhFakgP6zK+qXzZ35iA6+l3HE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718181226; c=relaxed/simple; bh=SuEdPAV6zFASfN6QuboL4vVbuP0MOntQ0ttRpzAV9so=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type; b=o2womhZBgM6wg2rIpOn3DCMj3aeE0yj9aUU5Vj/PpmKDNgOjilGH1bd1CGwlemDpVarOqECUCAkMWn3nCUhPHKO0TjDpnM0Go1ow05MUPT7XI0+0to4MZu1K6BWTGr8eGPIljIv4EUKmNRTpFZt4sKJb5kke/ge5Izegp8IdxlY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=t1AnBKfU; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=t8nVDWOx; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=t1AnBKfU; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=t8nVDWOx; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id D5432226A9; Wed, 12 Jun 2024 08:33:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718181222; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ueJMaSkE900pfLLr+27qj+1ZIC482XYU/yIHmHljQ/4=; b=t1AnBKfUF2RsbukpwJEfKaR1aPiqW1F1d+/Q0r/QLz8lTJKWhEUL+idN6Lh9dfM8EFHgq6 FvLqysXp7HuSSgb6vtaFelblMCdh3cz+DYfxaXmpKWbsKaZluoquULwdo/zKjCh0WpSJSd ILFxKeGod39vM2r9OVcHeKNh0SXOxdw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718181222; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ueJMaSkE900pfLLr+27qj+1ZIC482XYU/yIHmHljQ/4=; b=t8nVDWOxFes9cP2i9pSMJXoLhEbVHkPGibpmfF4ugEBpcQU0ghtUHo2DFJz56jxndOrJsX dAHfi2ie+JB4tyCQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718181222; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ueJMaSkE900pfLLr+27qj+1ZIC482XYU/yIHmHljQ/4=; b=t1AnBKfUF2RsbukpwJEfKaR1aPiqW1F1d+/Q0r/QLz8lTJKWhEUL+idN6Lh9dfM8EFHgq6 FvLqysXp7HuSSgb6vtaFelblMCdh3cz+DYfxaXmpKWbsKaZluoquULwdo/zKjCh0WpSJSd ILFxKeGod39vM2r9OVcHeKNh0SXOxdw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718181222; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ueJMaSkE900pfLLr+27qj+1ZIC482XYU/yIHmHljQ/4=; b=t8nVDWOxFes9cP2i9pSMJXoLhEbVHkPGibpmfF4ugEBpcQU0ghtUHo2DFJz56jxndOrJsX dAHfi2ie+JB4tyCQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id C019C1372E; Wed, 12 Jun 2024 08:33:42 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id UnetLGZdaWZGXgAAD6G6ig (envelope-from ); Wed, 12 Jun 2024 08:33:42 +0000 Message-ID: <3b24ef4a-996b-4a8b-89f3-385872573039@suse.de> Date: Wed, 12 Jun 2024 10:33:42 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 1/3] scsi: core: Add new helper to iterate all devices of host To: Wenchao Hao , "James E . J . Bottomley" , "Martin K . Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org References: <20240605091731.3111195-1-haowenchao22@gmail.com> <20240605091731.3111195-2-haowenchao22@gmail.com> Content-Language: en-US From: Hannes Reinecke In-Reply-To: <20240605091731.3111195-2-haowenchao22@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Score: -4.29 X-Spam-Level: X-Spam-Flag: NO X-Spamd-Result: default: False [-4.29 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-0.993]; MIME_GOOD(-0.10)[text/plain]; XM_UA_NO_VERSION(0.01)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; FREEMAIL_TO(0.00)[gmail.com,HansenPartnership.com,oracle.com,vger.kernel.org]; RCVD_VIA_SMTP_AUTH(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_FIVE(0.00)[5]; RCVD_TLS_ALL(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FUZZY_BLOCKED(0.00)[rspamd.com]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,imap1.dmz-prg2.suse.org:helo] On 6/5/24 11:17, Wenchao Hao wrote: > shost_for_each_device() would skip devices which is in SDEV_CANCEL or > SDEV_DEL state, for some scenarios, we donot want to skip these devices, > so add a new macro shost_for_each_device_include_deleted() to handle it. > > Following changes are introduced: > > 1. Rework scsi_device_get(), add new helper __scsi_device_get() which > determine if skip deleted scsi_device by parameter "skip_deleted". > 2. Add new parameter "skip_deleted" to __scsi_iterate_devices() which > is used when calling __scsi_device_get() > 3. Update shost_for_each_device() to call __scsi_iterate_devices() with > "skip_deleted" true > 4. Add new macro shost_for_each_device_include_deleted() which call > __scsi_iterate_devices() with "skip_deleted" false > > Signed-off-by: Wenchao Hao > --- > drivers/scsi/scsi.c | 46 ++++++++++++++++++++++++++------------ > include/scsi/scsi_device.h | 25 ++++++++++++++++++--- > 2 files changed, 54 insertions(+), 17 deletions(-) > > diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c > index 3e0c0381277a..5913de543d93 100644 > --- a/drivers/scsi/scsi.c > +++ b/drivers/scsi/scsi.c > @@ -735,20 +735,18 @@ int scsi_cdl_enable(struct scsi_device *sdev, bool enable) > return 0; > } > > -/** > - * scsi_device_get - get an additional reference to a scsi_device > +/* > + * __scsi_device_get - get an additional reference to a scsi_device > * @sdev: device to get a reference to > - * > - * Description: Gets a reference to the scsi_device and increments the use count > - * of the underlying LLDD module. You must hold host_lock of the > - * parent Scsi_Host or already have a reference when calling this. > - * > - * This will fail if a device is deleted or cancelled, or when the LLD module > - * is in the process of being unloaded. > + * @skip_deleted: when true, would return failed if device is deleted > */ > -int scsi_device_get(struct scsi_device *sdev) > +static int __scsi_device_get(struct scsi_device *sdev, bool skip_deleted) > { > - if (sdev->sdev_state == SDEV_DEL || sdev->sdev_state == SDEV_CANCEL) > + /* > + * if skip_deleted is true and device is in removing, return failed > + */ > + if (skip_deleted && > + (sdev->sdev_state == SDEV_DEL || sdev->sdev_state == SDEV_CANCEL)) > goto fail; Nack. SDEV_DEL means the device is about to be deleted, so we _must not_ access it at all. Cheers, Hannes -- Dr. Hannes Reinecke Kernel Storage Architect hare@suse.de +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich