mirror of
https://github.com/linux-msm/rmtfs.git
synced 2026-04-09 23:10:00 +02:00
storage: Reuse already open caller objects
In the event that the remote crashes, or for other reasons try to open a partition that we already have open we should reuse the caller objects, so that we don't run out of them. This should likely be replaced by a working mechanism for notifications when the remote is going away. Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
This commit is contained in:
14
storage.c
14
storage.c
@@ -19,6 +19,7 @@ struct caller {
|
||||
unsigned node;
|
||||
int fd;
|
||||
unsigned dev_error;
|
||||
const struct partition *partition;
|
||||
};
|
||||
|
||||
static const struct partition partition_table[] = {
|
||||
@@ -46,7 +47,7 @@ int storage_open(void)
|
||||
int storage_get(unsigned node, const char *path)
|
||||
{
|
||||
const struct partition *part;
|
||||
struct caller *caller;
|
||||
struct caller *caller = NULL;
|
||||
int saved_errno;
|
||||
int fd;
|
||||
int i;
|
||||
@@ -60,6 +61,14 @@ int storage_get(unsigned node, const char *path)
|
||||
return -EPERM;
|
||||
|
||||
found:
|
||||
/* Check if this node already has the requested path open */
|
||||
for (i = 0; i < MAX_CALLERS; i++) {
|
||||
if (caller_handles[i].fd != -1 &&
|
||||
caller_handles[i].node == node &&
|
||||
caller_handles[i].partition == part)
|
||||
return caller_handles[i].id;
|
||||
}
|
||||
|
||||
for (i = 0; i < MAX_CALLERS; i++) {
|
||||
if (caller_handles[i].fd == -1) {
|
||||
caller = &caller_handles[i];
|
||||
@@ -81,6 +90,7 @@ found:
|
||||
|
||||
caller->node = node;
|
||||
caller->fd = fd;
|
||||
caller->partition = part;
|
||||
|
||||
return caller->id;
|
||||
}
|
||||
@@ -98,6 +108,8 @@ int storage_put(unsigned node, int caller_id)
|
||||
|
||||
close(caller->fd);
|
||||
caller->fd = -1;
|
||||
caller->partition = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user