nfsfh.c 18 KB

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