vol: avoid query for parent id when deleting disk header
[openafs.git] / src / vol / vg_cache.c
index e9278ef..5a53a2f 100644 (file)
 #include <afsconfig.h>
 #include <afs/param.h>
 
-#ifdef AFS_DEMAND_ATTACH_FS
+#include <roken.h>
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <dirent.h>
-#include <afs/assert.h>
-#include <string.h>
-#ifdef AFS_NT40_ENV
-#include <io.h>
-#else
+#ifdef HAVE_SYS_FILE_H
 #include <sys/file.h>
-#include <sys/param.h>
-#if defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV)
-#include <unistd.h>
 #endif
-#endif /* AFS_NT40_ENV */
+
+#ifdef AFS_DEMAND_ATTACH_FS
+
+#include <afs/opr.h>
+#include <rx/rx_queue.h>
+#include <opr/lock.h>
 #include <lock.h>
 #include <afs/afsutil.h>
-#include <lwp.h>
 #include "nfs.h"
 #include <afs/afsint.h>
 #include "ihandle.h"
@@ -110,7 +101,7 @@ VVGCache_PkgInit(void)
     for (i = 0; i <= VOLMAXPARTS; i++) {
        VVGCache.part[i].state = VVGC_PART_STATE_INVALID;
        VVGCache.part[i].dlist_hash_buckets = NULL;
-       code = pthread_cond_init(&VVGCache.part[i].cv, NULL);
+       CV_INIT(&VVGCache.part[i].cv, "cache part", CV_DEFAULT, 0);
        if (code) {
            goto error;
        }
@@ -142,7 +133,7 @@ VVGCache_PkgShutdown(void)
     /* destroy per-partition VVGC state */
     for (i = 0; i <= VOLMAXPARTS; i++) {
        VVGCache.part[i].state = VVGC_PART_STATE_INVALID;
-       pthread_cond_destroy(&VVGCache.part[i].cv);
+       CV_DESTROY(&VVGCache.part[i].cv);
     }
 
     return EOPNOTSUPP;
@@ -161,19 +152,12 @@ VVGCache_PkgShutdown(void)
 static int
 _VVGC_entry_alloc(VVGCache_entry_t ** entry_out)
 {
-    int code = 0;
-    VVGCache_entry_t * ent;
+    *entry_out = calloc(1, sizeof(VVGCache_entry_t));
 
-    *entry_out = ent = malloc(sizeof(VVGCache_entry_t));
-    if (ent == NULL) {
-       code = ENOMEM;
-       goto error;
-    }
+    if (*entry_out == NULL)
+       return ENOMEM;
 
-    memset(ent, 0, sizeof(*ent));
-
- error:
-    return code;
+    return 0;
 }
 
 /**
@@ -191,7 +175,7 @@ _VVGC_entry_free(VVGCache_entry_t * entry)
 {
     int code = 0;
 
-    assert(entry->refcnt == 0);
+    opr_Assert(entry->refcnt == 0);
     free(entry);
 
     return code;
@@ -380,7 +364,7 @@ _VVGC_entry_put(struct DiskPartition64 * dp, VVGCache_entry_t * entry)
 {
     int code = 0;
 
-    assert(entry->refcnt > 0);
+    opr_Assert(entry->refcnt > 0);
 
     if (--entry->refcnt == 0) {
        VVGCache_entry_t *nentry;
@@ -772,7 +756,7 @@ VVGCache_entry_add_r(struct DiskPartition64 * dp,
        }
     }
 
-    assert(!child_ent);
+    opr_Assert(!child_ent);
     child_ent = parent_ent;
     code = _VVGC_hash_entry_add(dp,
                                child,
@@ -885,32 +869,37 @@ _VVGC_entry_purge_r(struct DiskPartition64 * dp,
                     VolumeId parent, VolumeId child)
 {
     int code = 0, res;
-    VVGCache_entry_t * parent_ent, * child_ent;
+    VVGCache_entry_t * child_ent;
     VVGCache_hash_entry_t * child_hent;
 
-    /* check mappings for each volid */
-    res = _VVGC_lookup(dp, parent, &parent_ent, NULL);
-    if (res) {
-       code = res;
-       goto done;
-    }
     res = _VVGC_lookup(dp, child, &child_ent, &child_hent);
     if (res) {
        code = res;
        goto done;
     }
 
-    /* if the mappings don't match, we have a serious error */
-    if (parent_ent != child_ent) {
-       ViceLog(0, ("VVGCache_entry_del: trying to delete vol %lu from VG %lu, "
-           "but vol %lu points to VGC entry %"AFS_PTR_FMT" and VG %lu "
-           "points to VGC entry %"AFS_PTR_FMT"\n",
-           afs_printable_uint32_lu(child),
-           afs_printable_uint32_lu(parent),
-           afs_printable_uint32_lu(child),
-           child_ent, afs_printable_uint32_lu(parent), parent_ent));
-       code = -1;
-       goto done;
+    if (parent != 0) {
+       VVGCache_entry_t * parent_ent;
+
+       res = _VVGC_lookup(dp, parent, &parent_ent, NULL);
+       if (res) {
+           code = res;
+           goto done;
+       }
+
+       /* if the mappings don't match, we have a serious error */
+       if (parent_ent != child_ent) {
+           ViceLog(0,
+                   ("VVGCache_entry_del: trying to delete vol %lu from VG %lu, "
+                    "but vol %lu points to VGC entry %" AFS_PTR_FMT
+                    " and VG %lu " "points to VGC entry %" AFS_PTR_FMT "\n",
+                    afs_printable_uint32_lu(child),
+                    afs_printable_uint32_lu(parent),
+                    afs_printable_uint32_lu(child), child_ent,
+                    afs_printable_uint32_lu(parent), parent_ent));
+           code = -1;
+           goto done;
+       }
     }
 
     code = _VVGC_hash_entry_del(child_hent);
@@ -1185,7 +1174,7 @@ _VVGC_state_change(struct DiskPartition64 * part,
     VVGCache.part[part->index].state = state;
 
     if (old_state != state) {
-       pthread_cond_broadcast(&VVGCache.part[part->index].cv);
+       CV_BROADCAST(&VVGCache.part[part->index].cv);
     }
 
     return old_state;