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