static int VGCDel(struct cmd_syndesc * as, void * rock) { afs_int32 code; struct fssync_state state; char * partName; VolumeId parent, child; struct cmd_item *ti; SYNC_response res; if (!(ti = as->parms[CUSTOM_PARMS_OFFSET+0].items)) { /* -partition */ return -1; } partName = ti->data; if (!(ti = as->parms[CUSTOM_PARMS_OFFSET+1].items)) { /* -parent */ return -1; } parent = atoi(ti->data); if (!(ti = as->parms[CUSTOM_PARMS_OFFSET+2].items)) { /* -child */ return -1; } child = atoi(ti->data); common_prolog(as, &state); fprintf(stderr, "calling FSYNC_VCGDel\n"); code = FSYNC_VGCDel(partName, parent, child, state.reason, &res); debug_response(code, &res); VDisconnectFS(); return 0; }
/** * destroy a volume disk header. * * @param[in] dp disk partition object * @param[in] volid volume id * @param[in] parent parent's volume id, 0 if unknown * * @return operation status * @retval 0 success * * @note if parent is 0, the parent volume ID will be looked up from the * fileserver * * @note for non-DAFS, parent is currently ignored */ afs_int32 VDestroyVolumeDiskHeader(struct DiskPartition64 * dp, VolumeId volid, VolumeId parent) { afs_int32 code = 0; char path[MAXPATHLEN]; #ifdef AFS_DEMAND_ATTACH_FS SYNC_response res; #endif /* AFS_DEMAND_ATTACH_FS */ (void)afs_snprintf(path, sizeof(path), "%s/" VFORMAT, VPartitionPath(dp), afs_printable_uint32_lu(volid)); code = unlink(path); if (code) { Log("VDestroyVolumeDiskHeader: Couldn't unlink disk header, error = %d\n", errno); goto done; } #ifdef AFS_DEMAND_ATTACH_FS memset(&res, 0, sizeof(res)); if (!parent) { FSSYNC_VGQry_response_t q_res; code = FSYNC_VGCQuery(dp->name, volid, &q_res, &res); if (code) { Log("VDestroyVolumeDiskHeader: FSYNC_VGCQuery(%s, %lu) failed " "with code %ld, reason %ld\n", dp->name, afs_printable_uint32_lu(volid), afs_printable_int32_ld(code), afs_printable_int32_ld(res.hdr.reason)); goto done; } parent = q_res.rw; } code = FSYNC_VGCDel(dp->name, parent, volid, FSYNC_WHATEVER, &res); if (code) { Log("VDestroyVolumeDiskHeader: FSYNC_VGCDel(%s, %lu, %lu) failed " "with code %ld reason %ld\n", dp->name, afs_printable_uint32_lu(parent), afs_printable_uint32_lu(volid), afs_printable_int32_ld(code), afs_printable_int32_ld(res.hdr.reason)); } #endif /* AFS_DEMAND_ATTACH_FS */ done: return code; }
/** * write an existing volume disk header. * * @param[in] hdr volume disk header * @param[in] dp disk partition object * * @return operation status * @retval 0 success * @retval ENOENT volume header doesn't exist * @retval EIO failed to write volume header */ afs_int32 VWriteVolumeDiskHeader(VolumeDiskHeader_t * hdr, struct DiskPartition64 * dp) { afs_int32 code; #ifdef AFS_DEMAND_ATTACH_FS VolumeDiskHeader_t oldhdr; int delvgc = 0, addvgc = 0; SYNC_response res; /* first, see if anything with the volume IDs have changed; if so, we * need to update the VGC */ code = VReadVolumeDiskHeader(hdr->id, dp, &oldhdr); if (code == 0 && (oldhdr.id != hdr->id || oldhdr.parent != hdr->parent)) { /* the vol id or parent vol id changed; need to delete the VGC entry * for the old vol id/parent, and add the new one */ delvgc = 1; addvgc = 1; } else if (code) { /* couldn't get the old header info; add the new header info to the * VGC in case it hasn't been added yet */ addvgc = 1; } #endif /* AFS_DEMAND_ATTACH_FS */ code = _VWriteVolumeDiskHeader(hdr, dp, 0); if (code) { goto done; } #ifdef AFS_DEMAND_ATTACH_FS if (delvgc) { memset(&res, 0, sizeof(res)); code = FSYNC_VGCDel(dp->name, oldhdr.parent, oldhdr.id, FSYNC_WHATEVER, &res); /* unknown vol id is okay; it just further suggests the old header * data was bogus, which is fine since we're trying to fix it */ if (code && res.hdr.reason != FSYNC_UNKNOWN_VOLID) { Log("VWriteVolumeDiskHeader: FSYNC_VGCDel(%s, %lu, %lu) " "failed with code %ld reason %ld\n", dp->name, afs_printable_uint32_lu(oldhdr.parent), afs_printable_uint32_lu(oldhdr.id), afs_printable_int32_ld(code), afs_printable_int32_ld(res.hdr.reason)); } } if (addvgc) { memset(&res, 0, sizeof(res)); code = FSYNC_VGCAdd(dp->name, hdr->parent, hdr->id, FSYNC_WHATEVER, &res); if (code) { Log("VWriteVolumeDiskHeader: FSYNC_VGCAdd(%s, %lu, %lu) " "failed with code %ld reason %ld\n", dp->name, afs_printable_uint32_lu(hdr->parent), afs_printable_uint32_lu(hdr->id), afs_printable_int32_ld(code), afs_printable_int32_ld(res.hdr.reason)); } } #endif /* AFS_DEMAND_ATTACH_FS */ done: return code; }