Skip to content

Commit 2e522ba

Browse files
bergwolferyugey
authored andcommitted
api/vfs: ensure entry attr st_ino consistency
Whenever we convert an entry, make sure the returned attribute st_ino field is updated as well. Otherwise entry.inode and entry.attr.st_ino are not consistent and it might confuse the kernel. Signed-off-by: Peng Tao <[email protected]>
1 parent 89c5fa7 commit 2e522ba

File tree

3 files changed

+26
-33
lines changed

3 files changed

+26
-33
lines changed

src/api/vfs/async_io.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ impl AsyncFileSystem for Vfs {
2626
// parent is in an underlying rootfs
2727
let mut entry = fs.async_lookup(ctx, idata.ino(), name).await?;
2828
// lookup success, hash it to a real fuse inode
29-
entry.inode = self.convert_inode(idata.fs_idx(), entry.inode)?;
30-
Ok(entry)
29+
self.convert_entry(idata.fs_idx(), entry.inode, &mut entry)
3130
}
3231
}
3332
}
@@ -96,7 +95,7 @@ impl AsyncFileSystem for Vfs {
9695
fs.async_create(ctx, idata.ino(), name, args)
9796
.await
9897
.map(|(mut a, b, c)| {
99-
a.inode = self.convert_inode(idata.fs_idx(), a.inode)?;
98+
self.convert_entry(idata.fs_idx(), a.inode, &mut a)?;
10099
Ok((a, b, c))
101100
})?
102101
}

src/api/vfs/mod.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ impl Vfs {
322322
let inode = self.root.mount(path)?;
323323
let real_root_ino = entry.inode;
324324

325-
entry.inode = self.convert_inode(fs_idx, entry.inode)?;
325+
self.convert_entry(fs_idx, entry.inode, &mut entry)?;
326326

327327
// Over mount would invalidate previous superblock inodes.
328328
if let Some(mnt) = mountpoints.get(&inode) {
@@ -454,6 +454,14 @@ impl Vfs {
454454
Ok(ino)
455455
}
456456

457+
fn convert_entry(&self, fs_idx: VfsIndex, inode: u64, entry: &mut Entry) -> Result<Entry> {
458+
self.convert_inode(fs_idx, inode).map(|ino| {
459+
entry.inode = ino;
460+
entry.attr.st_ino = ino;
461+
*entry
462+
})
463+
}
464+
457465
fn allocate_fs_idx(&self) -> Result<VfsIndex> {
458466
let superblocks = self.superblocks.load().deref().deref().clone();
459467
let start = self.next_super.load(Ordering::SeqCst);
@@ -528,20 +536,18 @@ impl Vfs {
528536
Some(mnt) => {
529537
// cross mountpoint, return mount root entry
530538
entry = mnt.root_entry;
531-
entry.inode = self.convert_inode(mnt.fs_idx, mnt.ino)?;
532-
entry.attr.st_ino = entry.inode;
539+
self.convert_entry(mnt.fs_idx, mnt.ino, &mut entry)?;
533540
trace!(
534541
"vfs lookup cross mountpoint, return new mount fs_idx {} inode 0x{:x} fuse inode 0x{:x}, attr inode 0x{:x}",
535542
mnt.fs_idx,
536543
mnt.ino,
537544
entry.inode,
538545
entry.attr.st_ino,
539546
);
547+
Ok(entry)
540548
}
541-
None => entry.inode = self.convert_inode(idata.fs_idx(), entry.inode)?,
549+
None => self.convert_entry(idata.fs_idx(), entry.inode, &mut entry),
542550
}
543-
544-
Ok(entry)
545551
}
546552
}
547553

src/api/vfs/sync_io.rs

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,7 @@ impl FileSystem for Vfs {
7979
// parent is in an underlying rootfs
8080
let mut entry = fs.lookup(ctx, idata.ino(), name)?;
8181
// lookup success, hash it to a real fuse inode
82-
let new_ino = self.convert_inode(idata.fs_idx(), entry.inode)?;
83-
entry.inode = new_ino;
84-
entry.attr.st_ino = new_ino;
85-
Ok(entry)
82+
self.convert_entry(idata.fs_idx(), entry.inode, &mut entry)
8683
}
8784
}
8885
}
@@ -155,10 +152,9 @@ impl FileSystem for Vfs {
155152

156153
match self.get_real_rootfs(parent)? {
157154
(Left(fs), idata) => fs.symlink(ctx, linkname, idata.ino(), name),
158-
(Right(fs), idata) => fs.symlink(ctx, linkname, idata.ino(), name).map(|mut e| {
159-
e.inode = self.convert_inode(idata.fs_idx(), e.inode)?;
160-
Ok(e)
161-
})?,
155+
(Right(fs), idata) => fs
156+
.symlink(ctx, linkname, idata.ino(), name)
157+
.map(|mut e| self.convert_entry(idata.fs_idx(), e.inode, &mut e))?,
162158
}
163159
}
164160

@@ -175,13 +171,9 @@ impl FileSystem for Vfs {
175171

176172
match self.get_real_rootfs(inode)? {
177173
(Left(fs), idata) => fs.mknod(ctx, idata.ino(), name, mode, rdev, umask),
178-
(Right(fs), idata) => {
179-
fs.mknod(ctx, idata.ino(), name, mode, rdev, umask)
180-
.map(|mut e| {
181-
e.inode = self.convert_inode(idata.fs_idx(), e.inode)?;
182-
Ok(e)
183-
})?
184-
}
174+
(Right(fs), idata) => fs
175+
.mknod(ctx, idata.ino(), name, mode, rdev, umask)
176+
.map(|mut e| self.convert_entry(idata.fs_idx(), e.inode, &mut e))?,
185177
}
186178
}
187179

@@ -197,10 +189,9 @@ impl FileSystem for Vfs {
197189

198190
match self.get_real_rootfs(parent)? {
199191
(Left(fs), idata) => fs.mkdir(ctx, idata.ino(), name, mode, umask),
200-
(Right(fs), idata) => fs.mkdir(ctx, idata.ino(), name, mode, umask).map(|mut e| {
201-
e.inode = self.convert_inode(idata.fs_idx(), e.inode)?;
202-
Ok(e)
203-
})?,
192+
(Right(fs), idata) => fs
193+
.mkdir(ctx, idata.ino(), name, mode, umask)
194+
.map(|mut e| self.convert_entry(idata.fs_idx(), e.inode, &mut e))?,
204195
}
205196
}
206197

@@ -281,10 +272,7 @@ impl FileSystem for Vfs {
281272
Left(fs) => fs.link(ctx, idata_old.ino(), idata_new.ino(), newname),
282273
Right(fs) => fs
283274
.link(ctx, idata_old.ino(), idata_new.ino(), newname)
284-
.map(|mut e| {
285-
e.inode = self.convert_inode(idata_new.fs_idx(), e.inode)?;
286-
Ok(e)
287-
})?,
275+
.map(|mut e| self.convert_entry(idata_new.fs_idx(), e.inode, &mut e))?,
288276
}
289277
}
290278

@@ -321,7 +309,7 @@ impl FileSystem for Vfs {
321309
(Right(fs), idata) => {
322310
fs.create(ctx, idata.ino(), name, args)
323311
.map(|(mut a, b, c)| {
324-
a.inode = self.convert_inode(idata.fs_idx(), a.inode)?;
312+
self.convert_entry(idata.fs_idx(), a.inode, &mut a)?;
325313
Ok((a, b, c))
326314
})?
327315
}

0 commit comments

Comments
 (0)