nfsfh.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  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(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: %pd2\n",
  232. dentry);
  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: %pd2 permission failure, "
  330. "acc=%x, error=%d\n",
  331. dentry,
  332. access, ntohl(error));
  333. }
  334. out:
  335. if (error == nfserr_stale)
  336. nfsdstats.fh_stale++;
  337. return error;
  338. }
  339. /*
  340. * Compose a file handle for an NFS reply.
  341. *
  342. * Note that when first composed, the dentry may not yet have
  343. * an inode. In this case a call to fh_update should be made
  344. * before the fh goes out on the wire ...
  345. */
  346. static void _fh_update(struct svc_fh *fhp, struct svc_export *exp,
  347. struct dentry *dentry)
  348. {
  349. if (dentry != exp->ex_path.dentry) {
  350. struct fid *fid = (struct fid *)
  351. (fhp->fh_handle.fh_auth + fhp->fh_handle.fh_size/4 - 1);
  352. int maxsize = (fhp->fh_maxsize - fhp->fh_handle.fh_size)/4;
  353. int subtreecheck = !(exp->ex_flags & NFSEXP_NOSUBTREECHECK);
  354. fhp->fh_handle.fh_fileid_type =
  355. exportfs_encode_fh(dentry, fid, &maxsize, subtreecheck);
  356. fhp->fh_handle.fh_size += maxsize * 4;
  357. } else {
  358. fhp->fh_handle.fh_fileid_type = FILEID_ROOT;
  359. }
  360. }
  361. /*
  362. * for composing old style file handles
  363. */
  364. static inline void _fh_update_old(struct dentry *dentry,
  365. struct svc_export *exp,
  366. struct knfsd_fh *fh)
  367. {
  368. fh->ofh_ino = ino_t_to_u32(dentry->d_inode->i_ino);
  369. fh->ofh_generation = dentry->d_inode->i_generation;
  370. if (S_ISDIR(dentry->d_inode->i_mode) ||
  371. (exp->ex_flags & NFSEXP_NOSUBTREECHECK))
  372. fh->ofh_dirino = 0;
  373. }
  374. static bool is_root_export(struct svc_export *exp)
  375. {
  376. return exp->ex_path.dentry == exp->ex_path.dentry->d_sb->s_root;
  377. }
  378. static struct super_block *exp_sb(struct svc_export *exp)
  379. {
  380. return exp->ex_path.dentry->d_inode->i_sb;
  381. }
  382. static bool fsid_type_ok_for_exp(u8 fsid_type, struct svc_export *exp)
  383. {
  384. switch (fsid_type) {
  385. case FSID_DEV:
  386. if (!old_valid_dev(exp_sb(exp)->s_dev))
  387. return 0;
  388. /* FALL THROUGH */
  389. case FSID_MAJOR_MINOR:
  390. case FSID_ENCODE_DEV:
  391. return exp_sb(exp)->s_type->fs_flags & FS_REQUIRES_DEV;
  392. case FSID_NUM:
  393. return exp->ex_flags & NFSEXP_FSID;
  394. case FSID_UUID8:
  395. case FSID_UUID16:
  396. if (!is_root_export(exp))
  397. return 0;
  398. /* fall through */
  399. case FSID_UUID4_INUM:
  400. case FSID_UUID16_INUM:
  401. return exp->ex_uuid != NULL;
  402. }
  403. return 1;
  404. }
  405. static void set_version_and_fsid_type(struct svc_fh *fhp, struct svc_export *exp, struct svc_fh *ref_fh)
  406. {
  407. u8 version;
  408. u8 fsid_type;
  409. retry:
  410. version = 1;
  411. if (ref_fh && ref_fh->fh_export == exp) {
  412. version = ref_fh->fh_handle.fh_version;
  413. fsid_type = ref_fh->fh_handle.fh_fsid_type;
  414. ref_fh = NULL;
  415. switch (version) {
  416. case 0xca:
  417. fsid_type = FSID_DEV;
  418. break;
  419. case 1:
  420. break;
  421. default:
  422. goto retry;
  423. }
  424. /*
  425. * As the fsid -> filesystem mapping was guided by
  426. * user-space, there is no guarantee that the filesystem
  427. * actually supports that fsid type. If it doesn't we
  428. * loop around again without ref_fh set.
  429. */
  430. if (!fsid_type_ok_for_exp(fsid_type, exp))
  431. goto retry;
  432. } else if (exp->ex_flags & NFSEXP_FSID) {
  433. fsid_type = FSID_NUM;
  434. } else if (exp->ex_uuid) {
  435. if (fhp->fh_maxsize >= 64) {
  436. if (is_root_export(exp))
  437. fsid_type = FSID_UUID16;
  438. else
  439. fsid_type = FSID_UUID16_INUM;
  440. } else {
  441. if (is_root_export(exp))
  442. fsid_type = FSID_UUID8;
  443. else
  444. fsid_type = FSID_UUID4_INUM;
  445. }
  446. } else if (!old_valid_dev(exp_sb(exp)->s_dev))
  447. /* for newer device numbers, we must use a newer fsid format */
  448. fsid_type = FSID_ENCODE_DEV;
  449. else
  450. fsid_type = FSID_DEV;
  451. fhp->fh_handle.fh_version = version;
  452. if (version)
  453. fhp->fh_handle.fh_fsid_type = fsid_type;
  454. }
  455. __be32
  456. fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry,
  457. struct svc_fh *ref_fh)
  458. {
  459. /* ref_fh is a reference file handle.
  460. * if it is non-null and for the same filesystem, then we should compose
  461. * a filehandle which is of the same version, where possible.
  462. * Currently, that means that if ref_fh->fh_handle.fh_version == 0xca
  463. * Then create a 32byte filehandle using nfs_fhbase_old
  464. *
  465. */
  466. struct inode * inode = dentry->d_inode;
  467. __u32 *datap;
  468. dev_t ex_dev = exp_sb(exp)->s_dev;
  469. dprintk("nfsd: fh_compose(exp %02x:%02x/%ld %pd2, ino=%ld)\n",
  470. MAJOR(ex_dev), MINOR(ex_dev),
  471. (long) exp->ex_path.dentry->d_inode->i_ino,
  472. dentry,
  473. (inode ? inode->i_ino : 0));
  474. /* Choose filehandle version and fsid type based on
  475. * the reference filehandle (if it is in the same export)
  476. * or the export options.
  477. */
  478. set_version_and_fsid_type(fhp, exp, ref_fh);
  479. if (ref_fh == fhp)
  480. fh_put(ref_fh);
  481. if (fhp->fh_locked || fhp->fh_dentry) {
  482. printk(KERN_ERR "fh_compose: fh %pd2 not initialized!\n",
  483. dentry);
  484. }
  485. if (fhp->fh_maxsize < NFS_FHSIZE)
  486. printk(KERN_ERR "fh_compose: called with maxsize %d! %pd2\n",
  487. fhp->fh_maxsize,
  488. dentry);
  489. fhp->fh_dentry = dget(dentry); /* our internal copy */
  490. fhp->fh_export = exp;
  491. cache_get(&exp->h);
  492. if (fhp->fh_handle.fh_version == 0xca) {
  493. /* old style filehandle please */
  494. memset(&fhp->fh_handle.fh_base, 0, NFS_FHSIZE);
  495. fhp->fh_handle.fh_size = NFS_FHSIZE;
  496. fhp->fh_handle.ofh_dcookie = 0xfeebbaca;
  497. fhp->fh_handle.ofh_dev = old_encode_dev(ex_dev);
  498. fhp->fh_handle.ofh_xdev = fhp->fh_handle.ofh_dev;
  499. fhp->fh_handle.ofh_xino =
  500. ino_t_to_u32(exp->ex_path.dentry->d_inode->i_ino);
  501. fhp->fh_handle.ofh_dirino = ino_t_to_u32(parent_ino(dentry));
  502. if (inode)
  503. _fh_update_old(dentry, exp, &fhp->fh_handle);
  504. } else {
  505. int len;
  506. fhp->fh_handle.fh_auth_type = 0;
  507. datap = fhp->fh_handle.fh_auth+0;
  508. mk_fsid(fhp->fh_handle.fh_fsid_type, datap, ex_dev,
  509. exp->ex_path.dentry->d_inode->i_ino,
  510. exp->ex_fsid, exp->ex_uuid);
  511. len = key_len(fhp->fh_handle.fh_fsid_type);
  512. datap += len/4;
  513. fhp->fh_handle.fh_size = 4 + len;
  514. if (inode)
  515. _fh_update(fhp, exp, dentry);
  516. if (fhp->fh_handle.fh_fileid_type == FILEID_INVALID) {
  517. fh_put(fhp);
  518. return nfserr_opnotsupp;
  519. }
  520. }
  521. return 0;
  522. }
  523. /*
  524. * Update file handle information after changing a dentry.
  525. * This is only called by nfsd_create, nfsd_create_v3 and nfsd_proc_create
  526. */
  527. __be32
  528. fh_update(struct svc_fh *fhp)
  529. {
  530. struct dentry *dentry;
  531. if (!fhp->fh_dentry)
  532. goto out_bad;
  533. dentry = fhp->fh_dentry;
  534. if (!dentry->d_inode)
  535. goto out_negative;
  536. if (fhp->fh_handle.fh_version != 1) {
  537. _fh_update_old(dentry, fhp->fh_export, &fhp->fh_handle);
  538. } else {
  539. if (fhp->fh_handle.fh_fileid_type != FILEID_ROOT)
  540. return 0;
  541. _fh_update(fhp, fhp->fh_export, dentry);
  542. if (fhp->fh_handle.fh_fileid_type == FILEID_INVALID)
  543. return nfserr_opnotsupp;
  544. }
  545. return 0;
  546. out_bad:
  547. printk(KERN_ERR "fh_update: fh not verified!\n");
  548. return nfserr_serverfault;
  549. out_negative:
  550. printk(KERN_ERR "fh_update: %pd2 still negative!\n",
  551. dentry);
  552. return nfserr_serverfault;
  553. }
  554. /*
  555. * Release a file handle.
  556. */
  557. void
  558. fh_put(struct svc_fh *fhp)
  559. {
  560. struct dentry * dentry = fhp->fh_dentry;
  561. struct svc_export * exp = fhp->fh_export;
  562. if (dentry) {
  563. fh_unlock(fhp);
  564. fhp->fh_dentry = NULL;
  565. dput(dentry);
  566. #ifdef CONFIG_NFSD_V3
  567. fhp->fh_pre_saved = 0;
  568. fhp->fh_post_saved = 0;
  569. #endif
  570. }
  571. fh_drop_write(fhp);
  572. if (exp) {
  573. exp_put(exp);
  574. fhp->fh_export = NULL;
  575. }
  576. return;
  577. }
  578. /*
  579. * Shorthand for dprintk()'s
  580. */
  581. char * SVCFH_fmt(struct svc_fh *fhp)
  582. {
  583. struct knfsd_fh *fh = &fhp->fh_handle;
  584. static char buf[80];
  585. sprintf(buf, "%d: %08x %08x %08x %08x %08x %08x",
  586. fh->fh_size,
  587. fh->fh_base.fh_pad[0],
  588. fh->fh_base.fh_pad[1],
  589. fh->fh_base.fh_pad[2],
  590. fh->fh_base.fh_pad[3],
  591. fh->fh_base.fh_pad[4],
  592. fh->fh_base.fh_pad[5]);
  593. return buf;
  594. }
  595. enum fsid_source fsid_source(struct svc_fh *fhp)
  596. {
  597. if (fhp->fh_handle.fh_version != 1)
  598. return FSIDSOURCE_DEV;
  599. switch(fhp->fh_handle.fh_fsid_type) {
  600. case FSID_DEV:
  601. case FSID_ENCODE_DEV:
  602. case FSID_MAJOR_MINOR:
  603. if (exp_sb(fhp->fh_export)->s_type->fs_flags & FS_REQUIRES_DEV)
  604. return FSIDSOURCE_DEV;
  605. break;
  606. case FSID_NUM:
  607. if (fhp->fh_export->ex_flags & NFSEXP_FSID)
  608. return FSIDSOURCE_FSID;
  609. break;
  610. default:
  611. break;
  612. }
  613. /* either a UUID type filehandle, or the filehandle doesn't
  614. * match the export.
  615. */
  616. if (fhp->fh_export->ex_flags & NFSEXP_FSID)
  617. return FSIDSOURCE_FSID;
  618. if (fhp->fh_export->ex_uuid)
  619. return FSIDSOURCE_UUID;
  620. return FSIDSOURCE_DEV;
  621. }