folder redirection: made changes to read/write routines to avoid race conditions

ulab-next
Laxmikant Rashinkar 12 years ago
parent 62a4403dd4
commit 2029867510

@ -259,7 +259,7 @@ int dev_redir_get_dir_listing(void *fusep, tui32 device_id, char *path);
int dev_redir_file_open(void *fusep, tui32 device_id, char *path, int dev_redir_file_open(void *fusep, tui32 device_id, char *path,
int mode, int type, char *gen_buf); int mode, int type, char *gen_buf);
int dev_redir_file_read(void *fusep, tui32 device_id, tui32 FileId, int devredir_file_read(void *fusep, tui32 device_id, tui32 FileId,
tui32 Length, tui64 Offset); tui32 Length, tui64 Offset);
int dev_redir_file_write(void *fusep, tui32 device_id, tui32 FileId, int dev_redir_file_write(void *fusep, tui32 device_id, tui32 FileId,
@ -2865,7 +2865,7 @@ static void xfuse_cb_read(fuse_req_t req, fuse_ino_t ino, size_t size,
fusep->device_id = fh->DeviceId; fusep->device_id = fh->DeviceId;
fusep->fi = fi; fusep->fi = fi;
dev_redir_file_read(fusep, fh->DeviceId, fh->FileId, size, off); devredir_file_read(fusep, fh->DeviceId, fh->FileId, size, off);
} }
/** /**

@ -775,16 +775,24 @@ void dev_redir_proc_device_iocompletion(struct stream *s)
log_debug("got CID_READ"); log_debug("got CID_READ");
xstream_rd_u32_le(s, Length); xstream_rd_u32_le(s, Length);
fuse_data = devredir_fuse_data_dequeue(irp); fuse_data = devredir_fuse_data_dequeue(irp);
if (fuse_data == NULL) if (fuse_data == NULL)
log_error("fuse_data is NULL"); log_error("fuse_data is NULL");
xfuse_devredir_cb_read_file(fuse_data->data_ptr, s->p, Length); xfuse_devredir_cb_read_file(fuse_data->data_ptr, s->p, Length);
devredir_irp_delete(irp);
break; break;
case CID_WRITE: case CID_WRITE:
log_debug("got CID_WRITE"); log_debug("got CID_WRITE");
xstream_rd_u32_le(s, Length); xstream_rd_u32_le(s, Length);
fuse_data = devredir_fuse_data_dequeue(irp); fuse_data = devredir_fuse_data_dequeue(irp);
if (fuse_data == NULL)
log_error("fuse_data is NULL");
xfuse_devredir_cb_write_file(fuse_data->data_ptr, s->p, Length); xfuse_devredir_cb_write_file(fuse_data->data_ptr, s->p, Length);
devredir_irp_delete(irp);
break; break;
case CID_CLOSE: case CID_CLOSE:
@ -1172,11 +1180,12 @@ int devredir_rmdir_or_file(void *fusep, tui32 device_id, char *path, int mode)
* @return 0 on success, -1 on failure * @return 0 on success, -1 on failure
*****************************************************************************/ *****************************************************************************/
int dev_redir_file_read(void *fusep, tui32 DeviceId, tui32 FileId, int devredir_file_read(void *fusep, tui32 DeviceId, tui32 FileId,
tui32 Length, tui64 Offset) tui32 Length, tui64 Offset)
{ {
struct stream *s; struct stream *s;
IRP *irp; IRP *irp;
IRP *new_irp;
int bytes; int bytes;
xstream_new(s, 1024); xstream_new(s, 1024);
@ -1188,12 +1197,22 @@ int dev_redir_file_read(void *fusep, tui32 DeviceId, tui32 FileId,
return -1; return -1;
} }
irp->completion_type = CID_READ; /* create a new IRP for this request */
devredir_fuse_data_enqueue(irp, fusep); if ((new_irp = devredir_irp_clone(irp)) == NULL)
{
/* system out of memory */
xfuse_devredir_cb_read_file(fusep, NULL, 0);
return -1;
}
new_irp->FileId = 0;
new_irp->completion_type = CID_READ;
new_irp->CompletionId = g_completion_id++;
devredir_fuse_data_enqueue(new_irp, fusep);
devredir_insert_DeviceIoRequest(s, devredir_insert_DeviceIoRequest(s,
DeviceId, DeviceId,
FileId, FileId,
irp->CompletionId, new_irp->CompletionId,
IRP_MJ_READ, IRP_MJ_READ,
0); 0);
@ -1214,6 +1233,7 @@ int dev_redir_file_write(void *fusep, tui32 DeviceId, tui32 FileId,
{ {
struct stream *s; struct stream *s;
IRP *irp; IRP *irp;
IRP *new_irp;
int bytes; int bytes;
log_debug("DeviceId=%d FileId=%d Length=%d Offset=%lld", log_debug("DeviceId=%d FileId=%d Length=%d Offset=%lld",
@ -1228,12 +1248,22 @@ int dev_redir_file_write(void *fusep, tui32 DeviceId, tui32 FileId,
return -1; return -1;
} }
irp->completion_type = CID_WRITE; /* create a new IRP for this request */
devredir_fuse_data_enqueue(irp, fusep); if ((new_irp = devredir_irp_clone(irp)) == NULL)
{
/* system out of memory */
xfuse_devredir_cb_write_file(fusep, NULL, 0);
return -1;
}
new_irp->FileId = 0;
new_irp->completion_type = CID_WRITE;
new_irp->CompletionId = g_completion_id++;
devredir_fuse_data_enqueue(new_irp, fusep);
devredir_insert_DeviceIoRequest(s, devredir_insert_DeviceIoRequest(s,
DeviceId, DeviceId,
FileId, FileId,
irp->CompletionId, new_irp->CompletionId,
IRP_MJ_WRITE, IRP_MJ_WRITE,
0); 0);

@ -101,7 +101,7 @@ int dev_redir_file_open(void *fusep, tui32 device_id, char *path,
int devredir_file_close(void *fusep, tui32 device_id, tui32 file_id); int devredir_file_close(void *fusep, tui32 device_id, tui32 file_id);
int dev_redir_file_read(void *fusep, tui32 device_id, tui32 FileId, int devredir_file_read(void *fusep, tui32 device_id, tui32 FileId,
tui32 Length, tui64 Offset); tui32 Length, tui64 Offset);
int send_channel_data(int chan_id, char *data, int size); int send_channel_data(int chan_id, char *data, int size);

@ -99,6 +99,35 @@ IRP * devredir_irp_new()
return irp; return irp;
} }
/**
* Clone specified IRP
*
* @return new IRP or NULL on error
*****************************************************************************/
IRP * devredir_irp_clone(IRP *irp)
{
IRP *new_irp;
IRP *prev;
IRP *next;
if ((new_irp = devredir_irp_new()) == NULL)
return NULL;
/* save link pointers */
prev = new_irp->prev;
next = new_irp->next;
/* copy all members */
memcpy(new_irp, irp, sizeof(IRP));
/* restore link pointers */
new_irp->prev = prev;
new_irp->next = next;
return new_irp;
}
/** /**
* Delete specified IRP from linked list * Delete specified IRP from linked list
* *

@ -55,6 +55,7 @@ struct irp
}; };
IRP * devredir_irp_new(); IRP * devredir_irp_new();
IRP * devredir_irp_clone(IRP *irp);
int devredir_irp_delete(IRP *irp); int devredir_irp_delete(IRP *irp);
IRP * devredir_irp_find(tui32 completion_id); IRP * devredir_irp_find(tui32 completion_id);
IRP * devredir_irp_find_by_fileid(tui32 FileId); IRP * devredir_irp_find_by_fileid(tui32 FileId);

Loading…
Cancel
Save