nfsfh.c 18 KB

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