Date: Sun, 15 Sep 2019 20:13:46 +0000 (UTC) From: Doug Moore <dougm@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r352365 - in stable/12: sbin/swapon share/man/man5 sys/vm Message-ID: <201909152013.x8FKDkad040406@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: dougm Date: Sun Sep 15 20:13:46 2019 New Revision: 352365 URL: https://svnweb.freebsd.org/changeset/base/352365 Log: MFC 351064 Don't let swapon trimming wipe the bsd label. Reviewed by: alc Approved by: markj (mentor, implicit) Modified: stable/12/sbin/swapon/swapon.8 stable/12/sbin/swapon/swapon.c stable/12/share/man/man5/fstab.5 stable/12/sys/vm/swap_pager.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sbin/swapon/swapon.8 ============================================================================== --- stable/12/sbin/swapon/swapon.8 Sun Sep 15 19:41:54 2019 (r352364) +++ stable/12/sbin/swapon/swapon.8 Sun Sep 15 20:13:46 2019 (r352365) @@ -90,7 +90,17 @@ The .Fl E option causes each of following devices to receive a .Dv BIO_DELETE -command to mark all blocks as unused. +command. +This command marks the device's blocks as unused, except those that +might store a disk label. +This marking can erase a crash dump. +To delay +.Nm swapon +for a device until after +.Nm savecore +has copied the crash dump to another location, use the +.Dq late +option. .Pp The .Nm swapoff Modified: stable/12/sbin/swapon/swapon.c ============================================================================== --- stable/12/sbin/swapon/swapon.c Sun Sep 15 19:41:54 2019 (r352364) +++ stable/12/sbin/swapon/swapon.c Sun Sep 15 20:13:46 2019 (r352365) @@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$"); #include <sys/param.h> #include <sys/disk.h> +#include <sys/disklabel.h> #include <sys/mdioctl.h> #include <sys/stat.h> #include <sys/sysctl.h> @@ -761,8 +762,8 @@ swapon_trim(const char *name) } else errx(1, "%s has an invalid file type", name); /* Trim the device. */ - ioarg[0] = 0; - ioarg[1] = sz; + ioarg[0] = BBSIZE; + ioarg[1] = sz - BBSIZE; if (ioctl(fd, DIOCGDELETE, ioarg) != 0) warn("ioctl(DIOCGDELETE)"); Modified: stable/12/share/man/man5/fstab.5 ============================================================================== --- stable/12/share/man/man5/fstab.5 Sun Sep 15 19:41:54 2019 (r352364) +++ stable/12/share/man/man5/fstab.5 Sun Sep 15 20:13:46 2019 (r352365) @@ -220,8 +220,17 @@ For swap devices, the keyword .Dq trimonce triggers the delivery of a .Dv BIO_DELETE -command to the device to mark -all blocks as unused. +command to the device. +This command marks the device's blocks as unused, except those that +might store a disk label. +This marking can erase a crash dump. +To delay +.Nm swapon +for a device until after +.Nm savecore +has copied the crash dump to another location, use the +.Dq late +option. For vnode-backed swap spaces, .Dq file is supported in the Modified: stable/12/sys/vm/swap_pager.c ============================================================================== --- stable/12/sys/vm/swap_pager.c Sun Sep 15 19:41:54 2019 (r352364) +++ stable/12/sys/vm/swap_pager.c Sun Sep 15 20:13:46 2019 (r352365) @@ -83,6 +83,7 @@ __FBSDID("$FreeBSD$"); #include <sys/bio.h> #include <sys/buf.h> #include <sys/disk.h> +#include <sys/disklabel.h> #include <sys/fcntl.h> #include <sys/mount.h> #include <sys/namei.h> @@ -2240,10 +2241,11 @@ swaponsomething(struct vnode *vp, void *id, u_long nbl sp->sw_blist = blist_create(nblks, M_WAITOK); /* - * Do not free the first two block in order to avoid overwriting + * Do not free the first blocks in order to avoid overwriting * any bsd label at the front of the partition */ - blist_free(sp->sw_blist, 2, nblks - 2); + blist_free(sp->sw_blist, howmany(BBSIZE, PAGE_SIZE), + nblks - howmany(BBSIZE, PAGE_SIZE)); dvbase = 0; mtx_lock(&sw_dev_mtx); @@ -2261,7 +2263,7 @@ swaponsomething(struct vnode *vp, void *id, u_long nbl sp->sw_end = dvbase + nblks; TAILQ_INSERT_TAIL(&swtailq, sp, sw_list); nswapdev++; - swap_pager_avail += nblks - 2; + swap_pager_avail += nblks - howmany(BBSIZE, PAGE_SIZE); swap_total += nblks; swapon_check_swzone(); swp_sizecheck();
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201909152013.x8FKDkad040406>