Whamcloud - gitweb
LU-2607 mdd: preserve input arguments in mdd_create()
[fs/lustre-release.git] / lustre / mdd / mdd_dir.c
index e83415e..6ba30e3 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2007, 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/
@@ -345,31 +345,31 @@ int mdd_may_unlink(const struct lu_env *env, struct mdd_object *pobj,
  * VTX feature has been checked already, no need check again.
  */
 static inline int mdd_is_sticky(const struct lu_env *env,
-                                struct mdd_object *pobj,
-                                struct mdd_object *cobj)
+                               struct mdd_object *pobj,
+                               struct mdd_object *cobj)
 {
-        struct lu_attr *tmp_la = &mdd_env_info(env)->mti_la;
-        struct md_ucred *uc = md_ucred(env);
-        int rc;
+       struct lu_attr *tmp_la = &mdd_env_info(env)->mti_la;
+       struct lu_ucred *uc = lu_ucred_assert(env);
+       int rc;
 
-        if (pobj) {
-                rc = mdd_la_get(env, pobj, tmp_la, BYPASS_CAPA);
-                if (rc)
-                        return rc;
+       if (pobj) {
+               rc = mdd_la_get(env, pobj, tmp_la, BYPASS_CAPA);
+               if (rc)
+                       return rc;
 
-                if (!(tmp_la->la_mode & S_ISVTX) ||
-                     (tmp_la->la_uid == uc->mu_fsuid))
-                        return 0;
-        }
+               if (!(tmp_la->la_mode & S_ISVTX) ||
+                   (tmp_la->la_uid == uc->uc_fsuid))
+                       return 0;
+       }
 
-        rc = mdd_la_get(env, cobj, tmp_la, BYPASS_CAPA);
-        if (rc)
-                return rc;
+       rc = mdd_la_get(env, cobj, tmp_la, BYPASS_CAPA);
+       if (rc)
+               return rc;
 
-        if (tmp_la->la_uid == uc->mu_fsuid)
-                return 0;
+       if (tmp_la->la_uid == uc->uc_fsuid)
+               return 0;
 
-        return !mdd_capable(uc, CFS_CAP_FOWNER);
+       return !mdd_capable(uc, CFS_CAP_FOWNER);
 }
 
 /*
@@ -499,27 +499,28 @@ static int __mdd_index_delete_only(const struct lu_env *env, struct mdd_object *
 }
 
 static int __mdd_index_insert_only(const struct lu_env *env,
-                                   struct mdd_object *pobj,
-                                   const struct lu_fid *lf, const char *name,
-                                   struct thandle *handle,
-                                   struct lustre_capa *capa)
+                                  struct mdd_object *pobj,
+                                  const struct lu_fid *lf, const char *name,
+                                  struct thandle *handle,
+                                  struct lustre_capa *capa)
 {
-        struct dt_object *next = mdd_object_child(pobj);
-        int               rc;
-        ENTRY;
+       struct dt_object *next = mdd_object_child(pobj);
+       int               rc;
+       ENTRY;
 
-        if (dt_try_as_dir(env, next)) {
-                struct md_ucred  *uc = md_ucred(env);
+       if (dt_try_as_dir(env, next)) {
+               struct lu_ucred  *uc = lu_ucred_check(env);
+               int ignore_quota;
 
-                rc = next->do_index_ops->dio_insert(env, next,
-                                                    (struct dt_rec*)lf,
-                                                    (const struct dt_key *)name,
-                                                    handle, capa, uc->mu_cap &
-                                                    CFS_CAP_SYS_RESOURCE_MASK);
-        } else {
-                rc = -ENOTDIR;
-        }
-        RETURN(rc);
+               ignore_quota = uc ? uc->uc_cap & CFS_CAP_SYS_RESOURCE_MASK : 1;
+               rc = next->do_index_ops->dio_insert(env, next,
+                                                   (struct dt_rec*)lf,
+                                                   (const struct dt_key *)name,
+                                                   handle, capa, ignore_quota);
+       } else {
+               rc = -ENOTDIR;
+       }
+       RETURN(rc);
 }
 
 /* insert named index, add reference if isdir */
