nfsfh.c 17 KB

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