ref counting for nfs41_open_state
This commit is contained in:
parent
ae4c67c21e
commit
006bdfa47a
10 changed files with 78 additions and 5 deletions
|
|
@ -61,6 +61,7 @@ static int create_open_state(
|
|||
"%u", open_owner_id);
|
||||
state->owner.owner_len = (uint32_t)strlen(
|
||||
(const char*)state->owner.owner);
|
||||
state->ref_count = 1;
|
||||
|
||||
*state_out = state;
|
||||
status = NO_ERROR;
|
||||
|
|
@ -73,13 +74,33 @@ out_free:
|
|||
}
|
||||
|
||||
static void free_open_state(
|
||||
IN nfs41_session *session,
|
||||
IN nfs41_open_state *state)
|
||||
{
|
||||
free(state);
|
||||
}
|
||||
|
||||
|
||||
void nfs41_open_state_ref(
|
||||
IN nfs41_open_state *state)
|
||||
{
|
||||
const LONG count = InterlockedIncrement(&state->ref_count);
|
||||
|
||||
dprintf(2, "nfs41_open_state_ref(%s) count %d\n",
|
||||
state->path.path, count);
|
||||
}
|
||||
|
||||
void nfs41_open_state_deref(
|
||||
IN nfs41_open_state *state)
|
||||
{
|
||||
const LONG count = InterlockedDecrement(&state->ref_count);
|
||||
|
||||
dprintf(2, "nfs41_open_state_deref(%s) count %d\n",
|
||||
state->path.path, count);
|
||||
if (count == 0)
|
||||
free_open_state(state);
|
||||
}
|
||||
|
||||
|
||||
/* NFS41_OPEN */
|
||||
static int parse_open(unsigned char *buffer, uint32_t length, nfs41_upcall *upcall)
|
||||
{
|
||||
|
|
@ -398,7 +419,7 @@ static int handle_open(nfs41_upcall *upcall)
|
|||
out:
|
||||
return status;
|
||||
out_free_state:
|
||||
free(state);
|
||||
nfs41_open_state_deref(state);
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
|
@ -461,7 +482,7 @@ static void cancel_open(IN nfs41_upcall *upcall)
|
|||
nfs_error_string(status));
|
||||
}
|
||||
|
||||
free_open_state(state->session, state);
|
||||
nfs41_open_state_deref(state);
|
||||
out:
|
||||
status = nfs_to_windows_error(status, ERROR_INTERNAL_ERROR);
|
||||
dprintf(1, "<-- cancel_open() returning %d\n", status);
|
||||
|
|
@ -531,13 +552,20 @@ static int handle_close(nfs41_upcall *upcall)
|
|||
}
|
||||
}
|
||||
|
||||
free_open_state(state->session, state);
|
||||
if (status || !rm_status)
|
||||
return status;
|
||||
else
|
||||
return rm_status;
|
||||
}
|
||||
|
||||
static void cleanup_close(nfs41_upcall *upcall)
|
||||
{
|
||||
close_upcall_args *args = &upcall->args.close;
|
||||
|
||||
/* release the initial reference from create_open_state() */
|
||||
nfs41_open_state_deref(args->state);
|
||||
}
|
||||
|
||||
|
||||
const nfs41_upcall_op nfs41_op_open = {
|
||||
parse_open,
|
||||
|
|
@ -547,5 +575,8 @@ const nfs41_upcall_op nfs41_op_open = {
|
|||
};
|
||||
const nfs41_upcall_op nfs41_op_close = {
|
||||
parse_close,
|
||||
handle_close
|
||||
handle_close,
|
||||
NULL,
|
||||
NULL,
|
||||
cleanup_close
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue