afs_open: Deal with afs_GetDCache returning NULL
authorAndrew Deason <adeason@sinenomine.net>
Tue, 6 Nov 2012 05:47:06 +0000 (23:47 -0600)
committerDerrick Brashear <shadow@your-file-system.com>
Tue, 4 Dec 2012 11:21:14 +0000 (03:21 -0800)
afs_open was assuming afs_GetDCache always returned non-NULL. Make it
deal with a NULL return.

Change-Id: Ib0593de27d65294726a4a40b3faa4687bb6fc5fe
Reviewed-on: http://gerrit.openafs.org/8408
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>

src/afs/VNOPS/afs_vnop_open.c

index d5d54ce..b6532c2 100644 (file)
@@ -170,28 +170,29 @@ afs_open(struct vcache **avcp, afs_int32 aflags, afs_ucred_t *acred)
        afs_size_t offset, len;
 
        tdc = afs_GetDCache(tvc, 0, &treq, &offset, &len, 1);
-
-       ObtainSharedLock(&tdc->mflock, 865);
-       if (!(tdc->mflags & DFFetchReq)) {
-           struct brequest *bp;
-
-           /* start the daemon (may already be running, however) */
-           UpgradeSToWLock(&tdc->mflock, 666);
-           tdc->mflags |= DFFetchReq;  /* guaranteed to be cleared by BKG or 
-                                          GetDCache */
-           /* last parm (1) tells bkg daemon to do an afs_PutDCache when it 
-              is done, since we don't want to wait for it to finish before 
-              doing so ourselves.
-           */
-           bp = afs_BQueue(BOP_FETCH, tvc, B_DONTWAIT, 0, acred,
-                           (afs_size_t) 0, (afs_size_t) 1, tdc,
-                           (void *)0, (void *)0);
-           if (!bp) {
-               tdc->mflags &= ~DFFetchReq;
+       if (tdc) {
+           ObtainSharedLock(&tdc->mflock, 865);
+           if (!(tdc->mflags & DFFetchReq)) {
+               struct brequest *bp;
+
+               /* start the daemon (may already be running, however) */
+               UpgradeSToWLock(&tdc->mflock, 666);
+               tdc->mflags |= DFFetchReq;  /* guaranteed to be cleared by BKG or
+                                              GetDCache */
+               /* last parm (1) tells bkg daemon to do an afs_PutDCache when it
+                  is done, since we don't want to wait for it to finish before
+                  doing so ourselves.
+               */
+               bp = afs_BQueue(BOP_FETCH, tvc, B_DONTWAIT, 0, acred,
+                               (afs_size_t) 0, (afs_size_t) 1, tdc,
+                               (void *)0, (void *)0);
+               if (!bp) {
+                   tdc->mflags &= ~DFFetchReq;
+               }
+               ReleaseWriteLock(&tdc->mflock);
+           } else {
+               ReleaseSharedLock(&tdc->mflock);
            }
-           ReleaseWriteLock(&tdc->mflock);
-       } else {
-           ReleaseSharedLock(&tdc->mflock);
        }
     }  
   done: