Index | Thread | Search

From:
Jonathan Gray <jsg@jsg.id.au>
Subject:
remove swap device struct
To:
tech@openbsd.org
Date:
Thu, 24 Oct 2024 22:32:31 +1100

Download raw body.

Thread
only the dev_t is used in struct swdevt

diff --git sys/arch/arm64/dev/apm.c sys/arch/arm64/dev/apm.c
index 49d4e1a6610..c030f7a3ca7 100644
--- sys/arch/arm64/dev/apm.c
+++ sys/arch/arm64/dev/apm.c
@@ -380,7 +380,7 @@ request_sleep(int sleepmode)
 		break;
 #ifdef HIBERNATE
 	case SLEEP_HIBERNATE:
-		if (get_hibernate_io_function(swdevt[0].sw_dev) == NULL)
+		if (get_hibernate_io_function(swdevt[0]) == NULL)
 			return EOPNOTSUPP;
 		task_add(sleep_taskq, &hibernate_task);
 		break;
diff --git sys/conf/swapgeneric.c sys/conf/swapgeneric.c
index a47c541db0a..dd672710833 100644
--- sys/conf/swapgeneric.c
+++ sys/conf/swapgeneric.c
@@ -47,7 +47,7 @@ int (*mountroot)(void) = NULL; /* tells autoconf.c that we are "generic" */
 dev_t	rootdev = NODEV;
 dev_t	dumpdev = NODEV;
 
-struct	swdevt swdevt[] = {
-	{ NODEV, 0 },	/* to be filled in */
-	{ NODEV, 0 }
+dev_t	swdevt[] = {
+	NODEV,		/* to be filled in */
+	NODEV
 };
diff --git sys/dev/acpi/acpi_apm.c sys/dev/acpi/acpi_apm.c
index c10e9d8607f..71eb1974d8a 100644
--- sys/dev/acpi/acpi_apm.c
+++ sys/dev/acpi/acpi_apm.c
@@ -138,7 +138,7 @@ acpiioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
 			error = EBADF;
 			break;
 		}
-		if (get_hibernate_io_function(swdevt[0].sw_dev) == NULL) {
+		if (get_hibernate_io_function(swdevt[0]) == NULL) {
 			error = EOPNOTSUPP;
 			break;
 		}
@@ -225,7 +225,7 @@ request_sleep(int sleepmode)
 
 #ifdef HIBERNATE
 	if (sleepmode == SLEEP_HIBERNATE) {
-		if (get_hibernate_io_function(swdevt[0].sw_dev) == NULL)
+		if (get_hibernate_io_function(swdevt[0]) == NULL)
 			return EOPNOTSUPP;
 	}
 #endif
diff --git sys/kern/subr_disk.c sys/kern/subr_disk.c
index bf169beff2e..5d51754b45a 100644
--- sys/kern/subr_disk.c
+++ sys/kern/subr_disk.c
@@ -1423,7 +1423,7 @@ void
 setroot(struct device *bootdv, int part, int exitflags)
 {
 	int majdev, unit, len, s, slept = 0;
-	struct swdevt *swp;
+	dev_t *swp;
 	struct device *dv;
 	dev_t nrootdev, nswapdev = NODEV, temp = NODEV;
 	struct ifnet *ifp = NULL;
@@ -1564,8 +1564,8 @@ setroot(struct device *bootdv, int part, int exitflags)
 gotswap:
 		rootdev = nrootdev;
 		dumpdev = nswapdev;
-		swdevt[0].sw_dev = nswapdev;
-		swdevt[1].sw_dev = NODEV;
+		swdevt[0] = nswapdev;
+		swdevt[1] = NODEV;
 #if defined(NFSCLIENT)
 	} else if (mountroot == nfs_mountroot) {
 		rootdv = bootdv;
@@ -1605,8 +1605,8 @@ gotswap:
 			nswapdev = NODEV;
 		}
 		dumpdev = nswapdev;
-		swdevt[0].sw_dev = nswapdev;
-		/* swdevt[1].sw_dev = NODEV; */
+		swdevt[0] = nswapdev;
+		/* swdevt[1] = NODEV; */
 	} else {
 		/* Completely pre-configured, but we want rootdv .. */
 		majdev = major(rootdev);
@@ -1653,27 +1653,27 @@ gotswap:
 	/*
 	 * Make the swap partition on the root drive the primary swap.
 	 */
-	for (swp = swdevt; swp->sw_dev != NODEV; swp++) {
-		if (major(rootdev) == major(swp->sw_dev) &&
-		    DISKUNIT(rootdev) == DISKUNIT(swp->sw_dev)) {
-			temp = swdevt[0].sw_dev;
-			swdevt[0].sw_dev = swp->sw_dev;
-			swp->sw_dev = temp;
+	for (swp = swdevt; *swp != NODEV; swp++) {
+		if (major(rootdev) == major(*swp) &&
+		    DISKUNIT(rootdev) == DISKUNIT(*swp)) {
+			temp = swdevt[0];
+			swdevt[0] = *swp;
+			*swp = temp;
 			break;
 		}
 	}
-	if (swp->sw_dev != NODEV) {
+	if (*swp != NODEV) {
 		/*
 		 * If dumpdev was the same as the old primary swap device,
 		 * move it to the new primary swap device.
 		 */
 		if (temp == dumpdev)
-			dumpdev = swdevt[0].sw_dev;
+			dumpdev = swdevt[0];
 	}
-	if (swdevt[0].sw_dev != NODEV)
-		printf(" swap on %s%d%c", findblkname(major(swdevt[0].sw_dev)),
-		    DISKUNIT(swdevt[0].sw_dev),
-		    'a' + DISKPART(swdevt[0].sw_dev));
+	if (swdevt[0] != NODEV)
+		printf(" swap on %s%d%c", findblkname(major(swdevt[0])),
+		    DISKUNIT(swdevt[0]),
+		    'a' + DISKPART(swdevt[0]));
 	if (dumpdev != NODEV)
 		printf(" dump on %s%d%c", findblkname(major(dumpdev)),
 		    DISKUNIT(dumpdev), 'a' + DISKPART(dumpdev));
diff --git sys/kern/subr_hibernate.c sys/kern/subr_hibernate.c
index 464bc48bab0..94f1c8dff86 100644
--- sys/kern/subr_hibernate.c
+++ sys/kern/subr_hibernate.c
@@ -573,12 +573,12 @@ get_hibernate_info(union hibernate_info *hib, int suspend)
 #endif /* ! NO_PROPOLICE */
 
 	/* Determine I/O function to use */
-	hib->io_func = get_hibernate_io_function(swdevt[0].sw_dev);
+	hib->io_func = get_hibernate_io_function(swdevt[0]);
 	if (hib->io_func == NULL)
 		return (1);
 
 	/* Calculate hibernate device */
-	hib->dev = swdevt[0].sw_dev;
+	hib->dev = swdevt[0];
 
 	/* Read disklabel (used to calculate signature and image offsets) */
 	dl_ret = disk_readlabel(&dl, hib->dev, err_string, sizeof(err_string));
diff --git sys/nfs/nfs_vfsops.c sys/nfs/nfs_vfsops.c
index 1bb790f3328..f467a456633 100644
--- sys/nfs/nfs_vfsops.c
+++ sys/nfs/nfs_vfsops.c
@@ -255,7 +255,7 @@ struct nfs_diskless nfs_diskless;
  * - Call nfs_boot_init() to fill in the nfs_diskless struct
  *   (using RARP, bootparam RPC, mountd RPC)
  * - hand craft the swap nfs vnode hanging off a fake mount point
- *	if swdevt[0].sw_dev == NODEV
+ *	if swdevt[0] == NODEV
  * - build the rootfs mount point and call mountnfs() to do the rest.
  */
 int
@@ -315,17 +315,17 @@ nfs_mountroot(void)
 	 * "Mount" the swap device.
 	 *
 	 * On a "dataless" configuration (swap on disk) we will have:
-	 *	(swdevt[0].sw_dev != NODEV) identifying the swap device.
+	 *	(swdevt[0] != NODEV) identifying the swap device.
 	 */
-	if (swdevt[0].sw_dev != NODEV) {
+	if (swdevt[0] != NODEV) {
 		if (bdevvp(swapdev, &swapdev_vp))
 			panic("nfs_mountroot: can't setup swap vp");
-		printf("swap on device 0x%x\n", swdevt[0].sw_dev);
+		printf("swap on device 0x%x\n", swdevt[0]);
 		return (0);
 	}
 
 	/*
-	 * If swapping to an nfs node:	(swdevt[0].sw_dev == NODEV)
+	 * If swapping to an nfs node:	(swdevt[0] == NODEV)
 	 * Create a fake mount point just for the swap vnode so that the
 	 * swap file can be on a different server from the rootfs.
 	 *
@@ -348,7 +348,7 @@ nfs_mountroot(void)
 		 * Next line is a hack to make swapmount() work on NFS
 		 * swap files.
 		 */
-		swdevt[0].sw_dev = NETDEV;
+		swdevt[0] = NETDEV;
 		/* end hack */
 		nfs_diskless.sw_vp = vp;
 
@@ -368,7 +368,7 @@ nfs_mountroot(void)
 	}
 
 	printf("WARNING: no swap\n");
-	swdevt[0].sw_dev = NODEV;
+	swdevt[0] = NODEV;
 	return (0);
 }
 
diff --git sys/sys/conf.h sys/sys/conf.h
index 422cd7f5c2a..0123d81dc2d 100644
--- sys/sys/conf.h
+++ sys/sys/conf.h
@@ -523,21 +523,7 @@ struct linesw {
 
 #ifdef _KERNEL
 extern struct linesw linesw[];
-#endif
-
-/*
- * Swap device table
- */
-struct swdevt {
-	dev_t	sw_dev;
-	int	sw_flags;
-};
-#define	SW_FREED	0x01
-#define	SW_SEQUENTIAL	0x02
-#define	sw_freed	sw_flags	/* XXX compat */
-
-#ifdef _KERNEL
-extern struct swdevt swdevt[];
+extern dev_t swdevt[];		/* Swap device table */
 extern const int chrtoblktbl[];
 extern const int nchrtoblktbl;
 
diff --git sys/uvm/uvm_swap.c sys/uvm/uvm_swap.c
index b2df93b7edf..2fd32597f53 100644
--- sys/uvm/uvm_swap.c
+++ sys/uvm/uvm_swap.c
@@ -1007,7 +1007,7 @@ swap_on(struct proc *p, struct swapdev *sdp)
 	 * Lock down the last region of primary disk swap, in case
 	 * hibernate needs to place a signature there.
 	 */
-	if (dev == swdevt[0].sw_dev && vp->v_type == VBLK && size > 3 ) {
+	if (dev == swdevt[0] && vp->v_type == VBLK && size > 3 ) {
 		if (blist_fill(sdp->swd_blist, npages - 1, 1) != 1)
 			panic("hibernate reserve");
 	}
@@ -1964,7 +1964,7 @@ swapmount(void)
 	struct swapdev *sdp;
 	struct swappri *spp;
 	struct vnode *vp;
-	dev_t swap_dev = swdevt[0].sw_dev;
+	dev_t swap_dev = swdevt[0];
 	char *nam;
 	char path[MNAMELEN + 1];
 
@@ -2037,7 +2037,7 @@ uvm_hibswap(dev_t dev, u_long *sp, u_long *ep)
 	struct swappri *spp;
 
 	/* no swap devices configured yet? */
-	if (uvmexp.nswapdev < 1 || dev != swdevt[0].sw_dev)
+	if (uvmexp.nswapdev < 1 || dev != swdevt[0])
 		return (1);
 
 	LIST_FOREACH(spp, &swap_priority, spi_swappri) {
diff --git usr.sbin/config/mkswap.c usr.sbin/config/mkswap.c
index f4a726fbb5d..ec62c513fd5 100644
--- usr.sbin/config/mkswap.c
+++ usr.sbin/config/mkswap.c
@@ -108,13 +108,13 @@ mkoneswap(struct config *cf)
 	if (fprintf(fp, "dev_t\tdumpdev = %s;\t/* %s */\n",
 	    mkdevstr(nv->nv_int), nv->nv_str) < 0)
 		goto wrerror;
-	if (fputs("\nstruct\tswdevt swdevt[] = {\n", fp) == EOF)
+	if (fputs("\ndev_t\tswdevt[] = {\n", fp) == EOF)
 		goto wrerror;
 	for (nv = cf->cf_swap; nv != NULL; nv = nv->nv_next)
-		if (fprintf(fp, "\t{ %s,\t0 },\t/* %s */\n",
+		if (fprintf(fp, "\t%s,\t/* %s */\n",
 		    mkdevstr(nv->nv_int), nv->nv_str) < 0)
 			goto wrerror;
-	if (fputs("\t{ NODEV, 0 }\n};\n\n", fp) == EOF)
+	if (fputs("\tNODEV\n};\n\n", fp) == EOF)
 		goto wrerror;
 	mountroot =
 	    cf->cf_root->nv_str == s_nfs ? "nfs_mountroot" : "dk_mountroot";