windows-cm_volume-recycling-20060825
[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                 if (!volp)
435                     osi_panic("Exceeded Max Volumes", __FILE__, __LINE__);
436             }
437
438             if (volp) {
439                 volp->rwID = volp->roID = volp->bkID = 0;
440                 volp->dotdotFid.cell = 0;
441                 volp->dotdotFid.volume = 0;
442                 volp->dotdotFid.unique = 0;
443                 volp->dotdotFid.vnode = 0;
444             } else {
445                 volp = &cm_data.volumeBaseAddress[cm_data.currentVolumes++];
446                 memset(volp, 0, sizeof(cm_volume_t));
447                 volp->magic = CM_VOLUME_MAGIC;
448                 volp->nextp = cm_data.allVolumesp;
449                 cm_data.allVolumesp = volp;
450                 lock_InitializeMutex(&volp->mx, "cm_volume_t mutex");
451             }
452             volp->cellp = cellp;
453             strncpy(volp->namep, volumeNamep, VL_MAXNAMELEN);
454             volp->namep[VL_MAXNAMELEN-1] = '\0';
455             volp->refCount = 1; /* starts off held */
456             volp->flags = CM_VOLUMEFLAG_RESET;
457         }
458         else {
459             volp->refCount++;
460         }
461         
462         /* next should work since no one could have gotten ptr to this structure yet */
463         lock_ReleaseWrite(&cm_volumeLock);
464         lock_ObtainMutex(&volp->mx);
465         
466         if (volp->flags & CM_VOLUMEFLAG_RESET) {
467             code = cm_UpdateVolume(cellp, userp, reqp, volp);
468             if (code == 0)
469                 volp->flags &= ~CM_VOLUMEFLAG_RESET;
470         }
471
472         if (code == 0)
473             *outVolpp = volp;
474         lock_ReleaseMutex(&volp->mx);
475         return code;
476 }
477
478 void cm_ForceUpdateVolume(cm_fid_t *fidp, cm_user_t *userp, cm_req_t *reqp)
479 {
480         cm_cell_t *cellp;
481         cm_volume_t *volp;
482
483         if (!fidp) return;
484
485         cellp = cm_FindCellByID(fidp->cell);
486         if (!cellp) return;
487
488         /* search for the volume */
489         lock_ObtainWrite(&cm_volumeLock);
490         for(volp = cm_data.allVolumesp; volp; volp=volp->nextp) {
491                 if (cellp == volp->cellp &&
492                         (fidp->volume == volp->rwID ||
493                          fidp->volume == volp->roID ||
494                          fidp->volume == volp->bkID))
495                                 break;
496         }
497
498         /* hold the volume if we found it */
499         if (volp) volp->refCount++;
500         lock_ReleaseWrite(&cm_volumeLock);
501
502         /* update it */
503         cm_data.mountRootGen = time(NULL);
504         lock_ObtainMutex(&volp->mx);
505         volp->flags |= CM_VOLUMEFLAG_RESET;
506 #ifdef COMMENT
507     /* Mark the volume to be updated but don't update it now.
508      * This function is called only from within cm_Analyze
509      * when cm_ConnByMServers has failed with all servers down
510      * The problem is that cm_UpdateVolume is going to call
511      * cm_ConnByMServers which may cause a recursive chain
512      * of calls each returning a retry on failure.
513      * Instead, set the flag so the next time the volume is
514      * accessed by Name or ID the UpdateVolume call will
515      * occur.
516      */
517         code = cm_UpdateVolume(cellp, userp, reqp, volp);
518         if (code == 0)
519                 volp->flags &= ~CM_VOLUMEFLAG_RESET;
520 #endif
521         lock_ReleaseMutex(&volp->mx);
522
523         cm_PutVolume(volp);
524 }
525
526 /* find the appropriate servers from a volume */
527 cm_serverRef_t **cm_GetVolServers(cm_volume_t *volp, unsigned long volume)
528 {
529     cm_serverRef_t **serverspp;
530     cm_serverRef_t *current;;
531
532     lock_ObtainWrite(&cm_serverLock);
533
534     if (volume == volp->rwID)
535         serverspp = &volp->rwServersp;
536     else if (volume == volp->roID)
537         serverspp = &volp->roServersp;
538     else if (volume == volp->bkID)
539         serverspp = &volp->bkServersp;
540     else 
541         osi_panic("bad volume ID in cm_GetVolServers", __FILE__, __LINE__);
542         
543     for (current = *serverspp; current; current = current->next)
544         current->refCount++;
545
546     lock_ReleaseWrite(&cm_serverLock);
547
548     return serverspp;
549 }
550
551 void cm_PutVolume(cm_volume_t *volp)
552 {
553     lock_ObtainWrite(&cm_volumeLock);
554     osi_assert(volp->refCount-- > 0);
555     lock_ReleaseWrite(&cm_volumeLock);
556 }
557
558 /* return the read-only volume, if there is one, or the read-write volume if
559  * not.
560  */
561 long cm_GetROVolumeID(cm_volume_t *volp)
562 {
563         long id;
564
565         lock_ObtainMutex(&volp->mx);
566         if (volp->roID && volp->roServersp)
567                 id = volp->roID;
568         else
569                 id = volp->rwID;
570         lock_ReleaseMutex(&volp->mx);
571
572         return id;
573 }
574
575 void cm_CheckVolumes(void)
576 {
577         cm_volume_t *volp;
578
579         cm_data.mountRootGen = time(NULL);
580         lock_ObtainWrite(&cm_volumeLock);
581         for (volp = cm_data.allVolumesp; volp; volp=volp->nextp) {
582                 volp->refCount++;
583                 lock_ReleaseWrite(&cm_volumeLock);
584                 lock_ObtainMutex(&volp->mx);
585
586                 volp->flags |= CM_VOLUMEFLAG_RESET;
587
588                 lock_ReleaseMutex(&volp->mx);
589                 lock_ObtainWrite(&cm_volumeLock);
590                 osi_assert(volp->refCount-- > 0);
591         }
592         lock_ReleaseWrite(&cm_volumeLock);
593
594         /* We should also refresh cached mount points */
595 }
596
597 /*
598 ** Finds all volumes that reside on this server and reorders their
599 ** RO list according to the changed rank of server.
600 */
601 void cm_ChangeRankVolume(cm_server_t       *tsp)
602 {
603         int             code;
604         cm_volume_t*    volp;
605
606         /* find volumes which might have RO copy on server*/
607         lock_ObtainWrite(&cm_volumeLock);
608         for(volp = cm_data.allVolumesp; volp; volp=volp->nextp)
609         {
610                 code = 1 ;      /* assume that list is unchanged */
611                 volp->refCount++;
612                 lock_ReleaseWrite(&cm_volumeLock);
613                 lock_ObtainMutex(&volp->mx);
614
615                 if ((tsp->cellp==volp->cellp) && (volp->roServersp))
616                     code =cm_ChangeRankServer(&volp->roServersp, tsp);
617
618                 /* this volume list was changed */
619                 if ( !code )
620                         cm_RandomizeServer(&volp->roServersp);
621
622                 lock_ReleaseMutex(&volp->mx);
623                 lock_ObtainWrite(&cm_volumeLock);
624                 osi_assert(volp->refCount-- > 0);
625         }
626         lock_ReleaseWrite(&cm_volumeLock);
627 }