Whamcloud - gitweb
LU-7579 osd: move ORPHAN/DEAD flag to OSD
[fs/lustre-release.git] / lustre / osd-zfs / osd_object.c
index 9884333..7935fab 100644 (file)
@@ -231,6 +231,28 @@ 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;
+               }
+       }
+
        if (S_ISCHR(la->la_mode) || S_ISBLK(la->la_mode)) {
                rc = -sa_lookup(sa_hdl, SA_ZPL_RDEV(o), &osa->rdev, 8);
                if (rc)
@@ -719,12 +741,18 @@ static int osd_attr_get(const struct lu_env *env,
        uint64_t                 blocks;
        uint32_t                 blksize;
 
-       LASSERT(dt_object_exists(dt));
+       if (unlikely(!dt_object_exists(dt)))
+               return -ENOENT;
+       if (unlikely(obj->oo_destroyed))
+               return -ENOENT;
+
        LASSERT(osd_invariant(obj));
        LASSERT(obj->oo_db);
 
        read_lock(&obj->oo_attr_lock);
        *attr = obj->oo_attr;
+       if (obj->oo_lma_flags & LUSTRE_ORPHAN_FL)
+               attr->la_flags |= LUSTRE_ORPHAN_FL;
        read_unlock(&obj->oo_attr_lock);
 
        /* with ZFS_DEBUG zrl_add_debug() called by DB_DNODE_ENTER()
@@ -842,6 +870,9 @@ static int osd_declare_attr_set(const struct lu_env *env,
        sa_object_size(obj->oo_sa_hdl, &blksize, &bspace);
        bspace = toqb(bspace * blksize);
 
+       __osd_xattr_declare_set(env, obj, sizeof(struct lustre_mdt_attrs),
+                               XATTR_NAME_LMA, oh);
+
        if (attr && attr->la_valid & LA_UID) {
                /* account for user inode tracking ZAP update */
                dmu_tx_hold_bonus(oh->ot_tx, osd->od_iusr_oid);
@@ -886,10 +917,11 @@ static int osd_declare_attr_set(const struct lu_env *env,
 static int osd_attr_set(const struct lu_env *env, struct dt_object *dt,
                        const struct lu_attr *la, struct thandle *handle)
 {
+       struct osd_thread_info  *info = osd_oti_get(env);
        struct osd_object       *obj = osd_dt_obj(dt);
        struct osd_device       *osd = osd_obj2dev(obj);
        struct osd_thandle      *oh;
-       struct osa_attr         *osa = &osd_oti_get(env)->oti_osa;
+       struct osa_attr         *osa = &info->oti_osa;
        sa_bulk_attr_t          *bulk;
        __u64                    valid = la->la_valid;
        int                      cnt;
@@ -913,6 +945,39 @@ static int osd_attr_set(const struct lu_env *env, struct dt_object *dt,
        if (valid == 0)
                RETURN(0);
 
+       if (valid & LA_FLAGS) {
+               struct lustre_mdt_attrs *lma;
+               struct lu_buf buf;
+
+               if (la->la_flags & LUSTRE_LMA_FL_MASKS) {
+                       CLASSERT(sizeof(info->oti_buf) >= sizeof(*lma));
+                       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) {
+                               lma->lma_incompat =
+                                       le32_to_cpu(lma->lma_incompat);
+                               lma->lma_incompat |=
+                                       lustre_to_lma_flags(la->la_flags);
+                               lma->lma_incompat =
+                                       cpu_to_le32(lma->lma_incompat);
+                               buf.lb_buf = lma;
+                               buf.lb_len = sizeof(*lma);
+                               rc = osd_xattr_set_internal(env, obj, &buf,
+                                                           XATTR_NAME_LMA,
+                                                           LU_XATTR_REPLACE,
+                                                           oh);
+                       }
+                       if (rc < 0) {
+                               CWARN("%s: failed to set LMA flags: rc = %d\n",
+                                      osd->od_svname, rc);
+                               RETURN(rc);
+                       }
+               }
+       }
+
        OBD_ALLOC(bulk, sizeof(sa_bulk_attr_t) * 10);
        if (bulk == NULL)
                RETURN(-ENOMEM);