Skip to content

Commit 5234d61

Browse files
committed
rafs: cleanup raw os error with error macros
With error macros, debug mode can show more informations such as stack trace. Signed-off-by: Liu Bo <liub.liubo@gmail.com>
1 parent 33022a7 commit 5234d61

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

api/src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ define_libc_error_macro!(ealready, EALREADY);
6363
define_libc_error_macro!(enosys, ENOSYS);
6464
define_libc_error_macro!(epipe, EPIPE);
6565
define_libc_error_macro!(eio, EIO);
66+
define_libc_error_macro!(erange, ERANGE);
67+
define_libc_error_macro!(enodata, ENODATA);
6668

6769
/// Return EINVAL error with formatted error message.
6870
#[macro_export]

rafs/src/fs.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ impl FileSystem for Rafs {
735735
let mut recorder = FopRecorder::settle(Getxattr, inode, &self.ios);
736736

737737
if !self.xattr_supported() {
738-
return Err(std::io::Error::from_raw_os_error(libc::ENOSYS));
738+
return Err(enosys!());
739739
}
740740

741741
let name = OsStr::from_bytes(name.to_bytes());
@@ -744,15 +744,15 @@ impl FileSystem for Rafs {
744744
let r = match value {
745745
Some(value) => match size {
746746
0 => Ok(GetxattrReply::Count((value.len() + 1) as u32)),
747-
x if x < value.len() as u32 => Err(std::io::Error::from_raw_os_error(libc::ERANGE)),
747+
x if x < value.len() as u32 => Err(erange!()),
748748
_ => Ok(GetxattrReply::Value(value)),
749749
},
750750
None => {
751751
// TODO: Hopefully, we can have a 'decorator' procedure macro in
752752
// the future to wrap this method thus to handle different reasonable
753753
// errors in a clean way.
754754
recorder.mark_success(0);
755-
Err(std::io::Error::from_raw_os_error(libc::ENODATA))
755+
Err(enodata!())
756756
}
757757
};
758758

@@ -765,7 +765,7 @@ impl FileSystem for Rafs {
765765
fn listxattr(&self, _ctx: &Context, inode: u64, size: u32) -> Result<ListxattrReply> {
766766
let mut rec = FopRecorder::settle(Listxattr, inode, &self.ios);
767767
if !self.xattr_supported() {
768-
return Err(std::io::Error::from_raw_os_error(libc::ENOSYS));
768+
return Err(enosys!());
769769
}
770770

771771
let inode = self.sb.get_inode(inode, false)?;
@@ -783,7 +783,7 @@ impl FileSystem for Rafs {
783783

784784
match size {
785785
0 => Ok(ListxattrReply::Count(count as u32)),
786-
x if x < count as u32 => Err(std::io::Error::from_raw_os_error(libc::ERANGE)),
786+
x if x < count as u32 => Err(erange!()),
787787
_ => Ok(ListxattrReply::Names(buf)),
788788
}
789789
}

rafs/src/metadata/direct_v6.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ impl DirectSuperBlockV6 {
237237
let block_size = state.block_size();
238238
let unit_size = size_of::<RafsV5ChunkInfo>();
239239
if size % unit_size != 0 {
240-
return Err(std::io::Error::from_raw_os_error(libc::EINVAL));
240+
return Err(einval!());
241241
}
242242

243243
for idx in 0..(size / unit_size) {

0 commit comments

Comments
 (0)