nfsfh.c 18 KB

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