bin/145309: bsdlabel: Editing disk label invalidates the whole device

Andrey V. Elsukov ae at FreeBSD.org
Wed Feb 8 07:31:52 UTC 2012


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
-------------- next part --------------
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


More information about the freebsd-fs mailing list