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.
This commit is contained in:
Arne Welzel 2012-09-27 22:23:49 +02:00 committed by Ben Gras
parent 7e1074732b
commit e35c4f78d2
2 changed files with 17 additions and 4 deletions

View file

@ -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);

View file

@ -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 *
*===========================================================================*/