[libos] Add status_flags support for stdio
This commit is contained in:
		
							parent
							
								
									cd5d9e6d57
								
							
						
					
					
						commit
						626ea3dc7c
					
				| @ -83,12 +83,7 @@ impl File for EventFile { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn set_status_flags(&self, new_status_flags: StatusFlags) -> Result<()> { |     fn set_status_flags(&self, new_status_flags: StatusFlags) -> Result<()> { | ||||||
|         let valid_flags_mask = StatusFlags::O_APPEND |         let raw_status_flags = (new_status_flags & STATUS_FLAGS_MASK).bits(); | ||||||
|             | StatusFlags::O_ASYNC |  | ||||||
|             | StatusFlags::O_DIRECT |  | ||||||
|             | StatusFlags::O_NOATIME |  | ||||||
|             | StatusFlags::O_NONBLOCK; |  | ||||||
|         let raw_status_flags = (new_status_flags & valid_flags_mask).bits(); |  | ||||||
|         try_libc!(libc::ocall::fcntl_arg1( |         try_libc!(libc::ocall::fcntl_arg1( | ||||||
|             self.host_fd(), |             self.host_fd(), | ||||||
|             libc::F_SETFL, |             libc::F_SETFL, | ||||||
|  | |||||||
| @ -111,6 +111,15 @@ bitflags! { | |||||||
|         const O_PATH = 1 << 21; |         const O_PATH = 1 << 21; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | // On Linux, F_SETFL can change only the O_APPEND,
 | ||||||
|  | // O_ASYNC, O_DIRECT, O_NOATIME, and O_NONBLOCK flags
 | ||||||
|  | pub const STATUS_FLAGS_MASK: StatusFlags = StatusFlags::from_bits_truncate( | ||||||
|  |     StatusFlags::O_APPEND.bits() | ||||||
|  |         | StatusFlags::O_ASYNC.bits() | ||||||
|  |         | StatusFlags::O_DIRECT.bits() | ||||||
|  |         | StatusFlags::O_NOATIME.bits() | ||||||
|  |         | StatusFlags::O_NONBLOCK.bits(), | ||||||
|  | ); | ||||||
| 
 | 
 | ||||||
| impl StatusFlags { | impl StatusFlags { | ||||||
|     pub fn always_append(&self) -> bool { |     pub fn always_append(&self) -> bool { | ||||||
|  | |||||||
| @ -8,7 +8,7 @@ pub use self::close::do_close; | |||||||
| pub use self::dup::{do_dup, do_dup2, do_dup3}; | pub use self::dup::{do_dup, do_dup2, do_dup3}; | ||||||
| pub use self::fallocate::{do_fallocate, FallocateFlags}; | pub use self::fallocate::{do_fallocate, FallocateFlags}; | ||||||
| pub use self::fcntl::{do_fcntl, FcntlCmd}; | pub use self::fcntl::{do_fcntl, FcntlCmd}; | ||||||
| pub use self::file_flags::{AccessMode, CreationFlags, StatusFlags}; | pub use self::file_flags::{AccessMode, CreationFlags, StatusFlags, STATUS_FLAGS_MASK}; | ||||||
| pub use self::flock::do_flock; | pub use self::flock::do_flock; | ||||||
| pub use self::fspath::{get_abs_path_by_fd, FsPath, AT_FDCWD}; | pub use self::fspath::{get_abs_path_by_fd, FsPath, AT_FDCWD}; | ||||||
| pub use self::fsync::{do_fdatasync, do_fsync}; | pub use self::fsync::{do_fdatasync, do_fsync}; | ||||||
|  | |||||||
| @ -176,14 +176,8 @@ impl File for INodeFile { | |||||||
| 
 | 
 | ||||||
|     fn set_status_flags(&self, new_status_flags: StatusFlags) -> Result<()> { |     fn set_status_flags(&self, new_status_flags: StatusFlags) -> Result<()> { | ||||||
|         let mut status_flags = self.status_flags.write().unwrap(); |         let mut status_flags = self.status_flags.write().unwrap(); | ||||||
|         // Currently, F_SETFL can change only the O_APPEND,
 |         status_flags.remove(STATUS_FLAGS_MASK); | ||||||
|         // O_ASYNC, O_NOATIME, and O_NONBLOCK flags
 |         status_flags.insert(new_status_flags & STATUS_FLAGS_MASK); | ||||||
|         let valid_flags_mask = StatusFlags::O_APPEND |  | ||||||
|             | StatusFlags::O_ASYNC |  | ||||||
|             | StatusFlags::O_NOATIME |  | ||||||
|             | StatusFlags::O_NONBLOCK; |  | ||||||
|         status_flags.remove(valid_flags_mask); |  | ||||||
|         status_flags.insert(new_status_flags & valid_flags_mask); |  | ||||||
|         Ok(()) |         Ok(()) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -21,6 +21,7 @@ pub use self::file::{File, FileRef}; | |||||||
| pub use self::file_ops::{ | pub use self::file_ops::{ | ||||||
|     occlum_ocall_ioctl, utimbuf_t, AccessMode, BuiltinIoctlNum, CreationFlags, FallocateFlags, |     occlum_ocall_ioctl, utimbuf_t, AccessMode, BuiltinIoctlNum, CreationFlags, FallocateFlags, | ||||||
|     FileMode, IfConf, IoctlCmd, Stat, StatusFlags, StructuredIoctlArgType, StructuredIoctlNum, |     FileMode, IfConf, IoctlCmd, Stat, StatusFlags, StructuredIoctlArgType, StructuredIoctlNum, | ||||||
|  |     STATUS_FLAGS_MASK, | ||||||
| }; | }; | ||||||
| pub use self::file_table::{FileDesc, FileTable, FileTableEvent, FileTableNotifier}; | pub use self::file_table::{FileDesc, FileTable, FileTableEvent, FileTableNotifier}; | ||||||
| pub use self::fs_ops::Statfs; | pub use self::fs_ops::Statfs; | ||||||
|  | |||||||
| @ -213,6 +213,24 @@ impl File for StdoutFile { | |||||||
|         Ok(ret) |         Ok(ret) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     fn status_flags(&self) -> Result<StatusFlags> { | ||||||
|  |         let ret = try_libc!(libc::ocall::fcntl_arg0( | ||||||
|  |             self.host_fd() as i32, | ||||||
|  |             libc::F_GETFL | ||||||
|  |         )); | ||||||
|  |         Ok(StatusFlags::from_bits_truncate(ret as u32)) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     fn set_status_flags(&self, new_status_flags: StatusFlags) -> Result<()> { | ||||||
|  |         let raw_status_flags = (new_status_flags & STATUS_FLAGS_MASK).bits(); | ||||||
|  |         try_libc!(libc::ocall::fcntl_arg1( | ||||||
|  |             self.host_fd() as i32, | ||||||
|  |             libc::F_SETFL, | ||||||
|  |             raw_status_flags as c_int | ||||||
|  |         )); | ||||||
|  |         Ok(()) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     fn as_any(&self) -> &dyn Any { |     fn as_any(&self) -> &dyn Any { | ||||||
|         self |         self | ||||||
|     } |     } | ||||||
| @ -375,6 +393,24 @@ impl File for StdinFile { | |||||||
|         Ok(ret) |         Ok(ret) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     fn status_flags(&self) -> Result<StatusFlags> { | ||||||
|  |         let ret = try_libc!(libc::ocall::fcntl_arg0( | ||||||
|  |             self.host_fd() as i32, | ||||||
|  |             libc::F_GETFL | ||||||
|  |         )); | ||||||
|  |         Ok(StatusFlags::from_bits_truncate(ret as u32)) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     fn set_status_flags(&self, new_status_flags: StatusFlags) -> Result<()> { | ||||||
|  |         let raw_status_flags = (new_status_flags & STATUS_FLAGS_MASK).bits(); | ||||||
|  |         try_libc!(libc::ocall::fcntl_arg1( | ||||||
|  |             self.host_fd() as i32, | ||||||
|  |             libc::F_SETFL, | ||||||
|  |             raw_status_flags as c_int | ||||||
|  |         )); | ||||||
|  |         Ok(()) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     fn as_any(&self) -> &dyn Any { |     fn as_any(&self) -> &dyn Any { | ||||||
|         self |         self | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -130,12 +130,7 @@ impl File for TimerFile { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn set_status_flags(&self, new_status_flags: StatusFlags) -> Result<()> { |     fn set_status_flags(&self, new_status_flags: StatusFlags) -> Result<()> { | ||||||
|         let valid_flags_mask = StatusFlags::O_APPEND |         let raw_status_flags = (new_status_flags & STATUS_FLAGS_MASK).bits(); | ||||||
|             | StatusFlags::O_ASYNC |  | ||||||
|             | StatusFlags::O_DIRECT |  | ||||||
|             | StatusFlags::O_NOATIME |  | ||||||
|             | StatusFlags::O_NONBLOCK; |  | ||||||
|         let raw_status_flags = (new_status_flags & valid_flags_mask).bits(); |  | ||||||
|         try_libc!(libc::ocall::fcntl_arg1( |         try_libc!(libc::ocall::fcntl_arg1( | ||||||
|             self.host_fd(), |             self.host_fd(), | ||||||
|             libc::F_SETFL, |             libc::F_SETFL, | ||||||
|  | |||||||
| @ -6,7 +6,7 @@ use atomic::{Atomic, Ordering}; | |||||||
| use super::*; | use super::*; | ||||||
| use crate::fs::{ | use crate::fs::{ | ||||||
|     occlum_ocall_ioctl, AccessMode, AtomicIoEvents, CreationFlags, File, FileRef, HostFd, IoEvents, |     occlum_ocall_ioctl, AccessMode, AtomicIoEvents, CreationFlags, File, FileRef, HostFd, IoEvents, | ||||||
|     IoctlCmd, StatusFlags, |     IoctlCmd, StatusFlags, STATUS_FLAGS_MASK, | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| //TODO: refactor write syscall to allow zero length with non-zero buffer
 | //TODO: refactor write syscall to allow zero length with non-zero buffer
 | ||||||
| @ -63,12 +63,7 @@ impl File for HostSocket { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn set_status_flags(&self, new_status_flags: StatusFlags) -> Result<()> { |     fn set_status_flags(&self, new_status_flags: StatusFlags) -> Result<()> { | ||||||
|         let valid_flags_mask = StatusFlags::O_APPEND |         let raw_status_flags = (new_status_flags & STATUS_FLAGS_MASK).bits(); | ||||||
|             | StatusFlags::O_ASYNC |  | ||||||
|             | StatusFlags::O_DIRECT |  | ||||||
|             | StatusFlags::O_NOATIME |  | ||||||
|             | StatusFlags::O_NONBLOCK; |  | ||||||
|         let raw_status_flags = (new_status_flags & valid_flags_mask).bits(); |  | ||||||
|         try_libc!(libc::ocall::fcntl_arg1( |         try_libc!(libc::ocall::fcntl_arg1( | ||||||
|             self.raw_host_fd() as i32, |             self.raw_host_fd() as i32, | ||||||
|             libc::F_SETFL, |             libc::F_SETFL, | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user