1 /****^  ******************************************************
  2         *                                                    *
  3         * Copyright, (C) Honeywell Bull Inc., 1987           *
  4         *                                                    *
  5         * Copyright (c) 1987 by Massachusetts Institute of   *
  6         * Technology and Honeywell Information Systems, Inc. *
  7         *                                                    *
  8         * Copyright (c) 1972 by Massachusetts Institute of   *
  9         * Technology and Honeywell Information Systems, Inc. *
 10         *                                                    *
 11         ****************************************************** */
 12 
 13 /*
 14    delete_vtoce (branchp, code)
 15 
 16 
 17    FUNCTION -
 18 
 19    This procedure deletes the vtoc entry of the segment whose branch is pointed  to
 20    by the input argument "branchp". It performs the following system functions:
 21    -  Disconnect  the  page table (if any) of the segment from any sdw that may be
 22    pointing to it.
 23    - Free all disk, bulk store and core addresses occupied by the  pages  of  that
 24    segment.
 25    - Free the vtoc entry for that segment.
 26    -  If  the  segment  is  a directory which received some quota from its parent,
 27    return this quota to the parent.
 28 
 29 
 30    IMPLEMENTATION -
 31 
 32    This procedure is called only by delentry.  It  assumes  the  following  initial
 33    conditions:
 34    -  The directory in which the branch resides is locked for writing on behalf of the current
 35    process.
 36    - All items of the branch pointed to by "branchp" are valid.
 37    - All conditions required to delete the segment have already been checked.
 38    - If the segment to be deleted is a directory, it is locked on  behalf  of  the
 39    current process.
 40 
 41 
 42    MODIFICATIONS -
 43 
 44    03/27/75         Andre Bensoussan.
 45    07/29/77         Greenberg, for TPP update.
 46    09/17/82         J. Bongiovanni to optimize by reducing work done under
 47    AST Lock
 48    10/26/82         J. Bongiovanni, for fm_damaged
 49    05/30/83         E. N. Kittlitz search_ast$check, setfaults$if_active pvid, vtocx args
 50 
 51 */
 52 
 53 
 54 /* format: style4 */
 55 %page;
 56 delete_vtoce: procedure (branchp, code);
 57 
 58 
 59 dcl  branchp ptr;                                           /* Input  - branch pointer */
 60 dcl  code fixed bin (35);                                   /* Output - error code */
 61 
 62 dcl  uid bit (36) aligned;
 63 dcl  pvid bit (36) aligned;
 64 dcl  (i, pvtx, vtocx) fixed bin (17);
 65 dcl  n_deposit_pages fixed bin;
 66 dcl  1 local_aste aligned like aste;
 67 dcl  1 local_vtoce aligned like vtoce;
 68 dcl  deposit_list (0:255) bit (22) aligned;
 69 dcl  pageno_list (0:255) fixed bin aligned;
 70 
 71 dcl  null builtin;
 72 
 73 dcl  error_table_$vtoce_connection_fail external fixed bin (35);
 74 dcl  sst$checksum_filemap fixed bin (35) external;
 75 
 76 dcl  lock$lock_ast entry;
 77 dcl  lock$unlock_ast entry;
 78 dcl  search_ast$check entry (bit (36) aligned, bit (36) aligned, fixed bin, fixed bin (35)) returns (ptr);
 79 dcl  setfaults$if_active entry (bit (36) aligned, bit (36) aligned, fixed bin, bit (1) aligned);
 80 dcl  quotaw$mq entry (ptr, ptr, fixed bin, bit (1) aligned, fixed bin (35));
 81 dcl  vtoc_man$await_vtoce entry (bit (36) aligned, fixed bin, fixed bin, fixed bin (35));
 82 dcl  vtoc_man$free_vtoce entry (bit (36) aligned, fixed bin, fixed bin, fixed bin (35));
 83 dcl  get_pvtx entry (bit (36), fixed bin (35)) returns (fixed bin);
 84 dcl  get_pvtx$hold_pvtx entry (bit (36) aligned, fixed bin, fixed bin (35));
 85 dcl  get_pvtx$release_pvtx entry (bit (36) aligned, fixed bin);
 86 dcl  activate entry (ptr, fixed bin (35)) returns (ptr);
 87 dcl  deactivate$for_delete entry (ptr, fixed bin (35));
 88 dcl  pc$get_file_map entry (ptr, ptr, ptr, fixed bin, ptr, ptr);
 89 dcl  pc$deposit_list entry (fixed bin, fixed bin, ptr, fixed bin, ptr);
 90 dcl  truncate_vtoce$truncate_vtoce_delete entry (ptr, fixed bin (35));
 91 dcl  syserr$error_code entry options (variable);
 92 
 93 dcl  (error_table_$mylock, error_table_$root) fixed bin (35) external;
 94 
 95 %page;
 96           code = 0;
 97           ep = branchp;
 98 
 99           uid = entry.uid;
