Whamcloud - gitweb
LU-14034 hsm: add PID file handling to lhsmtool_posix
[fs/lustre-release.git] / lustre / osd-zfs / osd_xattr.c
index 20b064e..e50f23f 100644 (file)
@@ -223,6 +223,46 @@ int osd_xattr_get_internal(const struct lu_env *env, struct osd_object *obj,
                                     buf, name, sizep);
 }
 
+/**
+ * Copy LMA extended attribute into provided buffer
+ *
+ * Note that no locking is done here.
+ *
+ * \param[in] env      execution environment
+ * \param[in] obj      object for which to retrieve xattr
+ * \param[out] buf     buffer to store xattr value in
+ *
+ * \retval 0           on success
+ * \retval negative    negated errno on failure
+ */
+int osd_xattr_get_lma(const struct lu_env *env, struct osd_object *obj,
+                     struct lu_buf *buf)
+{
+       int size = 0;
+       int rc = -ENOENT;
+
+       if (!buf)
+               return 0;
+
+       if (unlikely(obj->oo_destroyed))
+               goto out_lma;
+
+       /* check SA_ZPL_DXATTR first then fallback to directory xattr */
+       rc = __osd_sa_xattr_get(env, obj, buf, XATTR_NAME_LMA, &size);
+       if (!rc && unlikely(size < sizeof(struct lustre_mdt_attrs)))
+               rc = -EINVAL;
+       if (rc != -ENOENT)
+               goto out_lma;
+
+       rc = __osd_xattr_get_large(env, osd_obj2dev(obj), obj->oo_xattr,
+                                    buf, XATTR_NAME_LMA, &size);
+       if (!rc && unlikely(size < sizeof(struct lustre_mdt_attrs)))
+               rc = -EINVAL;
+
+out_lma:
+       return rc;
+}
+
 static int osd_get_pfid_from_lma(const struct lu_env *env,
                                 struct osd_object *obj,
                                 struct lu_buf *buf, int *sizep)
