From patchwork Thu Dec 13 17:01:42 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 1875601 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 ADDE3DF23A for ; Thu, 13 Dec 2012 17:01:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756539Ab2LMRBq (ORCPT ); Thu, 13 Dec 2012 12:01:46 -0500 Received: from mail-ie0-f174.google.com ([209.85.223.174]:65258 "EHLO mail-ie0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753702Ab2LMRBp (ORCPT ); Thu, 13 Dec 2012 12:01:45 -0500 Received: by mail-ie0-f174.google.com with SMTP id c11so4281511ieb.19 for ; Thu, 13 Dec 2012 09:01:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding :x-gm-message-state; bh=ka7zWRVthkQBPIlI0aTs6xof/+T3tEHwdX9LSWOJ98c=; b=cNRHLYMvyiyVpgDI6GAyFL6CzmMnTKkEsrRusuzX2j9droDEfc7NquaTHqvMJuRkpS 30idcqW1NaoHcTnb2qQ181Djc3vOHu509bk7ppNSifDpWU/4ojnnqUiyOCQqOyONukLn Oo2vYPKnLTY/w+h00KveeJGKsLhf4ca78F3O1me2IGKIFi8NdGfGLchWY2oKUQXpENAs A1y7EcBOG2w0ze8qH4/nWNjNa7sR9DhSFOtskrQZS+nYAHhqmOT1ADlzK4r6sPWd8PR5 pijhSly6G/gi2xouTehdyB25fKkcVyx+LWwPBugSQxsyUbIi7UEdeB/dyB/H7U2yCrQW OVLQ== Received: by 10.50.0.168 with SMTP id 8mr2385634igf.36.1355418105485; Thu, 13 Dec 2012 09:01:45 -0800 (PST) Received: from [172.22.22.4] (c-71-195-31-37.hsd1.mn.comcast.net. [71.195.31.37]) by mx.google.com with ESMTPS id ww6sm4631699igb.2.2012.12.13.09.01.43 (version=SSLv3 cipher=OTHER); Thu, 13 Dec 2012 09:01:44 -0800 (PST) Message-ID: <50CA09F6.9080606@inktank.com> Date: Thu, 13 Dec 2012 11:01:42 -0600 From: Alex Elder User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: ceph-devel@vger.kernel.org Subject: [PATCH 3/9] libceph: avoid using freed osd in __kick_osd_requests() References: <50CA0915.1090801@inktank.com> In-Reply-To: <50CA0915.1090801@inktank.com> X-Gm-Message-State: ALoCoQkAX0oxeLpqlnW1EIYriGIzNFvx/m97NPkp75VgAZuwo28F6qE9THcez+CU+dv9Mk5FYOZ0 Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org If an osd has no requests and no linger requests, __reset_osd() will just remove it with a call to __remove_osd(). That drops a reference to the osd, and therefore the osd may have been free by the time __reset_osd() returns. That function offers no indication this may have occurred, and as a result the osd will continue to be used even when it's no longer valid. Change__reset_osd() so it returns an error (ENODEV) when it deletes the osd being reset. And change __kick_osd_requests() so it returns immediately (before referencing osd again) if __reset_osd() returns *any* error. Signed-off-by: Alex Elder Reviewed-by: Sage Weil --- net/ceph/osd_client.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) list_for_each_entry(req, &osd->o_requests, r_osd_item) { @@ -745,6 +745,7 @@ static int __reset_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd) if (list_empty(&osd->o_requests) && list_empty(&osd->o_linger_requests)) { __remove_osd(osdc, osd); + ret = -ENODEV; } else if (memcmp(&osdc->osdmap->osd_addr[osd->o_osd], &osd->o_con.peer_addr, sizeof(osd->o_con.peer_addr)) == 0 && diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c index ac7be72..60c74c1 100644 --- a/net/ceph/osd_client.c +++ b/net/ceph/osd_client.c @@ -581,7 +581,7 @@ static void __kick_osd_requests(struct ceph_osd_client *osdc, dout("__kick_osd_requests osd%d\n", osd->o_osd); err = __reset_osd(osdc, osd); - if (err == -EAGAIN) + if (err) return;