From ruben@3vilHaX0rCave.bzerk.org  Mon Oct  6 01:45:51 2003
Return-Path: <ruben@3vilHaX0rCave.bzerk.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 7451616A4B3
	for <FreeBSD-gnats-submit@freebsd.org>; Mon,  6 Oct 2003 01:45:51 -0700 (PDT)
Received: from ei.bzerk.org (ei.xs4all.nl [213.84.67.5])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 05F1443FDF
	for <FreeBSD-gnats-submit@freebsd.org>; Mon,  6 Oct 2003 01:45:50 -0700 (PDT)
	(envelope-from ruben@3vilHaX0rCave.bzerk.org)
Received: from ei.bzerk.org (BOFH@localhost [127.0.0.1])
	by ei.bzerk.org (8.12.10/8.12.10) with ESMTP id h968kwl3030880
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 6 Oct 2003 10:46:58 +0200 (CEST)
	(envelope-from ruben@ei.bzerk.org)
Received: (from ruben@localhost)
	by ei.bzerk.org (8.12.10/8.12.10/Submit) id h968kwdg030879;
	Mon, 6 Oct 2003 10:46:58 +0200 (CEST)
	(envelope-from ruben)
Message-Id: <200310060846.h968kwdg030879@ei.bzerk.org>
Date: Mon, 6 Oct 2003 10:46:58 +0200 (CEST)
From: Ruben de Groot <rdg@bzerk.org>
Reply-To: Ruben de Groot <rdg@bzerk.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [patch] missing option in mdmfs (mount_mfs)
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         57641
>Category:       bin
>Synopsis:       [patch] missing option in mount_mfs(8)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    dd
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Oct 06 01:50:22 PDT 2003
>Closed-Date:    Mon Jan 02 01:53:09 UTC 2006
>Last-Modified:  Mon Jan 02 01:53:09 UTC 2006
>Originator:     Ruben de Groot
>Release:        FreeBSD 5.1-CURRENT i386
>Organization:
>Environment:
System: FreeBSD ei.bzerk.org 5.1-CURRENT FreeBSD 5.1-CURRENT #1: Thu Oct 2 09:35:43 CEST 2003 root@ei.bzerk.org:/usr/build/usr/obj/usr/build/current/usr/src/sys/SMP-EI i386


>Description:
	
	Currently, mdmfs will allways do a newfs before mounting a mfs.
	When using filesystem image files (MD_VNODE), an option to skip
	the newfs part, preserving the existing filesystem would be
	desirable.

>How-To-Repeat:

root@caliban:/root> tail -1 /etc/fstab
/dev/md1 /jails/jail1 mfs rw,-F/jails/vnodes/jail1fs,async 0 0
root@caliban:/root> mount /jails/jail1
root@caliban:/root> touch /jails/jail1/IMPORTANT_DATA
root@caliban:/root> umount /jails/jail1
root@caliban:/root> mount /jails/jail1
root@caliban:/root> ls /jails/jail1
root@caliban:/root>

>Fix:

	Add a -P option to mdmfs (and mount_mfs) that will skip the
	do_newfs() part. Adding P to the fstab line above like this:

/dev/md1 /jails/jail1 mfs rw,-PF/jails/vnodes/jail1fs,async 0 0

	will preserve data between mounts. The following patch adds the
	-P option (patch for HEAD) :


diff -u sbin/mdmfs.orig/mdmfs.8 sbin/mdmfs/mdmfs.8
--- sbin/mdmfs.orig/mdmfs.8	Wed Aug  6 04:41:52 2003
+++ sbin/mdmfs/mdmfs.8	Mon Oct  6 08:48:27 2003
@@ -36,7 +36,7 @@
 driver
 .Sh SYNOPSIS
 .Nm
-.Op Fl DLMNSUX
+.Op Fl DLMNPSUX
 .Op Fl a Ar maxcontig
 .Op Fl b Ar block-size
 .Op Fl c Ar cylinders
@@ -57,7 +57,7 @@
 .Ar mount-point
 .Nm
 .Fl C
-.Op Fl NU
+.Op Fl NPU
 .Op Fl a Ar maxcontig
 .Op Fl b Ar block-size
 .Op Fl c Ar cylinders
