]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
afs: Verify osi_UFSOpen worked
authorPerry Ruiter <pruiter@sinenomine.net>
Thu, 29 May 2014 22:51:57 +0000 (15:51 -0700)
committerD Brashear <shadow@your-file-system.com>
Mon, 6 Oct 2014 18:48:07 +0000 (14:48 -0400)
  In some builds (UKERNEL) osi_UFSOpen returns a NULL if it runs
into a problem.  On the other builds osi_UFSOpen simply panics.
afs/afs_cell.c was checking for a NULL return but other callers
were not.  Add checking logic to all callers.
  This is a prepartory patch.  A subsequent patch will have
osi_UFSOpen return NULL rather than panic for other builds too.

Change-Id: I3610a57dff59b84fe5ea8b1c862f3192157f255f
Reviewed-on: http://gerrit.openafs.org/11243
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Chas Williams - CONTRACTOR <chas@cmf.nrl.navy.mil>
Reviewed-by: Garrett Wollman <wollman@csail.mit.edu>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Reviewed-by: D Brashear <shadow@your-file-system.com>
src/afs/VNOPS/afs_vnop_read.c
src/afs/VNOPS/afs_vnop_symlink.c
src/afs/VNOPS/afs_vnop_write.c
src/afs/afs_dcache.c
src/afs/afs_init.c
src/afs/afs_volume.c

index 66370f31443bd0bec00dc0e1674943ce799b4779..5d3d1000c7d6665374e6d1241a0ed01e81b79a26 100644 (file)
@@ -485,6 +485,8 @@ afs_UFSReadUIO(afs_dcache_id_t *cacheId, struct uio *tuiop)
     struct osi_file *tfile;
 
     tfile = (struct osi_file *) osi_UFSOpen(cacheId);
+    if (!tfile)
+       return -1;
 
 #if defined(AFS_AIX41_ENV)
     AFS_GUNLOCK();
index 4ab1619d0be90dc19c0913c2612423782d2638dc..0571627b5dba68312e5672bfd43ff902124cecae 100644 (file)
@@ -394,6 +394,12 @@ afs_UFSHandleLink(struct vcache *avc, struct vrequest *areq)
        tlen = len;
        ObtainReadLock(&tdc->lock);
        tfile = osi_UFSOpen(&tdc->f.inode);
+       if (!tfile) {
+           ReleaseReadLock(&tdc->lock);
+           afs_PutDCache(tdc);
+           osi_FreeLargeSpace(rbuf);
+           return ENOENT;
+       }
        code = afs_osi_Read(tfile, -1, rbuf, tlen);
        osi_UFSClose(tfile);
        ReleaseReadLock(&tdc->lock);
index 44d0728583292370f15ee7640927cbfaa187c4bf..086fc9d2173697a961b8451ebfb3340cd51bbf9a 100644 (file)
@@ -104,6 +104,9 @@ afs_UFSWriteUIO(struct vcache *avc, afs_dcache_id_t *inode, struct uio *tuiop)
     int code;
 
     tfile = (struct osi_file *)osi_UFSOpen(inode);
+    if (!tfile)
+       return -1;
+
 #if defined(AFS_AIX41_ENV)
     AFS_GUNLOCK();
     code = VNOP_RDWR(tfile->vnode, UIO_WRITE, FWRITE, tuiop, NULL, NULL,
index dd75e2c847a2ddc74939e5ebe209713cd942a62d..235dce6e8fb238afde57e0acb6fa0650cabb4ae6 100644 (file)
@@ -3115,6 +3115,13 @@ afs_InitCacheFile(char *afile, ino_t ainode)
        if ((tdc->f.states & DWriting) || tdc->f.fid.Fid.Volume == 0)
            fileIsBad = 1;
        tfile = osi_UFSOpen(&tdc->f.inode);
+       if (!tfile) {
+           ReleaseWriteLock(&afs_xdcache);
+           ReleaseWriteLock(&tdc->lock);
+           afs_PutDCache(tdc);
+           return ENOENT;
+       }
+
        code = afs_osi_Stat(tfile, &tstat);
        if (code)
            osi_Panic("initcachefile stat");
index 45d4b12ac1bfd1a78bf01a782829b59c488039a0..d588c75fb71acd01cec6fcfef35aa6731f516c86 100644 (file)
@@ -349,7 +349,7 @@ afs_InitVolumeInfo(char *afile)
  *
  * Environment:
  *     This function is called only during initialization.  The given
- *     file should NOT be truncated to 0 lenght; its contents descrebe
+ *     file should NOT be truncated to 0 length; its contents describe
  *     what data is really in the cache.
  *
  *     WARNING: data will be written to this file over time by AFS.
@@ -472,6 +472,9 @@ afs_InitCacheInfo(char *afile)
        afs_fsfragsize = AFS_MIN_FRAGSIZE;
     }
     tfile = osi_UFSOpen(&cacheInode);
