Whamcloud - gitweb
LU-812 kernel: remove smp_lock.h
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_iam.c
index 290cf29..49f56de 100644 (file)
@@ -1,6 +1,4 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
  * GPL HEADER START
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -28,6 +26,8 @@
 /*
  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright (c) 2011, 2012, Whamcloud, Inc.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 #include <linux/string.h>
 #include <linux/quotaops.h>
 #include <linux/buffer_head.h>
-#include <linux/smp_lock.h>
 #include "osd_internal.h"
 
 #include "xattr.h"
-#include "iopen.h"
 #include "acl.h"
 
 /*
@@ -191,6 +189,8 @@ EXPORT_SYMBOL(iam_container_setup);
  */
 void iam_container_fini(struct iam_container *c)
 {
+        brelse(c->ic_root_bh);
+        c->ic_root_bh = NULL;
 }
 EXPORT_SYMBOL(iam_container_fini);
 
@@ -269,6 +269,18 @@ int iam_node_read(struct iam_container *c, iam_ptr_t ptr,
 {
         int result = 0;
 
+        /* NB: it can be called by iam_lfix_guess() which is still at
+         * very early stage, c->ic_root_bh and c->ic_descr->id_ops
+         * haven't been intialized yet.
+         * Also, we don't have this for IAM dir.
+         */
+        if (c->ic_root_bh != NULL &&
+            c->ic_descr->id_ops->id_root_ptr(c) == ptr) {
+                get_bh(c->ic_root_bh);
+                *bh = c->ic_root_bh;
+                return 0;
+        }
+
         *bh = ldiskfs_bread(h, c->ic_object, (int)ptr, 0, &result);
         if (*bh == NULL)
                 result = -EIO;
@@ -1643,7 +1655,7 @@ static int iam_shift_entries(struct iam_path *path,
         count2 = count - count1;
         dx_get_ikey(path, iam_entry_shift(path, entries, count1), pivot);
 
-        dxtrace(printk("Split index %i/%i\n", count1, count2));
+        dxtrace(printk("Split index %d/%d\n", count1, count2));
 
         memcpy((char *) iam_entry_shift(path, entries2, delta),
                (char *) iam_entry_shift(path, entries, count1),
@@ -2236,20 +2248,27 @@ EXPORT_SYMBOL(iam_insert);
  * Update record with the key @k in container @c (within context of
  * transaction @h), new record is given by @r.
  *
- * Return values: 0: success, -ve: error, including -ENOENT if no record with
- * the given key found.
+ * Return values: +1: skip because of the same rec value, 0: success,
+ * -ve: error, including -ENOENT if no record with the given key found.
  */
 int iam_update(handle_t *h, struct iam_container *c, const struct iam_key *k,
                const struct iam_rec *r, struct iam_path_descr *pd)
 {
         struct iam_iterator it;
-        int result;
-
-        iam_it_init(&it, c, IAM_IT_WRITE, pd);
-
-        result = iam_it_get_exact(&it, k);
-        if (result == 0)
-                iam_it_rec_set(h, &it, r);
+       struct iam_leaf *folio;
+       int result;
+
+       iam_it_init(&it, c, IAM_IT_WRITE, pd);
+
+       result = iam_it_get_exact(&it, k);
+       if (result == 0) {
+               folio = &it.ii_path.ip_leaf;
+               result = iam_leaf_ops(folio)->rec_eq(folio, r);
+               if (result == 0)
+                       iam_it_rec_set(h, &it, r);
+               else
+                       result = 1;
+       }
         iam_it_put(&it);
         iam_it_fini(&it);
         return result;