Whamcloud - gitweb
LU-6512 llite:ll_dir_ioctl cleanup of redundant comparisons
[fs/lustre-release.git] / lustre / llite / lcommon_cl.c
index d4c4daf..673bfbd 100644 (file)
  * 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, 2015, 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 <cl_object.h>
 
 #include "llite_internal.h"
-
-/*
- * ccc_ prefix stands for "Common Client Code".
- */
-
-static struct kmem_cache *ccc_thread_kmem;
-
-static struct lu_kmem_descr ccc_caches[] = {
-        {
-                .ckd_cache = &ccc_thread_kmem,
-                .ckd_name  = "ccc_thread_kmem",
-                .ckd_size  = sizeof (struct ccc_thread_info),
-        },
-        {
-                .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);
-}
-
-struct lu_context_key ccc_key = {
-        .lct_tags = LCT_CL_THREAD,
-        .lct_init = ccc_key_init,
-        .lct_fini = ccc_key_fini
-};
+#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;
-}
+static DEFINE_MUTEX(cl_inode_fini_guard);
 
-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);
-}
-
-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,
+                  unsigned int attr_flags)
 {
         struct lu_env *env;
         struct cl_io  *io;
         int            result;
-        int            refcheck;
+       __u16          refcheck;
 
         ENTRY;
 
@@ -172,16 +86,17 @@ 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_attr_flags = attr_flags;
        io->u.ci_setattr.sa_valid = attr->ia_valid;
-       io->u.ci_setattr.sa_parent_fid = ll_inode2fid(inode);
-       io->u.ci_setattr.sa_capa = capa;
+       io->u.ci_setattr.sa_parent_fid = lu_object_fid(&obj->co_lu);
 
 again:
         if (cl_io_init(env, io, CIT_SETATTR, io->ci_obj) == 0) {
@@ -199,12 +114,7 @@ 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);
 }
@@ -225,14 +135,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));
@@ -261,7 +171,6 @@ int cl_file_inode_init(struct inode *inode, struct lustre_md *md)
                          * 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);
@@ -297,14 +206,14 @@ static void cl_object_put_last(struct lu_env *env, struct cl_object *obj)
 
                bkt = lu_site_bkt_from_fid(site, &header->loh_fid);
 
-               init_waitqueue_entry_current(&waiter);
+               init_waitqueue_entry(&waiter, current);
                add_wait_queue(&bkt->lsb_marche_funebre, &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);
@@ -319,7 +228,7 @@ 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;
+       __u16  refcheck;
         int emergency;
 
         if (clob != NULL) {
@@ -328,12 +237,13 @@ void cl_inode_fini(struct inode *inode)
                 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;
-                }
+               if (emergency) {
+                       mutex_lock(&cl_inode_fini_guard);
+                       LASSERT(cl_inode_fini_env != NULL);
+                       cl_env_implant(cl_inode_fini_env, &refcheck);
+                       env = cl_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
@@ -343,38 +253,18 @@ 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);
+               if (emergency) {
+                       cl_env_unplant(cl_inode_fini_env, &refcheck);
+                       mutex_unlock(&cl_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));
-       }
-       return type;
-}
-
-/**
  * build inode number from passed @fid */
 __u64 cl_fid_build_ino(const struct lu_fid *fid, int api32)
 {
@@ -400,21 +290,3 @@ __u32 cl_fid_build_gen(const struct lu_fid *fid)
         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);
-}
-
-void inline ccc_inode_lsm_put(struct inode *inode, struct lov_stripe_md *lsm)
-{
-       lov_lsm_put(ll_i2info(inode)->lli_clob, lsm);
-}