Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F150823156
D21034.id60050.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D21034.id60050.diff
View Options
Index: sbin/swapon/swapon.c
===================================================================
--- sbin/swapon/swapon.c
+++ sbin/swapon/swapon.c
@@ -746,9 +746,11 @@
off_t ioarg[2], sz;
int error, fd;
+ /* Open a connection 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 @@
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);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Apr 5, 7:21 AM (14 h, 1 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
30877801
Default Alt Text
D21034.id60050.diff (1 KB)
Attached To
Mode
D21034: improve swapon comments
Attached
Detach File
Event Timeline
Log In to Comment