Whamcloud - gitweb
LU-7198 clio: remove mtime check in vvp_io_fault_start()
[fs/lustre-release.git] / lustre / llite / vvp_io.c
index 1fae402..a076e5a 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2014, Intel Corporation.
+ * Copyright (c) 2011, 2015, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -238,6 +238,7 @@ static int vvp_io_one_lock_index(const struct lu_env *env, struct cl_io *io,
        if (vio->vui_fd && (vio->vui_fd->fd_flags & LL_FILE_GROUP_LOCKED)) {
                descr->cld_mode = CLM_GROUP;
                descr->cld_gid  = vio->vui_fd->fd_grouplock.lg_gid;
+               enqflags |= CEF_LOCK_MATCH;
        } else {
                descr->cld_mode  = mode;
        }
@@ -310,7 +311,7 @@ static void vvp_io_fini(const struct lu_env *env, const struct cl_io_slice *ios)
               io->ci_ignore_layout, io->ci_verify_layout,
               vio->vui_layout_gen, io->ci_restore_needed);
 
-       if (io->ci_restore_needed == 1) {
+       if (io->ci_restore_needed) {
                int     rc;
 
                /* file was detected release, we need to restore it
@@ -351,8 +352,8 @@ static void vvp_io_fini(const struct lu_env *env, const struct cl_io_slice *ios)
                        /* today successful restore is the only possible
                         * case */
                        /* restore was done, clear restoring state */
-                       ll_i2info(vvp_object_inode(obj))->lli_flags &=
-                               ~LLIF_FILE_RESTORING;
+                       ll_file_clear_flag(ll_i2info(vvp_object_inode(obj)),
+                                          LLIF_FILE_RESTORING);
                }
        }
 }
