Whamcloud - gitweb
LU-129 Skip quotacheck on administratively disabled OSTs
[fs/lustre-release.git] / lustre / mdd / mdd_dir.c
index 2ee1985..f0efe38 100644 (file)
@@ -82,7 +82,7 @@ static int mdd_links_add(const struct lu_env *env,
                          struct mdd_object *mdd_obj,
                          const struct lu_fid *pfid,
                          const struct lu_name *lname,
-                         struct thandle *handle);
+                         struct thandle *handle, int first);
 static int mdd_links_rename(const struct lu_env *env,
                             struct mdd_object *mdd_obj,
                             const struct lu_fid *oldpfid,
@@ -251,7 +251,7 @@ static int mdd_dir_is_empty(const struct lu_env *env,
 
         iops = &obj->do_index_ops->dio_it;
         it = iops->init(env, obj, BYPASS_CAPA);
-        if (it != NULL) {
+        if (!IS_ERR(it)) {
                 result = iops->get(env, it, (const void *)"");
                 if (result > 0) {
                         int i;
@@ -270,7 +270,7 @@ static int mdd_dir_is_empty(const struct lu_env *env,
                 iops->put(env, it);
                 iops->fini(env, it);
         } else
-                result = -ENOMEM;
+                result = PTR_ERR(it);
         RETURN(result);
 }
 
@@ -619,6 +619,7 @@ static int __mdd_index_delete(const struct lu_env *env, struct mdd_object *pobj,
 static int mdd_changelog_ns_store(const struct lu_env  *env,
                                   struct mdd_device    *mdd,
                                   enum changelog_rec_type type,
+                                  int flags,
                                   struct mdd_object    *target,
                                   struct mdd_object    *parent,
                                   const struct lu_fid  *tf,
@@ -650,7 +651,7 @@ static int mdd_changelog_ns_store(const struct lu_env  *env,
                 RETURN(-ENOMEM);
         rec = (struct llog_changelog_rec *)buf->lb_buf;
 
-        rec->cr.cr_flags = CLF_VERSION;
+        rec->cr.cr_flags = CLF_VERSION | (CLF_FLAGMASK & flags);
         rec->cr.cr_type = (__u32)type;
         tfid = tf ? tf : mdo2fid(target);
         rec->cr.cr_tfid = *tfid;
@@ -741,8 +742,10 @@ static int mdd_link(const struct lu_env *env, struct md_object *tgt_obj,
 
         la->la_valid = LA_CTIME;
         rc = mdd_attr_check_set_internal(env, mdd_sobj, la, handle, 0);
-        if (rc == 0)
-                mdd_links_add(env, mdd_sobj, mdo2fid(mdd_tobj), lname, handle);
+        if (rc == 0) {
+                mdd_links_add(env, mdd_sobj,
+                              mdo2fid(mdd_tobj), lname, handle, 0);
+        }
 
         EXIT;
 out_unlock:
@@ -750,7 +753,7 @@ out_unlock:
         mdd_pdo_write_unlock(env, mdd_tobj, dlh);
 out_trans:
         if (rc == 0)
-                rc = mdd_changelog_ns_store(env, mdd, CL_HARDLINK, mdd_sobj,
+                rc = mdd_changelog_ns_store(env, mdd, CL_HARDLINK, 0, mdd_sobj,
                                             mdd_tobj, NULL, lname, handle);
         mdd_trans_stop(env, mdd, rc, handle);
 out_pending:
@@ -778,7 +781,9 @@ int mdd_finish_unlink(const struct lu_env *env,
 
         LASSERT(mdd_write_locked(env, obj) != 0);
 
-        rc = mdd_iattr_get(env, obj, ma);
+        /* read HSM flags, needed to set changelogs flags */
+        ma->ma_need = MA_HSM | MA_INODE;
+        rc = mdd_attr_get_internal(env, obj, ma);
         if (rc == 0 && ma->ma_attr.la_nlink == 0) {
                 obj->mod_flags |= DEAD_OBJ;
                 /* add new orphan and the object
@@ -884,10 +889,14 @@ static int mdd_unlink(const struct lu_env *env, struct md_object *pobj,
         if (rc)
                 GOTO(cleanup, rc);
 
-        la->la_valid = LA_CTIME;
-        rc = mdd_attr_check_set_internal(env, mdd_cobj, la, handle, 0);
-        if (rc)
-                GOTO(cleanup, rc);
+        if (ma->ma_attr.la_nlink > 0 || mdd_cobj->mod_count > 0) {
+                /* update ctime of an unlinked file only if it is still
+                 * opened or a link still exists */
+                la->la_valid = LA_CTIME;
+                rc = mdd_attr_check_set_internal(env, mdd_cobj, la, handle, 0);
+                if (rc)
+                        GOTO(cleanup, rc);
+        }
 
         rc = mdd_finish_unlink(env, mdd_cobj, ma, handle);
 #ifdef HAVE_QUOTA_SUPPORT
@@ -917,11 +926,18 @@ cleanup:
         mdd_write_unlock(env, mdd_cobj);
         mdd_pdo_write_unlock(env, mdd_pobj, dlh);
 out_trans:
-        if (rc == 0)
+        if (rc == 0) {
+                int cl_flags;
+
+                cl_flags = (ma->ma_attr.la_nlink == 0) ? CLF_UNLINK_LAST : 0;
+                if ((ma->ma_valid & MA_HSM) &&
+                    (ma->ma_hsm.mh_flags & HS_EXISTS))
+                        cl_flags |= CLF_UNLINK_HSM_EXISTS;
+
                 rc = mdd_changelog_ns_store(env, mdd,
-                                            is_dir ? CL_RMDIR : CL_UNLINK,
-                                            mdd_cobj, mdd_pobj, NULL, lname,
-                                            handle);
+                         is_dir ? CL_RMDIR : CL_UNLINK, cl_flags,
+                         mdd_cobj, mdd_pobj, NULL, lname, handle);
+        }
 
         mdd_trans_stop(env, mdd, rc, handle);
 #ifdef HAVE_QUOTA_SUPPORT
@@ -1295,7 +1311,7 @@ out_trans:
         if (rc == 0)
                 /* Bare EXT record with no RENAME in front of it signifies
                    a partial slave op */
-                rc = mdd_changelog_ns_store(env, mdd, CL_EXT, mdd_tobj,
+                rc = mdd_changelog_ns_store(env, mdd, CL_EXT, 0, mdd_tobj,
                                             mdd_tpobj, NULL, lname, handle);
 
         mdd_trans_stop(env, mdd, rc, handle);
@@ -1479,7 +1495,7 @@ int mdd_object_initialize(const struct lu_env *env, const struct lu_fid *pfid,
                         __mdd_ref_del(env, child, handle, 1);
         }
         if (rc == 0)
-                mdd_links_add(env, child, pfid, lname, handle);
+                mdd_links_add(env, child, pfid, lname, handle, 1);
 
         RETURN(rc);
 }
@@ -1846,10 +1862,10 @@ out_trans:
                             S_ISDIR(attr->la_mode) ? CL_MKDIR :
                             S_ISREG(attr->la_mode) ? CL_CREATE :
                             S_ISLNK(attr->la_mode) ? CL_SOFTLINK : CL_MKNOD,
-                            son, mdd_pobj, NULL, lname, handle);
+                            0, son, mdd_pobj, NULL, lname, handle);
         mdd_trans_stop(env, mdd, rc, handle);
 out_free:
-        /* finis lov_create stuff, free all temporary data */
+        /* finish lov_create stuff, free all temporary data */
         mdd_lov_create_finish(env, mdd, lmm, lmm_size, spec);
 out_pending:
 #ifdef HAVE_QUOTA_SUPPORT
@@ -2163,7 +2179,7 @@ static int mdd_rename(const struct lu_env *env,
                 if (rc == -ENOENT)
                         /* Old files might not have EA entry */
                         mdd_links_add(env, mdd_sobj, mdo2fid(mdd_spobj),
-                                      lsname, handle);
+                                      lsname, handle, 0);
                 mdd_write_unlock(env, mdd_sobj);
                 /* We don't fail the transaction if the link ea can't be
                    updated -- fid2path will use alternate lookup method. */
@@ -2220,10 +2236,10 @@ cleanup:
                 mdd_pdo_write_unlock(env, mdd_spobj, sdlh);
 cleanup_unlocked:
         if (rc == 0)
-                rc = mdd_changelog_ns_store(env, mdd, CL_RENAME, mdd_tobj,
+                rc = mdd_changelog_ns_store(env, mdd, CL_RENAME, 0, mdd_tobj,
                                             mdd_spobj, lf, lsname, handle);
         if (rc == 0)
-                rc = mdd_changelog_ns_store(env, mdd, CL_EXT, mdd_tobj,
+                rc = mdd_changelog_ns_store(env, mdd, CL_EXT, 0, mdd_tobj,
                                             mdd_tpobj, lf, ltname, handle);
 
         mdd_trans_stop(env, mdd, rc, handle);
@@ -2377,7 +2393,7 @@ static int mdd_links_add(const struct lu_env *env,
                          struct mdd_object *mdd_obj,
                          const struct lu_fid *pfid,
                          const struct lu_name *lname,
-                         struct thandle *handle)
+                         struct thandle *handle, int first)
 {
         struct lu_buf *buf;
         struct link_ea_header *leh;
@@ -2387,7 +2403,7 @@ static int mdd_links_add(const struct lu_env *env,
         if (!mdd_linkea_enable)
                 RETURN(0);
 
-        buf = mdd_links_get(env, mdd_obj);
+        buf = first ? ERR_PTR(-ENODATA) : mdd_links_get(env, mdd_obj);
         if (IS_ERR(buf)) {
                 rc = PTR_ERR(buf);
                 if (rc != -ENODATA) {
@@ -2426,7 +2442,7 @@ static int mdd_links_add(const struct lu_env *env,
                                PFID(mdd_object_fid(mdd_obj)));
         }
 
-        if (buf->lb_vmalloc)
+        if (buf->lb_len > OBD_ALLOC_BIG)
                 /* if we vmalloced a large buffer drop it */
                 mdd_buf_put(buf);
 
@@ -2513,7 +2529,7 @@ out:
                        oldlname->ln_namelen, oldlname->ln_name, rc,
                        PFID(mdd_object_fid(mdd_obj)));
 
-        if (buf->lb_vmalloc)
+        if (buf->lb_len > OBD_ALLOC_BIG)
                 /* if we vmalloced a large buffer drop it */
                 mdd_buf_put(buf);
 
@@ -2530,5 +2546,5 @@ const struct md_dir_operations mdd_dir_ops = {
         .mdo_name_insert   = mdd_name_insert,
         .mdo_name_remove   = mdd_name_remove,
         .mdo_rename_tgt    = mdd_rename_tgt,
-        .mdo_create_data   = mdd_create_data
+        .mdo_create_data   = mdd_create_data,
 };