home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / unix / wizards / 4876 < prev    next >
Encoding:
Internet Message Format  |  1992-11-24  |  7.4 KB

  1. Path: sparky!uunet!cis.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!agate!dog.ee.lbl.gov!horse.ee.lbl.gov!torek
  2. From: torek@horse.ee.lbl.gov (Chris Torek)
  3. Newsgroups: comp.unix.wizards
  4. Subject: Re: Changing the owner of a process
  5. Date: 24 Nov 1992 03:20:20 GMT
  6. Organization: Lawrence Berkeley Laboratory, Berkeley
  7. Lines: 155
  8. Message-ID: <27630@dog.ee.lbl.gov>
  9. References: <1992Nov21.022833.24351@exlog.com>
  10. Reply-To: torek@horse.ee.lbl.gov (Chris Torek)
  11. NNTP-Posting-Host: 128.3.112.15
  12. Keywords: process ownership
  13.  
  14. In article <1992Nov21.022833.24351@exlog.com> mcdowell@exlogcorp.exlog.com
  15. (Steve McDowell) writes:
  16. >Calm down Chris, there's no need for a personal exchange here. You don't
  17. >know me or what my background is, so be very careful before you presume
  18. >the wrong things. 
  19.  
  20. True (although the `exlog.com' is a bit of a giveaway :-) ).  Perhaps I
  21. was overly grouchy and irritable---moving tends to do that....  I could
  22. have included a smiley or something.
  23.  
  24. >>... I will not try to tell you how to sell commercial systems.
  25.  
  26. >But you don't understand, I wish you would -- we really do need the help....
  27.  
  28. Well, if you insist :-)
  29.  
  30. >Or, in the case that my original article was in response to, you have a user
  31. >who fancies himself a "system programmer". I'm a big believer in the 
  32. >condom approach to end-user computing -- let a user stroke himself all
  33. >he wants to but don't let his results impregnate the integrety of my 
  34. >operating system. 
  35.  
  36. One can easily take this too far.  For instance, it is possible on many
  37. (most? all?) Unix machines to open /dev/mem and alter the actual kernel
  38. code.  (I did this once on a live multi-user VAX, to patch a bug in the
  39. old 4.1BSD CMU IPC.  Quite an experience. :-) )  If someone replaces
  40. the kernel code, recovery is difficult---maybe not impossible (take a
  41. look at the techniques people use in CORE WARS), but certainly not
  42. worthwhile to everyone.
  43.  
  44. >... If there's a situation that can be recovered from, then recover.
  45.  
  46. This is a *very* hard problem in general.  Some researchers argue that
  47. fault tolerance is in fact *too* hard, and that a `reboot and recover
  48. work-in-progress' approach is more tractable.
  49.  
  50. What we do in practise (in both research and, in my previous
  51. incarnation at Univ. of MD, systems support) is try to anticipate
  52. `likely failures' and insert recovery code for these.  In this case
  53. (per-UID process counts), the failure is unlikely, and the recovery
  54. code will mostly be `dead weight'.  The benefit just does not match
  55. the cost.  Note that costs and benefits differ for others; people
  56. who buy Tandem systems to run banks are willing to spend the extra
  57. money for dual or triple redundant systems, and willing to take
  58. speed reduction factors of 2 or more, to achieve higher reliability.
  59.  
  60. Other things, like the `timeout table overflow' panic, are symptoms
  61. not of *errors* but of *overload*, and in this case I would be happy
  62. to replace it with something more effective (if I could just think
  63. of something simple and reliable...).
  64.  
  65. There are about 140 panic's in the 4.4-alpha `kern' directory right
  66. now.  Of these, I only see two or three that I think should `never' be
  67. there; the rest represent sanity checks that make sure the rest of the
  68. kernel is behaving in the manner expected.  Errors in device drivers,
  69. file systems, and so forth can trigger them, but presumably those
  70. installing such drivers or file systems will prefer to debug these.
  71. Note that many of these are under `#ifdef DIAGNOSTIC': if you believe
  72. the system works, you can simply turn them off entirely.  (This is not
  73. the same as `handling the situation'!)
  74.  
  75. >Of course, for your purposes developing an operating system is a means
  76. >unto itself. You don't have to worry about irrelevant things like 
  77. >"customers" and "applications".
  78.  
  79. True to some extent, anyway.  Our systems have to be reliable enough
  80. to keep us working, but not so reliable as to put us out of a job. :-)
  81.  
  82. Just for fun, let us consider several panic's and possible alternatives,
  83. all from /sys/kern/kern_descrip.c.
  84.  
  85. dup2(p, uap, retval)
  86.     ...
  87.     if (new >= fdp->fd_nfiles) {
  88.         if (error = fdalloc(p, new, &i))
  89.             return (error);
  90.         if (new != i)
  91.             panic("dup2: fdalloc");
  92.     } else if ...
  93.  
  94. Now, fdalloc's job is to allocate the first free file descriptor
  95. greater than or equal to the given one (arg 2; i holds the result).
  96. fdp->fd_nfiles is the limit on valid descriptors: all are in
  97. [0..fd_nfiles).  Since new >= fd_nfiles, we must (by definition) get
  98. back the desired descriptor.  If new != i, what went wrong?
  99.  
  100.   - maybe fd_nfiles is wrong.
  101.   - maybe fdalloc() is broken.
  102.   - maybe someone snuck in and allocated a descriptor while we were
  103.     not watching (i.e., there is a race).
  104.  
  105. Each of these appears to deserve different treatment.  If fd_nfiles was
  106. wrong, just fix it and continue.  If fdalloc() is broken, there is not
  107. much we can do here; we could return an error (EINTERNAL) to say that
  108. the system is broken, but we will never be able to get anything done
  109. that way.  If there is a race, we could try again and maybe win the
  110. race---but we have to be careful not to loop forever in this case.
  111.  
  112. fstat()
  113.     ...
  114.     switch (fp->f_type) {
  115.     ...
  116.     default:
  117.         panic("fstat");
  118.     }
  119.  
  120. Since the only known `type's are vnodes and sockets, something is
  121. definitely wrong.  Perhaps someone overwrote the original type.  In
  122. this case we really have no way to recover it.  I would argue that
  123. the right cure for this panic is to remove the distinctions between
  124. vnodes and sockets (this is now possible with the VFS, or would be
  125. with a few minor tweaks), so that instead of switching on the type,
  126. we just call through the appropriate pointer:
  127.  
  128.     struct vnode *vp;
  129.     vp = f->f_vp;
  130.     vp->v_ops->vo_stat(p, vp, &ub);
  131.  
  132. In this case, if any of the pointers are overwritten, we will probably
  133. just crash immediately; but at least we will have written less code. :-)
  134.  
  135. closef()
  136.     ...
  137.     if (fp->f_count < 0)
  138.         panic("closef: count < 0");
  139.  
  140. Those who ran 4.2BSD on the VAX when it first came out have some
  141. experience here.  This panic did not appear in the original code.
  142. Instead, the count actually did go negative, due to the ability to
  143. longjmp() out of a close when (e.g.) closing a tty with a SIGALRM
  144. pending.  When that happened, the kernel would eventually trash a file
  145. system.  The panic prevented that, and gave the clues needed to
  146. diagnose the problem.  Since then I have not seen this panic occur;
  147. its purpose is to act as a `firewall'.  Nonetheless, how would one
  148. fix this?  The count could be recovered, but only by scanning all
  149. descriptor tables for all processes---and in any case it is probably
  150. too late: the underlying close routine may have been called already,
  151. so the network connection to a peer (if that is what this represents)
  152. is already gone, with no way to get it back.
  153.  
  154. In all these cases, whenever a count could be wrong, the pointer that
  155. points to it could be wrong instead.  How do we tell the difference?
  156. Should we test every pointer before following it, in case it would
  157. cause a trap?  Or perhaps try to recover from within the trap handler?
  158. (This is *not* straightforward on many machines, and both methods have
  159. a high cost.)
  160.  
  161. So, all in all, the 4.4BSD line generally panics when a consistency
  162. check fails, because that makes it debuggable.  The system reboots in a
  163. few minutes (fsck is quicker than it was in 4.3BSD), and after saving
  164. the evidence (the vmunix and vmcore files) the machine is back up and
  165. running.
  166. -- 
  167. In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 510 486 5427)
  168. Berkeley, CA        Domain:    torek@ee.lbl.gov
  169.