pnfs: only return-on-close for last close

added pnfs_layout.open_count to count open references, and only return the layout when pnfs_open_state_close() takes the open_count to 0

use InterlockedIncrement/Decrement to avoid an exclusive lock on the layout

Signed-off-by: Casey Bodley <cbodley@citi.umich.edu>
This commit is contained in:
Casey Bodley 2011-02-21 16:53:08 -08:00 committed by unknown
parent 83ab0b3f86
commit d7e438be5e
2 changed files with 10 additions and 6 deletions

View file

@ -163,6 +163,7 @@ typedef struct __pnfs_layout {
enum pnfs_iomode iomode;
enum pnfs_layout_status status;
bool_t return_on_close;
LONG open_count; /* for return on last close */
uint32_t io_count; /* number of pending io operations */
SRWLOCK lock;
} pnfs_layout;

View file

@ -539,10 +539,11 @@ enum pnfs_status pnfs_open_state_layout(
if (status) {
status = file_layout_find_or_create(layouts, &state->file.fh, &layout);
if (status == PNFS_SUCCESS) {
LONG open_count = InterlockedIncrement(&layout->layout.open_count);
state->layout = layout;
dprintf(FLLVL, "pnfs_open_state_layout() caching layout %p\n",
state->layout);
dprintf(FLLVL, "pnfs_open_state_layout() caching layout %p "
"(%u opens)\n", state->layout, open_count);
}
}
@ -576,7 +577,7 @@ void pnfs_open_state_close(
IN bool_t remove)
{
pnfs_file_layout *layout;
bool_t return_on_close;
bool_t return_layout;
enum pnfs_status status;
AcquireSRWLockExclusive(&state->lock);
@ -585,12 +586,14 @@ void pnfs_open_state_close(
ReleaseSRWLockExclusive(&state->lock);
if (layout) {
/* check if we need to return the layout on close */
LONG open_count = InterlockedDecrement(&layout->layout.open_count);
AcquireSRWLockShared(&layout->layout.lock);
return_on_close = layout->layout.return_on_close;
/* only return on close if it's the last close */
return_layout = layout->layout.return_on_close && (open_count <= 0);
ReleaseSRWLockShared(&layout->layout.lock);
if (return_on_close) {
if (return_layout) {
status = file_layout_return(session, &state->file, layout);
if (status)
eprintf("file_layout_return() failed with %s\n",