extern "C" void delete_file (char *pathname, struct client client) { struct decafs_file_stat file_info; uint32_t num_chunks = 0, request_id = get_new_request_id(); // If the file doesn't exist if ((decafs_file_sstat (pathname, &file_info, client)) < 0) { // TODO halli check if this change is correct // old call //if (send_delete_result (client, 0, FILE_NOT_FOUND) < 0) { if (send_remove_result (client, FILE_NOT_FOUND) < 0) { printf ("\tDelete result could not reach client.\n"); } return; } if (get_exclusive_lock (client, file_info.file_id) < 0) { // TODO halli check if this change is correct // old call //if (send_delete_result (client, 0, FILE_IN_USE) < 0) { if (send_remove_result (client, FILE_IN_USE) < 0) { printf ("\tDelete result could not reach client.\n"); } return; } // Save the request id. active_delete_requests[request_id] = request_info (client, file_info.file_id); printf ("(request: %d) processing delete file %s\n", request_id, pathname); num_chunks = process_delete_file (request_id, file_info.file_id); assert (delete_request_exists (request_id)); active_delete_requests[request_id].chunks_expected = num_chunks; check_delete_complete(request_id); }
void check_delete_complete (uint32_t request_id) { assert (delete_request_exists (request_id)); if (active_delete_requests[request_id].chunks_expected == 0) { return; } if (active_delete_requests[request_id].chunks_expected == active_delete_requests[request_id].chunks_received) { uint32_t file_id = active_delete_requests[request_id].file_id; struct client client = active_delete_requests[request_id].client; // TODO halli check if this change is correct // old call if (send_delete_result (client, 0, 0) < 0) { if (send_remove_result (client, 0) < 0) { printf ("\tDelete result could not reach client.\n"); } while (delete_file_contents (file_id, client) == NO_METADATA_LOCK) { ; // retry metadata deletion until we succeed } // release the lock on the file release_lock (client, file_id); active_delete_requests.erase (request_id); } }
extern "C" void delete_file(char* pathname, struct client client) { send_remove_result(client, 0); }