diff options
author | Doug Moore <dougm@FreeBSD.org> | 2019-07-20 20:47:07 +0000 |
---|---|---|
committer | Doug Moore <dougm@FreeBSD.org> | 2019-07-20 20:47:07 +0000 |
commit | 6d5685c76278d8a3b7765b03bc33f0152af8f7a9 (patch) | |
tree | 4eb0e77c29977b64a9e95ecd62e9b91a763a620a | |
parent | b16e57a6c9a4c6f4f482445766f6c83796e5cfbb (diff) | |
download | src-6d5685c76278d8a3b7765b03bc33f0152af8f7a9.tar.gz src-6d5685c76278d8a3b7765b03bc33f0152af8f7a9.zip |
In trimming on startup, invoke swapon before closing the fd used for
trimming so that a geli device isn't detached before swapon is
invoked.
Submitted by: sigsys_gmail.com
Discussed with: alc
Approved by: markj (mentor)
Differential Revision: https://reviews.freebsd.org/D21006
Notes
Notes:
svn path=/head/; revision=350183
-rw-r--r-- | sbin/swapon/swapon.c | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/sbin/swapon/swapon.c b/sbin/swapon/swapon.c index e6c8b7eb215d..06250f3ecd73 100644 --- a/sbin/swapon/swapon.c +++ b/sbin/swapon/swapon.c @@ -739,12 +739,12 @@ run_cmd(int *ofd, const char *cmdline, ...) return (WEXITSTATUS(status)); } -static void -swap_trim(const char *name) +static int +swapon_trim(const char *name) { struct stat sb; off_t ioarg[2], sz; - int fd; + int error, fd; fd = open(name, O_WRONLY); if (fd < 0) @@ -762,7 +762,16 @@ swap_trim(const char *name) ioarg[1] = sz; if (ioctl(fd, DIOCGDELETE, ioarg) != 0) warn("ioctl(DIOCGDELETE)"); + + /* + * swapon is invoked after trimming, so that the trimming doesn't happen + * after the device is in use for swapping, but before the fd is closed, + * for the benefit of geli, which could otherwise detach the device, + * before swapon, on close. + */ + error = swapon(name); close(fd); + return (error); } static const char * @@ -770,11 +779,9 @@ swap_on_off_sfile(const char *name, int doingall) { int error; - if (which_prog == SWAPON) { - if (Eflag) - swap_trim(name); - error = swapon(name); - } else /* SWAPOFF */ + if (which_prog == SWAPON) + error = Eflag ? swapon_trim(name) : swapon(name); + else /* SWAPOFF */ error = swapoff(name); if (error == -1) { |