upcall.c 24 KB

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