~ubuntu-branches/ubuntu/intrepid/raidutils/intrepid

« back to all changes in this revision

Viewing changes to raideng/core_mgr.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Barak Pearlmutter
  • Date: 2004-05-18 11:33:42 UTC
  • Revision ID: james.westby@ubuntu.com-20040518113342-tyqavmso5q351xi2
Tags: upstream-0.0.4
ImportĀ upstreamĀ versionĀ 0.0.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 1996-2004, Adaptec Corporation
 
2
 * All rights reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions are met:
 
6
 *
 
7
 * - Redistributions of source code must retain the above copyright notice, this
 
8
 *   list of conditions and the following disclaimer.
 
9
 * - Redistributions in binary form must reproduce the above copyright notice,
 
10
 *   this list of conditions and the following disclaimer in the documentation
 
11
 *   and/or other materials provided with the distribution.
 
12
 * - Neither the name of the Adaptec Corporation nor the names of its
 
13
 *   contributors may be used to endorse or promote products derived from this
 
14
 *   software without specific prior written permission.
 
15
 *
 
16
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 
17
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
18
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
19
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 
20
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 
21
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 
22
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 
23
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 
24
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 
25
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 
26
 * POSSIBILITY OF SUCH DAMAGE.
 
27
 */
 
28
 
 
29
//File - CORE_MGR.CPP
 
30
//***************************************************************************
 
31
//
 
32
//Description:
 
33
//
 
34
//    This file contains the function definitions for the dptCoreMgr_C
 
35
//class.
 
36
//
 
37
//Author:       Doug Anderson
 
38
//Date:         10/14/92
 
39
//
 
40
//Editors:
 
41
//
 
42
//Remarks:
 
43
//
 
44
//
 
45
//***************************************************************************
 
46
#include "allfiles.hpp"
 
47
 
 
48
//Function - dptCoreMgr_C::dptCoreMgr_C() - start
 
49
//===========================================================================
 
50
//
 
51
//Description:
 
52
//
 
53
//    This function is the constructor for the dptCoreMgr_C class.
 
54
//
 
55
//Parameters:
 
56
//
 
57
//Return Value:
 
58
//
 
59
//Global Variables Affected:
 
60
//
 
61
//Remarks: (Side effects, Assumptions, Warnings...)
 
62
//
 
63
//
 
64
//---------------------------------------------------------------------------
 
65
 
 
66
dptCoreMgr_C::dptCoreMgr_C()
 
67
{
 
68
 
 
69
  // Clear all flags
 
70
flags = 0;
 
71
  // Initialize this manager's level of operation
 
72
level = 0;
 
73
  // Indicate that this object is a manager object
 
74
setMgr();
 
75
 
 
76
}
 
77
//dptCoreMgr_C::dptCoreMgr_C() - end
 
78
 
 
79
 
 
80
//Function - dptCoreMgr_C::enterLog() - start
 
81
//===========================================================================
 
82
//
 
83
//Description:
 
84
//
 
85
//    This function adds an object to this manager's logical devices list.
 
86
//
 
87
//Parameters:
 
88
//
 
89
//Return Value:
 
90
//
 
91
// 1 = The device was successfully entered into the engine core.
 
92
// 0 = The device was not entered into the engine core and was deleted.
 
93
//
 
94
//Global Variables Affected:
 
95
//
 
96
//Remarks: (Side effects, Assumptions, Warnings...)
 
97
//
 
98
//
 
99
//---------------------------------------------------------------------------
 
100
 
 
101
DPT_RTN_T       dptCoreMgr_C::enterLog(dptCoreDev_C *inDev_P)
 
