X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fosd-zfs%2Fosd_object.c;h=2dc03709e6e13ca56144af665f889d52dfc6e726;hb=953e9e5e75ca12a5ef72bfe844c1216341af12c9;hp=ab0a288848765858d8fd2a9d9fcb7ee5337b5df0;hpb=bc9eae65f0880e5ae781d373f843d2c76f263714;p=fs%2Flustre-release.git diff --git a/lustre/osd-zfs/osd_object.c b/lustre/osd-zfs/osd_object.c index ab0a288..2dc0370 100644 --- a/lustre/osd-zfs/osd_object.c +++ b/lustre/osd-zfs/osd_object.c @@ -27,7 +27,7 @@ * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012, 2014, Intel Corporation. + * Copyright (c) 2012, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -136,7 +136,7 @@ void osd_object_sa_dirty_rele(struct osd_thandle *oh) down(&oh->ot_sa_lock); while (!list_empty(&oh->ot_sa_list)) { obj = list_entry(oh->ot_sa_list.next, - struct osd_object, oo_sa_linkage); + struct osd_object, oo_sa_linkage); sa_spill_rele(obj->oo_sa_hdl); write_lock(&obj->oo_attr_lock); list_del_init(&obj->oo_sa_linkage); @@ -291,9 +291,11 @@ struct lu_object *osd_object_alloc(const struct lu_env *env, mo->oo_dt.do_ops = &osd_obj_ops; l->lo_ops = &osd_lu_obj_ops; INIT_LIST_HEAD(&mo->oo_sa_linkage); + INIT_LIST_HEAD(&mo->oo_unlinked_linkage); init_rwsem(&mo->oo_sem); sema_init(&mo->oo_guard, 1); rwlock_init(&mo->oo_attr_lock); + mo->oo_destroy = OSD_DESTROY_NONE; return l; } else { return NULL; @@ -306,7 +308,7 @@ struct lu_object *osd_object_alloc(const struct lu_env *env, int osd_object_init0(const struct lu_env *env, struct osd_object *obj) { struct osd_device *osd = osd_obj2dev(obj); - const struct lu_fid *fid = lu_object_fid(&obj->oo_dt.do_lu); + const struct lu_fid *fid = lu_object_fid(&obj->oo_dt.do_lu); int rc = 0; ENTRY; @@ -432,53 +434,46 @@ static void osd_object_free(const struct lu_env *env, struct lu_object *l) OBD_SLAB_FREE_PTR(obj, osd_object_kmem); } -static void __osd_declare_object_destroy(const struct lu_env *env, - struct osd_object *obj, - struct osd_thandle *oh) +static int +osd_object_unlinked_add(struct osd_object *obj, struct osd_thandle *oh) { - struct osd_device *osd = osd_obj2dev(obj); - dmu_buf_t *db = obj->oo_db; - zap_attribute_t *za = &osd_oti_get(env)->oti_za; - uint64_t oid = db->db_object, xid; - dmu_tx_t *tx = oh->ot_tx; - zap_cursor_t *zc; - int rc = 0; + int rc = -EBUSY; - dmu_tx_hold_free(tx, oid, 0, DMU_OBJECT_END); + down(&obj->oo_guard); - /* zap holding xattrs */ - if (obj->oo_xattr != ZFS_NO_OBJECT) { - oid = obj->oo_xattr; + LASSERT(obj->oo_destroy == OSD_DESTROY_ASYNC); - dmu_tx_hold_free(tx, oid, 0, DMU_OBJECT_END); + if (likely(list_empty(&obj->oo_unlinked_linkage))) { + list_add(&obj->oo_unlinked_linkage, &oh->ot_unlinked_list); + rc = 0; + } - rc = osd_zap_cursor_init(&zc, osd->od_os, oid, 0); - if (rc) - goto out; - - while ((rc = -zap_cursor_retrieve(zc, za)) == 0) { - BUG_ON(za->za_integer_length != sizeof(uint64_t)); - BUG_ON(za->za_num_integers != 1); - - rc = -zap_lookup(osd->od_os, obj->oo_xattr, za->za_name, - sizeof(uint64_t), 1, &xid); - if (rc) { - CERROR("%s: xattr lookup failed: rc = %d\n", - osd->od_svname, rc); - goto out_err; - } - dmu_tx_hold_free(tx, xid, 0, DMU_OBJECT_END); - - zap_cursor_advance(zc); - } - if (rc == -ENOENT) - rc = 0; -out_err: - osd_zap_cursor_fini(zc); + up(&obj->oo_guard); + + return rc; +} + +/* Default to max data size covered by a level-1 indirect block */ +static unsigned long osd_sync_destroy_max_size = + 1UL << (DN_MAX_INDBLKSHIFT - SPA_BLKPTRSHIFT + SPA_MAXBLOCKSHIFT); +CFS_MODULE_PARM(osd_sync_destroy_max_size, "ul", ulong, 0444, + "Maximum object size to use synchronous destroy."); + +static inline void +osd_object_set_destroy_type(struct osd_object *obj) +{ + /* + * Lock-less OST_WRITE can race with OST_DESTROY, so set destroy type + * only once and use it consistently thereafter. + */ + down(&obj->oo_guard); + if (obj->oo_destroy == OSD_DESTROY_NONE) { + if (obj->oo_attr.la_size <= osd_sync_destroy_max_size) + obj->oo_destroy = OSD_DESTROY_SYNC; + else /* Larger objects are destroyed asynchronously */ + obj->oo_destroy = OSD_DESTROY_ASYNC; } -out: - if (rc && tx->tx_err == 0) - tx->tx_err = -rc; + up(&obj->oo_guard); } static int osd_declare_object_destroy(const struct lu_env *env, @@ -490,8 +485,8 @@ static int osd_declare_object_destroy(const struct lu_env *env, struct osd_object *obj = osd_dt_obj(dt); struct osd_device *osd = osd_obj2dev(obj); struct osd_thandle *oh; - uint64_t zapid; int rc; + uint64_t zapid; ENTRY; LASSERT(th != NULL); @@ -500,19 +495,18 @@ static int osd_declare_object_destroy(const struct lu_env *env, oh = container_of0(th, struct osd_thandle, ot_super); LASSERT(oh->ot_tx != NULL); - /* declare that we'll destroy the object */ - __osd_declare_object_destroy(env, obj, oh); - /* declare that we'll remove object from fid-dnode mapping */ zapid = osd_get_name_n_idx(env, osd, fid, buf); dmu_tx_hold_bonus(oh->ot_tx, zapid); - dmu_tx_hold_zap(oh->ot_tx, zapid, 0, buf); + dmu_tx_hold_zap(oh->ot_tx, zapid, FALSE, buf); + + osd_declare_xattrs_destroy(env, obj, oh); /* declare that we'll remove object from inode accounting ZAPs */ dmu_tx_hold_bonus(oh->ot_tx, osd->od_iusr_oid); - dmu_tx_hold_zap(oh->ot_tx, osd->od_iusr_oid, 0, buf); + dmu_tx_hold_zap(oh->ot_tx, osd->od_iusr_oid, FALSE, buf); dmu_tx_hold_bonus(oh->ot_tx, osd->od_igrp_oid); - dmu_tx_hold_zap(oh->ot_tx, osd->od_igrp_oid, 0, buf); + dmu_tx_hold_zap(oh->ot_tx, osd->od_igrp_oid, FALSE, buf); /* one less inode */ rc = osd_declare_quota(env, osd, obj->oo_attr.la_uid, @@ -523,68 +517,21 @@ static int osd_declare_object_destroy(const struct lu_env *env, /* data to be truncated */ rc = osd_declare_quota(env, osd, obj->oo_attr.la_uid, obj->oo_attr.la_gid, 0, oh, true, NULL, false); - RETURN(rc); -} - -/* - * Delete a DMU object - * - * The transaction passed to this routine must have - * dmu_tx_hold_free(tx, oid, 0, DMU_OBJECT_END) called - * and then assigned to a transaction group. - * - * This will release db and set it to NULL to prevent further dbuf releases. - */ -static int __osd_object_destroy(const struct lu_env *env, - struct osd_object *obj, - dmu_tx_t *tx, void *tag) -{ - struct osd_device *osd = osd_obj2dev(obj); - uint64_t xid; - zap_attribute_t *za = &osd_oti_get(env)->oti_za; - zap_cursor_t *zc; - int rc; - - /* Assert that the transaction has been assigned to a - transaction group. */ - LASSERT(tx->tx_txg != 0); - - /* zap holding xattrs */ - if (obj->oo_xattr != ZFS_NO_OBJECT) { - rc = osd_zap_cursor_init(&zc, osd->od_os, obj->oo_xattr, 0); - if (rc) - return rc; - while ((rc = -zap_cursor_retrieve(zc, za)) == 0) { - BUG_ON(za->za_integer_length != sizeof(uint64_t)); - BUG_ON(za->za_num_integers != 1); - - 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); - continue; - } - rc = -dmu_object_free(osd->od_os, xid, tx); - if (rc) - CERROR("%s: fetch xattr %s failed: rc = %d\n", - osd->od_svname, za->za_name, rc); - zap_cursor_advance(zc); - } - osd_zap_cursor_fini(zc); + if (rc) + RETURN(rc); - rc = -dmu_object_free(osd->od_os, obj->oo_xattr, tx); - if (rc) - CERROR("%s: freeing xattr failed: rc = %d\n", - osd->od_svname, rc); - } + osd_object_set_destroy_type(obj); + if (obj->oo_destroy == OSD_DESTROY_SYNC) + dmu_tx_hold_free(oh->ot_tx, obj->oo_db->db_object, + 0, DMU_OBJECT_END); + else + dmu_tx_hold_zap(oh->ot_tx, osd->od_unlinkedid, TRUE, NULL); - return -dmu_object_free(osd->od_os, obj->oo_db->db_object, tx); + RETURN(0); } static int osd_object_destroy(const struct lu_env *env, - struct dt_object *dt, - struct thandle *th) + struct dt_object *dt, struct thandle *th) { char *buf = osd_oti_get(env)->oti_str; struct osd_object *obj = osd_dt_obj(dt); @@ -592,7 +539,7 @@ static int osd_object_destroy(const struct lu_env *env, const struct lu_fid *fid = lu_object_fid(&dt->do_lu); struct osd_thandle *oh; int rc; - uint64_t zapid; + uint64_t oid, zapid; ENTRY; LASSERT(obj->oo_db != NULL); @@ -603,13 +550,19 @@ static int osd_object_destroy(const struct lu_env *env, LASSERT(oh != NULL); LASSERT(oh->ot_tx != NULL); - zapid = osd_get_name_n_idx(env, osd, fid, buf); - /* remove obj ref from index dir (it depends) */ + zapid = osd_get_name_n_idx(env, osd, fid, buf); rc = -zap_remove(osd->od_os, zapid, buf, oh->ot_tx); if (rc) { - CERROR("%s: zap_remove() failed: rc = %d\n", - osd->od_svname, rc); + CERROR("%s: zap_remove(%s) failed: rc = %d\n", + osd->od_svname, buf, rc); + GOTO(out, rc); + } + + rc = osd_xattrs_destroy(env, obj, oh); + if (rc) { + CERROR("%s: cannot destroy xattrs for %s: rc = %d\n", + osd->od_svname, buf, rc); GOTO(out, rc); } @@ -617,30 +570,51 @@ static int osd_object_destroy(const struct lu_env *env, * operation if something goes wrong while updating accounting, but we * still log an error message to notify the administrator */ rc = -zap_increment_int(osd->od_os, osd->od_iusr_oid, - obj->oo_attr.la_uid, -1, oh->ot_tx); + obj->oo_attr.la_uid, -1, oh->ot_tx); if (rc) CERROR("%s: failed to remove "DFID" from accounting ZAP for usr" - " %d: rc = %d\n", osd->od_svname, PFID(fid), - obj->oo_attr.la_uid, rc); + " %d: rc = %d\n", osd->od_svname, PFID(fid), + obj->oo_attr.la_uid, rc); rc = -zap_increment_int(osd->od_os, osd->od_igrp_oid, obj->oo_attr.la_gid, -1, oh->ot_tx); if (rc) CERROR("%s: failed to remove "DFID" from accounting ZAP for grp" - " %d: rc = %d\n", osd->od_svname, PFID(fid), - obj->oo_attr.la_gid, rc); + " %d: rc = %d\n", osd->od_svname, PFID(fid), + obj->oo_attr.la_gid, rc); + + oid = obj->oo_db->db_object; + if (unlikely(obj->oo_destroy == OSD_DESTROY_NONE)) { + /* this may happen if the destroy wasn't declared + * e.g. when the object is created and then destroyed + * in the same transaction - we don't need additional + * space for destroy specifically */ + LASSERT(obj->oo_attr.la_size <= osd_sync_destroy_max_size); + rc = -dmu_object_free(osd->od_os, oid, oh->ot_tx); + if (rc) + CERROR("%s: failed to free %s "LPU64": rc = %d\n", + osd->od_svname, buf, oid, rc); + } else if (obj->oo_destroy == OSD_DESTROY_SYNC) { + rc = -dmu_object_free(osd->od_os, oid, oh->ot_tx); + if (rc) + CERROR("%s: failed to free %s "LPU64": rc = %d\n", + osd->od_svname, buf, oid, rc); + } else { /* asynchronous destroy */ + rc = osd_object_unlinked_add(obj, oh); + if (rc) + GOTO(out, rc); - /* kill object */ - rc = __osd_object_destroy(env, obj, oh->ot_tx, osd_obj_tag); - if (rc) { - CERROR("%s: __osd_object_destroy() failed: rc = %d\n", - osd->od_svname, rc); - GOTO(out, rc); + rc = -zap_add_int(osd->od_os, osd->od_unlinkedid, + oid, oh->ot_tx); + if (rc) + CERROR("%s: zap_add_int() failed %s "LPU64": rc = %d\n", + osd->od_svname, buf, oid, rc); } out: /* not needed in the cache anymore */ set_bit(LU_OBJECT_HEARD_BANSHEE, &dt->do_lu.lo_header->loh_flags); - + if (rc == 0) + obj->oo_destroyed = 1; RETURN (0); } @@ -686,7 +660,7 @@ static void osd_object_read_lock(const struct lu_env *env, LASSERT(osd_invariant(obj)); - down_read(&obj->oo_sem); + down_read_nested(&obj->oo_sem, role); } static void osd_object_write_lock(const struct lu_env *env, @@ -696,7 +670,7 @@ static void osd_object_write_lock(const struct lu_env *env, LASSERT(osd_invariant(obj)); - down_write(&obj->oo_sem); + down_write_nested(&obj->oo_sem, role); } static void osd_object_read_unlock(const struct lu_env *env, @@ -1477,7 +1451,8 @@ static int osd_object_create(const struct lu_env *env, struct dt_object *dt, /* to follow ZFS on-disk format we need * to initialize parent dnode properly */ zapid = 0; - if (hint && hint->dah_parent) + if (hint != NULL && hint->dah_parent != NULL && + !dt_object_remote(hint->dah_parent)) zapid = osd_dt_obj(hint->dah_parent)->oo_db->db_object; db = osd_create_type_f(dof->dof_type)(env, obj, attr, zapid, oh);