Whamcloud - gitweb
LU-11838 lustre: discard LTIME_S macro
[fs/lustre-release.git] / lustre / llite / lcommon_cl.c
index 983c74c..21a10ec 100644 (file)
  *
  * 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, 2014, Intel Corporation.
+ * Copyright (c) 2011, 2017, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
  * Lustre is a trademark of Sun Microsystems, Inc.
  *
- * cl code shared between vvp and liblustre (and other Lustre clients in the
- * future).
- *
  *   Author: Nikita Danilov <nikita.danilov@sun.com>
  */
 
 #include <obd_support.h>
 #include <lustre_fid.h>
 #include <lustre_dlm.h>
-#include <lustre_ver.h>
 #include <lustre_mdc.h>
 #include <cl_object.h>
 
 #include "llite_internal.h"
-
-static const struct cl_req_operations ccc_req_ops;
-
-/*
- * ccc_ prefix stands for "Common Client Code".
- */
-
-static struct kmem_cache *ccc_lock_kmem;
-static struct kmem_cache *ccc_object_kmem;
-static struct kmem_cache *ccc_thread_kmem;
-static struct kmem_cache *ccc_session_kmem;
-static struct kmem_cache *ccc_req_kmem;
-
-static struct lu_kmem_descr ccc_caches[] = {
-        {
-                .ckd_cache = &ccc_lock_kmem,
-                .ckd_name  = "ccc_lock_kmem",
-                .ckd_size  = sizeof (struct ccc_lock)
-        },
-        {
-                .ckd_cache = &ccc_object_kmem,
-                .ckd_name  = "ccc_object_kmem",
-                .ckd_size  = sizeof (struct ccc_object)
-        },
-        {
-                .ckd_cache = &ccc_thread_kmem,
-                .ckd_name  = "ccc_thread_kmem",
-                .ckd_size  = sizeof (struct ccc_thread_info),
-        },
-        {
-                .ckd_cache = &ccc_session_kmem,
-                .ckd_name  = "ccc_session_kmem",
-                .ckd_size  = sizeof (struct ccc_session)
-        },
-        {
-                .ckd_cache = &ccc_req_kmem,
-                .ckd_name  = "ccc_req_kmem",
-                .ckd_size  = sizeof (struct ccc_req)
-        },
-        {
-                .ckd_cache = NULL
-        }
-};
-
-/*****************************************************************************
- *
- * Vvp device and device type functions.
- *
- */
-
-void *ccc_key_init(const struct lu_context *ctx, struct lu_context_key *key)
-{
-       struct ccc_thread_info *info;
-
-       OBD_SLAB_ALLOC_PTR_GFP(info, ccc_thread_kmem, GFP_NOFS);
-       if (info == NULL)
-               info = ERR_PTR(-ENOMEM);
-       return info;
-}
-
-void ccc_key_fini(const struct lu_context *ctx,
-                         struct lu_context_key *key, void *data)
-{
-        struct ccc_thread_info *info = data;
-        OBD_SLAB_FREE_PTR(info, ccc_thread_kmem);
-}
-
-void *ccc_session_key_init(const struct lu_context *ctx,
-                          struct lu_context_key *key)
-{
-       struct ccc_session *session;
-
-       OBD_SLAB_ALLOC_PTR_GFP(session, ccc_session_kmem, GFP_NOFS);
-       if (session == NULL)
-               session = ERR_PTR(-ENOMEM);
-       return session;
-}
-
-void ccc_session_key_fini(const struct lu_context *ctx,
-                                 struct lu_context_key *key, void *data)
-{
-        struct ccc_session *session = data;
-        OBD_SLAB_FREE_PTR(session, ccc_session_kmem);
-}
-
-struct lu_context_key ccc_key = {
-        .lct_tags = LCT_CL_THREAD,
-        .lct_init = ccc_key_init,
-        .lct_fini = ccc_key_fini
-};
-
-struct lu_context_key ccc_session_key = {
-        .lct_tags = LCT_SESSION,
-        .lct_init = ccc_session_key_init,
-        .lct_fini = ccc_session_key_fini
-};
-
-int ccc_req_init(const struct lu_env *env, struct cl_device *dev,
-                struct cl_req *req)
-{
-       struct ccc_req *vrq;
-       int result;
-
-       OBD_SLAB_ALLOC_PTR_GFP(vrq, ccc_req_kmem, GFP_NOFS);
-       if (vrq != NULL) {
-               cl_req_slice_add(req, &vrq->crq_cl, dev, &ccc_req_ops);
-               result = 0;
-       } else
-               result = -ENOMEM;
-       return result;
-}
+#include "vvp_internal.h"
 
 /**
- * An `emergency' environment used by ccc_inode_fini() when cl_env_get()
- * fails. Access to this environment is serialized by ccc_inode_fini_guard
+ * An `emergency' environment used by cl_inode_fini() when cl_env_get()
+ * fails. Access to this environment is serialized by cl_inode_fini_guard
  * mutex.
  */
