Skip to content

Commit 1dc15e0

Browse files
jiangliubergwolf
authored andcommitted
ptfs: rename FileOrHandle to InodeHandle
Rename FileOrHandle to InodeHandle. Signed-off-by: Jiang Liu <[email protected]>
1 parent f8bc31c commit 1dc15e0

File tree

3 files changed

+37
-45
lines changed

3 files changed

+37
-45
lines changed

src/passthrough/inode_store.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::collections::BTreeMap;
55
use std::sync::Arc;
66

77
use super::file_handle::FileHandle;
8-
use super::{FileOrHandle, Inode, InodeData, InodeStat};
8+
use super::{Inode, InodeData, InodeHandle, InodeStat};
99

1010
#[derive(Clone, Copy, Default, PartialOrd, Ord, PartialEq, Eq, Debug)]
1111
/// Identify an inode in `PassthroughFs` by `InodeId`.
@@ -41,7 +41,7 @@ impl InodeStore {
4141
/// will get lost.
4242
pub fn insert(&mut self, data: Arc<InodeData>) {
4343
self.by_id.insert(data.id, data.inode);
44-
if let FileOrHandle::Handle(handle) = &data.file_or_handle {
44+
if let InodeHandle::Handle(handle) = &data.handle {
4545
self.by_handle
4646
.insert(handle.file_handle().clone(), data.inode);
4747
}
@@ -59,7 +59,7 @@ impl InodeStore {
5959
}
6060

6161
if let Some(data) = data.as_ref() {
62-
if let FileOrHandle::Handle(handle) = &data.file_or_handle {
62+
if let InodeHandle::Handle(handle) = &data.handle {
6363
self.by_handle.remove(handle.file_handle());
6464
}
6565
self.by_id.remove(&data.id);
@@ -116,11 +116,9 @@ mod test {
116116
return false;
117117
}
118118

119-
match (&self.file_or_handle, &other.file_or_handle) {
120-
(FileOrHandle::File(f1), FileOrHandle::File(f2)) => {
121-
f1.as_raw_fd() == f2.as_raw_fd()
122-
}
123-
(FileOrHandle::Handle(h1), FileOrHandle::Handle(h2)) => {
119+
match (&self.handle, &other.handle) {
120+
(InodeHandle::File(f1), InodeHandle::File(f2)) => f1.as_raw_fd() == f2.as_raw_fd(),
121+
(InodeHandle::Handle(h1), InodeHandle::Handle(h2)) => {
124122
h1.file_handle() == h2.file_handle()
125123
}
126124
_ => false,
@@ -167,8 +165,8 @@ mod test {
167165
};
168166
let id1 = InodeId::from_stat(&inode_stat1);
169167
let id2 = InodeId::from_stat(&inode_stat2);
170-
let file_or_handle1 = FileOrHandle::File(tmpfile1.into_file());
171-
let file_or_handle2 = FileOrHandle::File(tmpfile2.into_file());
168+
let file_or_handle1 = InodeHandle::File(tmpfile1.into_file());
169+
let file_or_handle2 = InodeHandle::File(tmpfile2.into_file());
172170
let data1 = InodeData::new(
173171
inode1,
174172
file_or_handle1,

src/passthrough/mod.rs

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,16 @@ impl InodeStat {
138138
}
139139

140140
#[derive(Debug)]
141-
enum FileOrHandle {
141+
enum InodeHandle {
142142
File(File),
143143
Handle(Arc<OpenableFileHandle>),
144144
}
145145

146-
impl FileOrHandle {
146+
impl InodeHandle {
147147
fn handle(&self) -> Option<&FileHandle> {
148148
match self {
149-
FileOrHandle::File(_) => None,
150-
FileOrHandle::Handle(h) => Some(h.file_handle().deref()),
149+
InodeHandle::File(_) => None,
150+
InodeHandle::Handle(h) => Some(h.file_handle().deref()),
151151
}
152152
}
153153
}
@@ -181,7 +181,7 @@ impl AsRawFd for InodeFile<'_> {
181181
pub struct InodeData {
182182
inode: Inode,
183183
// Most of these aren't actually files but ¯\_(ツ)_/¯.
184-
file_or_handle: FileOrHandle,
184+
handle: InodeHandle,
185185
id: InodeId,
186186
refcount: AtomicU64,
187187
// File type and mode, not used for now
@@ -200,20 +200,20 @@ fn is_dir(mode: u32) -> bool {
200200
}
201201

202202
impl InodeData {
203-
fn new(inode: Inode, f: FileOrHandle, refcount: u64, id: InodeId, mode: u32) -> Self {
203+
fn new(inode: Inode, f: InodeHandle, refcount: u64, id: InodeId, mode: u32) -> Self {
204204
InodeData {
205205
inode,
206-
file_or_handle: f,
206+
handle: f,
207207
id,
208208
refcount: AtomicU64::new(refcount),
209209
mode,
210210
}
211211
}
212212

213213
fn get_file(&self) -> io::Result<InodeFile<'_>> {
214-
match &self.file_or_handle {
215-
FileOrHandle::File(f) => Ok(InodeFile::Ref(f)),
216-
FileOrHandle::Handle(h) => {
214+
match &self.handle {
215+
InodeHandle::File(f) => Ok(InodeFile::Ref(f)),
216+
InodeHandle::Handle(h) => {
217217
let f = h.open(libc::O_PATH)?;
218218
Ok(InodeFile::Owned(f))
219219
}
@@ -283,7 +283,7 @@ impl InodeMap {
283283
// inode ID.
284284
// (This can happen when we look up a new file that has reused the inode ID
285285
// of some previously unlinked inode we still have in `.inodes`.)
286-
handle.is_none() || data.file_or_handle.handle().is_none()
286+
handle.is_none() || data.handle.handle().is_none()
287287
})
288288
})
289289
.map(Arc::clone)
@@ -715,7 +715,7 @@ impl<S: BitmapSlice + Send + Sync> PassthroughFs<S> {
715715
pub fn import(&self) -> io::Result<()> {
716716
let root = CString::new(self.cfg.root_dir.as_str()).expect("CString::new failed");
717717

718-
let (file_or_handle, st, id) = Self::open_file_or_handle(
718+
let (handle, st, id) = Self::open_file_or_handle(
719719
self.cfg.inode_file_handles,
720720
self.cfg.enable_mntid,
721721
libc::AT_FDCWD,
@@ -740,7 +740,7 @@ impl<S: BitmapSlice + Send + Sync> PassthroughFs<S> {
740740
// Not sure why the root inode gets a refcount of 2 but that's what libfuse does.
741741
self.inode_map.insert(Arc::new(InodeData::new(
742742
fuse::ROOT_ID,
743-
file_or_handle,
743+
handle,
744744
2,
745745
id,
746746
st.get_stat().st_mode,
@@ -893,7 +893,7 @@ impl<S: BitmapSlice + Send + Sync> PassthroughFs<S> {
893893
name: &CStr,
894894
mount_fds: &MountFds,
895895
reopen_dir: F,
896-
) -> io::Result<(FileOrHandle, InodeStat, InodeId)>
896+
) -> io::Result<(InodeHandle, InodeStat, InodeId)>
897897
where
898898
F: FnOnce(RawFd, libc::c_int, u32) -> io::Result<File>,
899899
{
@@ -904,8 +904,8 @@ impl<S: BitmapSlice + Send + Sync> PassthroughFs<S> {
904904
};
905905

906906
// Ignore errors, because having a handle is optional
907-
let file_or_handle = if let Ok(h) = handle {
908-
FileOrHandle::Handle(Arc::new(h))
907+
let handle = if let Ok(h) = handle {
908+
InodeHandle::Handle(Arc::new(h))
909909
} else {
910910
let f = Self::open_file(
911911
dir_fd,
@@ -914,11 +914,11 @@ impl<S: BitmapSlice + Send + Sync> PassthroughFs<S> {
914914
0,
915915
)?;
916916

917-
FileOrHandle::File(f)
917+
InodeHandle::File(f)
918918
};
919919

920-
let inode_stat = match &file_or_handle {
921-
FileOrHandle::File(f) => {
920+
let inode_stat = match &handle {
921+
InodeHandle::File(f) => {
922922
// Count mount ID as part of alt key if use_mntid is true. Note that using
923923
// name_to_handle_at() to get mntid is kind of expensive in Lookup intensive
924924
// workloads, e.g. when cache is none and accessing lots of files.
@@ -940,15 +940,15 @@ impl<S: BitmapSlice + Send + Sync> PassthroughFs<S> {
940940
mnt_id,
941941
}
942942
}
943-
FileOrHandle::Handle(h) => InodeStat {
943+
InodeHandle::Handle(h) => InodeStat {
944944
stat: Self::stat_fd(dir_fd, Some(name))?,
945945
mnt_id: h.mount_id(),
946946
},
947947
};
948948

949949
let id = InodeId::from_stat(&inode_stat);
950950

951-
Ok((file_or_handle, inode_stat, id))
951+
Ok((handle, inode_stat, id))
952952
}
953953

954954
fn allocate_inode_locked(
@@ -988,7 +988,7 @@ impl<S: BitmapSlice + Send + Sync> PassthroughFs<S> {
988988

989989
let dir = self.inode_map.get(parent)?;
990990
let dir_file = dir.get_file()?;
991-
let (file_or_handle, st, id) = Self::open_file_or_handle(
991+
let (handle, st, id) = Self::open_file_or_handle(
992992
self.cfg.inode_file_handles,
993993
self.cfg.enable_mntid,
994994
dir_file.as_raw_fd(),
@@ -1000,7 +1000,7 @@ impl<S: BitmapSlice + Send + Sync> PassthroughFs<S> {
10001000
// Note that this will always be `None` if `cfg.inode_file_handles` is false, but we only
10011001
// really need this alt key when we do not have an `O_PATH` fd open for every inode. So if
10021002
// `cfg.inode_file_handles` is false, we do not need this key anyway.
1003-
let handle_opt = file_or_handle.handle();
1003+
let handle_opt = handle.handle();
10041004

10051005
// Whether to enable file DAX according to the value of dax_file_size
10061006
let mut attr_flags: u32 = 0;
@@ -1070,13 +1070,7 @@ impl<S: BitmapSlice + Send + Sync> PassthroughFs<S> {
10701070

10711071
InodeMap::insert_locked(
10721072
inodes.deref_mut(),
1073-
Arc::new(InodeData::new(
1074-
inode,
1075-
file_or_handle,
1076-
1,
1077-
id,
1078-
st.get_stat().st_mode,
1079-
)),
1073+
Arc::new(InodeData::new(inode, handle, 1, id, st.get_stat().st_mode)),
10801074
);
10811075
inode
10821076
}
@@ -1510,7 +1504,7 @@ mod tests {
15101504

15111505
// Following test depends on host fs, it's not reliable.
15121506
//let data = fs.inode_map.get(c_entry.inode).unwrap();
1513-
//assert_eq!(matches!(data.file_or_handle, FileOrHandle::Handle(_)), true);
1507+
//assert_eq!(matches!(data.handle, InodeHandle::Handle(_)), true);
15141508

15151509
let (_, duration) = fs.getattr(&ctx, c_entry.inode, None).unwrap();
15161510
assert_eq!(duration, fs.cfg.attr_timeout);
@@ -1857,7 +1851,7 @@ mod tests {
18571851
let file = TempFile::new().expect("Cannot create temporary file.");
18581852
let mode = file.as_file().metadata().unwrap().mode();
18591853
let inode_data =
1860-
InodeData::new(inode, FileOrHandle::File(file.into_file()), 1, id, mode);
1854+
InodeData::new(inode, InodeHandle::File(file.into_file()), 1, id, mode);
18611855
m.insert(Arc::new(inode_data));
18621856
let inode = fs.allocate_inode_locked(&m, &id, None).unwrap();
18631857
assert_eq!(inode & MAX_HOST_INO, 2);

src/passthrough/sync_io.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,12 @@ impl<S: BitmapSlice + Send + Sync> PassthroughFs<S> {
227227
fd = hd.get_handle_raw_fd();
228228
st = Self::stat_fd(fd, None);
229229
} else {
230-
match &data.file_or_handle {
231-
FileOrHandle::File(f) => {
230+
match &data.handle {
231+
InodeHandle::File(f) => {
232232
fd = f.as_raw_fd();
233233
st = Self::stat_fd(fd, None);
234234
}
235-
FileOrHandle::Handle(_h) => {
235+
InodeHandle::Handle(_h) => {
236236
let file = data.get_file()?;
237237
fd = file.as_raw_fd();
238238
st = Self::stat_fd(fd, None);

0 commit comments

Comments
 (0)