diff mbox

[5/6] ubifs: Implement export_operations

Message ID 1495398051-4604-6-git-send-email-richard@nod.at (mailing list archive)
State New, archived
Headers show

Commit Message

Richard Weinberger May 21, 2017, 8:20 p.m. UTC
Signed-off-by: Richard Weinberger <richard@nod.at>
---
 fs/ubifs/super.c | 35 +++++++++++++++++++++++++++++++++++
 fs/ubifs/ubifs.h |  1 +
 2 files changed, 36 insertions(+)

Comments

Christoph Hellwig May 23, 2017, 8:39 a.m. UTC | #1
> +static struct inode *ubifs_nfs_get_inode(struct super_block *sb, uint64_t ino,
> +					 uint32_t generation)
> +{
> +	return ubifs_iget(sb, ino);
> +}

You need to maintain and check an inode generation counter for this
to be safe.
Richard Weinberger May 23, 2017, 8:41 a.m. UTC | #2
Christoph,

Am 23.05.2017 um 10:39 schrieb Christoph Hellwig:
>> +static struct inode *ubifs_nfs_get_inode(struct super_block *sb, uint64_t ino,
>> +					 uint32_t generation)
>> +{
>> +	return ubifs_iget(sb, ino);
>> +}
> 
> You need to maintain and check an inode generation counter for this
> to be safe.

UBIFS has no inode generations, inodes simply can't wrap around.
We "handle" it like JFF2 does, we assumes that the NAND is long dead
before we reach the maximum inode number.

Thanks,
//richard
Christoph Hellwig May 23, 2017, 8:48 a.m. UTC | #3
On Tue, May 23, 2017 at 10:41:16AM +0200, Richard Weinberger wrote:
> UBIFS has no inode generations, inodes simply can't wrap around.
> We "handle" it like JFF2 does, we assumes that the NAND is long dead
> before we reach the maximum inode number.

So you never ever reuse an inode number once it's been unlinked and
the last opener went away?

If that is the case please add a comment explaining this next to
the get_inode helper.
Richard Weinberger May 23, 2017, 8:50 a.m. UTC | #4
Christoph,

Am 23.05.2017 um 10:48 schrieb Christoph Hellwig:
> On Tue, May 23, 2017 at 10:41:16AM +0200, Richard Weinberger wrote:
>> UBIFS has no inode generations, inodes simply can't wrap around.
>> We "handle" it like JFF2 does, we assumes that the NAND is long dead
>> before we reach the maximum inode number.
> 
> So you never ever reuse an inode number once it's been unlinked and
> the last opener went away?

Correct.

> If that is the case please add a comment explaining this next to
> the get_inode helper.

Will do.

Thanks,
//richard
diff mbox

Patch

diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c
index 7560071534bf..4788420162b8 100644
--- a/fs/ubifs/super.c
+++ b/fs/ubifs/super.c
@@ -2005,6 +2005,41 @@  const struct fscrypt_operations ubifs_crypt_operations = {
 };
 #endif
 
+static struct dentry *ubifs_get_parent(struct dentry *child)
+{
+	struct ubifs_inode *ui = ubifs_inode(d_inode(child));
+
+	return d_obtain_alias(ubifs_iget(child->d_sb, ui->parent_inum));
+}
+
+static struct inode *ubifs_nfs_get_inode(struct super_block *sb, uint64_t ino,
+					 uint32_t generation)
+{
+	return ubifs_iget(sb, ino);
+}
+
+static struct dentry *ubifs_fh_to_dentry(struct super_block *sb,
+					 struct fid *fid, int fh_len,
+					 int fh_type)
+{
+	return generic_fh_to_dentry(sb, fid, fh_len, fh_type,
+				    ubifs_nfs_get_inode);
+}
+
+static struct dentry *ubifs_fh_to_parent(struct super_block *sb,
+					 struct fid *fid, int fh_len,
+					 int fh_type)
+{
+	return generic_fh_to_parent(sb, fid, fh_len, fh_type,
+				    ubifs_nfs_get_inode);
+}
+
+static const struct export_operations ubifs_export_ops = {
+	.get_parent = ubifs_get_parent,
+	.fh_to_dentry = ubifs_fh_to_dentry,
+	.fh_to_parent = ubifs_fh_to_parent,
+};
+
 static int ubifs_fill_super(struct super_block *sb, void *data, int silent)
 {
 	struct ubifs_info *c = sb->s_fs_info;
diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h
index 3c64481f4032..a728d6e3eb47 100644
--- a/fs/ubifs/ubifs.h
+++ b/fs/ubifs/ubifs.h
@@ -45,6 +45,7 @@ 
 #endif
 #include <linux/random.h>
 #include <linux/compat.h>
+#include <linux/exportfs.h>
 #include "ubifs-media.h"
 
 /* Version of this UBIFS implementation */