@@ -389,33 +390,41 @@ static int vvp_mmap_locks(const struct lu_env *env,
                          struct vvp_io *vio, struct cl_io *io)
 {
        struct vvp_thread_info *vti = vvp_env_info(env);
-        struct mm_struct       *mm = current->mm;
-        struct vm_area_struct  *vma;
-       struct cl_lock_descr   *descr = &vti->vti_descr;
-        ldlm_policy_data_t      policy;
-        unsigned long           addr;
-        unsigned long           seg;
-        ssize_t                 count;
-       int                     result = 0;
-        ENTRY;
-
-        LASSERT(io->ci_type == CIT_READ || io->ci_type == CIT_WRITE);
-
-        if (!cl_is_normalio(env, io))
-                RETURN(0);
-
-       if (vio->vui_iov == NULL) /* nfs or loop back device write */
+       struct mm_struct *mm = current->mm;
+       struct vm_area_struct *vma;
+       struct cl_lock_descr *descr = &vti->vti_descr;
+       union ldlm_policy_data policy;
+#ifdef HAVE_FILE_OPERATIONS_READ_WRITE_ITER
+       struct iovec iov;
+       struct iov_iter i;
+#else
+       unsigned long seg;
+#endif
+       int result = 0;
+       ENTRY;
+
+       LASSERT(io->ci_type == CIT_READ || io->ci_type == CIT_WRITE);
+
+       if (!cl_is_normalio(env, io))
+               RETURN(0);
+
+       /* nfs or loop back device write */
+       if (vio->vui_iter == NULL)
                RETURN(0);
 
        /* No MM (e.g. NFS)? No vmas too. */
        if (mm == NULL)
                RETURN(0);
 
-       for (seg = 0; seg < vio->vui_nrsegs; seg++) {
-               const struct iovec *iv = &vio->vui_iov[seg];
+#ifdef HAVE_FILE_OPERATIONS_READ_WRITE_ITER
+       iov_for_each(iov, i, *(vio->vui_iter)) {
+#else /* !HAVE_FILE_OPERATIONS_READ_WRITE_ITER */
+       for (seg = 0; seg < vio->vui_iter->nr_segs; seg++) {
+               const struct iovec iov = vio->vui_iter->iov[seg];
+#endif /* HAVE_FILE_OPERATIONS_READ_WRITE_ITER */
+               unsigned long addr = (unsigned long)iov.iov_base;
+               size_t count = iov.iov_len;
 
-                addr = (unsigned long)iv->iov_base;
-                count = iv->iov_len;
                 if (count == 0)
                         continue;
 
@@ -478,24 +487,39 @@ static void vvp_io_advance(const struct lu_env *env,
        struct vvp_io    *vio = cl2vvp_io(env, ios);
        struct cl_io     *io  = ios->cis_io;
        struct cl_object *obj = ios->cis_io->ci_obj;
+#ifndef HAVE_FILE_OPERATIONS_READ_WRITE_ITER
        struct iovec     *iov;
-
+#endif
        CLOBINVRNT(env, obj, vvp_object_invariant(obj));
 
        if (!cl_is_normalio(env, io))
                return;
 
-       LASSERT(vio->vui_tot_nrsegs >= vio->vui_nrsegs);
+#ifdef HAVE_FILE_OPERATIONS_READ_WRITE_ITER
+       vio->vui_tot_count -= nob;
+       iov_iter_reexpand(vio->vui_iter, vio->vui_tot_count);
+#else /* !HAVE_FILE_OPERATIONS_READ_WRITE_ITER */
+       LASSERT(vio->vui_tot_nrsegs >= vio->vui_iter->nr_segs);
        LASSERT(vio->vui_tot_count  >= nob);
 
        /* Restore the iov changed in vvp_io_update_iov() */
        if (vio->vui_iov_olen > 0) {
-               vio->vui_iov[vio->vui_nrsegs - 1].iov_len = vio->vui_iov_olen;
+               unsigned long idx = vio->vui_iter->nr_segs - 1;
+
+               /* In the latest kernels iov is const so that
+                * changes are done using iter helpers. In older
+                * kernels those helpers don't exist we lustre
+                * has to do some of the management of the iter
+                * itself. */
+               iov = (struct iovec *)&vio->vui_iter->iov[idx];
+               iov->iov_len = vio->vui_iov_olen;
                vio->vui_iov_olen = 0;
        }
 
-       /* advance iov */
-       iov = vio->vui_iov;
+       /* In the latest kernels special helpers exist to help
+        * advance the iov but we don't have that in older kernels
+        * so we need to do the book keeping ourselves. */
+       iov = (struct iovec *)vio->vui_iter->iov;
        while (nob > 0) {
                if (iov->iov_len > nob) {
                        iov->iov_len -= nob;
@@ -508,22 +532,29 @@ static void vvp_io_advance(const struct lu_env *env,
                vio->vui_tot_nrsegs--;
        }
 
-       vio->vui_iov = iov;
+       vio->vui_iter->iov = iov;
        vio->vui_tot_count -= nob;
+#endif /* HAVE_FILE_OPERATIONS_READ_WRITE_ITER */
 }
 
 static void vvp_io_update_iov(const struct lu_env *env,
                              struct vvp_io *vio, struct cl_io *io)
 {
-       int i;
        size_t size = io->u.ci_rw.crw_count;
+#ifdef HAVE_FILE_OPERATIONS_READ_WRITE_ITER
+       if (!cl_is_normalio(env, io) || vio->vui_iter == NULL)
+               return;
+
+       iov_iter_truncate(vio->vui_iter, size);
+#else /* !HAVE_FILE_OPERATIONS_READ_WRITE_ITER */
+       unsigned long i;
 
        vio->vui_iov_olen = 0;
        if (!cl_is_normalio(env, io) || vio->vui_tot_nrsegs == 0)
                return;
 
        for (i = 0; i < vio->vui_tot_nrsegs; i++) {
-               struct iovec *iv = &vio->vui_iov[i];
+               struct iovec *iv = (struct iovec *) &vio->vui_iter->iov[i];
 
                if (iv->iov_len < size) {
                        size -= iv->iov_len;
@@ -536,10 +567,11 @@ static void vvp_io_update_iov(const struct lu_env *env,
                }
        }
 
-       vio->vui_nrsegs = i + 1;
-       LASSERTF(vio->vui_tot_nrsegs >= vio->vui_nrsegs,
+       vio->vui_iter->nr_segs = i + 1;
+       LASSERTF(vio->vui_tot_nrsegs >= vio->vui_iter->nr_segs,
                 "tot_nrsegs: %lu, nrsegs: %lu\n",
-                vio->vui_tot_nrsegs, vio->vui_nrsegs);
+                vio->vui_tot_nrsegs, vio->vui_iter->nr_segs);
+#endif /* !HAVE_FILE_OPERATIONS_READ_WRITE_ITER */
 }
 
 static int vvp_io_rw_lock(const struct lu_env *env, struct cl_io *io,
@@ -736,7 +768,15 @@ static void vvp_io_setattr_end(const struct lu_env *env,
 static void vvp_io_setattr_fini(const struct lu_env *env,
                                const struct cl_io_slice *ios)
 {
+       bool restore_needed = ios->cis_io->ci_restore_needed;
+       struct inode *inode = vvp_object_inode(ios->cis_obj);
+
        vvp_io_fini(env, ios);
+
+       if (restore_needed && !ios->cis_io->ci_restore_needed) {
+               /* restore finished, set data modified flag for HSM */
+               ll_file_set_flag(ll_i2info(inode), LLIF_DATA_MODIFIED);
+       }
 }
 
 static int vvp_io_read_start(const struct lu_env *env,
@@ -791,9 +831,14 @@ static int vvp_io_read_start(const struct lu_env *env,
        switch (vio->vui_io_subtype) {
        case IO_NORMAL:
                LASSERT(vio->vui_iocb->ki_pos == pos);
+#ifdef HAVE_FILE_OPERATIONS_READ_WRITE_ITER
+               result = generic_file_read_iter(vio->vui_iocb, vio->vui_iter);
+#else
                result = generic_file_aio_read(vio->vui_iocb,
-                                              vio->vui_iov, vio->vui_nrsegs,
+                                              vio->vui_iter->iov,
+                                              vio->vui_iter->nr_segs,
                                               vio->vui_iocb->ki_pos);
+#endif
                break;
        case IO_SPLICE:
                result = generic_file_splice_read(file, &pos,
@@ -1046,7 +1091,7 @@ static int vvp_io_write_start(const struct lu_env *env,
                RETURN(-EFBIG);
        }
 
-       if (vio->vui_iov == NULL) {
+       if (vio->vui_iter == NULL) {
                /* from a temp io in ll_cl_init(). */
                result = 0;
        } else {
@@ -1058,9 +1103,14 @@ static int vvp_io_write_start(const struct lu_env *env,
                 * consistency, proper locking to protect against writes,
                 * trucates, etc. is handled in the higher layers of lustre.
                 */
+#ifdef HAVE_FILE_OPERATIONS_READ_WRITE_ITER
+               result = generic_file_write_iter(vio->vui_iocb, vio->vui_iter);
+#else
                result = __generic_file_aio_write(vio->vui_iocb,
-                                                 vio->vui_iov, vio->vui_nrsegs,
+                                                 vio->vui_iter->iov,
+                                                 vio->vui_iter->nr_segs,
                                                  &vio->vui_iocb->ki_pos);
+#endif
                if (result > 0 || result == -EIOCBQUEUED) {
                        ssize_t err;
 
@@ -1082,11 +1132,7 @@ static int vvp_io_write_start(const struct lu_env *env,
                }
        }
        if (result > 0) {
-               struct ll_inode_info *lli = ll_i2info(inode);
-
-               spin_lock(&lli->lli_lock);
-               lli->lli_flags |= LLIF_DATA_MODIFIED;
-               spin_unlock(&lli->lli_lock);
+               ll_file_set_flag(ll_i2info(inode), LLIF_DATA_MODIFIED);
 
                if (result < cnt)
                        io->ci_continue = 0;
@@ -1171,12 +1217,6 @@ static int vvp_io_fault_start(const struct lu_env *env,
        pgoff_t                  last_index;
        ENTRY;
 
-       if (fio->ft_executable &&
-           LTIME_S(inode->i_mtime) != vio->u.fault.ft_mtime)
-               CWARN("binary "DFID
-                     " changed while waiting for the page fault lock\n",
-                     PFID(lu_object_fid(&obj->co_lu)));
-
        down_read(&lli->lli_trunc_sem);
 
         /* offset of the last byte on the page */
@@ -1397,7 +1437,10 @@ static const struct cl_io_operations vvp_io_ops = {
                },
                [CIT_MISC] = {
                        .cio_fini       = vvp_io_fini
-               }
+               },
+               [CIT_LADVISE] = {
+                       .cio_fini       = vvp_io_fini
+               },
        },
        .cio_read_ahead = vvp_io_read_ahead
 };
@@ -1433,7 +1476,9 @@ int vvp_io_init(const struct lu_env *env, struct cl_object *obj,
                         result = 1;
                else {
                        vio->vui_tot_count = count;
+#ifndef HAVE_FILE_OPERATIONS_READ_WRITE_ITER
                        vio->vui_tot_nrsegs = 0;
+#endif
                }
 
                /* for read/write, we store the jobid in the inode, and