nfsfh.c 17 KB

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