nfsfh.c 16 KB

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