@@ -195,6 +195,11 @@
 See
 .Xr mount 8
 for more information.
+.It Fl P
+Preserve existing filesystem. Do not run newfs. This only makes sense if
+.Fl F
+is specified
+.Pq Dv MD_VNODE .
 .It Fl p Ar permissions
 Set the file (directory) permissions of the mount point
 .Ar mount-point
diff -u sbin/mdmfs.orig/mdmfs.c sbin/mdmfs/mdmfs.c
--- sbin/mdmfs.orig/mdmfs.c	Fri Oct  3 13:50:18 2003
+++ sbin/mdmfs/mdmfs.c	Sat Oct  4 13:41:14 2003
@@ -89,7 +89,7 @@
 	    *mount_arg;
 	enum md_types mdtype;		/* The type of our memory disk. */
 	bool have_mdtype;
-	bool detach, softdep, autounit;
+	bool detach, softdep, autounit, no_newfs;
 	char *mtpoint, *unitstr;
 	char ch, *p;
 	void *set;
@@ -99,6 +99,7 @@
 	detach = true;
 	softdep = true;
 	autounit = false;
+	no_newfs = false;
 	have_mdtype = false;
 	mdname = MD_NAME;
 	mdnamelen = strlen(mdname);
@@ -118,7 +119,7 @@
 		compat = true;
 
 	while ((ch = getopt(argc, argv,
-	    "a:b:Cc:Dd:e:F:f:hi:LMm:Nn:O:o:p:Ss:t:Uv:w:X")) != -1)
+	    "a:b:Cc:Dd:e:F:f:hi:LMm:Nn:O:o:Pp:Ss:t:Uv:w:X")) != -1)
 		switch (ch) {
 		case 'a':
 			argappend(&newfs_arg, "-a %s", optarg);
@@ -189,6 +190,9 @@
 		case 'o':
 			argappend(&mount_arg, "-o %s", optarg);
 			break;
+		case 'P':
+			no_newfs = true;
+			break;
 		case 'p':
 			if (compat)
 				usage();
@@ -264,7 +268,8 @@
 		do_mdconfig_attach_au(mdconfig_arg, mdtype);
 	else
 		do_mdconfig_attach(mdconfig_arg, mdtype);
-	do_newfs(newfs_arg);
+	if (!no_newfs || (mdtype != MD_VNODE))
+		do_newfs(newfs_arg);
 	do_mount(mount_arg, mtpoint);
 	do_mtptsetup(mtpoint, &mi);
 
@@ -661,13 +666,13 @@
 		name = "mdmfs";
 	if (!compat)
 		fprintf(stderr,
-"usage: %s [-DLMNSUX] [-a maxcontig [-b block-size] [-c cylinders]\n"
+"usage: %s [-DLMNPSUX] [-a maxcontig [-b block-size] [-c cylinders]\n"
 "\t[-d rotdelay] [-e maxbpg] [-F file] [-f frag-size] [-i bytes]\n"
 "\t[-m percent-free] [-n rotational-positions] [-O optimization]\n"
 "\t[-o mount-options] [-p permissions] [-s size] [-w user:group]\n"
 "\tmd-device mount-point\n", name);
 	fprintf(stderr,
-"usage: %s -C [-NU] [-a maxcontig] [-b block-size] [-c cylinders]\n"
+"usage: %s -C [-NPU] [-a maxcontig] [-b block-size] [-c cylinders]\n"
 "\t[-d rotdelay] [-e maxbpg] [-F file] [-f frag-size] [-i bytes]\n"
 "\t[-m percent-free] [-n rotational-positions] [-O optimization]\n"
 "\t[-o mount-options] [-s size] md-device mount-point\n", name);


>Release-Note:
>Audit-Trail:

From: Peter Pentchev <roam@ringlet.net>
To: Ruben de Groot <rdg@bzerk.org>
Cc: bug-followup@FreeBSD.org
Subject: Re: bin/57641: [patch] missing option in mdmfs (mount_mfs)
Date: Mon, 6 Oct 2003 12:38:25 +0300

 On Mon, Oct 06, 2003 at 10:46:58AM +0200, Ruben de Groot wrote:
 > 
 > >Number:         57641
 > >Category:       bin
 > >Synopsis:       [patch] missing option in mdmfs (mount_mfs)
 > >Originator:     Ruben de Groot
 > >Release:        FreeBSD 5.1-CURRENT i386
 [snip]
 > >Description:
 > 	
 > 	Currently, mdmfs will allways do a newfs before mounting a mfs.
 > 	When using filesystem image files (MD_VNODE), an option to skip
 > 	the newfs part, preserving the existing filesystem would be
 > 	desirable.
 [snip]
 > >Fix:
 > 
 > 	Add a -P option to mdmfs (and mount_mfs) that will skip the
 > 	do_newfs() part. Adding P to the fstab line above like this:
 [snip]
 > diff -u sbin/mdmfs.orig/mdmfs.8 sbin/mdmfs/mdmfs.8
 > --- sbin/mdmfs.orig/mdmfs.8	Wed Aug  6 04:41:52 2003
 > +++ sbin/mdmfs/mdmfs.8	Mon Oct  6 08:48:27 2003
 [snip]
 > @@ -195,6 +195,11 @@
 >  See
 >  .Xr mount 8
 >  for more information.
 > +.It Fl P
 > +Preserve existing filesystem. Do not run newfs. This only makes sense if
 > +.Fl F
 > +is specified
 > +.Pq Dv MD_VNODE .
 >  .It Fl p Ar permissions
 >  Set the file (directory) permissions of the mount point
 >  .Ar mount-point
 
 Just a minor mdoc comment on this part: generally we put new sentences
 on separate lines :)  Also, what do you think about this wording change:
 
 @@ -195,6 +195,12 @@
  See
  .Xr mount 8
  for more information.
 +.It Fl P
 +Preserve existing filesystem - do not run newfs.
 +This only makes sense if
 +.Fl F
 +is specified to create a vnode-backed disk
 +.Pq Dv MD_VNODE .
  .It Fl p Ar permissions
  Set the file (directory) permissions of the mount point
  .Ar mount-point
 
 G'luck,
 Peter
 
 -- 
 Peter Pentchev	roam@ringlet.net    roam@sbnd.net    roam@FreeBSD.org
 PGP key:	http://people.FreeBSD.org/~roam/roam.key.asc
 Key fingerprint	FDBA FD79 C26F 3C51 C95E  DF9E ED18 B68D 1619 4553
 What would this sentence be like if it weren't self-referential?

