Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F140466754
D21006.id59966.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
D21006.id59966.diff
View Options
Index: sbin/swapon/swapon.c
===================================================================
--- sbin/swapon/swapon.c
+++ sbin/swapon/swapon.c
@@ -739,12 +739,12 @@
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 @@
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 @@
{
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) {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 25, 6:31 AM (4 h, 9 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
27242620
Default Alt Text
D21006.id59966.diff (1 KB)
Attached To
Mode
D21006: swapon before closing trimming fd
Attached
Detach File
Event Timeline
Log In to Comment