From owner-svn-src-all@freebsd.org Tue Sep 3 14:07:41 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 3B16CDD09A; Tue, 3 Sep 2019 14:06:52 +0000 (UTC) (envelope-from yuripv@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2610:1c1:1:6074::16:84]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "freefall.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46N7zv6PMQz4Pyq; Tue, 3 Sep 2019 14:06:51 +0000 (UTC) (envelope-from yuripv@freebsd.org) Received: by freefall.freebsd.org (Postfix, from userid 1452) id 806311AC9C; Tue, 3 Sep 2019 14:06:19 +0000 (UTC) X-Original-To: yuripv@localmail.freebsd.org Delivered-To: yuripv@localmail.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [96.47.72.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mx1.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by freefall.freebsd.org (Postfix) with ESMTPS id 88F5858FF; Mon, 15 Apr 2019 12:10:02 +0000 (UTC) (envelope-from owner-src-committers@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [96.47.72.132]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "freefall.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 45E2776697; Mon, 15 Apr 2019 12:10:02 +0000 (UTC) (envelope-from owner-src-committers@freebsd.org) Received: by freefall.freebsd.org (Postfix, from userid 538) id 17B0258FE; Mon, 15 Apr 2019 12:10:02 +0000 (UTC) Delivered-To: src-committers@localmail.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mx1.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by freefall.freebsd.org (Postfix) with ESMTPS id B11D758FB for ; Mon, 15 Apr 2019 12:09:59 +0000 (UTC) (envelope-from mckusick@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 62D7176690; Mon, 15 Apr 2019 12:09:59 +0000 (UTC) (envelope-from mckusick@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 309697C21; Mon, 15 Apr 2019 12:09:59 +0000 (UTC) (envelope-from mckusick@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3FC9wnh099633; Mon, 15 Apr 2019 12:09:58 GMT (envelope-from mckusick@FreeBSD.org) Received: (from mckusick@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3FC9wxo099632; Mon, 15 Apr 2019 12:09:58 GMT (envelope-from mckusick@FreeBSD.org) Message-Id: <201904151209.x3FC9wxo099632@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mckusick set sender to mckusick@FreeBSD.org using -f From: Kirk McKusick To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r346222 - stable/11/sys/dev/md X-SVN-Group: stable-11 X-SVN-Commit-Author: mckusick X-SVN-Commit-Paths: stable/11/sys/dev/md X-SVN-Commit-Revision: 346222 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk X-Loop: FreeBSD.org Sender: owner-src-committers@freebsd.org X-Rspamd-Queue-Id: 45E2776697 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[freebsd.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.97)[-0.971,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; ASN(0.00)[asn:11403, ipnet:96.47.64.0/20, country:US] Status: O X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Date: Tue, 03 Sep 2019 14:07:41 -0000 X-Original-Date: Mon, 15 Apr 2019 12:09:58 +0000 (UTC) X-List-Received-Date: Tue, 03 Sep 2019 14:07:41 -0000 Author: mckusick Date: Mon Apr 15 12:09:58 2019 New Revision: 346222 URL: https://svnweb.freebsd.org/changeset/base/346222 Log: MFC of 345758 Properly flush outstanding I/Os when forcibly deleteing a memory disk device. Sponsored by: Netflix Modified: stable/11/sys/dev/md/md.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/dev/md/md.c ============================================================================== --- stable/11/sys/dev/md/md.c Mon Apr 15 12:07:41 2019 (r346221) +++ stable/11/sys/dev/md/md.c Mon Apr 15 12:09:58 2019 (r346222) @@ -106,6 +106,7 @@ #define MD_SHUTDOWN 0x10000 /* Tell worker thread to terminate. */ #define MD_EXITING 0x20000 /* Worker thread is exiting. */ +#define MD_PROVIDERGONE 0x40000 /* Safe to free the softc */ #ifndef MD_NSECT #define MD_NSECT (10000 * 2) @@ -152,6 +153,7 @@ static g_start_t g_md_start; static g_access_t g_md_access; static void g_md_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp, struct g_consumer *cp __unused, struct g_provider *pp); +static g_provgone_t g_md_providergone; static struct cdev *status_dev = NULL; static struct sx md_sx; @@ -173,6 +175,7 @@ struct g_class g_md_class = { .start = g_md_start, .access = g_md_access, .dumpconf = g_md_dumpconf, + .providergone = g_md_providergone, }; DECLARE_GEOM_CLASS(g_md_class, g_md); @@ -432,8 +435,8 @@ g_md_start(struct bio *bp) } mtx_lock(&sc->queue_mtx); bioq_disksort(&sc->bio_queue, bp); - mtx_unlock(&sc->queue_mtx); wakeup(sc); + mtx_unlock(&sc->queue_mtx); } #define MD_MALLOC_MOVE_ZERO 1 @@ -1421,17 +1424,30 @@ bad: return (error); } +static void +g_md_providergone(struct g_provider *pp) +{ + struct md_s *sc = pp->geom->softc; + + mtx_lock(&sc->queue_mtx); + sc->flags |= MD_PROVIDERGONE; + wakeup(&sc->flags); + mtx_unlock(&sc->queue_mtx); +} + static int mddestroy(struct md_s *sc, struct thread *td) { if (sc->gp) { - sc->gp->softc = NULL; g_topology_lock(); g_wither_geom(sc->gp, ENXIO); g_topology_unlock(); - sc->gp = NULL; - sc->pp = NULL; + + mtx_lock(&sc->queue_mtx); + while (!(sc->flags & MD_PROVIDERGONE)) + msleep(&sc->flags, &sc->queue_mtx, PRIBIO, "mddestroy", 0); + mtx_unlock(&sc->queue_mtx); } if (sc->devstat) { devstat_remove_entry(sc->devstat);