Changeset 230260ac in mainline
- Timestamp:
- 2009-06-09T22:27:43Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0e31a2b
- Parents:
- 041186f
- Location:
- uspace/srv/vfs
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/vfs/vfs.h
r041186f r230260ac 36 36 #include <ipc/ipc.h> 37 37 #include <adt/list.h> 38 #include <fibril_sync.h> 38 39 #include <futex.h> 39 #include <rwlock.h>40 40 #include <sys/types.h> 41 41 #include <devmap.h> … … 55 55 vfs_info_t vfs_info; 56 56 fs_handle_t fs_handle; 57 f utex_t phone_futex; /**< Phone serializing futex. */57 fibril_mutex_t phone_lock; 58 58 ipcarg_t phone; 59 59 } fs_info_t; … … 123 123 * Holding this rwlock prevents modifications of the node's contents. 124 124 */ 125 rwlock_t contents_rwlock;125 fibril_rwlock_t contents_rwlock; 126 126 } vfs_node_t; 127 127 … … 132 132 typedef struct { 133 133 /** Serializes access to this open file. */ 134 f utex_t lock;134 fibril_mutex_t lock; 135 135 136 136 vfs_node_t *node; … … 166 166 167 167 /** Holding this rwlock prevents changes in file system namespace. */ 168 extern rwlock_t namespace_rwlock;168 extern fibril_rwlock_t namespace_rwlock; 169 169 170 170 extern int vfs_grab_phone(fs_handle_t); -
uspace/srv/vfs/vfs_file.c
r041186f r230260ac 41 41 #include <assert.h> 42 42 #include <bool.h> 43 #include <fibril_sync.h> 43 44 #include "vfs.h" 44 45 … … 90 91 91 92 memset(files[i], 0, sizeof(vfs_file_t)); 92 f utex_initialize(&files[i]->lock, 1);93 fibril_mutex_initialize(&files[i]->lock); 93 94 vfs_file_addref(files[i]); 94 95 return (int) i; -
uspace/srv/vfs/vfs_lookup.c
r041186f r230260ac 166 166 vfs_release_phone(phone); 167 167 168 async_serialize_start();169 168 ipcarg_t rc; 170 169 async_wait_for(req, &rc); 171 async_serialize_end();172 170 173 171 futex_down(&plb_futex); -
uspace/srv/vfs/vfs_node.c
r041186f r230260ac 40 40 #include <string.h> 41 41 #include <futex.h> 42 #include < rwlock.h>42 #include <fibril_sync.h> 43 43 #include <adt/hash_table.h> 44 44 #include <assert.h> … … 178 178 node->type = result->type; 179 179 link_initialize(&node->nh_link); 180 rwlock_initialize(&node->contents_rwlock);180 fibril_rwlock_initialize(&node->contents_rwlock); 181 181 hash_table_insert(&nodes, key, &node->nh_link); 182 182 } else { -
uspace/srv/vfs/vfs_ops.c
r041186f r230260ac 45 45 #include <bool.h> 46 46 #include <futex.h> 47 #include < rwlock.h>47 #include <fibril_sync.h> 48 48 #include <adt/list.h> 49 49 #include <unistd.h> … … 73 73 * concurrent VFS operation which modifies the file system namespace. 74 74 */ 75 RWLOCK_INITIALIZE(namespace_rwlock);75 FIBRIL_RWLOCK_INITIALIZE(namespace_rwlock); 76 76 77 77 vfs_pair_t rootfs = { … … 96 96 97 97 /* Resolve the path to the mountpoint. */ 98 rwlock_write_lock(&namespace_rwlock);98 fibril_rwlock_write_lock(&namespace_rwlock); 99 99 if (rootfs.fs_handle) { 100 100 /* We already have the root FS. */ 101 101 if (str_cmp(mp, "/") == 0) { 102 102 /* Trying to mount root FS over root FS */ 103 fibril_rwlock_write_unlock(&namespace_rwlock); 103 104 ipc_answer_0(rid, EBUSY); 104 rwlock_write_unlock(&namespace_rwlock);105 105 return; 106 106 } … … 109 109 if (rc != EOK) { 110 110 /* The lookup failed for some reason. */ 111 fibril_rwlock_write_unlock(&namespace_rwlock); 111 112 ipc_answer_0(rid, rc); 112 rwlock_write_unlock(&namespace_rwlock);113 113 return; 114 114 } … … 116 116 mp_node = vfs_node_get(&mp_res); 117 117 if (!mp_node) { 118 fibril_rwlock_write_unlock(&namespace_rwlock); 118 119 ipc_answer_0(rid, ENOMEM); 119 rwlock_write_unlock(&namespace_rwlock);120 120 return; 121 121 } … … 142 142 str_size(opts)); 143 143 if (rc != EOK) { 144 vfs_release_phone(phone); 144 145 async_wait_for(msg, NULL); 145 vfs_release_phone(phone);146 fibril_rwlock_write_unlock(&namespace_rwlock); 146 147 ipc_answer_0(rid, rc); 147 rwlock_write_unlock(&namespace_rwlock);148 148 return; 149 149 } 150 vfs_release_phone(phone); 150 151 async_wait_for(msg, &rc); 151 vfs_release_phone(phone);152 152 153 153 if (rc != EOK) { 154 fibril_rwlock_write_unlock(&namespace_rwlock); 154 155 ipc_answer_0(rid, rc); 155 rwlock_write_unlock(&namespace_rwlock);156 156 return; 157 157 } … … 175 175 assert(mr_node); 176 176 177 fibril_rwlock_write_unlock(&namespace_rwlock); 177 178 ipc_answer_0(rid, rc); 178 rwlock_write_unlock(&namespace_rwlock);179 179 return; 180 180 } else { … … 183 183 * being mounted first. 184 184 */ 185 fibril_rwlock_write_unlock(&namespace_rwlock); 185 186 ipc_answer_0(rid, ENOENT); 186 rwlock_write_unlock(&namespace_rwlock);187 187 return; 188 188 } … … 208 208 rc = async_req_1_0(phone, IPC_M_CONNECTION_CLONE, mountee_phone); 209 209 if (rc != EOK) { 210 vfs_release_phone(phone); 210 211 async_wait_for(msg, NULL); 211 vfs_release_phone(phone);212 212 /* Mount failed, drop reference to mp_node. */ 213 213 if (mp_node) 214 214 vfs_node_put(mp_node); 215 215 ipc_answer_0(rid, rc); 216 rwlock_write_unlock(&namespace_rwlock);216 fibril_rwlock_write_unlock(&namespace_rwlock); 217 217 return; 218 218 } … … 221 221 rc = ipc_data_write_start(phone, (void *)opts, str_size(opts)); 222 222 if (rc != EOK) { 223 vfs_release_phone(phone); 223 224 async_wait_for(msg, NULL); 224 vfs_release_phone(phone);225 225 /* Mount failed, drop reference to mp_node. */ 226 226 if (mp_node) 227 227 vfs_node_put(mp_node); 228 ipc_answer_0(rid, rc); 229 rwlock_write_unlock(&namespace_rwlock); 230 return; 231 } 228 fibril_rwlock_write_unlock(&namespace_rwlock); 229 ipc_answer_0(rid, rc); 230 return; 231 } 232 vfs_release_phone(phone); 232 233 async_wait_for(msg, &rc); 233 vfs_release_phone(phone);234 234 235 235 if (rc == EOK) { … … 255 255 256 256 ipc_answer_0(rid, rc); 257 rwlock_write_unlock(&namespace_rwlock);257 fibril_rwlock_write_unlock(&namespace_rwlock); 258 258 } 259 259 … … 509 509 * L_DIRECTORY. Make sure that the user does not pass L_OPEN. 510 510 */ 511 if (((lflag & (L_FILE | L_DIRECTORY)) == 0) 512 || ((lflag & (L_FILE | L_DIRECTORY)) == (L_FILE | L_DIRECTORY))513 ||((lflag & L_OPEN) != 0)) {511 if (((lflag & (L_FILE | L_DIRECTORY)) == 0) || 512 ((lflag & (L_FILE | L_DIRECTORY)) == (L_FILE | L_DIRECTORY)) || 513 ((lflag & L_OPEN) != 0)) { 514 514 ipc_answer_0(rid, EINVAL); 515 515 return; … … 549 549 */ 550 550 if (lflag & L_CREATE) 551 rwlock_write_lock(&namespace_rwlock);551 fibril_rwlock_write_lock(&namespace_rwlock); 552 552 else 553 rwlock_read_lock(&namespace_rwlock);553 fibril_rwlock_read_lock(&namespace_rwlock); 554 554 555 555 /* The path is now populated and we can call vfs_lookup_internal(). */ … … 558 558 if (rc != EOK) { 559 559 if (lflag & L_CREATE) 560 rwlock_write_unlock(&namespace_rwlock);560 fibril_rwlock_write_unlock(&namespace_rwlock); 561 561 else 562 rwlock_read_unlock(&namespace_rwlock);562 fibril_rwlock_read_unlock(&namespace_rwlock); 563 563 ipc_answer_0(rid, rc); 564 564 free(path); … … 571 571 vfs_node_t *node = vfs_node_get(&lr); 572 572 if (lflag & L_CREATE) 573 rwlock_write_unlock(&namespace_rwlock);573 fibril_rwlock_write_unlock(&namespace_rwlock); 574 574 else 575 rwlock_read_unlock(&namespace_rwlock);575 fibril_rwlock_read_unlock(&namespace_rwlock); 576 576 577 577 /* Truncate the file if requested and if necessary. */ 578 578 if (oflag & O_TRUNC) { 579 rwlock_write_lock(&node->contents_rwlock);579 fibril_rwlock_write_lock(&node->contents_rwlock); 580 580 if (node->size) { 581 581 rc = vfs_truncate_internal(node->fs_handle, 582 582 node->dev_handle, node->index, 0); 583 583 if (rc) { 584 rwlock_write_unlock(&node->contents_rwlock);584 fibril_rwlock_write_unlock(&node->contents_rwlock); 585 585 vfs_node_put(node); 586 586 ipc_answer_0(rid, rc); … … 589 589 node->size = 0; 590 590 } 591 rwlock_write_unlock(&node->contents_rwlock);591 fibril_rwlock_write_unlock(&node->contents_rwlock); 592 592 } 593 593 … … 640 640 int oflag = IPC_GET_ARG4(*request); 641 641 642 rwlock_read_lock(&namespace_rwlock);642 fibril_rwlock_read_lock(&namespace_rwlock); 643 643 644 644 int rc = vfs_open_node_internal(&lr); 645 645 if (rc != EOK) { 646 rwlock_read_unlock(&namespace_rwlock);646 fibril_rwlock_read_unlock(&namespace_rwlock); 647 647 ipc_answer_0(rid, rc); 648 648 return; … … 650 650 651 651 vfs_node_t *node = vfs_node_get(&lr); 652 rwlock_read_unlock(&namespace_rwlock);652 fibril_rwlock_read_unlock(&namespace_rwlock); 653 653 654 654 /* Truncate the file if requested and if necessary. */ 655 655 if (oflag & O_TRUNC) { 656 rwlock_write_lock(&node->contents_rwlock);656 fibril_rwlock_write_lock(&node->contents_rwlock); 657 657 if (node->size) { 658 658 rc = vfs_truncate_internal(node->fs_handle, 659 659 node->dev_handle, node->index, 0); 660 660 if (rc) { 661 rwlock_write_unlock(&node->contents_rwlock);661 fibril_rwlock_write_unlock(&node->contents_rwlock); 662 662 vfs_node_put(node); 663 663 ipc_answer_0(rid, rc); … … 666 666 node->size = 0; 667 667 } 668 rwlock_write_unlock(&node->contents_rwlock);668 fibril_rwlock_write_unlock(&node->contents_rwlock); 669 669 } 670 670 … … 709 709 } 710 710 711 ipc_answer_3(rid, EOK, file->node->fs_handle, 712 file->node-> dev_handle, file->node->index);711 ipc_answer_3(rid, EOK, file->node->fs_handle, file->node->dev_handle, 712 file->node->index); 713 713 } 714 714 … … 728 728 * the same open file at a time. 729 729 */ 730 f utex_down(&file->lock);730 fibril_mutex_lock(&file->lock); 731 731 int fs_phone = vfs_grab_phone(file->node->fs_handle); 732 732 … … 737 737 file->node->dev_handle, file->node->index, &answer); 738 738 739 vfs_release_phone(fs_phone); 740 739 741 /* Wait for reply from the FS server. */ 740 742 ipcarg_t rc; 741 743 async_wait_for(msg, &rc); 742 744 743 vfs_release_phone(fs_phone); 744 futex_up(&file->lock); 745 fibril_mutex_unlock(&file->lock); 745 746 746 747 ipc_answer_1(rid, EOK, IPC_GET_ARG1(answer)); … … 762 763 * the same open file at a time. 763 764 */ 764 f utex_down(&file->lock);765 fibril_mutex_lock(&file->lock); 765 766 int fs_phone = vfs_grab_phone(file->node->fs_handle); 766 767 … … 770 771 msg = async_send_2(fs_phone, IPC_GET_METHOD(*request), 771 772 file->node->dev_handle, file->node->index, &answer); 772 773 774 vfs_release_phone(fs_phone); 775 773 776 /* Wait for reply from the FS server. */ 774 777 ipcarg_t rc; 775 778 async_wait_for(msg, &rc); 776 779 777 vfs_release_phone(fs_phone); 778 futex_up(&file->lock); 780 fibril_mutex_unlock(&file->lock); 779 781 780 782 ipc_answer_0(rid, rc); … … 796 798 * the same open file at a time. 797 799 */ 798 f utex_down(&file->lock);800 fibril_mutex_lock(&file->lock); 799 801 800 802 int fs_phone = vfs_grab_phone(file->node->fs_handle); … … 805 807 msg = async_send_2(fs_phone, IPC_GET_METHOD(*request), 806 808 file->node->dev_handle, file->node->index, &answer); 809 810 vfs_release_phone(fs_phone); 807 811 808 812 /* Wait for reply from the FS server. */ … … 810 814 async_wait_for(msg, &rc); 811 815 812 vfs_release_phone(fs_phone); 813 futex_up(&file->lock); 816 fibril_mutex_unlock(&file->lock); 814 817 815 818 int retval = IPC_GET_ARG1(answer); … … 863 866 * the same open file at a time. 864 867 */ 865 f utex_down(&file->lock);868 fibril_mutex_lock(&file->lock); 866 869 867 870 /* … … 870 873 */ 871 874 if (read) 872 rwlock_read_lock(&file->node->contents_rwlock);875 fibril_rwlock_read_lock(&file->node->contents_rwlock); 873 876 else 874 rwlock_write_lock(&file->node->contents_rwlock);877 fibril_rwlock_write_lock(&file->node->contents_rwlock); 875 878 876 879 if (file->node->type == VFS_NODE_DIRECTORY) { … … 880 883 */ 881 884 assert(read); 882 rwlock_read_lock(&namespace_rwlock);885 fibril_rwlock_read_lock(&namespace_rwlock); 883 886 } 884 887 … … 900 903 */ 901 904 ipc_forward_fast(callid, fs_phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME); 905 906 vfs_release_phone(fs_phone); 902 907 903 908 /* Wait for reply from the FS server. */ … … 905 910 async_wait_for(msg, &rc); 906 911 907 vfs_release_phone(fs_phone);908 909 912 size_t bytes = IPC_GET_ARG1(answer); 910 913 911 914 if (file->node->type == VFS_NODE_DIRECTORY) 912 rwlock_read_unlock(&namespace_rwlock);915 fibril_rwlock_read_unlock(&namespace_rwlock); 913 916 914 917 /* Unlock the VFS node. */ 915 918 if (read) 916 rwlock_read_unlock(&file->node->contents_rwlock);919 fibril_rwlock_read_unlock(&file->node->contents_rwlock); 917 920 else { 918 921 /* Update the cached version of node's size. */ 919 922 if (rc == EOK) 920 923 file->node->size = IPC_GET_ARG2(answer); 921 rwlock_write_unlock(&file->node->contents_rwlock);924 fibril_rwlock_write_unlock(&file->node->contents_rwlock); 922 925 } 923 926 … … 925 928 if (rc == EOK) 926 929 file->pos += bytes; 927 f utex_up(&file->lock);930 fibril_mutex_unlock(&file->lock); 928 931 929 932 /* … … 959 962 960 963 off_t newpos; 961 f utex_down(&file->lock);964 fibril_mutex_lock(&file->lock); 962 965 if (whence == SEEK_SET) { 963 966 file->pos = off; 964 f utex_up(&file->lock);967 fibril_mutex_unlock(&file->lock); 965 968 ipc_answer_1(rid, EOK, off); 966 969 return; … … 968 971 if (whence == SEEK_CUR) { 969 972 if (file->pos + off < file->pos) { 970 f utex_up(&file->lock);973 fibril_mutex_unlock(&file->lock); 971 974 ipc_answer_0(rid, EOVERFLOW); 972 975 return; … … 974 977 file->pos += off; 975 978 newpos = file->pos; 976 f utex_up(&file->lock);979 fibril_mutex_unlock(&file->lock); 977 980 ipc_answer_1(rid, EOK, newpos); 978 981 return; 979 982 } 980 983 if (whence == SEEK_END) { 981 rwlock_read_lock(&file->node->contents_rwlock);984 fibril_rwlock_read_lock(&file->node->contents_rwlock); 982 985 size_t size = file->node->size; 983 rwlock_read_unlock(&file->node->contents_rwlock);986 fibril_rwlock_read_unlock(&file->node->contents_rwlock); 984 987 if (size + off < size) { 985 f utex_up(&file->lock);988 fibril_mutex_unlock(&file->lock); 986 989 ipc_answer_0(rid, EOVERFLOW); 987 990 return; 988 991 } 989 992 newpos = size + off; 990 f utex_up(&file->lock);993 fibril_mutex_unlock(&file->lock); 991 994 ipc_answer_1(rid, EOK, newpos); 992 995 return; 993 996 } 994 f utex_up(&file->lock);997 fibril_mutex_unlock(&file->lock); 995 998 ipc_answer_0(rid, EINVAL); 996 999 } … … 1021 1024 return; 1022 1025 } 1023 f utex_down(&file->lock);1024 1025 rwlock_write_lock(&file->node->contents_rwlock);1026 fibril_mutex_lock(&file->lock); 1027 1028 fibril_rwlock_write_lock(&file->node->contents_rwlock); 1026 1029 rc = vfs_truncate_internal(file->node->fs_handle, 1027 1030 file->node->dev_handle, file->node->index, size); 1028 1031 if (rc == EOK) 1029 1032 file->node->size = size; 1030 rwlock_write_unlock(&file->node->contents_rwlock);1031 1032 f utex_up(&file->lock);1033 fibril_rwlock_write_unlock(&file->node->contents_rwlock); 1034 1035 fibril_mutex_unlock(&file->lock); 1033 1036 ipc_answer_0(rid, (ipcarg_t)rc); 1034 1037 } … … 1060 1063 path[len] = '\0'; 1061 1064 1062 rwlock_write_lock(&namespace_rwlock);1065 fibril_rwlock_write_lock(&namespace_rwlock); 1063 1066 int lflag = L_DIRECTORY | L_CREATE | L_EXCLUSIVE; 1064 1067 rc = vfs_lookup_internal(path, lflag, NULL, NULL); 1065 rwlock_write_unlock(&namespace_rwlock);1068 fibril_rwlock_write_unlock(&namespace_rwlock); 1066 1069 free(path); 1067 1070 ipc_answer_0(rid, rc); … … 1094 1097 path[len] = '\0'; 1095 1098 1096 rwlock_write_lock(&namespace_rwlock);1099 fibril_rwlock_write_lock(&namespace_rwlock); 1097 1100 lflag &= L_DIRECTORY; /* sanitize lflag */ 1098 1101 vfs_lookup_res_t lr; … … 1100 1103 free(path); 1101 1104 if (rc != EOK) { 1102 rwlock_write_unlock(&namespace_rwlock);1105 fibril_rwlock_write_unlock(&namespace_rwlock); 1103 1106 ipc_answer_0(rid, rc); 1104 1107 return; … … 1114 1117 node->lnkcnt--; 1115 1118 futex_up(&nodes_futex); 1116 rwlock_write_unlock(&namespace_rwlock);1119 fibril_rwlock_write_unlock(&namespace_rwlock); 1117 1120 vfs_node_put(node); 1118 1121 ipc_answer_0(rid, EOK); … … 1195 1198 vfs_lookup_res_t new_lr; 1196 1199 vfs_lookup_res_t new_par_lr; 1197 rwlock_write_lock(&namespace_rwlock);1200 fibril_rwlock_write_lock(&namespace_rwlock); 1198 1201 /* Lookup the node belonging to the old file name. */ 1199 1202 rc = vfs_lookup_internal(oldc, L_NONE, &old_lr, NULL); 1200 1203 if (rc != EOK) { 1201 rwlock_write_unlock(&namespace_rwlock);1204 fibril_rwlock_write_unlock(&namespace_rwlock); 1202 1205 ipc_answer_0(rid, rc); 1203 1206 free(old); … … 1207 1210 vfs_node_t *old_node = vfs_node_get(&old_lr); 1208 1211 if (!old_node) { 1209 rwlock_write_unlock(&namespace_rwlock);1212 fibril_rwlock_write_unlock(&namespace_rwlock); 1210 1213 ipc_answer_0(rid, ENOMEM); 1211 1214 free(old); … … 1216 1219 char *parentc = str_dup(newc); 1217 1220 if (!parentc) { 1218 rwlock_write_unlock(&namespace_rwlock);1221 fibril_rwlock_write_unlock(&namespace_rwlock); 1219 1222 ipc_answer_0(rid, rc); 1220 1223 free(old); … … 1231 1234 free(parentc); /* not needed anymore */ 1232 1235 if (rc != EOK) { 1233 rwlock_write_unlock(&namespace_rwlock);1236 fibril_rwlock_write_unlock(&namespace_rwlock); 1234 1237 ipc_answer_0(rid, rc); 1235 1238 free(old); … … 1240 1243 if ((old_node->fs_handle != new_par_lr.triplet.fs_handle) || 1241 1244 (old_node->dev_handle != new_par_lr.triplet.dev_handle)) { 1242 rwlock_write_unlock(&namespace_rwlock);1245 fibril_rwlock_write_unlock(&namespace_rwlock); 1243 1246 ipc_answer_0(rid, EXDEV); /* different file systems */ 1244 1247 free(old); … … 1256 1259 new_node = vfs_node_get(&new_lr); 1257 1260 if (!new_node) { 1258 rwlock_write_unlock(&namespace_rwlock);1261 fibril_rwlock_write_unlock(&namespace_rwlock); 1259 1262 ipc_answer_0(rid, ENOMEM); 1260 1263 free(old); … … 1267 1270 break; 1268 1271 default: 1269 rwlock_write_unlock(&namespace_rwlock);1272 fibril_rwlock_write_unlock(&namespace_rwlock); 1270 1273 ipc_answer_0(rid, ENOTEMPTY); 1271 1274 free(old); … … 1276 1279 rc = vfs_lookup_internal(newc, L_LINK, NULL, NULL, old_node->index); 1277 1280 if (rc != EOK) { 1278 rwlock_write_unlock(&namespace_rwlock);1281 fibril_rwlock_write_unlock(&namespace_rwlock); 1279 1282 if (new_node) 1280 1283 vfs_node_put(new_node); … … 1290 1293 rc = vfs_lookup_internal(oldc, L_UNLINK, NULL, NULL); 1291 1294 if (rc != EOK) { 1292 rwlock_write_unlock(&namespace_rwlock);1295 fibril_rwlock_write_unlock(&namespace_rwlock); 1293 1296 vfs_node_put(old_node); 1294 1297 if (new_node) … … 1302 1305 old_node->lnkcnt--; 1303 1306 futex_up(&nodes_futex); 1304 rwlock_write_unlock(&namespace_rwlock);1307 fibril_rwlock_write_unlock(&namespace_rwlock); 1305 1308 vfs_node_put(old_node); 1306 1309 if (new_node) -
uspace/srv/vfs/vfs_register.c
r041186f r230260ac 46 46 #include <ctype.h> 47 47 #include <bool.h> 48 #include <f utex.h>48 #include <fibril_sync.h> 49 49 #include <adt/list.h> 50 50 #include <as.h> … … 53 53 #include "vfs.h" 54 54 55 atomic_t fs_head_futex = FUTEX_INITIALIZER;55 FIBRIL_MUTEX_INITIALIZE(fs_head_lock); 56 56 link_t fs_head; 57 57 … … 160 160 } 161 161 link_initialize(&fs_info->fs_link); 162 f utex_initialize(&fs_info->phone_futex, 1);162 fibril_mutex_initialize(&fs_info->phone_lock); 163 163 164 164 rc = ipc_data_write_finalize(callid, &fs_info->vfs_info, size); … … 181 181 } 182 182 183 futex_down(&fs_head_futex); 184 fibril_inc_sercount(); 183 fibril_mutex_lock(&fs_head_lock); 185 184 186 185 /* … … 192 191 */ 193 192 dprintf("FS is already registered.\n"); 194 fibril_dec_sercount(); 195 futex_up(&fs_head_futex); 193 fibril_mutex_unlock(&fs_head_lock); 196 194 free(fs_info); 197 195 ipc_answer_0(callid, EEXISTS); … … 215 213 dprintf("Unexpected call, method = %d\n", IPC_GET_METHOD(call)); 216 214 list_remove(&fs_info->fs_link); 217 fibril_dec_sercount(); 218 futex_up(&fs_head_futex); 215 fibril_mutex_unlock(&fs_head_lock); 219 216 free(fs_info); 220 217 ipc_answer_0(callid, EINVAL); … … 234 231 dprintf("Unexpected call, method = %d\n", IPC_GET_METHOD(call)); 235 232 list_remove(&fs_info->fs_link); 236 fibril_dec_sercount(); 237 futex_up(&fs_head_futex); 233 fibril_mutex_unlock(&fs_head_lock); 238 234 ipc_hangup(fs_info->phone); 239 235 free(fs_info); … … 249 245 dprintf("Client suggests wrong size of PFB, size = %d\n", size); 250 246 list_remove(&fs_info->fs_link); 251 fibril_dec_sercount(); 252 futex_up(&fs_head_futex); 247 fibril_mutex_unlock(&fs_head_lock); 253 248 ipc_hangup(fs_info->phone); 254 249 free(fs_info); … … 274 269 ipc_answer_1(rid, EOK, (ipcarg_t) fs_info->fs_handle); 275 270 276 fibril_dec_sercount(); 277 futex_up(&fs_head_futex); 271 fibril_mutex_unlock(&fs_head_lock); 278 272 279 273 dprintf("\"%.*s\" filesystem successfully registered, handle=%d.\n", … … 298 292 * phone_futex and keep it until vfs_release_phone(). 299 293 */ 300 f utex_down(&fs_head_futex);294 fibril_mutex_lock(&fs_head_lock); 301 295 link_t *cur; 302 296 fs_info_t *fs; … … 304 298 fs = list_get_instance(cur, fs_info_t, fs_link); 305 299 if (fs->fs_handle == handle) { 306 futex_up(&fs_head_futex); 307 /* 308 * For now, take the futex unconditionally. 309 * Oh yeah, serialization rocks. 310 * It will be up'ed in vfs_release_phone(). 311 */ 312 futex_down(&fs->phone_futex); 313 /* 314 * Avoid deadlock with other fibrils in the same thread 315 * by disabling fibril preemption. 316 */ 317 fibril_inc_sercount(); 300 fibril_mutex_unlock(&fs_head_lock); 301 fibril_mutex_lock(&fs->phone_lock); 318 302 return fs->phone; 319 303 } 320 304 } 321 f utex_up(&fs_head_futex);305 fibril_mutex_unlock(&fs_head_lock); 322 306 return 0; 323 307 } … … 331 315 bool found = false; 332 316 333 /* 334 * Undo the fibril_inc_sercount() done in vfs_grab_phone(). 335 */ 336 fibril_dec_sercount(); 337 338 futex_down(&fs_head_futex); 317 fibril_mutex_lock(&fs_head_lock); 339 318 link_t *cur; 340 319 for (cur = fs_head.next; cur != &fs_head; cur = cur->next) { … … 342 321 if (fs->phone == phone) { 343 322 found = true; 344 f utex_up(&fs_head_futex);345 f utex_up(&fs->phone_futex);323 fibril_mutex_unlock(&fs_head_lock); 324 fibril_mutex_unlock(&fs->phone_lock); 346 325 return; 347 326 } 348 327 } 349 f utex_up(&fs_head_futex);328 fibril_mutex_unlock(&fs_head_lock); 350 329 351 330 /* … … 358 337 * 359 338 * @param name File system name. 360 * @param lock If true, the function will down and upthe361 * fs_head_ futex.339 * @param lock If true, the function will lock and unlock the 340 * fs_head_lock. 362 341 * 363 342 * @return File system handle or zero if file system not found. … … 368 347 369 348 if (lock) 370 f utex_down(&fs_head_futex);349 fibril_mutex_lock(&fs_head_lock); 371 350 link_t *cur; 372 351 for (cur = fs_head.next; cur != &fs_head; cur = cur->next) { … … 378 357 } 379 358 if (lock) 380 f utex_up(&fs_head_futex);359 fibril_mutex_unlock(&fs_head_lock); 381 360 return handle; 382 361 }
Note:
See TracChangeset
for help on using the changeset viewer.