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 8ef92c0..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/
@@ -660,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,
@@ -670,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,
@@ -1303,11 +1303,16 @@ static dmu_buf_t *osd_mkreg(const struct lu_env *env, struct osd_object *obj,
        if (rc)
                return ERR_PTR(rc);
 
+       /*
+        * XXX: This heuristic is non-optimal.  It would be better to
+        * increase the blocksize up to osd->od_max_blksz during the write.
+        * This is exactly how the ZPL behaves and it ensures that the right
+        * blocksize is selected based on the file size rather than the
+        * making broad assumptions based on the osd type.
+        */
        if (!lu_device_is_md(osd2lu_dev(osd))) {
-               /* uses 4K as default block size because clients write data
-                * with page size that is 4K at minimum */
                rc = -dmu_object_set_blocksize(osd->od_os, db->db_object,
-                                              4096, 0, oh->ot_tx);
+                                              osd->od_max_blksz, 0, oh->ot_tx);
                if (unlikely(rc)) {
                        CERROR("%s: can't change blocksize: %d\n",
                               osd->od_svname, rc);
@@ -1520,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);
@@ -1568,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,