Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 9 Dec 2001 12:56:33 -0800 (PST)
From:      Matthew Dillon <dillon@apollo.backplane.com>
To:        Greg Lehey <grog@FreeBSD.org>, Jordan Hubbard <jkh@winston.freebsd.org>, Garance A Drosihn <drosih@rpi.edu>, "Louis A. Mamakos" <louie@TransSys.COM>, Sheldon Hearn <sheldonh@starjuice.net>, Kirk McKusick <mckusick@beastie.mckusick.com>, freebsd-arch@FreeBSD.org
Subject:   Auto-resize-on-delete patch
Message-ID:  <200112092056.fB9KuXY39015@apollo.backplane.com>
References:  <49294.1007846108@winston.freebsd.org> <200112082211.fB8MBGm18685@apollo.backplane.com> <20011209165725.D83634@monorchid.lemis.com>

next in thread | previous in thread | raw e-mail | index | archive | help
   This patch is relatve to -current.  Note:  This patch also contains
   changes required to test with the "md" device which will not be in the
   final committed patch.

   I haven't tested it much yet, but it appears to work visually.  This
   patch will collapse a 'D'eleted partition's space into the previous
   partition.  For example, removing /var/tmp collapses that space into /var,
   removing /home collapses that space into /usr.

   This patch only collapses space into an auto-created partition.  It will
   not extend a manually created partition.  I still have some work to do...
   I need to add a NEWFS flag to libdisk so the code only extends partitions
   which are marked for NEWFSing (at the moment limiting it to auto-created
   partitions is good enough for testing purposes).

						-Matt

Index: lib/libdisk/chunk.c
===================================================================
RCS file: /home/ncvs/src/lib/libdisk/chunk.c,v
retrieving revision 1.28
diff -u -r1.28 chunk.c
--- lib/libdisk/chunk.c	2001/09/30 21:16:57	1.28
+++ lib/libdisk/chunk.c	2001/12/09 20:48:57
@@ -363,6 +363,7 @@
 {
 	struct chunk *c1=0, *c2, *c3;
 	chunk_e type = c->type;
+	long offset = c->offset;
 
 	if(type == whole)
 		return 1;
@@ -398,9 +399,18 @@
 	}
 	return 1;
     scan:
+	/*
+	 * Collapse multiple unused elements together, and attempt
+	 * to extend the previous chunk into the freed chunk.
+	 */
 	for(c2 = c1->part; c2; c2 = c2->next) {
-		if (c2->type != unused)
-			continue;
+		if (c2->type != unused) {
+			if (c2->offset + c2->size != offset ||
+			    (c2->flags & CHUNK_AUTO_SIZE) == 0) {
+				continue;
+			}
+			/* else extend into free area */
+		}
 		if (!c2->next)
 			continue;
 		if (c2->next->type != unused)
Index: lib/libdisk/disk.c
===================================================================
RCS file: /home/ncvs/src/lib/libdisk/disk.c,v
retrieving revision 1.72
diff -u -r1.72 disk.c
--- lib/libdisk/disk.c	2001/10/15 07:25:29	1.72
+++ lib/libdisk/disk.c	2001/12/09 20:48:16
@@ -478,9 +478,9 @@
 #endif
 
 #ifdef PC98
-static char * device_list[] = {"wd", "aacd", "ad", "da", "afd", "fla", "idad", "mlxd", "amrd", "twed", "ar", "fd", 0};
+static char * device_list[] = {"wd", "aacd", "ad", "da", "afd", "fla", "idad", "mlxd", "amrd", "twed", "ar", "fd", "md", 0};
 #else
-static char * device_list[] = {"aacd", "ad", "da", "afd", "fla", "idad", "mlxd", "amrd", "twed", "ar", "fd", 0};
+static char * device_list[] = {"aacd", "ad", "da", "afd", "fla", "idad", "mlxd", "amrd", "twed", "ar", "fd", "md", 0};
 #endif
 
 char **
Index: lib/libdisk/libdisk.h
===================================================================
RCS file: /home/ncvs/src/lib/libdisk/libdisk.h,v
retrieving revision 1.39
diff -u -r1.39 libdisk.h
--- lib/libdisk/libdisk.h	2001/05/13 20:08:54	1.39
+++ lib/libdisk/libdisk.h	2001/12/09 20:36:35
@@ -69,21 +69,6 @@
 	chunk_e		type;
 	int		subtype;
 	u_long		flags;
-#		define CHUNK_BSD_COMPAT	2
-		/* this chunk is in the BSD-compatibility, and has a
-		 * short name too, ie wd0s4f -> wd0f
-		*/
-#		define CHUNK_ALIGN		8
-		/* This chunk should be aligned */
-#		define CHUNK_IS_ROOT		16
-		/* This 'part' is a rootfs, allocate 'a' */
-#		define CHUNK_ACTIVE		32
-		/* This is the active slice in the MBR */
-#		define CHUNK_FORCE_ALL		64
-		/* Force a dedicated disk for FreeBSD, bypassing
-		 * all BIOS geometry considerations
-		 */
-
 	void		(*private_free)(void*);
 	void		*(*private_clone)(void*);
 	void		*private_data;
@@ -93,6 +78,28 @@
 	 * and freeing will just forget it.
 	 */
 };
