- spin_lock(&obj->oo_guard);
- osd_inode_getattr(env, obj->oo_inode, attr);
- if (obj->oo_lma_flags & LUSTRE_ORPHAN_FL)
- attr->la_flags |= LUSTRE_ORPHAN_FL;
+ if (obj->oo_dirent_count != LU_DIRENT_COUNT_UNSET) {
+ *count = obj->oo_dirent_count;
+ RETURN(0);
+ }
+
+ /* directory not initialized yet */
+ if (!dt->do_index_ops) {
+ *count = 0;
+ RETURN(0);
+ }
+
+ iops = &dt->do_index_ops->dio_it;
+ it = iops->init(env, dt, LUDA_64BITHASH);
+ if (IS_ERR(it))
+ RETURN(PTR_ERR(it));
+
+ rc = iops->load(env, it, 0);
+ if (rc < 0) {
+ if (rc == -ENODATA) {
+ rc = 0;
+ *count = 0;
+ }
+ GOTO(out, rc);
+ }
+ if (rc > 0)
+ rc = iops->next(env, it);
+
+ for (*count = 0; rc == 0 || rc == -ESTALE; rc = iops->next(env, it)) {
+ if (rc == -ESTALE)
+ continue;
+
+ if (iops->key_size(env, it) == 0)
+ continue;
+
+ (*count)++;
+ }
+ if (rc == 1) {
+ obj->oo_dirent_count = *count;
+ rc = 0;
+ }
+out:
+ iops->put(env, it);
+ iops->fini(env, it);
+
+ RETURN(rc);
+}
+
+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);
+ int rc = 0;
+
+ if (unlikely(!dt_object_exists(dt)))
+ return -ENOENT;
+ if (unlikely(obj->oo_destroyed))
+ return -ENOENT;
+
+ LASSERT(!dt_object_remote(dt));
+ LINVRNT(osd_invariant(obj));
+
+ spin_lock(&obj->oo_guard);
+ osd_inode_getattr(env, obj->oo_inode, attr);
+ if (obj->oo_lma_flags & LUSTRE_ORPHAN_FL) {
+ 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;
+ }