djgpp-killer-20060801
[openafs.git] / src / WINNT / afsd / cm_volume.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #include <afs/param.h>
11 #include <afs/stds.h>
12
13 #include <windows.h>
14 #include <winsock2.h>
15 #include <nb30.h>
16 #include <string.h>
17 #include <malloc.h>
18 #include "afsd.h"
19 #include <osi.h>
20 #include <rx/rx.h>
21
22 osi_rwlock_t cm_volumeLock;
23
24 long 
25 cm_ValidateVolume(void)
26 {
27     cm_volume_t * volp;
28     afs_uint32 count;
29
30     for (volp = cm_data.allVolumesp, count = 0; volp; volp=volp->nextp, count++) {
31         if ( volp->magic != CM_VOLUME_MAGIC ) {
32             afsi_log("cm_ValidateVolume failure: volp->magic != CM_VOLUME_MAGIC");
33             fprintf(stderr, "cm_ValidateVolume failure: volp->magic != CM_VOLUME_MAGIC\n");
34             return -1;
35         }
36         if ( volp->cellp && volp->cellp->magic != CM_CELL_MAGIC ) {
37             afsi_log("cm_ValidateVolume failure: volp->cellp->magic != CM_CELL_MAGIC");
38             fprintf(stderr, "cm_ValidateVolume failure: volp->cellp->magic != CM_CELL_MAGIC\n");
39             return -2;
40         }
41         if ( volp->nextp && volp->nextp->magic != CM_VOLUME_MAGIC ) {
42             afsi_log("cm_ValidateVolume failure: volp->nextp->magic != CM_VOLUME_MAGIC");
43             fprintf(stderr, "cm_ValidateVolume failure: volp->nextp->magic != CM_VOLUME_MAGIC\n");
44             return -3;
45         }
46         if ( count != 0 && volp == cm_data.allVolumesp || 
47              count > cm_data.maxVolumes ) {
48             afsi_log("cm_ValidateVolume failure: cm_data.allVolumep loop detected");
49             fprintf(stderr, "cm_ValidateVolume failure: cm_data.allVolumep loop detected\n");
50             return -4;
51         }
52     }
53
54     if ( count != cm_data.currentVolumes ) {
55         afsi_log("cm_ValidateVolume failure: count != cm_data.currentVolumes");
56         fprintf(stderr, "cm_ValidateVolume failure: count != cm_data.currentVolumes\n");
57         return -5;
58     }
59     
60     return 0;
61 }
62
63 long
64 cm_ShutdownVolume(void)
65 {
66     cm_volume_t * volp;
67
68     for (volp = cm_data.allVolumesp; volp; volp=volp->nextp)
69         lock_FinalizeMutex(&volp->mx);
70
71     return 0;
72 }
73
74 void cm_InitVolume(int newFile, long maxVols)
75 {
76     static osi_once_t once;
77
78     if (osi_Once(&once)) {
79         lock_InitializeRWLock(&cm_volumeLock, "cm global volume lock");
80
81         if ( newFile ) {
82             cm_data.allVolumesp = NULL;
83             cm_data.currentVolumes = 0;
84             cm_data.maxVolumes = maxVols;
85         } else {
86             cm_volume_t * volp;
87
88             for (volp = cm_data.allVolumesp; volp; volp=volp->nextp) {
89                 lock_InitializeMutex(&volp->mx, "cm_volume_t mutex");
90                 volp->flags |= CM_VOLUMEFLAG_RESET;
91                 volp->rwServersp = NULL;
92                 volp->roServersp = NULL;
93                 volp->bkServersp = NULL;
94             }
95         }
96         osi_EndOnce(&once);
97     }
98 }
99
100 /*
101  * Update a volume.  Caller holds volume's lock (volp->mx).
102  *
103  *
104  *  shadow / openafs / jhutz@CS.CMU.EDU {ANDREW.CMU.EDU}  01:38    (JHutz)
105  *    Yes, we support multihomed fileservers.
106  *    Since before we got the code from IBM.
107  *    But to find out about multiple addresses on a multihomed server, you need
108  *    to use VL_GetEntryByNameU and VL_GetAddrsU.  If you use
109  *    VL_GetEntryByNameO or VL_GetEntryByNameN, the vlserver just gives you one
110  *    address per server.
111  *  shadow / openafs / jhutz@CS.CMU.EDU {ANDREW.CMU.EDU}  01:39    (JHutz)
112  *    see src/afs/afs_volume.c, paying particular attention to
113  *    afs_NewVolumeByName, afs_SetupVolume, and InstallUVolumeEntry
114  *  shadow / openafs / jaltman {ANDREW.CMU.EDU}  01:40    (Jeffrey Altman)
115  *    thanks.  The windows client calls the 0 versions.
116  *  shadow / openafs / jhutz@CS.CMU.EDU {ANDREW.CMU.EDU}  01:51    (JHutz)
117  *    Oh.  Ew.
118  *    By not using the N versions, you only get up to 8 sites instead of 13.
119  *    By not using the U versions, you don't get to know about multihomed serve
120  *  shadow / openafs / jhutz@CS.CMU.EDU {ANDREW.CMU.EDU}  01:52    (JHutz)
121  *    Of course, you probably want to support the older versions for backward
122  *    compatibility.  If you do that, you need to call the newest interface
123  *    first, and fall back to successively older versions if you get
124  *    RXGEN_OPCODE.
125  */
126 #define MULTIHOMED 1
127 long cm_UpdateVolume(struct cm_cell *cellp, cm_user_t *userp, cm_req_t *reqp,
128         cm_volume_t *volp)
129 {
130     cm_conn_t *connp;
131     int i, j, k;
132     cm_serverRef_t *tsrp;
133     cm_server_t *tsp;
134     struct sockaddr_in tsockAddr;
135     long tflags;
136     u_long tempAddr;
137     struct vldbentry vldbEntry;
138     struct nvldbentry nvldbEntry;
139 #ifdef MULTIHOMED
140     struct uvldbentry uvldbEntry;
141 #endif
142     int type = -1;
143     int ROcount = 0;
144     long code;
145
146     /* clear out old bindings */
147     if (volp->rwServersp)
148         cm_FreeServerList(&volp->rwServersp);
149     if (volp->roServersp)
150         cm_FreeServerList(&volp->roServersp);
151     if (volp->bkServersp)
152         cm_FreeServerList(&volp->bkServersp);
153
154 #ifdef AFS_FREELANCE_CLIENT
155     if ( cellp->cellID == AFS_FAKE_ROOT_CELL_ID && atoi(volp->namep)==AFS_FAKE_ROOT_VOL_ID ) 
156     {
157         memset(&vldbEntry, 0, sizeof(vldbEntry));
158         vldbEntry.flags |= VLF_RWEXISTS;
159         vldbEntry.volumeId[0] = AFS_FAKE_ROOT_VOL_ID;
160         code = 0;
161         type = 0;
162     } else
163 #endif
164     {
165         /* now we have volume structure locked and held; make RPC to fill it */
166         osi_Log2(afsd_logp, "CALL VL_GetEntryByName{UNO} name %s:%s", volp->cellp->name, volp->namep);
167         do {
168             code = cm_ConnByMServers(cellp->vlServersp, userp, reqp, &connp);
169             if (code) 
170                 continue;
171 #ifdef MULTIHOMED
172             code = VL_GetEntryByNameU(connp->callp, volp->namep, &uvldbEntry);
173             type = 2;
174             if ( code == RXGEN_OPCODE ) 
175 #endif
176             {
177                 code = VL_GetEntryByNameN(connp->callp, volp->namep, &nvldbEntry);
178                 type = 1;
179             }
180             if ( code == RXGEN_OPCODE ) {
181                 code = VL_GetEntryByNameO(connp->callp, volp->namep, &vldbEntry);
182                 type = 0;
183             }
184         } while (cm_Analyze(connp, userp, reqp, NULL, NULL, cellp->vlServersp, NULL, code));
185         code = cm_MapVLRPCError(code, reqp);
186         if ( code )
187             osi_Log3(afsd_logp, "CALL VL_GetEntryByName{UNO} name %s:%s FAILURE, code 0x%x", 
188                       volp->cellp->name, volp->namep, code);
189         else
190             osi_Log2(afsd_logp, "CALL VL_GetEntryByName{UNO} name %s:%s SUCCESS", 
191                       volp->cellp->name, volp->namep);
192     }
193     if (code == 0) {
194         afs_int32 flags;
195         afs_int32 nServers;
196         afs_int32 rwID;
197         afs_int32 roID;
198         afs_int32 bkID;
199         afs_int32 serverNumber[NMAXNSERVERS];
200         afs_int32 serverFlags[NMAXNSERVERS];
201
202         switch ( type ) {
203         case 0:
204             flags = vldbEntry.flags;
205             nServers = vldbEntry.nServers;
206             rwID = vldbEntry.volumeId[0];
207             roID = vldbEntry.volumeId[1];
208             bkID = vldbEntry.volumeId[2];
209             for ( i=0; i<nServers; i++ ) {
210                 serverFlags[i] = vldbEntry.serverFlags[i];
211                 serverNumber[i] = vldbEntry.serverNumber[i];
212             }
213             break;
214         case 1:
215             flags = nvldbEntry.flags;
216             nServers = nvldbEntry.nServers;
217             rwID = nvldbEntry.volumeId[0];
218             roID = nvldbEntry.volumeId[1];
219             bkID = nvldbEntry.volumeId[2];
220             for ( i=0; i<nServers; i++ ) {
221                 serverFlags[i] = nvldbEntry.serverFlags[i];
222                 serverNumber[i] = nvldbEntry.serverNumber[i];
223             }
224             break;
225 #ifdef MULTIHOMED
226         case 2:
227             flags = uvldbEntry.flags;
228             nServers = uvldbEntry.nServers;
229             rwID = uvldbEntry.volumeId[0];
230             roID = uvldbEntry.volumeId[1];
231             bkID = uvldbEntry.volumeId[2];
232             for ( i=0, j=0; i<nServers && j<NMAXNSERVERS; i++ ) {
233                 if ( !(uvldbEntry.serverFlags[i] & VLSERVER_FLAG_UUID) ) {
234                     serverFlags[j] = uvldbEntry.serverFlags[i];
235                     serverNumber[j] = uvldbEntry.serverNumber[i].time_low;
236                     j++;
237                 } else {
238                     afs_uint32 * addrp, nentries, code, unique;
239                     bulkaddrs  addrs;
240                     ListAddrByAttributes attrs;
241                     afsUUID uuid;
242
243                     memset((char *)&attrs, 0, sizeof(attrs));
244                     attrs.Mask = VLADDR_UUID;
245                     attrs.uuid = uvldbEntry.serverNumber[i];
246                     memset((char *)&uuid, 0, sizeof(uuid));
247                     memset((char *)&addrs, 0, sizeof(addrs));
248
249                     do {
250                         code = cm_ConnByMServers(cellp->vlServersp, userp, reqp, &connp);
251                         if (code) 
252                             continue;
253                    
254                         code = VL_GetAddrsU(connp->callp, &attrs, &uuid, &unique, &nentries, &addrs);
255
256                         if (code == 0 && nentries == 0)
257                             code = VL_NOENT;
258                     } while (cm_Analyze(connp, userp, reqp, NULL, NULL, cellp->vlServersp, NULL, code));
259                     code = cm_MapVLRPCError(code, reqp);
260                     if (code)
261                         return code;
262
263                     addrp = addrs.bulkaddrs_val;
264                     for (k = 0; k < nentries && j < NMAXNSERVERS; j++, k++) {
265                         serverFlags[j] = uvldbEntry.serverFlags[i];
266                         serverNumber[j] = addrp[k];
267                     }
268
269                     free(addrs.bulkaddrs_val);  /* This is wrong */
270                 }
271             }
272             nServers = j;                                       /* update the server count */
273             break;
274 #endif
275         }
276
277         /* decode the response */
278         lock_ObtainWrite(&cm_volumeLock);
279         if (flags & VLF_RWEXISTS)
280             volp->rwID = rwID;
281         else
282             volp->rwID = 0;
283         if (flags & VLF_ROEXISTS)
284             volp->roID = roID;
285         else
286             volp->roID = 0;
287         if (flags & VLF_BACKEXISTS)
288             volp->bkID = bkID;
289         else
290             volp->bkID = 0;
291         lock_ReleaseWrite(&cm_volumeLock);
292         for (i=0; i<nServers; i++) {
293             /* create a server entry */
294             tflags = serverFlags[i];
295             if (tflags & VLSF_DONTUSE) 
296                 continue;
297             tsockAddr.sin_family = AF_INET;
298             tempAddr = htonl(serverNumber[i]);
299             tsockAddr.sin_addr.s_addr = tempAddr;
300             tsp = cm_FindServer(&tsockAddr, CM_SERVER_FILE);
301             if (!tsp)
302                 tsp = cm_NewServer(&tsockAddr, CM_SERVER_FILE,
303                                     cellp);
304
305             /* if this server was created by fs setserverprefs */
306             if ( !tsp->cellp ) 
307                 tsp->cellp = cellp;
308
309             osi_assert(tsp != NULL);
310                         
311             /* and add it to the list(s). */
312             /*
313              * Each call to cm_NewServerRef() increments the
314              * ref count of tsp.  These reference will be dropped,
315              * if and when the volume is reset; see reset code
316              * earlier in this function.
317              */
318             if ((tflags & VLSF_RWVOL) && (flags & VLF_RWEXISTS)) {
319                 tsrp = cm_NewServerRef(tsp);
320                 cm_InsertServerList(&volp->rwServersp, tsrp);
321                 lock_ObtainWrite(&cm_serverLock);
322                 tsrp->refCount--;       /* drop allocation reference */
323                 lock_ReleaseWrite(&cm_serverLock);
324             }
325             if ((tflags & VLSF_ROVOL) && (flags & VLF_ROEXISTS)) {
326                 tsrp = cm_NewServerRef(tsp);
327                 cm_InsertServerList(&volp->roServersp, tsrp);
328                 lock_ObtainWrite(&cm_serverLock);
329                 tsrp->refCount--;       /* drop allocation reference */
330                 lock_ReleaseWrite(&cm_serverLock);
331                 ROcount++;
332             }
333             /* We don't use VLSF_BACKVOL !?! */
334             if ((tflags & VLSF_RWVOL) && (flags & VLF_BACKEXISTS)) {
335                 tsrp = cm_NewServerRef(tsp);
336                 cm_InsertServerList(&volp->bkServersp, tsrp);
337                 lock_ObtainWrite(&cm_serverLock);
338                 tsrp->refCount--;       /* drop allocation reference */
339                 lock_ReleaseWrite(&cm_serverLock);
340             }
341             /* Drop the reference obtained by cm_FindServer() */
342             cm_PutServer(tsp);
343         }       
344
345         /*
346          * Randomize RO list
347          *
348          * If the first n servers have the same ipRank, then we 
349          * randomly pick one among them and move it to the beginning.
350          * We don't bother to re-order the whole list because
351          * the rest of the list is used only if the first server is
352          * down.  We only do this for the RO list; we assume the other
353          * lists are length 1.
354          */
355         if (ROcount > 1) {
356             cm_RandomizeServer(&volp->roServersp);
357         }
358     }
359     return code;
360 }
361
362 long cm_GetVolumeByID(cm_cell_t *cellp, long volumeID, cm_user_t *userp,
363         cm_req_t *reqp, cm_volume_t **outVolpp)
364 {
365         cm_volume_t *volp;
366         char volNameString[100];
367         long code;
368
369         lock_ObtainWrite(&cm_volumeLock);
370         for(volp = cm_data.allVolumesp; volp; volp=volp->nextp) {
371                 if (cellp == volp->cellp &&
372                         ((unsigned) volumeID == volp->rwID ||
373                          (unsigned) volumeID == volp->roID ||
374                          (unsigned) volumeID == volp->bkID))
375                                 break;
376         }
377
378         /* hold the volume if we found it */
379     if (volp) 
380         volp->refCount++;
381         lock_ReleaseWrite(&cm_volumeLock);
382         
383         /* return it held */
384         if (volp) {
385                 lock_ObtainMutex(&volp->mx);
386         
387                 if (volp->flags & CM_VOLUMEFLAG_RESET) {
388                         code = cm_UpdateVolume(cellp, userp, reqp, volp);
389                         if (code == 0) {
390                                 volp->flags &= ~CM_VOLUMEFLAG_RESET;
391                         }
392                 }
393                 else
394                         code = 0;
395                 lock_ReleaseMutex(&volp->mx);
396                 if (code == 0)
397                         *outVolpp = volp;
398                 return code;
399         }
400         
401         /* otherwise, we didn't find it so consult the VLDB */
402         sprintf(volNameString, "%u", volumeID);
403         code = cm_GetVolumeByName(cellp, volNameString, userp, reqp,
404                                   0, outVolpp);
405         return code;
406 }
407
408 long cm_GetVolumeByName(struct cm_cell *cellp, char *volumeNamep,
409         struct cm_user *userp, struct cm_req *reqp,
410         long flags, cm_volume_t **outVolpp)
411 {
412         cm_volume_t *volp;
413         long code;
414         
415         /* initialize this */
416         code = 0;
417
418         lock_ObtainWrite(&cm_volumeLock);
419         for (volp = cm_data.allVolumesp; volp; volp=volp->nextp) {
420             if (cellp == volp->cellp && strcmp(volumeNamep, volp->namep) == 0) {
421                 break;
422             }
423         }
424         
425         /* otherwise, get from VLDB */
426         if (!volp) {
427             if ( cm_data.currentVolumes >= cm_data.maxVolumes ) {
428                 for (volp = cm_data.allVolumesp; volp; volp=volp->nextp) {
429                     if ( volp->refCount == 0 ) {
430                         /* There is one we can re-use */
431                         break;
432                     }
433                 }
434                 osi_panic("Exceeded Max Volumes", __FILE__, __LINE__);
435             }
436
437             if (volp) {
438                 volp->rwID = volp->roID = volp->bkID = 0;
439                 volp->dotdotFid.cell = 0;
440                 volp->dotdotFid.volume = 0;
441                 volp->dotdotFid.unique = 0;
442                 volp->dotdotFid.vnode = 0;
443             } else {
444                 volp = &cm_data.volumeBaseAddress[cm_data.currentVolumes++];
445                 memset(volp, 0, sizeof(cm_volume_t));
446                 volp->magic = CM_VOLUME_MAGIC;
447                 volp->nextp = cm_data.allVolumesp;
448                 cm_data.allVolumesp = volp;
449                 lock_InitializeMutex(&volp->mx, "cm_volume_t mutex");
450             }
451             volp->cellp = cellp;
452             strncpy(volp->namep, volumeNamep, VL_MAXNAMELEN);
453             volp->namep[VL_MAXNAMELEN-1] = '\0';
454             volp->refCount = 1; /* starts off held */
455             volp->flags = CM_VOLUMEFLAG_RESET;
456         }
457         else {
458             volp->refCount++;
459         }
460         
461         /* next should work since no one could have gotten ptr to this structure yet */
462         lock_ReleaseWrite(&cm_volumeLock);
463         lock_ObtainMutex(&volp->mx);
464         
465         if (volp->flags & CM_VOLUMEFLAG_RESET) {
466             code = cm_UpdateVolume(cellp, userp, reqp, volp);
467             if (code == 0)
468                 volp->flags &= ~CM_VOLUMEFLAG_RESET;
469         }
470
471         if (code == 0)
472             *outVolpp = volp;
473         lock_ReleaseMutex(&volp->mx);
474         return code;
475 }
476
477 void cm_ForceUpdateVolume(cm_fid_t *fidp, cm_user_t *userp, cm_req_t *reqp)
478 {
479         cm_cell_t *cellp;
480         cm_volume_t *volp;
481
482         if (!fidp) return;
483
484         cellp = cm_FindCellByID(fidp->cell);
485         if (!cellp) return;
486
487         /* search for the volume */
488         lock_ObtainWrite(&cm_volumeLock);
489         for(volp = cm_data.allVolumesp; volp; volp=volp->nextp) {
490                 if (cellp == volp->cellp &&
491                         (fidp->volume == volp->rwID ||
492                          fidp->volume == volp->roID ||
493                          fidp->volume == volp->bkID))
494                                 break;
495         }
496
497         /* hold the volume if we found it */
498         if (volp) volp->refCount++;
499         lock_ReleaseWrite(&cm_volumeLock);
500
501         /* update it */
502         cm_data.mountRootGen = time(NULL);
503         lock_ObtainMutex(&volp->mx);
504         volp->flags |= CM_VOLUMEFLAG_RESET;
505 #ifdef COMMENT
506     /* Mark the volume to be updated but don't update it now.
507      * This function is called only from within cm_Analyze
508      * when cm_ConnByMServers has failed with all servers down
509      * The problem is that cm_UpdateVolume is going to call
510      * cm_ConnByMServers which may cause a recursive chain
511      * of calls each returning a retry on failure.
512      * Instead, set the flag so the next time the volume is
513      * accessed by Name or ID the UpdateVolume call will
514      * occur.
515      */
516         code = cm_UpdateVolume(cellp, userp, reqp, volp);
517         if (code == 0)
518                 volp->flags &= ~CM_VOLUMEFLAG_RESET;
519 #endif
520         lock_ReleaseMutex(&volp->mx);
521
522         cm_PutVolume(volp);
523 }
524
525 /* find the appropriate servers from a volume */
526 cm_serverRef_t **cm_GetVolServers(cm_volume_t *volp, unsigned long volume)
527 {
528     cm_serverRef_t **serverspp;
529     cm_serverRef_t *current;;
530
531     lock_ObtainWrite(&cm_serverLock);
532
533     if (volume == volp->rwID)
534         serverspp = &volp->rwServersp;
535     else if (volume == volp->roID)
536         serverspp = &volp->roServersp;
537     else if (volume == volp->bkID)
538         serverspp = &volp->bkServersp;
539     else 
540         osi_panic("bad volume ID in cm_GetVolServers", __FILE__, __LINE__);
541         
542     for (current = *serverspp; current; current = current->next)
543         current->refCount++;
544
545     lock_ReleaseWrite(&cm_serverLock);
546
547     return serverspp;
548 }
549
550 void cm_PutVolume(cm_volume_t *volp)
551 {
552     lock_ObtainWrite(&cm_volumeLock);
553     osi_assert(volp->refCount-- > 0);
554     lock_ReleaseWrite(&cm_volumeLock);
555 }
556
557 /* return the read-only volume, if there is one, or the read-write volume if
558  * not.
559  */
560 long cm_GetROVolumeID(cm_volume_t *volp)
561 {
562         long id;
563
564         lock_ObtainMutex(&volp->mx);
565         if (volp->roID && volp->roServersp)
566                 id = volp->roID;
567         else
568                 id = volp->rwID;
569         lock_ReleaseMutex(&volp->mx);
570
571         return id;
572 }
573
574 void cm_CheckVolumes(void)
575 {
576         cm_volume_t *volp;
577
578         cm_data.mountRootGen = time(NULL);
579         lock_ObtainWrite(&cm_volumeLock);
580         for (volp = cm_data.allVolumesp; volp; volp=volp->nextp) {
581                 volp->refCount++;
582                 lock_ReleaseWrite(&cm_volumeLock);
583                 lock_ObtainMutex(&volp->mx);
584
585                 volp->flags |= CM_VOLUMEFLAG_RESET;
586
587                 lock_ReleaseMutex(&volp->mx);
588                 lock_ObtainWrite(&cm_volumeLock);
589                 osi_assert(volp->refCount-- > 0);
590         }
591         lock_ReleaseWrite(&cm_volumeLock);
592
593         /* We should also refresh cached mount points */
594 }
595
596 /*
597 ** Finds all volumes that reside on this server and reorders their
598 ** RO list according to the changed rank of server.
599 */
600 void cm_ChangeRankVolume(cm_server_t       *tsp)
601 {
602         int             code;
603         cm_volume_t*    volp;
604
605         /* find volumes which might have RO copy on server*/
606         lock_ObtainWrite(&cm_volumeLock);
607         for(volp = cm_data.allVolumesp; volp; volp=volp->nextp)
608         {
609                 code = 1 ;      /* assume that list is unchanged */
610                 volp->refCount++;
611                 lock_ReleaseWrite(&cm_volumeLock);
612                 lock_ObtainMutex(&volp->mx);
613
614                 if ((tsp->cellp==volp->cellp) && (volp->roServersp))
615                     code =cm_ChangeRankServer(&volp->roServersp, tsp);
616
617                 /* this volume list was changed */
618                 if ( !code )
619                         cm_RandomizeServer(&volp->roServersp);
620
621                 lock_ReleaseMutex(&volp->mx);
622                 lock_ObtainWrite(&cm_volumeLock);
623                 osi_assert(volp->refCount-- > 0);
624         }
625         lock_ReleaseWrite(&cm_volumeLock);
626 }