/** * flush all cache entries for a given disk partition. * * @param[in] part disk partition object * * @return operation status * @retval 0 success * * @internal */ int _VVGC_flush_part(struct DiskPartition64 * part) { int code; VOL_LOCK; code = _VVGC_flush_part_r(part); VOL_UNLOCK; return code; }
/** * scan a disk partition for .vol files * * @param[in] part disk partition object * * @pre VOL_LOCK is NOT held * * @return operation status * @retval 0 success * @retval -1 invalid disk partition object * @retval -2 failed to flush stale entries for this partition * * @internal */ static int _VVGC_scan_partition(struct DiskPartition64 * part) { int code, res; DIR *dirp = NULL; VVGCache_scan_table_t tbl; char *part_path = NULL; code = _VVGC_scan_table_init(&tbl); if (code) { ViceLog(0, ("VVGC_scan_partition: could not init scan table; error = %d\n", code)); goto done; } part_path = VPartitionPath(part); if (part_path == NULL) { ViceLog(0, ("VVGC_scan_partition: invalid partition object given; aborting scan\n")); code = -1; goto done; } VOL_LOCK; res = _VVGC_flush_part_r(part); if (res) { ViceLog(0, ("VVGC_scan_partition: error flushing partition %s; error = %d\n", VPartitionPath(part), res)); code = -2; } VOL_UNLOCK; if (code) { goto done; } dirp = opendir(part_path); if (dirp == NULL) { ViceLog(0, ("VVGC_scan_partition: could not open %s, aborting scan; error = %d\n", part_path, errno)); code = -1; goto done; } ViceLog(5, ("VVGC_scan_partition: scanning partition %s for VG cache\n", part_path)); code = VWalkVolumeHeaders(part, part_path, _VVGC_RecordHeader, _VVGC_UnlinkHeader, &tbl); if (code < 0) { goto done; } _VVGC_scan_table_flush(&tbl, part); done: if (dirp) { closedir(dirp); dirp = NULL; } if (code) { ViceLog(0, ("VVGC_scan_partition: error %d while scanning %s\n", code, part_path)); } else { ViceLog(0, ("VVGC_scan_partition: finished scanning %s: %lu volumes in %lu groups\n", part_path, tbl.newvols, tbl.newvgs)); } VOL_LOCK; _VVGC_flush_dlist(part); free(VVGCache.part[part->index].dlist_hash_buckets); VVGCache.part[part->index].dlist_hash_buckets = NULL; if (code) { _VVGC_state_change(part, VVGC_PART_STATE_INVALID); } else { _VVGC_state_change(part, VVGC_PART_STATE_VALID); } VOL_UNLOCK; return code; }