@@ -703,12 +704,12 @@ int mdd_changelog_store(const struct lu_env *env, struct mdd_device *mdd,
        rec->cr_hdr.lrh_type = CHANGELOG_REC;
        rec->cr.cr_time = cl_time();
 
-       cfs_spin_lock(&mdd->mdd_cl.mc_lock);
+       spin_lock(&mdd->mdd_cl.mc_lock);
        /* NB: I suppose it's possible llog_add adds out of order wrt cr_index,
         * but as long as the MDD transactions are ordered correctly for e.g.
         * rename conflicts, I don't think this should matter. */
        rec->cr.cr_index = ++mdd->mdd_cl.mc_index;
-       cfs_spin_unlock(&mdd->mdd_cl.mc_lock);
+       spin_unlock(&mdd->mdd_cl.mc_lock);
 
        ctxt = llog_get_context(obd, LLOG_CHANGELOG_ORIG_CTXT);
        if (ctxt == NULL)
@@ -741,12 +742,12 @@ int mdd_changelog_ext_store(const struct lu_env *env, struct mdd_device *mdd,
        rec->cr_hdr.lrh_type = CHANGELOG_REC;
        rec->cr.cr_time = cl_time();
 
-       cfs_spin_lock(&mdd->mdd_cl.mc_lock);
+       spin_lock(&mdd->mdd_cl.mc_lock);
        /* NB: I suppose it's possible llog_add adds out of order wrt cr_index,
         * but as long as the MDD transactions are ordered correctly for e.g.
         * rename conflicts, I don't think this should matter. */
        rec->cr.cr_index = ++mdd->mdd_cl.mc_index;
-       cfs_spin_unlock(&mdd->mdd_cl.mc_lock);
+       spin_unlock(&mdd->mdd_cl.mc_lock);
 
        ctxt = llog_get_context(obd, LLOG_CHANGELOG_ORIG_CTXT);
        if (ctxt == NULL)
@@ -877,7 +878,6 @@ static int mdd_changelog_ext_ns_store(const struct lu_env  *env,
        rec->cr.cr_namelen = tname->ln_namelen;
        memcpy(rec->cr.cr_name, tname->ln_name, tname->ln_namelen);
        if (sname) {
-               LASSERT(sfid != NULL);
                rec->cr.cr_name[tname->ln_namelen] = '\0';
                memcpy(rec->cr.cr_name + tname->ln_namelen + 1, sname->ln_name,
                        sname->ln_namelen);
@@ -1436,9 +1436,19 @@ int mdd_object_initialize(const struct lu_env *env, const struct lu_fid *pfid,
          *  (2) maybe, the child attributes should be set in OSD when creation.
          */
 
+       /*
+        * inode mode has been set in creation time, and it's based on umask,
+        * la_mode and acl, don't set here again! (which will go wrong
+        * because below function doesn't consider umask).
+        * I'd suggest set all object attributes in creation time, see above.
+        */
+       LASSERT(attr->la_valid & LA_MODE);
+       attr->la_valid &= ~LA_MODE;
        rc = mdd_attr_set_internal(env, child, attr, handle, 0);
-        if (rc != 0)
-                RETURN(rc);
+       /* arguments are supposed to stay the same */
+       attr->la_valid |= LA_MODE;
+       if (rc != 0)
+               RETURN(rc);
 
        if (S_ISDIR(attr->la_mode)) {
                 /* Add "." and ".." for newly created dir */
@@ -1788,7 +1798,7 @@ static int mdd_create(const struct lu_env *env, struct md_object *pobj,
         inserted = 1;
 
         if (S_ISLNK(attr->la_mode)) {
-                struct md_ucred  *uc = md_ucred(env);
+               struct lu_ucred  *uc = lu_ucred_assert(env);
                 struct dt_object *dt = mdd_object_child(son);
                 const char *target_name = spec->u.sp_symname;
                 int sym_len = strlen(target_name);
@@ -1796,10 +1806,10 @@ static int mdd_create(const struct lu_env *env, struct md_object *pobj,
                 loff_t pos = 0;
 
                 buf = mdd_buf_get_const(env, target_name, sym_len);
-                rc = dt->do_body_ops->dbo_write(env, dt, buf, &pos, handle,
-                                                mdd_object_capa(env, son),
-                                                uc->mu_cap &
-                                                CFS_CAP_SYS_RESOURCE_MASK);
+               rc = dt->do_body_ops->dbo_write(env, dt, buf, &pos, handle,
+                                               mdd_object_capa(env, son),
+                                               uc->uc_cap &
+                                               CFS_CAP_SYS_RESOURCE_MASK);
 
                 if (rc == sym_len)
                         rc = 0;
@@ -1860,7 +1870,7 @@ out_stop:
 out_free:
         /* The child object shouldn't be cached anymore */
         if (rc)
-                cfs_set_bit(LU_OBJECT_HEARD_BANSHEE,
+               set_bit(LU_OBJECT_HEARD_BANSHEE,
                             &child->mo_lu.lo_header->loh_flags);
         return rc;
 }
@@ -2737,16 +2747,22 @@ out:
        if (rc == 0)
                rc = rc2;
        if (rc) {
+               int error = 1;
+               if (rc == -EOVERFLOW || rc == - ENOENT)
+                       error = 0;
                if (oldpfid == NULL)
-                       CERROR("link_ea add '%.*s' failed %d "DFID"\n",
+                       CDEBUG(error ? D_ERROR : D_OTHER,
+                              "link_ea add '%.*s' failed %d "DFID"\n",
                               newlname->ln_namelen, newlname->ln_name,
                               rc, PFID(mdd_object_fid(mdd_obj)));
                else if (newpfid == NULL)
-                       CERROR("link_ea del '%.*s' failed %d "DFID"\n",
+                       CDEBUG(error ? D_ERROR : D_OTHER,
+                              "link_ea del '%.*s' failed %d "DFID"\n",
                               oldlname->ln_namelen, oldlname->ln_name,
                               rc, PFID(mdd_object_fid(mdd_obj)));
                else
-                       CERROR("link_ea rename '%.*s'->'%.*s' failed %d "
+                       CDEBUG(error ? D_ERROR : D_OTHER,
+                              "link_ea rename '%.*s'->'%.*s' failed %d "
                               DFID"\n",
                               oldlname->ln_namelen, oldlname->ln_name,
                               newlname->ln_namelen, newlname->ln_name,