[Midnightbsd-cvs] src [8700] trunk/sbin/growfs: make it possible to resize filesystems mounted read-write

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sun Sep 25 18:15:11 EDT 2016


Revision: 8700
          http://svnweb.midnightbsd.org/src/?rev=8700
Author:   laffer1
Date:     2016-09-25 18:15:10 -0400 (Sun, 25 Sep 2016)
Log Message:
-----------
make it possible to resize filesystems mounted read-write

Modified Paths:
--------------
    trunk/sbin/growfs/growfs.8
    trunk/sbin/growfs/growfs.c

Modified: trunk/sbin/growfs/growfs.8
===================================================================
--- trunk/sbin/growfs/growfs.8	2016-09-25 22:14:24 UTC (rev 8699)
+++ trunk/sbin/growfs/growfs.8	2016-09-25 22:15:10 UTC (rev 8700)
@@ -115,11 +115,17 @@
 .Nm
 utility first appeared in
 .Fx 4.4 .
+The ability to resize mounted filesystems was added in
+.Fx 10.0 .
 .Sh AUTHORS
 .An Christoph Herrmann Aq chm at FreeBSD.org
 .An Thomas-Henning von Kamptz Aq tomsoft at FreeBSD.org
 .An The GROWFS team Aq growfs at Tomsoft.COM
 .An Edward Tomasz Napierala Aq trasz at FreeBSD.org
+.Sh CAVEATS
+.Pp
+When expanding a file system mounted read-write, any writes to that file system
+will be temporarily suspended until the expansion is finished.
 .Sh BUGS
 .Pp
 Normally

Modified: trunk/sbin/growfs/growfs.c
===================================================================
--- trunk/sbin/growfs/growfs.c	2016-09-25 22:14:24 UTC (rev 8699)
+++ trunk/sbin/growfs/growfs.c	2016-09-25 22:15:10 UTC (rev 8700)
@@ -69,6 +69,7 @@
 #include <inttypes.h>
 #include <limits.h>
 #include <mntopts.h>
+#include <paths.h>
 #include <stdlib.h>
 #include <stdint.h>
 #include <string.h>
@@ -1523,8 +1524,9 @@
 
 	if (yflag == 0 && Nflag == 0) {
 		if (statfsp != NULL && (statfsp->f_flags & MNT_RDONLY) == 0)
-			errx(1, "%s is mounted read-write on %s",
-			    statfsp->f_mntfromname, statfsp->f_mntonname);
+			printf("Device is mounted read-write; resizing will "
+			    "result in temporary write suspension for %s.\n",
+			    statfsp->f_mntonname);
 		printf("It's strongly recommended to make a backup "
 		    "before growing the file system.\n"
 		    "OK to grow filesystem on %s", device);
@@ -1553,9 +1555,18 @@
 	if (Nflag) {
 		fso = -1;
 	} else {
-		fso = open(device, O_WRONLY);
-		if (fso < 0)
-			err(1, "%s", device);
+		if (statfsp != NULL && (statfsp->f_flags & MNT_RDONLY) == 0) {
+			fso = open(_PATH_UFSSUSPEND, O_RDWR);
+			if (fso == -1)
+				err(1, "unable to open %s", _PATH_UFSSUSPEND);
+			error = ioctl(fso, UFSSUSPEND, &statfsp->f_fsid);
+			if (error != 0)
+				err(1, "UFSSUSPEND");
+		} else {
+			fso = open(device, O_WRONLY);
+			if (fso < 0)
+				err(1, "%s", device);
+		}
 	}
 
 	/*
@@ -1625,12 +1636,17 @@
 
 	close(fsi);
 	if (fso > -1) {
+		if (statfsp != NULL && (statfsp->f_flags & MNT_RDONLY) == 0) {
+			error = ioctl(fso, UFSRESUME);
+			if (error != 0)
+				err(1, "UFSRESUME");
+		}
 		error = close(fso);
 		if (error != 0)
 			err(1, "close");
+		if (statfsp != NULL && (statfsp->f_flags & MNT_RDONLY) != 0)
+			mount_reload(statfsp);
 	}
-	if (statfsp != NULL)
-		mount_reload(statfsp);
 
 	DBG_CLOSE;
 



More information about the Midnightbsd-cvs mailing list