Whamcloud - gitweb
LU-569: Make lu_object cache size adjustable
[fs/lustre-release.git] / lustre / cmm / mdc_object.c
index f1d45a8..c332def 100644 (file)
@@ -16,8 +16,8 @@
  * in the LICENSE file that accompanied this code).
  *
  * You should have received a copy of the GNU General Public License
- * version 2 along with this program; If not, see [sun.com URL with a
- * copy of GPLv2].
+ * 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
@@ -26,7 +26,7 @@
  * GPL HEADER END
  */
 /*
- * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  */
 /*
 #include "cmm_internal.h"
 #include "mdc_internal.h"
 
-static struct md_object_operations mdc_mo_ops;
-static struct md_dir_operations mdc_dir_ops;
-static struct lu_object_operations mdc_obj_ops;
+static const struct md_object_operations mdc_mo_ops;
+static const struct md_dir_operations mdc_dir_ops;
+static const struct lu_object_operations mdc_obj_ops;
 
 extern struct lu_context_key mdc_thread_key;
-
+/**
+ * \addtogroup cmm_mdc
+ * @{
+ */
+/**
+ * Allocate new mdc object.
+ */
 struct lu_object *mdc_object_alloc(const struct lu_env *env,
                                    const struct lu_object_header *hdr,
                                    struct lu_device *ld)
 {
-       struct mdc_object *mco;
+        struct mdc_object *mco;
         ENTRY;
 
-       OBD_ALLOC_PTR(mco);
-       if (mco != NULL) {
-               struct lu_object *lo;
+        OBD_ALLOC_PTR(mco);
+        if (mco != NULL) {
+                struct lu_object *lo;
 
-               lo = &mco->mco_obj.mo_lu;
+                lo = &mco->mco_obj.mo_lu;
                 lu_object_init(lo, NULL, ld);
                 mco->mco_obj.mo_ops = &mdc_mo_ops;
                 mco->mco_obj.mo_dir_ops = &mdc_dir_ops;
                 lo->lo_ops = &mdc_obj_ops;
                 RETURN(lo);
-       } else
-               RETURN(NULL);
+        } else
+                RETURN(NULL);
 }
 
+/** Free current mdc object */
 static void mdc_object_free(const struct lu_env *env, struct lu_object *lo)
 {
         struct mdc_object *mco = lu2mdc_obj(lo);
-       lu_object_fini(lo);
+        lu_object_fini(lo);
         OBD_FREE_PTR(mco);
 }
 
-static int mdc_object_init(const struct lu_env *env, struct lu_object *lo)
+/**
+ * Initialize mdc object. All of them have loh_attr::LOHA_REMOTE set.
+ */
+static int mdc_object_init(const struct lu_env *env, struct lu_object *lo,
+                           const struct lu_object_conf *unused)
 {
         ENTRY;
         lo->lo_header->loh_attr |= LOHA_REMOTE;
         RETURN(0);
 }
 
