Changeset 41811af in mainline for uspace/srv/vfs/vfs_ops.c
- Timestamp:
- 2011-06-10T10:14:26Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ab547063
- Parents:
- 9536e6e (diff), 390d80d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/vfs/vfs_ops.c
r9536e6e r41811af 78 78 size_t rsize; 79 79 unsigned rlnkcnt; 80 async_exch_t *exch; 80 81 sysarg_t rc; 81 int phone;82 82 aid_t msg; 83 83 ipc_call_t answer; … … 123 123 124 124 /* Tell the mountee that it is being mounted. */ 125 phone = vfs_grab_phone(fs_handle);126 msg = async_send_1( phone, VFS_OUT_MOUNTED,125 exch = vfs_exchange_grab(fs_handle); 126 msg = async_send_1(exch, VFS_OUT_MOUNTED, 127 127 (sysarg_t) devmap_handle, &answer); 128 /* send the mount options */129 rc = async_data_write_start( phone, (void *)opts,128 /* Send the mount options */ 129 rc = async_data_write_start(exch, (void *)opts, 130 130 str_size(opts)); 131 vfs_exchange_release(exch); 132 131 133 if (rc != EOK) { 132 134 async_wait_for(msg, NULL); 133 vfs_release_phone(fs_handle, phone);134 135 fibril_rwlock_write_unlock(&namespace_rwlock); 135 136 async_answer_0(rid, rc); … … 137 138 } 138 139 async_wait_for(msg, &rc); 139 vfs_release_phone(fs_handle, phone);140 140 141 141 if (rc != EOK) { … … 182 182 */ 183 183 184 int mountee_phone = vfs_grab_phone(fs_handle);185 assert(mountee_ phone >= 0);186 187 phone = vfs_grab_phone(mp_res.triplet.fs_handle);188 msg = async_send_4( phone, VFS_OUT_MOUNT,184 async_exch_t *mountee_exch = vfs_exchange_grab(fs_handle); 185 assert(mountee_exch); 186 187 exch = vfs_exchange_grab(mp_res.triplet.fs_handle); 188 msg = async_send_4(exch, VFS_OUT_MOUNT, 189 189 (sysarg_t) mp_res.triplet.devmap_handle, 190 190 (sysarg_t) mp_res.triplet.index, … … 192 192 (sysarg_t) devmap_handle, &answer); 193 193 194 /* send connection */ 195 rc = async_req_1_0(phone, IPC_M_CONNECTION_CLONE, mountee_phone); 196 if (rc != EOK) { 194 /* Send connection */ 195 rc = async_exchange_clone(exch, mountee_exch); 196 vfs_exchange_release(mountee_exch); 197 198 if (rc != EOK) { 199 vfs_exchange_release(exch); 197 200 async_wait_for(msg, NULL); 198 vfs_release_phone(fs_handle, mountee_phone); 199 vfs_release_phone(mp_res.triplet.fs_handle, phone); 201 200 202 /* Mount failed, drop reference to mp_node. */ 201 203 if (mp_node) 202 204 vfs_node_put(mp_node); 203 async_answer_0(rid, rc); 204 fibril_rwlock_write_unlock(&namespace_rwlock); 205 return; 206 } 207 208 vfs_release_phone(fs_handle, mountee_phone); 205 206 async_answer_0(rid, rc); 207 fibril_rwlock_write_unlock(&namespace_rwlock); 208 return; 209 } 209 210 210 211 /* send the mount options */ 211 rc = async_data_write_start(phone, (void *)opts, str_size(opts)); 212 if (rc != EOK) { 212 rc = async_data_write_start(exch, (void *) opts, str_size(opts)); 213 if (rc != EOK) { 214 vfs_exchange_release(exch); 213 215 async_wait_for(msg, NULL); 214 vfs_release_phone(mp_res.triplet.fs_handle, phone);216 215 217 /* Mount failed, drop reference to mp_node. */ 216 218 if (mp_node) 217 219 vfs_node_put(mp_node); 218 fibril_rwlock_write_unlock(&namespace_rwlock); 219 async_answer_0(rid, rc); 220 return; 221 } 220 221 fibril_rwlock_write_unlock(&namespace_rwlock); 222 async_answer_0(rid, rc); 223 return; 224 } 225 226 vfs_exchange_release(exch); 222 227 async_wait_for(msg, &rc); 223 vfs_release_phone(mp_res.triplet.fs_handle, phone);224 228 225 229 if (rc == EOK) { … … 227 231 rsize = (size_t) IPC_GET_ARG2(answer); 228 232 rlnkcnt = (unsigned) IPC_GET_ARG3(answer); 229 233 230 234 mr_res.triplet.fs_handle = fs_handle; 231 235 mr_res.triplet.devmap_handle = devmap_handle; … … 234 238 mr_res.lnkcnt = rlnkcnt; 235 239 mr_res.type = VFS_NODE_DIRECTORY; 236 240 237 241 /* Add reference to the mounted root. */ 238 242 mr_node = vfs_node_get(&mr_res); … … 243 247 vfs_node_put(mp_node); 244 248 } 245 249 246 250 async_answer_0(rid, rc); 247 251 fibril_rwlock_write_unlock(&namespace_rwlock); … … 303 307 304 308 /* 305 * Wait for IPC_M_PING so that we can return an error if we don't know309 * Wait for VFS_IN_PING so that we can return an error if we don't know 306 310 * fs_name. 307 311 */ 308 312 ipc_call_t data; 309 313 ipc_callid_t callid = async_get_call(&data); 310 if (IPC_GET_IMETHOD(data) != IPC_M_PING) {314 if (IPC_GET_IMETHOD(data) != VFS_IN_PING) { 311 315 async_answer_0(callid, ENOTSUP); 312 316 async_answer_0(rid, ENOTSUP); … … 358 362 vfs_lookup_res_t mr_res; 359 363 vfs_node_t *mr_node; 360 int phone;361 364 async_exch_t *exch; 365 362 366 /* 363 367 * Receive the mount point path. … … 367 371 if (rc != EOK) 368 372 async_answer_0(rid, rc); 369 373 370 374 /* 371 375 * Taking the namespace lock will do two things for us. First, it will … … 395 399 return; 396 400 } 397 401 398 402 /* 399 403 * Count the total number of references for the mounted file system. We … … 411 415 return; 412 416 } 413 417 414 418 if (str_cmp(mp, "/") == 0) { 415 419 416 420 /* 417 421 * Unmounting the root file system. … … 420 424 * VFS_OUT_UNMOUNTED directly to the mounted file system. 421 425 */ 422 426 423 427 free(mp); 424 phone = vfs_grab_phone(mr_node->fs_handle); 425 rc = async_req_1_0(phone, VFS_OUT_UNMOUNTED, 428 429 exch = vfs_exchange_grab(mr_node->fs_handle); 430 rc = async_req_1_0(exch, VFS_OUT_UNMOUNTED, 426 431 mr_node->devmap_handle); 427 vfs_release_phone(mr_node->fs_handle, phone); 432 vfs_exchange_release(exch); 433 428 434 if (rc != EOK) { 429 435 fibril_rwlock_write_unlock(&namespace_rwlock); … … 432 438 return; 433 439 } 440 434 441 rootfs.fs_handle = 0; 435 442 rootfs.devmap_handle = 0; 436 443 } else { 437 444 438 445 /* 439 446 * Unmounting a non-root file system. … … 442 449 * file system, so we delegate the operation to it. 443 450 */ 444 451 445 452 rc = vfs_lookup_internal(mp, L_MP, &mp_res, NULL); 446 453 free(mp); … … 451 458 return; 452 459 } 460 453 461 vfs_node_t *mp_node = vfs_node_get(&mp_res); 454 462 if (!mp_node) { … … 458 466 return; 459 467 } 460 461 phone = vfs_grab_phone(mp_node->fs_handle);462 rc = async_req_2_0( phone, VFS_OUT_UNMOUNT,468 469 exch = vfs_exchange_grab(mp_node->fs_handle); 470 rc = async_req_2_0(exch, VFS_OUT_UNMOUNT, 463 471 mp_node->devmap_handle, mp_node->index); 464 vfs_release_phone(mp_node->fs_handle, phone); 472 vfs_exchange_release(exch); 473 465 474 if (rc != EOK) { 466 475 fibril_rwlock_write_unlock(&namespace_rwlock); … … 470 479 return; 471 480 } 472 481 473 482 /* Drop the reference we got above. */ 474 483 vfs_node_put(mp_node); … … 476 485 vfs_node_put(mp_node); 477 486 } 478 479 487 480 488 /* 481 489 * All went well, the mounted file system was successfully unmounted. … … 483 491 */ 484 492 vfs_node_forget(mr_node); 485 493 486 494 fibril_rwlock_write_unlock(&namespace_rwlock); 487 495 async_answer_0(rid, EOK); … … 698 706 */ 699 707 fibril_mutex_lock(&file->lock); 700 int fs_phone = vfs_grab_phone(file->node->fs_handle);708 async_exch_t *fs_exch = vfs_exchange_grab(file->node->fs_handle); 701 709 702 710 /* Make a VFS_OUT_SYMC request at the destination FS server. */ 703 711 aid_t msg; 704 712 ipc_call_t answer; 705 msg = async_send_2(fs_ phone, VFS_OUT_SYNC, file->node->devmap_handle,713 msg = async_send_2(fs_exch, VFS_OUT_SYNC, file->node->devmap_handle, 706 714 file->node->index, &answer); 707 715 716 vfs_exchange_release(fs_exch); 717 708 718 /* Wait for reply from the FS server. */ 709 719 sysarg_t rc; 710 720 async_wait_for(msg, &rc); 711 721 712 vfs_release_phone(file->node->fs_handle, fs_phone);713 722 fibril_mutex_unlock(&file->lock); 714 723 715 724 vfs_file_put(file); 716 725 async_answer_0(rid, rc); 717 726 } 718 727 719 int vfs_close_internal(vfs_file_t *file)720 {721 /*722 * Lock the open file structure so that no other thread can manipulate723 * the same open file at a time.724 */725 fibril_mutex_lock(&file->lock);726 727 if (file->refcnt <= 1) {728 /* Only close the file on the destination FS server729 if there are no more file descriptors (except the730 present one) pointing to this file. */731 732 int fs_phone = vfs_grab_phone(file->node->fs_handle);733 734 /* Make a VFS_OUT_CLOSE request at the destination FS server. */735 aid_t msg;736 ipc_call_t answer;737 msg = async_send_2(fs_phone, VFS_OUT_CLOSE,738 file->node->devmap_handle, file->node->index, &answer);739 740 /* Wait for reply from the FS server. */741 sysarg_t rc;742 async_wait_for(msg, &rc);743 744 vfs_release_phone(file->node->fs_handle, fs_phone);745 fibril_mutex_unlock(&file->lock);746 747 return IPC_GET_ARG1(answer);748 }749 750 fibril_mutex_unlock(&file->lock);751 return EOK;752 }753 754 728 void vfs_close(ipc_callid_t rid, ipc_call_t *request) 755 729 { 756 730 int fd = IPC_GET_ARG1(*request); 757 758 /* Lookup the file structure corresponding to the file descriptor. */ 759 vfs_file_t *file = vfs_file_get(fd); 760 if (!file) { 761 async_answer_0(rid, ENOENT); 762 return; 763 } 764 765 int ret = vfs_close_internal(file); 766 if (ret != EOK) 767 async_answer_0(rid, ret); 768 769 vfs_file_put(file); 770 ret = vfs_fd_free(fd); 731 int ret = vfs_fd_free(fd); 771 732 async_answer_0(rid, ret); 772 733 } … … 774 735 static void vfs_rdwr(ipc_callid_t rid, ipc_call_t *request, bool read) 775 736 { 776 vfs_info_t *vi;777 778 737 /* 779 738 * The following code strongly depends on the fact that the files data … … 785 744 * open files supports parallel access! 786 745 */ 787 746 788 747 int fd = IPC_GET_ARG1(*request); 789 748 … … 800 759 */ 801 760 fibril_mutex_lock(&file->lock); 802 803 v i= fs_handle_to_info(file->node->fs_handle);804 assert( vi);805 761 762 vfs_info_t *fs_info = fs_handle_to_info(file->node->fs_handle); 763 assert(fs_info); 764 806 765 /* 807 766 * Lock the file's node so that no other client can read/write to it at … … 809 768 * write implementation does not modify the file size. 810 769 */ 811 if (read || (vi->concurrent_read_write && vi->write_retains_size)) 770 if ((read) || 771 ((fs_info->concurrent_read_write) && (fs_info->write_retains_size))) 812 772 fibril_rwlock_read_lock(&file->node->contents_rwlock); 813 773 else 814 774 fibril_rwlock_write_lock(&file->node->contents_rwlock); 815 775 816 776 if (file->node->type == VFS_NODE_DIRECTORY) { 817 777 /* … … 823 783 } 824 784 825 int fs_phone = vfs_grab_phone(file->node->fs_handle);785 async_exch_t *fs_exch = vfs_exchange_grab(file->node->fs_handle); 826 786 827 787 /* … … 835 795 ipc_call_t answer; 836 796 if (read) { 837 rc = async_data_read_forward_3_1(fs_ phone, VFS_OUT_READ,797 rc = async_data_read_forward_3_1(fs_exch, VFS_OUT_READ, 838 798 file->node->devmap_handle, file->node->index, file->pos, 839 799 &answer); … … 842 802 file->pos = file->node->size; 843 803 844 rc = async_data_write_forward_3_1(fs_ phone, VFS_OUT_WRITE,804 rc = async_data_write_forward_3_1(fs_exch, VFS_OUT_WRITE, 845 805 file->node->devmap_handle, file->node->index, file->pos, 846 806 &answer); 847 807 } 848 808 849 vfs_ release_phone(file->node->fs_handle, fs_phone);809 vfs_exchange_release(fs_exch); 850 810 851 811 size_t bytes = IPC_GET_ARG1(answer); … … 855 815 856 816 /* Unlock the VFS node. */ 857 if (read || (vi->concurrent_read_write && vi->write_retains_size)) 817 if ((read) || 818 ((fs_info->concurrent_read_write) && (fs_info->write_retains_size))) 858 819 fibril_rwlock_read_unlock(&file->node->contents_rwlock); 859 820 else { … … 975 936 fs_index_t index, aoff64_t size) 976 937 { 977 sysarg_t rc; 978 int fs_phone; 979 980 fs_phone = vfs_grab_phone(fs_handle); 981 rc = async_req_4_0(fs_phone, VFS_OUT_TRUNCATE, (sysarg_t) devmap_handle, 982 (sysarg_t) index, LOWER32(size), UPPER32(size)); 983 vfs_release_phone(fs_handle, fs_phone); 984 return (int)rc; 938 async_exch_t *exch = vfs_exchange_grab(fs_handle); 939 sysarg_t rc = async_req_4_0(exch, VFS_OUT_TRUNCATE, 940 (sysarg_t) devmap_handle, (sysarg_t) index, LOWER32(size), 941 UPPER32(size)); 942 vfs_exchange_release(exch); 943 944 return (int) rc; 985 945 } 986 946 … … 1032 992 fibril_mutex_lock(&file->lock); 1033 993 1034 int fs_phone = vfs_grab_phone(file->node->fs_handle);994 async_exch_t *exch = vfs_exchange_grab(file->node->fs_handle); 1035 995 1036 996 aid_t msg; 1037 msg = async_send_3( fs_phone, VFS_OUT_STAT, file->node->devmap_handle,997 msg = async_send_3(exch, VFS_OUT_STAT, file->node->devmap_handle, 1038 998 file->node->index, true, NULL); 1039 async_forward_fast(callid, fs_phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME); 999 async_forward_fast(callid, exch, 0, 0, 0, IPC_FF_ROUTE_FROM_ME); 1000 1001 vfs_exchange_release(exch); 1002 1040 1003 async_wait_for(msg, &rc); 1041 vfs_release_phone(file->node->fs_handle, fs_phone); 1042 1004 1043 1005 fibril_mutex_unlock(&file->lock); 1044 1006 vfs_file_put(file); … … 1083 1045 fibril_rwlock_read_unlock(&namespace_rwlock); 1084 1046 1085 int fs_phone = vfs_grab_phone(node->fs_handle); 1047 async_exch_t *exch = vfs_exchange_grab(node->fs_handle); 1048 1086 1049 aid_t msg; 1087 msg = async_send_3( fs_phone, VFS_OUT_STAT, node->devmap_handle,1050 msg = async_send_3(exch, VFS_OUT_STAT, node->devmap_handle, 1088 1051 node->index, false, NULL); 1089 async_forward_fast(callid, fs_phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME); 1052 async_forward_fast(callid, exch, 0, 0, 0, IPC_FF_ROUTE_FROM_ME); 1053 1054 vfs_exchange_release(exch); 1090 1055 1091 1056 sysarg_t rv; 1092 1057 async_wait_for(msg, &rv); 1093 vfs_release_phone(node->fs_handle, fs_phone);1094 1058 1095 1059 async_answer_0(rid, rv); … … 1369 1333 fibril_mutex_lock(&oldfile->lock); 1370 1334 1371 /* Lookup an open file structure possibly corresponding to newfd. */ 1372 vfs_file_t *newfile = vfs_file_get(newfd); 1373 if (newfile) { 1374 /* Close the originally opened file. */ 1375 int ret = vfs_close_internal(newfile); 1376 if (ret != EOK) { 1377 fibril_mutex_unlock(&oldfile->lock); 1378 vfs_file_put(oldfile); 1379 vfs_file_put(newfile); 1380 async_answer_0(rid, ret); 1381 return; 1382 } 1383 1384 ret = vfs_fd_free(newfd); 1385 if (ret != EOK) { 1386 fibril_mutex_unlock(&oldfile->lock); 1387 vfs_file_put(oldfile); 1388 vfs_file_put(newfile); 1389 async_answer_0(rid, ret); 1390 return; 1391 } 1392 vfs_file_put(newfile); 1393 } 1335 /* Make sure newfd is closed. */ 1336 (void) vfs_fd_free(newfd); 1394 1337 1395 1338 /* Assign the old file to newfd. */
Note:
See TracChangeset
for help on using the changeset viewer.