From patchwork Mon Jul 2 03:31:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guanjun He X-Patchwork-Id: 1145391 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 4DD35DFFF2 for ; Mon, 2 Jul 2012 03:34:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753974Ab2GBDdu (ORCPT ); Sun, 1 Jul 2012 23:33:50 -0400 Received: from mail-wi0-f178.google.com ([209.85.212.178]:43766 "EHLO mail-wi0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753311Ab2GBDdY (ORCPT ); Sun, 1 Jul 2012 23:33:24 -0400 Received: by wibhr14 with SMTP id hr14so2729304wib.1 for ; Sun, 01 Jul 2012 20:33:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=wL9kVgZIk2+mJUu6CThHfUXrwmoiTBZSxoesSkG7dpo=; b=0Tjk/IVMsaPD7Bh8xRri81ru6G9dYUSpqyCqwRyU04r1y+hV7CdhGVXazqm7Gvd0ZP MUA2oFA8hlTAjN+LquXCRzGB0qOHW8cIuy0T/hOoCl6MYYFwAlwB3CX/86QLZFGbrXzt 9GKIKqwgZAOPM4+pzeoRXul4QxMKsNA67BLUElnVM6Nyqg2UBsWPI3VMNWv9vIwFtA9o RAGAAUWjVKO0ZmZ7wNNsSPGoTFLirC/G7HijOp1H15LZkIXhLPdM5YsvbgsvLN6cYZ8i RI5b8QgUU3pGASNPAlEQ+RRbz8lvPQKg5nX7NkPViwsH6icIS10PHeSG0gtaIE/emI7/ nNkA== Received: by 10.216.196.218 with SMTP id r68mr914839wen.122.1341200002657; Sun, 01 Jul 2012 20:33:22 -0700 (PDT) Received: from localhost.localdomain ([114.112.46.39]) by mx.google.com with ESMTPS id e9sm190836wiw.10.2012.07.01.20.33.12 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 01 Jul 2012 20:33:17 -0700 (PDT) From: Guanjun He To: sage@inktank.com, ceph-devel@vger.kernel.org Cc: Guanjun He Subject: Re: [PATCH 1/1] client: prevent the race of incoming work during teardown Date: Mon, 2 Jul 2012 11:31:41 +0800 Message-Id: <1341199901-16730-1-git-send-email-gjhe@suse.com> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: References: Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org Reproduce the patch against the latest source repo. Add an atomic variable 'stopping' as flag in struct ceph_messenger, set this flag to 1 in function ceph_destroy_client(), and add the condition code in function ceph_data_ready() to test the flag value, if true(1), just return. Signed-off-by: Guanjun He --- include/linux/ceph/messenger.h | 1 + net/ceph/ceph_common.c | 2 ++ net/ceph/messenger.c | 5 +++++ 3 files changed, 8 insertions(+), 0 deletions(-) diff --git a/include/linux/ceph/messenger.h b/include/linux/ceph/messenger.h index 2521a95..2586f34 100644 --- a/include/linux/ceph/messenger.h +++ b/include/linux/ceph/messenger.h @@ -53,6 +53,7 @@ struct ceph_messenger { struct ceph_entity_inst inst; /* my name+address */ struct ceph_entity_addr my_enc_addr; + atomic_t stopping; bool nocrc; /* diff --git a/net/ceph/ceph_common.c b/net/ceph/ceph_common.c index ba4323b..478f3a4 100644 --- a/net/ceph/ceph_common.c +++ b/net/ceph/ceph_common.c @@ -501,6 +501,8 @@ void ceph_destroy_client(struct ceph_client *client) { dout("destroy_client %p\n", client); + atomic_set(&client->msgr->stopping, 1); + /* unmount */ ceph_osdc_stop(&client->osdc); diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c index b332c3d..11ea62e 100644 --- a/net/ceph/messenger.c +++ b/net/ceph/messenger.c @@ -156,6 +156,9 @@ EXPORT_SYMBOL(ceph_msgr_flush); static void ceph_data_ready(struct sock *sk, int count_unused) { struct ceph_connection *con = sk->sk_user_data; + if (atomic_read(&con->msgr->stopping)) { + return; + } if (sk->sk_state != TCP_CLOSE_WAIT) { dout("ceph_data_ready on %p state = %lu, queueing work\n", @@ -2285,6 +2288,8 @@ struct ceph_messenger *ceph_messenger_create(struct ceph_entity_addr *myaddr, get_random_bytes(&msgr->inst.addr.nonce, sizeof(msgr->inst.addr.nonce)); encode_my_addr(msgr); + atomic_set(&msgr->stopping, 0); + dout("messenger_create %p\n", msgr); return msgr; }