From e33ba5895dbad524e0a26fd0b2b8baee4d43b466 Mon Sep 17 00:00:00 2001 From: Bobi Jam Date: Thu, 29 May 2014 15:55:27 +0800 Subject: [PATCH] LU-4308 llite: protect file write and page_mkwrite race Normal file write also need to grab a read semaphore of lli_trunc_sem so that it would not race against ll_page_mkwrite. Signed-off-by: Bobi Jam Change-Id: I6cc2980b9e67e48bfb132296cf6c36ae69d4c153 Reviewed-on: http://review.whamcloud.com/11098 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Lai Siyao Reviewed-by: Oleg Drokin --- lustre/llite/file.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lustre/llite/file.c b/lustre/llite/file.c index 37116df..e1b8620 100644 --- a/lustre/llite/file.c +++ b/lustre/llite/file.c @@ -1151,12 +1151,11 @@ restart: if ((iot == CIT_WRITE) && !(cio->cui_fd->fd_flags & LL_FILE_GROUP_LOCKED)) { if (mutex_lock_interruptible(&lli-> - lli_write_mutex)) - GOTO(out, result = -ERESTARTSYS); - write_mutex_locked = 1; - } else if (iot == CIT_READ) { - down_read(&lli->lli_trunc_sem); - } + lli_write_mutex)) + GOTO(out, result = -ERESTARTSYS); + write_mutex_locked = 1; + } + down_read(&lli->lli_trunc_sem); break; case IO_SENDFILE: vio->u.sendfile.cui_actor = args->u.sendfile.via_actor; @@ -1171,10 +1170,10 @@ restart: LBUG(); } result = cl_io_loop(env, io); - if (write_mutex_locked) - mutex_unlock(&lli->lli_write_mutex); - else if (args->via_io_subtype == IO_NORMAL && iot == CIT_READ) + if (args->via_io_subtype == IO_NORMAL) up_read(&lli->lli_trunc_sem); + if (write_mutex_locked) + mutex_unlock(&lli->lli_write_mutex); } else { /* cl_io_rw_init() handled IO */ result = io->ci_result; -- 1.8.3.1