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
This commit is contained in:
parent
f34d9e5d6b
commit
473fe2c000
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=350359
@ -746,9 +746,11 @@ swapon_trim(const char *name)
|
|||||||
off_t ioarg[2], sz;
|
off_t ioarg[2], sz;
|
||||||
int error, fd;
|
int error, fd;
|
||||||
|
|
||||||
|
/* Open a descriptor to create a consumer of the device. */
|
||||||
fd = open(name, O_WRONLY);
|
fd = open(name, O_WRONLY);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
errx(1, "Cannot open %s", name);
|
errx(1, "Cannot open %s", name);
|
||||||
|
/* Find the device size. */
|
||||||
if (fstat(fd, &sb) < 0)
|
if (fstat(fd, &sb) < 0)
|
||||||
errx(1, "Cannot stat %s", name);
|
errx(1, "Cannot stat %s", name);
|
||||||
if (S_ISREG(sb.st_mode))
|
if (S_ISREG(sb.st_mode))
|
||||||
@ -758,18 +760,22 @@ swapon_trim(const char *name)
|
|||||||
err(1, "ioctl(DIOCGMEDIASIZE)");
|
err(1, "ioctl(DIOCGMEDIASIZE)");
|
||||||
} else
|
} else
|
||||||
errx(1, "%s has an invalid file type", name);
|
errx(1, "%s has an invalid file type", name);
|
||||||
|
/* Trim the device. */
|
||||||
ioarg[0] = 0;
|
ioarg[0] = 0;
|
||||||
ioarg[1] = sz;
|
ioarg[1] = sz;
|
||||||
if (ioctl(fd, DIOCGDELETE, ioarg) != 0)
|
if (ioctl(fd, DIOCGDELETE, ioarg) != 0)
|
||||||
warn("ioctl(DIOCGDELETE)");
|
warn("ioctl(DIOCGDELETE)");
|
||||||
|
|
||||||
/*
|
/* Start using the device for swapping, creating a second consumer. */
|
||||||
* 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);
|
error = swapon(name);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
close(fd);
|
close(fd);
|
||||||
return (error);
|
return (error);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user