2 /* Sending requests to VFS and handling the replies. */
6 #include <minix/callnr.h>
8 #include <minix/config.h>
9 #include <minix/const.h>
11 #include <minix/endpoint.h>
12 #include <minix/minlib.h>
13 #include <minix/type.h>
14 #include <minix/ipc.h>
15 #include <minix/sysutil.h>
16 #include <minix/syslib.h>
17 #include <minix/type.h>
18 #include <minix/bitmap.h>
24 #include <sys/param.h>
30 #include "sanitycheck.h"
34 static struct vfs_request_node
{
36 char reqstate
[STATELEN
];
40 vfs_callback_t callback
;
41 struct vfs_request_node
*next
;
42 } *first_queued
, *active
;
44 static void activate(void)
49 active
= first_queued
;
50 first_queued
= first_queued
->next
;
52 if(asynsend3(VFS_PROC_NR
, &active
->reqmsg
, AMF_NOREPLY
) != OK
)
53 panic("VM: asynsend to VFS failed");
56 #define ID_MAX LONG_MAX
58 /*===========================================================================*
60 *===========================================================================*/
61 int vfs_request(int reqno
, int fd
, struct vmproc
*vmp
, u64_t offset
, u32_t len
,
62 vfs_callback_t reply_callback
, void *cbarg
, void *state
, int statelen
)
64 /* Perform an asynchronous request to VFS.
65 * We send a message of type VFS_VMCALL to VFS. VFS will respond
66 * with message type VM_VFS_REPLY. We send the request asynchronously
67 * and then handle the reply as it if were a VM_VFS_REPLY request.
71 struct vfs_request_node
*reqnode
;
75 assert(statelen
<= STATELEN
);
77 if(!SLABALLOC(reqnode
)) {
78 printf("vfs_request: no memory for request node\n");
83 memset(m
, 0, sizeof(*m
));
84 m
->m_type
= VFS_VMCALL
;
85 m
->VFS_VMCALL_REQ
= reqno
;
86 m
->VFS_VMCALL_FD
= fd
;
87 m
->VFS_VMCALL_REQID
= reqid
;
88 m
->VFS_VMCALL_ENDPOINT
= vmp
->vm_endpoint
;
89 m
->VFS_VMCALL_OFFSET
= offset
;
90 m
->VFS_VMCALL_LENGTH
= len
;
92 reqnode
->who
= vmp
->vm_endpoint
;
93 reqnode
->req_id
= reqid
;
94 reqnode
->next
= first_queued
;
95 reqnode
->callback
= reply_callback
;
96 reqnode
->opaque
= cbarg
;
97 if(state
) memcpy(reqnode
->reqstate
, state
, statelen
);
98 first_queued
= reqnode
;
100 /* Send the request message if none pending. */
107 /*===========================================================================*
109 *===========================================================================*/
110 int do_vfs_reply(message
*m
)
112 /* VFS has handled a VM request and VFS has replied. It must be the
115 struct vfs_request_node
*orignode
= active
;
116 vfs_callback_t req_callback
;
122 assert(active
->req_id
== m
->VMV_REQID
);
124 /* the endpoint may have exited */
125 if(vm_isokendpt(m
->VMV_ENDPOINT
, &n
) != OK
)
127 else vmp
= &vmproc
[n
];
129 req_callback
= active
->callback
;
130 cbarg
= active
->opaque
;
133 /* Invoke requested reply-callback within VM. */
134 if(req_callback
) req_callback(vmp
, m
, cbarg
, orignode
->reqstate
);
138 /* Send the next request message if any and not re-activated. */
139 if(first_queued
&& !active
)
142 return SUSPEND
; /* don't reply to the reply */