-static int mdc_object_print(const struct lu_env *env, void *cookie,
-                            lu_printer_t p, const struct lu_object *lo)
-{
-       return (*p)(env, cookie, LUSTRE_CMM_MDC_NAME"-object@%p", lo);
-}
-
-static struct lu_object_operations mdc_obj_ops = {
+/**
+ * Instance of lu_object_operations for mdc.
+ */
+static const struct lu_object_operations mdc_obj_ops = {
         .loo_object_init    = mdc_object_init,
         .loo_object_free    = mdc_object_free,
-       .loo_object_print   = mdc_object_print,
 };
 
-/* md_object_operations */
+/**
+ * \name The set of md_object_operations.
+ * @{
+ */
+/**
+ * Get mdc_thread_info from lu_context
+ */
 static
 struct mdc_thread_info *mdc_info_get(const struct lu_env *env)
 {
@@ -116,6 +129,9 @@ struct mdc_thread_info *mdc_info_get(const struct lu_env *env)
         return mci;
 }
 
+/**
+ * Initialize mdc_thread_info.
+ */
 static
 struct mdc_thread_info *mdc_info_init(const struct lu_env *env)
 {
@@ -124,6 +140,9 @@ struct mdc_thread_info *mdc_info_init(const struct lu_env *env)
         return mci;
 }
 
+/**
+ * Convert attributes from mdt_body to the md_attr.
+ */
 static void mdc_body2attr(struct mdt_body *body, struct md_attr *ma)
 {
         struct lu_attr *la = &ma->ma_attr;
@@ -155,14 +174,18 @@ static void mdc_body2attr(struct mdt_body *body, struct md_attr *ma)
         ma->ma_valid = MA_INODE;
 }
 
+/**
+ * Fill the md_attr \a ma with attributes from request.
+ */
 static int mdc_req2attr_update(const struct lu_env *env,
                                struct md_attr *ma)
 {
         struct mdc_thread_info *mci;
         struct ptlrpc_request *req;
         struct mdt_body *body;
-        struct lov_mds_md *lov;
+        struct lov_mds_md *md;
         struct llog_cookie *cookie;
+        void *acl;
 
         ENTRY;
         mci = mdc_info_get(env);
@@ -181,46 +204,75 @@ static int mdc_req2attr_update(const struct lu_env *env,
                 LASSERT(ma->ma_capa != NULL);
                 *ma->ma_capa = *capa;
         }
-                
-        if (!(body->valid & OBD_MD_FLEASIZE))
-                RETURN(0);
 
-        if (body->eadatasize == 0) {
-                CERROR("OBD_MD_FLEASIZE is set but eadatasize is zero\n");
-                RETURN(-EPROTO);
+        if ((body->valid & OBD_MD_FLEASIZE) || (body->valid & OBD_MD_FLDIREA)) {
+                if (body->eadatasize == 0) {
+                        CERROR("No size defined for easize field\n");
+                        RETURN(-EPROTO);
+                }
+
+                md = req_capsule_server_sized_get(&req->rq_pill, &RMF_MDT_MD,
+                                                  body->eadatasize);
+                if (md == NULL)
+                        RETURN(-EPROTO);
+
+                LASSERT(ma->ma_lmm != NULL);
+                LASSERT(ma->ma_lmm_size >= body->eadatasize);
+                ma->ma_lmm_size = body->eadatasize;
+                memcpy(ma->ma_lmm, md, ma->ma_lmm_size);
+                ma->ma_valid |= MA_LOV;
         }
 
-        lov = req_capsule_server_sized_get(&req->rq_pill, &RMF_MDT_MD,
-                                           body->eadatasize);
-        if (lov == NULL)
-                RETURN(-EPROTO);
+        if (body->valid & OBD_MD_FLCOOKIE) {
+                /*
+                 * ACL and cookie share the same body->aclsize, we need
+                 * to make sure that they both never come here.
+                 */
+                LASSERT(!(body->valid & OBD_MD_FLACL));
 
-        LASSERT(ma->ma_lmm != NULL);
-        LASSERT(ma->ma_lmm_size >= body->eadatasize); 
-        ma->ma_lmm_size = body->eadatasize;
-        memcpy(ma->ma_lmm, lov, ma->ma_lmm_size);
-        ma->ma_valid |= MA_LOV;
+                if (body->aclsize == 0) {
+                        CERROR("No size defined for cookie field\n");
+                        RETURN(-EPROTO);
+                }
 
-        if (!(body->valid & OBD_MD_FLCOOKIE))
-                RETURN(0);
+                cookie = req_capsule_server_sized_get(&req->rq_pill,
+                                                      &RMF_LOGCOOKIES,
+                                                      body->aclsize);
+                if (cookie == NULL)
+                        RETURN(-EPROTO);
 
-        if (body->aclsize == 0) {
-                CERROR("OBD_MD_FLCOOKIE is set but cookie size is zero\n");
-                RETURN(-EPROTO);
+                LASSERT(ma->ma_cookie != NULL);
+                LASSERT(ma->ma_cookie_size == body->aclsize);
+                memcpy(ma->ma_cookie, cookie, ma->ma_cookie_size);
+                ma->ma_valid |= MA_COOKIE;
         }
 
-        cookie = req_capsule_server_sized_get(&req->rq_pill, &RMF_ACL,
-                                              body->aclsize);
-        if (cookie == NULL)
-                RETURN(-EPROTO);
+#ifdef CONFIG_FS_POSIX_ACL
+        if (body->valid & OBD_MD_FLACL) {
+                if (body->aclsize == 0) {
+                        CERROR("No size defined for acl field\n");
+                        RETURN(-EPROTO);
+                }
+
+                acl = req_capsule_server_sized_get(&req->rq_pill,
+                                                   &RMF_ACL,
+                                                   body->aclsize);
+                if (acl == NULL)
+                        RETURN(-EPROTO);
+
+                LASSERT(ma->ma_acl != NULL);
+                LASSERT(ma->ma_acl_size == body->aclsize);
+                memcpy(ma->ma_acl, acl, ma->ma_acl_size);
+                ma->ma_valid |= MA_ACL_DEF;
+        }
+#endif
 
-        LASSERT(ma->ma_cookie != NULL);
-        LASSERT(ma->ma_cookie_size == body->aclsize);
-        memcpy(ma->ma_cookie, cookie, ma->ma_cookie_size);
-        ma->ma_valid |= MA_COOKIE;
         RETURN(0);
 }
 
+/**
+ * The md_object_operations::moo_attr_get() in mdc.
+ */
 static int mdc_attr_get(const struct lu_env *env, struct md_object *mo,
                         struct md_attr *ma)
 {
@@ -234,9 +286,13 @@ static int mdc_attr_get(const struct lu_env *env, struct md_object *mo,
 
         memset(&mci->mci_opdata, 0, sizeof(mci->mci_opdata));
 
-        rc = md_getattr(mc->mc_desc.cl_exp, lu_object_fid(&mo->mo_lu),
-                        NULL, OBD_MD_FLMODE | OBD_MD_FLUID | OBD_MD_FLGID |
-                        OBD_MD_FLFLAGS | OBD_MD_FLCROSSREF, 0, &mci->mci_req);
+        memcpy(&mci->mci_opdata.op_fid1, lu_object_fid(&mo->mo_lu),
+               sizeof (struct lu_fid));
+        mci->mci_opdata.op_valid = OBD_MD_FLMODE | OBD_MD_FLUID |
+                                   OBD_MD_FLGID | OBD_MD_FLFLAGS |
+                                   OBD_MD_FLCROSSREF;
+
+        rc = md_getattr(mc->mc_desc.cl_exp, &mci->mci_opdata, &mci->mci_req);
         if (rc == 0) {
                 /* get attr from request */
                 rc = mdc_req2attr_update(env, ma);
@@ -247,15 +303,20 @@ static int mdc_attr_get(const struct lu_env *env, struct md_object *mo,
         RETURN(rc);
 }
 
-static inline struct timespec *mdc_attr_time(struct timespec *t, __u64 seconds)
+/**
+ * Helper to init timspec \a t.
+ */
+static inline struct timespec *mdc_attr_time(struct timespec *t, obd_time seconds)
 {
         t->tv_sec = seconds;
         t->tv_nsec = 0;
         return t;
 }
 
-/*
- * XXX: It is only used for set ctime when rename's source on remote MDS.
+/**
+ * The md_object_operations::moo_attr_set() in mdc.
+ *
+ * \note It is only used for set ctime when rename's source on remote MDS.
  */
 static int mdc_attr_set(const struct lu_env *env, struct md_object *mo,
                         const struct md_attr *ma)
@@ -293,7 +354,7 @@ static int mdc_attr_set(const struct lu_env *env, struct md_object *mo,
         } else {
                 mci->mci_opdata.op_fsuid = la->la_uid;
                 mci->mci_opdata.op_fsgid = la->la_gid;
-                mci->mci_opdata.op_cap = current->cap_effective;
+                mci->mci_opdata.op_cap = cfs_curproc_cap_pack();
                 mci->mci_opdata.op_suppgids[0] =
                                 mci->mci_opdata.op_suppgids[1] = -1;
         }
@@ -306,6 +367,9 @@ static int mdc_attr_set(const struct lu_env *env, struct md_object *mo,
         RETURN(rc);
 }
 
+/**
+ * The md_object_operations::moo_object_create() in mdc.
+ */
 static int mdc_object_create(const struct lu_env *env,
                              struct md_object *mo,
                              const struct md_op_spec *spec,
@@ -319,7 +383,7 @@ static int mdc_object_create(const struct lu_env *env,
         int rc, symlen;
         uid_t uid;
         gid_t gid;
-        __u32 cap;
+        cfs_cap_t cap;
         ENTRY;
 
         LASSERT(S_ISDIR(la->la_mode));
@@ -328,7 +392,7 @@ static int mdc_object_create(const struct lu_env *env,
         mci = mdc_info_init(env);
         mci->mci_opdata.op_bias = MDS_CROSS_REF;
         mci->mci_opdata.op_fid2 = *lu_object_fid(&mo->mo_lu);
-        
+
         /* Parent fid is needed to create dotdot on the remote node. */
         mci->mci_opdata.op_fid1 = *(spec->u.sp_pfid);
         mci->mci_opdata.op_mod_time = la->la_ctime;
@@ -383,6 +447,9 @@ static int mdc_object_create(const struct lu_env *env,
         RETURN(rc);
 }
 
+/**
+ * The md_object_operations::moo_ref_add() in mdc.
+ */
 static int mdc_ref_add(const struct lu_env *env, struct md_object *mo,
                        const struct md_attr *ma)
 {
@@ -415,7 +482,7 @@ static int mdc_ref_add(const struct lu_env *env, struct md_object *mo,
         } else {
                 mci->mci_opdata.op_fsuid = la->la_uid;
                 mci->mci_opdata.op_fsgid = la->la_gid;
-                mci->mci_opdata.op_cap = current->cap_effective;
+                mci->mci_opdata.op_cap = cfs_curproc_cap_pack();
                 mci->mci_opdata.op_suppgids[0] =
                                 mci->mci_opdata.op_suppgids[1] = -1;
         }
@@ -428,6 +495,9 @@ static int mdc_ref_add(const struct lu_env *env, struct md_object *mo,
         RETURN(rc);
 }
 
+/**
+ * The md_object_operations::moo_ref_del() in mdc.
+ */
 static int mdc_ref_del(const struct lu_env *env, struct md_object *mo,
                        struct md_attr *ma)
 {
@@ -459,7 +529,7 @@ static int mdc_ref_del(const struct lu_env *env, struct md_object *mo,
         } else {
                 mci->mci_opdata.op_fsuid = la->la_uid;
                 mci->mci_opdata.op_fsgid = la->la_gid;
-                mci->mci_opdata.op_cap = current->cap_effective;
+                mci->mci_opdata.op_cap = cfs_curproc_cap_pack();
                 mci->mci_opdata.op_suppgids[0] = -1;
         }
 
@@ -475,6 +545,7 @@ static int mdc_ref_del(const struct lu_env *env, struct md_object *mo,
 }
 
 #ifdef HAVE_SPLIT_SUPPORT
+/** Send page with directory entries to another MDS. */
 int mdc_send_page(struct cmm_device *cm, const struct lu_env *env,
                   struct md_object *mo, struct page *page, __u32 offset)
 {
@@ -490,15 +561,25 @@ int mdc_send_page(struct cmm_device *cm, const struct lu_env *env,
 }
 #endif
 
-static struct md_object_operations mdc_mo_ops = {
+/**
+ * Instance of md_object_operations for mdc.
+ */
+static const struct md_object_operations mdc_mo_ops = {
         .moo_attr_get       = mdc_attr_get,
         .moo_attr_set       = mdc_attr_set,
         .moo_object_create  = mdc_object_create,
         .moo_ref_add        = mdc_ref_add,
         .moo_ref_del        = mdc_ref_del,
 };
+/** @} */
 
-/* md_dir_operations */
+/**
+ * \name The set of md_dir_operations.
+ * @{
+ */
+/**
+ * The md_dir_operations::mdo_rename_tgt in mdc.
+ */
 static int mdc_rename_tgt(const struct lu_env *env, struct md_object *mo_p,
                           struct md_object *mo_t, const struct lu_fid *lf,
                           const struct lu_name *lname, struct md_attr *ma)
@@ -535,7 +616,7 @@ static int mdc_rename_tgt(const struct lu_env *env, struct md_object *mo_p,
         } else {
                 mci->mci_opdata.op_fsuid = la->la_uid;
                 mci->mci_opdata.op_fsgid = la->la_gid;
-                mci->mci_opdata.op_cap = current->cap_effective;
+                mci->mci_opdata.op_cap = cfs_curproc_cap_pack();
                 mci->mci_opdata.op_suppgids[0] =
                                 mci->mci_opdata.op_suppgids[1] = -1;
         }
@@ -551,10 +632,13 @@ static int mdc_rename_tgt(const struct lu_env *env, struct md_object *mo_p,
 
         RETURN(rc);
 }
-/* 
- * Return resulting fid in sfid
- * 0: fids are not relatives
- * fid: fid at which search stopped
+/**
+ * Check the fids are not relatives.
+ * The md_dir_operations::mdo_is_subdir() in mdc.
+ *
+ * Return resulting fid in sfid.
+ * \retval \a sfid = 0 fids are not relatives
+ * \retval \a sfid = FID at which search stopped
  */
 static int mdc_is_subdir(const struct lu_env *env, struct md_object *mo,
                          const struct lu_fid *fid, struct lu_fid *sfid)
@@ -573,7 +657,7 @@ static int mdc_is_subdir(const struct lu_env *env, struct md_object *mo,
                 body = req_capsule_server_get(&mci->mci_req->rq_pill,
                                               &RMF_MDT_BODY);
                 LASSERT(body->valid & OBD_MD_FLID);
-        
+
                 CDEBUG(D_INFO, "Remote mdo_is_subdir(), new src "DFID"\n",
                        PFID(&body->fid1));
                 *sfid = body->fid1;
@@ -582,7 +666,9 @@ static int mdc_is_subdir(const struct lu_env *env, struct md_object *mo,
         RETURN(rc);
 }
 
-static struct md_dir_operations mdc_dir_ops = {
+/** Instance of md_dir_operations for mdc. */
+static const struct md_dir_operations mdc_dir_ops = {
         .mdo_is_subdir   = mdc_is_subdir,
         .mdo_rename_tgt  = mdc_rename_tgt
 };
+/** @} */