From owner-svn-src-all@freebsd.org Fri Jul 26 15:18:12 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 00DDBA333B; Fri, 26 Jul 2019 15:18:11 +0000 (UTC) (envelope-from dougm@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id CFD106DEE0; Fri, 26 Jul 2019 15:18:11 +0000 (UTC) (envelope-from dougm@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 8C15A19033; Fri, 26 Jul 2019 15:18:11 +0000 (UTC) (envelope-from dougm@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x6QFIB01059385; Fri, 26 Jul 2019 15:18:11 GMT (envelope-from dougm@FreeBSD.org) Received: (from dougm@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x6QFIBPk059384; Fri, 26 Jul 2019 15:18:11 GMT (envelope-from dougm@FreeBSD.org) Message-Id: <201907261518.x6QFIBPk059384@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dougm set sender to dougm@FreeBSD.org using -f From: Doug Moore Date: Fri, 26 Jul 2019 15:18:11 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r350359 - head/sbin/swapon X-SVN-Group: head X-SVN-Commit-Author: dougm X-SVN-Commit-Paths: head/sbin/swapon X-SVN-Commit-Revision: 350359 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: CFD106DEE0 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.94 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.94)[-0.941,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Jul 2019 15:18:12 -0000 Author: dougm Date: Fri Jul 26 15:18:11 2019 New Revision: 350359 URL: https://svnweb.freebsd.org/changeset/base/350359 Log: Rewrite the comments that explain swapon_trim() to make them more comprehensible. Suggested by: rpokala Approved by: markj (mentor) Differential Revision: https://reviews.freebsd.org/D21034 Modified: head/sbin/swapon/swapon.c Modified: head/sbin/swapon/swapon.c ============================================================================== --- head/sbin/swapon/swapon.c Fri Jul 26 13:12:33 2019 (r350358) +++ head/sbin/swapon/swapon.c Fri Jul 26 15:18:11 2019 (r350359) @@ -746,9 +746,11 @@ swapon_trim(const char *name) off_t ioarg[2], sz; int error, fd; + /* Open a descriptor to create a consumer of the device. */ fd = open(name, O_WRONLY); if (fd < 0) errx(1, "Cannot open %s", name); + /* Find the device size. */ if (fstat(fd, &sb) < 0) errx(1, "Cannot stat %s", name); if (S_ISREG(sb.st_mode)) @@ -758,18 +760,22 @@ swapon_trim(const char *name) err(1, "ioctl(DIOCGMEDIASIZE)"); } else errx(1, "%s has an invalid file type", name); + /* Trim the device. */ ioarg[0] = 0; ioarg[1] = sz; if (ioctl(fd, DIOCGDELETE, ioarg) != 0) warn("ioctl(DIOCGDELETE)"); + /* Start using the device for swapping, creating a second consumer. */ + error = swapon(name); + /* - * 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. + * Do not close the device until the swap pager has attempted to create + * another consumer. For GELI devices created with the 'detach -l' + * option, removing the last consumer causes the device to be detached + * - that is, to disappear. This ordering ensures that the device will + * not be detached until swapoff is called. */ - error = swapon(name); close(fd); return (error); }