nfsfh.c 18 KB

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