From patchwork Mon Sep 17 13:16:30 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Derr X-Patchwork-Id: 1467161 Return-Path: X-Original-To: patchwork-v9fs-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) by patchwork2.kernel.org (Postfix) with ESMTP id 74B86DF2D8 for ; Mon, 17 Sep 2012 13:41:58 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-1.b.ch3.sourceforge.com) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1TDba1-0004JD-SX; Mon, 17 Sep 2012 13:41:41 +0000 Received: from sog-mx-3.v43.ch3.sourceforge.com ([172.29.43.193] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1TDba1-0004Iy-95 for v9fs-developer@lists.sourceforge.net; Mon, 17 Sep 2012 13:41:41 +0000 X-ACL-Warn: Received: from ecfrec.frec.bull.fr ([129.183.4.8]) by sog-mx-3.v43.ch3.sourceforge.com with esmtp (Exim 4.76) id 1TDbZq-0007Av-Bb for v9fs-developer@lists.sourceforge.net; Mon, 17 Sep 2012 13:41:41 +0000 Received: from localhost (localhost [127.0.0.1]) by ecfrec.frec.bull.fr (Postfix) with ESMTP id 8C06819DD62; Mon, 17 Sep 2012 15:16:50 +0200 (CEST) Received: from ecfrec.frec.bull.fr ([127.0.0.1]) by localhost (ecfrec.frec.bull.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 02140-02; Mon, 17 Sep 2012 15:16:42 +0200 (CEST) Received: from atlas.frec.bull.fr (atlas.frec.bull.fr [129.183.91.13]) by ecfrec.frec.bull.fr (Postfix) with ESMTP id C0E3119DD67; Mon, 17 Sep 2012 15:16:33 +0200 (CEST) Received: by atlas.frec.bull.fr (Postfix, from userid 15269) id A8E8037FFA7; Mon, 17 Sep 2012 15:16:33 +0200 (CEST) From: Simon Derr To: v9fs-developer@lists.sourceforge.net Date: Mon, 17 Sep 2012 15:16:30 +0200 Message-Id: <1347887791-13726-4-git-send-email-simon.derr@bull.net> X-Mailer: git-send-email 1.7.2.2 In-Reply-To: <1347887791-13726-1-git-send-email-simon.derr@bull.net> References: <1347887791-13726-1-git-send-email-simon.derr@bull.net> To: v9fs-developer@lists.sourceforge.net X-Virus-Scanned: by amavisd-new at frec.bull.fr X-Spam-Score: -0.5 (/) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.5 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain X-Headers-End: 1TDbZq-0007Av-Bb Cc: simon.derr@bull.net Subject: [V9fs-developer] [PATCH 3/4] 9P: Fix race in p9_write_work() X-BeenThere: v9fs-developer@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: v9fs-developer-bounces@lists.sourceforge.net See previous commit about p9_read_work() for details. This fixes a similar race between p9_write_work() and p9_poll_mux() Signed-off-by: Simon Derr --- net/9p/trans_fd.c | 19 ++++++++++--------- 1 files changed, 10 insertions(+), 9 deletions(-) diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c index e8a00a2..baec49a 100644 --- a/net/9p/trans_fd.c +++ b/net/9p/trans_fd.c @@ -476,10 +476,9 @@ static void p9_write_work(struct work_struct *work) clear_bit(Wpending, &m->wsched); err = p9_fd_write(m->client, m->wbuf + m->wpos, m->wsize - m->wpos); p9_debug(P9_DEBUG_TRANS, "mux %p sent %d bytes\n", m, err); - if (err == -EAGAIN) { - clear_bit(Wworksched, &m->wsched); - return; - } + if (err == -EAGAIN) + goto end_clear; + if (err < 0) goto error; @@ -492,19 +491,21 @@ static void p9_write_work(struct work_struct *work) if (m->wpos == m->wsize) m->wpos = m->wsize = 0; +end_clear: + clear_bit(Wworksched, &m->wsched); + if (m->wsize || !list_empty(&m->unsent_req_list)) { if (test_and_clear_bit(Wpending, &m->wsched)) n = POLLOUT; else n = p9_fd_poll(m->client, NULL); - if (n & POLLOUT) { + if ((n & POLLOUT) && + !test_and_set_bit(Wworksched, &m->wsched)) { p9_debug(P9_DEBUG_TRANS, "sched write work %p\n", m); schedule_work(&m->wq); - } else - clear_bit(Wworksched, &m->wsched); - } else - clear_bit(Wworksched, &m->wsched); + } + } return;