nfsfh.c 18 KB

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