From 05a8aa6216160b7c00d2b9cdfda89f35c5489901 Mon Sep 17 00:00:00 2001 From: jxiong Date: Thu, 24 Sep 2009 12:46:39 +0000 Subject: [PATCH] b=20529 r=green,wangdi Fixed ignore lock related things. --- lustre/include/cl_object.h | 1 + lustre/llite/file.c | 15 +++++++-------- lustre/llite/llite_internal.h | 9 +++++++++ lustre/llite/llite_mmap.c | 25 ++++++++++++------------- lustre/llite/vvp_io.c | 42 +++++++++++++++++++----------------------- lustre/obdclass/cl_object.c | 16 ++++++++++++++++ 6 files changed, 64 insertions(+), 44 deletions(-) diff --git a/lustre/include/cl_object.h b/lustre/include/cl_object.h index 51daf11..c7e8ed6 100644 --- a/lustre/include/cl_object.h +++ b/lustre/include/cl_object.h @@ -2628,6 +2628,7 @@ int cl_conf_set (const struct lu_env *env, struct cl_object *obj, const struct cl_object_conf *conf); void cl_object_prune (const struct lu_env *env, struct cl_object *obj); void cl_object_kill (const struct lu_env *env, struct cl_object *obj); +int cl_object_has_locks (struct cl_object *obj); /** * Returns true, iff \a o0 and \a o1 are slices of the same object. diff --git a/lustre/llite/file.c b/lustre/llite/file.c index 8a05635..12c2b0c 100644 --- a/lustre/llite/file.c +++ b/lustre/llite/file.c @@ -776,19 +776,15 @@ int ll_glimpse_ioctl(struct ll_sb_info *sbi, struct lov_stripe_md *lsm, void ll_io_init(struct cl_io *io, const struct file *file, int write) { - struct inode *inode = file->f_dentry->d_inode; - struct ll_sb_info *sbi = ll_i2sbi(inode); - struct ll_file_data *fd = LUSTRE_FPRIVATE(file); + struct inode *inode = file->f_dentry->d_inode; - LASSERT(fd != NULL); memset(io, 0, sizeof *io); io->u.ci_rw.crw_nonblock = file->f_flags & O_NONBLOCK; if (write) io->u.ci_wr.wr_append = file->f_flags & O_APPEND; io->ci_obj = ll_i2info(inode)->lli_clob; io->ci_lockreq = CILR_MAYBE; - if (fd->fd_flags & LL_FILE_IGNORE_LOCK || - sbi->ll_flags & LL_SBI_NOLCK) { + if (ll_file_nolock(file)) { io->ci_lockreq = CILR_NEVER; io->ci_no_srvlock = 1; } else if (file->f_flags & O_APPEND) { @@ -1413,6 +1409,9 @@ int ll_get_grouplock(struct inode *inode, struct file *file, unsigned long arg) int rc; ENTRY; + if (ll_file_nolock(file)) + RETURN(-EOPNOTSUPP); + spin_lock(&lli->lli_lock); if (fd->fd_flags & LL_FILE_GROUP_LOCKED) { CERROR("group lock already existed with gid %lu\n", @@ -1436,7 +1435,7 @@ int ll_get_grouplock(struct inode *inode, struct file *file, unsigned long arg) RETURN(-EINVAL); } - fd->fd_flags |= (LL_FILE_GROUP_LOCKED | LL_FILE_IGNORE_LOCK); + fd->fd_flags |= LL_FILE_GROUP_LOCKED; fd->fd_grouplock = grouplock; spin_unlock(&lli->lli_lock); @@ -1470,7 +1469,7 @@ int ll_put_grouplock(struct inode *inode, struct file *file, unsigned long arg) fd->fd_grouplock.cg_env = NULL; fd->fd_grouplock.cg_lock = NULL; fd->fd_grouplock.cg_gid = 0; - fd->fd_flags &= ~(LL_FILE_GROUP_LOCKED | LL_FILE_IGNORE_LOCK); + fd->fd_flags &= ~LL_FILE_GROUP_LOCKED; spin_unlock(&lli->lli_lock); cl_put_grouplock(&grouplock); diff --git a/lustre/llite/llite_internal.h b/lustre/llite/llite_internal.h index 14f0f18..92a59d3 100644 --- a/lustre/llite/llite_internal.h +++ b/lustre/llite/llite_internal.h @@ -1230,4 +1230,13 @@ extern ssize_t ll_direct_rw_pages(const struct lu_env *env, struct cl_io *io, int rw, struct inode *inode, struct ll_dio_pages *pv); +static inline int ll_file_nolock(const struct file *file) +{ + struct ll_file_data *fd = LUSTRE_FPRIVATE(file); + struct inode *inode = file->f_dentry->d_inode; + + LASSERT(fd != NULL); + return ((fd->fd_flags & LL_FILE_IGNORE_LOCK) || + (ll_i2sbi(inode)->ll_flags & LL_SBI_NOLCK)); +} #endif /* LLITE_INTERNAL_H */ diff --git a/lustre/llite/llite_mmap.c b/lustre/llite/llite_mmap.c index c237fac..95e0809 100644 --- a/lustre/llite/llite_mmap.c +++ b/lustre/llite/llite_mmap.c @@ -135,6 +135,9 @@ struct page *ll_nopage(struct vm_area_struct *vma, unsigned long address, ENTRY; + if (ll_file_nolock(file)) + RETURN(ERR_PTR(-EOPNOTSUPP)); + /* * vm_operations_struct::nopage() can be called when lustre IO is * already active for the current thread, e.g., when doing read/write @@ -176,19 +179,11 @@ struct page *ll_nopage(struct vm_area_struct *vma, unsigned long address, struct vvp_io *vio = vvp_env_io(env); struct ccc_io *cio = ccc_env_io(env); struct ll_file_data *fd = LUSTRE_FPRIVATE(file); - struct ll_sb_info *sbi = ll_i2sbi(inode); LASSERT(cio->cui_cl.cis_io == io); - /* mmap lock should be MANDATORY or NEVER. */ - if (fd->fd_flags & LL_FILE_IGNORE_LOCK || - sbi->ll_flags & LL_SBI_NOLCK) { - io->ci_lockreq = CILR_NEVER; - io->ci_no_srvlock = 1; - } else { - io->ci_lockreq = CILR_MANDATORY; - } - + /* mmap lock must be MANDATORY. */ + io->ci_lockreq = CILR_MANDATORY; vio->u.fault.ft_vma = vma; vio->u.fault.ft_address = address; vio->u.fault.ft_type = type; @@ -292,12 +287,16 @@ static struct vm_operations_struct ll_file_vm_ops = { .populate = ll_populate, }; -int ll_file_mmap(struct file * file, struct vm_area_struct * vma) +int ll_file_mmap(struct file *file, struct vm_area_struct * vma) { + struct inode *inode = file->f_dentry->d_inode; int rc; ENTRY; - ll_stats_ops_tally(ll_i2sbi(file->f_dentry->d_inode), LPROC_LL_MAP, 1); + if (ll_file_nolock(file)) + RETURN(-EOPNOTSUPP); + + ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_MAP, 1); rc = generic_file_mmap(file, vma); if (rc == 0) { #if !defined(HAVE_FILEMAP_POPULATE) @@ -307,7 +306,7 @@ int ll_file_mmap(struct file * file, struct vm_area_struct * vma) vma->vm_ops = &ll_file_vm_ops; vma->vm_ops->open(vma); /* update the inode's size and mtime */ - rc = cl_glimpse_size(file->f_dentry->d_inode); + rc = cl_glimpse_size(inode); } RETURN(rc); diff --git a/lustre/llite/vvp_io.c b/lustre/llite/vvp_io.c index 50ce909..760be79 100644 --- a/lustre/llite/vvp_io.c +++ b/lustre/llite/vvp_io.c @@ -123,7 +123,6 @@ static int vvp_mmap_locks(const struct lu_env *env, struct vm_area_struct *vma; struct cl_lock_descr *descr = &cti->cti_descr; ldlm_policy_data_t policy; - struct inode *inode; unsigned long addr; unsigned long seg; ssize_t count; @@ -146,16 +145,16 @@ static int vvp_mmap_locks(const struct lu_env *env, count += addr & (~CFS_PAGE_MASK); addr &= CFS_PAGE_MASK; while((vma = our_vma(addr, count)) != NULL) { - struct file *file = vma->vm_file; - struct ll_file_data *fd; + struct inode *inode = vma->vm_file->f_dentry->d_inode; + int flags = CEF_MUST; - LASSERT(file); - fd = LUSTRE_FPRIVATE(file); - - inode = file->f_dentry->d_inode; - if (!(fd->fd_flags & LL_FILE_IGNORE_LOCK || - ll_i2sbi(inode)->ll_flags & LL_SBI_NOLCK)) - goto cont; + if (ll_file_nolock(vma->vm_file)) { + /* + * For no lock case, a lockless lock will be + * generated. + */ + flags = CEF_NEVER; + } /* * XXX: Required lock mode can be weakened: CIT_WRITE @@ -169,13 +168,13 @@ static int vvp_mmap_locks(const struct lu_env *env, policy.l_extent.start); descr->cld_end = cl_index(descr->cld_obj, policy.l_extent.end); - result = cl_io_lock_alloc_add(env, io, descr, CEF_MUST); + result = cl_io_lock_alloc_add(env, io, descr, flags); if (result < 0) RETURN(result); - cont: if (vma->vm_end - addr >= count) break; + count -= vma->vm_end - addr; addr = vma->vm_end; } @@ -615,6 +614,7 @@ static int vvp_io_read_page(const struct lu_env *env, struct ll_readahead_state *ras = &fd->fd_ras; cfs_page_t *vmpage = cp->cpg_page; struct cl_2queue *queue = &io->ci_queue; + int rc; CLOBINVRNT(env, obj, ccc_object_invariant(obj)); LASSERT(cl2vvp_io(env, ios)->cui_oneshot == 0); @@ -627,17 +627,13 @@ static int vvp_io_read_page(const struct lu_env *env, cp->cpg_defer_uptodate); /* Sanity check whether the page is protected by a lock. */ - if (likely(!(fd->fd_flags & LL_FILE_IGNORE_LOCK))) { - int rc; - - rc = cl_page_is_under_lock(env, io, page); - if (rc != -EBUSY) { - CL_PAGE_HEADER(D_WARNING, env, page, "%s: %i\n", - rc == -ENODATA ? "without a lock" : - "match failed", rc); - if (rc != -ENODATA) - RETURN(rc); - } + rc = cl_page_is_under_lock(env, io, page); + if (rc != -EBUSY) { + CL_PAGE_HEADER(D_WARNING, env, page, "%s: %i\n", + rc == -ENODATA ? "without a lock" : + "match failed", rc); + if (rc != -ENODATA) + RETURN(rc); } if (cp->cpg_defer_uptodate) { diff --git a/lustre/obdclass/cl_object.c b/lustre/obdclass/cl_object.c index cea73b0..7ca27c6 100644 --- a/lustre/obdclass/cl_object.c +++ b/lustre/obdclass/cl_object.c @@ -370,6 +370,22 @@ void cl_object_prune(const struct lu_env *env, struct cl_object *obj) } EXPORT_SYMBOL(cl_object_prune); +/** + * Check if the object has locks. + */ +int cl_object_has_locks(struct cl_object *obj) +{ + struct cl_object_header *head = cl_object_header(obj); + int has; + + spin_lock(&head->coh_lock_guard); + has = list_empty(&head->coh_locks); + spin_unlock(&head->coh_lock_guard); + + return (has == 0); +} +EXPORT_SYMBOL(cl_object_has_locks); + void cache_stats_init(struct cache_stats *cs, const char *name) { cs->cs_name = name; -- 1.8.3.1