Skip to contentSkip to conversation

fat: restructure export_operations

PATCH Superseded Namjae Jeon 2 participants 7 messages Feb 9, 2013 – Feb 18, 2013

Subsystems (3)

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v6 4/7 fat: restructure export_operations

From: Namjae Jeon <[email protected]>

Define two nfs export_operation structures,one for 'stale_rw' mounts and the other for 'nostale_ro'.The latter uses i_pos as a basis for encoding and decoding file handles.

Also, assign i_pos to kstat->ino.The logic for rebuilding the inode is added in the subsequent patches.

---
 fs/fat/fat.h             |    8 +--
 fs/fat/file.c            |    9 ++++
 fs/fat/inode.c           |   11 ++--
 fs/fat/nfs.c             |  126 ++++++++++++++++++++++++++++++++++++++++++++--
 include/linux/exportfs.h |   11 ++++
 5 files changed, 146 insertions(+), 19 deletions(-)
fs/fat/fat.h +2 -6
index 980c034..c517fc0 100644
@@ -406,12 +406,8 @@ int fat_cache_init(void);
 void fat_cache_destroy(void);
 
 /* fat/nfs.c */
-struct fid;
-extern struct dentry *fat_fh_to_dentry(struct super_block *sb, struct fid *fid,
-				       int fh_len, int fh_type);
-extern struct dentry *fat_fh_to_parent(struct super_block *sb, struct fid *fid,
-				       int fh_len, int fh_type);
-extern struct dentry *fat_get_parent(struct dentry *child_dir);
+extern const struct export_operations fat_export_ops;
+extern const struct export_operations fat_export_ops_nostale;
 
 /* helper for printk */
 typedef unsigned long long	llu;
fs/fat/file.c +9 -0
index a62e0ec..de74655 100644
@@ -306,6 +306,15 @@ int fat_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
 	struct inode *inode = dentry->d_inode;
 	generic_fillattr(inode, stat);
 	stat->blksize = MSDOS_SB(inode->i_sb)->cluster_size;
+
+	if (MSDOS_SB(inode->i_sb)->options.nfs == FAT_NFS_NOSTALE_RO) {
+		if (inode->i_ino == MSDOS_ROOT_INO)
+			stat->ino = MSDOS_ROOT_INO;
+		else
+			/* Use i_pos for ino. This is used as fileid of nfs. */
+			stat->ino = fat_i_pos_read(MSDOS_SB(inode->i_sb),
+						   inode);
+	}
 	return 0;
 }
 EXPORT_SYMBOL_GPL(fat_getattr);
fs/fat/inode.c +3 -8
index 8356a05..951e675 100644
@@ -18,7 +18,6 @@
 #include <linux/pagemap.h>
 #include <linux/mpage.h>
 #include <linux/buffer_head.h>
-#include <linux/exportfs.h>
 #include <linux/mount.h>
 #include <linux/aio.h>
 #include <linux/vfs.h>
@@ -749,12 +748,6 @@ static const struct super_operations fat_sops = {
 	.show_options	= fat_show_options,
 };
 
-static const struct export_operations fat_export_ops = {
-	.fh_to_dentry	= fat_fh_to_dentry,
-	.fh_to_parent	= fat_fh_to_parent,
-	.get_parent	= fat_get_parent,
-};
-
 static int fat_show_options(struct seq_file *m, struct dentry *root)
 {
 	struct msdos_sb_info *sbi = MSDOS_SB(root->d_sb);
@@ -1178,8 +1171,10 @@ out:
 		opts->allow_utime = ~opts->fs_dmask & (S_IWGRP | S_IWOTH);
 	if (opts->unicode_xlate)
 		opts->utf8 = 0;
-	if (opts->nfs == FAT_NFS_NOSTALE_RO)
+	if (opts->nfs == FAT_NFS_NOSTALE_RO) {
 		sb->s_flags |= MS_RDONLY;
+		sb->s_export_op = &fat_export_ops_nostale;
+	}
 
 	return 0;
 }
fs/fat/nfs.c +121 -5

173 lines not on this page · raw message

include/linux/exportfs.h +11 -0
index 5b9b5b3..41b223a 100644
@@ -85,6 +85,17 @@ enum fid_type {
 	FILEID_NILFS_WITH_PARENT = 0x62,
 
 	/*
+	 * 32 bit generation number, 40 bit i_pos.
+	 */
+	FILEID_FAT_WITHOUT_PARENT = 0x71,
+
+	/*
+	 * 32 bit generation number, 40 bit i_pos,
+	 * 32 bit parent generation number, 40 bit parent i_pos
+	 */
+	FILEID_FAT_WITH_PARENT = 0x72,
+
+	/*
 	 * Filesystems must not use 0xff file ID.
 	 */
 	FILEID_INVALID = 0xff,
Signature · 1 line
1.7.9.5
maintainer
#1 lore raw

fs/fat/file.c int fat_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) · line 312

