nfsfh.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. /*
  2. * linux/fs/nfsd/nfsfh.c
  3. *
  4. * NFS server file handle treatment.
  5. *
  6. * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
  7. * Portions Copyright (C) 1999 G. Allen Morris III <gam3@acm.org>
  8. * Extensive rewrite by Neil Brown <neilb@cse.unsw.edu.au> Southern-Spring 1999
  9. * ... and again Southern-Winter 2001 to support export_operations
  10. */
  11. #include <linux/slab.h>
  12. #include <linux/fs.h>
  13. #include <linux/unistd.h>
  14. #include <linux/string.h>
  15. #include <linux/stat.h>
  16. #include <linux/dcache.h>
  17. #include <linux/exportfs.h>
  18. #include <linux/mount.h>
  19. #include <linux/sunrpc/clnt.h>
  20. #include <linux/sunrpc/svc.h>
  21. #include <linux/sunrpc/svcauth_gss.h>
  22. #include <linux/nfsd/nfsd.h>
  23. #include "auth.h"
  24. #define NFSDDBG_FACILITY NFSDDBG_FH
  25. /*
  26. * our acceptability function.
  27. * if NOSUBTREECHECK, accept anything
  28. * if not, require that we can walk up to exp->ex_dentry
  29. * doing some checks on the 'x' bits
  30. */
  31. static int nfsd_acceptable(void *expv, struct dentry *dentry)
  32. {
  33. struct svc_export *exp = expv;
  34. int rv;
  35. struct dentry *tdentry;
  36. struct dentry *parent;
  37. if (exp->ex_flags & NFSEXP_NOSUBTREECHECK)
  38. return 1;
  39. tdentry = dget(dentry);
  40. while (tdentry != exp->ex_path.dentry && !IS_ROOT(tdentry)) {
  41. /* make sure parents give x permission to user */
  42. int err;
  43. parent = dget_parent(tdentry);
  44. err = inode_permission(parent->d_inode, MAY_EXEC);
  45. if (err < 0) {
  46. dput(parent);
  47. break;
  48. }
  49. dput(tdentry);
  50. tdentry = parent;
  51. }
  52. if (tdentry != exp->ex_path.dentry)
  53. dprintk("nfsd_acceptable failed at %p %s\n", tdentry, tdentry->d_name.name);
  54. rv = (tdentry == exp->ex_path.dentry);
  55. dput(tdentry);
  56. return rv;
  57. }
  58. /* Type check. The correct error return for type mismatches does not seem to be
  59. * generally agreed upon. SunOS seems to use EISDIR if file isn't S_IFREG; a
  60. * comment in the NFSv3 spec says this is incorrect (implementation notes for
  61. * the write call).
  62. */
  63. static inline __be32
  64. nfsd_mode_check(struct svc_rqst *rqstp, umode_t mode, int type)
  65. {
  66. /* Type can be negative when creating hardlinks - not to a dir */
  67. if (type > 0 && (mode & S_IFMT) != type) {
  68. if (rqstp->rq_vers == 4 && (mode & S_IFMT) == S_IFLNK)
  69. return nfserr_symlink;
  70. else if (type == S_IFDIR)
  71. return nfserr_notdir;
  72. else if ((mode & S_IFMT) == S_IFDIR)
  73. return nfserr_isdir;
  74. else
  75. return nfserr_inval;
  76. }
  77. if (type < 0 && (mode & S_IFMT) == -type) {
  78. if (rqstp->rq_vers == 4 && (mode & S_IFMT) == S_IFLNK)
  79. return nfserr_symlink;
  80. else if (type == -S_IFDIR)
  81. return nfserr_isdir;
  82. else
  83. return nfserr_notdir;
  84. }
  85. return 0;
  86. }
  87. static __be32 nfsd_setuser_and_check_port(struct svc_rqst *rqstp,
  88. struct svc_export *exp)
  89. {
  90. /* Check if the request originated from a secure port. */
  91. if (!rqstp->rq_secure && EX_SECURE(exp)) {
  92. RPC_IFDEBUG(char buf[RPC_MAX_ADDRBUFLEN]);
  93. dprintk(KERN_WARNING
  94. "nfsd: request from insecure port %s!\n",
  95. svc_print_addr(rqstp, buf, sizeof(buf)));
  96. return nfserr_perm;
  97. }
  98. /* Set user creds for this exportpoint */
  99. return nfserrno(nfsd_setuser(rqstp, exp));
  100. }
  101. /*
  102. * Use the given filehandle to look up the corresponding export and
  103. * dentry. On success, the results are used to set fh_export and
  104. * fh_dentry.
  105. */
  106. static __be32 nfsd_set_fh_dentry(struct svc_rqst *rqstp, struct svc_fh *fhp)
  107. {
  108. struct knfsd_fh *fh = &fhp->fh_handle;
  109. struct fid *fid = NULL, sfid;
  110. struct svc_export *exp;
  111. struct dentry *dentry;
  112. int fileid_type;
  113. int data_left = fh->fh_size/4;
  114. __be32 error;
  115. error = nfserr_stale;
  116. if (rqstp->rq_vers > 2)
  117. error = nfserr_badhandle;
  118. if (rqstp->rq_vers == 4 && fh->fh_size == 0)
  119. return nfserr_nofilehandle;
  120. if (fh->fh_version == 1) {
  121. int len;
  122. if (--data_left < 0)
  123. return error;
  124. if (fh->fh_auth_type != 0)
  125. return error;
  126. len = key_len(fh->fh_fsid_type) / 4;
  127. if (len == 0)
  128. return error;
  129. if (fh->fh_fsid_type == FSID_MAJOR_MINOR) {
  130. /* deprecated, convert to type 3 */
  131. len = key_len(FSID_ENCODE_DEV)/4;
  132. fh->fh_fsid_type = FSID_ENCODE_DEV;
  133. fh->fh_fsid[0] = new_encode_dev(MKDEV(ntohl(fh->fh_fsid[0]), ntohl(fh->fh_fsid[1])));
  134. fh->fh_fsid[1] = fh->fh_fsid[2];
  135. }
  136. data_left -= len;
  137. if (data_left < 0)
  138. return error;
  139. exp = rqst_exp_find(rqstp, fh->fh_fsid_type, fh->fh_auth);
  140. fid = (struct fid *)(fh->fh_auth + len);
  141. } else {
  142. __u32 tfh[2];
  143. dev_t xdev;
  144. ino_t xino;
  145. if (fh->fh_size != NFS_FHSIZE)
  146. return error;
  147. /* assume old filehandle format */
  148. xdev = old_decode_dev(fh->ofh_xdev);
  149. xino = u32_to_ino_t(fh->ofh_xino);
  150. mk_fsid(FSID_DEV, tfh, xdev, xino, 0, NULL);
  151. exp = rqst_exp_find(rqstp, FSID_DEV, tfh);
  152. }
  153. error = nfserr_stale;
  154. if (PTR_ERR(exp) == -ENOENT)
  155. return error;
  156. if (IS_ERR(exp))
  157. return nfserrno(PTR_ERR(exp));
  158. if (exp->ex_flags & NFSEXP_NOSUBTREECHECK) {
  159. /* Elevate privileges so that the lack of 'r' or 'x'
  160. * permission on some parent directory will
  161. * not stop exportfs_decode_fh from being able
  162. * to reconnect a directory into the dentry cache.
  163. * The same problem can affect "SUBTREECHECK" exports,
  164. * but as nfsd_acceptable depends on correct
  165. * access control settings being in effect, we cannot
  166. * fix that case easily.
  167. */
  168. struct cred *new = prepare_creds();
  169. if (!new)
  170. return nfserrno(-ENOMEM);
  171. new->cap_effective =
  172. cap_raise_nfsd_set(new->cap_effective,
  173. new->cap_permitted);
  174. put_cred(override_creds(new));
  175. put_cred(new);
  176. } else {
  177. error = nfsd_setuser_and_check_port(rqstp, exp);
  178. if (error)
  179. goto out;
  180. }
  181. /*
  182. * Look up the dentry using the NFS file handle.
  183. */
  184. error = nfserr_stale;
  185. if (rqstp->rq_vers > 2)
  186. error = nfserr_badhandle;
  187. if (fh->fh_version != 1) {
  188. sfid.i32.ino = fh->ofh_ino;
  189. sfid.i32.gen = fh->ofh_generation;
  190. sfid.i32.parent_ino = fh->ofh_dirino;
  191. fid = &sfid;
  192. data_left = 3;
  193. if (fh->ofh_dirino == 0)
  194. fileid_type = FILEID_INO32_GEN;
  195. else
  196. fileid_type = FILEID_INO32_GEN_PARENT;
  197. } else
  198. fileid_type = fh->fh_fileid_type;
  199. if (fileid_type == FILEID_ROOT)
  200. dentry = dget(exp->ex_path.dentry);
  201. else {
  202. dentry = exportfs_decode_fh(exp->ex_path.mnt, fid,
  203. data_left, fileid_type,
  204. nfsd_acceptable, exp);
  205. }
  206. if (dentry == NULL)
  207. goto out;
  208. if (IS_ERR(dentry)) {
  209. if (PTR_ERR(dentry) != -EINVAL)
  210. error = nfserrno(PTR_ERR(dentry));
  211. goto out;
  212. }
  213. if (exp->ex_flags & NFSEXP_NOSUBTREECHECK) {
  214. error = nfsd_setuser_and_check_port(rqstp, exp);
  215. if (error) {
  216. dput(dentry);
  217. goto out;
  218. }
  219. }
  220. if (S_ISDIR(dentry->d_inode->i_mode) &&
  221. (dentry->d_flags & DCACHE_DISCONNECTED)) {
  222. printk("nfsd: find_fh_dentry returned a DISCONNECTED directory: %s/%s\n",
  223. dentry->d_parent->d_name.name, dentry->d_name.name);
  224. }
  225. fhp->fh_dentry = dentry;
  226. fhp->fh_export = exp;
  227. return 0;
  228. out:
  229. exp_put(exp);
  230. return error;
  231. }
  232. /**
  233. * fh_verify - filehandle lookup and access checking
  234. * @rqstp: pointer to current rpc request
  235. * @fhp: filehandle to be verified
  236. * @type: expected type of object pointed to by filehandle
  237. * @access: type of access needed to object
  238. *
  239. * Look up a dentry from the on-the-wire filehandle, check the client's
  240. * access to the export, and set the current task's credentials.
  241. *
  242. * Regardless of success or failure of fh_verify(), fh_put() should be
  243. * called on @fhp when the caller is finished with the filehandle.
  244. *
  245. * fh_verify() may be called multiple times on a given filehandle, for
  246. * example, when processing an NFSv4 compound. The first call will look
  247. * up a dentry using the on-the-wire filehandle. Subsequent calls will
  248. * skip the lookup and just perform the other checks and possibly change
  249. * the current task's credentials.
  250. *
  251. * @type specifies the type of object expected using one of the S_IF*
  252. * constants defined in include/linux/stat.h. The caller may use zero
  253. * to indicate that it doesn't care, or a negative integer to indicate
  254. * that it expects something not of the given type.
  255. *
  256. * @access is formed from the NFSD_MAY_* constants defined in
  257. * include/linux/nfsd/nfsd.h.
  258. */
  259. __be32
  260. fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, int access)
  261. {
  262. struct svc_export *exp;
  263. struct dentry *dentry;
  264. __be32 error;
  265. dprintk("nfsd: fh_verify(%s)\n", SVCFH_fmt(fhp));
  266. if (!fhp->fh_dentry) {
  267. error = nfsd_set_fh_dentry(rqstp, fhp);
  268. if (error)
  269. goto out;
  270. dentry = fhp->fh_dentry;
  271. exp = fhp->fh_export;
  272. } else {
  273. /*
  274. * just rechecking permissions
  275. * (e.g. nfsproc_create calls fh_verify, then nfsd_create
  276. * does as well)
  277. */
  278. dprintk("nfsd: fh_verify - just checking\n");
  279. dentry = fhp->fh_dentry;
  280. exp = fhp->fh_export;
  281. /*
  282. * Set user creds for this exportpoint; necessary even
  283. * in the "just checking" case because this may be a
  284. * filehandle that was created by fh_compose, and that
  285. * is about to be used in another nfsv4 compound
  286. * operation.
  287. */
  288. error = nfsd_setuser_and_check_port(rqstp, exp);
  289. if (error)
  290. goto out;
  291. }
  292. error = nfsd_mode_check(rqstp, dentry->d_inode->i_mode, type);
  293. if (error)
  294. goto out;
  295. /*
  296. * pseudoflavor restrictions are not enforced on NLM,
  297. * which clients virtually always use auth_sys for,
  298. * even while using RPCSEC_GSS for NFS.
  299. */
  300. if (access & NFSD_MAY_LOCK)
  301. goto skip_pseudoflavor_check;
  302. /*
  303. * Clients may expect to be able to use auth_sys during mount,
  304. * even if they use gss for everything else; see section 2.3.2
  305. * of rfc 2623.
  306. */
  307. if (access & NFSD_MAY_BYPASS_GSS_ON_ROOT
  308. && exp->ex_path.dentry == dentry)
  309. goto skip_pseudoflavor_check;
  310. error = check_nfsd_access(exp, rqstp);
  311. if (error)
  312. goto out;
  313. skip_pseudoflavor_check:
  314. /* Finally, check access permissions. */
  315. error = nfsd_permission(rqstp, exp, dentry, access);
  316. if (error) {
  317. dprintk("fh_verify: %s/%s permission failure, "
  318. "acc=%x, error=%d\n",
  319. dentry->d_parent->d_name.name,
  320. dentry->d_name.name,
  321. access, ntohl(error));
  322. }
  323. out:
  324. if (error == nfserr_stale)
  325. nfsdstats.fh_stale++;
  326. return error;
  327. }
  328. /*
  329. * Compose a file handle for an NFS reply.
  330. *
  331. * Note that when first composed, the dentry may not yet have
  332. * an inode. In this case a call to fh_update should be made
  333. * before the fh goes out on the wire ...
  334. */
  335. static void _fh_update(struct svc_fh *fhp, struct svc_export *exp,
  336. struct dentry *dentry)
  337. {
  338. if (dentry != exp->ex_path.dentry) {
  339. struct fid *fid = (struct fid *)
  340. (fhp->fh_handle.fh_auth + fhp->fh_handle.fh_size/4 - 1);
  341. int maxsize = (fhp->fh_maxsize - fhp->fh_handle.fh_size)/4;
  342. int subtreecheck = !(exp->ex_flags & NFSEXP_NOSUBTREECHECK);
  343. fhp->fh_handle.fh_fileid_type =
  344. exportfs_encode_fh(dentry, fid, &maxsize, subtreecheck);
  345. fhp->fh_handle.fh_size += maxsize * 4;
  346. } else {
  347. fhp->fh_handle.fh_fileid_type = FILEID_ROOT;
  348. }
  349. }
  350. /*
  351. * for composing old style file handles
  352. */
  353. static inline void _fh_update_old(struct dentry *dentry,
  354. struct svc_export *exp,
  355. struct knfsd_fh *fh)
  356. {
  357. fh->ofh_ino = ino_t_to_u32(dentry->d_inode->i_ino);
  358. fh->ofh_generation = dentry->d_inode->i_generation;
  359. if (S_ISDIR(dentry->d_inode->i_mode) ||
  360. (exp->ex_flags & NFSEXP_NOSUBTREECHECK))
  361. fh->ofh_dirino = 0;
  362. }
  363. static bool is_root_export(struct svc_export *exp)
  364. {
  365. return exp->ex_path.dentry == exp->ex_path.dentry->d_sb->s_root;
  366. }
  367. static struct super_block *exp_sb(struct svc_export *exp)
  368. {
  369. return exp->ex_path.dentry->d_inode->i_sb;
  370. }
  371. static bool fsid_type_ok_for_exp(u8 fsid_type, struct svc_export *exp)
  372. {
  373. switch (fsid_type) {
  374. case FSID_DEV:
  375. if (!old_valid_dev(exp_sb(exp)->s_dev))
  376. return 0;
  377. /* FALL THROUGH */
  378. case FSID_MAJOR_MINOR:
  379. case FSID_ENCODE_DEV:
  380. return exp_sb(exp)->s_type->fs_flags & FS_REQUIRES_DEV;
  381. case FSID_NUM:
  382. return exp->ex_flags & NFSEXP_FSID;
  383. case FSID_UUID8:
  384. case FSID_UUID16:
  385. if (!is_root_export(exp))
  386. return 0;
  387. /* fall through */
  388. case FSID_UUID4_INUM:
  389. case FSID_UUID16_INUM:
  390. return exp->ex_uuid != NULL;
  391. }
  392. return 1;
  393. }
  394. static void set_version_and_fsid_type(struct svc_fh *fhp, struct svc_export *exp, struct svc_fh *ref_fh)
  395. {
  396. u8 version;
  397. u8 fsid_type;
  398. retry:
  399. version = 1;
  400. if (ref_fh && ref_fh->fh_export == exp) {
  401. version = ref_fh->fh_handle.fh_version;
  402. fsid_type = ref_fh->fh_handle.fh_fsid_type;
  403. ref_fh = NULL;
  404. switch (version) {
  405. case 0xca:
  406. fsid_type = FSID_DEV;
  407. break;
  408. case 1:
  409. break;
  410. default:
  411. goto retry;
  412. }
  413. /*
  414. * As the fsid -> filesystem mapping was guided by
  415. * user-space, there is no guarantee that the filesystem
  416. * actually supports that fsid type. If it doesn't we
  417. * loop around again without ref_fh set.
  418. */
  419. if (!fsid_type_ok_for_exp(fsid_type, exp))
  420. goto retry;
  421. } else if (exp->ex_flags & NFSEXP_FSID) {
  422. fsid_type = FSID_NUM;
  423. } else if (exp->ex_uuid) {
  424. if (fhp->fh_maxsize >= 64) {
  425. if (is_root_export(exp))
  426. fsid_type = FSID_UUID16;
  427. else
  428. fsid_type = FSID_UUID16_INUM;
  429. } else {
  430. if (is_root_export(exp))
  431. fsid_type = FSID_UUID8;
  432. else
  433. fsid_type = FSID_UUID4_INUM;
  434. }
  435. } else if (!old_valid_dev(exp_sb(exp)->s_dev))
  436. /* for newer device numbers, we must use a newer fsid format */
  437. fsid_type = FSID_ENCODE_DEV;
  438. else
  439. fsid_type = FSID_DEV;
  440. fhp->fh_handle.fh_version = version;
  441. if (version)
  442. fhp->fh_handle.fh_fsid_type = fsid_type;
  443. }
  444. __be32
  445. fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry,
  446. struct svc_fh *ref_fh)
  447. {
  448. /* ref_fh is a reference file handle.
  449. * if it is non-null and for the same filesystem, then we should compose
  450. * a filehandle which is of the same version, where possible.
  451. * Currently, that means that if ref_fh->fh_handle.fh_version == 0xca
  452. * Then create a 32byte filehandle using nfs_fhbase_old
  453. *
  454. */
  455. struct inode * inode = dentry->d_inode;
  456. struct dentry *parent = dentry->d_parent;
  457. __u32 *datap;
  458. dev_t ex_dev = exp_sb(exp)->s_dev;
  459. dprintk("nfsd: fh_compose(exp %02x:%02x/%ld %s/%s, ino=%ld)\n",
  460. MAJOR(ex_dev), MINOR(ex_dev),
  461. (long) exp->ex_path.dentry->d_inode->i_ino,
  462. parent->d_name.name, dentry->d_name.name,
  463. (inode ? inode->i_ino : 0));
  464. /* Choose filehandle version and fsid type based on
  465. * the reference filehandle (if it is in the same export)
  466. * or the export options.
  467. */
  468. set_version_and_fsid_type(fhp, exp, ref_fh);
  469. if (ref_fh == fhp)
  470. fh_put(ref_fh);
  471. if (fhp->fh_locked || fhp->fh_dentry) {
  472. printk(KERN_ERR "fh_compose: fh %s/%s not initialized!\n",
  473. parent->d_name.name, dentry->d_name.name);
  474. }
  475. if (fhp->fh_maxsize < NFS_FHSIZE)
  476. printk(KERN_ERR "fh_compose: called with maxsize %d! %s/%s\n",
  477. fhp->fh_maxsize,
  478. parent->d_name.name, dentry->d_name.name);
  479. fhp->fh_dentry = dget(dentry); /* our internal copy */
  480. fhp->fh_export = exp;
  481. cache_get(&exp->h);
  482. if (fhp->fh_handle.fh_version == 0xca) {
  483. /* old style filehandle please */
  484. memset(&fhp->fh_handle.fh_base, 0, NFS_FHSIZE);
  485. fhp->fh_handle.fh_size = NFS_FHSIZE;
  486. fhp->fh_handle.ofh_dcookie = 0xfeebbaca;
  487. fhp->fh_handle.ofh_dev = old_encode_dev(ex_dev);
  488. fhp->fh_handle.ofh_xdev = fhp->fh_handle.ofh_dev;
  489. fhp->fh_handle.ofh_xino =
  490. ino_t_to_u32(exp->ex_path.dentry->d_inode->i_ino);
  491. fhp->fh_handle.ofh_dirino = ino_t_to_u32(parent_ino(dentry));
  492. if (inode)
  493. _fh_update_old(dentry, exp, &fhp->fh_handle);
  494. } else {
  495. int len;
  496. fhp->fh_handle.fh_auth_type = 0;
  497. datap = fhp->fh_handle.fh_auth+0;
  498. mk_fsid(fhp->fh_handle.fh_fsid_type, datap, ex_dev,
  499. exp->ex_path.dentry->d_inode->i_ino,
  500. exp->ex_fsid, exp->ex_uuid);
  501. len = key_len(fhp->fh_handle.fh_fsid_type);
  502. datap += len/4;
  503. fhp->fh_handle.fh_size = 4 + len;
  504. if (inode)
  505. _fh_update(fhp, exp, dentry);
  506. if (fhp->fh_handle.fh_fileid_type == 255) {
  507. fh_put(fhp);
  508. return nfserr_opnotsupp;
  509. }
  510. }
  511. return 0;
  512. }
  513. /*
  514. * Update file handle information after changing a dentry.
  515. * This is only called by nfsd_create, nfsd_create_v3 and nfsd_proc_create
  516. */
  517. __be32
  518. fh_update(struct svc_fh *fhp)
  519. {
  520. struct dentry *dentry;
  521. if (!fhp->fh_dentry)
  522. goto out_bad;
  523. dentry = fhp->fh_dentry;
  524. if (!dentry->d_inode)
  525. goto out_negative;
  526. if (fhp->fh_handle.fh_version != 1) {
  527. _fh_update_old(dentry, fhp->fh_export, &fhp->fh_handle);
  528. } else {
  529. if (fhp->fh_handle.fh_fileid_type != FILEID_ROOT)
  530. goto out;
  531. _fh_update(fhp, fhp->fh_export, dentry);
  532. if (fhp->fh_handle.fh_fileid_type == 255)
  533. return nfserr_opnotsupp;
  534. }
  535. out:
  536. return 0;
  537. out_bad:
  538. printk(KERN_ERR "fh_update: fh not verified!\n");
  539. goto out;
  540. out_negative:
  541. printk(KERN_ERR "fh_update: %s/%s still negative!\n",
  542. dentry->d_parent->d_name.name, dentry->d_name.name);
  543. goto out;
  544. }
  545. /*
  546. * Release a file handle.
  547. */
  548. void
  549. fh_put(struct svc_fh *fhp)
  550. {
  551. struct dentry * dentry = fhp->fh_dentry;
  552. struct svc_export * exp = fhp->fh_export;
  553. if (dentry) {
  554. fh_unlock(fhp);
  555. fhp->fh_dentry = NULL;
  556. dput(dentry);
  557. #ifdef CONFIG_NFSD_V3
  558. fhp->fh_pre_saved = 0;
  559. fhp->fh_post_saved = 0;
  560. #endif
  561. }
  562. if (exp) {
  563. cache_put(&exp->h, &svc_export_cache);
  564. fhp->fh_export = NULL;
  565. }
  566. return;
  567. }
  568. /*
  569. * Shorthand for dprintk()'s
  570. */
  571. char * SVCFH_fmt(struct svc_fh *fhp)
  572. {
  573. struct knfsd_fh *fh = &fhp->fh_handle;
  574. static char buf[80];
  575. sprintf(buf, "%d: %08x %08x %08x %08x %08x %08x",
  576. fh->fh_size,
  577. fh->fh_base.fh_pad[0],
  578. fh->fh_base.fh_pad[1],
  579. fh->fh_base.fh_pad[2],
  580. fh->fh_base.fh_pad[3],
  581. fh->fh_base.fh_pad[4],
  582. fh->fh_base.fh_pad[5]);
  583. return buf;
  584. }
  585. enum fsid_source fsid_source(struct svc_fh *fhp)
  586. {
  587. if (fhp->fh_handle.fh_version != 1)
  588. return FSIDSOURCE_DEV;
  589. switch(fhp->fh_handle.fh_fsid_type) {
  590. case FSID_DEV:
  591. case FSID_ENCODE_DEV:
  592. case FSID_MAJOR_MINOR:
  593. if (exp_sb(fhp->fh_export)->s_type->fs_flags & FS_REQUIRES_DEV)
  594. return FSIDSOURCE_DEV;
  595. break;
  596. case FSID_NUM:
  597. if (fhp->fh_export->ex_flags & NFSEXP_FSID)
  598. return FSIDSOURCE_FSID;
  599. break;
  600. default:
  601. break;
  602. }
  603. /* either a UUID type filehandle, or the filehandle doesn't
  604. * match the export.
  605. */
  606. if (fhp->fh_export->ex_flags & NFSEXP_FSID)
  607. return FSIDSOURCE_FSID;
  608. if (fhp->fh_export->ex_uuid)
  609. return FSIDSOURCE_UUID;
  610. return FSIDSOURCE_DEV;
  611. }