From patchwork Tue Oct 24 19:57:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10025447 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9DDB260375 for ; Tue, 24 Oct 2017 19:57:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8EC6D28A67 for ; Tue, 24 Oct 2017 19:57:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 83B5828A6A; Tue, 24 Oct 2017 19:57:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E959C28A67 for ; Tue, 24 Oct 2017 19:57:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932211AbdJXT5Y (ORCPT ); Tue, 24 Oct 2017 15:57:24 -0400 Received: from mail-qt0-f194.google.com ([209.85.216.194]:45116 "EHLO mail-qt0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932281AbdJXT5V (ORCPT ); Tue, 24 Oct 2017 15:57:21 -0400 Received: by mail-qt0-f194.google.com with SMTP id p1so32020831qtg.2 for ; Tue, 24 Oct 2017 12:57:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=oaUC3e0k2RGVsl8qpEpvcr6OCY2+mHj2QkZLWtcDYSI=; b=D7s2sOyIBjGOwZYXNoD1On9UybjctYOiWkNS79pTDi2ebvBXofJUv8Qhvyr7HaPiKU q8w6kxMaLmdV5jbrbPDmii/+C86vRmfkxqTVS22LThPV9PgSHoNT2ijmNWyV5YFBVNSW ycTEOoIAwzFLPPrJ++YY5jI+x4e1dFBBluINP4LSui5cSoq93jBIpUjis5kPQGtnly1L tPvxnpj8DpGOan6DV0tnIlZzp8eItPdHZfSYpSaJnFW58eBhD5BqD/3DO+w6cVWQMz+G I4d2L1P7YfEpptdER8vlEHENUb9dkSI+59sJVTossKoEvDSk5Em6SnqOOyvcByDXy8lI hPUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=oaUC3e0k2RGVsl8qpEpvcr6OCY2+mHj2QkZLWtcDYSI=; b=fitEhtMF3m7AL/8ITUZ/Z04XORkv7+gnvzAOJc864eFpiItAWVz7IaJA2/68J2X88p kLszv/kAFPcvscFKAQc/uKwRwxzUfOHTEKzy0ICOrRKSSUipwCCiWnxEkkQtbJIOeDcd zeyRj4TnD2hAQuwkSiaehwa4jnfN3lS6Ecre50TrlC99RR4+MzZlUPEy2FaKROLbhKLp RPCYrQcELY7oLkiPz5voEkBoO/EWOaFglw63GU2Rh9GV/X/sMR/cct/33xTxT7CNA0iP Ckt/mfdrgZCGCQDV3pweQf2EH2hrkYHcMWcgw/WMT0/WUwf7IvLzkD5kU/bZcLvb4B9w sTpQ== X-Gm-Message-State: AMCzsaUQgpvrz1z6j73m/fQBmd0bi/XjZISz/Xo9CmuZulIIG2oVT4PT x2bDa6adyj8YZ7GbYH0xVOqBMlY7 X-Google-Smtp-Source: ABhQp+RW1LSQ4a5K1wPlU7PTjMRR7Pgz0PP1211P0HKmlHS/EGct4gTyuGusuFYUYenLyFLcardA0Q== X-Received: by 10.200.51.170 with SMTP id c39mr26066390qtb.216.1508875040285; Tue, 24 Oct 2017 12:57:20 -0700 (PDT) Received: from localhost ([2606:a000:4381:1201:225:22ff:feb3:e51a]) by smtp.gmail.com with ESMTPSA id n44sm800854qtb.41.2017.10.24.12.57.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Oct 2017 12:57:19 -0700 (PDT) From: Josef Bacik To: axboe@kernel.dk, nbd@other.debian.org, linux-block@vger.kernel.org, kernel-team@fb.com Cc: Josef Bacik , stable@vger.kernel.org Subject: [PATCH] nbd: handle interrupted sendmsg with a sndtimeo set Date: Tue, 24 Oct 2017 15:57:18 -0400 Message-Id: <1508875038-3397-1-git-send-email-josef@toxicpanda.com> X-Mailer: git-send-email 2.7.5 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Josef Bacik If you do not set sk_sndtimeo you will get -ERESTARTSYS if there is a pending signal when you enter sendmsg, which we handle properly. However if you set a timeout for your commands we'll set sk_sndtimeo to that timeout, which means that sendmsg will start returning -EINTR instead of -ERESTARTSYS. Fix this by checking either cases and doing the correct thing. Cc: stable@vger.kernel.org Fixes: dc88e34d69d8 ("nbd: set sk->sk_sndtimeo for our sockets") Reported-and-tested-by: Daniel Xu Signed-off-by: Josef Bacik --- drivers/block/nbd.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 528e6f6951cc..8c3aa7ae79c8 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -378,6 +378,15 @@ static int sock_xmit(struct nbd_device *nbd, int index, int send, return result; } +/* + * Different settings for sk->sk_sndtimeo can result in different return values + * if there is a signal pending when we enter sendmsg, because reasons? + */ +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) { @@ -450,7 +459,7 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index) result = sock_xmit(nbd, index, 1, &from, (type == NBD_CMD_WRITE) ? MSG_MORE : 0, &sent); if (result <= 0) { - if (result == -ERESTARTSYS) { + if (was_interrupted(result)) { /* If we havne't sent anything we can just return BUSY, * however if we have sent something we need to make * sure we only allow this req to be sent until we are @@ -494,7 +503,7 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index) } result = sock_xmit(nbd, index, 1, &from, flags, &sent); if (result <= 0) { - if (result == -ERESTARTSYS) { + if (was_interrupted(result)) { /* We've already sent the header, we * have no choice but to set pending and * return BUSY.