-static struct lu_env *ccc_inode_fini_env = NULL;
+struct lu_env *cl_inode_fini_env;
+__u16 cl_inode_fini_refcheck;
 
 /**
  * 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 int dummy_refcheck;
-
-int ccc_global_init(struct lu_device_type *device_type)
-{
-        int result;
-
-        result = lu_kmem_init(ccc_caches);
-        if (result)
-                return result;
-
-        result = lu_device_type_init(device_type);
-        if (result)
-                goto out_kmem;
-
-        ccc_inode_fini_env = cl_env_alloc(&dummy_refcheck,
-                                          LCT_REMEMBER|LCT_NOREF);
-        if (IS_ERR(ccc_inode_fini_env)) {
-                result = PTR_ERR(ccc_inode_fini_env);
-                goto out_device;
-        }
-
-        ccc_inode_fini_env->le_ctx.lc_cookie = 0x4;
-        return 0;
-out_device:
-        lu_device_type_fini(device_type);
-out_kmem:
-        lu_kmem_fini(ccc_caches);
-        return result;
-}
-
-void ccc_global_fini(struct lu_device_type *device_type)
-{
-        if (ccc_inode_fini_env != NULL) {
-                cl_env_put(ccc_inode_fini_env, &dummy_refcheck);
-                ccc_inode_fini_env = NULL;
-        }
-        lu_device_type_fini(device_type);
-        lu_kmem_fini(ccc_caches);
-}
-
-/*****************************************************************************
- *
- * Object operations.
- *
- */
-
-struct lu_object *ccc_object_alloc(const struct lu_env *env,
-                                  const struct lu_object_header *unused,
-                                  struct lu_device *dev,
-                                  const struct cl_object_operations *clops,
-                                  const struct lu_object_operations *luops)
-{
-       struct ccc_object *vob;
-       struct lu_object  *obj;
-
-       OBD_SLAB_ALLOC_PTR_GFP(vob, ccc_object_kmem, GFP_NOFS);
-       if (vob != NULL) {
-               struct cl_object_header *hdr;
-
-               obj = ccc2lu(vob);
-               hdr = &vob->cob_header;
-               cl_object_header_init(hdr);
-               hdr->coh_page_bufsize = cfs_size_round(sizeof(struct cl_page));
-
-               lu_object_init(obj, &hdr->coh_lu, dev);
-               lu_object_add_top(&hdr->coh_lu, obj);
-
-               vob->cob_cl.co_ops = clops;
-               obj->lo_ops = luops;
-       } else
-               obj = NULL;
-       return obj;
-}
-
-int ccc_object_init0(const struct lu_env *env,
-                    struct ccc_object *vob,
-                    const struct cl_object_conf *conf)
-{
-       vob->cob_inode = conf->coc_inode;
-       atomic_set(&vob->cob_transient_pages, 0);
-       cl_object_page_init(&vob->cob_cl, sizeof(struct ccc_page));
-       return 0;
-}
-
-int ccc_object_init(const struct lu_env *env, struct lu_object *obj,
-                   const struct lu_object_conf *conf)
-{
-       struct vvp_device *dev = lu2vvp_dev(obj->lo_dev);
-        struct ccc_object *vob = lu2ccc(obj);
-        struct lu_object  *below;
-        struct lu_device  *under;
-        int result;
-
-       under = &dev->vdv_next->cd_lu_dev;
-        below = under->ld_ops->ldo_object_alloc(env, obj->lo_header, under);
-        if (below != NULL) {
-                const struct cl_object_conf *cconf;
-
-                cconf = lu2cl_conf(conf);
-               INIT_LIST_HEAD(&vob->cob_pending_list);
-                lu_object_add(obj, below);
-                result = ccc_object_init0(env, vob, cconf);
-        } else
-                result = -ENOMEM;
-        return result;
-}
-
-void ccc_object_free(const struct lu_env *env, struct lu_object *obj)
-{
-        struct ccc_object *vob = lu2ccc(obj);
-
-        lu_object_fini(obj);
-        lu_object_header_fini(obj->lo_header);
-        OBD_SLAB_FREE_PTR(vob, ccc_object_kmem);
-}
-
-int ccc_lock_init(const struct lu_env *env,
-                 struct cl_object *obj, struct cl_lock *lock,
-                 const struct cl_io *unused,
-                 const struct cl_lock_operations *lkops)
-{
-       struct ccc_lock *clk;
-       int result;
-
-       CLOBINVRNT(env, obj, ccc_object_invariant(obj));
-
-       OBD_SLAB_ALLOC_PTR_GFP(clk, ccc_lock_kmem, GFP_NOFS);
-       if (clk != NULL) {
-               cl_lock_slice_add(lock, &clk->clk_cl, obj, lkops);
-               result = 0;
-       } else
-               result = -ENOMEM;
-       return result;
-}
-
-int ccc_attr_set(const struct lu_env *env, struct cl_object *obj,
-                 const struct cl_attr *attr, unsigned valid)
-{
-        return 0;
-}
-
-int ccc_object_glimpse(const struct lu_env *env,
-                      const struct cl_object *obj, struct ost_lvb *lvb)
-{
-       struct inode *inode = ccc_object_inode(obj);
-
-       ENTRY;
-       lvb->lvb_mtime = LTIME_S(inode->i_mtime);
-       lvb->lvb_atime = LTIME_S(inode->i_atime);
-       lvb->lvb_ctime = LTIME_S(inode->i_ctime);
-        /*
-         * LU-417: Add dirty pages block count lest i_blocks reports 0, some
-         * "cp" or "tar" on remote node may think it's a completely sparse file
-         * and skip it.
-         */
-        if (lvb->lvb_size > 0 && lvb->lvb_blocks == 0)
-                lvb->lvb_blocks = dirty_cnt(inode);
-        RETURN(0);
-}
-
-
-
-int ccc_conf_set(const struct lu_env *env, struct cl_object *obj,
-                        const struct cl_object_conf *conf)
-{
-        /* TODO: destroy all pages attached to this object. */
-        return 0;
-}
-
-static void ccc_object_size_lock(struct cl_object *obj)
-{
-       struct inode *inode = ccc_object_inode(obj);
-
-       ll_inode_size_lock(inode);
-       cl_object_attr_lock(obj);
-}
-
-static void ccc_object_size_unlock(struct cl_object *obj)
-{
-       struct inode *inode = ccc_object_inode(obj);
-
-       cl_object_attr_unlock(obj);
-       ll_inode_size_unlock(inode);
-}
-
-/*****************************************************************************
- *
- * Page operations.
- *
- */
-
-int ccc_fail(const struct lu_env *env, const struct cl_page_slice *slice)
-{
-        /*
-         * Cached read?
-         */
-        LBUG();
-        return 0;
-}
-
-void ccc_transient_page_verify(const struct cl_page *page)
-{
-}
-
-int ccc_transient_page_own(const struct lu_env *env,
-                                   const struct cl_page_slice *slice,
-                                   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,
-                                      const struct cl_page_slice *slice,
-                                      struct cl_io *unused)
-{
-        ccc_transient_page_verify(slice->cpl_page);
-}
-
-void ccc_transient_page_unassume(const struct lu_env *env,
-                                        const struct cl_page_slice *slice,
-                                        struct cl_io *unused)
-{
-        ccc_transient_page_verify(slice->cpl_page);
-}
-
-void ccc_transient_page_disown(const struct lu_env *env,
-                                      const struct cl_page_slice *slice,
-                                      struct cl_io *unused)
-{
-        ccc_transient_page_verify(slice->cpl_page);
-}
-
-void ccc_transient_page_discard(const struct lu_env *env,
-                                       const struct cl_page_slice *slice,
-                                       struct cl_io *unused)
-{
-        struct cl_page *page = slice->cpl_page;
-
-        ccc_transient_page_verify(slice->cpl_page);
-
-        /*
-         * For transient pages, remove it from the radix tree.
-         */
-        cl_page_delete(env, page);
-}
-
-int ccc_transient_page_prep(const struct lu_env *env,
-                                   const struct cl_page_slice *slice,
-                                   struct cl_io *unused)
-{
-        ENTRY;
-        /* transient page should always be sent. */
-        RETURN(0);
-}
-
-/*****************************************************************************
- *
- * Lock operations.
- *
- */
+static DEFINE_MUTEX(cl_inode_fini_guard);
 
