From owner-svn-src-all@freebsd.org Sun Oct 18 16:24:12 2020 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 43E0D436907; Sun, 18 Oct 2020 16:24:12 +0000 (UTC) (envelope-from trasz@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 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 4CDlZh1HQvz4ggk; Sun, 18 Oct 2020 16:24:12 +0000 (UTC) (envelope-from trasz@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 0FCB415682; Sun, 18 Oct 2020 16:24:12 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 09IGOBV9036661; Sun, 18 Oct 2020 16:24:11 GMT (envelope-from trasz@FreeBSD.org) Received: (from trasz@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 09IGO88U036637; Sun, 18 Oct 2020 16:24:08 GMT (envelope-from trasz@FreeBSD.org) Message-Id: <202010181624.09IGO88U036637@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: trasz set sender to trasz@FreeBSD.org using -f From: Edward Tomasz Napierala Date: Sun, 18 Oct 2020 16:24:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r366811 - in head: share/man/man9 sys/geom sys/geom/bde sys/geom/cache sys/geom/concat sys/geom/journal sys/geom/label sys/geom/linux_lvm sys/geom/mirror sys/geom/mountver sys/geom/mult... X-SVN-Group: head X-SVN-Commit-Author: trasz X-SVN-Commit-Paths: in head: share/man/man9 sys/geom sys/geom/bde sys/geom/cache sys/geom/concat sys/geom/journal sys/geom/label sys/geom/linux_lvm sys/geom/mirror sys/geom/mountver sys/geom/multipath sys/geom/raid sys/g... X-SVN-Commit-Revision: 366811 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list 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: , X-List-Received-Date: Sun, 18 Oct 2020 16:24:12 -0000 Author: trasz Date: Sun Oct 18 16:24:08 2020 New Revision: 366811 URL: https://svnweb.freebsd.org/changeset/base/366811 Log: Make g_attach() return ENXIO for orphaned providers; update various classes to add missing error checking. Reviewed by: imp MFC after: 2 weeks Sponsored by: NetApp, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D26658 Modified: head/share/man/man9/g_attach.9 head/sys/geom/bde/g_bde.c head/sys/geom/cache/g_cache.c head/sys/geom/concat/g_concat.c head/sys/geom/geom_dev.c head/sys/geom/geom_subr.c head/sys/geom/geom_vfs.c head/sys/geom/journal/g_journal.c head/sys/geom/label/g_label.c head/sys/geom/linux_lvm/g_linux_lvm.c head/sys/geom/mirror/g_mirror.c head/sys/geom/mirror/g_mirror_ctl.c head/sys/geom/mountver/g_mountver.c head/sys/geom/multipath/g_multipath.c head/sys/geom/raid/g_raid.c head/sys/geom/raid3/g_raid3.c head/sys/geom/shsec/g_shsec.c head/sys/geom/stripe/g_stripe.c head/sys/geom/virstor/g_virstor.c Modified: head/share/man/man9/g_attach.9 ============================================================================== --- head/share/man/man9/g_attach.9 Sun Oct 18 16:16:22 2020 (r366810) +++ head/share/man/man9/g_attach.9 Sun Oct 18 16:24:08 2020 (r366811) @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd January 16, 2004 +.Dd October 10, 2020 .Dt G_ATTACH 9 .Os .Sh NAME @@ -122,6 +122,8 @@ Possible errors: .Bl -tag -width Er .It Bq Er ELOOP The operation creates a topology loop. +.It Bq Er ENXIO +Provider got orphaned. .El .Sh SEE ALSO .Xr geom 4 , Modified: head/sys/geom/bde/g_bde.c ============================================================================== --- head/sys/geom/bde/g_bde.c Sun Oct 18 16:16:22 2020 (r366810) +++ head/sys/geom/bde/g_bde.c Sun Oct 18 16:24:08 2020 (r366811) @@ -131,7 +131,13 @@ g_bde_create_geom(struct gctl_req *req, struct g_class gp = g_new_geomf(mp, "%s.bde", pp->name); cp = g_new_consumer(gp); - g_attach(cp, pp); + error = g_attach(cp, pp); + if (error != 0) { + g_destroy_consumer(cp); + g_destroy_geom(gp); + gctl_error(req, "could not attach consumer"); + return; + } error = g_access(cp, 1, 1, 1); if (error) { g_detach(cp); Modified: head/sys/geom/cache/g_cache.c ============================================================================== --- head/sys/geom/cache/g_cache.c Sun Oct 18 16:16:22 2020 (r366810) +++ head/sys/geom/cache/g_cache.c Sun Oct 18 16:24:08 2020 (r366811) @@ -673,9 +673,11 @@ g_cache_taste(struct g_class *mp, struct g_provider *p gp->orphan = g_cache_orphan; gp->access = g_cache_access; cp = g_new_consumer(gp); - g_attach(cp, pp); - error = g_cache_read_metadata(cp, &md); - g_detach(cp); + error = g_attach(cp, pp); + if (error == 0) { + error = g_cache_read_metadata(cp, &md); + g_detach(cp); + } g_destroy_consumer(cp); g_destroy_geom(gp); if (error != 0) Modified: head/sys/geom/concat/g_concat.c ============================================================================== --- head/sys/geom/concat/g_concat.c Sun Oct 18 16:16:22 2020 (r366810) +++ head/sys/geom/concat/g_concat.c Sun Oct 18 16:24:08 2020 (r366811) @@ -718,9 +718,11 @@ g_concat_taste(struct g_class *mp, struct g_provider * gp->access = g_concat_access; gp->orphan = g_concat_orphan; cp = g_new_consumer(gp); - g_attach(cp, pp); - error = g_concat_read_metadata(cp, &md); - g_detach(cp); + error = g_attach(cp, pp); + if (error == 0) { + error = g_concat_read_metadata(cp, &md); + g_detach(cp); + } g_destroy_consumer(cp); g_destroy_geom(gp); if (error != 0) Modified: head/sys/geom/geom_dev.c ============================================================================== --- head/sys/geom/geom_dev.c Sun Oct 18 16:16:22 2020 (r366810) +++ head/sys/geom/geom_dev.c Sun Oct 18 16:24:08 2020 (r366811) @@ -346,7 +346,7 @@ g_dev_taste(struct g_class *mp, struct g_provider *pp, cp->private = sc; cp->flags |= G_CF_DIRECT_SEND | G_CF_DIRECT_RECEIVE; error = g_attach(cp, pp); - KASSERT(error == 0, + KASSERT(error == 0 || error == ENXIO, ("g_dev_taste(%s) failed to g_attach, err=%d", pp->name, error)); make_dev_args_init(&args); Modified: head/sys/geom/geom_subr.c ============================================================================== --- head/sys/geom/geom_subr.c Sun Oct 18 16:16:22 2020 (r366810) +++ head/sys/geom/geom_subr.c Sun Oct 18 16:24:08 2020 (r366811) @@ -896,6 +896,8 @@ g_attach(struct g_consumer *cp, struct g_provider *pp) G_VALID_PROVIDER(pp); g_trace(G_T_TOPOLOGY, "g_attach(%p, %p)", cp, pp); KASSERT(cp->provider == NULL, ("attach but attached")); + if ((pp->flags & (G_PF_ORPHAN | G_PF_WITHER)) != 0) + return (ENXIO); cp->provider = pp; cp->flags &= ~G_CF_ORPHAN; LIST_INSERT_HEAD(&pp->consumers, cp, consumers); Modified: head/sys/geom/geom_vfs.c ============================================================================== --- head/sys/geom/geom_vfs.c Sun Oct 18 16:16:22 2020 (r366810) +++ head/sys/geom/geom_vfs.c Sun Oct 18 16:24:08 2020 (r366811) @@ -260,7 +260,11 @@ g_vfs_open(struct vnode *vp, struct g_consumer **cpp, sc->sc_bo = bo; gp->softc = sc; cp = g_new_consumer(gp); - g_attach(cp, pp); + error = g_attach(cp, pp); + if (error) { + g_wither_geom(gp, ENXIO); + return (error); + } error = g_access(cp, 1, wr, wr); if (error) { g_wither_geom(gp, ENXIO); Modified: head/sys/geom/journal/g_journal.c ============================================================================== --- head/sys/geom/journal/g_journal.c Sun Oct 18 16:16:22 2020 (r366810) +++ head/sys/geom/journal/g_journal.c Sun Oct 18 16:24:08 2020 (r366811) @@ -2483,9 +2483,11 @@ g_journal_taste(struct g_class *mp, struct g_provider /* This orphan function should be never called. */ gp->orphan = g_journal_taste_orphan; cp = g_new_consumer(gp); - g_attach(cp, pp); - error = g_journal_metadata_read(cp, &md); - g_detach(cp); + error = g_attach(cp, pp); + if (error == 0) { + error = g_journal_metadata_read(cp, &md); + g_detach(cp); + } g_destroy_consumer(cp); g_destroy_geom(gp); if (error != 0) Modified: head/sys/geom/label/g_label.c ============================================================================== --- head/sys/geom/label/g_label.c Sun Oct 18 16:16:22 2020 (r366810) +++ head/sys/geom/label/g_label.c Sun Oct 18 16:24:08 2020 (r366811) @@ -400,7 +400,8 @@ g_label_taste(struct g_class *mp, struct g_provider *p gp->access = g_label_access_taste; gp->orphan = g_label_orphan_taste; cp = g_new_consumer(gp); - g_attach(cp, pp); + if (g_attach(cp, pp) != 0) + goto end2; if (g_access(cp, 1, 0, 0) != 0) goto end; for (i = 0; g_labels[i] != NULL; i++) { @@ -425,6 +426,7 @@ g_label_taste(struct g_class *mp, struct g_provider *p g_access(cp, -1, 0, 0); end: g_detach(cp); +end2: g_destroy_consumer(cp); g_destroy_geom(gp); return (NULL); Modified: head/sys/geom/linux_lvm/g_linux_lvm.c ============================================================================== --- head/sys/geom/linux_lvm/g_linux_lvm.c Sun Oct 18 16:16:22 2020 (r366810) +++ head/sys/geom/linux_lvm/g_linux_lvm.c Sun Oct 18 16:24:08 2020 (r366811) @@ -543,11 +543,13 @@ g_llvm_taste(struct g_class *mp, struct g_provider *pp /* This orphan function should be never called. */ gp->orphan = g_llvm_taste_orphan; cp = g_new_consumer(gp); - g_attach(cp, pp); - error = g_llvm_read_label(cp, &ll); - if (!error) - error = g_llvm_read_md(cp, &md, &ll); - g_detach(cp); + error = g_attach(cp, pp); + if (error == 0) { + error = g_llvm_read_label(cp, &ll); + if (error == 0) + error = g_llvm_read_md(cp, &md, &ll); + g_detach(cp); + } g_destroy_consumer(cp); g_destroy_geom(gp); if (error != 0) Modified: head/sys/geom/mirror/g_mirror.c ============================================================================== --- head/sys/geom/mirror/g_mirror.c Sun Oct 18 16:16:22 2020 (r366810) +++ head/sys/geom/mirror/g_mirror.c Sun Oct 18 16:24:08 2020 (r366811) @@ -3241,9 +3241,11 @@ g_mirror_taste(struct g_class *mp, struct g_provider * */ gp->orphan = g_mirror_taste_orphan; cp = g_new_consumer(gp); - g_attach(cp, pp); - error = g_mirror_read_metadata(cp, &md); - g_detach(cp); + error = g_attach(cp, pp); + if (error == 0) { + error = g_mirror_read_metadata(cp, &md); + g_detach(cp); + } g_destroy_consumer(cp); g_destroy_geom(gp); if (error != 0) Modified: head/sys/geom/mirror/g_mirror_ctl.c ============================================================================== --- head/sys/geom/mirror/g_mirror_ctl.c Sun Oct 18 16:16:22 2020 (r366810) +++ head/sys/geom/mirror/g_mirror_ctl.c Sun Oct 18 16:24:08 2020 (r366811) @@ -449,7 +449,11 @@ err: g_topology_unlock(); return; } - g_attach(cp, pp); + if (g_attach(cp, pp) != 0) { + G_MIRROR_DEBUG(1, "Can't attach disk %s.", pp->name); + gctl_error(req, "Can't attach disk %s.", pp->name); + goto err; + } if (g_access(cp, 1, 0, 0) != 0) { G_MIRROR_DEBUG(1, "Can't open disk %s.", pp->name); gctl_error(req, "Can't open disk %s.", pp->name); Modified: head/sys/geom/mountver/g_mountver.c ============================================================================== --- head/sys/geom/mountver/g_mountver.c Sun Oct 18 16:16:22 2020 (r366810) +++ head/sys/geom/mountver/g_mountver.c Sun Oct 18 16:24:08 2020 (r366811) @@ -586,7 +586,12 @@ g_mountver_taste(struct g_class *mp, struct g_provider return (NULL); cp = LIST_FIRST(&gp->consumer); - g_attach(cp, pp); + error = g_attach(cp, pp); + if (error != 0) { + G_MOUNTVER_DEBUG(0, "Cannot attach to %s; error = %d.", pp->name, error); + return (NULL); + } + error = g_mountver_ident_matches(gp); if (error != 0) { g_detach(cp); Modified: head/sys/geom/multipath/g_multipath.c ============================================================================== --- head/sys/geom/multipath/g_multipath.c Sun Oct 18 16:16:22 2020 (r366810) +++ head/sys/geom/multipath/g_multipath.c Sun Oct 18 16:24:08 2020 (r366811) @@ -823,9 +823,11 @@ g_multipath_taste(struct g_class *mp, struct g_provide gp->access = g_multipath_access; gp->orphan = g_multipath_orphan; cp = g_new_consumer(gp); - g_attach(cp, pp); - error = g_multipath_read_metadata(cp, &md); - g_detach(cp); + error = g_attach(cp, pp); + if (error == 0) { + error = g_multipath_read_metadata(cp, &md); + g_detach(cp); + } g_destroy_consumer(cp); g_destroy_geom(gp); if (error != 0) Modified: head/sys/geom/raid/g_raid.c ============================================================================== --- head/sys/geom/raid/g_raid.c Sun Oct 18 16:16:22 2020 (r366810) +++ head/sys/geom/raid/g_raid.c Sun Oct 18 16:24:08 2020 (r366811) @@ -2228,7 +2228,8 @@ g_raid_taste(struct g_class *mp, struct g_provider *pp gp->orphan = g_raid_taste_orphan; cp = g_new_consumer(gp); cp->flags |= G_CF_DIRECT_RECEIVE; - g_attach(cp, pp); + if (g_attach(cp, pp) != 0) + goto ofail2; if (g_access(cp, 1, 0, 0) != 0) goto ofail; @@ -2251,6 +2252,7 @@ g_raid_taste(struct g_class *mp, struct g_provider *pp (void)g_access(cp, -1, 0, 0); ofail: g_detach(cp); +ofail2: g_destroy_consumer(cp); g_destroy_geom(gp); G_RAID_DEBUG(2, "Tasting provider %s done.", pp->name); Modified: head/sys/geom/raid3/g_raid3.c ============================================================================== --- head/sys/geom/raid3/g_raid3.c Sun Oct 18 16:16:22 2020 (r366810) +++ head/sys/geom/raid3/g_raid3.c Sun Oct 18 16:24:08 2020 (r366811) @@ -3315,9 +3315,11 @@ g_raid3_taste(struct g_class *mp, struct g_provider *p /* This orphan function should be never called. */ gp->orphan = g_raid3_taste_orphan; cp = g_new_consumer(gp); - g_attach(cp, pp); - error = g_raid3_read_metadata(cp, &md); - g_detach(cp); + error = g_attach(cp, pp); + if (error == 0) { + error = g_raid3_read_metadata(cp, &md); + g_detach(cp); + } g_destroy_consumer(cp); g_destroy_geom(gp); if (error != 0) Modified: head/sys/geom/shsec/g_shsec.c ============================================================================== --- head/sys/geom/shsec/g_shsec.c Sun Oct 18 16:16:22 2020 (r366810) +++ head/sys/geom/shsec/g_shsec.c Sun Oct 18 16:24:08 2020 (r366811) @@ -646,9 +646,11 @@ g_shsec_taste(struct g_class *mp, struct g_provider *p gp->access = g_shsec_access; gp->orphan = g_shsec_orphan; cp = g_new_consumer(gp); - g_attach(cp, pp); - error = g_shsec_read_metadata(cp, &md); - g_detach(cp); + error = g_attach(cp, pp); + if (error == 0) { + error = g_shsec_read_metadata(cp, &md); + g_detach(cp); + } g_destroy_consumer(cp); g_destroy_geom(gp); if (error != 0) Modified: head/sys/geom/stripe/g_stripe.c ============================================================================== --- head/sys/geom/stripe/g_stripe.c Sun Oct 18 16:16:22 2020 (r366810) +++ head/sys/geom/stripe/g_stripe.c Sun Oct 18 16:24:08 2020 (r366811) @@ -963,9 +963,11 @@ g_stripe_taste(struct g_class *mp, struct g_provider * gp->access = g_stripe_access; gp->orphan = g_stripe_orphan; cp = g_new_consumer(gp); - g_attach(cp, pp); - error = g_stripe_read_metadata(cp, &md); - g_detach(cp); + error = g_attach(cp, pp); + if (error == 0) { + error = g_stripe_read_metadata(cp, &md); + g_detach(cp); + } g_destroy_consumer(cp); g_destroy_geom(gp); if (error != 0) Modified: head/sys/geom/virstor/g_virstor.c ============================================================================== --- head/sys/geom/virstor/g_virstor.c Sun Oct 18 16:16:22 2020 (r366810) +++ head/sys/geom/virstor/g_virstor.c Sun Oct 18 16:24:08 2020 (r366811) @@ -780,9 +780,11 @@ g_virstor_taste(struct g_class *mp, struct g_provider gp->orphan = (void *)invalid_call; /* I really want these to fail. */ cp = g_new_consumer(gp); - g_attach(cp, pp); - error = read_metadata(cp, &md); - g_detach(cp); + error = g_attach(cp, pp); + if (error == 0) { + error = read_metadata(cp, &md); + g_detach(cp); + } g_destroy_consumer(cp); g_destroy_geom(gp);