nfsfh.c 18 KB

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