static void SalvageClient(VolumeId vid, char * pname) { int done = 0; afs_int32 code; SYNC_response res; SALVSYNC_response_hdr sres; VolumePackageOptions opts; VOptDefaults(volumeUtility, &opts); if (VInitVolumePackage2(volumeUtility, &opts)) { /* VInitVolumePackage2 can fail on e.g. partition attachment errors, * but we don't really care, since all we're doing is trying to use * SALVSYNC */ fprintf(stderr, "errors encountered initializing volume package, but " "trying to continue anyway\n"); } SALVSYNC_clientInit(); code = SALVSYNC_SalvageVolume(vid, pname, SALVSYNC_SALVAGE, SALVSYNC_OPERATOR, 0, NULL); if (code != SYNC_OK) { goto sync_error; } res.payload.buf = (void *) &sres; res.payload.len = sizeof(sres); while(!done) { sleep(2); code = SALVSYNC_SalvageVolume(vid, pname, SALVSYNC_QUERY, SALVSYNC_WHATEVER, 0, &res); if (code != SYNC_OK) { goto sync_error; } switch (sres.state) { case SALVSYNC_STATE_ERROR: printf("salvageserver reports salvage ended in an error; check log files for more details\n"); case SALVSYNC_STATE_DONE: case SALVSYNC_STATE_UNKNOWN: done = 1; } } SALVSYNC_clientFinis(); return; sync_error: if (code == SYNC_DENIED) { printf("salvageserver refused to salvage volume %u on partition %s\n", vid, pname); } else if (code == SYNC_BAD_COMMAND) { printf("SALVSYNC protocol mismatch; please make sure fileserver, volserver, salvageserver and salvager are same version\n"); } else if (code == SYNC_COM_ERROR) { printf("SALVSYNC communications error\n"); } SALVSYNC_clientFinis(); exit(-1); }
static int do_salvop(struct fssync_state * state, afs_int32 command, SYNC_response * res) { afs_int32 code; SALVSYNC_response_hdr hdr_l, *hdr; SYNC_response res_l; if (!res) { res = &res_l; res->payload.len = sizeof(hdr_l); res->payload.buf = hdr = &hdr_l; } else { hdr = (SALVSYNC_response_hdr *) res->payload.buf; } fprintf(stderr, "calling SALVSYNC_SalvageVolume with command code %d (%s)\n", command, command_code_to_string(command)); code = SALVSYNC_SalvageVolume(state->sop->volume, state->sop->partName, command, state->reason, state->sop->prio, res); switch (code) { case SYNC_OK: case SYNC_DENIED: break; default: fprintf(stderr, "possible sync protocol error. return code was %d\n", code); } fprintf(stderr, "SALVSYNC_SalvageVolume returned %d (%s)\n", code, response_code_to_string(code)); fprintf(stderr, "protocol response code was %d (%s)\n", res->hdr.response, response_code_to_string(res->hdr.response)); fprintf(stderr, "protocol reason code was %d (%s)\n", res->hdr.reason, reason_code_to_string(res->hdr.reason)); printf("state = {\n"); if (res->hdr.flags & SALVSYNC_FLAG_VOL_STATS_VALID) { printf("\tstate = %d (%s)\n", hdr->state, state_code_to_string(hdr->state)); printf("\tprio = %d\n", hdr->prio); } printf("\tsq_len = %d\n", hdr->sq_len); printf("\tpq_len = %d\n", hdr->pq_len); printf("}\n"); VDisconnectSALV(); return 0; }