+    if (!tfile)
+       return ENOENT;
+
     afs_osi_Stat(tfile, &tstat);
     cacheInfoModTime = tstat.mtime;
     code = afs_osi_Read(tfile, -1, &theader, sizeof(theader));
index e9996e7d000efb5e2cbf7b4ac626aff644450732..bf53767edd3de76e224a2b569af226c48d67e581 100644 (file)
@@ -201,6 +201,10 @@ afs_UFSGetVolSlot(afs_int32 volid, struct cell *tcell)
             */
            if (afs_FVIndex != tv->vtix) {
                tfile = osi_UFSOpen(&volumeInode);
+               if (!tfile) {
+                   afs_warn("afs_UFSGetVolSlot: unable to open volumeinfo\n");
+                   goto error;
+               }
                code =
                    afs_osi_Read(tfile, sizeof(struct fvolume) * tv->vtix,
                                 &staticFVolume, sizeof(struct fvolume));
@@ -210,7 +214,6 @@ afs_UFSGetVolSlot(afs_int32 volid, struct cell *tcell)
                             (int)code);
                    goto error;
                }
-               afs_FVIndex = tv->vtix;
            }
        }
        afs_FVIndex = tv->vtix;
@@ -221,6 +224,10 @@ afs_UFSGetVolSlot(afs_int32 volid, struct cell *tcell)
        staticFVolume.rootVnode = tv->rootVnode;
        staticFVolume.rootUnique = tv->rootUnique;
        tfile = osi_UFSOpen(&volumeInode);
+       if (!tfile) {
+           afs_warn("afs_UFSGetVolSlot: unable to open volumeinfo\n");
+           goto error;
+       }
        code =
            afs_osi_Write(tfile, sizeof(struct fvolume) * afs_FVIndex,
                          &staticFVolume, sizeof(struct fvolume));
@@ -243,13 +250,20 @@ afs_UFSGetVolSlot(afs_int32 volid, struct cell *tcell)
     for (j = fvTable[FVHash(tcell->cellNum, volid)]; j != 0; j = tf->next) {
        if (afs_FVIndex != j) {
            tfile = osi_UFSOpen(&volumeInode);
-           code =
-               afs_osi_Read(tfile, sizeof(struct fvolume) * j,
-                            &staticFVolume, sizeof(struct fvolume));
-           osi_UFSClose(tfile);
+           if (!tfile) {
+               afs_warn("afs_UFSGetVolSlot: unable to open volumeinfo\n");
+               code = -1;   /* indicate error */
+           } else {
+               code =
+                   afs_osi_Read(tfile, sizeof(struct fvolume) * j,
+                                &staticFVolume, sizeof(struct fvolume));
+               osi_UFSClose(tfile);
+               if (code != sizeof(struct fvolume)) {
+                   afs_warn("afs_SetupVolume: error %d reading volumeinfo\n",
+                            (int)code);
+               }
+           }
            if (code != sizeof(struct fvolume)) {
-               afs_warn("afs_SetupVolume: error %d reading volumeinfo\n",
-                        (int)code);
                /* put tv back on the free list; the data in it is not valid */
                tv->next = afs_freeVolList;
                afs_freeVolList = tv;