nfsfh.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. /*
  2. * linux/fs/nfsd/nfsfh.c
  3. *
  4. * NFS server file handle treatment.
  5. *
  6. * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
  7. * Portions Copyright (C) 1999 G. Allen Morris III <gam3@acm.org>
  8. * Extensive rewrite by Neil Brown <neilb@cse.unsw.edu.au> Southern-Spring 1999
  9. * ... and again Southern-Winter 2001 to support export_operations
  10. */
  11. #include <linux/slab.h>
  12. #include <linux/fs.h>
  13. #include <linux/unistd.h>
  14. #include <linux/string.h>
  15. #include <linux/stat.h>
  16. #include <linux/dcache.h>
  17. #include <linux/exportfs.h>
  18. #include <linux/mount.h>
  19. #include <linux/sunrpc/clnt.h>
  20. #include <linux/sunrpc/svc.h>
  21. #include <linux/sunrpc/svcauth_gss.h>
  22. #include <linux/nfsd/nfsd.h>
  23. #include "auth.h"
  24. #define NFSDDBG_FACILITY NFSDDBG_FH
  25. /*
  26. * our acceptability function.
  27. * if NOSUBTREECHECK, accept anything
  28. * if not, require that we can walk up to exp->ex_dentry
  29. * doing some checks on the 'x' bits
  30. */
  31. static int nfsd_acceptable(void *expv, struct dentry *dentry)
  32. {
  33. struct svc_export *exp = expv;
  34. int rv;
  35. struct dentry *tdentry;
  36. struct dentry *parent;
  37. if (exp->ex_flags & NFSEXP_NOSUBTREECHECK)
  38. return 1;
  39. tdentry = dget(dentry);
  40. while (tdentry != exp->ex_path.dentry && !IS_ROOT(tdentry)) {
  41. /* make sure parents give x permission to user */
  42. int err;
  43. parent = dget_parent(tdentry);
  44. err = inode_permission(parent->d_inode, MAY_EXEC);
  45. if (err < 0) {
  46. dput(parent);
  47. break;
  48. }
  49. dput(tdentry);
  50. tdentry = parent;
  51. }
  52. if (tdentry != exp->ex_path.dentry)
  53. dprintk("nfsd_acceptable failed at %p %s\n", tdentry, tdentry->d_name.name);
  54. rv = (tdentry == exp->ex_path.dentry);
  55. dput(tdentry);
  56. return rv;
  57. }
  58. /* Type check. The correct error return for type mismatches does not seem to be
  59. * generally agreed upon. SunOS seems to use EISDIR if file isn't S_IFREG; a
  60. * comment in the NFSv3 spec says this is incorrect (implementation notes for
  61. * the write call).
  62. */
  63. static inline __be32
  64. nfsd_mode_check(struct svc_rqst *rqstp, umode_t mode, int type)
  65. {
  66. /* Type can be negative when creating hardlinks - not to a dir */
  67. if (type > 0 && (mode & S_IFMT) != type) {
  68. if (rqstp->rq_vers == 4 && (mode & S_IFMT) == S_IFLNK)
  69. return nfserr_symlink;
  70. else if (type == S_IFDIR)
  71. return nfserr_notdir;
  72. else if ((mode & S_IFMT) == S_IFDIR)
  73. return nfserr_isdir;
  74. else
  75. return nfserr_inval;
  76. }
  77. if (type < 0 && (mode & S_IFMT) == -type) {
  78. if (rqstp->rq_vers == 4 && (mode & S_IFMT) == S_IFLNK)
  79. return nfserr_symlink;
  80. else if (type == -S_IFDIR)
  81. return nfserr_isdir;
  82. else
  83. return nfserr_notdir;
  84. }
  85. return 0;
  86. }
  87. static __be32 nfsd_setuser_and_check_port(struct svc_rqst *rqstp,
  88. struct svc_export *exp)
  89. {
  90. /* Check if the request originated from a secure port. */
  91. if (!rqstp->rq_secure && EX_SECURE(exp)) {
  92. RPC_IFDEBUG(char buf[RPC_MAX_ADDRBUFLEN]);
  93. dprintk(KERN_WARNING
  94. "nfsd: request from insecure port %s!\n",
  95. svc_print_addr(rqstp, buf, sizeof(buf)));
  96. return nfserr_perm;
  97. }
  98. /* Set user creds for this exportpoint */
  99. return nfserrno(nfsd_setuser(rqstp, exp));
  100. }
  101. /*
  102. * Use the given filehandle to look up the corresponding export and
  103. * dentry. On success, the results are used to set fh_export and
  104. * fh_dentry.
  105. */
  106. static __be32 nfsd_set_fh_dentry(struct svc_rqst *rqstp, struct svc_fh *fhp)
  107. {
  108. struct knfsd_fh *fh = &fhp->fh_handle;
  109. struct fid *fid = NULL, sfid;
  110. struct svc_export *exp;
  111. struct dentry *dentry;
  112. int fileid_type;
  113. int data_left = fh->fh_size/4;
  114. __be32 error;
  115. error = nfserr_stale;
  116. if (rqstp->rq_vers > 2)
  117. error = nfserr_badhandle;
  118. if (rqstp->rq_vers == 4 && fh->fh_size == 0)
  119. return nfserr_nofilehandle;
  120. if (fh->fh_version == 1) {
  121. int len;
  122. if (--data_left < 0)
  123. return error;
  124. if (fh->fh_auth_type != 0)
  125. return error;
  126. len = key_len(fh->fh_fsid_type) / 4;
  127. if (len == 0)
  128. return error;
  129. if (fh->fh_fsid_type == FSID_MAJOR_MINOR) {
  130. /* deprecated, convert to type 3 */
  131. len = key_len(FSID_ENCODE_DEV)/4;
  132. fh->fh_fsid_type = FSID_ENCODE_DEV;
  133. fh->fh_fsid[0] = new_encode_dev(MKDEV(ntohl(fh->fh_fsid[0]), ntohl(fh->fh_fsid[1])));
  134. fh->fh_fsid[1] = fh->fh_fsid[2];
  135. }
  136. data_left -= len;
  137. if (data_left < 0)
  138. return error;
  139. exp = rqst_exp_find(rqstp, fh->fh_fsid_type, fh->fh_auth);
  140. fid = (struct fid *)(fh->fh_auth + len);
  141. } else {
  142. __u32 tfh[2];
  143. dev_t xdev;
  144. ino_t xino;
  145. if (fh->fh_size != NFS_FHSIZE)
  146. return error;
  147. /* assume old filehandle format */
  148. xdev = old_decode_dev(fh->ofh_xdev);
  149. xino = u32_to_ino_t(fh->ofh_xino);
  150. mk_fsid(FSID_DEV, tfh, xdev, xino, 0, NULL);
  151. exp = rqst_exp_find(rqstp, FSID_DEV, tfh);
  152. }
  153. error = nfserr_stale;
  154. if (PTR_ERR(exp) == -ENOENT)
  155. return error;
  156. if (IS_ERR(exp))
  157. return nfserrno(PTR_ERR(exp));
  158. if (exp->ex_flags & NFSEXP_NOSUBTREECHECK) {
  159. /* Elevate privileges so that the lack of 'r' or 'x'
  160. * permission on some parent directory will
  161. * not stop exportfs_decode_fh from being able
  162. * to reconnect a directory into the dentry cache.
  163. * The same problem can affect "SUBTREECHECK" exports,
  164. * but as nfsd_acceptable depends on correct
  165. * access control settings being in effect, we cannot
  166. * fix that case easily.
  167. */
  168. struct cred *new = prepare_creds();
  169. if (!new)
  170. return nfserrno(-ENOMEM);
  171. new->cap_effective =
  172. cap_raise_nfsd_set(new->cap_effective,
  173. new->cap_permitted);
  174. put_cred(override_creds(new));
  175. put_cred(new);
  176. } else {
  177. error = nfsd_setuser_and_check_port(rqstp, exp);
  178. if (error)
  179. goto out;
  180. }
  181. /*
  182. * Look up the dentry using the NFS file handle.
  183. */
  184. error = nfserr_stale;
  185. if (rqstp->rq_vers > 2)
  186. error = nfserr_badhandle;
  187. if (fh->fh_version != 1) {
  188. sfid.i32.ino = fh->ofh_ino;
  189. sfid.i32.gen = fh->ofh_generation;
  190. sfid.i32.parent_ino = fh->ofh_dirino;
  191. fid = &sfid;
  192. data_left = 3;
  193. if (fh->ofh_dirino == 0)
  194. fileid_type = FILEID_INO32_GEN;
  195. else
  196. fileid_type = FILEID_INO32_GEN_PARENT;
  197. } else
  198. fileid_type = fh->fh_fileid_type;
  199. if (fileid_type == FILEID_ROOT)
  200. dentry = dget(exp->ex_path.dentry);
  201. else {
  202. dentry = exportfs_decode_fh(exp->ex_path.mnt, fid,
  203. data_left, fileid_type,
  204. nfsd_acceptable, exp);
  205. }
  206. if (dentry == NULL)
  207. goto out;
  208. if (IS_ERR(dentry)) {
  209. if (PTR_ERR(dentry) != -EINVAL)
  210. error = nfserrno(PTR_ERR(dentry));
  211. goto out;
  212. }
  213. if (exp->ex_flags & NFSEXP_NOSUBTREECHECK) {
  214. error = nfsd_setuser_and_check_port(rqstp, exp);
  215. if (error) {
  216. dput(dentry);
  217. goto out;
  218. }
  219. }
  220. if (S_ISDIR(dentry->d_inode->i_mode) &&
  221. (dentry->d_flags & DCACHE_DISCONNECTED)) {
  222. printk("nfsd: find_fh_dentry returned a DISCONNECTED directory: %s/%s\n",
  223. dentry->d_parent->d_name.name, dentry->d_name.name);
  224. }
  225. fhp->fh_dentry = dentry;
  226. fhp->fh_export = exp;
  227. return 0;
  228. out:
  229. exp_put(exp);
  230. return error;
  231. }
  232. /**
  233. * fh_verify - filehandle lookup and access checking
  234. * @rqstp: pointer to current rpc request
  235. * @fhp: filehandle to be verified
  236. * @type: expected type of object pointed to by filehandle
  237. * @access: type of access needed to object
  238. *
  239. * Look up a dentry from the on-the-wire filehandle, check the client's
  240. * access to the export, and set the current task's credentials.
  241. *
  242. * Regardless of success or failure of fh_verify(), fh_put() should be
  243. * called on @fhp when the caller is finished with the filehandle.
  244. *
  245. * fh_verify() may be called multiple times on a given filehandle, for
  246. * example, when processing an NFSv4 compound. The first call will look
  247. * up a dentry using the on-the-wire filehandle. Subsequent calls will
  248. * skip the lookup and just perform the other checks and possibly change
  249. * the current task's credentials.
  250. *
  251. * @type specifies the type of object expected using one of the S_IF*
  252. * constants defined in include/linux/stat.h. The caller may use zero
  253. * to indicate that it doesn't care, or a negative integer to indicate
  254. * that it expects something not of the given type.
  255. *
  256. * @access is formed from the NFSD_MAY_* constants defined in
  257. * include/linux/nfsd/nfsd.h.
  258. */
  259. __be32
  260. fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, int access)
  261. {
  262. struct svc_export *exp;
  263. struct dentry *dentry;
  264. __be32 error;
  265. dprintk("nfsd: fh_verify(%s)\n", SVCFH_fmt(fhp));
  266. if (!fhp->fh_dentry) {
  267. error = nfsd_set_fh_dentry(rqstp, fhp);
  268. if (error)
  269. goto out;
  270. dentry = fhp->fh_dentry;
  271. exp = fhp->fh_export;
  272. } else {
  273. /*
  274. * just rechecking permissions
  275. * (e.g. nfsproc_create calls fh_verify, then nfsd_create
  276. * does as well)
  277. */
  278. dprintk("nfsd: fh_verify - just checking\n");
  279. dentry = fhp->fh_dentry;
  280. exp = fhp->fh_export;
  281. /*
  282. * Set user creds for this exportpoint; necessary even
  283. * in the "just checking" case because this may be a
  284. * filehandle that was created by fh_compose, and that
  285. * is about to be used in another nfsv4 compound
  286. * operation.
  287. */
  288. error = nfsd_setuser_and_check_port(rqstp, exp);
  289. if (error)
  290. goto out;
  291. }
  292. error = nfsd_mode_check(rqstp, dentry->d_inode->i_mode, type);
  293. if (error)
  294. goto out;
  295. /*
  296. * pseudoflavor restrictions are not enforced on NLM,
  297. * which clients virtually always use auth_sys for,
  298. * even while using RPCSEC_GSS for NFS.
  299. */
  300. if (access & NFSD_MAY_LOCK)
  301. goto skip_pseudoflavor_check;
  302. /*
  303. * Clients may expect to be able to use auth_sys during mount,
  304. * even if they use gss for everything else; see section 2.3.2
  305. * of rfc 2623.
  306. */
  307. if (access & NFSD_MAY_BYPASS_GSS_ON_ROOT
  308. && exp->ex_path.dentry == dentry)
  309. goto skip_pseudoflavor_check;
  310. error = check_nfsd_access(exp, rqstp);
  311. if (error)
  312. goto out;
  313. skip_pseudoflavor_check:
  314. /* Finally, check access permissions. */
  315. error = nfsd_permission(rqstp, exp, dentry, access);
  316. if (error) {
  317. dprintk("fh_verify: %s/%s permission failure, "
  318. "acc=%x, error=%d\n",
  319. dentry->d_parent->d_name.name,
  320. dentry->d_name.name,
  321. access, ntohl(error));
  322. }
  323. out:
  324. if (error == nfserr_stale)
  325. nfsdstats.fh_stale++;
  326. return error;
  327. }
  328. /*
  329. * Compose a file handle for an NFS reply.
  330. *
  331. * Note that when first composed, the dentry may not yet have
  332. * an inode. In this case a call to fh_update should be made
  333. * before the fh goes out on the wire ...
  334. */
  335. static void _fh_update(struct svc_fh *fhp, struct svc_export *exp,
  336. struct dentry *dentry)
  337. {
  338. if (dentry != exp->ex_path.dentry) {
  339. struct fid *fid = (struct fid *)
  340. (fhp->fh_handle.fh_auth + fhp->fh_handle.fh_size/4 - 1);
  341. int maxsize = (fhp->fh_maxsize - fhp->fh_handle.fh_size)/4;
  342. int subtreecheck = !(exp->ex_flags & NFSEXP_NOSUBTREECHECK);
  343. fhp->fh_handle.fh_fileid_type =
  344. exportfs_encode_fh(dentry, fid, &maxsize, subtreecheck);
  345. fhp->fh_handle.fh_size += maxsize * 4;
  346. } else {
  347. fhp->fh_handle.fh_fileid_type = FILEID_ROOT;
  348. }
  349. }
  350. /*
  351. * for composing old style file handles
  352. */
  353. static inline void _fh_update_old(struct dentry *dentry,
  354. struct svc_export *exp,
  355. struct knfsd_fh *fh)
  356. {
  357. fh->ofh_ino = ino_t_to_u32(dentry->d_inode->i_ino);
  358. fh->ofh_generation = dentry->d_inode->i_generation;
  359. if (S_ISDIR(dentry->d_inode->i_mode) ||
  360. (exp->ex_flags & NFSEXP_NOSUBTREECHECK))
  361. fh->ofh_dirino = 0;
  362. }
  363. __be32
  364. fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry,
  365. struct svc_fh *ref_fh)
  366. {
  367. /* ref_fh is a reference file handle.
  368. * if it is non-null and for the same filesystem, then we should compose
  369. * a filehandle which is of the same version, where possible.
  370. * Currently, that means that if ref_fh->fh_handle.fh_version == 0xca
  371. * Then create a 32byte filehandle using nfs_fhbase_old
  372. *
  373. */
  374. u8 version;
  375. u8 fsid_type = 0;
  376. struct inode * inode = dentry->d_inode;
  377. struct dentry *parent = dentry->d_parent;
  378. __u32 *datap;
  379. dev_t ex_dev = exp->ex_path.dentry->d_inode->i_sb->s_dev;
  380. int root_export = (exp->ex_path.dentry == exp->ex_path.dentry->d_sb->s_root);
  381. dprintk("nfsd: fh_compose(exp %02x:%02x/%ld %s/%s, ino=%ld)\n",
  382. MAJOR(ex_dev), MINOR(ex_dev),
  383. (long) exp->ex_path.dentry->d_inode->i_ino,
  384. parent->d_name.name, dentry->d_name.name,
  385. (inode ? inode->i_ino : 0));
  386. /* Choose filehandle version and fsid type based on
  387. * the reference filehandle (if it is in the same export)
  388. * or the export options.
  389. */
  390. retry:
  391. version = 1;
  392. if (ref_fh && ref_fh->fh_export == exp) {
  393. version = ref_fh->fh_handle.fh_version;
  394. fsid_type = ref_fh->fh_handle.fh_fsid_type;
  395. if (ref_fh == fhp)
  396. fh_put(ref_fh);
  397. ref_fh = NULL;
  398. switch (version) {
  399. case 0xca:
  400. fsid_type = FSID_DEV;
  401. break;
  402. case 1:
  403. break;
  404. default:
  405. goto retry;
  406. }
  407. /* Need to check that this type works for this
  408. * export point. As the fsid -> filesystem mapping
  409. * was guided by user-space, there is no guarantee
  410. * that the filesystem actually supports that fsid
  411. * type. If it doesn't we loop around again without
  412. * ref_fh set.
  413. */
  414. switch(fsid_type) {
  415. case FSID_DEV:
  416. if (!old_valid_dev(ex_dev))
  417. goto retry;
  418. /* FALL THROUGH */
  419. case FSID_MAJOR_MINOR:
  420. case FSID_ENCODE_DEV:
  421. if (!(exp->ex_path.dentry->d_inode->i_sb->s_type->fs_flags
  422. & FS_REQUIRES_DEV))
  423. goto retry;
  424. break;
  425. case FSID_NUM:
  426. if (! (exp->ex_flags & NFSEXP_FSID))
  427. goto retry;
  428. break;
  429. case FSID_UUID8:
  430. case FSID_UUID16:
  431. if (!root_export)
  432. goto retry;
  433. /* fall through */
  434. case FSID_UUID4_INUM:
  435. case FSID_UUID16_INUM:
  436. if (exp->ex_uuid == NULL)
  437. goto retry;
  438. break;
  439. }
  440. } else if (exp->ex_flags & NFSEXP_FSID) {
  441. fsid_type = FSID_NUM;
  442. } else if (exp->ex_uuid) {
  443. if (fhp->fh_maxsize >= 64) {
  444. if (root_export)
  445. fsid_type = FSID_UUID16;
  446. else
  447. fsid_type = FSID_UUID16_INUM;
  448. } else {
  449. if (root_export)
  450. fsid_type = FSID_UUID8;
  451. else
  452. fsid_type = FSID_UUID4_INUM;
  453. }
  454. } else if (!old_valid_dev(ex_dev))
  455. /* for newer device numbers, we must use a newer fsid format */
  456. fsid_type = FSID_ENCODE_DEV;
  457. else
  458. fsid_type = FSID_DEV;
  459. if (ref_fh == fhp)
  460. fh_put(ref_fh);
  461. if (fhp->fh_locked || fhp->fh_dentry) {
  462. printk(KERN_ERR "fh_compose: fh %s/%s not initialized!\n",
  463. parent->d_name.name, dentry->d_name.name);
  464. }
  465. if (fhp->fh_maxsize < NFS_FHSIZE)
  466. printk(KERN_ERR "fh_compose: called with maxsize %d! %s/%s\n",
  467. fhp->fh_maxsize,
  468. parent->d_name.name, dentry->d_name.name);
  469. fhp->fh_dentry = dget(dentry); /* our internal copy */
  470. fhp->fh_export = exp;
  471. cache_get(&exp->h);
  472. if (version == 0xca) {
  473. /* old style filehandle please */
  474. memset(&fhp->fh_handle.fh_base, 0, NFS_FHSIZE);
  475. fhp->fh_handle.fh_size = NFS_FHSIZE;
  476. fhp->fh_handle.ofh_dcookie = 0xfeebbaca;
  477. fhp->fh_handle.ofh_dev = old_encode_dev(ex_dev);
  478. fhp->fh_handle.ofh_xdev = fhp->fh_handle.ofh_dev;
  479. fhp->fh_handle.ofh_xino =
  480. ino_t_to_u32(exp->ex_path.dentry->d_inode->i_ino);
  481. fhp->fh_handle.ofh_dirino = ino_t_to_u32(parent_ino(dentry));
  482. if (inode)
  483. _fh_update_old(dentry, exp, &fhp->fh_handle);
  484. } else {
  485. int len;
  486. fhp->fh_handle.fh_version = 1;
  487. fhp->fh_handle.fh_auth_type = 0;
  488. datap = fhp->fh_handle.fh_auth+0;
  489. fhp->fh_handle.fh_fsid_type = fsid_type;
  490. mk_fsid(fsid_type, datap, ex_dev,
  491. exp->ex_path.dentry->d_inode->i_ino,
  492. exp->ex_fsid, exp->ex_uuid);
  493. len = key_len(fsid_type);
  494. datap += len/4;
  495. fhp->fh_handle.fh_size = 4 + len;
  496. if (inode)
  497. _fh_update(fhp, exp, dentry);
  498. if (fhp->fh_handle.fh_fileid_type == 255)
  499. return nfserr_opnotsupp;
  500. }
  501. return 0;
  502. }
  503. /*
  504. * Update file handle information after changing a dentry.
  505. * This is only called by nfsd_create, nfsd_create_v3 and nfsd_proc_create
  506. */
  507. __be32
  508. fh_update(struct svc_fh *fhp)
  509. {
  510. struct dentry *dentry;
  511. if (!fhp->fh_dentry)
  512. goto out_bad;
  513. dentry = fhp->fh_dentry;
  514. if (!dentry->d_inode)
  515. goto out_negative;
  516. if (fhp->fh_handle.fh_version != 1) {
  517. _fh_update_old(dentry, fhp->fh_export, &fhp->fh_handle);
  518. } else {
  519. if (fhp->fh_handle.fh_fileid_type != FILEID_ROOT)
  520. goto out;
  521. _fh_update(fhp, fhp->fh_export, dentry);
  522. if (fhp->fh_handle.fh_fileid_type == 255)
  523. return nfserr_opnotsupp;
  524. }
  525. out:
  526. return 0;
  527. out_bad:
  528. printk(KERN_ERR "fh_update: fh not verified!\n");
  529. goto out;
  530. out_negative:
  531. printk(KERN_ERR "fh_update: %s/%s still negative!\n",
  532. dentry->d_parent->d_name.name, dentry->d_name.name);
  533. goto out;
  534. }
  535. /*
  536. * Release a file handle.
  537. */
  538. void
  539. fh_put(struct svc_fh *fhp)
  540. {
  541. struct dentry * dentry = fhp->fh_dentry;
  542. struct svc_export * exp = fhp->fh_export;
  543. if (dentry) {
  544. fh_unlock(fhp);
  545. fhp->fh_dentry = NULL;
  546. dput(dentry);
  547. #ifdef CONFIG_NFSD_V3
  548. fhp->fh_pre_saved = 0;
  549. fhp->fh_post_saved = 0;
  550. #endif
  551. }
  552. if (exp) {
  553. cache_put(&exp->h, &svc_export_cache);
  554. fhp->fh_export = NULL;
  555. }
  556. return;
  557. }
  558. /*
  559. * Shorthand for dprintk()'s
  560. */
  561. char * SVCFH_fmt(struct svc_fh *fhp)
  562. {
  563. struct knfsd_fh *fh = &fhp->fh_handle;
  564. static char buf[80];
  565. sprintf(buf, "%d: %08x %08x %08x %08x %08x %08x",
  566. fh->fh_size,
  567. fh->fh_base.fh_pad[0],
  568. fh->fh_base.fh_pad[1],
  569. fh->fh_base.fh_pad[2],
  570. fh->fh_base.fh_pad[3],
  571. fh->fh_base.fh_pad[4],
  572. fh->fh_base.fh_pad[5]);
  573. return buf;
  574. }
  575. enum fsid_source fsid_source(struct svc_fh *fhp)
  576. {
  577. if (fhp->fh_handle.fh_version != 1)
  578. return FSIDSOURCE_DEV;
  579. switch(fhp->fh_handle.fh_fsid_type) {
  580. case FSID_DEV:
  581. case FSID_ENCODE_DEV:
  582. case FSID_MAJOR_MINOR:
  583. if (fhp->fh_export->ex_path.dentry->d_inode->i_sb->s_type->fs_flags
  584. & FS_REQUIRES_DEV)
  585. return FSIDSOURCE_DEV;
  586. break;
  587. case FSID_NUM:
  588. if (fhp->fh_export->ex_flags & NFSEXP_FSID)
  589. return FSIDSOURCE_FSID;
  590. break;
  591. default:
  592. break;
  593. }
  594. /* either a UUID type filehandle, or the filehandle doesn't
  595. * match the export.
  596. */
  597. if (fhp->fh_export->ex_flags & NFSEXP_FSID)
  598. return FSIDSOURCE_FSID;
  599. if (fhp->fh_export->ex_uuid)
  600. return FSIDSOURCE_UUID;
  601. return FSIDSOURCE_DEV;
  602. }