102
{
 
103
 
 
104
   DPT_RTN_T    retVal;
 
105
   uSHORT       _status = 0;
 
106
 
 
107
  // Determine if it is OK to add this device
 
108
if ((retVal = preEnterLog(inDev_P)) == MSG_RTN_COMPLETED) {
 
109
     // The device originates in a logical device list
 
110
   inDev_P->coreFlags |= FLG_ENG_LIST;
 
111
     // The object is attached to this manager.
 
112
   inDev_P->attachedTo_P = this;
 
113
     // Set the object's connection pointer
 
114
   inDev_P->conn_P = myConn_P();
 
115
     // Add the object to the connection's master object list
 
116
   if (myConn_P()->objectList.addEnd(inDev_P)) {
 
117
        // Attempt to add the new device to this manager's logical device
 
118
        // list and all higher level managers' logical device lists
 
119
      _status = bubble(inDev_P);
 
120
      if (_status==2)
 
121
           // Call the handler for an incomplete bubble
 
122
         _status = myConn_P()->enterSuppressed(inDev_P);
 
123
      else if (_status==0)
 
124
           // Remove from the connection's master device list
 
125
         myConn_P()->objectList.remove(inDev_P);
 
126
   } // end if (objectList.addEnd())
 
127
   if (_status==0)
 
128
      retVal = MSG_RTN_FAILED | ERR_MEM_ALLOC;
 
129
} // end if (preEnterLog())
 
130
 
 
131
if (_status==0)
 
132
     // Call the handler for an invalid add to engine core
 
133
   notAddedToCore(inDev_P);
 
134
 
 
135
return (retVal);
 
136
 
 
137
}
 
138
//dptCoreMgr_C::enterLog() - end
 
139
 
 
140
 
 
141
//Function - dptCoreMgr_C::enterPhy() - start
 
142
//===========================================================================
 
143
//
 
144
//Description:
 
145
//
 
146
//    This function adds an object to the physical device list.
 
147
//
 
148
//Parameters:
 
149
//
 
150
//Return Value:
 
151
//
 
152
//Global Variables Affected:
 
153
//
 
154
//Remarks: (Side effects, Assumptions, Warnings...)
 
155
//
 
156
//
 
157
//---------------------------------------------------------------------------
 
158
 
 
159
DPT_RTN_T       dptCoreMgr_C::enterPhy(dptCoreObj_C *inObj_P)
 
160
{
 
161
 
 
162
   DPT_RTN_T            retVal;
 
163
   uSHORT               _status = 0;
 
164
   dptCoreDev_C         *dev_P;
 
165
   dptCoreMgr_C         *mgr_P;
 
166
 
 
167
  // Determine if it is OK to enter this object
 
168
if ((retVal = preEnterPhy(inObj_P))==MSG_RTN_COMPLETED) {
 
169
   retVal = MSG_RTN_FAILED | ERR_MEM_ALLOC;
 
170
     // Add the object to the connection's master object list
 
171
   if (myConn_P()->objectList.addEnd(inObj_P)) {
 
172
      if (preAddPhy(inObj_P)) {
 
173
         if (phyList.add(inObj_P)) {
 
174
              // The object is attached to this manager.
 
175
            inObj_P->attachedTo_P = this;
 
176
              // Set the object's connection pointer
 
177
            inObj_P->conn_P = myConn_P();
 
178
              // If the object is a device...
 
179
            if (inObj_P->isDevice()) {
 
180
                 // Cast the object as a device
 
181
               dev_P = (dptCoreDev_C *) inObj_P;
 
182
                 // Set the object's highest visible level
 
183
               dev_P->visibleLevel = level + 1;
 
184
                // If this manager bubbles physical devices...
 
185
               if (isBubbler()) {
 
186
                    // Bubble the object up the logical device chain
 
187
                  _status = bubble(dev_P);
 
188
                  if ((_status==2) || (_status==0))
 
189
                      // Enter in the connection's suppressed device list
 
190
                     myConn_P()->enterSuppressed(dev_P);
 
191
               } // end if (isBubbler())
 
192
               else {
 
193
                    // Intentionally suppress the device
 
194
                  myConn_P()->suppress(dev_P);
 
195
               }
 
196
            } // end if (isDevice())
 
197
            else {
 
198
                 // Cast the object as a manager
 
199
               mgr_P = (dptCoreMgr_C *) inObj_P;
 
200
                 // Set the sub-manager's level
 
201
               mgr_P->level = level + 1;
 
202
            }
 
203
              // Call the post add physical handler
 
204
            postAddPhy(inObj_P);
 
205
              // The object was added to the engine core
 
206
            _status = 1;
 
207
              // Indicate success
 
208
            retVal = MSG_RTN_COMPLETED;
 
209
         } // end if (phyList.add())
 
210
      } // end if (preAddPhy())
 
211
   } // end if (objectList.addEnd())
 
212
} // end if (preEnterPhy())
 
213
 
 
214
if (_status==0) {
 
215
     // Remove from the connection's master device list
 
216
   myConn_P()->objectList.remove(inObj_P);
 
217
     // Call the handler for an invalid add to engine core
 
218
   notAddedToCore(inObj_P);
 
219
}
 
220
 
 
221
return (retVal);
 
222
 
 
223
}
 
