diff options
author | J. Bruce Fields <bfields@citi.umich.edu> | 2009-12-04 19:36:06 -0500 |
---|---|---|
committer | J. Bruce Fields <bfields@citi.umich.edu> | 2009-12-15 15:01:46 -0500 |
commit | 1557aca7904ed6fadd22cdc3364754070bb3d3c3 (patch) | |
tree | 97af309e4cff7e9fc2cb9d90aeceff8404c2c47f | |
parent | c7af6b0895229bd080b86afc91302b66f6df0378 (diff) |
nfsd: move most of nfsfh.h to fs/nfsd
Most of this can be trivially moved to a private header as well.
Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
-rw-r--r-- | fs/nfsd/export.c | 1 | ||||
-rw-r--r-- | fs/nfsd/nfsfh.h | 208 | ||||
-rw-r--r-- | fs/nfsd/state.h | 1 | ||||
-rw-r--r-- | fs/nfsd/vfs.h | 2 | ||||
-rw-r--r-- | fs/nfsd/xdr.h | 1 | ||||
-rw-r--r-- | include/linux/nfsd/nfsfh.h | 199 |
6 files changed, 213 insertions, 199 deletions
diff --git a/fs/nfsd/export.c b/fs/nfsd/export.c index 7d5ba1b0ffcf..b26a3644fbb9 100644 --- a/fs/nfsd/export.c +++ b/fs/nfsd/export.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <net/ipv6.h> | 22 | #include <net/ipv6.h> |
23 | 23 | ||
24 | #include "nfsd.h" | 24 | #include "nfsd.h" |
25 | #include "nfsfh.h" | ||
25 | 26 | ||
26 | #define NFSDDBG_FACILITY NFSDDBG_EXPORT | 27 | #define NFSDDBG_FACILITY NFSDDBG_EXPORT |
27 | 28 | ||
diff --git a/fs/nfsd/nfsfh.h b/fs/nfsd/nfsfh.h new file mode 100644 index 000000000000..cdfb8c6a4206 --- /dev/null +++ b/fs/nfsd/nfsfh.h | |||
@@ -0,0 +1,208 @@ | |||
1 | /* Copyright (C) 1995, 1996, 1997 Olaf Kirch <okir@monad.swb.de> */ | ||
2 | |||
3 | #ifndef _LINUX_NFSD_FH_INT_H | ||
4 | #define _LINUX_NFSD_FH_INT_H | ||
5 | |||
6 | #include <linux/nfsd/nfsfh.h> | ||
7 | |||
8 | enum nfsd_fsid { | ||
9 | FSID_DEV = 0, | ||
10 | FSID_NUM, | ||
11 | FSID_MAJOR_MINOR, | ||
12 | FSID_ENCODE_DEV, | ||
13 | FSID_UUID4_INUM, | ||
14 | FSID_UUID8, | ||
15 | FSID_UUID16, | ||
16 | FSID_UUID16_INUM, | ||
17 | }; | ||
18 | |||
19 | enum fsid_source { | ||
20 | FSIDSOURCE_DEV, | ||
21 | FSIDSOURCE_FSID, | ||
22 | FSIDSOURCE_UUID, | ||
23 | }; | ||
24 | extern enum fsid_source fsid_source(struct svc_fh *fhp); | ||
25 | |||
26 | |||
27 | /* This might look a little large to "inline" but in all calls except | ||
28 | * one, 'vers' is constant so moste of the function disappears. | ||
29 | */ | ||
30 | static inline void mk_fsid(int vers, u32 *fsidv, dev_t dev, ino_t ino, | ||
31 | u32 fsid, unsigned char *uuid) | ||
32 | { | ||
33 | u32 *up; | ||
34 | switch(vers) { | ||
35 | case FSID_DEV: | ||
36 | fsidv[0] = htonl((MAJOR(dev)<<16) | | ||
37 | MINOR(dev)); | ||
38 | fsidv[1] = ino_t_to_u32(ino); | ||
39 | break; | ||
40 | case FSID_NUM: | ||
41 | fsidv[0] = fsid; | ||
42 | break; | ||
43 | case FSID_MAJOR_MINOR: | ||
44 | fsidv[0] = htonl(MAJOR(dev)); | ||
45 | fsidv[1] = htonl(MINOR(dev)); | ||
46 | fsidv[2] = ino_t_to_u32(ino); | ||
47 | break; | ||
48 | |||
49 | case FSID_ENCODE_DEV: | ||
50 | fsidv[0] = new_encode_dev(dev); | ||
51 | fsidv[1] = ino_t_to_u32(ino); | ||
52 | break; | ||
53 | |||
54 | case FSID_UUID4_INUM: | ||
55 | /* 4 byte fsid and inode number */ | ||
56 | up = (u32*)uuid; | ||
57 | fsidv[0] = ino_t_to_u32(ino); | ||
58 | fsidv[1] = up[0] ^ up[1] ^ up[2] ^ up[3]; | ||
59 | break; | ||
60 | |||
61 | case FSID_UUID8: | ||
62 | /* 8 byte fsid */ | ||
63 | up = (u32*)uuid; | ||
64 | fsidv[0] = up[0] ^ up[2]; | ||
65 | fsidv[1] = up[1] ^ up[3]; | ||
66 | break; | ||
67 | |||
68 | case FSID_UUID16: | ||
69 | /* 16 byte fsid - NFSv3+ only */ | ||
70 | memcpy(fsidv, uuid, 16); | ||
71 | break; | ||
72 | |||
73 | case FSID_UUID16_INUM: | ||
74 | /* 8 byte inode and 16 byte fsid */ | ||
75 | *(u64*)fsidv = (u64)ino; | ||
76 | memcpy(fsidv+2, uuid, 16); | ||
77 | break; | ||
78 | default: BUG(); | ||
79 | } | ||
80 | } | ||
81 | |||
82 | static inline int key_len(int type) | ||
83 | { | ||
84 | switch(type) { | ||
85 | case FSID_DEV: return 8; | ||
86 | case FSID_NUM: return 4; | ||
87 | case FSID_MAJOR_MINOR: return 12; | ||
88 | case FSID_ENCODE_DEV: return 8; | ||
89 | case FSID_UUID4_INUM: return 8; | ||
90 | case FSID_UUID8: return 8; | ||
91 | case FSID_UUID16: return 16; | ||
92 | case FSID_UUID16_INUM: return 24; | ||
93 | default: return 0; | ||
94 | } | ||
95 | } | ||
96 | |||
97 | /* | ||
98 | * Shorthand for dprintk()'s | ||
99 | */ | ||
100 | extern char * SVCFH_fmt(struct svc_fh *fhp); | ||
101 | |||
102 | /* | ||
103 | * Function prototypes | ||
104 | */ | ||
105 | __be32 fh_verify(struct svc_rqst *, struct svc_fh *, int, int); | ||
106 | __be32 fh_compose(struct svc_fh *, struct svc_export *, struct dentry *, struct svc_fh *); | ||
107 | __be32 fh_update(struct svc_fh *); | ||
108 | void fh_put(struct svc_fh *); | ||
109 | |||
110 | static __inline__ struct svc_fh * | ||
111 | fh_copy(struct svc_fh *dst, struct svc_fh *src) | ||
112 | { | ||
113 | WARN_ON(src->fh_dentry || src->fh_locked); | ||
114 | |||
115 | *dst = *src; | ||
116 | return dst; | ||
117 | } | ||
118 | |||
119 | static inline void | ||
120 | fh_copy_shallow(struct knfsd_fh *dst, struct knfsd_fh *src) | ||
121 | { | ||
122 | dst->fh_size = src->fh_size; | ||
123 | memcpy(&dst->fh_base, &src->fh_base, src->fh_size); | ||
124 | } | ||
125 | |||
126 | static __inline__ struct svc_fh * | ||
127 | fh_init(struct svc_fh *fhp, int maxsize) | ||
128 | { | ||
129 | memset(fhp, 0, sizeof(*fhp)); | ||
130 | fhp->fh_maxsize = maxsize; | ||
131 | return fhp; | ||
132 | } | ||
133 | |||
134 | #ifdef CONFIG_NFSD_V3 | ||
135 | /* | ||
136 | * Fill in the pre_op attr for the wcc data | ||
137 | */ | ||
138 | static inline void | ||
139 | fill_pre_wcc(struct svc_fh *fhp) | ||
140 | { | ||
141 | struct inode *inode; | ||
142 | |||
143 | inode = fhp->fh_dentry->d_inode; | ||
144 | if (!fhp->fh_pre_saved) { | ||
145 | fhp->fh_pre_mtime = inode->i_mtime; | ||
146 | fhp->fh_pre_ctime = inode->i_ctime; | ||
147 | fhp->fh_pre_size = inode->i_size; | ||
148 | fhp->fh_pre_change = inode->i_version; | ||
149 | fhp->fh_pre_saved = 1; | ||
150 | } | ||
151 | } | ||
152 | |||
153 | extern void fill_post_wcc(struct svc_fh *); | ||
154 | #else | ||
155 | #define fill_pre_wcc(ignored) | ||
156 | #define fill_post_wcc(notused) | ||
157 | #endif /* CONFIG_NFSD_V3 */ | ||
158 | |||
159 | |||
160 | /* | ||
161 | * Lock a file handle/inode | ||
162 | * NOTE: both fh_lock and fh_unlock are done "by hand" in | ||
163 | * vfs.c:nfsd_rename as it needs to grab 2 i_mutex's at once | ||
164 | * so, any changes here should be reflected there. | ||
165 | */ | ||
166 | |||
167 | static inline void | ||
168 | fh_lock_nested(struct svc_fh *fhp, unsigned int subclass) | ||
169 | { | ||
170 | struct dentry *dentry = fhp->fh_dentry; | ||
171 | struct inode *inode; | ||
172 | |||
173 | BUG_ON(!dentry); | ||
174 | |||
175 | if (fhp->fh_locked) { | ||
176 | printk(KERN_WARNING "fh_lock: %s/%s already locked!\n", | ||
177 | dentry->d_parent->d_name.name, dentry->d_name.name); | ||
178 | return; | ||
179 | } | ||
180 | |||
181 | inode = dentry->d_inode; | ||
182 | mutex_lock_nested(&inode->i_mutex, subclass); | ||
183 | fill_pre_wcc(fhp); | ||
184 | fhp->fh_locked = 1; | ||
185 | } | ||
186 | |||
187 | static inline void | ||
188 | fh_lock(struct svc_fh *fhp) | ||
189 | { | ||
190 | fh_lock_nested(fhp, I_MUTEX_NORMAL); | ||
191 | } | ||
192 | |||
193 | /* | ||
194 | * Unlock a file handle/inode | ||
195 | */ | ||
196 | static inline void | ||
197 | fh_unlock(struct svc_fh *fhp) | ||
198 | { | ||
199 | BUG_ON(!fhp->fh_dentry); | ||
200 | |||
201 | if (fhp->fh_locked) { | ||
202 | fill_post_wcc(fhp); | ||
203 | mutex_unlock(&fhp->fh_dentry->d_inode->i_mutex); | ||
204 | fhp->fh_locked = 0; | ||
205 | } | ||
206 | } | ||
207 | |||
208 | #endif /* _LINUX_NFSD_FH_INT_H */ | ||
diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h index 2af75686e0d3..775b8d281d6a 100644 --- a/fs/nfsd/state.h +++ b/fs/nfsd/state.h | |||
@@ -38,6 +38,7 @@ | |||
38 | #define _NFSD4_STATE_H | 38 | #define _NFSD4_STATE_H |
39 | 39 | ||
40 | #include <linux/nfsd/nfsfh.h> | 40 | #include <linux/nfsd/nfsfh.h> |
41 | #include "nfsfh.h" | ||
41 | 42 | ||
42 | typedef struct { | 43 | typedef struct { |
43 | u32 cl_boot; | 44 | u32 cl_boot; |
diff --git a/fs/nfsd/vfs.h b/fs/nfsd/vfs.h index f4fa6d351bbd..4b1de0a9ea75 100644 --- a/fs/nfsd/vfs.h +++ b/fs/nfsd/vfs.h | |||
@@ -5,6 +5,8 @@ | |||
5 | #ifndef LINUX_NFSD_VFS_H | 5 | #ifndef LINUX_NFSD_VFS_H |
6 | #define LINUX_NFSD_VFS_H | 6 | #define LINUX_NFSD_VFS_H |
7 | 7 | ||
8 | #include "nfsfh.h" | ||
9 | |||
8 | /* | 10 | /* |
9 | * Flags for nfsd_permission | 11 | * Flags for nfsd_permission |
10 | */ | 12 | */ |
diff --git a/fs/nfsd/xdr.h b/fs/nfsd/xdr.h index 235ee5c3be54..87fe6f64b8f7 100644 --- a/fs/nfsd/xdr.h +++ b/fs/nfsd/xdr.h | |||
@@ -9,6 +9,7 @@ | |||
9 | 9 | ||
10 | #include <linux/vfs.h> | 10 | #include <linux/vfs.h> |
11 | #include "nfsd.h" | 11 | #include "nfsd.h" |
12 | #include "nfsfh.h" | ||
12 | 13 | ||
13 | struct nfsd_fhandle { | 14 | struct nfsd_fhandle { |
14 | struct svc_fh fh; | 15 | struct svc_fh fh; |
diff --git a/include/linux/nfsd/nfsfh.h b/include/linux/nfsd/nfsfh.h index 49523edbc510..65e333afaee4 100644 --- a/include/linux/nfsd/nfsfh.h +++ b/include/linux/nfsd/nfsfh.h | |||
@@ -162,205 +162,6 @@ typedef struct svc_fh { | |||
162 | 162 | ||
163 | } svc_fh; | 163 | } svc_fh; |
164 | 164 | ||
165 | enum nfsd_fsid { | ||
166 | FSID_DEV = 0, | ||
167 | FSID_NUM, | ||
168 | FSID_MAJOR_MINOR, | ||
169 | FSID_ENCODE_DEV, | ||
170 | FSID_UUID4_INUM, | ||
171 | FSID_UUID8, | ||
172 | FSID_UUID16, | ||
173 | FSID_UUID16_INUM, | ||
174 | }; | ||
175 | |||
176 | enum fsid_source { | ||
177 | FSIDSOURCE_DEV, | ||
178 | FSIDSOURCE_FSID, | ||
179 | FSIDSOURCE_UUID, | ||
180 | }; | ||
181 | extern enum fsid_source fsid_source(struct svc_fh *fhp); | ||
182 | |||
183 | |||
184 | /* This might look a little large to "inline" but in all calls except | ||
185 | * one, 'vers' is constant so moste of the function disappears. | ||
186 | */ | ||
187 | static inline void mk_fsid(int vers, u32 *fsidv, dev_t dev, ino_t ino, | ||
188 | u32 fsid, unsigned char *uuid) | ||
189 | { | ||
190 | u32 *up; | ||
191 | switch(vers) { | ||
192 | case FSID_DEV: | ||
193 | fsidv[0] = htonl((MAJOR(dev)<<16) | | ||
194 | MINOR(dev)); | ||
195 | fsidv[1] = ino_t_to_u32(ino); | ||
196 | break; | ||
197 | case FSID_NUM: | ||
198 | fsidv[0] = fsid; | ||
199 | break; | ||
200 | case FSID_MAJOR_MINOR: | ||
201 | fsidv[0] = htonl(MAJOR(dev)); | ||
202 | fsidv[1] = htonl(MINOR(dev)); | ||
203 | fsidv[2] = ino_t_to_u32(ino); | ||
204 | break; | ||
205 | |||
206 | case FSID_ENCODE_DEV: | ||
207 | fsidv[0] = new_encode_dev(dev); | ||
208 | fsidv[1] = ino_t_to_u32(ino); | ||
209 | break; | ||
210 | |||
211 | case FSID_UUID4_INUM: | ||
212 | /* 4 byte fsid and inode number */ | ||
213 | up = (u32*)uuid; | ||
214 | fsidv[0] = ino_t_to_u32(ino); | ||
215 | fsidv[1] = up[0] ^ up[1] ^ up[2] ^ up[3]; | ||
216 | break; | ||
217 | |||
218 | case FSID_UUID8: | ||
219 | /* 8 byte fsid */ | ||
220 | up = (u32*)uuid; | ||
221 | fsidv[0] = up[0] ^ up[2]; | ||
222 | fsidv[1] = up[1] ^ up[3]; | ||
223 | break; | ||
224 | |||
225 | case FSID_UUID16: | ||
226 | /* 16 byte fsid - NFSv3+ only */ | ||
227 | memcpy(fsidv, uuid, 16); | ||
228 | break; | ||
229 | |||
230 | case FSID_UUID16_INUM: | ||
231 | /* 8 byte inode and 16 byte fsid */ | ||
232 | *(u64*)fsidv = (u64)ino; | ||
233 | memcpy(fsidv+2, uuid, 16); | ||
234 | break; | ||
235 | default: BUG(); | ||
236 | } | ||
237 | } | ||
238 | |||
239 | static inline int key_len(int type) | ||
240 | { | ||
241 | switch(type) { | ||
242 | case FSID_DEV: return 8; | ||
243 | case FSID_NUM: return 4; | ||
244 | case FSID_MAJOR_MINOR: return 12; | ||
245 | case FSID_ENCODE_DEV: return 8; | ||
246 | case FSID_UUID4_INUM: return 8; | ||
247 | case FSID_UUID8: return 8; | ||
248 | case FSID_UUID16: return 16; | ||
249 | case FSID_UUID16_INUM: return 24; | ||
250 | default: return 0; | ||
251 | } | ||
252 | } | ||
253 | |||
254 | /* | ||
255 | * Shorthand for dprintk()'s | ||
256 | */ | ||
257 | extern char * SVCFH_fmt(struct svc_fh *fhp); | ||
258 | |||
259 | /* | ||
260 | * Function prototypes | ||
261 | */ | ||
262 | __be32 fh_verify(struct svc_rqst *, struct svc_fh *, int, int); | ||
263 | __be32 fh_compose(struct svc_fh *, struct svc_export *, struct dentry *, struct svc_fh *); | ||
264 | __be32 fh_update(struct svc_fh *); | ||
265 | void fh_put(struct svc_fh *); | ||
266 | |||
267 | static __inline__ struct svc_fh * | ||
268 | fh_copy(struct svc_fh *dst, struct svc_fh *src) | ||
269 | { | ||
270 | WARN_ON(src->fh_dentry || src->fh_locked); | ||
271 | |||
272 | *dst = *src; | ||
273 | return dst; | ||
274 | } | ||
275 | |||
276 | static inline void | ||
277 | fh_copy_shallow(struct knfsd_fh *dst, struct knfsd_fh *src) | ||
278 | { | ||
279 | dst->fh_size = src->fh_size; | ||
280 | memcpy(&dst->fh_base, &src->fh_base, src->fh_size); | ||
281 | } | ||
282 | |||
283 | static __inline__ struct svc_fh * | ||
284 | fh_init(struct svc_fh *fhp, int maxsize) | ||
285 | { | ||
286 | memset(fhp, 0, sizeof(*fhp)); | ||
287 | fhp->fh_maxsize = maxsize; | ||
288 | return fhp; | ||
289 | } | ||
290 | |||
291 | #ifdef CONFIG_NFSD_V3 | ||
292 | /* | ||
293 | * Fill in the pre_op attr for the wcc data | ||
294 | */ | ||
295 | static inline void | ||
296 | fill_pre_wcc(struct svc_fh *fhp) | ||
297 | { | ||
298 | struct inode *inode; | ||
299 | |||
300 | inode = fhp->fh_dentry->d_inode; | ||
301 | if (!fhp->fh_pre_saved) { | ||
302 | fhp->fh_pre_mtime = inode->i_mtime; | ||
303 | fhp->fh_pre_ctime = inode->i_ctime; | ||
304 | fhp->fh_pre_size = inode->i_size; | ||
305 | fhp->fh_pre_change = inode->i_version; | ||
306 | fhp->fh_pre_saved = 1; | ||
307 | } | ||
308 | } | ||
309 | |||
310 | extern void fill_post_wcc(struct svc_fh *); | ||
311 | #else | ||
312 | #define fill_pre_wcc(ignored) | ||
313 | #define fill_post_wcc(notused) | ||
314 | #endif /* CONFIG_NFSD_V3 */ | ||
315 | |||
316 | |||
317 | /* | ||
318 | * Lock a file handle/inode | ||
319 | * NOTE: both fh_lock and fh_unlock are done "by hand" in | ||
320 | * vfs.c:nfsd_rename as it needs to grab 2 i_mutex's at once | ||
321 | * so, any changes here should be reflected there. | ||
322 | */ | ||
323 | |||
324 | static inline void | ||
325 | fh_lock_nested(struct svc_fh *fhp, unsigned int subclass) | ||
326 | { | ||
327 | struct dentry *dentry = fhp->fh_dentry; | ||
328 | struct inode *inode; | ||
329 | |||
330 | BUG_ON(!dentry); | ||
331 | |||
332 | if (fhp->fh_locked) { | ||
333 | printk(KERN_WARNING "fh_lock: %s/%s already locked!\n", | ||
334 | dentry->d_parent->d_name.name, dentry->d_name.name); | ||
335 | return; | ||
336 | } | ||
337 | |||
338 | inode = dentry->d_inode; | ||
339 | mutex_lock_nested(&inode->i_mutex, subclass); | ||
340 | fill_pre_wcc(fhp); | ||
341 | fhp->fh_locked = 1; | ||
342 | } | ||
343 | |||
344 | static inline void | ||
345 | fh_lock(struct svc_fh *fhp) | ||
346 | { | ||
347 | fh_lock_nested(fhp, I_MUTEX_NORMAL); | ||
348 | } | ||
349 | |||
350 | /* | ||
351 | * Unlock a file handle/inode | ||
352 | */ | ||
353 | static inline void | ||
354 | fh_unlock(struct svc_fh *fhp) | ||
355 | { | ||
356 | BUG_ON(!fhp->fh_dentry); | ||
357 | |||
358 | if (fhp->fh_locked) { | ||
359 | fill_post_wcc(fhp); | ||
360 | mutex_unlock(&fhp->fh_dentry->d_inode->i_mutex); | ||
361 | fhp->fh_locked = 0; | ||
362 | } | ||
363 | } | ||
364 | #endif /* __KERNEL__ */ | 165 | #endif /* __KERNEL__ */ |
365 | 166 | ||
366 | 167 | ||