Whamcloud - gitweb
LU-14286 osd-ldiskfs: don't read unwritten blocks
[fs/lustre-release.git] / lustre / osd-zfs / osd_xattr.c
index 0db69f3..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)
@@ -430,7 +470,7 @@ int __osd_sa_attr_init(const struct lu_env *env, struct osd_object *obj,
        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;
+       uint64_t gen;
        inode_timespec_t now;
        size_t size;
        int rc, cnt;
@@ -440,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;
@@ -475,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)