Whamcloud - gitweb
LU-14513 osd: release o_guard before quota acquisition
[fs/lustre-release.git] / lustre / osd-zfs / osd_object.c
index f28bcb7..464e0d6 100644 (file)
@@ -27,7 +27,6 @@
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
  *
  * lustre/osd-zfs/osd_object.c
  *
@@ -64,9 +63,9 @@
 char *osd_obj_tag = "osd_object";
 static int osd_object_sync_delay_us = -1;
 
-static struct dt_object_operations osd_obj_ops;
-static struct lu_object_operations osd_lu_obj_ops;
-static struct dt_object_operations osd_obj_otable_it_ops;
+static const struct dt_object_operations osd_obj_ops;
+static const struct lu_object_operations osd_lu_obj_ops;
+static const struct dt_object_operations osd_obj_otable_it_ops;
 
 static void
 osd_object_sa_fini(struct osd_object *obj)
@@ -186,9 +185,11 @@ osd_object_sa_bulk_update(struct osd_object *obj, sa_bulk_attr_t *attrs,
 static int __osd_object_attr_get(const struct lu_env *env, struct osd_device *o,
                                 struct osd_object *obj, struct lu_attr *la)
 {
-       struct osa_attr *osa = &osd_oti_get(env)->oti_osa;
-       sa_bulk_attr_t  *bulk = osd_oti_get(env)->oti_attr_bulk;
-       int              cnt = 0;
+       struct osa_attr *osa = &osd_oti_get(env)->oti_osa;
+       sa_bulk_attr_t *bulk = osd_oti_get(env)->oti_attr_bulk;
+       struct lustre_mdt_attrs *lma;
+       struct lu_buf buf;
+       int cnt = 0;
        int              rc;
        ENTRY;
 
@@ -244,27 +245,22 @@ static int __osd_object_attr_get(const struct lu_env *env, struct osd_device *o,
        la->la_flags = attrs_zfs2fs(osa->flags);
        la->la_size = osa->size;
 
-       /* Try to get extra flag from LMA. Right now, only LMAI_ORPHAN
-        * flags is stored in LMA, and it is only for orphan directory */
-       if (S_ISDIR(la->la_mode) && dt_object_exists(&obj->oo_dt)) {
-               struct osd_thread_info *info = osd_oti_get(env);
-               struct lustre_mdt_attrs *lma;
-               struct lu_buf buf;
-
-               lma = (struct lustre_mdt_attrs *)info->oti_buf;
-               buf.lb_buf = lma;
-               buf.lb_len = sizeof(info->oti_buf);
-               rc = osd_xattr_get(env, &obj->oo_dt, &buf, XATTR_NAME_LMA);
-               if (rc > 0) {
-                       rc = 0;
-                       lma->lma_incompat = le32_to_cpu(lma->lma_incompat);
-                       obj->oo_lma_flags =
-                               lma_to_lustre_flags(lma->lma_incompat);
-
-               } else if (rc == -ENODATA) {
-                       rc = 0;
-               }
+       /* Try to get extra flags from LMA */
+       lma = (struct lustre_mdt_attrs *)osd_oti_get(env)->oti_buf;
+       buf.lb_buf = lma;
+       buf.lb_len = sizeof(osd_oti_get(env)->oti_buf);
+       down_read(&obj->oo_guard);
+       rc = osd_xattr_get_lma(env, obj, &buf);
+       if (!rc) {
+               lma->lma_incompat = le32_to_cpu(lma->lma_incompat);
+               obj->oo_lma_flags =
+                       lma_to_lustre_flags(lma->lma_incompat);
+       } else if (rc == -ENODATA ||
+                  !(S_ISDIR(la->la_mode) &&
+                    dt_object_exists(&obj->oo_dt))) {
+               rc = 0;
        }
+       up_read(&obj->oo_guard);
 
        if (S_ISCHR(la->la_mode) || S_ISBLK(la->la_mode)) {
                rc = -sa_lookup(obj->oo_sa_hdl, SA_ZPL_RDEV(o), &osa->rdev, 8);
@@ -619,9 +615,12 @@ zget:
                GOTO(out, rc = 0);
 
        rc = osd_check_lma(env, obj);
-       if ((!rc && !remote) || (rc != -EREMCHG))
+       if (rc != -EREMCHG)
                GOTO(out, rc);
 
+       osd_scrub_refresh_mapping(env, osd, fid, oid, DTO_INDEX_DELETE, true,
+                                 NULL);
+
 trigger:
        /* We still have chance to get the valid dnode: for the object that is
         * referenced by remote name entry, the object on the local MDT will be
@@ -644,7 +643,7 @@ trigger:
        }
 
        /* The case someone triggered the OI scrub already. */
-       if (thread_is_running(&scrub->os_thread)) {
+       if (scrub->os_running) {
                if (!rc) {
                        LASSERT(remote);
 
@@ -664,8 +663,9 @@ trigger:
        /* It is me to trigger the OI scrub. */
        rc1 = osd_scrub_start(env, osd, SS_CLEAR_DRYRUN |
                              SS_CLEAR_FAILOUT | SS_AUTO_FULL);
-       LCONSOLE_WARN("%s: trigger OI scrub by RPC for the "DFID": rc = %d\n",
-                     osd_name(osd), PFID(fid), rc1);
+       CDEBUG_LIMIT(D_LFSCK | D_CONSOLE | D_WARNING,
+                    "%s: trigger OI scrub by RPC for "DFID"/%#llx: rc = %d\n",
+                    osd_name(osd), PFID(fid), oid, rc1);
        if (!rc) {
                LASSERT(remote);
 
@@ -699,11 +699,8 @@ static void osd_object_free(const struct lu_env *env, struct lu_object *l)
        dt_object_fini(&obj->oo_dt);
        /* obj doesn't contain an lu_object_header, so we don't need call_rcu */
        OBD_SLAB_FREE_PTR(obj, osd_object_kmem);
-       if (unlikely(h)) {
-               lu_object_header_fini(h);
-               OBD_FREE_PRE(h, sizeof(*h), "kfreed");
-               kfree_rcu(h, loh_rcu);
-       }
+       if (unlikely(h))
+               lu_object_header_free(h);
 }
 
 static int
@@ -857,12 +854,12 @@ static int osd_destroy(const struct lu_env *env, struct dt_object *dt,
                LASSERT(obj->oo_attr.la_size <= osd_sync_destroy_max_size);
                rc = -dmu_object_free(osd->od_os, oid, oh->ot_tx);
                if (rc)
-                       CERROR("%s: failed to free %s %llu: rc = %d\n",
+                       CERROR("%s: failed to free %s/%#llx: rc = %d\n",
                               osd->od_svname, buf, oid, rc);
        } else if (obj->oo_destroy == OSD_DESTROY_SYNC) {
                rc = -dmu_object_free(osd->od_os, oid, oh->ot_tx);
                if (rc)
-                       CERROR("%s: failed to free %s %llu: rc = %d\n",
+                       CERROR("%s: failed to free %s/%#llx: rc = %d\n",
                               osd->od_svname, buf, oid, rc);
        } else { /* asynchronous destroy */
                char *key = info->oti_key;
@@ -875,7 +872,7 @@ static int osd_destroy(const struct lu_env *env, struct dt_object *dt,
                rc = osd_zap_add(osd, osd->od_unlinked->dn_object,
                                 osd->od_unlinked, key, 8, 1, &oid, oh->ot_tx);
                if (rc)
-                       CERROR("%s: zap_add_int() failed %s %llu: rc = %d\n",
+                       CERROR("%s: zap_add_int() failed %s/%#llx: rc = %d\n",
                               osd->od_svname, buf, oid, rc);
        }
 
@@ -990,10 +987,11 @@ static int osd_write_locked(const struct lu_env *env, struct dt_object *dt)
 static int osd_attr_get(const struct lu_env *env, struct dt_object *dt,
                        struct lu_attr *attr)
 {
-       struct osd_object       *obj = osd_dt_obj(dt);
-       uint64_t                 blocks;
-       uint32_t                 blksize;
-       int                      rc = 0;
+       struct osd_object *obj = osd_dt_obj(dt);
+       struct osd_device *osd = osd_obj2dev(obj);
+       uint64_t blocks;
+       uint32_t blksize;
+       int rc = 0;
 
        down_read(&obj->oo_guard);
 
@@ -1012,9 +1010,13 @@ static int osd_attr_get(const struct lu_env *env, struct dt_object *dt,
                attr->la_valid |= LA_FLAGS;
                attr->la_flags |= LUSTRE_ORPHAN_FL;
        }
+       if (obj->oo_lma_flags & LUSTRE_ENCRYPT_FL) {
+               attr->la_valid |= LA_FLAGS;
+               attr->la_flags |= LUSTRE_ENCRYPT_FL;
+       }
        read_unlock(&obj->oo_attr_lock);
        if (attr->la_valid & LA_FLAGS && attr->la_flags & LUSTRE_ORPHAN_FL)
-               CDEBUG(D_INFO, "%s: set orphan flag on "DFID" (%llx/%x)\n",
+               CDEBUG(D_INFO, "%s: set orphan flag on "DFID" (%#llx/%#x)\n",
                       osd_obj2dev(obj)->od_svname,
                       PFID(lu_object_fid(&dt->do_lu)),
                       attr->la_valid, obj->oo_lma_flags);
@@ -1025,8 +1027,11 @@ static int osd_attr_get(const struct lu_env *env, struct dt_object *dt,
        sa_object_size(obj->oo_sa_hdl, &blksize, &blocks);
        /* we do not control size of indices, so always calculate
         * it from number of blocks reported by DMU */
-       if (S_ISDIR(attr->la_mode))
+       if (S_ISDIR(attr->la_mode)) {
                attr->la_size = 512 * blocks;
+               rc = -zap_count(osd->od_os, obj->oo_dn->dn_object,
+                               &attr->la_dirent_count);
+       }
        /* Block size may be not set; suggest maximal I/O transfers. */
        if (blksize == 0)
                blksize = osd_spa_maxblocksize(
@@ -1126,7 +1131,7 @@ static int osd_declare_attr_set(const struct lu_env *env,
 
        down_read(&obj->oo_guard);
        if (unlikely(!dt_object_exists(dt) || obj->oo_destroyed))
-               GOTO(out, rc = 0);
+               GOTO(out_sem, rc = 0);
 
        LASSERT(obj->oo_sa_hdl != NULL);
        LASSERT(oh->ot_tx != NULL);
@@ -1148,7 +1153,7 @@ static int osd_declare_attr_set(const struct lu_env *env,
        if (!found)
                dmu_tx_hold_bonus(oh->ot_tx, obj->oo_dn->dn_object);
        if (oh->ot_tx->tx_err != 0)
-               GOTO(out, rc = -oh->ot_tx->tx_err);
+               GOTO(out_sem, rc = -oh->ot_tx->tx_err);
 
        if (attr && attr->la_valid & LA_FLAGS) {
                /* LMA is usually a part of bonus, no need to declare
@@ -1164,6 +1169,9 @@ static int osd_declare_attr_set(const struct lu_env *env,
                       osd->od_svname,
                       attr->la_uid, attr->la_gid, bspace, blksize);
        }
+       /* to preserve locking order - qsd_transfer() may need to flush
+        * currently running transaction when we're out of quota. */
+       up_read(&obj->oo_guard);
 
        if (attr && attr->la_valid & LA_UID) {
                /* quota enforcement for user */
@@ -1224,6 +1232,8 @@ static int osd_declare_attr_set(const struct lu_env *env,
        }
 #endif
 out:
+       RETURN(rc);
+out_sem:
        up_read(&obj->oo_guard);
        RETURN(rc);
 }
@@ -1335,6 +1345,9 @@ static int osd_attr_set(const struct lu_env *env, struct dt_object *dt,
                                CWARN("%s: failed to set LMA flags: rc = %d\n",
                                       osd->od_svname, rc);
                                GOTO(out, rc);
+                       } else {
+                               obj->oo_lma_flags =
+                                       la->la_flags & LUSTRE_LMA_FL_MASKS;
                        }
                }
        }
@@ -1946,6 +1959,8 @@ static int osd_create(const struct lu_env *env, struct dt_object *dt,
 
        /* we may fix some attributes, better do not change the source */
        obj->oo_attr = *attr;
+       obj->oo_attr.la_size = 0;
+       obj->oo_attr.la_nlink = 0;
        obj->oo_attr.la_valid |= LA_SIZE | LA_NLINK | LA_TYPE;
 
 #ifdef ZFS_PROJINHERIT
@@ -1965,7 +1980,7 @@ static int osd_create(const struct lu_env *env, struct dt_object *dt,
 
        zde->zde_pad = 0;
        zde->zde_dnode = dn->dn_object;
-       zde->zde_type = IFTODT(attr->la_mode & S_IFMT);
+       zde->zde_type = S_DT(attr->la_mode & S_IFMT);
 
        zapid = osd_get_name_n_idx(env, osd, fid, buf,
                                   sizeof(info->oti_str), &zdn);
@@ -2116,18 +2131,13 @@ static int osd_object_sync(const struct lu_env *env, struct dt_object *dt,
                           __u64 start, __u64 end)
 {
        struct osd_device *osd = osd_obj2dev(osd_dt_obj(dt));
-       struct dmu_buf_impl *db = osd_dt_obj(dt)->oo_dn->dn_dbuf;
        uint64_t txg = 0;
        ENTRY;
 
        if (osd->od_dt_dev.dd_rdonly)
                RETURN(0);
 
-       mutex_enter(&db->db_mtx);
-       if (db->db_last_dirty)
-               txg = db->db_last_dirty->dr_txg;
-       mutex_exit(&db->db_mtx);
-
+       txg = osd_db_dirty_txg(osd_dt_obj(dt)->oo_dn->dn_dbuf);
        if (txg) {
                /* the object is dirty or being synced */
                if (osd_object_sync_delay_us < 0)
@@ -2144,7 +2154,12 @@ static int osd_invalidate(const struct lu_env *env, struct dt_object *dt)
        return 0;
 }
 
-static struct dt_object_operations osd_obj_ops = {
+static bool osd_check_stale(struct dt_object *dt)
+{
+       return false;
+}
+
+static const struct dt_object_operations osd_obj_ops = {
        .do_read_lock           = osd_read_lock,
        .do_write_lock          = osd_write_lock,
        .do_read_unlock         = osd_read_unlock,
@@ -2171,9 +2186,10 @@ static struct dt_object_operations osd_obj_ops = {
        .do_xattr_list          = osd_xattr_list,
        .do_object_sync         = osd_object_sync,
        .do_invalidate          = osd_invalidate,
+       .do_check_stale         = osd_check_stale,
 };
 
-static struct lu_object_operations osd_lu_obj_ops = {
+static const struct lu_object_operations osd_lu_obj_ops = {
        .loo_object_init        = osd_object_init,
        .loo_object_delete      = osd_object_delete,
        .loo_object_release     = osd_object_release,
@@ -2190,7 +2206,7 @@ static int osd_otable_it_attr_get(const struct lu_env *env,
        return 0;
 }
 
-static struct dt_object_operations osd_obj_otable_it_ops = {
+static const struct dt_object_operations osd_obj_otable_it_ops = {
        .do_attr_get            = osd_otable_it_attr_get,
        .do_index_try           = osd_index_try,
 };