Skip to content

Commit 0108b3c

Browse files
authored
Puts direct_io support behind a feature flag (mdaffin#39)
Fixes mdaffin#38 * Puts direct_io support behind a feature flag * Bumps minimum version in travis
1 parent 14af6ff commit 0108b3c

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

.travis.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ rust:
1111
- nightly
1212
- beta
1313
- stable
14-
- 1.42.0
15-
- 1.41.0
16-
- 1.40.0
14+
- 1.45.0
15+
- 1.44.0
16+
- 1.43.0
1717

1818
matrix:
1919
allow_failures:

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ keywords = ["loop", "losetup"]
1212
[badges]
1313
travis-ci = { repository = "serde-rs/serde" }
1414

15+
[features]
16+
direct_io = []
17+
1518
[dependencies]
1619
errno = "0.2"
1720
libc = "0.2"

src/lib.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@
3636
3737
extern crate libc;
3838

39+
#[cfg(feature = "direct_io")]
40+
use bindings::LOOP_SET_DIRECT_IO;
3941
use bindings::{
40-
loop_info64, LOOP_CLR_FD, LOOP_CTL_GET_FREE, LOOP_SET_CAPACITY, LOOP_SET_DIRECT_IO,
41-
LOOP_SET_FD, LOOP_SET_STATUS64, LO_FLAGS_AUTOCLEAR, LO_FLAGS_READ_ONLY,
42+
loop_info64, LOOP_CLR_FD, LOOP_CTL_GET_FREE, LOOP_SET_CAPACITY, LOOP_SET_FD, LOOP_SET_STATUS64,
43+
LO_FLAGS_AUTOCLEAR, LO_FLAGS_READ_ONLY,
4244
};
4345
use libc::{c_int, ioctl};
4446
use std::{
@@ -160,6 +162,7 @@ impl LoopDevice {
160162
AttachOptions {
161163
device: self,
162164
info: Default::default(),
165+
#[cfg(feature = "direct_io")]
163166
direct_io: false,
164167
}
165168
}
@@ -343,6 +346,7 @@ impl LoopDevice {
343346
}
344347

345348
// Enable or disable direct I/O for the backing file.
349+
#[cfg(feature = "direct_io")]
346350
pub fn set_direct_io(&self, direct_io: bool) -> io::Result<()> {
347351
ioctl_to_error(unsafe {
348352
ioctl(
@@ -386,6 +390,7 @@ impl LoopDevice {
386390
pub struct AttachOptions<'d> {
387391
device: &'d LoopDevice,
388392
info: loop_info64,
393+
#[cfg(feature = "direct_io")]
389394
direct_io: bool,
390395
}
391396

@@ -423,6 +428,7 @@ impl AttachOptions<'_> {
423428
}
424429

425430
// Enable or disable direct I/O for the backing file.
431+
#[cfg(feature = "direct_io")]
426432
pub fn set_direct_io(mut self, direct_io: bool) -> Self {
427433
self.direct_io = direct_io;
428434
self
@@ -442,6 +448,7 @@ impl AttachOptions<'_> {
442448
/// Attach the loop device to a file with the set options.
443449
pub fn attach(self, backing_file: impl AsRef<Path>) -> io::Result<()> {
444450
self.device.attach_with_loop_info(backing_file, self.info)?;
451+
#[cfg(feature = "direct_io")]
445452
if self.direct_io {
446453
self.device.set_direct_io(self.direct_io)?;
447454
}
@@ -452,6 +459,7 @@ impl AttachOptions<'_> {
452459
pub fn attach_fd(self, backing_file_fd: impl AsRawFd) -> io::Result<()> {
453460
self.device
454461
.attach_fd_with_loop_info(backing_file_fd, self.info)?;
462+
#[cfg(feature = "direct_io")]
455463
if self.direct_io {
456464
self.device.set_direct_io(self.direct_io)?;
457465
}

0 commit comments

Comments
 (0)