Whamcloud - gitweb
LU-6856 zfs: handle non existing file in osd_object_ref_del
[fs/lustre-release.git] / lustre / osd-zfs / osd_object.c
index 2279df0..d59aa91 100644 (file)
@@ -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/
@@ -583,7 +583,17 @@ static int osd_object_destroy(const struct lu_env *env,
                       obj->oo_attr.la_gid, rc);
 
        oid = obj->oo_db->db_object;
-       if (obj->oo_destroy == OSD_DESTROY_SYNC) {
+       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",
@@ -603,7 +613,8 @@ static int osd_object_destroy(const struct lu_env *env,
 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);
 }
 
@@ -649,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,
@@ -659,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,
@@ -1440,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);
@@ -1513,8 +1525,10 @@ static int osd_object_ref_add(const struct lu_env *env,
 
        ENTRY;
 
+       if (!dt_object_exists(dt))
+               RETURN(-ENOENT);
+
        LASSERT(osd_invariant(obj));
-       LASSERT(dt_object_exists(dt));
        LASSERT(obj->oo_sa_hdl != NULL);
 
        oh = container_of0(handle, struct osd_thandle, ot_super);
@@ -1561,7 +1575,7 @@ static int osd_object_ref_del(const struct lu_env *env,
        write_unlock(&obj->oo_attr_lock);
 
        rc = osd_object_sa_update(obj, SA_ZPL_LINKS(osd), &nlink, 8, oh);
-       return rc;
+       RETURN(rc);
 }
 
 static int osd_object_sync(const struct lu_env *env, struct dt_object *dt,