From: Arne Welzel Date: Thu, 27 Sep 2012 20:23:49 +0000 (+0200) Subject: VFS: fix check_bsf() locking X-Git-Tag: v3.2.1~297 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/Bv9ARM.ch01.html?a=commitdiff_plain;h=e35c4f78d23a36aba640c71de5a694c5cc88c7c4;p=minix.git VFS: fix check_bsf() locking The check_bsf() macro uses assert(mutex_trylock(&bsf_lock)) and assumes bsf_lock is locked afterwards. This breaks when compiling with NOASSERTS="yes". Also: macro to function transition. --- diff --git a/servers/vfs/proto.h b/servers/vfs/proto.h index 735624472..74b4b8ab8 100644 --- a/servers/vfs/proto.h +++ b/servers/vfs/proto.h @@ -78,10 +78,6 @@ void write_elf_core_file(struct filp *f, int csig, char *exe_name); /* exec.c */ int pm_exec(endpoint_t proc_e, vir_bytes path, size_t path_len, vir_bytes frame, size_t frame_len, vir_bytes *pc, vir_bytes *newsp, int flags); -#define check_bsf_lock() do { \ - assert(mutex_trylock(&bsf_lock) == 0); \ - unlock_bsf(); \ - } while(0) /* filedes.c */ void *do_filp_gc(void *arg); @@ -213,6 +209,7 @@ int do_read(void); int do_getdents(void); void lock_bsf(void); void unlock_bsf(void); +void check_bsf_lock(void); int do_read_write(int rw_flag); int read_write(int rw_flag, struct filp *f, char *buffer, size_t nbytes, endpoint_t for_e); diff --git a/servers/vfs/read.c b/servers/vfs/read.c index 4b7715017..db6a65558 100644 --- a/servers/vfs/read.c +++ b/servers/vfs/read.c @@ -65,6 +65,22 @@ void unlock_bsf(void) panic("failed to unlock block special file lock"); } +/*===========================================================================* + * check_bsf * + *===========================================================================*/ +void check_bsf_lock(void) +{ + int r = mutex_trylock(&bsf_lock); + + if (r == -EBUSY) + panic("bsf_lock locked"); + else if (r != 0) + panic("bsf_lock weird state"); + + /* r == 0 */ + unlock_bsf(); +} + /*===========================================================================* * do_read_write * *===========================================================================*/