From: Ruben de Groot <rdg@bzerk.org>
To: Peter Pentchev <roam@ringlet.net>
Cc: bug-followup@FreeBSD.org
Subject: Re: bin/57641: [patch] missing option in mdmfs (mount_mfs)
Date: Mon, 6 Oct 2003 13:15:29 +0200

 On Mon, Oct 06, 2003 at 12:38:25PM +0300, Peter Pentchev typed:
 > 
 > Just a minor mdoc comment on this part: generally we put new sentences
 > on separate lines :)  Also, what do you think about this wording change:
 > 
 > @@ -195,6 +195,12 @@
 >  See
 >  .Xr mount 8
 >  for more information.
 > +.It Fl P
 > +Preserve existing filesystem - do not run newfs.
 > +This only makes sense if
 > +.Fl F
 > +is specified to create a vnode-backed disk
 > +.Pq Dv MD_VNODE .
 >  .It Fl p Ar permissions
 >  Set the file (directory) permissions of the mount point
 >  .Ar mount-point
 
 This looks better. Thanks for pointing that out. I'm no mdoc expert
 (yet)
 
 Ruben
 
 -- 
 "We don't care.  We don't have to.  We're the Phone Company."
Responsible-Changed-From-To: freebsd-bugs->dd 
Responsible-Changed-By: dd 
Responsible-Changed-When: Tue Nov 30 14:40:14 UTC 2004 
Responsible-Changed-Why:  
Looks mostly reasonable. I'll fix up the patch and commit it later this week. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=57641 
State-Changed-From-To: open->closed 
State-Changed-By: dd 
State-Changed-When: Mon Jan 2 01:52:49 UTC 2006 
State-Changed-Why:  
Committed to -current, thanks! (And sorry for taking so long.) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=57641 
>Unformatted:
