upcall.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  1. /*
  2. * Mostly platform independent upcall operations to Venus:
  3. * -- upcalls
  4. * -- upcall routines
  5. *
  6. * Linux 2.0 version
  7. * Copyright (C) 1996 Peter J. Braam <braam@maths.ox.ac.uk>,
  8. * Michael Callahan <callahan@maths.ox.ac.uk>
  9. *
  10. * Redone for Linux 2.1
  11. * Copyright (C) 1997 Carnegie Mellon University
  12. *
  13. * Carnegie Mellon University encourages users of this code to contribute
  14. * improvements to the Coda project. Contact Peter Braam <coda@cs.cmu.edu>.
  15. */
  16. #include <asm/system.h>
  17. #include <linux/signal.h>
  18. #include <linux/types.h>
  19. #include <linux/kernel.h>
  20. #include <linux/mm.h>
  21. #include <linux/time.h>
  22. #include <linux/fs.h>
  23. #include <linux/file.h>
  24. #include <linux/stat.h>
  25. #include <linux/errno.h>
  26. #include <linux/string.h>
  27. #include <asm/uaccess.h>
  28. #include <linux/vmalloc.h>
  29. #include <linux/vfs.h>
  30. #include <linux/coda.h>
  31. #include <linux/coda_linux.h>
  32. #include <linux/coda_psdev.h>
  33. #include <linux/coda_fs_i.h>
  34. #include <linux/coda_cache.h>
  35. #include <linux/coda_proc.h>
  36. #define upc_alloc() kmalloc(sizeof(struct upc_req), GFP_KERNEL)
  37. #define upc_free(r) kfree(r)
  38. static int coda_upcall(struct coda_sb_info *mntinfo, int inSize, int *outSize,
  39. union inputArgs *buffer);
  40. static void *alloc_upcall(int opcode, int size)
  41. {
  42. union inputArgs *inp;
  43. CODA_ALLOC(inp, union inputArgs *, size);
  44. if (!inp)
  45. return ERR_PTR(-ENOMEM);
  46. inp->ih.opcode = opcode;
  47. inp->ih.pid = current->pid;
  48. inp->ih.pgid = process_group(current);
  49. #ifdef CONFIG_CODA_FS_OLD_API
  50. memset(&inp->ih.cred, 0, sizeof(struct coda_cred));
  51. inp->ih.cred.cr_fsuid = current->fsuid;
  52. #else
  53. inp->ih.uid = current->fsuid;
  54. #endif
  55. return (void*)inp;
  56. }
  57. #define UPARG(op)\
  58. do {\
  59. inp = (union inputArgs *)alloc_upcall(op, insize); \
  60. if (IS_ERR(inp)) { return PTR_ERR(inp); }\
  61. outp = (union outputArgs *)(inp); \
  62. outsize = insize; \
  63. } while (0)
  64. #define INSIZE(tag) sizeof(struct coda_ ## tag ## _in)
  65. #define OUTSIZE(tag) sizeof(struct coda_ ## tag ## _out)
  66. #define SIZE(tag) max_t(unsigned int, INSIZE(tag), OUTSIZE(tag))
  67. /* the upcalls */
  68. int venus_rootfid(struct super_block *sb, struct CodaFid *fidp)
  69. {
  70. union inputArgs *inp;
  71. union outputArgs *outp;
  72. int insize, outsize, error;
  73. insize = SIZE(root);
  74. UPARG(CODA_ROOT);
  75. error = coda_upcall(coda_sbp(sb), insize, &outsize, inp);
  76. if (error) {
  77. printk("coda_get_rootfid: error %d\n", error);
  78. } else {
  79. *fidp = outp->coda_root.VFid;
  80. }
  81. CODA_FREE(inp, insize);
  82. return error;
  83. }
  84. int venus_getattr(struct super_block *sb, struct CodaFid *fid,
  85. struct coda_vattr *attr)
  86. {
  87. union inputArgs *inp;
  88. union outputArgs *outp;
  89. int insize, outsize, error;
  90. insize = SIZE(getattr);
  91. UPARG(CODA_GETATTR);
  92. inp->coda_getattr.VFid = *fid;
  93. error = coda_upcall(coda_sbp(sb), insize, &outsize, inp);
  94. *attr = outp->coda_getattr.attr;
  95. CODA_FREE(inp, insize);
  96. return error;
  97. }
  98. int venus_setattr(struct super_block *sb, struct CodaFid *fid,
  99. struct coda_vattr *vattr)
  100. {
  101. union inputArgs *inp;
  102. union outputArgs *outp;
  103. int insize, outsize, error;
  104. insize = SIZE(setattr);
  105. UPARG(CODA_SETATTR);
  106. inp->coda_setattr.VFid = *fid;
  107. inp->coda_setattr.attr = *vattr;
  108. error = coda_upcall(coda_sbp(sb), insize, &outsize, inp);
  109. CODA_FREE(inp, insize);
  110. return error;
  111. }
  112. int venus_lookup(struct super_block *sb, struct CodaFid *fid,
  113. const char *name, int length, int * type,
  114. struct CodaFid *resfid)
  115. {
  116. union inputArgs *inp;
  117. union outputArgs *outp;
  118. int insize, outsize, error;
  119. int offset;
  120. offset = INSIZE(lookup);
  121. insize = max_t(unsigned int, offset + length +1, OUTSIZE(lookup));
  122. UPARG(CODA_LOOKUP);
  123. inp->coda_lookup.VFid = *fid;
  124. inp->coda_lookup.name = offset;
  125. inp->coda_lookup.flags = CLU_CASE_SENSITIVE;
  126. /* send Venus a null terminated string */
  127. memcpy((char *)(inp) + offset, name, length);
  128. *((char *)inp + offset + length) = '\0';
  129. error = coda_upcall(coda_sbp(sb), insize, &outsize, inp);
  130. *resfid = outp->coda_lookup.VFid;
  131. *type = outp->coda_lookup.vtype;
  132. CODA_FREE(inp, insize);
  133. return error;
  134. }
  135. int venus_store(struct super_block *sb, struct CodaFid *fid, int flags,
  136. vuid_t uid)
  137. {
  138. union inputArgs *inp;
  139. union outputArgs *outp;
  140. int insize, outsize, error;
  141. #ifdef CONFIG_CODA_FS_OLD_API
  142. struct coda_cred cred = { 0, };
  143. cred.cr_fsuid = uid;
  144. #endif
  145. insize = SIZE(store);
  146. UPARG(CODA_STORE);
  147. #ifdef CONFIG_CODA_FS_OLD_API
  148. memcpy(&(inp->ih.cred), &cred, sizeof(cred));
  149. #else
  150. inp->ih.uid = uid;
  151. #endif
  152. inp->coda_store.VFid = *fid;
  153. inp->coda_store.flags = flags;
  154. error = coda_upcall(coda_sbp(sb), insize, &outsize, inp);
  155. CODA_FREE(inp, insize);
  156. return error;
  157. }
  158. int venus_release(struct super_block *sb, struct CodaFid *fid, int flags)
  159. {
  160. union inputArgs *inp;
  161. union outputArgs *outp;
  162. int insize, outsize, error;
  163. insize = SIZE(release);
  164. UPARG(CODA_RELEASE);
  165. inp->coda_release.VFid = *fid;
  166. inp->coda_release.flags = flags;
  167. error = coda_upcall(coda_sbp(sb), insize, &outsize, inp);
  168. CODA_FREE(inp, insize);
  169. return error;
  170. }
  171. int venus_close(struct super_block *sb, struct CodaFid *fid, int flags,
  172. vuid_t uid)
  173. {
  174. union inputArgs *inp;
  175. union outputArgs *outp;
  176. int insize, outsize, error;
  177. #ifdef CONFIG_CODA_FS_OLD_API
  178. struct coda_cred cred = { 0, };
  179. cred.cr_fsuid = uid;
  180. #endif
  181. insize = SIZE(release);
  182. UPARG(CODA_CLOSE);
  183. #ifdef CONFIG_CODA_FS_OLD_API
  184. memcpy(&(inp->ih.cred), &cred, sizeof(cred));
  185. #else
  186. inp->ih.uid = uid;
  187. #endif
  188. inp->coda_close.VFid = *fid;
  189. inp->coda_close.flags = flags;
  190. error = coda_upcall(coda_sbp(sb), insize, &outsize, inp);
  191. CODA_FREE(inp, insize);
  192. return error;
  193. }
  194. int venus_open(struct super_block *sb, struct CodaFid *fid,
  195. int flags, struct file **fh)
  196. {
  197. union inputArgs *inp;
  198. union outputArgs *outp;
  199. int insize, outsize, error;
  200. insize = SIZE(open_by_fd);
  201. UPARG(CODA_OPEN_BY_FD);
  202. inp->coda_open.VFid = *fid;
  203. inp->coda_open.flags = flags;
  204. error = coda_upcall(coda_sbp(sb), insize, &outsize, inp);
  205. *fh = outp->coda_open_by_fd.fh;
  206. CODA_FREE(inp, insize);
  207. return error;
  208. }
  209. int venus_mkdir(struct super_block *sb, struct CodaFid *dirfid,
  210. const char *name, int length,
  211. struct CodaFid *newfid, struct coda_vattr *attrs)
  212. {
  213. union inputArgs *inp;
  214. union outputArgs *outp;
  215. int insize, outsize, error;
  216. int offset;
  217. offset = INSIZE(mkdir);
  218. insize = max_t(unsigned int, offset + length + 1, OUTSIZE(mkdir));
  219. UPARG(CODA_MKDIR);
  220. inp->coda_mkdir.VFid = *dirfid;
  221. inp->coda_mkdir.attr = *attrs;
  222. inp->coda_mkdir.name = offset;
  223. /* Venus must get null terminated string */
  224. memcpy((char *)(inp) + offset, name, length);
  225. *((char *)inp + offset + length) = '\0';
  226. error = coda_upcall(coda_sbp(sb), insize, &outsize, inp);
  227. *attrs = outp->coda_mkdir.attr;
  228. *newfid = outp->coda_mkdir.VFid;
  229. CODA_FREE(inp, insize);
  230. return error;
  231. }
  232. int venus_rename(struct super_block *sb, struct CodaFid *old_fid,
  233. struct CodaFid *new_fid, size_t old_length,
  234. size_t new_length, const char *old_name,
  235. const char *new_name)
  236. {
  237. union inputArgs *inp;
  238. union outputArgs *outp;
  239. int insize, outsize, error;
  240. int offset, s;
  241. offset = INSIZE(rename);
  242. insize = max_t(unsigned int, offset + new_length + old_length + 8,
  243. OUTSIZE(rename));
  244. UPARG(CODA_RENAME);
  245. inp->coda_rename.sourceFid = *old_fid;
  246. inp->coda_rename.destFid = *new_fid;
  247. inp->coda_rename.srcname = offset;
  248. /* Venus must receive an null terminated string */
  249. s = ( old_length & ~0x3) +4; /* round up to word boundary */
  250. memcpy((char *)(inp) + offset, old_name, old_length);
  251. *((char *)inp + offset + old_length) = '\0';
  252. /* another null terminated string for Venus */
  253. offset += s;
  254. inp->coda_rename.destname = offset;
  255. s = ( new_length & ~0x3) +4; /* round up to word boundary */
  256. memcpy((char *)(inp) + offset, new_name, new_length);
  257. *((char *)inp + offset + new_length) = '\0';
  258. error = coda_upcall(coda_sbp(sb), insize, &outsize, inp);
  259. CODA_FREE(inp, insize);
  260. return error;
  261. }
  262. int venus_create(struct super_block *sb, struct CodaFid *dirfid,
  263. const char *name, int length, int excl, int mode,
  264. struct CodaFid *newfid, struct coda_vattr *attrs)
  265. {
  266. union inputArgs *inp;
  267. union outputArgs *outp;
  268. int insize, outsize, error;
  269. int offset;
  270. offset = INSIZE(create);
  271. insize = max_t(unsigned int, offset + length + 1, OUTSIZE(create));
  272. UPARG(CODA_CREATE);
  273. inp->coda_create.VFid = *dirfid;
  274. inp->coda_create.attr.va_mode = mode;
  275. inp->coda_create.excl = excl;
  276. inp->coda_create.mode = mode;
  277. inp->coda_create.name = offset;
  278. /* Venus must get null terminated string */
  279. memcpy((char *)(inp) + offset, name, length);
  280. *((char *)inp + offset + length) = '\0';
  281. error = coda_upcall(coda_sbp(sb), insize, &outsize, inp);
  282. *attrs = outp->coda_create.attr;
  283. *newfid = outp->coda_create.VFid;
  284. CODA_FREE(inp, insize);
  285. return error;
  286. }
  287. int venus_rmdir(struct super_block *sb, struct CodaFid *dirfid,
  288. const char *name, int length)
  289. {
  290. union inputArgs *inp;
  291. union outputArgs *outp;
  292. int insize, outsize, error;
  293. int offset;
  294. offset = INSIZE(rmdir);
  295. insize = max_t(unsigned int, offset + length + 1, OUTSIZE(rmdir));
  296. UPARG(CODA_RMDIR);
  297. inp->coda_rmdir.VFid = *dirfid;
  298. inp->coda_rmdir.name = offset;
  299. memcpy((char *)(inp) + offset, name, length);
  300. *((char *)inp + offset + length) = '\0';
  301. error = coda_upcall(coda_sbp(sb), insize, &outsize, inp);
  302. CODA_FREE(inp, insize);
  303. return error;
  304. }
  305. int venus_remove(struct super_block *sb, struct CodaFid *dirfid,
  306. const char *name, int length)
  307. {
  308. union inputArgs *inp;
  309. union outputArgs *outp;
  310. int error=0, insize, outsize, offset;
  311. offset = INSIZE(remove);
  312. insize = max_t(unsigned int, offset + length + 1, OUTSIZE(remove));
  313. UPARG(CODA_REMOVE);
  314. inp->coda_remove.VFid = *dirfid;
  315. inp->coda_remove.name = offset;
  316. memcpy((char *)(inp) + offset, name, length);
  317. *((char *)inp + offset + length) = '\0';
  318. error = coda_upcall(coda_sbp(sb), insize, &outsize, inp);
  319. CODA_FREE(inp, insize);
  320. return error;
  321. }
  322. int venus_readlink(struct super_block *sb, struct CodaFid *fid,
  323. char *buffer, int *length)
  324. {
  325. union inputArgs *inp;
  326. union outputArgs *outp;
  327. int insize, outsize, error;
  328. int retlen;
  329. char *result;
  330. insize = max_t(unsigned int,
  331. INSIZE(readlink), OUTSIZE(readlink)+ *length + 1);
  332. UPARG(CODA_READLINK);
  333. inp->coda_readlink.VFid = *fid;
  334. error = coda_upcall(coda_sbp(sb), insize, &outsize, inp);
  335. if (! error) {
  336. retlen = outp->coda_readlink.count;
  337. if ( retlen > *length )
  338. retlen = *length;
  339. *length = retlen;
  340. result = (char *)outp + (long)outp->coda_readlink.data;
  341. memcpy(buffer, result, retlen);
  342. *(buffer + retlen) = '\0';
  343. }
  344. CODA_FREE(inp, insize);
  345. return error;
  346. }
  347. int venus_link(struct super_block *sb, struct CodaFid *fid,
  348. struct CodaFid *dirfid, const char *name, int len )
  349. {
  350. union inputArgs *inp;
  351. union outputArgs *outp;
  352. int insize, outsize, error;
  353. int offset;
  354. offset = INSIZE(link);
  355. insize = max_t(unsigned int, offset + len + 1, OUTSIZE(link));
  356. UPARG(CODA_LINK);
  357. inp->coda_link.sourceFid = *fid;
  358. inp->coda_link.destFid = *dirfid;
  359. inp->coda_link.tname = offset;
  360. /* make sure strings are null terminated */
  361. memcpy((char *)(inp) + offset, name, len);
  362. *((char *)inp + offset + len) = '\0';
  363. error = coda_upcall(coda_sbp(sb), insize, &outsize, inp);
  364. CODA_FREE(inp, insize);
  365. return error;
  366. }
  367. int venus_symlink(struct super_block *sb, struct CodaFid *fid,
  368. const char *name, int len,
  369. const char *symname, int symlen)
  370. {
  371. union inputArgs *inp;
  372. union outputArgs *outp;
  373. int insize, outsize, error;
  374. int offset, s;
  375. offset = INSIZE(symlink);
  376. insize = max_t(unsigned int, offset + len + symlen + 8, OUTSIZE(symlink));
  377. UPARG(CODA_SYMLINK);
  378. /* inp->coda_symlink.attr = *tva; XXXXXX */
  379. inp->coda_symlink.VFid = *fid;
  380. /* Round up to word boundary and null terminate */
  381. inp->coda_symlink.srcname = offset;
  382. s = ( symlen & ~0x3 ) + 4;
  383. memcpy((char *)(inp) + offset, symname, symlen);
  384. *((char *)inp + offset + symlen) = '\0';
  385. /* Round up to word boundary and null terminate */
  386. offset += s;
  387. inp->coda_symlink.tname = offset;
  388. s = (len & ~0x3) + 4;
  389. memcpy((char *)(inp) + offset, name, len);
  390. *((char *)inp + offset + len) = '\0';
  391. error = coda_upcall(coda_sbp(sb), insize, &outsize, inp);
  392. CODA_FREE(inp, insize);
  393. return error;
  394. }
  395. int venus_fsync(struct super_block *sb, struct CodaFid *fid)
  396. {
  397. union inputArgs *inp;
  398. union outputArgs *outp;
  399. int insize, outsize, error;
  400. insize=SIZE(fsync);
  401. UPARG(CODA_FSYNC);
  402. inp->coda_fsync.VFid = *fid;
  403. error = coda_upcall(coda_sbp(sb), sizeof(union inputArgs),
  404. &outsize, inp);
  405. CODA_FREE(inp, insize);
  406. return error;
  407. }
  408. int venus_access(struct super_block *sb, struct CodaFid *fid, int mask)
  409. {
  410. union inputArgs *inp;
  411. union outputArgs *outp;
  412. int insize, outsize, error;
  413. insize = SIZE(access);
  414. UPARG(CODA_ACCESS);
  415. inp->coda_access.VFid = *fid;
  416. inp->coda_access.flags = mask;
  417. error = coda_upcall(coda_sbp(sb), insize, &outsize, inp);
  418. CODA_FREE(inp, insize);
  419. return error;
  420. }
  421. int venus_pioctl(struct super_block *sb, struct CodaFid *fid,
  422. unsigned int cmd, struct PioctlData *data)
  423. {
  424. union inputArgs *inp;
  425. union outputArgs *outp;
  426. int insize, outsize, error;
  427. int iocsize;
  428. insize = VC_MAXMSGSIZE;
  429. UPARG(CODA_IOCTL);
  430. /* build packet for Venus */
  431. if (data->vi.in_size > VC_MAXDATASIZE) {
  432. error = -EINVAL;
  433. goto exit;
  434. }
  435. if (data->vi.out_size > VC_MAXDATASIZE) {
  436. error = -EINVAL;
  437. goto exit;
  438. }
  439. inp->coda_ioctl.VFid = *fid;
  440. /* the cmd field was mutated by increasing its size field to
  441. * reflect the path and follow args. We need to subtract that
  442. * out before sending the command to Venus. */
  443. inp->coda_ioctl.cmd = (cmd & ~(PIOCPARM_MASK << 16));
  444. iocsize = ((cmd >> 16) & PIOCPARM_MASK) - sizeof(char *) - sizeof(int);
  445. inp->coda_ioctl.cmd |= (iocsize & PIOCPARM_MASK) << 16;
  446. /* in->coda_ioctl.rwflag = flag; */
  447. inp->coda_ioctl.len = data->vi.in_size;
  448. inp->coda_ioctl.data = (char *)(INSIZE(ioctl));
  449. /* get the data out of user space */
  450. if ( copy_from_user((char*)inp + (long)inp->coda_ioctl.data,
  451. data->vi.in, data->vi.in_size) ) {
  452. error = -EINVAL;
  453. goto exit;
  454. }
  455. error = coda_upcall(coda_sbp(sb), SIZE(ioctl) + data->vi.in_size,
  456. &outsize, inp);
  457. if (error) {
  458. printk("coda_pioctl: Venus returns: %d for %s\n",
  459. error, coda_f2s(fid));
  460. goto exit;
  461. }
  462. if (outsize < (long)outp->coda_ioctl.data + outp->coda_ioctl.len) {
  463. error = -EINVAL;
  464. goto exit;
  465. }
  466. /* Copy out the OUT buffer. */
  467. if (outp->coda_ioctl.len > data->vi.out_size) {
  468. error = -EINVAL;
  469. goto exit;
  470. }
  471. /* Copy out the OUT buffer. */
  472. if (copy_to_user(data->vi.out,
  473. (char *)outp + (long)outp->coda_ioctl.data,
  474. outp->coda_ioctl.len)) {
  475. error = -EFAULT;
  476. goto exit;
  477. }
  478. exit:
  479. CODA_FREE(inp, insize);
  480. return error;
  481. }
  482. int venus_statfs(struct dentry *dentry, struct kstatfs *sfs)
  483. {
  484. union inputArgs *inp;
  485. union outputArgs *outp;
  486. int insize, outsize, error;
  487. insize = max_t(unsigned int, INSIZE(statfs), OUTSIZE(statfs));
  488. UPARG(CODA_STATFS);
  489. error = coda_upcall(coda_sbp(dentry->d_sb), insize, &outsize, inp);
  490. if (!error) {
  491. sfs->f_blocks = outp->coda_statfs.stat.f_blocks;
  492. sfs->f_bfree = outp->coda_statfs.stat.f_bfree;
  493. sfs->f_bavail = outp->coda_statfs.stat.f_bavail;
  494. sfs->f_files = outp->coda_statfs.stat.f_files;
  495. sfs->f_ffree = outp->coda_statfs.stat.f_ffree;
  496. } else {
  497. printk("coda_statfs: Venus returns: %d\n", error);
  498. }
  499. CODA_FREE(inp, insize);
  500. return error;
  501. }
  502. /*
  503. * coda_upcall and coda_downcall routines.
  504. *
  505. */
  506. static inline void coda_waitfor_upcall(struct upc_req *vmp,
  507. struct venus_comm *vcommp)
  508. {
  509. DECLARE_WAITQUEUE(wait, current);
  510. vmp->uc_posttime = jiffies;
  511. add_wait_queue(&vmp->uc_sleep, &wait);
  512. for (;;) {
  513. if ( !coda_hard && vmp->uc_opcode != CODA_CLOSE )
  514. set_current_state(TASK_INTERRUPTIBLE);
  515. else
  516. set_current_state(TASK_UNINTERRUPTIBLE);
  517. /* venus died */
  518. if ( !vcommp->vc_inuse )
  519. break;
  520. /* got a reply */
  521. if ( vmp->uc_flags & ( REQ_WRITE | REQ_ABORT ) )
  522. break;
  523. if ( !coda_hard && vmp->uc_opcode != CODA_CLOSE && signal_pending(current) ) {
  524. /* if this process really wants to die, let it go */
  525. if ( sigismember(&(current->pending.signal), SIGKILL) ||
  526. sigismember(&(current->pending.signal), SIGINT) )
  527. break;
  528. /* signal is present: after timeout always return
  529. really smart idea, probably useless ... */
  530. if ( jiffies - vmp->uc_posttime > coda_timeout * HZ )
  531. break;
  532. }
  533. schedule();
  534. }
  535. remove_wait_queue(&vmp->uc_sleep, &wait);
  536. set_current_state(TASK_RUNNING);
  537. return;
  538. }
  539. /*
  540. * coda_upcall will return an error in the case of
  541. * failed communication with Venus _or_ will peek at Venus
  542. * reply and return Venus' error.
  543. *
  544. * As venus has 2 types of errors, normal errors (positive) and internal
  545. * errors (negative), normal errors are negated, while internal errors
  546. * are all mapped to -EINTR, while showing a nice warning message. (jh)
  547. *
  548. */
  549. static int coda_upcall(struct coda_sb_info *sbi,
  550. int inSize, int *outSize,
  551. union inputArgs *buffer)
  552. {
  553. struct venus_comm *vcommp;
  554. union outputArgs *out;
  555. struct upc_req *req;
  556. int error = 0;
  557. vcommp = sbi->sbi_vcomm;
  558. if ( !vcommp->vc_inuse ) {
  559. printk("No pseudo device in upcall comms at %p\n", vcommp);
  560. return -ENXIO;
  561. }
  562. /* Format the request message. */
  563. req = upc_alloc();
  564. if (!req) {
  565. printk("Failed to allocate upc_req structure\n");
  566. return -ENOMEM;
  567. }
  568. req->uc_data = (void *)buffer;
  569. req->uc_flags = 0;
  570. req->uc_inSize = inSize;
  571. req->uc_outSize = *outSize ? *outSize : inSize;
  572. req->uc_opcode = ((union inputArgs *)buffer)->ih.opcode;
  573. req->uc_unique = ++vcommp->vc_seq;
  574. init_waitqueue_head(&req->uc_sleep);
  575. /* Fill in the common input args. */
  576. ((union inputArgs *)buffer)->ih.unique = req->uc_unique;
  577. /* Append msg to pending queue and poke Venus. */
  578. list_add_tail(&(req->uc_chain), &vcommp->vc_pending);
  579. wake_up_interruptible(&vcommp->vc_waitq);
  580. /* We can be interrupted while we wait for Venus to process
  581. * our request. If the interrupt occurs before Venus has read
  582. * the request, we dequeue and return. If it occurs after the
  583. * read but before the reply, we dequeue, send a signal
  584. * message, and return. If it occurs after the reply we ignore
  585. * it. In no case do we want to restart the syscall. If it
  586. * was interrupted by a venus shutdown (psdev_close), return
  587. * ENODEV. */
  588. /* Go to sleep. Wake up on signals only after the timeout. */
  589. coda_waitfor_upcall(req, vcommp);
  590. if (vcommp->vc_inuse) { /* i.e. Venus is still alive */
  591. /* Op went through, interrupt or not... */
  592. if (req->uc_flags & REQ_WRITE) {
  593. out = (union outputArgs *)req->uc_data;
  594. /* here we map positive Venus errors to kernel errors */
  595. error = -out->oh.result;
  596. *outSize = req->uc_outSize;
  597. goto exit;
  598. }
  599. if ( !(req->uc_flags & REQ_READ) && signal_pending(current)) {
  600. /* Interrupted before venus read it. */
  601. list_del(&(req->uc_chain));
  602. /* perhaps the best way to convince the app to
  603. give up? */
  604. error = -EINTR;
  605. goto exit;
  606. }
  607. if ( (req->uc_flags & REQ_READ) && signal_pending(current) ) {
  608. /* interrupted after Venus did its read, send signal */
  609. union inputArgs *sig_inputArgs;
  610. struct upc_req *sig_req;
  611. list_del(&(req->uc_chain));
  612. error = -ENOMEM;
  613. sig_req = upc_alloc();
  614. if (!sig_req) goto exit;
  615. CODA_ALLOC((sig_req->uc_data), char *, sizeof(struct coda_in_hdr));
  616. if (!sig_req->uc_data) {
  617. upc_free(sig_req);
  618. goto exit;
  619. }
  620. error = -EINTR;
  621. sig_inputArgs = (union inputArgs *)sig_req->uc_data;
  622. sig_inputArgs->ih.opcode = CODA_SIGNAL;
  623. sig_inputArgs->ih.unique = req->uc_unique;
  624. sig_req->uc_flags = REQ_ASYNC;
  625. sig_req->uc_opcode = sig_inputArgs->ih.opcode;
  626. sig_req->uc_unique = sig_inputArgs->ih.unique;
  627. sig_req->uc_inSize = sizeof(struct coda_in_hdr);
  628. sig_req->uc_outSize = sizeof(struct coda_in_hdr);
  629. /* insert at head of queue! */
  630. list_add(&(sig_req->uc_chain), &vcommp->vc_pending);
  631. wake_up_interruptible(&vcommp->vc_waitq);
  632. } else {
  633. printk("Coda: Strange interruption..\n");
  634. error = -EINTR;
  635. }
  636. } else { /* If venus died i.e. !VC_OPEN(vcommp) */
  637. printk("coda_upcall: Venus dead on (op,un) (%d.%d) flags %d\n",
  638. req->uc_opcode, req->uc_unique, req->uc_flags);
  639. error = -ENODEV;
  640. }
  641. exit:
  642. upc_free(req);
  643. return error;
  644. }
  645. /*
  646. The statements below are part of the Coda opportunistic
  647. programming -- taken from the Mach/BSD kernel code for Coda.
  648. You don't get correct semantics by stating what needs to be
  649. done without guaranteeing the invariants needed for it to happen.
  650. When will be have time to find out what exactly is going on? (pjb)
  651. */
  652. /*
  653. * There are 7 cases where cache invalidations occur. The semantics
  654. * of each is listed here:
  655. *
  656. * CODA_FLUSH -- flush all entries from the name cache and the cnode cache.
  657. * CODA_PURGEUSER -- flush all entries from the name cache for a specific user
  658. * This call is a result of token expiration.
  659. *
  660. * The next arise as the result of callbacks on a file or directory.
  661. * CODA_ZAPFILE -- flush the cached attributes for a file.
  662. * CODA_ZAPDIR -- flush the attributes for the dir and
  663. * force a new lookup for all the children
  664. of this dir.
  665. *
  666. * The next is a result of Venus detecting an inconsistent file.
  667. * CODA_PURGEFID -- flush the attribute for the file
  668. * purge it and its children from the dcache
  669. *
  670. * The last allows Venus to replace local fids with global ones
  671. * during reintegration.
  672. *
  673. * CODA_REPLACE -- replace one CodaFid with another throughout the name cache */
  674. int coda_downcall(int opcode, union outputArgs * out, struct super_block *sb)
  675. {
  676. /* Handle invalidation requests. */
  677. if ( !sb || !sb->s_root || !sb->s_root->d_inode)
  678. return 0;
  679. switch (opcode) {
  680. case CODA_FLUSH : {
  681. coda_cache_clear_all(sb);
  682. shrink_dcache_sb(sb);
  683. coda_flag_inode(sb->s_root->d_inode, C_FLUSH);
  684. return(0);
  685. }
  686. case CODA_PURGEUSER : {
  687. coda_cache_clear_all(sb);
  688. return(0);
  689. }
  690. case CODA_ZAPDIR : {
  691. struct inode *inode;
  692. struct CodaFid *fid = &out->coda_zapdir.CodaFid;
  693. inode = coda_fid_to_inode(fid, sb);
  694. if (inode) {
  695. coda_flag_inode_children(inode, C_PURGE);
  696. coda_flag_inode(inode, C_VATTR);
  697. iput(inode);
  698. }
  699. return(0);
  700. }
  701. case CODA_ZAPFILE : {
  702. struct inode *inode;
  703. struct CodaFid *fid = &out->coda_zapfile.CodaFid;
  704. inode = coda_fid_to_inode(fid, sb);
  705. if ( inode ) {
  706. coda_flag_inode(inode, C_VATTR);
  707. iput(inode);
  708. }
  709. return 0;
  710. }
  711. case CODA_PURGEFID : {
  712. struct inode *inode;
  713. struct CodaFid *fid = &out->coda_purgefid.CodaFid;
  714. inode = coda_fid_to_inode(fid, sb);
  715. if ( inode ) {
  716. coda_flag_inode_children(inode, C_PURGE);
  717. /* catch the dentries later if some are still busy */
  718. coda_flag_inode(inode, C_PURGE);
  719. d_prune_aliases(inode);
  720. iput(inode);
  721. }
  722. return 0;
  723. }
  724. case CODA_REPLACE : {
  725. struct inode *inode;
  726. struct CodaFid *oldfid = &out->coda_replace.OldFid;
  727. struct CodaFid *newfid = &out->coda_replace.NewFid;
  728. inode = coda_fid_to_inode(oldfid, sb);
  729. if ( inode ) {
  730. coda_replace_fid(inode, oldfid, newfid);
  731. iput(inode);
  732. }
  733. return 0;
  734. }
  735. }
  736. return 0;
  737. }