aboutsummaryrefslogtreecommitdiffstats
path: root/fs/fat/nfs.c
diff options
context:
space:
mode:
authorNamjae Jeon <namjae.jeon@samsung.com>2013-04-29 19:21:11 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-04-29 21:28:40 -0400
commitea3983ace6b79c96e6ab3d3837e2eaf81ab881e2 (patch)
treeebd063193dcbbddaccd10e62894d477f9e203ac3 /fs/fat/nfs.c
parente22a444275d1e7c80db5d8bec08fb8d0d79617ad (diff)
fat: restructure export_operations
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. Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com> Signed-off-by: Ravishankar N <ravi.n1@samsung.com> Signed-off-by: Amit Sahrawat <a.sahrawat@samsung.com> Acked-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/fat/nfs.c')
-rw-r--r--fs/fat/nfs.c130
1 files changed, 125 insertions, 5 deletions
diff --git a/fs/fat/nfs.c b/fs/fat/nfs.c
index 499c10438ca2..d59c02543a10 100644
--- a/fs/fat/nfs.c
+++ b/fs/fat/nfs.c
@@ -14,6 +14,18 @@
14#include <linux/exportfs.h> 14#include <linux/exportfs.h>
15#include "fat.h" 15#include "fat.h"
16 16
17struct fat_fid {
18 u32 i_gen;
19 u32 i_pos_low;
20 u16 i_pos_hi;
21 u16 parent_i_pos_hi;
22 u32 parent_i_pos_low;
23 u32 parent_i_gen;
24};
25
26#define FAT_FID_SIZE_WITHOUT_PARENT 3
27#define FAT_FID_SIZE_WITH_PARENT (sizeof(struct fat_fid)/sizeof(u32))
28
17/** 29/**
18 * Look up a directory inode given its starting cluster. 30 * Look up a directory inode given its starting cluster.
19 */ 31 */
@@ -38,8 +50,8 @@ static struct inode *fat_dget(struct super_block *sb, int i_logstart)
38 return inode; 50 return inode;
39} 51}
40 52
41static struct inode *fat_nfs_get_inode(struct super_block *sb, 53static struct inode *__fat_nfs_get_inode(struct super_block *sb,
42 u64 ino, u32 generation) 54 u64 ino, u32 generation, loff_t i_pos)
43{ 55{
44 struct inode *inode; 56 struct inode *inode;
45 57
@@ -55,35 +67,130 @@ static struct inode *fat_nfs_get_inode(struct super_block *sb,
55 return inode; 67 return inode;
56} 68}
57 69
70static struct inode *fat_nfs_get_inode(struct super_block *sb,
71 u64 ino, u32 generation)
72{
73
74 return __fat_nfs_get_inode(sb, ino, generation, 0);
75}
76
77static int
78fat_encode_fh_nostale(struct inode *inode, __u32 *fh, int *lenp,
79 struct inode *parent)
80{
81 int len = *lenp;
82 struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb);
83 struct fat_fid *fid = (struct fat_fid *) fh;
84 loff_t i_pos;
85 int type = FILEID_FAT_WITHOUT_PARENT;
86
87 if (parent) {
88 if (len < FAT_FID_SIZE_WITH_PARENT) {
89 *lenp = FAT_FID_SIZE_WITH_PARENT;
90 return FILEID_INVALID;
91 }
92 } else {
93 if (len < FAT_FID_SIZE_WITHOUT_PARENT) {
94 *lenp = FAT_FID_SIZE_WITHOUT_PARENT;
95 return FILEID_INVALID;
96 }
97 }
98
99 i_pos = fat_i_pos_read(sbi, inode);
100 *lenp = FAT_FID_SIZE_WITHOUT_PARENT;
101 fid->i_gen = inode->i_generation;
102 fid->i_pos_low = i_pos & 0xFFFFFFFF;
103 fid->i_pos_hi = (i_pos >> 32) & 0xFFFF;
104 if (parent) {
105 i_pos = fat_i_pos_read(sbi, parent);
106 fid->parent_i_pos_hi = (i_pos >> 32) & 0xFFFF;
107 fid->parent_i_pos_low = i_pos & 0xFFFFFFFF;
108 fid->parent_i_gen = parent->i_generation;
109 type = FILEID_FAT_WITH_PARENT;
110 *lenp = FAT_FID_SIZE_WITH_PARENT;
111 }
112
113 return type;
114}
115
58/** 116/**
59 * Map a NFS file handle to a corresponding dentry. 117 * Map a NFS file handle to a corresponding dentry.
60 * The dentry may or may not be connected to the filesystem root. 118 * The dentry may or may not be connected to the filesystem root.
61 */ 119 */
62struct dentry *fat_fh_to_dentry(struct super_block *sb, struct fid *fid, 120static struct dentry *fat_fh_to_dentry(struct super_block *sb, struct fid *fid,
63 int fh_len, int fh_type) 121 int fh_len, int fh_type)
64{ 122{
65 return generic_fh_to_dentry(sb, fid, fh_len, fh_type, 123 return generic_fh_to_dentry(sb, fid, fh_len, fh_type,
66 fat_nfs_get_inode); 124 fat_nfs_get_inode);
67} 125}
68 126
127static struct dentry *fat_fh_to_dentry_nostale(struct super_block *sb,
128 struct fid *fh, int fh_len,
129 int fh_type)
130{
131 struct inode *inode = NULL;
132 struct fat_fid *fid = (struct fat_fid *)fh;
133 loff_t i_pos;
134
135 switch (fh_type) {
136 case FILEID_FAT_WITHOUT_PARENT:
137 if (fh_len < FAT_FID_SIZE_WITHOUT_PARENT)
138 return NULL;
139 break;
140 case FILEID_FAT_WITH_PARENT:
141 if (fh_len < FAT_FID_SIZE_WITH_PARENT)
142 return NULL;
143 break;
144 default:
145 return NULL;
146 }
147 i_pos = fid->i_pos_hi;
148 i_pos = (i_pos << 32) | (fid->i_pos_low);
149 inode = __fat_nfs_get_inode(sb, 0, fid->i_gen, i_pos);
150
151 return d_obtain_alias(inode);
152}
153
69/* 154/*
70 * Find the parent for a file specified by NFS handle. 155 * Find the parent for a file specified by NFS handle.
71 * This requires that the handle contain the i_ino of the parent. 156 * This requires that the handle contain the i_ino of the parent.
72 */ 157 */
73struct dentry *fat_fh_to_parent(struct super_block *sb, struct fid *fid, 158static struct dentry *fat_fh_to_parent(struct super_block *sb, struct fid *fid,
74 int fh_len, int fh_type) 159 int fh_len, int fh_type)
75{ 160{
76 return generic_fh_to_parent(sb, fid, fh_len, fh_type, 161 return generic_fh_to_parent(sb, fid, fh_len, fh_type,
77 fat_nfs_get_inode); 162 fat_nfs_get_inode);
78} 163}
79 164
165static struct dentry *fat_fh_to_parent_nostale(struct super_block *sb,
166 struct fid *fh, int fh_len,
167 int fh_type)
168{
169 struct inode *inode = NULL;
170 struct fat_fid *fid = (struct fat_fid *)fh;
171 loff_t i_pos;
172
173 if (fh_len < FAT_FID_SIZE_WITH_PARENT)
174 return NULL;
175
176 switch (fh_type) {
177 case FILEID_FAT_WITH_PARENT:
178 i_pos = fid->parent_i_pos_hi;
179 i_pos = (i_pos << 32) | (fid->parent_i_pos_low);
180 inode = __fat_nfs_get_inode(sb, 0, fid->parent_i_gen, i_pos);
181 break;
182 }
183
184 return d_obtain_alias(inode);
185}
186
80/* 187/*
81 * Find the parent for a directory that is not currently connected to 188 * Find the parent for a directory that is not currently connected to
82 * the filesystem root. 189 * the filesystem root.
83 * 190 *
84 * On entry, the caller holds child_dir->d_inode->i_mutex. 191 * On entry, the caller holds child_dir->d_inode->i_mutex.
85 */ 192 */
86struct dentry *fat_get_parent(struct dentry *child_dir) 193static struct dentry *fat_get_parent(struct dentry *child_dir)
87{ 194{
88 struct super_block *sb = child_dir->d_sb; 195 struct super_block *sb = child_dir->d_sb;
89 struct buffer_head *bh = NULL; 196 struct buffer_head *bh = NULL;
@@ -98,3 +205,16 @@ struct dentry *fat_get_parent(struct dentry *child_dir)
98 205
99 return d_obtain_alias(parent_inode); 206 return d_obtain_alias(parent_inode);
100} 207}
208
209const struct export_operations fat_export_ops = {
210 .fh_to_dentry = fat_fh_to_dentry,
211 .fh_to_parent = fat_fh_to_parent,
212 .get_parent = fat_get_parent,
213};
214
215const struct export_operations fat_export_ops_nostale = {
216 .encode_fh = fat_encode_fh_nostale,
217 .fh_to_dentry = fat_fh_to_dentry_nostale,
218 .fh_to_parent = fat_fh_to_parent_nostale,
219 .get_parent = fat_get_parent,
220};