+
+/*
+ * flags:
+ *
+ * BSD_COMPAT	-	This chunk is in the BSD-compatibility, and has
+ *			a short name too, ie wd0s4f -> wd0f
+ * ALIGN	-	This chunk should be aligned
+ * IS_ROOT	-	This 'part' is a rootfs, allocate 'a'
+ * ACTIVE	-	This is the active slice in the MBR
+ * FORCE_ALL	-	Force a dedicated disk for FreeBSD, bypassing
+ *			all BIOS geometry considerations
+ * AUTO_SIZE	-	This chunk was auto-sized and can fill-out a
+ *			following chunk if the following chunk is deleted.
+ */
+
+#define CHUNK_BSD_COMPAT	0x0002
+#define CHUNK_ALIGN		0x0008
+#define CHUNK_IS_ROOT		0x0010
+#define CHUNK_ACTIVE		0x0020
+#define CHUNK_FORCE_ALL		0x0040	
+#define CHUNK_AUTO_SIZE		0x0080
+
 
 extern const char *chunk_n[];
 
Index: usr.sbin/sysinstall/devices.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/sysinstall/devices.c,v
retrieving revision 1.137
diff -u -r1.137 devices.c
--- usr.sbin/sysinstall/devices.c	30 Sep 2001 00:43:32 -0000	1.137
+++ usr.sbin/sysinstall/devices.c	9 Dec 2001 20:51:21 -0000
@@ -439,9 +439,11 @@
 	    Chunk *c1;
 	    Disk *d;
 
+#if 0
 	    /* Ignore memory disks */
 	    if (!strncmp(names[i], "md", 2))
 		continue;
+#endif
 
 	    d = Open_Disk(names[i]);
 	    if (!d) {
Index: usr.sbin/sysinstall/label.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/sysinstall/label.c,v
retrieving revision 1.111
diff -u -r1.111 label.c
--- usr.sbin/sysinstall/label.c	9 Dec 2001 09:47:09 -0000	1.111
+++ usr.sbin/sysinstall/label.c	9 Dec 2001 20:51:22 -0000
@@ -1183,8 +1183,9 @@
     if (!rootdev) {
 	sz = requested_part_size(VAR_ROOT_SIZE, ROOT_NOMINAL_SIZE, ROOT_DEFAULT_SIZE, perc);
 
-	root_chunk = Create_Chunk_DWIM(label_chunk_info[here].c->disk, label_chunk_info[here].c,
-				sz, part, FS_BSDFFS,  CHUNK_IS_ROOT);
+	root_chunk = Create_Chunk_DWIM(label_chunk_info[here].c->disk,
+			    label_chunk_info[here].c, sz, part,
+			    FS_BSDFFS,  CHUNK_IS_ROOT | CHUNK_AUTO_SIZE);
 	if (!root_chunk) {
 	    *req = 1;
 	    msg = "Unable to create the root partition. Too big?";
@@ -1212,8 +1213,9 @@
 	    nom = (int)(physmem / 512) / 2;
 	    sz = nom + (def - nom) * perc / 100;
 	}
-	swap_chunk = Create_Chunk_DWIM(label_chunk_info[here].c->disk, label_chunk_info[here].c,
-				sz, part, FS_SWAP, 0);
+	swap_chunk = Create_Chunk_DWIM(label_chunk_info[here].c->disk, 
+			    label_chunk_info[here].c, sz, part,
+			    FS_SWAP, CHUNK_AUTO_SIZE);
 	if (!swap_chunk) {
 	    *req = 1;
 	    msg = "Unable to create the swap partition. Too big?";
@@ -1226,8 +1228,9 @@
     if (!vardev) {
 	sz = requested_part_size(VAR_VAR_SIZE, VAR_NOMINAL_SIZE, VAR_DEFAULT_SIZE, perc);
 
-	var_chunk = Create_Chunk_DWIM(label_chunk_info[here].c->disk, label_chunk_info[here].c,
-				sz, part, FS_BSDFFS, 0);
+	var_chunk = Create_Chunk_DWIM(label_chunk_info[here].c->disk, 
+				label_chunk_info[here].c, sz, part,
+				FS_BSDFFS, CHUNK_AUTO_SIZE);
 	if (!var_chunk) {
 	    *req = 1;
 	    msg = "Not enough free space for /var - you will need to\n"
@@ -1241,8 +1244,9 @@
     if (!vartmpdev && !variable_get(VAR_NO_VARTMP)) {
 	sz = requested_part_size(VAR_VARTMP_SIZE, VARTMP_NOMINAL_SIZE, VARTMP_DEFAULT_SIZE, perc);
 
-	vartmp_chunk = Create_Chunk_DWIM(label_chunk_info[here].c->disk, label_chunk_info[here].c,
-				sz, part, FS_BSDFFS, 0);
+	vartmp_chunk = Create_Chunk_DWIM(label_chunk_info[here].c->disk, 
+				label_chunk_info[here].c, sz, part,
+				FS_BSDFFS, CHUNK_AUTO_SIZE);
 	if (!vartmp_chunk) {
 	    *req = 1;
 	    msg = "Not enough free space for /var/tmp - you will need to\n"
@@ -1266,8 +1270,8 @@
 	    }
 
 	    usr_chunk = Create_Chunk_DWIM(label_chunk_info[here].c->disk,
-				    label_chunk_info[here].c,
-				    sz, part, FS_BSDFFS, 0);
+				    label_chunk_info[here].c, sz, part,
+				    FS_BSDFFS, CHUNK_AUTO_SIZE);
 	    if (!usr_chunk) {
 		msg = "Unable to create the /usr partition.  Not enough space?\n"
 			   "You will need to partition your disk manually with a custom install!";
@@ -1291,8 +1295,8 @@
 	    }
 
 	    home_chunk = Create_Chunk_DWIM(label_chunk_info[here].c->disk,
-				    label_chunk_info[here].c,
-				    sz, part, FS_BSDFFS, 0);
+				    label_chunk_info[here].c, sz, part,
+				    FS_BSDFFS, CHUNK_AUTO_SIZE);
 	    if (!home_chunk) {
 		msg = "Unable to create the /home partition.  Not enough space?\n"
 			   "You will need to partition your disk manually with a custom install!";

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




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