-void ccc_lock_fini(const struct lu_env *env, struct cl_lock_slice *slice)
-{
-        struct ccc_lock *clk = cl2ccc_lock(slice);
-        OBD_SLAB_FREE_PTR(clk, ccc_lock_kmem);
-}
-
-int ccc_lock_enqueue(const struct lu_env *env,
-                    const struct cl_lock_slice *slice,
-                    struct cl_io *unused, struct cl_sync_io *anchor)
-{
-       CLOBINVRNT(env, slice->cls_obj, ccc_object_invariant(slice->cls_obj));
-       return 0;
-}
-
-/*****************************************************************************
- *
- * io operations.
- *
- */
-
-void ccc_io_fini(const struct lu_env *env, const struct cl_io_slice *ios)
-{
-        struct cl_io *io = ios->cis_io;
-
-        CLOBINVRNT(env, io->ci_obj, ccc_object_invariant(io->ci_obj));
-}
-
-int ccc_io_one_lock_index(const struct lu_env *env, struct cl_io *io,
-                          __u32 enqflags, enum cl_lock_mode mode,
-                          pgoff_t start, pgoff_t end)
-{
-        struct ccc_io          *cio   = ccc_env_io(env);
-        struct cl_lock_descr   *descr = &cio->cui_link.cill_descr;
-        struct cl_object       *obj   = io->ci_obj;
-
-        CLOBINVRNT(env, obj, ccc_object_invariant(obj));
-        ENTRY;
-
-        CDEBUG(D_VFSTRACE, "lock: %d [%lu, %lu]\n", mode, start, end);
-
-        memset(&cio->cui_link, 0, sizeof cio->cui_link);
-
-        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;
-
-        cl_io_lock_add(env, io, &cio->cui_link);
-        RETURN(0);
-}
-
-void ccc_io_update_iov(const struct lu_env *env,
-                       struct ccc_io *cio, struct cl_io *io)
-{
-        int i;
-        size_t size = io->u.ci_rw.crw_count;
-
-        cio->cui_iov_olen = 0;
-        if (!cl_is_normalio(env, io) || cio->cui_tot_nrsegs == 0)
-                return;
-
-        for (i = 0; i < cio->cui_tot_nrsegs; i++) {
-                struct iovec *iv = &cio->cui_iov[i];
-
-                if (iv->iov_len < size)
-                        size -= iv->iov_len;
-                else {
-                        if (iv->iov_len > size) {
-                                cio->cui_iov_olen = iv->iov_len;
-                                iv->iov_len = size;
-                        }
-                        break;
-                }
-        }
-
-        cio->cui_nrsegs = i + 1;
-       LASSERTF(cio->cui_tot_nrsegs >= cio->cui_nrsegs,
-                "tot_nrsegs: %lu, nrsegs: %lu\n",
-                cio->cui_tot_nrsegs, cio->cui_nrsegs);
-}
-
-int ccc_io_one_lock(const struct lu_env *env, struct cl_io *io,
-                    __u32 enqflags, enum cl_lock_mode mode,
-                    loff_t start, loff_t end)
-{
-        struct cl_object *obj = io->ci_obj;
-        return ccc_io_one_lock_index(env, io, enqflags, mode,
-                                     cl_index(obj, start), cl_index(obj, end));
-}
-
-void ccc_io_end(const struct lu_env *env, const struct cl_io_slice *ios)
-{
-        CLOBINVRNT(env, ios->cis_io->ci_obj,
-                   ccc_object_invariant(ios->cis_io->ci_obj));
-}
-
-void ccc_io_advance(const struct lu_env *env,
-                    const struct cl_io_slice *ios,
-                    size_t nob)
-{
-       struct ccc_io    *cio = cl2ccc_io(env, ios);
-       struct cl_io     *io  = ios->cis_io;
-       struct cl_object *obj = ios->cis_io->ci_obj;
-
-       CLOBINVRNT(env, obj, ccc_object_invariant(obj));
-
-       if (!cl_is_normalio(env, io))
-               return;
-
-       LASSERT(cio->cui_tot_nrsegs >= cio->cui_nrsegs);
-       LASSERT(cio->cui_tot_count  >= nob);
-
-       cio->cui_iov        += cio->cui_nrsegs;
-       cio->cui_tot_nrsegs -= cio->cui_nrsegs;
-       cio->cui_tot_count  -= nob;
-
-       /* update the iov */
-       if (cio->cui_iov_olen > 0) {
-               struct iovec *iv;
-
-               cio->cui_iov--;
-               cio->cui_tot_nrsegs++;
-               iv = &cio->cui_iov[0];
-               if (io->ci_continue) {
-                       iv->iov_base += iv->iov_len;
-                       LASSERT(cio->cui_iov_olen > iv->iov_len);
-                       iv->iov_len = cio->cui_iov_olen - iv->iov_len;
-               } else {
-                       /* restore the iov_len, in case of restart io. */
-                       iv->iov_len = cio->cui_iov_olen;
-               }
-               cio->cui_iov_olen = 0;
-       }
-}
-
-/**
- * Helper function that if necessary adjusts file size (inode->i_size), when
- * position at the offset \a pos is accessed. File size can be arbitrary stale
- * on a Lustre client, but client at least knows KMS. If accessed area is
- * inside [0, KMS], set file size to KMS, otherwise glimpse file size.
- *
- * Locking: cl_isize_lock is used to serialize changes to inode size and to
- * protect consistency between inode size and cl_object
- * attributes. cl_object_size_lock() protects consistency between cl_attr's of
- * top-object and sub-objects.
- */
-int ccc_prep_size(const struct lu_env *env, struct cl_object *obj,
-                  struct cl_io *io, loff_t start, size_t count, int *exceed)
-{
-        struct cl_attr *attr  = ccc_env_thread_attr(env);
-        struct inode   *inode = ccc_object_inode(obj);
-        loff_t          pos   = start + count - 1;
-        loff_t kms;
-        int result;
-
-        /*
-         * Consistency guarantees: following possibilities exist for the
-         * relation between region being accessed and real file size at this
-         * moment:
-         *
-         *  (A): the region is completely inside of the file;
-         *
-         *  (B-x): x bytes of region are inside of the file, the rest is
-         *  outside;
-         *
-         *  (C): the region is completely outside of the file.
-         *
-         * This classification is stable under DLM lock already acquired by
-         * the caller, because to change the class, other client has to take
-         * DLM lock conflicting with our lock. Also, any updates to ->i_size
-         * by other threads on this client are serialized by
-         * ll_inode_size_lock(). This guarantees that short reads are handled
-         * correctly in the face of concurrent writes and truncates.
-         */
-        ccc_object_size_lock(obj);
-        result = cl_object_attr_get(env, obj, attr);
-        if (result == 0) {
-                kms = attr->cat_kms;
-                if (pos > kms) {
-                        /*
-                         * A glimpse is necessary to determine whether we
-                         * return a short read (B) or some zeroes at the end
-                         * of the buffer (C)
-                         */
-                        ccc_object_size_unlock(obj);
-                        result = cl_glimpse_lock(env, io, inode, obj, 0);
-                        if (result == 0 && exceed != NULL) {
-                                /* If objective page index exceed end-of-file
-                                 * page index, return directly. Do not expect
-                                 * kernel will check such case correctly.
-                                 * linux-2.6.18-128.1.1 miss to do that.
-                                 * --bug 17336 */
-                               loff_t size = i_size_read(inode);
-                               unsigned long cur_index = start >>
-                                                         PAGE_CACHE_SHIFT;
-
-                               if ((size == 0 && cur_index != 0) ||
-                                   (((size - 1) >> PAGE_CACHE_SHIFT) <
-                                    cur_index))
-                               *exceed = 1;
-                        }
-                        return result;
-                } else {
-                        /*
-                         * region is within kms and, hence, within real file
-                         * size (A). We need to increase i_size to cover the
-                         * read region so that generic_file_read() will do its
-                         * job, but that doesn't mean the kms size is
-                         * _correct_, it is only the _minimum_ size. If
-                         * someone does a stat they will get the correct size
-                         * which will always be >= the kms value here.
-                         * b=11081
-                         */
-                       if (i_size_read(inode) < kms) {
-                               i_size_write(inode, kms);
-                                CDEBUG(D_VFSTRACE,
-                                       DFID" updating i_size "LPU64"\n",
-                                       PFID(lu_object_fid(&obj->co_lu)),
-                                      (__u64)i_size_read(inode));
-
-                        }
-                }
-        }
-        ccc_object_size_unlock(obj);
-        return result;
-}
-
-/*****************************************************************************
- *
- * Transfer operations.
- *
- */
-
-void ccc_req_completion(const struct lu_env *env,
-                        const struct cl_req_slice *slice, int ioret)
-{
-        struct ccc_req *vrq;
-
-        if (ioret > 0)
-                cl_stats_tally(slice->crs_dev, slice->crs_req->crq_type, ioret);
-
-        vrq = cl2ccc_req(slice);
-        OBD_SLAB_FREE_PTR(vrq, ccc_req_kmem);
-}
-
-/**
- * Implementation of struct cl_req_operations::cro_attr_set() for ccc
- * layer. ccc is responsible for
- *
- *    - o_[mac]time
- *
- *    - o_mode
- *
- *    - o_parent_seq
- *
- *    - o_[ug]id
- *
- *    - o_parent_oid
- *
- *    - o_parent_ver
- *
- *    - o_ioepoch,
- *
- *  and capability.
- */
-void ccc_req_attr_set(const struct lu_env *env,
-                      const struct cl_req_slice *slice,
-                      const struct cl_object *obj,
-                      struct cl_req_attr *attr, obd_valid flags)
-{
-        struct inode *inode;
-        struct obdo  *oa;
-        obd_flag      valid_flags;
-
-       oa = attr->cra_oa;
-       inode = ccc_object_inode(obj);
-       valid_flags = OBD_MD_FLTYPE;
-
-       if ((flags & OBD_MD_FLOSSCAPA) != 0) {
-               LASSERT(attr->cra_capa == NULL);
-               attr->cra_capa = cl_capa_lookup(inode,
-                                               slice->crs_req->crq_type);
-       }
-
-       if (slice->crs_req->crq_type == CRT_WRITE) {
-               if (flags & OBD_MD_FLEPOCH) {
-                       oa->o_valid |= OBD_MD_FLEPOCH;
-                       oa->o_ioepoch = ll_i2info(inode)->lli_ioepoch;
-                       valid_flags |= OBD_MD_FLMTIME | OBD_MD_FLCTIME |
-                                      OBD_MD_FLUID | OBD_MD_FLGID;
-               }
-       }
-       obdo_from_inode(oa, inode, valid_flags & flags);
-       obdo_set_parent_fid(oa, &ll_i2info(inode)->lli_fid);
-       if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_INVALID_PFID))
-               oa->o_parent_oid++;
-       memcpy(attr->cra_jobid, ll_i2info(inode)->lli_jobid,
-              LUSTRE_JOBID_SIZE);
-}
-
-static const struct cl_req_operations ccc_req_ops = {
-        .cro_attr_set   = ccc_req_attr_set,
-        .cro_completion = ccc_req_completion
-};
-
-int cl_setattr_ost(struct inode *inode, const struct iattr *attr,
-                   struct obd_capa *capa)
+int cl_setattr_ost(struct cl_object *obj, const struct iattr *attr,
+                  enum op_xvalid xvalid, unsigned int attr_flags)
 {
         struct lu_env *env;
         struct cl_io  *io;
         int            result;
-        int            refcheck;
+       __u16          refcheck;
 
         ENTRY;
 
@@ -771,24 +81,30 @@ int cl_setattr_ost(struct inode *inode, const struct iattr *attr,
         if (IS_ERR(env))
                 RETURN(PTR_ERR(env));
 
-        io = ccc_env_thread_io(env);
-       io->ci_obj = ll_i2info(inode)->lli_clob;
+       io = vvp_env_thread_io(env);
+       io->ci_obj = obj;
+       io->ci_verify_layout = 1;
 
-        io->u.ci_setattr.sa_attr.lvb_atime = LTIME_S(attr->ia_atime);
-        io->u.ci_setattr.sa_attr.lvb_mtime = LTIME_S(attr->ia_mtime);
-        io->u.ci_setattr.sa_attr.lvb_ctime = LTIME_S(attr->ia_ctime);
-        io->u.ci_setattr.sa_attr.lvb_size = attr->ia_size;
-        io->u.ci_setattr.sa_valid = attr->ia_valid;
-        io->u.ci_setattr.sa_capa = capa;
+       io->u.ci_setattr.sa_attr.lvb_atime = attr->ia_atime.tv_sec;
+       io->u.ci_setattr.sa_attr.lvb_mtime = attr->ia_mtime.tv_sec;
+       io->u.ci_setattr.sa_attr.lvb_ctime = attr->ia_ctime.tv_sec;
+       io->u.ci_setattr.sa_attr.lvb_size = attr->ia_size;
+       io->u.ci_setattr.sa_attr_flags = attr_flags;
+       io->u.ci_setattr.sa_avalid = attr->ia_valid;
+       io->u.ci_setattr.sa_xvalid = xvalid;
+       io->u.ci_setattr.sa_parent_fid = lu_object_fid(&obj->co_lu);
 
 again:
+       if (attr->ia_valid & ATTR_FILE)
+               ll_io_set_mirror(io, attr->ia_file);
+
         if (cl_io_init(env, io, CIT_SETATTR, io->ci_obj) == 0) {
-                struct ccc_io *cio = ccc_env_io(env);
+               struct vvp_io *vio = vvp_env_io(env);
 
-                if (attr->ia_valid & ATTR_FILE)
-                        /* populate the file descriptor for ftruncate to honor
-                         * group lock - see LU-787 */
-                       cio->cui_fd = LUSTRE_FPRIVATE(attr->ia_file);
+               if (attr->ia_valid & ATTR_FILE)
+                       /* populate the file descriptor for ftruncate to honor
+                        * group lock - see LU-787 */
+                       vio->vui_fd = LUSTRE_FPRIVATE(attr->ia_file);
 
                 result = cl_io_loop(env, io);
         } else {
@@ -797,92 +113,11 @@ again:
         cl_io_fini(env, io);
        if (unlikely(io->ci_need_restart))
                goto again;
-       /* HSM import case: file is released, cannot be restored
-        * no need to fail except if restore registration failed
-        * with -ENODATA */
-       if (result == -ENODATA && io->ci_restore_needed &&
-           io->ci_result != -ENODATA)
-               result = 0;
+
        cl_env_put(env, &refcheck);
        RETURN(result);
 }
 
-/*****************************************************************************
- *
- * Type conversions.
- *
- */
-
-struct lu_object *ccc2lu(struct ccc_object *vob)
-{
-        return &vob->cob_cl.co_lu;
-}
-
-struct ccc_object *lu2ccc(const struct lu_object *obj)
-{
-        return container_of0(obj, struct ccc_object, cob_cl.co_lu);
-}
-
-struct ccc_object *cl2ccc(const struct cl_object *obj)
-{
-        return container_of0(obj, struct ccc_object, cob_cl);
-}
-
-struct ccc_lock *cl2ccc_lock(const struct cl_lock_slice *slice)
-{
-        return container_of(slice, struct ccc_lock, clk_cl);
-}
-
-struct ccc_io *cl2ccc_io(const struct lu_env *env,
-                         const struct cl_io_slice *slice)
-{
-        struct ccc_io *cio;
-
-        cio = container_of(slice, struct ccc_io, cui_cl);
-        LASSERT(cio == ccc_env_io(env));
-        return cio;
-}
-
-struct ccc_req *cl2ccc_req(const struct cl_req_slice *slice)
-{
-        return container_of0(slice, struct ccc_req, crq_cl);
-}
-
-struct page *cl2vm_page(const struct cl_page_slice *slice)
-{
-        return cl2ccc_page(slice)->cpg_page;
-}
-
-/*****************************************************************************
- *
- * Accessors.
- *
- */
-int ccc_object_invariant(const struct cl_object *obj)
-{
-       struct inode            *inode  = ccc_object_inode(obj);
-       struct ll_inode_info    *lli    = ll_i2info(inode);
-
-       return (S_ISREG(inode->i_mode) || inode->i_mode == 0) &&
-              lli->lli_clob == obj;
-}
-
-struct inode *ccc_object_inode(const struct cl_object *obj)
-{
-        return cl2ccc(obj)->cob_inode;
-}
-
-/**
- * Returns a pointer to cl_page associated with \a vmpage, without acquiring
- * additional reference to the resulting page. This is an unsafe version of
- * cl_vmpage_page() that can only be used under vmpage lock.
- */
-struct cl_page *ccc_vmpage_page_transient(struct page *vmpage)
-{
-        KLASSERT(PageLocked(vmpage));
-        return (struct cl_page *)vmpage->private;
-}
-
 /**
  * Initialize or update CLIO structures for regular files when new
  * meta-data arrives from the server.
@@ -899,14 +134,14 @@ int cl_file_inode_init(struct inode *inode, struct lustre_md *md)
         struct cl_object     *clob;
         struct lu_site       *site;
         struct lu_fid        *fid;
-        struct cl_object_conf conf = {
-                .coc_inode = inode,
-                .u = {
-                        .coc_md    = md
-                }
-        };
+       struct cl_object_conf conf = {
+               .coc_inode = inode,
+               .u = {
+                       .coc_layout = md->layout,
+               }
+       };
         int result = 0;
-        int refcheck;
+       __u16 refcheck;
 
        LASSERT(md->body->mbo_valid & OBD_MD_FLID);
        LASSERT(S_ISREG(inode->i_mode));
@@ -917,38 +152,52 @@ int cl_file_inode_init(struct inode *inode, struct lustre_md *md)
 
        site = ll_i2sbi(inode)->ll_site;
        lli  = ll_i2info(inode);
-        fid  = &lli->lli_fid;
-        LASSERT(fid_is_sane(fid));
+       fid  = &lli->lli_fid;
+       LASSERT(fid_is_sane(fid));
+
+       if (lli->lli_clob == NULL) {
+               /* clob is slave of inode, empty lli_clob means for new inode,
+                * there is no clob in cache with the given fid, so it is
+                * unnecessary to perform lookup-alloc-lookup-insert, just
+                * alloc and insert directly.
+                */
+               if (!(inode->i_state & I_NEW)) {
+                       result = -EIO;
+                       CERROR("%s: unexpected not-NEW inode "DFID": rc = %d\n",
+                              ll_get_fsname(inode->i_sb, NULL, 0), PFID(fid),
+                              result);
+                       goto out;
+               }
 
-        if (lli->lli_clob == NULL) {
-                /* clob is slave of inode, empty lli_clob means for new inode,
-                 * there is no clob in cache with the given fid, so it is
-                 * unnecessary to perform lookup-alloc-lookup-insert, just
-                 * alloc and insert directly. */
-                LASSERT(inode->i_state & I_NEW);
-                conf.coc_lu.loc_flags = LOC_F_NEW;
-                clob = cl_object_find(env, lu2cl_dev(site->ls_top_dev),
-                                      fid, &conf);
-                if (!IS_ERR(clob)) {
-                        /*
-                         * No locking is necessary, as new inode is
-                         * locked by I_NEW bit.
-                         */
-                        lli->lli_clob = clob;
-                       lli->lli_has_smd = lsm_has_objects(md->lsm);
-                        lu_object_ref_add(&clob->co_lu, "inode", inode);
-                } else
-                        result = PTR_ERR(clob);
+               conf.coc_lu.loc_flags = LOC_F_NEW;
+               clob = cl_object_find(env, lu2cl_dev(site->ls_top_dev),
+                                     fid, &conf);
+               if (!IS_ERR(clob)) {
+                       /*
+                        * No locking is necessary, as new inode is
+                        * locked by I_NEW bit.
+                        */
+                       lli->lli_clob = clob;
+                       lu_object_ref_add(&clob->co_lu, "inode", inode);
+               } else {
+                       result = PTR_ERR(clob);
+               }
        } else {
                result = cl_conf_set(env, lli->lli_clob, &conf);
+               if (result == -EBUSY) {
+                       /* ignore the error since I/O will handle it later */
+                       result = 0;
+               }
        }
 
-        cl_env_put(env, &refcheck);
+       if (result != 0)
+               CERROR("%s: failed to initialize cl_object "DFID": rc = %d\n",
+                       ll_get_fsname(inode->i_sb, NULL, 0), PFID(fid), result);
 
-        if (result != 0)
-                CERROR("Failure to initialize cl object "DFID": %d\n",
-                       PFID(fid), result);
-        return result;
+out:
+       cl_env_put(env, &refcheck);
+
+       return result;
 }
 
 /**
@@ -963,26 +212,26 @@ int cl_file_inode_init(struct inode *inode, struct lustre_md *md)
 static void cl_object_put_last(struct lu_env *env, struct cl_object *obj)
 {
        struct lu_object_header *header = obj->co_lu.lo_header;
-       wait_queue_t           waiter;
+       wait_queue_entry_t waiter;
 
        if (unlikely(atomic_read(&header->loh_ref) != 1)) {
                struct lu_site *site = obj->co_lu.lo_dev->ld_site;
-               struct lu_site_bkt_data *bkt;
+               wait_queue_head_t *wq;
 
-               bkt = lu_site_bkt_from_fid(site, &header->loh_fid);
+               wq = lu_site_wq_from_fid(site, &header->loh_fid);
 
-               init_waitqueue_entry_current(&waiter);
-               add_wait_queue(&bkt->lsb_marche_funebre, &waiter);
+               init_waitqueue_entry(&waiter, current);
+               add_wait_queue(wq, &waiter);
 
                while (1) {
                        set_current_state(TASK_UNINTERRUPTIBLE);
                        if (atomic_read(&header->loh_ref) == 1)
                                break;
-                       waitq_wait(&waiter, TASK_UNINTERRUPTIBLE);
+                       schedule();
                }
 
                set_current_state(TASK_RUNNING);
-               remove_wait_queue(&bkt->lsb_marche_funebre, &waiter);
+               remove_wait_queue(wq, &waiter);
        }
 
        cl_object_put(env, obj);
@@ -992,22 +241,19 @@ void cl_inode_fini(struct inode *inode)
 {
        struct lu_env           *env;
        struct ll_inode_info    *lli  = ll_i2info(inode);
-        struct cl_object        *clob = lli->lli_clob;
-        int refcheck;
-        int emergency;
-
-        if (clob != NULL) {
-                void                    *cookie;
+       struct cl_object        *clob = lli->lli_clob;
+       __u16  refcheck;
+       int emergency;
+
+       if (clob != NULL) {
+               env = cl_env_get(&refcheck);
+               emergency = IS_ERR(env);
+               if (emergency) {
+                       mutex_lock(&cl_inode_fini_guard);
+                       LASSERT(cl_inode_fini_env != NULL);
+                       env = cl_inode_fini_env;
+               }
 
-                cookie = cl_env_reenter();
-                env = cl_env_get(&refcheck);
-                emergency = IS_ERR(env);
-                if (emergency) {
-                       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;
-                }
                 /*
                  * cl_object cache is a slave to inode cache (which, in turn
                  * is a slave to dentry cache), don't keep cl_object in memory
@@ -1017,78 +263,36 @@ void cl_inode_fini(struct inode *inode)
                 lu_object_ref_del(&clob->co_lu, "inode", inode);
                 cl_object_put_last(env, clob);
                 lli->lli_clob = NULL;
-                if (emergency) {
-                        cl_env_unplant(ccc_inode_fini_env, &refcheck);
-                       mutex_unlock(&ccc_inode_fini_guard);
-                } else
-                        cl_env_put(env, &refcheck);
-                cl_env_reexit(cookie);
-        }
-}
-
-/**
- * return IF_* type for given lu_dirent entry.
- * IF_* flag shld be converted to particular OS file type in
- * platform llite module.
- */
-__u16 ll_dirent_type_get(struct lu_dirent *ent)
-{
-        __u16 type = 0;
-        struct luda_type *lt;
-        int len = 0;
-
-        if (le32_to_cpu(ent->lde_attrs) & LUDA_TYPE) {
-                const unsigned align = sizeof(struct luda_type) - 1;
-
-                len = le16_to_cpu(ent->lde_namelen);
-                len = (len + align) & ~align;
-               lt = (void *)ent->lde_name + len;
-               type = IFTODT(le16_to_cpu(lt->lt_type));
+               if (emergency)
+                       mutex_unlock(&cl_inode_fini_guard);
+               else
+                       cl_env_put(env, &refcheck);
        }
-       return type;
 }
 
 /**
- * build inode number from passed @fid */
+ * build inode number from passed @fid.
+ *
+ * For 32-bit systems or syscalls limit the inode number to a 32-bit value
+ * to avoid EOVERFLOW errors.  This will inevitably result in inode number
+ * collisions, but fid_flatten32() tries hard to avoid this if possible.
+ */
 __u64 cl_fid_build_ino(const struct lu_fid *fid, int api32)
 {
-        if (BITS_PER_LONG == 32 || api32)
-                RETURN(fid_flatten32(fid));
-        else
-                RETURN(fid_flatten(fid));
+       if (BITS_PER_LONG == 32 || api32)
+               RETURN(fid_flatten32(fid));
+
+       RETURN(fid_flatten(fid));
 }
 
 /**
  * build inode generation from passed @fid.  If our FID overflows the 32-bit
- * inode number then return a non-zero generation to distinguish them. */
+ * 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);
-}
-
-/* lsm is unreliable after hsm implementation as layout can be changed at
- * any time. This is only to support old, non-clio-ized interfaces. It will
- * cause deadlock if clio operations are called with this extra layout refcount
- * because in case the layout changed during the IO, ll_layout_refresh() will
- * have to wait for the refcount to become zero to destroy the older layout.
- *
- * Notice that the lsm returned by this function may not be valid unless called
- * inside layout lock - MDS_INODELOCK_LAYOUT. */
-struct lov_stripe_md *ccc_inode_lsm_get(struct inode *inode)
-{
-       return lov_lsm_get(ll_i2info(inode)->lli_clob);
-}
+       if (fid_is_igif(fid))
+               RETURN(lu_igif_gen(fid));
 
-void inline ccc_inode_lsm_put(struct inode *inode, struct lov_stripe_md *lsm)
-{
-       lov_lsm_put(ll_i2info(inode)->lli_clob, lsm);
+       RETURN(fid_flatten(fid) >> 32);
 }