Whamcloud - gitweb
b=21551 holding ->lli_size_sem to update inode size
[fs/lustre-release.git] / lustre / lclient / lcommon_cl.c
index 2f0419c..1bb57b3 100644 (file)
@@ -300,7 +300,7 @@ static struct lu_env *ccc_inode_fini_env = NULL;
  * A mutex serializing calls to slp_inode_fini() under extreme memory
  * pressure, when environments cannot be allocated.
  */
-static DEFINE_MUTEX(ccc_inode_fini_guard);
+static CFS_DEFINE_MUTEX(ccc_inode_fini_guard);
 static int dummy_refcheck;
 
 int ccc_global_init(struct lu_device_type *device_type)
@@ -503,11 +503,13 @@ void ccc_transient_page_verify(const struct cl_page *page)
 {
 }
 
-void ccc_transient_page_own(const struct lu_env *env,
+int ccc_transient_page_own(const struct lu_env *env,
                                    const struct cl_page_slice *slice,
-                                   struct cl_io *unused)
+                                   struct cl_io *unused,
+                                   int nonblock)
 {
         ccc_transient_page_verify(slice->cpl_page);
+        return 0;
 }
 
 void ccc_transient_page_assume(const struct lu_env *env,
@@ -599,7 +601,6 @@ int ccc_lock_wait(const struct lu_env *env, const struct cl_lock_slice *slice)
  * cached lock "fits" into io.
  *
  * \param slice lock to be checked
- *
  * \param io    IO that wants a lock.
  *
  * \see lov_lock_fits_into().
@@ -624,12 +625,10 @@ int ccc_lock_fits_into(const struct lu_env *env,
          */
         if (cio->cui_glimpse)
                 result = descr->cld_mode != CLM_WRITE;
+
         /*
          * Also, don't match incomplete write locks for read, otherwise read
          * would enqueue missing sub-locks in the write mode.
-         *
-         * XXX this is a candidate for generic locking policy, to be moved
-         * into cl_lock_lookup().
          */
         else if (need->cld_mode != descr->cld_mode)
                 result = lock->cll_state >= CLS_ENQUEUED;
@@ -683,7 +682,7 @@ void ccc_lock_state(const struct lu_env *env,
                 if (rc == 0) {
                         if (lock->cll_descr.cld_start == 0 &&
                             lock->cll_descr.cld_end == CL_PAGE_EOF) {
-                                cl_isize_write(inode, attr->cat_kms);
+                                cl_isize_write_nolock(inode, attr->cat_kms);
                                 CDEBUG(D_INODE, DFID" updating i_size %llu\n",
                                        PFID(lu_object_fid(&obj->co_lu)),
                                        (__u64)cl_isize_read(inode));
@@ -691,8 +690,9 @@ void ccc_lock_state(const struct lu_env *env,
                         cl_inode_mtime(inode) = attr->cat_mtime;
                         cl_inode_atime(inode) = attr->cat_atime;
                         cl_inode_ctime(inode) = attr->cat_ctime;
-                } else
-                        CL_LOCK_DEBUG(D_ERROR, env, lock, "attr_get: %i\n", rc);
+                } else {
+                        CL_LOCK_DEBUG(D_INFO, env, lock, "attr_get: %i\n", rc);
+                }
                 cl_object_attr_unlock(obj);
                 cl_isize_unlock(inode, 0);
         }
@@ -726,12 +726,18 @@ int ccc_io_one_lock_index(const struct lu_env *env, struct cl_io *io,
         CDEBUG(D_VFSTRACE, "lock: %i [%lu, %lu]\n", mode, start, end);
 
         memset(&cio->cui_link, 0, sizeof cio->cui_link);
-        descr->cld_mode  = mode;
+
+        if (cio->cui_fd && (cio->cui_fd->fd_flags & LL_FILE_GROUP_LOCKED)) {
+                descr->cld_mode = CLM_GROUP;
+                descr->cld_gid  = cio->cui_fd->fd_grouplock.cg_gid;
+        } else {
+                descr->cld_mode  = mode;
+        }
         descr->cld_obj   = obj;
         descr->cld_start = start;
         descr->cld_end   = end;
+        descr->cld_enq_flags = enqflags;
 
-        cio->cui_link.cill_enq_flags = enqflags;
         cl_io_lock_add(env, io, &cio->cui_link);
         RETURN(0);
 }
@@ -743,7 +749,7 @@ void ccc_io_update_iov(const struct lu_env *env,
         size_t size = io->u.ci_rw.crw_count;
 
         cio->cui_iov_olen = 0;
-        if (cl_io_is_sendfile(io) || size == cio->cui_tot_count)
+        if (!cl_is_normalio(env, io) || size == cio->cui_tot_count)
                 return;
 
         if (cio->cui_tot_nrsegs == 0)
@@ -791,7 +797,7 @@ void ccc_io_advance(const struct lu_env *env,
 
         CLOBINVRNT(env, obj, ccc_object_invariant(obj));
 
-        if (!cl_io_is_sendfile(io) && io->ci_continue) {
+        if (cl_is_normalio(env, io) && io->ci_continue) {
                 /* update the iov */
                 LASSERT(cio->cui_tot_nrsegs >= cio->cui_nrsegs);
                 LASSERT(cio->cui_tot_count  >= nob);
@@ -926,9 +932,9 @@ int ccc_prep_size(const struct lu_env *env, struct cl_object *obj,
                          */
                         if (cl_isize_read(inode) < kms) {
                                 if (vfslock)
-                                        cl_isize_write(inode, kms);
-                                else
                                         cl_isize_write_nolock(inode, kms);
+                                else
+                                        cl_isize_write(inode, kms);
                         }
                 }
         }
@@ -965,7 +971,7 @@ void ccc_req_completion(const struct lu_env *env,
  *
  *    - o_generation
  *
- *    - and IO epoch (stored in o_easize),
+ *    - o_ioepoch,
  *
  *  and capability.
  */
@@ -993,7 +999,7 @@ void ccc_req_attr_set(const struct lu_env *env,
         if (slice->crs_req->crq_type == CRT_WRITE) {
                 if (flags & OBD_MD_FLEPOCH) {
                         oa->o_valid |= OBD_MD_FLEPOCH;
-                        oa->o_easize = cl_i2info(inode)->lli_ioepoch;
+                        oa->o_ioepoch = cl_i2info(inode)->lli_ioepoch;
                         valid_flags |= OBD_MD_FLMTIME|OBD_MD_FLCTIME|
                                 OBD_MD_FLUID|OBD_MD_FLGID|
                                 OBD_MD_FLFID|OBD_MD_FLGENER;
@@ -1059,6 +1065,7 @@ int cl_setattr_ost(struct inode *inode, struct obd_capa *capa)
 
                 oinfo.oi_oa = oa;
                 oinfo.oi_md = lsm;
+                oinfo.oi_capa = capa;
 
                 /* XXX: this looks unnecessary now. */
                 rc = obd_setattr_rqset(cl_i2sbi(inode)->ll_dt_exp, &oinfo,
@@ -1242,7 +1249,7 @@ void cl_inode_fini(struct inode *inode)
                 env = cl_env_get(&refcheck);
                 emergency = IS_ERR(env);
                 if (emergency) {
-                        mutex_lock(&ccc_inode_fini_guard);
+                        cfs_mutex_lock(&ccc_inode_fini_guard);
                         LASSERT(ccc_inode_fini_env != NULL);
                         cl_env_implant(ccc_inode_fini_env, &refcheck);
                         env = ccc_inode_fini_env;
@@ -1258,7 +1265,7 @@ void cl_inode_fini(struct inode *inode)
                 lli->lli_clob = NULL;
                 if (emergency) {
                         cl_env_unplant(ccc_inode_fini_env, &refcheck);
-                        mutex_unlock(&ccc_inode_fini_guard);
+                        cfs_mutex_unlock(&ccc_inode_fini_guard);
                 } else
                         cl_env_put(env, &refcheck);
                 cl_env_reexit(cookie);
@@ -1286,3 +1293,43 @@ __u16 ll_dirent_type_get(struct lu_dirent *ent)
         }
         return type;
 }
+
+/**
+ * build inode number from passed @fid */
+ino_t cl_fid_build_ino(const struct lu_fid *fid)
+{
+        ino_t ino;
+        ENTRY;
+
+        if (fid_is_igif(fid)) {
+                ino = lu_igif_ino(fid);
+                RETURN(ino);
+        }
+
+        /* Very stupid and having many downsides inode allocation algorithm
+         * based on fid. */
+        ino = fid_flatten(fid) & 0xFFFFFFFF;
+
+        if (unlikely(ino == 0))
+                /* the first result ino is 0xFFC001, so this is rarely used */
+                ino = 0xffbcde;
+        ino = ino | 0x80000000;
+        RETURN(ino);
+}
+
+/**
+ * build inode generation from passed @fid.  If our FID overflows the 32-bit
+ * inode number then return a non-zero generation to distinguish them. */
+__u32 cl_fid_build_gen(const struct lu_fid *fid)
+{
+        __u32 gen;
+        ENTRY;
+
+        if (fid_is_igif(fid)) {
+                gen = lu_igif_gen(fid);
+                RETURN(gen);
+        }
+
+        gen = (fid_flatten(fid) >> 32);
+        RETURN(gen);
+}