Quoted 3 lines · Namjae Jeon
fs/fat/file.c +3 -0
+	if (MSDOS_SB(inode->i_sb)->options.nfs == FAT_NFS_NOSTALE_RO) {
+		if (inode->i_ino == MSDOS_ROOT_INO)
+			stat->ino = MSDOS_ROOT_INO;

Can we simply set i_pos = MSDOS_ROOT_INO in fat_read_root()? If so, I think we can avoid this check.

Quoted 8 lines
(quoted diff) +5 -0
+		else
+			/* Use i_pos for ino. This is used as fileid of nfs. */
+			stat->ino = fat_i_pos_read(MSDOS_SB(inode->i_sb),
+						   inode);
+	}
 	return 0;
 }
 EXPORT_SYMBOL_GPL(fat_getattr);

Review

Quoted 10 lines
(quoted diff) +8 -0
 
 
+struct fat_fid {
+	u32 i_gen;
+	u32 i_pos_low;
+	u16 i_pos_hi;
+	u16 parent_i_pos_hi;
+	u32 parent_i_pos_low;
+	u32 parent_i_gen;
+} __packed;

Do we need to use __packed? Unnecessary __packed can generate slower code for alignment check on arch has unaligned fault.

fs/fat/nfs.c static struct inode *fat_nfs_get_inode(struct super_block *sb, · line 93

Quoted 7 lines
fs/fat/nfs.c +7 -0
+	if (parent && (len < FAT_FID_SIZE_WITH_PARENT)) {
+		*lenp = FAT_FID_SIZE_WITH_PARENT;
+		return 255;
+	} else if (len < FAT_FID_SIZE_WITHOUT_PARENT) {
+		*lenp = FAT_FID_SIZE_WITHOUT_PARENT;
+		return 255;
+	}

This check strange. "parent && len == FAT_FID_SIZE_WITHOUT_PARENT" will overwrite over limit of fh size?

Signature · 1 line
OGAWA Hirofumi <[email protected]>
maintainer
#2 lore raw
Quoted 6 lines · OGAWA Hirofumi

fs/fat/nfs.c static struct inode *fat_nfs_get_inode(struct super_block *sb, · line 92

Quoted 6 lines
fs/fat/nfs.c +6 -0
+	if (parent && (len < FAT_FID_SIZE_WITH_PARENT)) {
+		*lenp = FAT_FID_SIZE_WITH_PARENT;
+		return 255;
+	} else if (len < FAT_FID_SIZE_WITHOUT_PARENT) {
+		*lenp = FAT_FID_SIZE_WITHOUT_PARENT;
+		return 255;

We would be better to use FILEID_INVALID on all places, instead of 255.

Signature · 1 line
OGAWA Hirofumi <[email protected]>
#3 lore raw

2013/2/18 OGAWA Hirofumi <[email protected]>:

Quoted 10 lines
Quoted 6 lines · OGAWA Hirofumi

fs/fat/nfs.c static struct inode *fat_nfs_get_inode(struct super_block *sb, · line 92

Quoted 6 lines
fs/fat/nfs.c +6 -0
+    if (parent && (len < FAT_FID_SIZE_WITH_PARENT)) {
+            *lenp = FAT_FID_SIZE_WITH_PARENT;
+            return 255;
+    } else if (len < FAT_FID_SIZE_WITHOUT_PARENT) {
+            *lenp = FAT_FID_SIZE_WITHOUT_PARENT;
+            return 255;

We would be better to use FILEID_INVALID on all places, instead of 255.

Yes, right. I will fix it.
Thanks!

Quoted 2 lines

--
OGAWA Hirofumi <[email protected]>

#4 lore raw
In reply to OGAWA Hirofumi

2013/2/18 OGAWA Hirofumi <[email protected]>:

Quoted 8 lines

fs/fat/file.c int fat_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) · line 312

Quoted 3 lines · Namjae Jeon
fs/fat/file.c +3 -0
+     if (MSDOS_SB(inode->i_sb)->options.nfs == FAT_NFS_NOSTALE_RO) {
+             if (inode->i_ino == MSDOS_ROOT_INO)
+                     stat->ino = MSDOS_ROOT_INO;

Can we simply set i_pos = MSDOS_ROOT_INO in fat_read_root()? If so, I think we can avoid this check.

Yes, we can. I will change it.

Quoted 11 lines
Quoted 9 lines
fs/fat/file.c +5 -0
+             else
+                     /* Use i_pos for ino. This is used as fileid of nfs. */
+                     stat->ino = fat_i_pos_read(MSDOS_SB(inode->i_sb),
+                                                inode);
+     }
      return 0;
 }
 EXPORT_SYMBOL_GPL(fat_getattr);
Quoted 11 lines

fs/fat/nfs.c line 24

Quoted 8 lines
fs/fat/nfs.c +8 -0
+struct fat_fid {
+     u32 i_gen;
+     u32 i_pos_low;
+     u16 i_pos_hi;
+     u16 parent_i_pos_hi;
+     u32 parent_i_pos_low;
+     u32 parent_i_gen;
+} __packed;

Do we need to use __packed? Unnecessary __packed can generate slower code for alignment check on arch has unaligned fault.

Actually, I referenced other filesystem's exportfs code like btrfs and xfs. they are packing their fids.
your opinion is reasonable, so I can fix it as your opinion.

Quoted 11 lines

fs/fat/nfs.c static struct inode *fat_nfs_get_inode(struct super_block *sb, · line 93

Quoted 8 lines
fs/fat/nfs.c +7 -0
+     if (parent && (len < FAT_FID_SIZE_WITH_PARENT)) {
+             *lenp = FAT_FID_SIZE_WITH_PARENT;
+             return 255;
+     } else if (len < FAT_FID_SIZE_WITHOUT_PARENT) {
+             *lenp = FAT_FID_SIZE_WITHOUT_PARENT;
+             return 255;
+     }

This check strange. "parent && len == FAT_FID_SIZE_WITHOUT_PARENT" will overwrite over limit of fh size?

I need to check more. because I followed the logic in export_encode_fh() function.

Thanks for review!

Quoted 2 lines

--
OGAWA Hirofumi <[email protected]>

maintainer
#5 lore raw
Quoted 8 lines · Namjae Jeon
Quoted 8 lines
Quoted 7 lines
fs/fat/nfs.c +7 -0
+     if (parent && (len < FAT_FID_SIZE_WITH_PARENT)) {
+             *lenp = FAT_FID_SIZE_WITH_PARENT;
+             return 255;
+     } else if (len < FAT_FID_SIZE_WITHOUT_PARENT) {
+             *lenp = FAT_FID_SIZE_WITHOUT_PARENT;
+             return 255;
+     }
Quoted 4 lines
Quoted 2 lines

This check strange. "parent && len == FAT_FID_SIZE_WITHOUT_PARENT" will overwrite over limit of fh size?

I need to check more. because I followed the logic in export_encode_fh() function.

Ah, my fault, it doesn't have real problem. But code is quite strange.

If input is "parent && len >= FAT_FID_SIZE_WITHOUT_PARENT", "else if (len < FAT_FID_SIZE_WITHOUT_PARENT)" check is entirely useless, but this code itself checks "len".

if (parent) {
	if (len < FAT_FID_SIZE_WITH_PARENT)
		/* error */
} else {
	if (len < FAT_FID_SIZE_WITHOUT_PARENT)
		/* error */
}

I think this would readable, and I guess this will generates faster/simpler code (at least, this doesn't depends an optimization of gcc).

Thanks.

Signature · 1 line
OGAWA Hirofumi <[email protected]>
#6 lore raw

2013/2/18 OGAWA Hirofumi <[email protected]>:

Quoted 29 lines
Quoted 8 lines · Namjae Jeon
Quoted 8 lines
Quoted 7 lines
fs/fat/nfs.c +7 -0
+     if (parent && (len < FAT_FID_SIZE_WITH_PARENT)) {
+             *lenp = FAT_FID_SIZE_WITH_PARENT;
+             return 255;
+     } else if (len < FAT_FID_SIZE_WITHOUT_PARENT) {
+             *lenp = FAT_FID_SIZE_WITHOUT_PARENT;
+             return 255;
+     }
Quoted 4 lines
Quoted 2 lines

This check strange. "parent && len == FAT_FID_SIZE_WITHOUT_PARENT" will overwrite over limit of fh size?

I need to check more. because I followed the logic in export_encode_fh() function.

Ah, my fault, it doesn't have real problem. But code is quite strange.

If input is "parent && len >= FAT_FID_SIZE_WITHOUT_PARENT", "else if (len < FAT_FID_SIZE_WITHOUT_PARENT)" check is entirely useless, but this code itself checks "len".

if (parent) {
if (len < FAT_FID_SIZE_WITH_PARENT)
/* error */
} else {
if (len < FAT_FID_SIZE_WITHOUT_PARENT)
/* error */
}

Quoted 2 lines

I think this would readable, and I guess this will generates faster/simpler code (at least, this doesn't depends an optimization of gcc).

I agree. I will change it as your opinion.
Thanks a lot, OGAWA!.

Quoted 4 lines

Thanks.
--
OGAWA Hirofumi <[email protected]>