From patchwork Fri May 10 20:23:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13661918 Received: from 008.lax.mailroute.net (008.lax.mailroute.net [199.89.1.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD6C44D9EF for ; Fri, 10 May 2024 20:23:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.1.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715372619; cv=none; b=Ad9+e8Hggg7qxeyhBAbKdnodH8F/H7tDos+H3bIvKyPwbDXSVH3iGsjJ1tQ9JPpbG3zV6dNMXrVZka+noPO0+kweoeaSEPUQPvifGEfiEGoeYS0+v2UjxcHl3Q17jP8dzYtCFlmb8SLLrgnRQlZoBb31Sj0mzVwsmZFau5w2oOo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715372619; c=relaxed/simple; bh=SU48rvFsJmciPJZDbPt/sSt+K7l6wEHLMj/VbI3UBU4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z7dR5X0ClOFepBfWRfBjAZXX2oxDfRPH8ls1jDf7jxPW5tI8dEQQgUUrOf9KAJWthQGpKFg4QOlFJQ6uNyDUDBtzQOZs6EpLsVkoWOeU4sqbvFDW/TRKTl2sKxZHwmj5ua+ID5buP0SEewenh3AO6OyxiNTtE/qRdzD6Vc1XlpA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=Qjve3fli; arc=none smtp.client-ip=199.89.1.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="Qjve3fli" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4VbgLl0s2bz6Cnk97; Fri, 10 May 2024 20:23:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1715372604; x=1717964605; bh=ncpBU YtPwyHbcLGHAP9rZjdTni9O+34Sb/jyhW2bRmA=; b=Qjve3fliwSN+4dt9/DjV1 xyUDw186+m8I7CNedSADT3xoTD04kng16UEk0HnejGpO84ISirQKOLeGX7cFNBAb Q+gsAY1xTcP2fpGER1zawSoZjG25LiJvO4ih6yqhK5E5WdUcjgTM38DPfi58bHdX UcD+THO1TEE8Hkv+zoM4Bs+z04wgDbwU/LmZvjGOSzWYti0+/Q4uxoE9CH6YMaiR UMAsrkKe743WnBAoN2x2AiUjfqs8lg1H7giy9novTrkWXN0FllzzpzXY4gNgETUy e5vr0SenN6skYqQKILE36l88fJR08A5eFAH2vweuzfFt/jfugG16Qn2TeN3Gx5B2 g== X-Virus-Scanned: by MailRoute Received: from 008.lax.mailroute.net ([127.0.0.1]) by localhost (008.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id yr2wsDA8Ulx1; Fri, 10 May 2024 20:23:24 +0000 (UTC) Received: from asus.hsd1.ca.comcast.net (c-73-231-117-72.hsd1.ca.comcast.net [73.231.117.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 008.lax.mailroute.net (Postfix) with ESMTPSA id 4VbgLg18CGz6Cnk8y; Fri, 10 May 2024 20:23:23 +0000 (UTC) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Josef Bacik , Yu Kuai , Markus Pargmann Subject: [PATCH 1/5] nbd: Use NULL to represent a pointer Date: Fri, 10 May 2024 13:23:09 -0700 Message-ID: <20240510202313.25209-2-bvanassche@acm.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240510202313.25209-1-bvanassche@acm.org> References: <20240510202313.25209-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This patch fixes the following sparse warnings: drivers/block/nbd.c: note: in included file (through include/trace/trace_events.h, include/trace/define_trace.h, include/trace/events/nbd.h): ./include/trace/events/nbd.h:61:1: warning: Using plain integer as NULL pointer drivers/block/nbd.c: note: in included file (through include/trace/perf.h, include/trace/define_trace.h, include/trace/events/nbd.h): ./include/trace/events/nbd.h:61:1: warning: Using plain integer as NULL pointer Cc: Christoph Hellwig Cc: Josef Bacik Cc: Yu Kuai Cc: Markus Pargmann Signed-off-by: Bart Van Assche --- include/trace/events/nbd.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/trace/events/nbd.h b/include/trace/events/nbd.h index 9849956f34d8..390d98a05c9d 100644 --- a/include/trace/events/nbd.h +++ b/include/trace/events/nbd.h @@ -72,7 +72,7 @@ DECLARE_EVENT_CLASS(nbd_send_request, ), TP_fast_assign( - __entry->nbd_request = 0; + __entry->nbd_request = NULL; __entry->dev_index = index; __entry->request = rq; ), From patchwork Fri May 10 20:23:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13661919 Received: from 008.lax.mailroute.net (008.lax.mailroute.net [199.89.1.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9518450A66 for ; Fri, 10 May 2024 20:23:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.1.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715372629; cv=none; b=YXOKSu+ffxusYQu4h0CpwSiiteUATJnh4Md83lqyGNkIG2mV7Ff7CLdSyou92S8AfBiNhRlJv1MNXasIXsbr2sNcB7NoDUPYc8Sav9IgAgPzK40p4RvIdApNBXYjtSIRwZUTDARZJzttLPGMNEkt9P0Tjwi1F6aGmQ1YTsMjjD8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715372629; c=relaxed/simple; bh=GGmXYLda3aUshZYlnfpM0J4P6wlT9Bhb4G3DwmMVkKI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HI9ClhoJXpH1ZTzD+27OEX6vk3FWC+sJEtwxQnYRdnwQNcPf/2PWDQ+ymDore5ibtizdHhsPFJy2c3fCfnk7Mojf71BAt5fXdpx6s4QdUNidSppwjkgOyH/+Adc9eYANcKRHWBQsCk8yDpMUpU+slcrTGfOL/jxGXSwCZq3jSVk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=LOcQZjvz; arc=none smtp.client-ip=199.89.1.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="LOcQZjvz" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4VbgLl6Sgpz6Cnk98; Fri, 10 May 2024 20:23:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1715372605; x=1717964606; bh=rKr+Z PSBQvSYhNcTe1Dl+1VPya0C0a3BjPn8yAwdUII=; b=LOcQZjvzUFz9OdGCViS2o HPlx6dFR3chxYii1yrUBBOpsc9ZGgLuFrkgpjyfkMN3M/6pN9uRO6/2LEnKLS+2b an2igFjSjrrcoH3xPzV8RkhOLutQ4jL6z77xEPhI1lMKIcV9q7boRQhiIKoukVS3 KOxTx8SCirKgiwrSRYboj3YLk5akn2j/F0AOjmEg23JsV+RQiy8NItChh4Ion/Ep P5ZqpcFDgC8ztCTNbdYD/1RpT0/XXu+gPMt6PjhfjP5+LMZl9z1BlhFPjrdgZ4BH K6NUusPK14tfHWG1gCVkHqmj3BlOnNBtrz3He4okAFWayqPAxhyDAPb3lFtF0A8V A== X-Virus-Scanned: by MailRoute Received: from 008.lax.mailroute.net ([127.0.0.1]) by localhost (008.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id EvCOWkilxcSy; Fri, 10 May 2024 20:23:25 +0000 (UTC) Received: from asus.hsd1.ca.comcast.net (c-73-231-117-72.hsd1.ca.comcast.net [73.231.117.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 008.lax.mailroute.net (Postfix) with ESMTPSA id 4VbgLh1G7Mz6Cnk90; Fri, 10 May 2024 20:23:24 +0000 (UTC) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Josef Bacik , Yu Kuai , Markus Pargmann Subject: [PATCH 2/5] nbd: Remove superfluous casts Date: Fri, 10 May 2024 13:23:10 -0700 Message-ID: <20240510202313.25209-3-bvanassche@acm.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240510202313.25209-1-bvanassche@acm.org> References: <20240510202313.25209-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In Linux kernel code it is preferred not to use a cast when converting a void pointer to another pointer type. Cc: Christoph Hellwig Cc: Josef Bacik Cc: Yu Kuai Cc: Markus Pargmann Signed-off-by: Bart Van Assche --- drivers/block/nbd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 9d4ec9273bf9..90760f27824d 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -222,7 +222,7 @@ static ssize_t pid_show(struct device *dev, struct device_attribute *attr, char *buf) { struct gendisk *disk = dev_to_disk(dev); - struct nbd_device *nbd = (struct nbd_device *)disk->private_data; + struct nbd_device *nbd = disk->private_data; return sprintf(buf, "%d\n", nbd->pid); } @@ -236,7 +236,7 @@ static ssize_t backend_show(struct device *dev, struct device_attribute *attr, char *buf) { struct gendisk *disk = dev_to_disk(dev); - struct nbd_device *nbd = (struct nbd_device *)disk->private_data; + struct nbd_device *nbd = disk->private_data; return sprintf(buf, "%s\n", nbd->backend ?: ""); } From patchwork Fri May 10 20:23:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13661920 Received: from 008.lax.mailroute.net (008.lax.mailroute.net [199.89.1.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 874205027B for ; Fri, 10 May 2024 20:23:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.1.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715372635; cv=none; b=rE/tsYGFzCzDcJl00H0GQjUM/H9CG1qgC1w31UcjZiMOcXjOPP3ZF01/uv95Abg6cvom8Ip8jHtDTvHiOGheVn0ao83IiZNfCsqClOd9KI4MXXBWiLS0TDpEMf4jl8qP3RAmeItM0mb7KQ5S2+tqdH8buodSTmL85+h7fUNZBm0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715372635; c=relaxed/simple; bh=eqeh6JylJkKjgBXxnvqmNvWKa9WriJ/6Tut3n+L8cGM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Htapa6I9HunCfWTT9LF4ytqIMnwRM3fdgsYJ+5cfSCSWAFb4XIP2uPdCRrnukGOx2jjYne89RvIGv4Y5prRy98oA1OKDsWpfk5GkRkGDtlbzIAsvx7hodZdCrivEhePgJY/OW2zEEI5Onjz0rWdAvkWfKosQLk1oBoiOUKLQN9Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=ABhxr71z; arc=none smtp.client-ip=199.89.1.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="ABhxr71z" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4VbgLn24rTz6Cnk90; Fri, 10 May 2024 20:23:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1715372606; x=1717964607; bh=ZJUhX WOuyzwWrWPwZjQW4ihwlG1UQ5bqT512VQlm9Y8=; b=ABhxr71z4lDpVIVJ/uyRN 1Awal/jGUExyWSiQZP0ADzrahgJpeR6SdRlKFfGC9ISh7Mn/ItwkcyMoW9nem3En hOQQfKzTJNPO0k6ti90wlxd7lsMGE3P6iO6X8wTVZhlcOVclRuY6XLeTCIE0RD9Q XN6mZKMGQqPfWIT1i7bAfLW/T806J6wtZ5JVBaRBivTnSTaOHwSN0sNhXGSscDRK ILuPnjgV8rfmDtX2D5UOJILkZUrd7qUOzxFVilFlK7GLm42zxZ63m9HKyN/2nOVG jqijLskYjo9ZCVVcQD6zTw4dePDy3VQGZ618hJJ8xLY79+XfsQV5Qtk2cD+EQ3Kl Q== X-Virus-Scanned: by MailRoute Received: from 008.lax.mailroute.net ([127.0.0.1]) by localhost (008.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id yCJYxpLGo6yk; Fri, 10 May 2024 20:23:26 +0000 (UTC) Received: from asus.hsd1.ca.comcast.net (c-73-231-117-72.hsd1.ca.comcast.net [73.231.117.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 008.lax.mailroute.net (Postfix) with ESMTPSA id 4VbgLj1Nklz6Cnk8s; Fri, 10 May 2024 20:23:25 +0000 (UTC) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Josef Bacik , Yu Kuai , Markus Pargmann Subject: [PATCH 3/5] nbd: Improve the documentation of the locking assumptions Date: Fri, 10 May 2024 13:23:11 -0700 Message-ID: <20240510202313.25209-4-bvanassche@acm.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240510202313.25209-1-bvanassche@acm.org> References: <20240510202313.25209-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Document locking assumptions with lockdep_assert_held() instead of source code comments. The advantage of lockdep_assert_held() is that it is verified at runtime if lockdep is enabled in the kernel config. Cc: Christoph Hellwig Cc: Josef Bacik Cc: Yu Kuai Cc: Markus Pargmann Signed-off-by: Bart Van Assche --- drivers/block/nbd.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 90760f27824d..05f69710afe8 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -588,7 +588,6 @@ static inline int was_interrupted(int result) return result == -ERESTARTSYS || result == -EINTR; } -/* always call with the tx_lock held */ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index) { struct request *req = blk_mq_rq_from_pdu(cmd); @@ -605,6 +604,9 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index) u32 nbd_cmd_flags = 0; int sent = nsock->sent, skip = 0; + lockdep_assert_held(&cmd->lock); + lockdep_assert_held(&nsock->tx_lock); + iov_iter_kvec(&from, ITER_SOURCE, &iov, 1, sizeof(request)); type = req_to_nbd_cmd_type(req); @@ -1015,6 +1017,8 @@ static int nbd_handle_cmd(struct nbd_cmd *cmd, int index) struct nbd_sock *nsock; int ret; + lockdep_assert_held(&cmd->lock); + config = nbd_get_config_unlocked(nbd); if (!config) { dev_err_ratelimited(disk_to_dev(nbd->disk), From patchwork Fri May 10 20:23:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13661921 Received: from 008.lax.mailroute.net (008.lax.mailroute.net [199.89.1.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4F0445BEC for ; Fri, 10 May 2024 20:23:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.1.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715372639; cv=none; b=iL37Z03HapKy1tPRoFM2UaOR05ay5zfmsnAa5KYHDDtbssSOqfbfgEaRnmNEqMmMh3CTDwR++DAyAySi0NR23GeLZe7WBUqtlzzDO2+y9mrgInVdZr+ZRNkGiu9JAvJkIh/Ya9aRW1fIyWHXtP7MOWsreurg3PlmEedtR8Xfi+E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715372639; c=relaxed/simple; bh=tMQAzzorkRLy2Oo0O06lHPU7O8QBYrRB210rj5jjXyA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ffLI5A3g305vi3webKpSs5qKC1yuET64qN2vl1sH2ViSXHKPZ+WtRnjq0B3ZIJTuUQ4/MHjvKZQ20XLy+scUiA2Vfr+q2aspI/NgscpANyr3wg0HIkJ33ueIHCGfpNoVCeSicrVO498kvBKz1dmp6lvcI/dAoLC04yDLLKiuYjg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=0VKORnCw; arc=none smtp.client-ip=199.89.1.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="0VKORnCw" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4VbgLp55Vcz6Cnk8s; Fri, 10 May 2024 20:23:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1715372607; x=1717964608; bh=H2iwq Gm2MBWmx2IQ7zvyluZvsqTbVwqEiMhPPsPHgXU=; b=0VKORnCw5vApyIsRSsrhV ThILbu0xIaYz6nAkngPWD5hvVoBefggWg8g9M2GUSDXTdhwAxryUR1iNy/BictEg rAVoG85Qfa95fNSt80UyMh0pYBIvEddbop4kpG7KmKhtbwN4HYZ7lPjKElORYq6Y jWIpZHpD9wXl5QRvRXIhkIrGI8xgBcWiHXeU4GsUU0Kt688BKm17r2WhwSZ9w5+W QNUBxo+ZSinflSXvPEuFWlTKZbAUe/vHJbdb4yDZPKTejxjddWQZ5ItR16BCUroO oXWqOSkdqb+0hXw7fBtYsvqoSiOeV5iPDWV5oo0rHwYgN1mPoRU754ERVGKL2oWW w== X-Virus-Scanned: by MailRoute Received: from 008.lax.mailroute.net ([127.0.0.1]) by localhost (008.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id vbVrQSFGnp7S; Fri, 10 May 2024 20:23:27 +0000 (UTC) Received: from asus.hsd1.ca.comcast.net (c-73-231-117-72.hsd1.ca.comcast.net [73.231.117.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 008.lax.mailroute.net (Postfix) with ESMTPSA id 4VbgLk1YgWz6Cnk95; Fri, 10 May 2024 20:23:26 +0000 (UTC) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Josef Bacik , Yu Kuai , Markus Pargmann Subject: [PATCH 4/5] nbd: Remove a local variable from nbd_send_cmd() Date: Fri, 10 May 2024 13:23:12 -0700 Message-ID: <20240510202313.25209-5-bvanassche@acm.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240510202313.25209-1-bvanassche@acm.org> References: <20240510202313.25209-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 blk_rq_bytes() returns an unsigned int while 'size' has type unsigned long. This is confusing. Improve code readability by removing the local variable 'size'. Cc: Christoph Hellwig Cc: Josef Bacik Cc: Yu Kuai Cc: Markus Pargmann Signed-off-by: Bart Van Assche --- drivers/block/nbd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 05f69710afe8..29e43ab1650c 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -597,7 +597,6 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index) struct nbd_request request = {.magic = htonl(NBD_REQUEST_MAGIC)}; struct kvec iov = {.iov_base = &request, .iov_len = sizeof(request)}; struct iov_iter from; - unsigned long size = blk_rq_bytes(req); struct bio *bio; u64 handle; u32 type; @@ -646,7 +645,7 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index) request.type = htonl(type | nbd_cmd_flags); if (type != NBD_CMD_FLUSH) { request.from = cpu_to_be64((u64)blk_rq_pos(req) << 9); - request.len = htonl(size); + request.len = htonl(blk_rq_bytes(req)); } handle = nbd_cmd_handle(cmd); request.cookie = cpu_to_be64(handle); From patchwork Fri May 10 20:23:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13661922 Received: from 008.lax.mailroute.net (008.lax.mailroute.net [199.89.1.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 64D3A5028A; Fri, 10 May 2024 20:23:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.1.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715372643; cv=none; b=KMnw1hpj2NDHuXcFmLSh3tVN0NhePqXW6cpwOunqB9Jd26yG3ac8duyunweo6QjbgRKjOSml5DUuOu19wwZKyI22Xiz6xeVCbjGX9dhbi3KOrpBneQ51ZTTiIyquTCjisA7U3VMXG6JEmhDrHUVMfO9eNrDxXW1Za4xjSAf4Bpw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715372643; c=relaxed/simple; bh=+lwJebfu+is0C5ZFW/N58T0glXMTb8j4kdQ+8l6sE5c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hptN3aC6fUjmYvOJO3XFxIgjmH5R9HZFqtAR+te/I5o0UQFnKL9pPfrlXAsX9UMe8n+eevg8T2/ZqspJ4AQjjAzBysfS7ULVZjO/cWlU9mXqmAS2ZiByEes+IBh1pcHQNK3aWjjam63KyX/ESQ50AX3IB1PfVe6LdJgDekxfWOQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=EdX7PlBx; arc=none smtp.client-ip=199.89.1.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="EdX7PlBx" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4VbgLt6ql4z6Cnk95; Fri, 10 May 2024 20:23:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1715372608; x=1717964609; bh=OdB1l /QW8mmPj53pOGxXVfdkmJXzlBmjUEF1G2X1fQQ=; b=EdX7PlBx8/nke0an3J4Gy az+/Gc+opZwjZOJI1X9YFceoNSTKIAuAcRZia+xBIWd9uyWZMDdq1XMFs8w8oo0r uFJWGmDRwaEryNrx4GJQ+vIXLQyt8TSWFiez/AM1CQpsisG+kL/YiRncIaqnuXhZ kRm+qe0XFMOB7eFwxKNd7010wTvctg1ubOahf7RCik1uO4jhGiP+tTUvvOhjADbg nSmi2zZgx01BcEei9lHJLU32OdAQgzGi46zUe7ob+W/PNADfNQ+ROk32RcALiwAS ilWmJAkxLsYnGvkjxRwfdU2CTDOj0DtIETT5yax9nIA13bF+gqOFmlJMCypFZ3lI g== X-Virus-Scanned: by MailRoute Received: from 008.lax.mailroute.net ([127.0.0.1]) by localhost (008.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id 1fI7r24ppDBx; Fri, 10 May 2024 20:23:28 +0000 (UTC) Received: from asus.hsd1.ca.comcast.net (c-73-231-117-72.hsd1.ca.comcast.net [73.231.117.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 008.lax.mailroute.net (Postfix) with ESMTPSA id 4VbgLl1jRsz6Cnk8y; Fri, 10 May 2024 20:23:27 +0000 (UTC) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Josef Bacik , Yu Kuai , Markus Pargmann , stable@vger.kernel.org Subject: [PATCH 5/5] nbd: Fix signal handling Date: Fri, 10 May 2024 13:23:13 -0700 Message-ID: <20240510202313.25209-6-bvanassche@acm.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240510202313.25209-1-bvanassche@acm.org> References: <20240510202313.25209-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Both nbd_send_cmd() and nbd_handle_cmd() return either a negative error number or a positive blk_status_t value. nbd_queue_rq() converts these return values into a blk_status_t value. There is a bug in the conversion code: if nbd_send_cmd() returns BLK_STS_RESOURCE, nbd_queue_rq() should return BLK_STS_RESOURCE instead of BLK_STS_OK. Fix this, move the conversion code into nbd_handle_cmd() and fix the remaining sparse warnings. This patch fixes the following sparse warnings: drivers/block/nbd.c:673:32: warning: incorrect type in return expression (different base types) drivers/block/nbd.c:673:32: expected int drivers/block/nbd.c:673:32: got restricted blk_status_t [usertype] drivers/block/nbd.c:714:48: warning: incorrect type in return expression (different base types) drivers/block/nbd.c:714:48: expected int drivers/block/nbd.c:714:48: got restricted blk_status_t [usertype] drivers/block/nbd.c:1120:21: warning: incorrect type in assignment (different base types) drivers/block/nbd.c:1120:21: expected int [assigned] ret drivers/block/nbd.c:1120:21: got restricted blk_status_t [usertype] drivers/block/nbd.c:1125:16: warning: incorrect type in return expression (different base types) drivers/block/nbd.c:1125:16: expected restricted blk_status_t drivers/block/nbd.c:1125:16: got int [assigned] ret Cc: Christoph Hellwig Cc: Josef Bacik Cc: Yu Kuai Cc: Markus Pargmann Fixes: fc17b6534eb8 ("blk-mq: switch ->queue_rq return value to blk_status_t") Cc: stable@vger.kernel.org Signed-off-by: Bart Van Assche --- drivers/block/nbd.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 29e43ab1650c..22a79a62cc4e 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -588,6 +588,10 @@ static inline int was_interrupted(int result) return result == -ERESTARTSYS || result == -EINTR; } +/* + * Returns BLK_STS_RESOURCE if the caller should retry after a delay. Returns + * -EAGAIN if the caller should requeue @cmd. Returns -EIO if sending failed. + */ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index) { struct request *req = blk_mq_rq_from_pdu(cmd); @@ -670,7 +674,7 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index) nsock->sent = sent; } set_bit(NBD_CMD_REQUEUED, &cmd->flags); - return BLK_STS_RESOURCE; + return (__force int)BLK_STS_RESOURCE; } dev_err_ratelimited(disk_to_dev(nbd->disk), "Send control failed (result %d)\n", result); @@ -711,7 +715,7 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index) nsock->pending = req; nsock->sent = sent; set_bit(NBD_CMD_REQUEUED, &cmd->flags); - return BLK_STS_RESOURCE; + return (__force int)BLK_STS_RESOURCE; } dev_err(disk_to_dev(nbd->disk), "Send data failed (result %d)\n", @@ -1008,7 +1012,7 @@ static int wait_for_reconnect(struct nbd_device *nbd) return !test_bit(NBD_RT_DISCONNECTED, &config->runtime_flags); } -static int nbd_handle_cmd(struct nbd_cmd *cmd, int index) +static blk_status_t nbd_handle_cmd(struct nbd_cmd *cmd, int index) { struct request *req = blk_mq_rq_from_pdu(cmd); struct nbd_device *nbd = cmd->nbd; @@ -1022,14 +1026,14 @@ static int nbd_handle_cmd(struct nbd_cmd *cmd, int index) if (!config) { dev_err_ratelimited(disk_to_dev(nbd->disk), "Socks array is empty\n"); - return -EINVAL; + return BLK_STS_IOERR; } if (index >= config->num_connections) { dev_err_ratelimited(disk_to_dev(nbd->disk), "Attempted send on invalid socket\n"); nbd_config_put(nbd); - return -EINVAL; + return BLK_STS_IOERR; } cmd->status = BLK_STS_OK; again: @@ -1052,7 +1056,7 @@ static int nbd_handle_cmd(struct nbd_cmd *cmd, int index) */ sock_shutdown(nbd); nbd_config_put(nbd); - return -EIO; + return BLK_STS_IOERR; } goto again; } @@ -1065,7 +1069,7 @@ static int nbd_handle_cmd(struct nbd_cmd *cmd, int index) blk_mq_start_request(req); if (unlikely(nsock->pending && nsock->pending != req)) { nbd_requeue_cmd(cmd); - ret = 0; + ret = BLK_STS_OK; goto out; } /* @@ -1084,19 +1088,19 @@ static int nbd_handle_cmd(struct nbd_cmd *cmd, int index) "Request send failed, requeueing\n"); nbd_mark_nsock_dead(nbd, nsock, 1); nbd_requeue_cmd(cmd); - ret = 0; + ret = BLK_STS_OK; } out: mutex_unlock(&nsock->tx_lock); nbd_config_put(nbd); - return ret; + return ret < 0 ? BLK_STS_IOERR : (__force blk_status_t)ret; } static blk_status_t nbd_queue_rq(struct blk_mq_hw_ctx *hctx, const struct blk_mq_queue_data *bd) { struct nbd_cmd *cmd = blk_mq_rq_to_pdu(bd->rq); - int ret; + blk_status_t ret; /* * Since we look at the bio's to send the request over the network we @@ -1116,10 +1120,6 @@ static blk_status_t nbd_queue_rq(struct blk_mq_hw_ctx *hctx, * appropriate. */ ret = nbd_handle_cmd(cmd, hctx->queue_num); - if (ret < 0) - ret = BLK_STS_IOERR; - else if (!ret) - ret = BLK_STS_OK; mutex_unlock(&cmd->lock); return ret;