/** * Restore iterator from cookie. if the \a hash isn't found, * restore the first valid record. * * \param di - osd iterator * \param hash - iterator location cookie * * \retval +ve - di points to exact matched key * \retval 0 - di points to the first valid record * \retval -ve - failure */ static int osd_it_acct_load(const struct lu_env *env, const struct dt_it *di, __u64 hash) { struct osd_it_quota *it = (struct osd_it_quota *)di; struct osd_device *osd = osd_obj2dev(it->oiq_obj); zap_attribute_t *za = &osd_oti_get(env)->oti_za; zap_cursor_t *zc; int rc; ENTRY; /* create new cursor pointing to the new hash */ rc = osd_zap_cursor_init(&zc, osd->od_os, it->oiq_oid, hash); if (rc) RETURN(rc); osd_zap_cursor_fini(it->oiq_zc); it->oiq_zc = zc; it->oiq_reset = 0; rc = -zap_cursor_retrieve(it->oiq_zc, za); if (rc == 0) rc = 1; else if (rc == -ENOENT) rc = 0; RETURN(rc); }
/** * Free given iterator. * * \param di - osd iterator */ static void osd_it_acct_fini(const struct lu_env *env, struct dt_it *di) { struct osd_thread_info *info = osd_oti_get(env); struct osd_it_quota *it = (struct osd_it_quota *)di; ENTRY; osd_zap_cursor_fini(it->oiq_zc); lu_object_put(env, &it->oiq_obj->oo_dt.do_lu); if (it != &info->oti_it_quota) OBD_FREE_PTR(it); else info->oti_it_inline = 0; EXIT; }
int osd_xattrs_destroy(const struct lu_env *env, struct osd_object *obj, struct osd_thandle *oh) { struct osd_device *osd = osd_obj2dev(obj); dmu_tx_t *tx = oh->ot_tx; zap_attribute_t *za = &osd_oti_get(env)->oti_za; zap_cursor_t *zc; uint64_t xid; int rc; /* The transaction must have been assigned to a transaction group. */ LASSERT(tx->tx_txg != 0); if (obj->oo_xattr == ZFS_NO_OBJECT) return 0; /* Nothing to do for SA xattrs */ /* Free the ZAP holding the xattrs */ rc = osd_zap_cursor_init(&zc, osd->od_os, obj->oo_xattr, 0); if (rc) return rc; while (zap_cursor_retrieve(zc, za) == 0) { LASSERT(za->za_num_integers == 1); LASSERT(za->za_integer_length == sizeof(uint64_t)); rc = -zap_lookup(osd->od_os, obj->oo_xattr, za->za_name, sizeof(uint64_t), 1, &xid); if (rc) { CERROR("%s: lookup xattr %s failed: rc = %d\n", osd->od_svname, za->za_name, rc); } else { rc = -dmu_object_free(osd->od_os, xid, tx); if (rc) CERROR("%s: free xattr %s failed: rc = %d\n", osd->od_svname, za->za_name, rc); } zap_cursor_advance(zc); } osd_zap_cursor_fini(zc); rc = -dmu_object_free(osd->od_os, obj->oo_xattr, tx); if (rc) CERROR("%s: free xattr "LPU64" failed: rc = %d\n", osd->od_svname, obj->oo_xattr, rc); return rc; }
void osd_declare_xattrs_destroy(const struct lu_env *env, struct osd_object *obj, struct osd_thandle *oh) { struct osd_device *osd = osd_obj2dev(obj); zap_attribute_t *za = &osd_oti_get(env)->oti_za; uint64_t oid = obj->oo_xattr, xid; dmu_tx_t *tx = oh->ot_tx; zap_cursor_t *zc; int rc; if (oid == ZFS_NO_OBJECT) return; /* Nothing to do for SA xattrs */ /* Declare to free the ZAP holding xattrs */ dmu_tx_hold_free(tx, oid, 0, DMU_OBJECT_END); rc = osd_zap_cursor_init(&zc, osd->od_os, oid, 0); if (rc) goto out; while (zap_cursor_retrieve(zc, za) == 0) { LASSERT(za->za_num_integers == 1); LASSERT(za->za_integer_length == sizeof(uint64_t)); rc = -zap_lookup(osd->od_os, oid, za->za_name, sizeof(uint64_t), 1, &xid); if (rc) { CERROR("%s: xattr %s lookup failed: rc = %d\n", osd->od_svname, za->za_name, rc); break; } dmu_tx_hold_free(tx, xid, 0, DMU_OBJECT_END); zap_cursor_advance(zc); } osd_zap_cursor_fini(zc); out: if (rc && tx->tx_err == 0) tx->tx_err = -rc; }
int osd_xattr_list(const struct lu_env *env, struct dt_object *dt, const struct lu_buf *lb) { struct osd_object *obj = osd_dt_obj(dt); struct osd_device *osd = osd_obj2dev(obj); zap_attribute_t *za = &osd_oti_get(env)->oti_za; zap_cursor_t *zc; int rc, counted; ENTRY; LASSERT(obj->oo_db != NULL); LASSERT(osd_invariant(obj)); LASSERT(dt_object_exists(dt)); down_read(&obj->oo_guard); rc = osd_sa_xattr_list(env, obj, lb); if (rc < 0) GOTO(out, rc); counted = rc; /* continue with dnode xattr if any */ if (obj->oo_xattr == ZFS_NO_OBJECT) GOTO(out, rc = counted); rc = osd_zap_cursor_init(&zc, osd->od_os, obj->oo_xattr, 0); if (rc) GOTO(out, rc); while ((rc = -zap_cursor_retrieve(zc, za)) == 0) { if (!osd_obj2dev(obj)->od_posix_acl && (strcmp(za->za_name, POSIX_ACL_XATTR_ACCESS) == 0 || strcmp(za->za_name, POSIX_ACL_XATTR_DEFAULT) == 0)) { zap_cursor_advance(zc); continue; } rc = strlen(za->za_name); if (lb->lb_buf != NULL) { if (counted + rc + 1 > lb->lb_len) GOTO(out_fini, rc = -ERANGE); memcpy(lb->lb_buf + counted, za->za_name, rc + 1); } counted += rc + 1; zap_cursor_advance(zc); } if (rc == -ENOENT) /* no more kes in the index */ rc = 0; else if (unlikely(rc < 0)) GOTO(out_fini, rc); rc = counted; out_fini: osd_zap_cursor_fini(zc); out: up_read(&obj->oo_guard); RETURN(rc); }