failing rename of onto an opened file

adding a check to see if the destination filename is currently opened by
looking through the list of open states stored for a given client.

fail rename with ERROR_FILE_EXISTS if we find an open.
This commit is contained in:
Olga Kornievskaia 2011-03-22 12:24:50 -04:00 committed by unknown
parent 8d171e71a0
commit 887caeb922

View file

@ -196,6 +196,32 @@ static void open_state_rename(
ReleaseSRWLockExclusive(&state->path.lock);
}
static int nfs41_abs_path_compare(
IN const struct list_entry *entry,
IN const void *value)
{
nfs41_open_state *client = list_container(entry, nfs41_open_state, client_entry);
const nfs41_abs_path *name = (const nfs41_abs_path *)value;
if (client->path.len == name->len &&
!strncmp(client->path.path, name->path, client->path.len))
return NO_ERROR;
return ERROR_FILE_NOT_FOUND;
}
static int is_dst_name_opened(nfs41_abs_path *dst_path, nfs41_session *dst_session)
{
int status;
nfs41_client *client = dst_session->client;
EnterCriticalSection(&client->state.lock);
if (list_search(&client->state.opens, dst_path, nfs41_abs_path_compare))
status = TRUE;
else
status = FALSE;
LeaveCriticalSection(&client->state.lock);
return status;
}
static int handle_nfs41_rename(setattr_upcall_args *args)
{
nfs41_open_state *state = args->state;
@ -294,6 +320,16 @@ static int handle_nfs41_rename(setattr_upcall_args *args)
goto out;
}
status = is_dst_name_opened(&dst_path, dst_session);
if (status) {
/* AGLO: 03/21/2011: we can't handle rename of a file with a filename
* that is currently opened by this client
*/
eprintf("handle_nfs41_rename: %s is opened\n", dst_path.path);
status = ERROR_FILE_EXISTS;
goto out;
}
status = nfs41_rename(state->session,
&state->parent, src_name,
&dst_dir, &dst_name);