*
* You should have received a copy of the GNU General Public License
* version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
+ * http://www.gnu.org/licenses/gpl-2.0.html
*
* GPL HEADER END
*/
* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*
- * Copyright (c) 2011, 2015, Intel Corporation.
+ * Copyright (c) 2011, 2017, Intel Corporation.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
#include <obd.h>
#include "llite_internal.h"
#include "vvp_internal.h"
+#include <libcfs/linux/linux-misc.h>
static struct vvp_io *cl2vvp_io(const struct lu_env *env,
const struct cl_io_slice *slice)
* --bug 17336 */
loff_t size = i_size_read(inode);
unsigned long cur_index = start >>
- PAGE_CACHE_SHIFT;
+ PAGE_SHIFT;
if ((size == 0 && cur_index != 0) ||
- (((size - 1) >> PAGE_CACHE_SHIFT) <
+ (((size - 1) >> PAGE_SHIFT) <
cur_index))
*exceed = 1;
}
struct inode *inode = vvp_object_inode(ios->cis_obj);
LASSERT(inode == file_inode(vio->vui_fd->fd_file));
- vio->u.fault.ft_mtime = LTIME_S(inode->i_mtime);
+ vio->u.fault.ft_mtime = inode->i_mtime.tv_sec;
return 0;
}
struct cl_object *obj = io->ci_obj;
struct vvp_io *vio = cl2vvp_io(env, ios);
struct inode *inode = vvp_object_inode(obj);
+ __u32 gen = 0;
+ int rc;
+ ENTRY;
CLOBINVRNT(env, obj, vvp_object_invariant(obj));
CDEBUG(D_VFSTRACE, DFID" ignore/verify layout %d/%d, layout version %d "
- "restore needed %d\n",
+ "need write layout %d, restore needed %d\n",
PFID(lu_object_fid(&obj->co_lu)),
io->ci_ignore_layout, io->ci_verify_layout,
- vio->vui_layout_gen, io->ci_restore_needed);
+ vio->vui_layout_gen, io->ci_need_write_intent,
+ io->ci_restore_needed);
if (io->ci_restore_needed) {
- int rc;
-
/* file was detected release, we need to restore it
* before finishing the io
*/
* block on layout lock held by the MDT
* as MDT will not send new layout in lvb (see LU-3124)
* we have to explicitly fetch it, all this will be done
- * by ll_layout_refresh()
+ * by ll_layout_refresh().
+ * Even if ll_layout_restore() returns zero, it doesn't mean
+ * that restore has been successful. Therefore it sets
+ * ci_verify_layout so that it will check layout at the end
+ * of this function.
*/
- if (rc == 0) {
- io->ci_restore_needed = 0;
- io->ci_need_restart = 1;
- io->ci_verify_layout = 1;
- } else {
+ if (rc) {
io->ci_restore_needed = 1;
io->ci_need_restart = 0;
io->ci_verify_layout = 0;
io->ci_result = rc;
+ GOTO(out, rc);
}
- }
- if (!io->ci_ignore_layout && io->ci_verify_layout) {
- __u32 gen = 0;
+ io->ci_restore_needed = 0;
- /* check layout version */
+ /* Even if ll_layout_restore() returns zero, it doesn't mean
+ * that restore has been successful. Therefore it should verify
+ * if there was layout change and restart I/O correspondingly.
+ */
ll_layout_refresh(inode, &gen);
io->ci_need_restart = vio->vui_layout_gen != gen;
if (io->ci_need_restart) {
ll_file_clear_flag(ll_i2info(vvp_object_inode(obj)),
LLIF_FILE_RESTORING);
}
+ GOTO(out, 0);
+ }
+
+ /**
+ * dynamic layout change needed, send layout intent
+ * RPC.
+ */
+ if (io->ci_need_write_intent) {
+ enum layout_intent_opc opc = LAYOUT_INTENT_WRITE;
+
+ io->ci_need_write_intent = 0;
+
+ LASSERT(io->ci_type == CIT_WRITE ||
+ cl_io_is_trunc(io) || cl_io_is_mkwrite(io));
+
+ CDEBUG(D_VFSTRACE, DFID" write layout, type %u "DEXT"\n",
+ PFID(lu_object_fid(&obj->co_lu)), io->ci_type,
+ PEXT(&io->ci_write_intent));
+
+ if (cl_io_is_trunc(io))
+ opc = LAYOUT_INTENT_TRUNC;
+
+ rc = ll_layout_write_intent(inode, opc, &io->ci_write_intent);
+ io->ci_result = rc;
+ if (!rc)
+ io->ci_need_restart = 1;
+ GOTO(out, rc);
+ }
+
+ if (!io->ci_need_restart &&
+ !io->ci_ignore_layout && io->ci_verify_layout) {
+ /* check layout version */
+ ll_layout_refresh(inode, &gen);
+ io->ci_need_restart = vio->vui_layout_gen != gen;
+ if (io->ci_need_restart) {
+ CDEBUG(D_VFSTRACE,
+ DFID" layout changed from %d to %d.\n",
+ PFID(lu_object_fid(&obj->co_lu)),
+ vio->vui_layout_gen, gen);
+ }
+ GOTO(out, 0);
}
+out:
+ EXIT;
}
static void vvp_io_fault_fini(const struct lu_env *env,
union ldlm_policy_data policy;
struct iovec iov;
struct iov_iter i;
+ unsigned long addr;
+ ssize_t count;
int result = 0;
ENTRY;
if (mm == NULL)
RETURN(0);
- iov_for_each(iov, i, *(vio->vui_iter)) {
- unsigned long addr = (unsigned long)iov.iov_base;
- size_t count = iov.iov_len;
+ if (!iter_is_iovec(vio->vui_iter) && !iov_iter_is_kvec(vio->vui_iter))
+ RETURN(0);
+
+ for (i = *vio->vui_iter;
+ iov_iter_count(&i);
+ iov_iter_advance(&i, iov.iov_len)) {
+ iov = iov_iter_iovec(&i);
+ addr = (unsigned long)iov.iov_base;
+ count = iov.iov_len;
if (count == 0)
continue;
if (io->u.ci_rw.crw_nonblock)
ast_flags |= CEF_NONBLOCK;
+ if (io->ci_lock_no_expand)
+ ast_flags |= CEF_LOCK_NO_EXPAND;
result = vvp_mmap_locks(env, vio, io);
if (result == 0)
result = vvp_io_one_lock(env, io, ast_flags, mode, start, end);
- RETURN(result);
+ RETURN(result);
}
static int vvp_io_read_lock(const struct lu_env *env,
const struct cl_io_slice *ios)
{
- struct cl_io *io = ios->cis_io;
- struct cl_io_rw_common *rd = &io->u.ci_rd.rd;
+ struct cl_io *io = ios->cis_io;
+ struct cl_io_rw_common *rd = &io->u.ci_rd.rd;
int result;
ENTRY;
}
static int vvp_io_write_lock(const struct lu_env *env,
- const struct cl_io_slice *ios)
+ const struct cl_io_slice *ios)
{
- struct cl_io *io = ios->cis_io;
- loff_t start;
- loff_t end;
-
- if (io->u.ci_wr.wr_append) {
- start = 0;
- end = OBD_OBJECT_EOF;
- } else {
- start = io->u.ci_wr.wr.crw_pos;
- end = start + io->u.ci_wr.wr.crw_count - 1;
- }
- return vvp_io_rw_lock(env, io, CLM_WRITE, start, end);
+ struct cl_io *io = ios->cis_io;
+ loff_t start;
+ loff_t end;
+
+ if (io->u.ci_wr.wr_append) {
+ start = 0;
+ end = OBD_OBJECT_EOF;
+ } else {
+ start = io->u.ci_wr.wr.crw_pos;
+ end = start + io->u.ci_wr.wr.crw_count - 1;
+ }
+
+ RETURN(vvp_io_rw_lock(env, io, CLM_WRITE, start, end));
}
static int vvp_io_setattr_iter_init(const struct lu_env *env,
const struct cl_io_slice *ios)
+
{
return 0;
}
__u64 new_size;
__u32 enqflags = 0;
- if (cl_io_is_trunc(io)) {
- new_size = io->u.ci_setattr.sa_attr.lvb_size;
- if (new_size == 0)
- enqflags = CEF_DISCARD_DATA;
- } else {
- unsigned int valid = io->u.ci_setattr.sa_valid;
+ if (cl_io_is_trunc(io)) {
+ new_size = io->u.ci_setattr.sa_attr.lvb_size;
+ if (new_size == 0)
+ enqflags = CEF_DISCARD_DATA;
+ } else {
+ unsigned int valid = io->u.ci_setattr.sa_avalid;
if (!(valid & TIMES_SET_FLAGS))
return 0;
int result;
unsigned valid = CAT_CTIME;
- cl_object_attr_lock(obj);
- attr->cat_ctime = io->u.ci_setattr.sa_attr.lvb_ctime;
- if (io->u.ci_setattr.sa_valid & ATTR_ATIME_SET) {
- attr->cat_atime = io->u.ci_setattr.sa_attr.lvb_atime;
- valid |= CAT_ATIME;
- }
- if (io->u.ci_setattr.sa_valid & ATTR_MTIME_SET) {
- attr->cat_mtime = io->u.ci_setattr.sa_attr.lvb_mtime;
- valid |= CAT_MTIME;
- }
+ cl_object_attr_lock(obj);
+ attr->cat_ctime = io->u.ci_setattr.sa_attr.lvb_ctime;
+ if (io->u.ci_setattr.sa_avalid & ATTR_ATIME_SET) {
+ attr->cat_atime = io->u.ci_setattr.sa_attr.lvb_atime;
+ valid |= CAT_ATIME;
+ }
+ if (io->u.ci_setattr.sa_avalid & ATTR_MTIME_SET) {
+ attr->cat_mtime = io->u.ci_setattr.sa_attr.lvb_mtime;
+ valid |= CAT_MTIME;
+ }
result = cl_object_attr_update(env, obj, attr, valid);
cl_object_attr_unlock(obj);
inode_lock(inode);
}
- if (io->u.ci_setattr.sa_valid & TIMES_SET_FLAGS)
+ if (io->u.ci_setattr.sa_avalid & TIMES_SET_FLAGS)
return vvp_io_setattr_time(env, ios);
return 0;
struct inode *inode = vvp_object_inode(obj);
struct ll_inode_info *lli = ll_i2info(inode);
struct file *file = vio->vui_fd->fd_file;
-
- int result;
loff_t pos = io->u.ci_rd.rd.crw_pos;
long cnt = io->u.ci_rd.rd.crw_count;
long tot = vio->vui_tot_count;
- int exceed = 0;
+ int exceed = 0;
+ int result;
+ ENTRY;
CLOBINVRNT(env, obj, vvp_object_invariant(obj));
- CDEBUG(D_VFSTRACE, "read: -> [%lli, %lli)\n", pos, pos + cnt);
+ CDEBUG(D_VFSTRACE, "%s: read [%llu, %llu)\n",
+ file_dentry(file)->d_name.name,
+ pos, pos + cnt);
if (vio->vui_io_subtype == IO_NORMAL)
down_read(&lli->lli_trunc_sem);
+ if (io->ci_async_readahead) {
+ file_accessed(file);
+ RETURN(0);
+ }
+
if (!can_populate_pages(env, io, inode))
- return 0;
+ RETURN(0);
- result = vvp_prep_size(env, obj, io, pos, tot, &exceed);
+ /* Unless this is reading a sparse file, otherwise the lock has already
+ * been acquired so vvp_prep_size() is an empty op. */
+ result = vvp_prep_size(env, obj, io, pos, cnt, &exceed);
if (result != 0)
- return result;
+ RETURN(result);
else if (exceed != 0)
- goto out;
+ GOTO(out, result);
LU_OBJECT_HEADER(D_INODE, env, &obj->co_lu,
- "Read ino %lu, %lu bytes, offset %lld, size %llu\n",
- inode->i_ino, cnt, pos, i_size_read(inode));
+ "Read ino %lu, %lu bytes, offset %lld, size %llu\n",
+ inode->i_ino, cnt, pos, i_size_read(inode));
/* turn off the kernel's read-ahead */
vio->vui_fd->fd_file->f_ra.ra_pages = 0;
if (!vio->vui_ra_valid) {
vio->vui_ra_valid = true;
vio->vui_ra_start = cl_index(obj, pos);
- vio->vui_ra_count = cl_index(obj, tot + PAGE_CACHE_SIZE - 1);
- ll_ras_enter(file);
+ vio->vui_ra_count = cl_index(obj, tot + PAGE_SIZE - 1);
}
/* BUG: 5972 */
CERROR("Wrong IO type %u\n", vio->vui_io_subtype);
LBUG();
}
+ GOTO(out, result);
out:
if (result >= 0) {
struct cl_object *obj = io->ci_obj;
struct inode *inode = vvp_object_inode(obj);
struct ll_inode_info *lli = ll_i2info(inode);
+ struct file *file = vio->vui_fd->fd_file;
ssize_t result = 0;
loff_t pos = io->u.ci_wr.wr.crw_pos;
size_t cnt = io->u.ci_wr.wr.crw_count;
+ bool lock_inode = !IS_NOSEC(inode);
ENTRY;
pos = io->u.ci_wr.wr.crw_pos = i_size_read(inode);
vio->vui_iocb->ki_pos = pos;
} else {
- LASSERT(vio->vui_iocb->ki_pos == pos);
+ LASSERTF(vio->vui_iocb->ki_pos == pos,
+ "ki_pos %lld [%lld, %lld)\n",
+ vio->vui_iocb->ki_pos,
+ pos, pos + cnt);
}
- CDEBUG(D_VFSTRACE, "write: [%lli, %lli)\n", pos, pos + (long long)cnt);
+ CDEBUG(D_VFSTRACE, "%s: write [%llu, %llu)\n",
+ file_dentry(file)->d_name.name,
+ pos, pos + cnt);
/* The maximum Lustre file size is variable, based on the OST maximum
* object size and number of stripes. This needs another check in
* addition to the VFS checks earlier. */
if (pos + cnt > ll_file_maxbytes(inode)) {
CDEBUG(D_INODE,
- "%s: file "DFID" offset %llu > maxbytes %llu\n",
- ll_get_fsname(inode->i_sb, NULL, 0),
+ "%s: file %s ("DFID") offset %llu > maxbytes %llu\n",
+ ll_i2sbi(inode)->ll_fsname,
+ file_dentry(file)->d_name.name,
PFID(ll_inode2fid(inode)), pos + cnt,
ll_file_maxbytes(inode));
RETURN(-EFBIG);
}
+ /* Tests to verify we take the i_mutex correctly */
+ if (OBD_FAIL_CHECK(OBD_FAIL_LLITE_IMUTEX_SEC) && !lock_inode)
+ RETURN(-EINVAL);
+
+ if (OBD_FAIL_CHECK(OBD_FAIL_LLITE_IMUTEX_NOSEC) && lock_inode)
+ RETURN(-EINVAL);
+
if (vio->vui_iter == NULL) {
/* from a temp io in ll_cl_init(). */
result = 0;
* consistency, proper locking to protect against writes,
* trucates, etc. is handled in the higher layers of lustre.
*/
- result = generic_file_write_iter(vio->vui_iocb, vio->vui_iter);
- if (result > 0 || result == -EIOCBQUEUED) {
+ lock_inode = !IS_NOSEC(inode);
+
+ if (unlikely(lock_inode))
+ inode_lock(inode);
+ result = __generic_file_write_iter(vio->vui_iocb,
+ vio->vui_iter);
+ if (unlikely(lock_inode))
+ inode_unlock(inode);
+
+ if (result > 0 || result == -EIOCBQUEUED)
+#ifdef HAVE_GENERIC_WRITE_SYNC_2ARGS
+ result = generic_write_sync(vio->vui_iocb, result);
+#else
+ {
ssize_t err;
- err = generic_write_sync(vio->vui_iocb->ki_filp,
- pos, result);
+ err = generic_write_sync(vio->vui_iocb->ki_filp, pos,
+ result);
if (err < 0 && result > 0)
result = err;
}
-
+#endif
}
+
if (result > 0) {
result = vvp_io_write_commit(env, io);
if (vio->u.write.vui_written > 0) {
result = vio->u.write.vui_written;
- io->ci_nob += result;
-
- CDEBUG(D_VFSTRACE, "write: nob %zd, result: %zd\n",
+ CDEBUG(D_VFSTRACE, "%s: write nob %zd, result: %zd\n",
+ file_dentry(file)->d_name.name,
io->ci_nob, result);
+ io->ci_nob += result;
}
}
if (result > 0) {
{
struct vm_fault *vmf = cfio->ft_vmf;
- cfio->ft_flags = filemap_fault(cfio->ft_vma, vmf);
+ cfio->ft_flags = ll_filemap_fault(cfio->ft_vma, vmf);
cfio->ft_flags_valid = 1;
if (vmf->page) {
LL_CDEBUG_PAGE(D_PAGE, vmf->page, "got addr %p type NOPAGE\n",
- vmf->virtual_address);
+ get_vmf_address(vmf));
if (unlikely(!(cfio->ft_flags & VM_FAULT_LOCKED))) {
lock_page(vmf->page);
cfio->ft_flags |= VM_FAULT_LOCKED;
}
if (cfio->ft_flags & VM_FAULT_SIGBUS) {
- CDEBUG(D_PAGE, "got addr %p - SIGBUS\n", vmf->virtual_address);
+ CDEBUG(D_PAGE, "got addr %p - SIGBUS\n", get_vmf_address(vmf));
return -EFAULT;
}
if (cfio->ft_flags & VM_FAULT_OOM) {
- CDEBUG(D_PAGE, "got addr %p - OOM\n", vmf->virtual_address);
+ CDEBUG(D_PAGE, "got addr %p - OOM\n", get_vmf_address(vmf));
return -ENOMEM;
}
LASSERT(PageLocked(vmpage));
if (OBD_FAIL_CHECK(OBD_FAIL_LLITE_FAULT_TRUNC_RACE))
- ll_invalidate_page(vmpage);
+ generic_error_remove_page(vmpage->mapping, vmpage);
size = i_size_read(inode);
/* Though we have already held a cl_lock upon this page, but
.cio_start = vvp_io_fsync_start,
.cio_fini = vvp_io_fini
},
+ [CIT_GLIMPSE] = {
+ .cio_fini = vvp_io_fini
+ },
[CIT_MISC] = {
.cio_fini = vvp_io_fini
},
size_t count;
struct ll_inode_info *lli = ll_i2info(inode);
- count = io->u.ci_rw.crw_count;
- /* "If nbyte is 0, read() will return 0 and have no other
- * results." -- Single Unix Spec */
- if (count == 0)
- result = 1;
+ count = io->u.ci_rw.crw_count;
+ /* "If nbyte is 0, read() will return 0 and have no other
+ * results." -- Single Unix Spec */
+ if (count == 0)
+ result = 1;
else
vio->vui_tot_count = count;
* it's not accurate if the file is shared by different
* jobs.
*/
- lustre_get_jobid(lli->lli_jobid);
+ lustre_get_jobid(lli->lli_jobid, sizeof(lli->lli_jobid));
} else if (io->ci_type == CIT_SETATTR) {
if (!cl_io_is_trunc(io))
io->ci_lockreq = CILR_MANDATORY;
result = 0;
if (result < 0)
CERROR("%s: refresh file layout " DFID " error %d.\n",
- ll_get_fsname(inode->i_sb, NULL, 0),
- PFID(lu_object_fid(&obj->co_lu)), result);
+ ll_i2sbi(inode)->ll_fsname,
+ PFID(lu_object_fid(&obj->co_lu)), result);
}
+ io->ci_result = result < 0 ? result : 0;
RETURN(result);
}