Whamcloud - gitweb
LU-13799 llite: Adjust dio refcounting
[fs/lustre-release.git] / lustre / obdecho / echo_client.c
index 7609490..4042fe5 100644 (file)
@@ -27,7 +27,6 @@
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
  */
 
 #define DEBUG_SUBSYSTEM S_ECHO
@@ -39,7 +38,6 @@
 #include <obd.h>
 #include <obd_support.h>
 #include <obd_class.h>
-#include <lustre_debug.h>
 #include <lprocfs_status.h>
 #include <cl_object.h>
 #include <lustre_fid.h>
@@ -126,16 +124,16 @@ struct echo_md_device {
 #endif /* HAVE_SERVER_SUPPORT */
 
 static int echo_client_setup(const struct lu_env *env,
-                            struct obd_device *obddev,
+                            struct obd_device *obd,
                             struct lustre_cfg *lcfg);
-static int echo_client_cleanup(struct obd_device *obddev);
+static int echo_client_cleanup(struct obd_device *obd);
 
 /** \defgroup echo_helpers Helper functions
  * @{
  */
 static inline struct echo_device *cl2echo_dev(const struct cl_device *dev)
 {
-       return container_of0(dev, struct echo_device, ed_cl);
+       return container_of_safe(dev, struct echo_device, ed_cl);
 }
 
 static inline struct cl_device *echo_dev2cl(struct echo_device *d)
@@ -193,7 +191,8 @@ struct echo_object_conf *cl2echo_conf(const struct cl_object_conf *c)
 #ifdef HAVE_SERVER_SUPPORT
 static inline struct echo_md_device *lu2emd_dev(struct lu_device *d)
 {
-       return container_of0(d, struct echo_md_device, emd_md_dev.md_lu_dev);
+       return container_of_safe(d, struct echo_md_device,
+                                emd_md_dev.md_lu_dev);
 }
 
 static inline struct lu_device *emd2lu_dev(struct echo_md_device *d)
@@ -400,8 +399,8 @@ static void echo_lock_fini(const struct lu_env *env,
        OBD_SLAB_FREE_PTR(ecl, echo_lock_kmem);
 }
 
-static struct cl_lock_operations echo_lock_ops = {
-       .clo_fini      = echo_lock_fini,
+static const struct cl_lock_operations echo_lock_ops = {
+       .clo_fini       = echo_lock_fini,
 };
 
 /** @} echo_lock */
@@ -427,7 +426,7 @@ static int echo_page_init(const struct lu_env *env, struct cl_object *obj,
         * wait_on_bit() interface to wait for the bit to be clear.
         */
        ep->ep_lock = 0;
-       cl_page_slice_add(page, &ep->ep_cl, obj, index, &echo_page_ops);
+       cl_page_slice_add(page, &ep->ep_cl, obj, &echo_page_ops);
        atomic_inc(&eco->eo_npages);
        RETURN(0);
 }
@@ -545,6 +544,14 @@ static void echo_object_delete(const struct lu_env *env, struct lu_object *obj)
                OBD_FREE_PTR(eco->eo_oinfo);
 }
 
+static void echo_object_free_rcu(struct rcu_head *head)
+{
+       struct echo_object *eco = container_of(head, struct echo_object,
+                                              eo_hdr.coh_lu.loh_rcu);
+
+       kmem_cache_free(echo_object_kmem, eco);
+}
+
 static void echo_object_free(const struct lu_env *env, struct lu_object *obj)
 {
        struct echo_object *eco    = cl2echo_obj(lu2cl(obj));
@@ -554,7 +561,8 @@ static void echo_object_free(const struct lu_env *env, struct lu_object *obj)
        lu_object_fini(obj);
        lu_object_header_fini(obj->lo_header);
 
-       OBD_SLAB_FREE_PTR(eco, echo_object_kmem);
+       OBD_FREE_PRE(eco, sizeof(*eco), "slab-freed");
+       call_rcu(&eco->eo_hdr.coh_lu.loh_rcu, echo_object_free_rcu);
        EXIT;
 }
 
@@ -609,7 +617,7 @@ static struct lu_object *echo_object_alloc(const struct lu_env *env,
        RETURN(obj);
 }
 
-static struct lu_device_operations echo_device_lu_ops = {
+static const struct lu_device_operations echo_device_lu_ops = {
        .ldo_object_alloc   = echo_object_alloc,
 };
 
@@ -724,13 +732,11 @@ static int echo_fid_init(struct echo_device *ed, char *obd_name,
        snprintf(prefix, MAX_OBD_NAME + 5, "srv-%s", obd_name);
 
        /* Init client side sequence-manager */
-       rc = seq_client_init(ed->ed_cl_seq, NULL,
-                            LUSTRE_SEQ_METADATA,
-                            prefix, ss->ss_server_seq);
+       seq_client_init(ed->ed_cl_seq, NULL,
+                       LUSTRE_SEQ_METADATA,
+                       prefix, ss->ss_server_seq);
        ed->ed_cl_seq->lcs_width = ECHO_SEQ_WIDTH;
        OBD_FREE(prefix, MAX_OBD_NAME + 5);
-       if (rc)
-               GOTO(out_free_seq, rc);
 
        RETURN(0);
 
@@ -740,9 +746,9 @@ out_free_seq:
        RETURN(rc);
 }
 
-static int echo_fid_fini(struct obd_device *obddev)
+static int echo_fid_fini(struct obd_device *obd)
 {
-       struct echo_device *ed = obd2echo_dev(obddev);
+       struct echo_device *ed = obd2echo_dev(obd);
 
        ENTRY;
        if (ed->ed_cl_seq) {
@@ -1079,8 +1085,7 @@ static struct lu_device *echo_device_free(const struct lu_env *env,
                spin_unlock(&ec->ec_lock);
                CERROR(
                       "echo_client still has objects at cleanup time, wait for 1 second\n");
-               set_current_state(TASK_UNINTERRUPTIBLE);
-               schedule_timeout(cfs_time_seconds(1));
+               schedule_timeout_uninterruptible(cfs_time_seconds(1));
                lu_site_purge(env, ed->ed_site, -1);
                spin_lock(&ec->ec_lock);
        }
@@ -1323,7 +1328,7 @@ static void echo_commit_callback(const struct lu_env *env, struct cl_io *io,
                struct page *vmpage = pvec->pages[i];
                struct cl_page *page = (struct cl_page *)vmpage->private;
 
-               cl_page_list_add(&queue->c2_qout, page);
+               cl_page_list_add(&queue->c2_qout, page, true);
        }
 }
 
@@ -1386,7 +1391,7 @@ static int cl_echo_object_brw(struct echo_object *eco, int rw, u64 offset,
                        break;
                }
 
-               cl_2queue_add(queue, clp);
+               cl_2queue_add(queue, clp, true);
 
                /*
                 * drop the reference count for cl_page_find, so that the page
@@ -1685,7 +1690,7 @@ echo_md_dir_stripe_choose(const struct lu_env *env, struct echo_device *ed,
        }
 
        lmv = (struct lmv_mds_md_v1 *)ma->ma_lmm;
-       if (le32_to_cpu(lmv->lmv_magic) != LMV_MAGIC_V1) {
+       if (!lmv_is_sane(lmv)) {
                rc = -EINVAL;
                CERROR("Invalid mds md magic %x "DFID": rc = %d\n",
                       le32_to_cpu(lmv->lmv_magic), PFID(lu_object_fid(obj)),
@@ -1701,9 +1706,8 @@ echo_md_dir_stripe_choose(const struct lu_env *env, struct echo_device *ed,
                echo_md_build_name(&tmp_ln_name, info->eti_name, id);
        }
 
-       idx = lmv_name_to_stripe_index(LMV_HASH_TYPE_FNV_1A_64,
-                               le32_to_cpu(lmv->lmv_stripe_count),
-                               tmp_ln_name.ln_name, tmp_ln_name.ln_namelen);
+       idx = lmv_name_to_stripe_index(lmv, tmp_ln_name.ln_name,
+                                      tmp_ln_name.ln_namelen);
 
        LASSERT(idx < le32_to_cpu(lmv->lmv_stripe_count));
        fid_le_to_cpu(&stripe_fid, &lmv->lmv_stripe_fids[idx]);
@@ -2241,6 +2245,7 @@ static struct lu_object *echo_resolve_path(const struct lu_env *env,
 static void echo_ucred_init(struct lu_env *env)
 {
        struct lu_ucred *ucred = lu_ucred(env);
+       kernel_cap_t kcap = current_cap();
 
        ucred->uc_valid = UCRED_INVALID;
 
@@ -2258,8 +2263,11 @@ static void echo_ucred_init(struct lu_env *env)
        ucred->uc_cap = cfs_curproc_cap_pack();
 
        /* remove fs privilege for non-root user. */
-       if (ucred->uc_fsuid)
-               ucred->uc_cap &= ~CFS_CAP_FS_MASK;
+       if (ucred->uc_fsuid) {
+               kcap = cap_drop_nfsd_set(kcap);
+               kcap = cap_drop_fs_set(kcap);
+       }
+       ucred->uc_cap = kcap.cap[0];
        ucred->uc_valid = UCRED_NEW;
 }
 
@@ -2567,13 +2575,13 @@ static int echo_client_kbrw(struct echo_device *ed, int rw, struct obdo *oa,
        if (rw == OBD_BRW_WRITE)
                brw_flags = OBD_BRW_ASYNC;
 
-       OBD_ALLOC(pga, npages * sizeof(*pga));
+       OBD_ALLOC_PTR_ARRAY_LARGE(pga, npages);
        if (!pga)
                RETURN(-ENOMEM);
 
-       OBD_ALLOC(pages, npages * sizeof(*pages));
+       OBD_ALLOC_PTR_ARRAY_LARGE(pages, npages);
        if (!pages) {
-               OBD_FREE(pga, npages * sizeof(*pga));
+               OBD_FREE_PTR_ARRAY_LARGE(pga, npages);
                RETURN(-ENOMEM);
        }
 
@@ -2588,6 +2596,8 @@ static int echo_client_kbrw(struct echo_device *ed, int rw, struct obdo *oa,
                if (!pgp->pg)
                        goto out;
 
+               /* set mapping so page is not considered encrypted */
+               pgp->pg->mapping = ECHO_MAPPING_UNENCRYPTED;
                pages[i] = pgp->pg;
                pgp->count = PAGE_SIZE;
                pgp->off = off;
@@ -2623,8 +2633,8 @@ static int echo_client_kbrw(struct echo_device *ed, int rw, struct obdo *oa,
                }
                __free_page(pgp->pg);
        }
-       OBD_FREE(pga, npages * sizeof(*pga));
-       OBD_FREE(pages, npages * sizeof(*pages));
+       OBD_FREE_PTR_ARRAY_LARGE(pga, npages);
+       OBD_FREE_PTR_ARRAY_LARGE(pages, npages);
        RETURN(rc);
 }
 
@@ -2648,7 +2658,7 @@ static int echo_client_prep_commit(const struct lu_env *env,
        apc = npages = batch >> PAGE_SHIFT;
        tot_pages = count >> PAGE_SHIFT;
 
-       OBD_ALLOC_LARGE(lnb, apc * sizeof(*lnb));
+       OBD_ALLOC_PTR_ARRAY_LARGE(lnb, apc);
        if (!lnb)
                RETURN(-ENOMEM);
 
@@ -2714,7 +2724,7 @@ static int echo_client_prep_commit(const struct lu_env *env,
        }
 
 out:
-       OBD_FREE_LARGE(lnb, apc * sizeof(*lnb));
+       OBD_FREE_PTR_ARRAY_LARGE(lnb, apc);
 
        RETURN(ret);
 }
@@ -2834,7 +2844,7 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
 
        switch (cmd) {
        case OBD_IOC_CREATE:                    /* may create echo object */
-               if (!cfs_capable(CFS_CAP_SYS_ADMIN))
+               if (!capable(CAP_SYS_ADMIN))
                        GOTO(out, rc = -EPERM);
 
                rc = echo_create_object(env, ed, oa);
@@ -2848,7 +2858,7 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                int dirlen;
                __u64 id;
 
-               if (!cfs_capable(CFS_CAP_SYS_ADMIN))
+               if (!capable(CAP_SYS_ADMIN))
                        GOTO(out, rc = -EPERM);
 
                count = data->ioc_count;
@@ -2873,7 +2883,7 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                __u64            seq;
                int              max_count;
 
-               if (!cfs_capable(CFS_CAP_SYS_ADMIN))
+               if (!capable(CAP_SYS_ADMIN))
                        GOTO(out, rc = -EPERM);
 
                rc = seq_client_get_seq(env, ed->ed_cl_seq, &seq);
@@ -2894,7 +2904,7 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
        }
 #endif /* HAVE_SERVER_SUPPORT */
        case OBD_IOC_DESTROY:
-               if (!cfs_capable(CFS_CAP_SYS_ADMIN))
+               if (!capable(CAP_SYS_ADMIN))
                        GOTO(out, rc = -EPERM);
 
                rc = echo_get_object(&eco, ed, oa);
@@ -2915,7 +2925,7 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                GOTO(out, rc);
 
        case OBD_IOC_SETATTR:
-               if (!cfs_capable(CFS_CAP_SYS_ADMIN))
+               if (!capable(CAP_SYS_ADMIN))
                        GOTO(out, rc = -EPERM);
 
                rc = echo_get_object(&eco, ed, oa);
@@ -2926,7 +2936,7 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                GOTO(out, rc);
 
        case OBD_IOC_BRW_WRITE:
-               if (!cfs_capable(CFS_CAP_SYS_ADMIN))
+               if (!capable(CAP_SYS_ADMIN))
                        GOTO(out, rc = -EPERM);
 
                rw = OBD_BRW_WRITE;
@@ -2949,9 +2959,9 @@ out:
 }
 
 static int echo_client_setup(const struct lu_env *env,
-                            struct obd_device *obddev, struct lustre_cfg *lcfg)
+                            struct obd_device *obd, struct lustre_cfg *lcfg)
 {
-       struct echo_client_obd *ec = &obddev->u.echo_client;
+       struct echo_client_obd *ec = &obd->u.echo_client;
        struct obd_device *tgt;
        struct obd_uuid echo_uuid = { "ECHO_UUID" };
        struct obd_connect_data *ocd = NULL;
@@ -2999,7 +3009,9 @@ static int echo_client_setup(const struct lu_env *env,
                                 OBD_CONNECT_BRW_SIZE |
                                 OBD_CONNECT_GRANT | OBD_CONNECT_FULL20 |
                                 OBD_CONNECT_64BITHASH | OBD_CONNECT_LVB_TYPE |
-                                OBD_CONNECT_FID;
+                                OBD_CONNECT_FID | OBD_CONNECT_FLAGS2;
+       ocd->ocd_connect_flags2 = OBD_CONNECT2_REP_MBITS;
+
        ocd->ocd_brw_size = DT_MAX_BRW_SIZE;
        ocd->ocd_version = LUSTRE_VERSION_CODE;
        ocd->ocd_group = FID_SEQ_ECHO;
@@ -3023,10 +3035,10 @@ static int echo_client_setup(const struct lu_env *env,
        RETURN(rc);
 }
 
-static int echo_client_cleanup(struct obd_device *obddev)
+static int echo_client_cleanup(struct obd_device *obd)
 {
-       struct echo_device *ed = obd2echo_dev(obddev);
-       struct echo_client_obd *ec = &obddev->u.echo_client;
+       struct echo_device *ed = obd2echo_dev(obd);
+       struct echo_client_obd *ec = &obd->u.echo_client;
        int rc;
 
        ENTRY;
@@ -3046,7 +3058,7 @@ static int echo_client_cleanup(struct obd_device *obddev)
                RETURN(0);
        }
 
-       if (!list_empty(&obddev->obd_exports)) {
+       if (!list_empty(&obd->obd_exports)) {
                CERROR("still has clients!\n");
                RETURN(-EBUSY);
        }
@@ -3110,7 +3122,7 @@ static int __init obdecho_init(void)
        if (rc != 0)
                goto failed_0;
 
-       rc = class_register_type(&echo_obd_ops, NULL, true, NULL,
+       rc = class_register_type(&echo_obd_ops, NULL, true,
                                 LUSTRE_ECHO_NAME, &echo_srv_type);
        if (rc != 0)
                goto failed_1;
@@ -3119,7 +3131,7 @@ static int __init obdecho_init(void)
        rc = lu_kmem_init(echo_caches);
        if (rc == 0) {
                rc = class_register_type(&echo_client_obd_ops, NULL, false,
-                                        NULL, LUSTRE_ECHO_CLIENT_NAME,
+                                        LUSTRE_ECHO_CLIENT_NAME,
                                         &echo_device_type);
                if (rc)
                        lu_kmem_fini(echo_caches);