100           pvid = entry.pvid;
101           pvtx = get_pvtx (entry.pvid, code); if code ^= 0 then return;
102           vtocx = entry.vtocx;
103 
104 
105           call get_pvtx$hold_pvtx (pvid, pvtx, code);
106           if code ^= 0 then return;
107           call setfaults$if_active (uid, pvid, vtocx, "0"b);
108 
109           call truncate_vtoce$truncate_vtoce_delete (ep, code);
110           if code ^= 0 then if code = error_table_$vtoce_connection_fail then do;
111                     code = 0;                               /* delete the branch only */
112                     go to release;
113                end;
114                else go to release;
115 
116           if entry.dirsw then call RETURN_QUOTA;
117 
118           n_deposit_pages = 0;
119 
120           call lock$lock_ast;
121 
122           astep = search_ast$check (uid, pvid, vtocx, (0)); /* don't worry about double uid */
123           if astep ^= null then do;
124                if aste.dius then do;                        /* volume dumper is using this */
125                     call lock$unlock_ast;
126                     astep = activate (ep, code);
127                     if code ^= 0 then go to release;
128                end;
129                call pc$get_file_map (astep, addr (local_aste), addr (local_vtoce.fm), n_deposit_pages,
130                     addr (deposit_list), addr (pageno_list));
131                if aste.fm_damaged & (sst$checksum_filemap ^= 0)
132                then n_deposit_pages = 0;
133                call deactivate$for_delete (astep, code);
134           end;
135 
136           if code = 0 then
137                call vtoc_man$free_vtoce (pvid, pvtx, vtocx, code);
138 
139           call lock$unlock_ast;
140           if code ^= 0 then go to release;
141 
142           if n_deposit_pages > 0 then do;
143                call vtoc_man$await_vtoce (pvid, pvtx, vtocx, code);
144                if code = 0 then
145                     call pc$deposit_list (pvtx, n_deposit_pages, addr (deposit_list),
146                          vtocx, addr (pageno_list));
147           end;
148 
149 release:
150           call get_pvtx$release_pvtx (pvid, pvtx);
151 
152           return;
153 
154 
155 
156 RETURN_QUOTA: procedure;
157 
158 dcl  qsw bit (1) init ("0"b);
159 dcl  local_tpp (0:1) fixed bin (71) aligned;
160 dcl  fixedoverflow condition;
161 dcl  par_pvid bit (36) aligned;
162 dcl  par_pvtx fixed bin;
163 dcl  pep ptr;
164 dcl  par_vtocx fixed bin (17);
165 dcl  sumcode fixed bin (35);
166 dcl  READ_LOCK bit (36) options (constant) static init ("000000000000"b3) aligned;
167 
168 
169 dcl  sum$getbranch_root_my entry (ptr, bit (36) aligned, ptr, fixed bin (35));
170 dcl  lock$dir_unlock entry (ptr);
171 dcl  (vtoc_man$get_vtoce, vtoc_man$put_vtoce) entry (bit (36) aligned, fixed bin, fixed bin, bit (3), ptr,
172           fixed bin (35));
173 
174 dcl  1 local_vtoce like vtoce aligned;
175 
176           astep = activate (ep, code); if code ^= 0 then return; /* Locks the AST and leaves it locked */
177 
178           do i = 0 to 1;
179                if (i = 0 & aste.tqsw (i) & ^aste.master_dir) |
180                     (i = 1 & aste.tqsw (i)) then
181                     do;
182                     qsw = "1"b;
183                     call quotaw$mq (ptr (astep, astep -> aste.par_astep), astep, -aste.quota (i),
184                          bit (fixed (i, 1), 1), code);
185                     if code ^= 0 then call syserr$error_code (4, code,
186                               "delete_vtoce: from quotaw, pvid ^w, vtocx ^o", pvid, vtocx);
187                end;
188           end;
189 
190           call lock$unlock_ast;
191 
192           if ^qsw then return;
193 
194 /*        UPDATE TPP TO THE SUPERIOR */
195 
196           call vtoc_man$get_vtoce (pvid, pvtx, vtocx, "100"b, addr (local_vtoce), code);
197           if code ^= 0 then return;
198 
199           local_tpp = local_vtoce.trp;
200           if local_tpp (0) = 0 & local_tpp (1) = 0 then return;
201 
202 
203           dp = ptr (ep, 0);                                 /* We're deleting >a>b>c>d. dp -> >a>b>c */
204           call sum$getbranch_root_my (dp, READ_LOCK, pep, sumcode);
205                                                             /* This locking of parent's parent is to prevent seg move on parent. */
206 
207           if sumcode = 0 | sumcode = error_table_$root | sumcode = error_table_$mylock then do;
208                par_pvid = dir.pvid;
209                par_vtocx = dir.vtocx;
210           end;
211           else do;
212                code = sumcode;
213                go to tploss;
214           end;
215 
216           call lock$lock_ast;                               /* must protect VTOCE */
217 
218           par_pvtx = get_pvtx ((par_pvid), code);
219           if code ^= 0 then go to tpploss1;
220                                                             /* Shouldn't happen, RLV better be mounted. */
221           call vtoc_man$get_vtoce (par_pvid, par_pvtx, par_vtocx, "100"b, addr (local_vtoce), code);
222           if code ^= 0 then go to tpploss1;
223 
224           on fixedoverflow go to tpploss1;
225           local_vtoce.trp = local_vtoce.trp + local_tpp;
226           revert fixedoverflow;
227 
228           call vtoc_man$put_vtoce (par_pvid, par_pvtx, par_vtocx, "100"b, addr (local_vtoce), code);
229 tpploss1:
230           call lock$unlock_ast;
231 tploss:
232           if sumcode = 0 then call lock$dir_unlock (ptr (pep, 0));
233 
234           if code ^= 0 then call syserr$error_code (4, code,
235                     "delete_vtoce: cannot add time/page product (^d ^d) to pvid ^w vtocx ^o uid ^w.",
236                     local_tpp, par_pvid, par_vtocx, dir.uid);
237 
238           return;
239 
240      end RETURN_QUOTA;
241 
242 /* format: off */
243 %page; %include aste;
244 %page; %include dir_header;
245 %page; %include dir_entry;
246 %page; %include vtoce;
247 
248 /* format: on */
249 %page;
250 /* BEGIN MESSAGE DOCUMENTATION
251 
252    Message:
253    delete_vtoce: from quotaw, pvid PPP. vtocx VVV ERRORMESSAGE
254 
255    S: $log
256 
257    T: $run
258 
259    M: While deleting a directory which had a quota
260    account, a quota handling  problem usually record
261    quota overflow, was encountered.
262 
263    A: $ignore
264 
265    Message:
266    delete_vtoce: cannot add time/page product (SEGTPP DIRTPP)
267    to pvid PPP vtocx VVV uid UUU ERRORMESSAGE
268 
269    S: $log
270 
271    T: $run
272 
273    M: During the deletion of a directory which had
274    a quota account, a difficulty was encountered in
275    reflecting its time/page product upward. SEGTPP and
276    DIRTPP are the time/page product for segments and directories,
277    respectively.
278 
279    A: $notify_sa
280 
281    END MESSAGE DOCUMENTATION */
282      end delete_vtoce;