Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 08 Feb 2012 11:31:49 +0400
From:      "Andrey V. Elsukov" <ae@FreeBSD.org>
To:        Yar Tikhiy <yar@freebsd.org>
Cc:        freebsd-fs@FreeBSD.org, Marcel Moolenaar <marcel@FreeBSD.org>, Pawel Jakub Dawidek <pjd@FreeBSD.org>
Subject:   Re: bin/145309: bsdlabel: Editing disk label invalidates the whole device
Message-ID:  <4F3224E5.10406@FreeBSD.org>
In-Reply-To: <201202072310.q17NAD0h052230@freefall.freebsd.org>
References:  <201202072310.q17NAD0h052230@freefall.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------030908090907000300080105
Content-Type: text/plain; charset=KOI8-R
Content-Transfer-Encoding: 7bit

On 08.02.2012 3:10, Yar Tikhiy wrote:
>  > When you are in single user mode your root filesystem is mounted read-onl=
>  y.
>  > When you run bsdlabel it opens geom provider for writing and this trigger=
>  s spoiling for it.
>  > When bsdlabel closes provider GEOM_PART destroys it and creates again.
>  > But VFS code seems loses it.
>  
>  Sorry but do you think it's intended behavior or not?  It doesn't look
>  so to me and, IMMSMR, it wasn't there before.  Please correct me if
>  I'm wrong.

GEOM_BSD class uses g_slice interface to implement partitions. It grabs an
extra exclusive access bit when provider is opened first time. This grants
him protection from spoiling. GEOM_PART class does this only when provider
is opened for writing. We can try to change this behavior or just don't use
bsdlabel :)
Changes may lead to unexpected problems. If you want to test you can try
attached patch (untested).

-- 
WBR, Andrey V. Elsukov

--------------030908090907000300080105
Content-Type: text/plain;
 name="g_part.c.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="g_part.c.diff"

Index: head/sys/geom/part/g_part.c
===================================================================
--- head/sys/geom/part/g_part.c	(revision 231127)
+++ head/sys/geom/part/g_part.c	(working copy)
@@ -1948,8 +1948,13 @@ g_part_access(struct g_provider *pp, int dr, int d
 
 	cp = LIST_FIRST(&pp->geom->consumer);
 
-	/* We always gain write-exclusive access. */
-	return (g_access(cp, dr, dw, dw + de));
+	/* On first open, grab an extra "exclusive" bit */
+	if (cp->acr == 0 && cp->acw == 0 && cp->ace == 0)
+		de++;
+	/* ... and let go of it on last close */
+	if ((cp->acr + dr) == 0 && (cp->acw + dw) == 0 && (cp->ace + de) == 1)
+		de--;
+	return (g_access(cp, dr, dw, de));
 }
 
 static void

--------------030908090907000300080105--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4F3224E5.10406>