Changes in uspace/srv/vfs/vfs_register.c [ffa2c8ef:79ae36dd] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/vfs/vfs_register.c
rffa2c8ef r79ae36dd 62 62 /** Verify the VFS info structure. 63 63 * 64 * @param info Info structure to be verified. 65 * 66 * @return Non-zero if the info structure is sane, zero otherwise. 64 * @param info Info structure to be verified. 65 * 66 * @return Non-zero if the info structure is sane, zero otherwise. 67 * 67 68 */ 68 69 static bool vfs_info_sane(vfs_info_t *info) 69 70 { 70 71 int i; 71 72 72 73 /* 73 74 * Check if the name is non-empty and is composed solely of ASCII … … 78 79 return false; 79 80 } 81 80 82 for (i = 1; i < FS_NAME_MAXLEN; i++) { 81 83 if (!(islower(info->name[i]) || isdigit(info->name[i])) && … … 90 92 } 91 93 } 94 92 95 /* 93 96 * This check is not redundant. It ensures that the name is … … 104 107 /** VFS_REGISTER protocol function. 105 108 * 106 * @param rid Hash of the call with the request. 107 * @param request Call structure with the request. 109 * @param rid Hash of the call with the request. 110 * @param request Call structure with the request. 111 * 108 112 */ 109 113 void vfs_register(ipc_callid_t rid, ipc_call_t *request) 110 114 { 111 int phone;112 113 115 dprintf("Processing VFS_REGISTER request received from %p.\n", 114 116 request->in_phone_hash); … … 174 176 * which to forward VFS requests to it. 175 177 */ 176 ipc_call_t call; 177 ipc_callid_t callid = async_get_call(&call); 178 if (IPC_GET_IMETHOD(call) != IPC_M_CONNECT_TO_ME) { 179 dprintf("Unexpected call, method = %d\n", IPC_GET_IMETHOD(call)); 178 fs_info->sess = async_callback_receive(EXCHANGE_PARALLEL); 179 if (!fs_info->sess) { 180 dprintf("Callback connection expected\n"); 180 181 list_remove(&fs_info->fs_link); 181 182 fibril_mutex_unlock(&fs_head_lock); 182 183 free(fs_info); 183 async_answer_0(callid, EINVAL);184 184 async_answer_0(rid, EINVAL); 185 185 return; 186 186 } 187 187 188 phone = IPC_GET_ARG5(call);189 async_session_create(&fs_info->session, phone, 0);190 async_answer_0(callid, EOK);191 192 188 dprintf("Callback connection to FS created.\n"); 193 189 … … 197 193 198 194 size_t size; 195 ipc_callid_t callid; 199 196 if (!async_share_in_receive(&callid, &size)) { 200 197 dprintf("Unexpected call, method = %d\n", IPC_GET_IMETHOD(call)); 201 198 list_remove(&fs_info->fs_link); 202 199 fibril_mutex_unlock(&fs_head_lock); 203 async_session_destroy(&fs_info->session); 204 async_hangup(phone); 200 async_hangup(fs_info->sess); 205 201 free(fs_info); 206 202 async_answer_0(callid, EINVAL); … … 216 212 list_remove(&fs_info->fs_link); 217 213 fibril_mutex_unlock(&fs_head_lock); 218 async_session_destroy(&fs_info->session); 219 async_hangup(phone); 214 async_hangup(fs_info->sess); 220 215 free(fs_info); 221 216 async_answer_0(callid, EINVAL); … … 247 242 } 248 243 249 /** For a given file system handle, implement policy for allocating a phone. 250 * 251 * @param handle File system handle. 252 * 253 * @return Phone over which a multi-call request can be safely 254 * sent. Return 0 if no phone was found. 255 */ 256 int vfs_grab_phone(fs_handle_t handle) 257 { 244 /** Begin an exchange for a given file system handle 245 * 246 * @param handle File system handle. 247 * 248 * @return Exchange for a multi-call request. 249 * @return NULL if no such file exists. 250 * 251 */ 252 async_exch_t *vfs_exchange_grab(fs_handle_t handle) 253 { 254 /* 255 * For now, we don't try to be very clever and very fast. 256 * We simply lookup the session in the fs_head list and 257 * begin an exchange. 258 */ 259 fibril_mutex_lock(&fs_head_lock); 260 258 261 link_t *cur; 259 fs_info_t *fs;260 int phone;261 262 /*263 * For now, we don't try to be very clever and very fast. We simply264 * lookup the phone in the fs_head list and duplicate it. The duplicate265 * phone will be returned to the client and the client will use it for266 * communication. In the future, we should cache the connections so267 * that they do not have to be reestablished over and over again.268 */269 fibril_mutex_lock(&fs_head_lock);270 262 for (cur = fs_head.next; cur != &fs_head; cur = cur->next) { 271 fs = list_get_instance(cur, fs_info_t, fs_link); 263 fs_info_t *fs = list_get_instance(cur, fs_info_t, fs_link); 264 272 265 if (fs->fs_handle == handle) { 273 266 fibril_mutex_unlock(&fs_head_lock); 274 phone = async_exchange_begin(&fs->session); 275 276 assert(phone > 0); 277 return phone; 267 268 assert(fs->sess); 269 async_exch_t *exch = async_exchange_begin(fs->sess); 270 271 assert(exch); 272 return exch; 278 273 } 279 274 } 275 280 276 fibril_mutex_unlock(&fs_head_lock); 281 return 0; 282 } 283 284 /** Tell VFS that the phone is not needed anymore. 285 * 286 * @param phone Phone to FS task. 287 */ 288 void vfs_release_phone(fs_handle_t handle, int phone) 289 { 290 link_t *cur; 291 fs_info_t *fs; 292 293 fibril_mutex_lock(&fs_head_lock); 294 for (cur = fs_head.next; cur != &fs_head; cur = cur->next) { 295 fs = list_get_instance(cur, fs_info_t, fs_link); 296 if (fs->fs_handle == handle) { 297 fibril_mutex_unlock(&fs_head_lock); 298 async_exchange_end(&fs->session, phone); 299 return; 300 } 301 } 302 /* should not really get here */ 303 abort(); 304 fibril_mutex_unlock(&fs_head_lock); 277 278 return NULL; 279 } 280 281 /** End VFS server exchange. 282 * 283 * @param exch VFS server exchange. 284 * 285 */ 286 void vfs_exchange_release(async_exch_t *exch) 287 { 288 async_exchange_end(exch); 305 289 } 306 290 307 291 /** Convert file system name to its handle. 308 292 * 309 * @param name File system name. 310 * @param lock If true, the function will lock and unlock the 311 * fs_head_lock. 312 * 313 * @return File system handle or zero if file system not found. 293 * @param name File system name. 294 * @param lock If true, the function will lock and unlock the 295 * fs_head_lock. 296 * 297 * @return File system handle or zero if file system not found. 298 * 314 299 */ 315 300 fs_handle_t fs_name_to_handle(char *name, bool lock) … … 319 304 if (lock) 320 305 fibril_mutex_lock(&fs_head_lock); 306 321 307 link_t *cur; 322 308 for (cur = fs_head.next; cur != &fs_head; cur = cur->next) { … … 327 313 } 328 314 } 315 329 316 if (lock) 330 317 fibril_mutex_unlock(&fs_head_lock); 318 331 319 return handle; 332 320 } … … 334 322 /** Find the VFS info structure. 335 323 * 336 * @param handle FS handle for which the VFS info structure is sought. 337 * @return VFS info structure on success or NULL otherwise. 324 * @param handle FS handle for which the VFS info structure is sought. 325 * 326 * @return VFS info structure on success or NULL otherwise. 327 * 338 328 */ 339 329 vfs_info_t *fs_handle_to_info(fs_handle_t handle) … … 341 331 vfs_info_t *info = NULL; 342 332 link_t *cur; 343 333 344 334 fibril_mutex_lock(&fs_head_lock); 345 335 for (cur = fs_head.next; cur != &fs_head; cur = cur->next) { … … 351 341 } 352 342 fibril_mutex_unlock(&fs_head_lock); 353 343 354 344 return info; 355 345 } … … 357 347 /** 358 348 * @} 359 */ 349 */
Note:
See TracChangeset
for help on using the changeset viewer.