Whamcloud - gitweb
b=20529
authorjxiong <jxiong>
Thu, 24 Sep 2009 12:46:39 +0000 (12:46 +0000)
committerjxiong <jxiong>
Thu, 24 Sep 2009 12:46:39 +0000 (12:46 +0000)
r=green,wangdi

Fixed ignore lock related things.

lustre/include/cl_object.h
lustre/llite/file.c
lustre/llite/llite_internal.h
lustre/llite/llite_mmap.c
lustre/llite/vvp_io.c
lustre/obdclass/cl_object.c

index 51daf11..c7e8ed6 100644 (file)
@@ -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);
                            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.
 
 /**
  * Returns true, iff \a o0 and \a o1 are slices of the same object.
index 8a05635..12c2b0c 100644 (file)
@@ -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)
 {
 
 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;
         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) {
                 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;
 
         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",
         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);
         }
 
                 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);
 
         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_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);
         spin_unlock(&lli->lli_lock);
 
         cl_put_grouplock(&grouplock);
index 14f0f18..92a59d3 100644 (file)
@@ -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);
 
                                   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 */
 #endif /* LLITE_INTERNAL_H */
index c237fac..95e0809 100644 (file)
@@ -135,6 +135,9 @@ struct page *ll_nopage(struct vm_area_struct *vma, unsigned long address,
 
         ENTRY;
 
 
         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
         /*
          * 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 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);
 
 
                         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;
                         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,
 };
 
         .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;
 
         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)
         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 */
                 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);
         }
 
         RETURN(rc);
index 50ce909..760be79 100644 (file)
@@ -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 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;
         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) {
                 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
 
                         /*
                          * 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);
                                                     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);
 
                         if (result < 0)
                                 RETURN(result);
 
-                cont:
                         if (vma->vm_end - addr >= count)
                                 break;
                         if (vma->vm_end - addr >= count)
                                 break;
+
                         count -= vma->vm_end - addr;
                         addr = vma->vm_end;
                 }
                         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;
         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);
 
         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. */
                            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) {
         }
 
         if (cp->cpg_defer_uptodate) {
index cea73b0..7ca27c6 100644 (file)
@@ -370,6 +370,22 @@ void cl_object_prune(const struct lu_env *env, struct cl_object *obj)
 }
 EXPORT_SYMBOL(cl_object_prune);
 
 }
 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;
 void cache_stats_init(struct cache_stats *cs, const char *name)
 {
         cs->cs_name = name;