224
//dptCoreMgr_C::enterPhy() - end
 
225
 
 
226
 
 
227
//Function - dptCoreMgr_C::bubble() - start
 
228
//===========================================================================
 
229
//
 
230
//Description:
 
231
//
 
232
//    This function attempts to add a device to the logical device list.
 
233
//If the object is successfully added to this manager's logical device
 
234
//list, the logical addition is passed to the next manager.
 
235
//
 
236
//Parameters:
 
237
//
 
238
//Return Value:
 
239
//
 
240
//  2 = The device was added to this manager's logical device list
 
241
//      but could not be added to a higher level manager's logical
 
242
//      device list (An incomplete bubble).
 
243
//  1 = The device was added to or already existed in this manager's
 
244
//      logical device list and all higher level manager's logical
 
245
//      device lists.
 
246
//  0 = The device could not be added to this manager's logical device
 
247
//      list.
 
248
//
 
249
//Global Variables Affected:
 
250
//
 
251
//Remarks: (Side effects, Assumptions, Warnings...)
 
252
//
 
253
//
 
254
//---------------------------------------------------------------------------
 
255
 
 
256
uSHORT  dptCoreMgr_C::bubble(dptCoreDev_C *inDev_P)
 
257
{
 
258
 
 
259
   uSHORT               retVal = 0;
 
260
 
 
261
  // Check if the device already exists
 
262
if (logList.exists(inDev_P))
 
263
   retVal = 1;
 
264
else {
 
265
     // If the pre-add logical functions were performed OK...
 
266
   if (preAddLog(inDev_P)) {
 
267
        // Attempt to add the device to the logical device list
 
268
      if (logList.add(inDev_P)) {
 
269
           // Set the object's highest visible level
 
270
         inDev_P->visibleLevel = level;
 
271
           // Call the post enter logical handler
 
272
         postAddLog(inDev_P);
 
273
         retVal = 1;
 
274
      }
 
275
   }
 
276
}
 
277
 
 
278
if (retVal==1) {
 
279
   if (myMgr_P()!=NULL) {
 
280
        // Pass the addition up the attachment chain
 
281
      retVal = ((dptCoreMgr_C *)myMgr_P())->bubble(inDev_P);
 
282
        // If the next level failed, indicate an incomplete bubble
 
283
      if (retVal==0) retVal = 2;
 
284
   }
 
285
}
 
286
 
 
287
return (retVal);
 
288
 
 
289
}
 
290
//dptCoreMgr_C::bubble() - end
 
291
 
 
292
 
 
293
//Function - dptCoreMgr_C::remLogical() - start
 
294
//===========================================================================
 
295
//
 
296
//Description:
 
297
//
 
298
//    This function removes the specified device from this manager's
 
299
//logical device list and passes the removal request up the attachment
 
300
//chain.
 
301
//
 
302
//Parameters:
 
303
//
 
304
//Return Value:
 
305
//
 
306
//Global Variables Affected:
 
307
//
 
308
//Remarks: (Side effects, Assumptions, Warnings...)
 
309
//
 
310
//
 
311
//---------------------------------------------------------------------------
 
312
 
 
313
void    dptCoreMgr_C::remLogical(dptCoreDev_C *dev_P)
 
314
{
 
315
 
 
316
  // Remove the device from this manager's logical device list
 
317
logList.remove(dev_P);
 
318
 
 
319
if (attachedTo_P!=NULL)
 
320
     // Pass the logical removal up the attachment chain
 
321
   attachedTo_P->remLogical(dev_P);
 
322
 
 
323
}
 
324
//dptCoreMgr_C::remLogical() - end
 
325
 
 
326
 
 
327
//Function - dptCoreMgr_C::remFromMgr() - start
 
328
//===========================================================================
 
329
//
 
330
//Description:
 
331
//
 
332
//    This function removes the specified object from this manager's lists.
 
333
//
 
334
//Parameters:
 
335
//
 
336
//Return Value:
 
337
//
 
338
//Global Variables Affected:
 
339
//
 
340
//Remarks: (Side effects, Assumptions, Warnings...)
 
341
//
 
342
//
 
343
//---------------------------------------------------------------------------
 
344
 
 
345
void    dptCoreMgr_C::remFromMgr(dptCoreObj_C *obj_P)
 
