Changeset c577a9a in mainline
- Timestamp:
- 2017-03-05T20:23:05Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 354b642
- Parents:
- 1dff985
- git-author:
- Jiri Zarevucky <zarevucky.jiri@…> (2017-03-05 20:23:05)
- git-committer:
- Jakub Jermar <jakub@…> (2017-03-05 20:23:05)
- Location:
- uspace/srv/vfs
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/vfs/vfs.h
r1dff985 rc577a9a 129 129 typedef struct { 130 130 /** Serializes access to this open file. */ 131 fibril_mutex_t lock;131 fibril_mutex_t _lock; 132 132 133 133 vfs_node_t *node; … … 202 202 extern void vfs_file_put(vfs_file_t *); 203 203 extern int vfs_fd_assign(vfs_file_t *, int); 204 extern int vfs_fd_alloc( bool desc);204 extern int vfs_fd_alloc(vfs_file_t **file, bool desc); 205 205 extern int vfs_fd_free(int); 206 206 -
uspace/srv/vfs/vfs_file.c
r1dff985 rc577a9a 187 187 } 188 188 189 static int _vfs_fd_alloc(vfs_client_data_t *vfs_data, bool desc)189 static int _vfs_fd_alloc(vfs_client_data_t *vfs_data, vfs_file_t **file, bool desc) 190 190 { 191 191 if (!vfs_files_init(vfs_data)) … … 207 207 } 208 208 209 209 210 memset(vfs_data->files[i], 0, sizeof(vfs_file_t)); 210 fibril_mutex_initialize(&vfs_data->files[i]->lock); 211 212 fibril_mutex_initialize(&vfs_data->files[i]->_lock); 213 fibril_mutex_lock(&vfs_data->files[i]->_lock); 211 214 vfs_file_addref(vfs_data, vfs_data->files[i]); 215 216 *file = vfs_data->files[i]; 217 vfs_file_addref(vfs_data, *file); 218 212 219 fibril_mutex_unlock(&vfs_data->lock); 213 220 return (int) i; … … 233 240 /** Allocate a file descriptor. 234 241 * 242 * @param file Is set to point to the newly created file structure. Must be put afterwards. 235 243 * @param desc If true, look for an available file descriptor 236 244 * in a descending order. … … 239 247 * code. 240 248 */ 241 int vfs_fd_alloc( bool desc)242 { 243 return _vfs_fd_alloc(VFS_DATA, desc);249 int vfs_fd_alloc(vfs_file_t **file, bool desc) 250 { 251 return _vfs_fd_alloc(VFS_DATA, file, desc); 244 252 } 245 253 … … 314 322 vfs_file_addref(vfs_data, file); 315 323 fibril_mutex_unlock(&vfs_data->lock); 324 fibril_mutex_lock(&file->_lock); 316 325 return file; 317 326 } … … 335 344 static void _vfs_file_put(vfs_client_data_t *vfs_data, vfs_file_t *file) 336 345 { 346 fibril_mutex_unlock(&file->_lock); 347 337 348 fibril_mutex_lock(&vfs_data->lock); 338 349 vfs_file_delref(vfs_data, file); … … 376 387 goto out; 377 388 378 acceptor_fd = _vfs_fd_alloc(acceptor_data, false);389 acceptor_fd = _vfs_fd_alloc(acceptor_data, &acceptor_file, false); 379 390 if (acceptor_fd < 0) 380 391 goto out; … … 388 399 (void) vfs_open_node_remote(donor_file->node); 389 400 390 acceptor_file = _vfs_file_get(acceptor_data, acceptor_fd);391 401 assert(acceptor_file); 392 402 -
uspace/srv/vfs/vfs_ops.c
r1dff985 rc577a9a 500 500 vfs_node_t *node = vfs_node_get(&lr); 501 501 502 int fd = vfs_fd_alloc(false); 502 vfs_file_t *file; 503 int fd = vfs_fd_alloc(&file, false); 503 504 if (fd < 0) { 504 505 vfs_node_put(node); … … 509 510 return; 510 511 } 511 512 vfs_file_t *file = vfs_file_get(fd);513 512 assert(file != NULL); 514 513 … … 598 597 * the same open file at a time. 599 598 */ 600 fibril_mutex_lock(&file->lock);601 599 async_exch_t *fs_exch = vfs_exchange_grab(file->node->fs_handle); 602 600 … … 612 610 sysarg_t rc; 613 611 async_wait_for(msg, &rc); 614 615 fibril_mutex_unlock(&file->lock);616 612 617 613 vfs_file_put(file); … … 702 698 return ENOENT; 703 699 704 /*705 * Lock the open file structure so that no other thread can manipulate706 * the same open file at a time.707 */708 fibril_mutex_lock(&file->lock);709 710 700 if ((read && !file->open_read) || (!read && !file->open_write)) { 711 fibril_mutex_unlock(&file->lock);701 vfs_file_put(file); 712 702 return EINVAL; 713 703 } … … 770 760 if (rc == EOK) 771 761 file->pos += bytes; 772 fibril_mutex_unlock(&file->lock);773 762 vfs_file_put(file); 774 763 … … 812 801 return; 813 802 } 814 815 fibril_mutex_lock(&file->lock);816 803 817 804 off64_t newoff; … … 820 807 if (off >= 0) { 821 808 file->pos = (aoff64_t) off; 822 fibril_mutex_unlock(&file->lock);823 809 vfs_file_put(file); 824 810 async_answer_1(rid, EOK, off); … … 828 814 case SEEK_CUR: 829 815 if ((off >= 0) && (file->pos + off < file->pos)) { 830 fibril_mutex_unlock(&file->lock);831 816 vfs_file_put(file); 832 817 async_answer_0(rid, EOVERFLOW); … … 835 820 836 821 if ((off < 0) && (file->pos < (aoff64_t) -off)) { 837 fibril_mutex_unlock(&file->lock);838 822 vfs_file_put(file); 839 823 async_answer_0(rid, EOVERFLOW); … … 844 828 newoff = (file->pos > OFF64_MAX) ? OFF64_MAX : file->pos; 845 829 846 fibril_mutex_unlock(&file->lock);847 830 vfs_file_put(file); 848 831 async_answer_2(rid, EOK, LOWER32(newoff), … … 855 838 if ((off >= 0) && (size + off < size)) { 856 839 fibril_rwlock_read_unlock(&file->node->contents_rwlock); 857 fibril_mutex_unlock(&file->lock);858 840 vfs_file_put(file); 859 841 async_answer_0(rid, EOVERFLOW); … … 863 845 if ((off < 0) && (size < (aoff64_t) -off)) { 864 846 fibril_rwlock_read_unlock(&file->node->contents_rwlock); 865 fibril_mutex_unlock(&file->lock);866 847 vfs_file_put(file); 867 848 async_answer_0(rid, EOVERFLOW); … … 873 854 874 855 fibril_rwlock_read_unlock(&file->node->contents_rwlock); 875 fibril_mutex_unlock(&file->lock);876 856 vfs_file_put(file); 877 857 async_answer_2(rid, EOK, LOWER32(newoff), UPPER32(newoff)); … … 879 859 } 880 860 881 fibril_mutex_unlock(&file->lock);882 861 vfs_file_put(file); 883 862 async_answer_0(rid, EINVAL); … … 908 887 return; 909 888 } 910 fibril_mutex_lock(&file->lock);911 889 912 890 fibril_rwlock_write_lock(&file->node->contents_rwlock); … … 917 895 fibril_rwlock_write_unlock(&file->node->contents_rwlock); 918 896 919 fibril_mutex_unlock(&file->lock);920 897 vfs_file_put(file); 921 898 async_answer_0(rid, (sysarg_t)rc); … … 932 909 return; 933 910 } 911 assert(file->node); 934 912 935 913 ipc_callid_t callid; … … 941 919 } 942 920 943 fibril_mutex_lock(&file->lock);944 945 921 async_exch_t *exch = vfs_exchange_grab(file->node->fs_handle); 922 assert(exch); 946 923 947 924 aid_t msg; 948 925 msg = async_send_3(exch, VFS_OUT_STAT, file->node->service_id, 949 926 file->node->index, true, NULL); 927 assert(msg); 950 928 async_forward_fast(callid, exch, 0, 0, 0, IPC_FF_ROUTE_FROM_ME); 951 929 … … 954 932 async_wait_for(msg, &rc); 955 933 956 fibril_mutex_unlock(&file->lock);957 934 vfs_file_put(file); 958 935 async_answer_0(rid, rc); … … 989 966 int lflag = (wflag&WALK_DIRECTORY) ? L_DIRECTORY: 0; 990 967 991 if (parentfd >= 0) { 968 /* Files are retrieved in order of file descriptors, to prevent deadlock. */ 969 if (parentfd >= 0 && parentfd < expectfd) { 992 970 parent = vfs_file_get(parentfd); 993 971 if (!parent) { … … 995 973 goto exit; 996 974 } 997 parent_node = parent->node;998 975 } 999 976 … … 1004 981 goto exit; 1005 982 } 1006 983 } 984 985 if (parentfd >= 0 && parentfd >= expectfd) { 986 parent = vfs_file_get(parentfd); 987 if (!parent) { 988 rc = ENOENT; 989 goto exit; 990 } 991 } 992 993 if (parent) { 994 parent_node = parent->node; 995 } 996 997 if (expectfd >= 0) { 1007 998 vfs_lookup_res_t lr; 1008 999 rc = vfs_lookup_internal(parent_node, path, lflag, &lr); … … 1228 1219 } 1229 1220 1230 /*1231 * Lock the open file structure so that no other thread can manipulate1232 * the same open file at a time.1233 */1234 fibril_mutex_lock(&oldfile->lock);1235 1236 1221 /* Make sure newfd is closed. */ 1237 1222 (void) vfs_fd_free(newfd); … … 1239 1224 /* Assign the old file to newfd. */ 1240 1225 int ret = vfs_fd_assign(oldfile, newfd); 1241 fibril_mutex_unlock(&oldfile->lock);1242 1226 vfs_file_put(oldfile); 1243 1227 -
uspace/srv/vfs/vfs_pager.c
r1dff985 rc577a9a 71 71 }; 72 72 73 fibril_mutex_lock(&file->lock);74 73 file->pos = offset; 75 fibril_mutex_unlock(&file->lock);76 74 77 75 size_t total = 0;
Note:
See TracChangeset
for help on using the changeset viewer.