@@ -240,7 +280,7 @@ static int osd_get_pfid_from_lma(const struct lu_env *env,
        int rc;
        ENTRY;
 
-       CLASSERT(sizeof(info->oti_buf) >= sizeof(*loa));
+       BUILD_BUG_ON(sizeof(info->oti_buf) < sizeof(*loa));
        rc = osd_xattr_get_internal(env, obj, &tbuf,
                                    XATTR_NAME_LMA, sizep);
        if (rc)
@@ -292,6 +332,11 @@ int osd_xattr_get(const struct lu_env *env, struct dt_object *dt,
                RETURN(-EOPNOTSUPP);
 
        down_read(&obj->oo_guard);
+       if (unlikely(!dt_object_exists(dt) || obj->oo_destroyed)) {
+               up_read(&obj->oo_guard);
+               RETURN(-ENOENT);
+       }
+
        /* For the OST migrated from ldiskfs, the PFID EA may
         * be stored in LMA because of ldiskfs inode size. */
        if (strcmp(name, XATTR_NAME_FID) == 0 && obj->oo_pfid_in_lma)
@@ -409,7 +454,7 @@ int osd_declare_xattr_set(const struct lu_env *env, struct dt_object *dt,
        ENTRY;
 
        LASSERT(handle != NULL);
-       oh = container_of0(handle, struct osd_thandle, ot_super);
+       oh = container_of(handle, struct osd_thandle, ot_super);
 
        down_read(&obj->oo_guard);
        __osd_xattr_declare_set(env, obj, buf->lb_len, name, oh);
@@ -421,12 +466,12 @@ int osd_declare_xattr_set(const struct lu_env *env, struct dt_object *dt,
 int __osd_sa_attr_init(const struct lu_env *env, struct osd_object *obj,
                       struct osd_thandle *oh)
 {
-       sa_bulk_attr_t  *bulk = osd_oti_get(env)->oti_attr_bulk;
-       struct osa_attr *osa = &osd_oti_get(env)->oti_osa;
+       sa_bulk_attr_t *bulk = osd_oti_get(env)->oti_attr_bulk;
+       struct osa_attr *osa = &osd_oti_get(env)->oti_osa;
        struct lu_buf *lb = &osd_oti_get(env)->oti_xattr_lbuf;
        struct osd_device *osd = osd_obj2dev(obj);
-       uint64_t crtime[2], gen;
-       timestruc_t now;
+       uint64_t gen;
+       inode_timespec_t now;
        size_t size;
        int rc, cnt;
 
@@ -435,8 +480,10 @@ int __osd_sa_attr_init(const struct lu_env *env, struct osd_object *obj,
 
        gen = dmu_tx_get_txg(oh->ot_tx);
        gethrestime(&now);
-       ZFS_TIME_ENCODE(&now, crtime);
+       ZFS_TIME_ENCODE(&now, osa->btime);
 
+       obj->oo_attr.la_valid |= LA_BTIME;
+       obj->oo_attr.la_btime = osa->btime[0];
        osa->atime[0] = obj->oo_attr.la_atime;
        osa->ctime[0] = obj->oo_attr.la_ctime;
        osa->mtime[0] = obj->oo_attr.la_mtime;
@@ -470,7 +517,7 @@ int __osd_sa_attr_init(const struct lu_env *env, struct osd_object *obj,
        SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_ATIME(osd), NULL, osa->atime, 16);
        SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_MTIME(osd), NULL, osa->mtime, 16);
        SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_CTIME(osd), NULL, osa->ctime, 16);
-       SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_CRTIME(osd), NULL, crtime, 16);
+       SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_CRTIME(osd), NULL, osa->btime, 16);
        SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_LINKS(osd), NULL, &osa->nlink, 8);
 #ifdef ZFS_PROJINHERIT
        if (osd->od_projectused_dn)
@@ -578,8 +625,7 @@ int __osd_sa_xattr_set(const struct lu_env *env, struct osd_object *obj,
                return rc;
 
        LASSERT(obj->oo_sa_xattr);
-       /* Limited to 32k to keep nvpair memory allocations small */
-       if (buf->lb_len > DXATTR_MAX_ENTRY_SIZE) {
+       if (buf->lb_len > OBD_MAX_EA_SIZE) {
                too_big = 1;
        } else {
                /* Prevent the DXATTR SA from consuming the entire SA
@@ -773,7 +819,7 @@ static int osd_xattr_split_pfid(const struct lu_env *env,
        int rc;
        ENTRY;
 
-       CLASSERT(sizeof(info->oti_buf) >= sizeof(*loa));
+       BUILD_BUG_ON(sizeof(info->oti_buf) < sizeof(*loa));
        rc = osd_xattr_get_internal(env, obj, &buf, XATTR_NAME_LMA, &size);
        if (rc)
                RETURN(rc);
@@ -872,7 +918,7 @@ int osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
             strcmp(name, XATTR_NAME_POSIX_ACL_DEFAULT) == 0))
                RETURN(-EOPNOTSUPP);
 
-       oh = container_of0(handle, struct osd_thandle, ot_super);
+       oh = container_of(handle, struct osd_thandle, ot_super);
 
        down_write(&obj->oo_guard);
        CDEBUG(D_INODE, "Setting xattr %s with size %d\n",
@@ -942,7 +988,7 @@ int osd_declare_xattr_del(const struct lu_env *env, struct dt_object *dt,
        LASSERT(handle != NULL);
        LASSERT(osd_invariant(obj));
 
-       oh = container_of0(handle, struct osd_thandle, ot_super);
+       oh = container_of(handle, struct osd_thandle, ot_super);
        LASSERT(oh->ot_tx != NULL);
        LASSERT(obj->oo_dn != NULL);
 
@@ -964,7 +1010,17 @@ static int __osd_sa_xattr_del(const struct lu_env *env, struct osd_object *obj,
                return rc;
 
        rc = -nvlist_remove(obj->oo_sa_xattr, name, DATA_TYPE_BYTE_ARRAY);
-       if (rc == 0)
+       if (rc)
+               return rc;
+
+       /*
+        * only migrate delete LMV, and it needs to be done immediately, because
+        * it's used in deleting sub stripes, and if this is delayed, later when
+        * destroying the master object, it will delete sub stripes again.
+        */
+       if (!strcmp(name, XATTR_NAME_LMV))
+               rc = __osd_sa_xattr_update(env, obj, oh);
+       else
                rc = __osd_sa_xattr_schedule_update(env, obj, oh);
        return rc;
 }
@@ -1018,7 +1074,7 @@ int osd_xattr_del(const struct lu_env *env, struct dt_object *dt,
        LASSERT(obj->oo_dn != NULL);
        LASSERT(osd_invariant(obj));
        LASSERT(dt_object_exists(dt));
-       oh = container_of0(handle, struct osd_thandle, ot_super);
+       oh = container_of(handle, struct osd_thandle, ot_super);
        LASSERT(oh->ot_tx != NULL);
 
        if (!osd_obj2dev(obj)->od_posix_acl &&