Whamcloud - gitweb
LU-744 clio: save memory allocations for cl_page
[fs/lustre-release.git] / lustre / obdecho / echo_client.c
index 43619cc..a8f5b0b 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2012, Whamcloud, Inc.
+ * Copyright (c) 2011, 2012, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -222,7 +222,6 @@ struct echo_session_info {
         unsigned long dummy;
 };
 
-static cfs_mem_cache_t *echo_page_kmem;
 static cfs_mem_cache_t *echo_lock_kmem;
 static cfs_mem_cache_t *echo_object_kmem;
 static cfs_mem_cache_t *echo_thread_kmem;
@@ -231,11 +230,6 @@ static cfs_mem_cache_t *echo_session_kmem;
 
 static struct lu_kmem_descr echo_caches[] = {
         {
-                .ckd_cache = &echo_page_kmem,
-                .ckd_name  = "echo_page_kmem",
-                .ckd_size  = sizeof (struct echo_page)
-        },
-        {
                 .ckd_cache = &echo_lock_kmem,
                 .ckd_name  = "echo_lock_kmem",
                 .ckd_size  = sizeof (struct echo_lock)
@@ -334,7 +328,6 @@ static void echo_page_fini(const struct lu_env *env,
 
         cfs_atomic_dec(&eco->eo_npages);
         page_cache_release(vmpage);
-        OBD_SLAB_FREE_PTR(ep, echo_page_kmem);
         EXIT;
 }
 
@@ -422,23 +415,19 @@ static struct cl_lock_operations echo_lock_ops = {
  *
  * @{
  */
-static struct cl_page *echo_page_init(const struct lu_env *env,
-                                      struct cl_object *obj,
-                                      struct cl_page *page, cfs_page_t *vmpage)
+static int echo_page_init(const struct lu_env *env, struct cl_object *obj,
+                       struct cl_page *page, cfs_page_t *vmpage)
 {
-        struct echo_page *ep;
+        struct echo_page *ep = cl_object_page_slice(obj, page);
+       struct echo_object *eco = cl2echo_obj(obj);
         ENTRY;
 
-        OBD_SLAB_ALLOC_PTR_GFP(ep, echo_page_kmem, CFS_ALLOC_IO);
-        if (ep != NULL) {
-                struct echo_object *eco = cl2echo_obj(obj);
-                ep->ep_vmpage = vmpage;
-                page_cache_get(vmpage);
-               mutex_init(&ep->ep_lock);
-                cl_page_slice_add(page, &ep->ep_cl, obj, &echo_page_ops);
-                cfs_atomic_inc(&eco->eo_npages);
-        }
-        RETURN(ERR_PTR(ep ? 0 : -ENOMEM));
+       ep->ep_vmpage = vmpage;
+       page_cache_get(vmpage);
+       mutex_init(&ep->ep_lock);
+       cl_page_slice_add(page, &ep->ep_cl, obj, &echo_page_ops);
+       cfs_atomic_inc(&eco->eo_npages);
+        RETURN(0);
 }
 
 static int echo_io_init(const struct lu_env *env, struct cl_object *obj,
@@ -518,6 +507,7 @@ static int echo_object_init(const struct lu_env *env, struct lu_object *obj,
 
         eco->eo_dev = ed;
         cfs_atomic_set(&eco->eo_npages, 0);
+       cl_object_page_init(lu2cl(obj), sizeof(struct echo_page));
 
        spin_lock(&ec->ec_lock);
        cfs_list_add_tail(&eco->eo_obj_chain, &ec->ec_objects);
@@ -754,7 +744,7 @@ LU_TYPE_INIT_FINI(echo, &echo_thread_key, &echo_session_key);
 
 #define ECHO_SEQ_WIDTH 0xffffffff
 static int echo_fid_init(struct echo_device *ed, char *obd_name,
-                         struct md_site *ms)
+                        struct seq_server_site *ss)
 {
         char *prefix;
         int rc;
@@ -770,10 +760,10 @@ 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, ms->ms_server_seq);
+       /* Init client side sequence-manager */
+       rc = 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)
@@ -900,11 +890,11 @@ static struct lu_device *echo_device_alloc(const struct lu_env *env,
                 ed->ed_site_myself.cs_lu = *ls;
                 ed->ed_site = &ed->ed_site_myself;
                 ed->ed_cl.cd_lu_dev.ld_site = &ed->ed_site_myself.cs_lu;
-                rc = echo_fid_init(ed, obd->obd_name, lu_site2md(ls));
-                if (rc) {
-                        CERROR("echo fid init error %d\n", rc);
-                        GOTO(out, rc);
-                }
+               rc = echo_fid_init(ed, obd->obd_name, lu_site2seq(ls));
+               if (rc) {
+                       CERROR("echo fid init error %d\n", rc);
+                       GOTO(out, rc);
+               }
         } else {
                  /* if echo client is to be stacked upon ost device, the next is
                   * NULL since ost is not a clio device so far */
@@ -1682,6 +1672,8 @@ static int echo_create_md_object(const struct lu_env *env,
 
        ENTRY;
 
+       if (ec_parent == NULL)
+               return -1;
         parent = lu_object_locate(ec_parent->lo_header, ld->ld_type);
        if (parent == NULL)
                RETURN(-ENXIO);
@@ -1777,6 +1769,8 @@ static int echo_setattr_object(const struct lu_env *env,
 
        ENTRY;
 
+       if (ec_parent == NULL)
+               return -1;
         parent = lu_object_locate(ec_parent->lo_header, ld->ld_type);
        if (parent == NULL)
                RETURN(-ENXIO);
@@ -1840,6 +1834,8 @@ static int echo_getattr_object(const struct lu_env *env,
 
        ENTRY;
 
+       if (ec_parent == NULL)
+               return -1;
         parent = lu_object_locate(ec_parent->lo_header, ld->ld_type);
        if (parent == NULL)
                RETURN(-ENXIO);
@@ -1902,6 +1898,8 @@ static int echo_lookup_object(const struct lu_env *env,
         int                      rc = 0;
         int                      i;
 
+       if (ec_parent == NULL)
+               return -1;
         parent = lu_object_locate(ec_parent->lo_header, ld->ld_type);
        if (parent == NULL)
                return -ENXIO;
@@ -2091,6 +2089,33 @@ static struct lu_object *echo_resolve_path(const struct lu_env *env,
         RETURN(parent);
 }
 
+static void echo_ucred_init(struct lu_env *env)
+{
+       struct lu_ucred *ucred = lu_ucred(env);
+
+       ucred->uc_valid = UCRED_INVALID;
+
+       ucred->uc_suppgids[0] = -1;
+       ucred->uc_suppgids[1] = -1;
+
+       ucred->uc_uid   = ucred->uc_o_uid   = cfs_curproc_uid();
+       ucred->uc_gid   = ucred->uc_o_gid   = cfs_curproc_gid();
+       ucred->uc_fsuid = ucred->uc_o_fsuid = cfs_curproc_fsuid();
+       ucred->uc_fsgid = ucred->uc_o_fsgid = cfs_curproc_fsgid();
+       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;
+       ucred->uc_valid = UCRED_NEW;
+}
+
+static void echo_ucred_fini(struct lu_env *env)
+{
+       struct lu_ucred *ucred = lu_ucred(env);
+       ucred->uc_valid = UCRED_INIT;
+}
+
 #define ECHO_MD_CTX_TAG (LCT_REMEMBER | LCT_MD_THREAD)
 #define ECHO_MD_SES_TAG (LCT_REMEMBER | LCT_SESSION)
 static int echo_md_handler(struct echo_device *ed, int command,
@@ -2148,6 +2173,8 @@ static int echo_md_handler(struct echo_device *ed, int command,
                        GOTO(out_name, rc = -EFAULT);
         }
 
+       echo_ucred_init(env);
+
         switch (command) {
         case ECHO_MD_CREATE:
         case ECHO_MD_MKDIR: {
@@ -2190,6 +2217,8 @@ static int echo_md_handler(struct echo_device *ed, int command,
                 rc = -EINVAL;
                 break;
         }
+       echo_ucred_fini(env);
+
 out_name:
         if (name != NULL)
                 OBD_FREE(name, namelen + 1);
@@ -2845,11 +2874,11 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                 if (cfs_copy_to_user(data->ioc_pbuf1, &seq, data->ioc_plen1))
                         return -EFAULT;
 
-                max_count = LUSTRE_SEQ_MAX_WIDTH;
-                if (cfs_copy_to_user(data->ioc_pbuf2, &max_count,
-                                     data->ioc_plen2))
-                        return -EFAULT;
-                GOTO(out, rc);
+               max_count = LUSTRE_METADATA_SEQ_MAX_WIDTH;
+               if (cfs_copy_to_user(data->ioc_pbuf2, &max_count,
+                                    data->ioc_plen2))
+                       return -EFAULT;
+               GOTO(out, rc);
         }
         case OBD_IOC_DESTROY:
                 if (!cfs_capable(CFS_CAP_SYS_ADMIN))