From patchwork Tue Jan 17 04:39:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Mahoney X-Patchwork-Id: 9519921 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 478ED6043D for ; Tue, 17 Jan 2017 04:39:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3BF8128174 for ; Tue, 17 Jan 2017 04:39:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 30CBB2848E; Tue, 17 Jan 2017 04:39:50 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 586B428174 for ; Tue, 17 Jan 2017 04:39:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751169AbdAQEjm (ORCPT ); Mon, 16 Jan 2017 23:39:42 -0500 Received: from mx2.suse.de ([195.135.220.15]:36267 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751152AbdAQEjl (ORCPT ); Mon, 16 Jan 2017 23:39:41 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 4D616ABDF for ; Tue, 17 Jan 2017 04:39:40 +0000 (UTC) Received: by starscream.home.jeffm.io (Postfix, from userid 1000) id 67BF58BA88; Mon, 16 Jan 2017 23:39:37 -0500 (EST) From: jeffm@suse.com To: linux-xfs@vger.kernel.org Cc: Jeff Mahoney Subject: [PATCH 1/3] xfs_repair: clear pthread_t when pthread_create fails Date: Mon, 16 Jan 2017 23:39:31 -0500 Message-Id: <1484627973-11535-2-git-send-email-jeffm@suse.com> X-Mailer: git-send-email 2.7.1 In-Reply-To: <1484627973-11535-1-git-send-email-jeffm@suse.com> References: <1484627973-11535-1-git-send-email-jeffm@suse.com> Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jeff Mahoney pf_queuing_worker and pf_create_prefetch_thread both try to handle thread creation failure gracefully, but assume that pthread_create doesn't modify the pthread_t when it fails. From the pthread_create man page: On success, pthread_create() returns 0; on error, it returns an error number, and the contents of *thread are undefined. In fact, glibc's pthread_create writes the pthread_t value before calling clone(). When we join the created threads in cleanup_inode_prefetch and the cleanup stage of pf_queuing_worker, we assume that if the pthread_t is nonzero that it's a valid thread handle and end up crashing in pthread_join. This patch zeros out the handle after pthread_create failure. Signed-off-by: Jeff Mahoney Reviewed-by: Eric Sandeen --- repair/prefetch.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/repair/prefetch.c b/repair/prefetch.c index ff50606..044fab2 100644 --- a/repair/prefetch.c +++ b/repair/prefetch.c @@ -703,6 +703,7 @@ pf_queuing_worker( if (err != 0) { do_warn(_("failed to create prefetch thread: %s\n"), strerror(err)); + args->io_threads[i] = 0; if (i == 0) { pf_start_processing(args); return NULL; @@ -816,6 +817,7 @@ pf_create_prefetch_thread( if (err != 0) { do_warn(_("failed to create prefetch thread: %s\n"), strerror(err)); + args->queuing_thread = 0; cleanup_inode_prefetch(args); }