346
{
 
347
 
 
348
  // If the object is a manager...
 
349
if (obj_P->isManager())
 
350
     // Delete all the manager's objects
 
351
   ((dptCoreMgr_C *)obj_P)->delAllObjects();
 
352
else
 
353
     // Remove from this manager's logical device list & all
 
354
     // higher level manager's logical device lists
 
355
   remLogical((dptCoreDev_C *)obj_P);
 
356
 
 
357
  // Remove the object from this manager's physical device list
 
358
phyList.remove(obj_P);
 
359
 
 
360
}
 
361
//dptCoreMgr_C::remFromMgr() - end
 
362
 
 
363
 
 
364
//Function - dptCoreMgr_C::delAllObjects() - start
 
365
//===========================================================================
 
366
//
 
367
//Description:
 
368
//
 
369
//    This function deletes all objects attached directly to this manager.
 
370
//
 
371
//Parameters:
 
372
//
 
373
//Return Value:
 
374
//
 
375
//Global Variables Affected:
 
376
//
 
377
//Remarks: (Side effects, Assumptions, Warnings...)
 
378
//
 
379
//
 
380
//---------------------------------------------------------------------------
 
381
 
 
382
void    dptCoreMgr_C::delAllObjects()
 
383
{
 
384
 
 
385
   dptCoreDev_C         *dev_P;
 
386
   dptCoreObj_C         *obj_P;
 
387
 
 
388
  // Delete all logical devices attached directly to this manager
 
389
dev_P = (dptCoreDev_C *) logList.reset();
 
390
while (dev_P!=NULL) {
 
391
   if (dev_P->isMyObject(this) && dev_P->isLogical()) {
 
392
        // Remove the device from any higher level manager's log lists
 
393
      if (attachedTo_P!=NULL)
 
394
           // Pass the logical removal up the attachment chain
 
395
         attachedTo_P->remLogical(dev_P);
 
396
 
 
397
        // Remove the device from the connection's lists
 
398
      myConn_P()->remFromCon(dev_P);
 
399
        // Delete the device
 
400
      delete(dev_P);
 
401
        // Remove the device from this manager's logical device list
 
402
      dev_P = (dptCoreDev_C *) logList.remove();
 
403
   }
 
404
   else
 
405
        // Get the next logical device
 
406
      dev_P = (dptCoreDev_C *) logList.next();
 
407
}
 
408
 
 
409
  // Delete all physical objects attached directly to this manager
 
410
obj_P = (dptCoreObj_C *) phyList.reset();
 
411
while (obj_P!=NULL) {
 
412
     // If the object is a manager...
 
413
   if (obj_P->isManager())
 
414
        // Delete all of the sub-manager's objects
 
415
      ((dptCoreMgr_C *)obj_P)->delAllObjects();
 
416
   else
 
417
        // Remove from this manager's logical device list & all
 
418
        // higher level manager's logical device lists
 
419
      remLogical((dptCoreDev_C *)obj_P);
 
420
 
 
421
     // Remove the object from the connection's lists
 
422
   myConn_P()->remFromCon(obj_P);
 
423
     // Delete the object
 
424
   delete(obj_P);
 
425
     // Remove the object from this manager's physical object list
 
426
   obj_P = (dptCoreObj_C *) phyList.remove();
 
427
}
 
428
 
 
429
}
 
430
//dptCoreMgr_C::delAllObjects() - end
 
431
 
 
432
 
 
433
//Function - dptCoreMgr_C::getDevLevel() - start
 
434
//===========================================================================
 
435
//
 
436
//Description:
 
437
//
 
438
//    This function determines the logical level of the attached device.
 
439
//
 
440
//Parameters:
 
441
//
 
442
//Return Value:
 
443
//
 
444
//Global Variables Affected:
 
445
//
 
446
//Remarks: (Side effects, Assumptions, Warnings...)
 
447
//
 
448
//
 
449
//---------------------------------------------------------------------------
 
450
 
 
451
uSHORT  dptCoreMgr_C::getDevLevel(dptCoreDev_C *dev_P)
 
452
{
 
453
 
 
454
   uSHORT       retVal = level;
 
455
 
 
456
if (dev_P->isPhysical())
 
457
   retVal++;
 
458
 
 
459
return (retVal);
 
460
 
 
461
}
 
462
//dptCoreMgr_C::getDevLevel() - end
 
463
 
 
464
 
 
465