Whamcloud - gitweb
LU-4308 llite: protect file write and page_mkwrite race 98/11098/2
authorBobi Jam <bobijam.xu@intel.com>
Thu, 29 May 2014 07:55:27 +0000 (15:55 +0800)
committerOleg Drokin <oleg.drokin@intel.com>
Thu, 14 Aug 2014 14:08:29 +0000 (14:08 +0000)
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 <bobijam.xu@intel.com>
Change-Id: I6cc2980b9e67e48bfb132296cf6c36ae69d4c153
Reviewed-on: http://review.whamcloud.com/11098
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Lai Siyao <lai.siyao@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/llite/file.c

index 37116df..e1b8620 100644 (file)
@@ -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;